X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fvertexsetup.cpp;h=4b2e2a5f0e5b8d3ccfb1bb435772f58557c15efb;hb=82282de52e8e8f3bbafefaf92bf76f53f2c2495e;hp=0cbe9a921a3dce33fc9190fbec59abc33654c719;hpb=68b74ce23dd20822b07d79dc25aa0a0a19ef27a5;p=libs%2Fgl.git diff --git a/source/core/vertexsetup.cpp b/source/core/vertexsetup.cpp index 0cbe9a92..4b2e2a5f 100644 --- a/source/core/vertexsetup.cpp +++ b/source/core/vertexsetup.cpp @@ -5,9 +5,11 @@ #include #include #include +#include #include "buffer.h" #include "error.h" #include "gl.h" +#include "misc.h" #include "vertexarray.h" #include "vertexsetup.h" @@ -38,7 +40,7 @@ VertexSetup::~VertexSetup() void VertexSetup::set_vertex_array(const VertexArray &a) { - if(!a.get_buffer()) + if(!verify_array(a)) throw invalid_argument("VertexSetup::set_vertex_array"); vertex_array = &a; @@ -50,7 +52,7 @@ void VertexSetup::set_instance_array(const VertexArray *a) { if(a) { - if(!a->get_buffer()) + if(!verify_array(*a)) throw invalid_argument("VertexSetup::set_instance_array"); static Require req(ARB_instanced_arrays); @@ -76,6 +78,23 @@ void VertexSetup::refresh() set_instance_array(inst_array); } +bool VertexSetup::verify_array(const VertexArray &array) +{ + if(!array.get_buffer()) + return false; + + static int max_attribs = -1; + if(max_attribs<0) + max_attribs = get_i(GL_MAX_VERTEX_ATTRIBS); + + const VertexFormat &fmt = array.get_format(); + for(const unsigned char *a=fmt.begin(); a!=fmt.end(); ++a) + if(static_cast(get_attribute_semantic(*a))>=max_attribs) + return false; + + return true; +} + unsigned VertexSetup::get_attribs(const VertexFormat &fmt) { unsigned mask = 0; @@ -191,5 +210,15 @@ void VertexSetup::unbind() glBindVertexArray(0); } +void VertexSetup::set_debug_name(const string &name) +{ +#ifdef DEBUG + if(KHR_debug) + glObjectLabel(GL_VERTEX_ARRAY, id, name.size(), name.c_str()); +#else + (void)name; +#endif +} + } // namespace GL } // namespace Msp