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>
6 #include "texture1d_backend.h"
11 OpenGLTexture1D::OpenGLTexture1D():
12 Texture(GL_TEXTURE_1D)
14 static Require _req(MSP_texture1D);
17 void OpenGLTexture1D::allocate()
19 unsigned width = static_cast<const Texture1D *>(this)->width;
20 unsigned levels = static_cast<const Texture1D *>(this)->levels;
22 GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
23 if(ARB_texture_storage)
25 if(ARB_direct_state_access)
26 glTextureStorage1D(id, levels, gl_fmt, width);
30 glTexStorage1D(target, levels, gl_fmt, width);
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)
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);
49 void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
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);
58 glTexSubImage1D(target, level, x, wd, comp, type, data);