]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/texture1d_backend.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / backends / opengl / texture1d_backend.cpp
1 #include <msp/gl/extensions/arb_direct_state_access.h>
2 #include <msp/gl/extensions/arb_texture_storage.h>
3 #include <msp/gl/extensions/msp_texture1d.h>
4 #include "gl.h"
5 #include "texture1d.h"
6 #include "texture1d_backend.h"
7
8 namespace Msp {
9 namespace GL {
10
11 OpenGLTexture1D::OpenGLTexture1D():
12         Texture(GL_TEXTURE_1D)
13 {
14         static Require _req(MSP_texture1D);
15 }
16
17 void OpenGLTexture1D::allocate()
18 {
19         const Texture1D &self = *static_cast<const Texture1D *>(this);
20
21         if(!id)
22                 create();
23
24         GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
25         if(ARB_texture_storage)
26         {
27                 if(ARB_direct_state_access)
28                         glTextureStorage1D(id, n_levels, gl_fmt, self.width);
29                 else
30                 {
31                         bind_scratch();
32                         glTexStorage1D(target, n_levels, gl_fmt, self.width);
33                 }
34         }
35         else
36         {
37                 bind_scratch();
38                 glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, n_levels-1);
39                 GLenum comp = get_gl_components(get_components(storage_fmt));
40                 GLenum type = get_gl_type(get_component_type(storage_fmt));
41                 for(unsigned i=0; i<n_levels; ++i)
42                 {
43                         unsigned lv_size = self.get_level_size(i);
44                         glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
45                 }
46         }
47
48         apply_swizzle();
49 }
50
51 void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
52 {
53         GLenum comp = get_gl_components(get_components(storage_fmt));
54         GLenum type = get_gl_type(get_component_type(storage_fmt));
55         if(ARB_direct_state_access)
56                 glTextureSubImage1D(id, level, x, wd, comp, type, data);
57         else
58         {
59                 bind_scratch();
60                 glTexSubImage1D(target, level, x, wd, comp, type, data);
61         }
62 }
63
64 size_t OpenGLTexture1D::get_data_size() const
65 {
66         if(!id)
67                 return 0;
68
69         const Texture1D &self = *static_cast<const Texture1D *>(this);
70
71         size_t level_size = self.width*get_pixel_size(storage_fmt);
72         size_t total_size = level_size;
73         for(unsigned i=0; i<n_levels; ++i, level_size>>=2)
74                 total_size += level_size;
75         return total_size;
76 }
77
78 } // namespace GL
79 } // namespace Msp