]> git.tdb.fi Git - libs/gl.git/commitdiff
Adjust access to main class members from backend classes
authorMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 14:49:52 +0000 (16:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 17 Nov 2021 14:49:52 +0000 (16:49 +0200)
source/backends/opengl/framebuffer_backend.cpp
source/backends/opengl/pipelinestate_backend.cpp
source/backends/opengl/sampler_backend.cpp
source/backends/opengl/texture1d_backend.cpp
source/backends/opengl/texture2d_backend.cpp
source/backends/opengl/texture2dmultisample_backend.cpp
source/backends/opengl/texture3d_backend.cpp
source/backends/opengl/texturecube_backend.cpp
source/backends/opengl/vertexsetup_backend.cpp

index de8a9c6eabd2274cceb83b7c087b570b06149d16..18566ac3c2553fd82ea1dd71ab735dc0f3cd3168 100644 (file)
@@ -76,23 +76,24 @@ void OpenGLFramebuffer::require_layered()
 
 void OpenGLFramebuffer::resize_system(unsigned w, unsigned h)
 {
-       Framebuffer *self = static_cast<Framebuffer *>(this);
-       self->width = w;
-       self->height = h;
+       Framebuffer &self = *static_cast<Framebuffer *>(this);
+       self.width = w;
+       self.height = h;
 }
 
 void OpenGLFramebuffer::update(unsigned mask) const
 {
-       const FrameFormat &format = static_cast<const Framebuffer *>(this)->format;
+       const Framebuffer &self = *static_cast<const Framebuffer *>(this);
+
        vector<GLenum> color_bufs;
-       color_bufs.reserve(format.size());
+       color_bufs.reserve(self.format.size());
        unsigned i = 0;
-       for(FrameAttachment a: format)
+       for(FrameAttachment a: self.format)
        {
                GLenum gl_attach_point = get_gl_attachment(a);
                if(mask&(1<<i))
                {
-                       const Framebuffer::Attachment &attch = static_cast<const Framebuffer *>(this)->attachments[i];
+                       const Framebuffer::Attachment &attch = self.attachments[i];
                        if(attch.tex)
                        {
                                if(ARB_direct_state_access)
index 91789701705d31441a55864f80a4e337d84cfdae..7cd654008d524f38c4d75c495959e54419a9faa0 100644 (file)
@@ -56,11 +56,11 @@ void OpenGLPipelineState::apply() const
 
 void OpenGLPipelineState::apply(unsigned mask) const
 {
-       const PipelineState *self = static_cast<const PipelineState *>(this);
+       const PipelineState &self = *static_cast<const PipelineState *>(this);
 
        if(mask&PipelineState::FRAMEBUFFER)
        {
-               const Framebuffer *framebuffer = self->framebuffer;
+               const Framebuffer *framebuffer = self.framebuffer;
                glBindFramebuffer(GL_FRAMEBUFFER, framebuffer ? framebuffer->id : 0);
                if(framebuffer)
                {
@@ -71,15 +71,15 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&(PipelineState::VIEWPORT|PipelineState::FRAMEBUFFER))
        {
-               if(const Rect *viewport = self->viewport)
+               if(const Rect *viewport = self.viewport)
                        glViewport(viewport->left, viewport->bottom, viewport->width, viewport->height);
-               else if(const Framebuffer *framebuffer = self->framebuffer)
+               else if(const Framebuffer *framebuffer = self.framebuffer)
                        glViewport(0, 0, framebuffer->get_width(), framebuffer->get_height());
        }
 
        if(mask&PipelineState::SCISSOR)
        {
-               if(const Rect *scissor = self->scissor)
+               if(const Rect *scissor = self.scissor)
                {
                        glEnable(GL_SCISSOR_TEST);
                        glScissor(scissor->left, scissor->bottom, scissor->width, scissor->height);
@@ -90,9 +90,9 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::SHPROG)
        {
-               glUseProgram(self->shprog ? self->shprog->id : 0);
+               glUseProgram(self.shprog ? self.shprog->id : 0);
 
-               unsigned ncd = (self->shprog ? self->shprog->get_n_clip_distances() : 0);
+               unsigned ncd = (self.shprog ? self.shprog->get_n_clip_distances() : 0);
                if(ncd!=n_clip_distances)
                {
                        for(unsigned i=0; (i<ncd || i<n_clip_distances); ++i)
@@ -108,7 +108,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::UNIFORMS)
        {
-               for(const PipelineState::BoundUniformBlock &u: self->uniform_blocks)
+               for(const PipelineState::BoundUniformBlock &u: self.uniform_blocks)
                        if(u.changed || mask==~0U)
                        {
                                if(u.block)
@@ -118,10 +118,10 @@ void OpenGLPipelineState::apply(unsigned mask) const
                                                glBindBufferRange(GL_UNIFORM_BUFFER, u.binding, u.block->get_buffer()->id, u.block->get_offset(), u.block->get_data_size());
                                                bound_uniform_blocks[u.binding] = 1;
                                        }
-                                       else if(self->shprog)
+                                       else if(self.shprog)
                                        {
                                                const char *data = static_cast<const char *>(u.block->get_data_pointer());
-                                               for(const Program::UniformCall &call: self->shprog->uniform_calls)
+                                               for(const Program::UniformCall &call: self.shprog->uniform_calls)
                                                        call.func(call.location, call.size, data+call.location*16);
                                        }
                                }
@@ -132,7 +132,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::TEXTURES)
        {
-               for(const PipelineState::BoundTexture &t: self->textures)
+               for(const PipelineState::BoundTexture &t: self.textures)
                        if(t.changed || mask==~0U)
                        {
                                if(t.texture && t.sampler)
@@ -159,7 +159,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::VERTEX_SETUP)
        {
-               const VertexSetup *vertex_setup = self->vertex_setup;
+               const VertexSetup *vertex_setup = self.vertex_setup;
                glBindVertexArray(vertex_setup ? vertex_setup->id : 0);
                if(vertex_setup)
                {
@@ -179,12 +179,12 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::FACE_CULL)
        {
-               glFrontFace(self->front_face==CLOCKWISE ? GL_CW : GL_CCW);
+               glFrontFace(self.front_face==CLOCKWISE ? GL_CW : GL_CCW);
 
-               if(self->face_cull!=NO_CULL && self->front_face!=NON_MANIFOLD)
+               if(self.face_cull!=NO_CULL && self.front_face!=NON_MANIFOLD)
                {
                        glEnable(GL_CULL_FACE);
-                       glCullFace(self->face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
+                       glCullFace(self.face_cull==CULL_FRONT ? GL_FRONT : GL_BACK);
                }
                else
                        glDisable(GL_CULL_FACE);
@@ -192,7 +192,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::DEPTH_TEST)
        {
-               const DepthTest *depth_test = self->depth_test;
+               const DepthTest *depth_test = self.depth_test;
                if(depth_test && depth_test->enabled)
                {
                        glEnable(GL_DEPTH_TEST);
@@ -206,7 +206,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::STENCIL_TEST)
        {
-               const StencilTest *stencil_test = self->stencil_test;
+               const StencilTest *stencil_test = self.stencil_test;
                if(stencil_test && stencil_test->enabled)
                {
                        glEnable(GL_STENCIL_TEST);
@@ -219,7 +219,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
 
        if(mask&PipelineState::BLEND)
        {
-               const Blend *blend = self->blend;
+               const Blend *blend = self.blend;
                if(blend && blend->enabled)
                {
                        glEnable(GL_BLEND);
@@ -237,7 +237,7 @@ void OpenGLPipelineState::apply(unsigned mask) const
        }
 
        last_applied = this;
-       self->changes &= ~mask;
+       self.changes &= ~mask;
 }
 
 void OpenGLPipelineState::clear()
index 8198e40feba4c20f5966c4e3a1d194611596587f..31dcc6bcf0f48b5b18a06625fc02cb5f9c3c8d33 100644 (file)
@@ -46,26 +46,26 @@ bool OpenGLSampler::check_anisotropic(bool require)
 
 void OpenGLSampler::update(unsigned mask) const
 {
-       const Sampler *self = static_cast<const Sampler *>(this);
+       const Sampler &self = *static_cast<const Sampler *>(this);
        if(mask&Sampler::MIN_FILTER)
-               glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(self->min_filter));
+               glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, get_gl_filter(self.min_filter));
        if(mask&Sampler::MAG_FILTER)
-               glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, get_gl_filter(self->mag_filter));
+               glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, get_gl_filter(self.mag_filter));
        if(mask&Sampler::MAX_ANISOTROPY)
-               glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, self->max_anisotropy);
+               glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, self.max_anisotropy);
        if(mask&Sampler::WRAP_S)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_S, get_gl_wrap(self->wrap_s));
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_S, get_gl_wrap(self.wrap_s));
        if(mask&Sampler::WRAP_T)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(self->wrap_t));
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_T, get_gl_wrap(self.wrap_t));
        if(mask&Sampler::WRAP_R)
-               glSamplerParameteri(id, GL_TEXTURE_WRAP_R, get_gl_wrap(self->wrap_r));
+               glSamplerParameteri(id, GL_TEXTURE_WRAP_R, get_gl_wrap(self.wrap_r));
        if(mask&Sampler::BORDER_COLOR)
-               glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &self->border_color.r);
+               glSamplerParameterfv(id, GL_TEXTURE_BORDER_COLOR, &self.border_color.r);
        if(mask&Sampler::COMPARE)
        {
-               glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (self->compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
-               if(self->compare)
-                       glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, get_gl_predicate(self->cmp_func));
+               glSamplerParameteri(id, GL_TEXTURE_COMPARE_MODE, (self.compare ? GL_COMPARE_R_TO_TEXTURE : GL_NONE));
+               if(self.compare)
+                       glSamplerParameteri(id, GL_TEXTURE_COMPARE_FUNC, get_gl_predicate(self.cmp_func));
        }
 }
 
index b8424872b37c3ee960801bfda52eddd4f4185611..8e33d278984ca06c8f81c4222e01717d195b5b55 100644 (file)
@@ -16,8 +16,7 @@ OpenGLTexture1D::OpenGLTexture1D():
 
 void OpenGLTexture1D::allocate()
 {
-       unsigned width = static_cast<const Texture1D *>(this)->width;
-       unsigned levels = static_cast<const Texture1D *>(this)->levels;
+       const Texture1D &self = *static_cast<const Texture1D *>(this);
 
        if(!id)
                create();
@@ -26,22 +25,22 @@ void OpenGLTexture1D::allocate()
        if(ARB_texture_storage)
        {
                if(ARB_direct_state_access)
-                       glTextureStorage1D(id, levels, gl_fmt, width);
+                       glTextureStorage1D(id, self.levels, gl_fmt, self.width);
                else
                {
                        bind_scratch();
-                       glTexStorage1D(target, levels, gl_fmt, width);
+                       glTexStorage1D(target, self.levels, gl_fmt, self.width);
                }
        }
        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)
                {
-                       unsigned lv_size = static_cast<const Texture1D *>(this)->get_level_size(i);
+                       unsigned lv_size = self.get_level_size(i);
                        glTexImage1D(target, i, gl_fmt, lv_size, 0, comp, type, 0);
                }
        }
@@ -67,12 +66,11 @@ size_t OpenGLTexture1D::get_data_size() const
        if(!id)
                return 0;
 
-       unsigned width = static_cast<const Texture1D *>(this)->width;
-       unsigned levels = static_cast<const Texture1D *>(this)->levels;
+       const Texture1D &self = *static_cast<const Texture1D *>(this);
 
-       size_t level_size = width*get_pixel_size(storage_fmt);
+       size_t level_size = self.width*get_pixel_size(storage_fmt);
        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;
 }
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;
 }
