]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/texture2d_backend.cpp
Adjust access to main class members from backend classes
[libs/gl.git] / source / backends / opengl / texture2d_backend.cpp
index 45ba78cc8f6f10c1e4e8d3b7d372b82b148843f0..54c82280e5b1a0e3e30b0e51bc7a1da6abf28ff6 100644 (file)
@@ -41,9 +41,7 @@ OpenGLTexture2D::OpenGLTexture2D():
 
 void OpenGLTexture2D::allocate()
 {
-       unsigned width = static_cast<const Texture2D *>(this)->width;
-       unsigned height = static_cast<const Texture2D *>(this)->height;
-       unsigned levels = static_cast<const Texture2D *>(this)->levels;
+       const Texture2D &self = *static_cast<const Texture2D *>(this);
 
        if(!id)
                create();
@@ -52,22 +50,22 @@ void OpenGLTexture2D::allocate()
        if(ARB_texture_storage)
        {
                if(ARB_direct_state_access)
-                       glTextureStorage2D(id, levels, gl_fmt, width, height);
+                       glTextureStorage2D(id, self.levels, gl_fmt, self.width, self.height);
                else
                {
                        bind_scratch();
-                       glTexStorage2D(target, levels, gl_fmt, width, height);
+                       glTexStorage2D(target, self.levels, gl_fmt, self.width, self.height);
                }
        }
        else
        {
                bind_scratch();
-               glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+               glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.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<levels; ++i)
+               for(unsigned i=0; i<self.levels; ++i)
                {
-                       auto lv_size = static_cast<const Texture2D *>(this)->get_level_size(i);
+                       auto lv_size = self.get_level_size(i);
                        glTexImage2D(target, i, gl_fmt, lv_size.x, lv_size.y, 0, comp, type, 0);
                }
        }
@@ -105,13 +103,11 @@ uint64_t OpenGLTexture2D::get_data_size() const
        if(!id)
                return 0;
 
-       unsigned width = static_cast<const Texture2D *>(this)->width;
-       unsigned height = static_cast<const Texture2D *>(this)->height;
-       unsigned levels = static_cast<const Texture2D *>(this)->levels;
+       const Texture2D &self = *static_cast<const Texture2D *>(this);
 
-       size_t level_size = width*height*get_pixel_size(format);
+       size_t level_size = self.width*self.height*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;
 }