]> git.tdb.fi Git - libs/gl.git/blobdiff - source/vertexsetup.cpp
Require vertex arrays to have a buffer when adding them to VertexSetup
[libs/gl.git] / source / vertexsetup.cpp
index 8465ab060d54fe77041106a2c3c67a342102116e..7cfc1b6d99499c34ba3831f63495cc109921dba5 100644 (file)
@@ -6,10 +6,13 @@
 #include <msp/gl/extensions/arb_vertex_buffer_object.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
 #include "buffer.h"
+#include "error.h"
 #include "gl.h"
 #include "vertexarray.h"
 #include "vertexsetup.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -35,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);
 }
@@ -42,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);
@@ -124,8 +135,14 @@ void VertexSetup::update_vertex_array(const VertexArray &array, unsigned binding
 
 void VertexSetup::bind() const
 {
+       if(!vertex_array || !index_buffer)
+               throw invalid_operation("VertexSetup::bind");
+
        if(set_current(this))
        {
+               vertex_array->refresh();
+               if(inst_array)
+                       inst_array->refresh();
                glBindVertexArray(id);
                if(dirty)
                {