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 const Texture1D &self = *static_cast<const Texture1D *>(this);
24 GLenum gl_fmt = get_gl_pixelformat(storage_fmt);
25 if(ARB_texture_storage)
27 if(ARB_direct_state_access)
28 glTextureStorage1D(id, n_levels, gl_fmt, self.width);
32 glTexStorage1D(target, n_levels, gl_fmt, self.width);
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)
43 unsigned lv_size = self.get_level_size(i);
44 glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
51 void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void *data)
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);
60 glTexSubImage1D(target, level, x, wd, comp, type, data);
64 size_t OpenGLTexture1D::get_data_size() const
69 const Texture1D &self = *static_cast<const Texture1D *>(this);
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;