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