]> git.tdb.fi Git - libs/gl.git/blobdiff - source/backends/opengl/vertexsetup_backend.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / backends / opengl / vertexsetup_backend.cpp
index 90189db7227eba94575f99a27fc98ab39e234843..6dc97411113a21bd0d3d9aae9ca0292415c7d243 100644 (file)
@@ -27,9 +27,16 @@ OpenGLVertexSetup::OpenGLVertexSetup()
                glGenVertexArrays(1, &id);
 }
 
+OpenGLVertexSetup::OpenGLVertexSetup(OpenGLVertexSetup &&other):
+       id(other.id)
+{
+       other.id = 0;
+}
+
 OpenGLVertexSetup::~OpenGLVertexSetup()
 {
-       glDeleteVertexArrays(1, &id);
+       if(id)
+               glDeleteVertexArrays(1, &id);
 }
 
 void OpenGLVertexSetup::require_format(const VertexFormat &fmt, bool instanced)
@@ -44,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
@@ -76,31 +85,34 @@ void OpenGLVertexSetup::update_vertex_array(const VertexArray &array, unsigned b
                glVertexArrayBindingDivisor(id, binding, divisor);
        }
 
-       unsigned offset = 0;
+       unsigned offset = array.get_offset();
        for(VertexAttribute a: fmt)
        {
                unsigned sem = get_attribute_semantic(a);
-               bool integer = is_integer_attribute(a);
-               GLenum type = get_gl_type(get_attribute_source_type(a));
-               unsigned cc = get_attribute_component_count(a);
-               if(direct)
-               {
-                       if(integer)
-                               glVertexArrayAttribIFormat(id, sem, cc, type, offset);
-                       else
-                               glVertexArrayAttribFormat(id, sem, cc, type, true, offset);
-                       glVertexArrayAttribBinding(id, sem, binding);
-                       glEnableVertexArrayAttrib(id, sem);
-               }
-               else
+               if(!is_padding(a))
                {
-                       if(integer)
-                               glVertexAttribIPointer(sem, cc, type, stride, reinterpret_cast<void *>(offset));
+                       bool integer = is_integer_attribute(a);
+                       GLenum type = get_gl_type(get_attribute_source_type(a));
+                       unsigned cc = get_attribute_component_count(a);
+                       if(direct)
+                       {
+                               if(integer)
+                                       glVertexArrayAttribIFormat(id, sem, cc, type, offset);
+                               else
+                                       glVertexArrayAttribFormat(id, sem, cc, type, true, offset);
+                               glVertexArrayAttribBinding(id, sem, binding);
+                               glEnableVertexArrayAttrib(id, sem);
+                       }
                        else
-                               glVertexAttribPointer(sem, cc, type, true, stride, reinterpret_cast<void *>(offset));
-                       if(ARB_instanced_arrays)
-                               glVertexAttribDivisor(sem, divisor);
-                       glEnableVertexAttribArray(sem);
+                       {
+                               if(integer)
+                                       glVertexAttribIPointer(sem, cc, type, stride, reinterpret_cast<void *>(offset));
+                               else
+                                       glVertexAttribPointer(sem, cc, type, true, stride, reinterpret_cast<void *>(offset));
+                               if(ARB_instanced_arrays)
+                                       glVertexAttribDivisor(sem, divisor);
+                               glEnableVertexAttribArray(sem);
+                       }
                }
                offset += get_attribute_size(a);
        }
@@ -119,21 +131,25 @@ 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)
-               {
-                       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)
-               {
-                       unsigned sem = get_attribute_semantic(a);
-                       glDisableVertexAttribArray(sem);
-                       glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
-               }
+               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: self.inst_format)
+                       if(!is_padding(a))
+                       {
+                               unsigned sem = get_attribute_semantic(a);
+                               glDisableVertexAttribArray(sem);
+                               glVertexAttribPointer(sem, 1, GL_FLOAT, false, 0, 0);
+                       }
 
                glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
        }