X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fvertexsetup.cpp;h=19edfb39e4a6da0b2ddfe6a0d5566d8d27c56254;hb=c89b596e05705f9a23f6c5cdf0b98ffd5f8f273c;hp=8465ab060d54fe77041106a2c3c67a342102116e;hpb=b0059bd068c99dadfc922584911fcb25a21b737b;p=libs%2Fgl.git diff --git a/source/vertexsetup.cpp b/source/vertexsetup.cpp index 8465ab06..19edfb39 100644 --- a/source/vertexsetup.cpp +++ b/source/vertexsetup.cpp @@ -6,10 +6,13 @@ #include #include #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); @@ -115,7 +126,8 @@ void VertexSetup::update_vertex_array(const VertexArray &array, unsigned binding glVertexAttribPointer(t, 4, GL_UNSIGNED_BYTE, true, stride, reinterpret_cast(offset)); else glVertexAttribPointer(t, sz, GL_FLOAT, false, stride, reinterpret_cast(offset)); - glVertexAttribDivisor(t, divisor); + if(ARB_instanced_arrays) + glVertexAttribDivisor(t, divisor); glEnableVertexAttribArray(t); } offset += sz*sizeof(float); @@ -124,8 +136,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) {