index e6ee7614b028b88c1c56ea1e11a78e3ead733598..f0675044b23cdb6b8fcf72dacf86bdb7b79f885d 100644 (file)
@@ -15,9 +15,7 @@ OpenGLTexture2DMultisample::OpenGLTexture2DMultisample():
 
 void OpenGLTexture2DMultisample::allocate()
 {
-       unsigned width = static_cast<const Texture2DMultisample *>(this)->width;
-       unsigned height = static_cast<const Texture2DMultisample *>(this)->height;
-       unsigned samples = static_cast<const Texture2DMultisample *>(this)->samples;
+       const Texture2DMultisample &self = *static_cast<const Texture2DMultisample *>(this);
 
        if(!id)
                create();
@@ -26,27 +24,25 @@ void OpenGLTexture2DMultisample::allocate()
        if(ARB_texture_storage_multisample)
        {
                if(ARB_direct_state_access)
-                       glTextureStorage2DMultisample(id, samples, gl_fmt, width, height, false);
+                       glTextureStorage2DMultisample(id, self.samples, gl_fmt, self.width, self.height, false);
                else
                {
                        bind_scratch();
-                       glTexStorage2DMultisample(target, samples, gl_fmt, width, height, false);
+                       glTexStorage2DMultisample(target, self.samples, gl_fmt, self.width, self.height, false);
                }
        }
        else
        {
                bind_scratch();
-               glTexImage2DMultisample(target, samples, gl_fmt, width, height, false);
+               glTexImage2DMultisample(target, self.samples, gl_fmt, self.width, self.height, false);
        }
        apply_swizzle();
 }
 
 size_t OpenGLTexture2DMultisample::get_data_size() const
 {
-       unsigned width = static_cast<const Texture2DMultisample *>(this)->width;
-       unsigned height = static_cast<const Texture2DMultisample *>(this)->height;
-       unsigned samples = static_cast<const Texture2DMultisample *>(this)->samples;
-       return width*height*get_pixel_size(format)*samples;
+       const Texture2DMultisample &self = *static_cast<const Texture2DMultisample *>(this);
+       return self.width*self.height*get_pixel_size(format)*self.samples;
 }
 
 } // namespace GL
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;
 }
