X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbackends%2Fopengl%2Ftexture3d_backend.cpp;h=81783850383c0db70670768e0e318b7cd8e88b13;hb=HEAD;hp=1197405ee367ff192690437f37ccca89b677000f;hpb=57ca8f2bd18525d80ed6ad5d3f72e57901162d55;p=libs%2Fgl.git diff --git a/source/backends/opengl/texture3d_backend.cpp b/source/backends/opengl/texture3d_backend.cpp index 1197405e..81783850 100644 --- a/source/backends/opengl/texture3d_backend.cpp +++ b/source/backends/opengl/texture3d_backend.cpp @@ -21,23 +21,20 @@ OpenGLTexture3D::OpenGLTexture3D(unsigned t): void OpenGLTexture3D::allocate() { - unsigned width = static_cast(this)->width; - unsigned height = static_cast(this)->height; - unsigned depth = static_cast(this)->depth; - unsigned levels = static_cast(this)->levels; + const Texture3D &self = *static_cast(this); if(!id) - generate_id(); + create(); GLenum gl_fmt = get_gl_pixelformat(storage_fmt); if(ARB_texture_storage) { if(ARB_direct_state_access) - glTextureStorage3D(id, levels, gl_fmt, width, height, depth); + glTextureStorage3D(id, n_levels, gl_fmt, self.width, self.height, self.depth); else { bind_scratch(); - glTexStorage3D(target, levels, gl_fmt, width, height, depth); + glTexStorage3D(target, n_levels, gl_fmt, self.width, self.height, self.depth); } } else @@ -45,12 +42,12 @@ void OpenGLTexture3D::allocate() bind_scratch(); 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); + auto lv_size = self.get_level_size(i); glTexImage3D(target, i, gl_fmt, lv_size.x, lv_size.y, lv_size.z, 0, comp, type, 0); } - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, n_levels-1); } apply_swizzle(); @@ -74,5 +71,19 @@ bool OpenGLTexture3D::is_array() const return target==GL_TEXTURE_2D_ARRAY; } +size_t OpenGLTexture3D::get_data_size() const +{ + if(!id) + return 0; + + const Texture3D &self = *static_cast(this); + + size_t level_size = self.width*self.height*self.depth*get_pixel_size(format); + size_t total_size = level_size; + for(unsigned i=0; i>=2) + total_size += level_size; + return total_size; +} + } // namespace GL } // namespace Msp