X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture1d_backend.cpp;h=aa9e1f298f9f5a9a407ccc9b24262762bf86ac8f;hb=HEAD;hp=e44ceb4e757d6efefc4b54414d396894d8a9f019;hpb=160e9eea29bd10034733d59507fa1bcca36be401;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture1d_backend.cpp b/source/backends/opengl/texture1d_backend.cpp index e44ceb4e..aa9e1f29 100644 --- a/source/backends/opengl/texture1d_backend.cpp +++ b/source/backends/opengl/texture1d_backend.cpp @@ -16,29 +16,31 @@ OpenGLTexture1D::OpenGLTexture1D(): void OpenGLTexture1D::allocate() { - unsigned width = static_cast(this)->width; - unsigned levels = static_cast(this)->levels; + const Texture1D &self = *static_cast(this); + + if(!id) + create(); GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { if(ARB_direct_state_access) - glTextureStorage1D(id, levels, gl_fmt, width); + glTextureStorage1D(id, n_levels, gl_fmt, self.width); else { bind_scratch(); - glTexStorage1D(target, levels, gl_fmt, width); + glTexStorage1D(target, n_levels, gl_fmt, self.width); } } else { bind_scratch(); - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, n_levels-1); GLenum comp = get_gl_components(get_components(storage_fmt)); GLenum type = get_gl_type(get_component_type(storage_fmt)); - for(unsigned i=0; i(this)->get_level_size(i); + unsigned lv_size = self.get_level_size(i); glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0); } } @@ -59,5 +61,19 @@ void OpenGLTexture1D::sub_image(unsigned level, int x, unsigned wd, const void * } } +size_t OpenGLTexture1D::get_data_size() const +{ + if(!id) + return 0; + + const Texture1D &self = *static_cast(this); + + size_t level_size = self.width*get_pixel_size(storage_fmt); + size_t total_size = level_size; + for(unsigned i=0; i>=2) + total_size += level_size; + return total_size; +} + } // namespace GL } // namespace Msp