]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexsetup.cpp
Refactor writing files in the Blender exporter
[libs/gl.git] / source / vertexsetup.cpp
index 53f825697b34b16444e783cfb32262361d10fc4f..19edfb39e4a6da0b2ddfe6a0d5566d8d27c56254 100644 (file)
@@ -11,6 +11,8 @@
 #include "vertexarray.h"
 #include "vertexsetup.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -36,6 +38,9 @@ VertexSetup::~VertexSetup()
 
 void VertexSetup::set_vertex_array(const VertexArray &a)
 {
+       if(!a.get_buffer())
+               throw invalid_argument("VertexSetup::set_vertex_array");
+
        vertex_array = &a;
        update(VERTEX_ARRAY);
 }
@@ -43,7 +48,12 @@ void VertexSetup::set_vertex_array(const VertexArray &a)
 void VertexSetup::set_instance_array(const VertexArray *a)
 {
        if(a)
+       {
+               if(!a->get_buffer())
+                       throw invalid_argument("VertexSetup::set_instance_array");
+
                static Require req(ARB_instanced_arrays);
+       }
 
        inst_array = a;
        update(INSTANCE_ARRAY);
@@ -116,7 +126,8 @@ void VertexSetup::update_vertex_array(const VertexArray &array, unsigned binding
                                glVertexAttribPointer(t, 4, GL_UNSIGNED_BYTE, true, stride, reinterpret_cast<unsigned char *>(offset));
                        else
                                glVertexAttribPointer(t, sz, GL_FLOAT, false, stride, reinterpret_cast<float *>(offset));
-                       glVertexAttribDivisor(t, divisor);
+                       if(ARB_instanced_arrays)
+                               glVertexAttribDivisor(t, divisor);
                        glEnableVertexAttribArray(t);
                }
                offset += sz*sizeof(float);
@@ -130,6 +141,9 @@ void VertexSetup::bind() const
 
        if(set_current(this))
        {
+               vertex_array->refresh();
+               if(inst_array)
+                       inst_array->refresh();
                glBindVertexArray(id);
                if(dirty)
                {