index 1cc3f8377f23eaf3027d8e54caeb58f83dbefd7b..142e343dd9984bb881148ee3dd66739c9cddf3e3 100644 (file)
@@ -28,8 +28,7 @@ OpenGLTextureCube::OpenGLTextureCube():
 
 void OpenGLTextureCube::allocate()
 {
-       unsigned size = static_cast<const TextureCube *>(this)->size;
-       unsigned levels = static_cast<const TextureCube *>(this)->levels;
+       const TextureCube &self = *static_cast<const TextureCube *>(this);
 
        if(!id)
                create();
@@ -38,11 +37,11 @@ void OpenGLTextureCube::allocate()
        if(ARB_texture_storage)
        {
                if(ARB_direct_state_access)
-                       glTextureStorage2D(id, levels, gl_fmt, size, size);
+                       glTextureStorage2D(id, self.levels, gl_fmt, self.size, self.size);
                else
                {
                        bind_scratch();
-                       glTexStorage2D(target, levels, gl_fmt, size, size);
+                       glTexStorage2D(target, self.levels, gl_fmt, self.size, self.size);
                }
        }
        else
@@ -50,13 +49,13 @@ void OpenGLTextureCube::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)
                {
                        unsigned lv_size = static_cast<const TextureCube *>(this)->get_level_size(i);
                        for(unsigned j=0; j<6; ++j)
                                glTexImage2D(get_gl_cube_face(j), i, gl_fmt, lv_size, lv_size, 0, comp, type, 0);
                }
