]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/texture3d_backend.cpp
Adjust access to main class members from backend classes
[libs/gl.git] / source / backends / opengl / texture3d_backend.cpp
index 961dd7e721766596f439312c45d11348e4eaebc7..f446e653cfc4a90df6cabc3ce3fe8661541de24d 100644 (file)
@@ -21,10 +21,7 @@ OpenGLTexture3D::OpenGLTexture3D(unsigned t):
 
 void OpenGLTexture3D::allocate()
 {
-       unsigned width = static_cast<const Texture3D *>(this)->width;
-       unsigned height = static_cast<const Texture3D *>(this)->height;
-       unsigned depth = static_cast<const Texture3D *>(this)->depth;
-       unsigned levels = static_cast<const Texture3D *>(this)->levels;
+       const Texture3D &self = *static_cast<const Texture3D *>(this);
 
        if(!id)
                create();
@@ -33,11 +30,11 @@ void OpenGLTexture3D::allocate()
        if(ARB_texture_storage)
        {
                if(ARB_direct_state_access)
-                       glTextureStorage3D(id, levels, gl_fmt, width, height, depth);
+                       glTextureStorage3D(id, self.levels, gl_fmt, self.width, self.height, self.depth);
                else
                {
                        bind_scratch();
-                       glTexStorage3D(target, levels, gl_fmt, width, height, depth);
+                       glTexStorage3D(target, self.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<levels; ++i)
+               for(unsigned i=0; i<self.levels; ++i)
                {
-                       auto lv_size = static_cast<const Texture3D *>(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, self.levels-1);
        }
 
        apply_swizzle();
@@ -79,14 +76,11 @@ size_t OpenGLTexture3D::get_data_size() const
        if(!id)
                return 0;
 
-       unsigned width = static_cast<const Texture3D *>(this)->width;
-       unsigned height = static_cast<const Texture3D *>(this)->height;
-       unsigned depth = static_cast<const Texture3D *>(this)->depth;
-       unsigned levels = static_cast<const Texture3D *>(this)->levels;
+       const Texture3D &self = *static_cast<const Texture3D *>(this);
 
-       size_t level_size = width*height*depth*get_pixel_size(format);
+       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<levels; ++i, level_size>>=2)
+       for(unsigned i=0; i<self.levels; ++i, level_size>>=2)
                total_size += level_size;
        return total_size;
 }