]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/texture1d_backend.cpp
Allow a push constant block to be specified, but flatten it for now
[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         unsigned width = static_cast<const Texture1D *>(this)->width;
20         unsigned levels = static_cast<const Texture1D *>(this)->levels;
21
22         if(!id)
23                 create();
24
25         GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
26         if(ARB_texture_storage)
27         {
28                 if(ARB_direct_state_access)
29                         glTextureStorage1D(id, levels, gl_fmt, width);
30                 else
31                 {
32                         bind_scratch();
33                         glTexStorage1D(target, levels, gl_fmt, width);
34                 }
35         }
36         else
37         {
38                 bind_scratch();
39                 glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
40                 GLenum comp = get_gl_components(get_components(storage_fmt));
41                 GLenum type = get_gl_type(get_component_type(storage_fmt));
42                 for(unsigned i=0; i<levels; ++i)
43                 {
44                         unsigned lv_size = static_cast<const Texture1D *>(this)->get_level_size(i);
45                         glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
46                 }
47         }
48
49         apply_swizzle();
50 }
51
52 void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
53 {
54         GLenum comp = get_gl_components(get_components(storage_fmt));
55         GLenum type = get_gl_type(get_component_type(storage_fmt));
56         if(ARB_direct_state_access)
57                 glTextureSubImage1D(id, level, x, wd, comp, type, data);
58         else
59         {
60                 bind_scratch();
61                 glTexSubImage1D(target, level, x, wd, comp, type, data);
62         }
63 }
64
65 } // namespace GL
66 } // namespace Msp