-               glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels-1);
+               glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, self.levels-1);
        }
 
        apply_swizzle();
@@ -80,12 +79,11 @@ size_t OpenGLTextureCube::get_data_size() const
        if(!id)
                return 0;
 
-       unsigned size = static_cast<const TextureCube *>(this)->size;
-       unsigned levels = static_cast<const TextureCube *>(this)->levels;
+       const TextureCube &self = *static_cast<const TextureCube *>(this);
 
-       size_t level_size = size*size*get_pixel_size(storage_fmt);
+       size_t level_size = self.size*self.size*get_pixel_size(storage_fmt);
        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;
 }
index f3243107b9591186b649a298fe9f7234c7b46355..6dc97411113a21bd0d3d9aae9ca0292415c7d243 100644 (file)
@@ -51,15 +51,17 @@ void OpenGLVertexSetup::update(unsigned mask) const
 {
        static bool direct = ARB_direct_state_access && ARB_vertex_attrib_binding;
 
+       const VertexSetup &self = *static_cast<const VertexSetup *>(this);
+
        if(mask&VertexSetup::VERTEX_ARRAY)
-               update_vertex_array(*static_cast<const VertexSetup *>(this)->vertex_array, 0, 0, direct);
+               update_vertex_array(*self.vertex_array, 0, 0, direct);
 
        if(mask&VertexSetup::INSTANCE_ARRAY)
-               update_vertex_array(*static_cast<const VertexSetup *>(this)->inst_array, 1, 1, direct);
+               update_vertex_array(*self.inst_array, 1, 1, direct);
 
        if(mask&VertexSetup::INDEX_BUFFER)
        {
-               unsigned buf_id = static_cast<const VertexSetup *>(this)->index_buffer->id;
+               unsigned buf_id = self.index_buffer->id;
                if(direct)
                        glVertexArrayElementBuffer(id, buf_id);
                else
@@ -129,17 +131,19 @@ void OpenGLVertexSetup::unload()
        }
        else
        {
+               const VertexSetup &self = *static_cast<const VertexSetup *>(this);
+
                glBindVertexArray(id);
                glBindBuffer(GL_ARRAY_BUFFER, 0);
 
-               for(VertexAttribute a: static_cast<const VertexSetup *>(this)->vertex_format)
+               for(VertexAttribute a: self.vertex_format)
                        if(!is_padding(a))
                        {
                                unsigned sem = get_attribute_semantic(a);
                                glDisableVertexAttribArray(sem);
                                glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
                        }
-               for(VertexAttribute a: static_cast<const VertexSetup *>(this)->inst_format)
+               for(VertexAttribute a: self.inst_format)
                        if(!is_padding(a))
                        {
                                unsigned sem = get_attribute_semantic(a);