]> git.tdb.fi Git - libs/gl.git/blob - source/core/texture2dmultisample.cpp
Use standard fixed-size integer types
[libs/gl.git] / source / core / texture2dmultisample.cpp
1 #include <msp/gl/extensions/arb_direct_state_access.h>
2 #include <msp/gl/extensions/arb_texture_multisample.h>
3 #include <msp/gl/extensions/arb_texture_storage_multisample.h>
4 #include "deviceinfo.h"
5 #include "error.h"
6 #include "texture2dmultisample.h"
7
8 using namespace std;
9
10 namespace Msp {
11 namespace GL {
12
13 Texture2DMultisample::Texture2DMultisample():
14         Texture(GL_TEXTURE_2D_MULTISAMPLE),
15         width(0),
16         height(0)
17 {
18         static Require _req(ARB_texture_multisample);
19 }
20
21 void Texture2DMultisample::storage(PixelFormat fmt, unsigned wd, unsigned ht, unsigned sm)
22 {
23         if(width>0)
24         {
25                 if(fmt!=format || wd!=width || ht!=height || sm!=samples)
26                         throw incompatible_data("Texture2DMultisample::storage");
27                 return;
28         }
29         if(wd==0 || ht==0)
30                 throw invalid_argument("Texture2DMultisample::storage");
31         if(!sm || sm>Limits::get_global().max_samples)
32                 throw invalid_argument("Texture2DMultisample::storage");
33
34         set_format(fmt);
35         width = wd;
36         height = ht;
37         samples = sm;
38
39         GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
40         if(ARB_texture_storage_multisample)
41         {
42                 if(ARB_direct_state_access)
43                         glTextureStorage2DMultisample(id, samples, gl_fmt, width, height, false);
44                 else
45                 {
46                         bind_scratch();
47                         glTexStorage2DMultisample(target, samples, gl_fmt, width, height, false);
48                 }
49         }
50         else
51         {
52                 bind_scratch();
53                 glTexImage2DMultisample(target, samples, gl_fmt, width, height, false);
54         }
55         apply_swizzle();
56 }
57
58 void Texture2DMultisample::image(const Graphics::Image &, unsigned)
59 {
60         throw invalid_operation("Texture2DMultisample::image");
61 }
62
63 uint64_t Texture2DMultisample::get_data_size() const
64 {
65         return id ? width*height*get_pixel_size(format)*samples : 0;
66 }
67
68 } // namespace GL
69 } // namespace Msp