]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexarray.cpp
Move vertex buffer management from VertexArray to Mesh
[libs/gl.git] / source / vertexarray.cpp
index 9d8e4477b0ab5a4e3008c72b4f048de2b9d213f7..3fca527d75aee2dba990a176a2415f514a537f92 100644 (file)
@@ -1,5 +1,5 @@
-#include "arb_multitexture.h"
-#include "arb_vertex_shader.h"
+#include <msp/gl/extensions/arb_multitexture.h>
+#include <msp/gl/extensions/arb_vertex_shader.h>
 #include "buffer.h"
 #include "error.h"
 #include "gl.h"
@@ -11,7 +11,6 @@ namespace Msp {
 namespace GL {
 
 VertexArray::VertexArray(const VertexFormat &f):
-       defer_vbuf(true),
        dirty(false)
 {
        reset(f);
@@ -76,21 +75,9 @@ unsigned VertexArray::get_array_slot(unsigned char comp)
        }
 }
 
-void VertexArray::use_vertex_buffer()
-{
-       if(vbuf)
-               return;
-
-       vbuf = new Buffer(ARRAY_BUFFER);
-       defer_vbuf = false;
-       dirty = true;
-}
-
 void VertexArray::use_vertex_buffer(Buffer *b)
 {
        vbuf = b;
-       vbuf.keep();
-       defer_vbuf = false;
        dirty = true;
 }
 
@@ -120,11 +107,6 @@ float *VertexArray::modify(unsigned i)
 void VertexArray::set_dirty()
 {
        dirty = true;
-       if(defer_vbuf)
-       {
-               vbuf = new Buffer(ARRAY_BUFFER);
-               defer_vbuf = false;
-       }
 }
 
 void VertexArray::apply() const
@@ -133,7 +115,11 @@ void VertexArray::apply() const
                throw invalid_operation("VertexArray::apply");
 
        const VertexArray *old = current();
-       if(!set_current(this))
+       /* If the array has been modified, apply it even if it was the last one to
+       be applied.  This is necessary to get the data updated to vertex buffer, and
+       to resync things after a format change.  Radeon drivers also have some
+       problems with modifying vertex arrays without re-setting the pointers. */
+       if(!set_current(this) && !dirty)
                return;
 
        if(vbuf)