#include <msp/strings/lexicalcast.h>
#include <msp/strings/utils.h>
#include "error.h"
-#include "misc.h"
#include "vertexformat.h"
-#include <msp/gl/extensions/arb_vertex_shader.h>
using namespace std;
else if(attr<GENERIC1 || attr>GENERIC4)
throw invalid_argument("make_indexed_attribute");
- static int max_attribs = -1;
- if(max_attribs<0)
- max_attribs = get_i(GL_MAX_VERTEX_ATTRIBS);
-
- if(static_cast<int>((base>>3)+index)>=max_attribs)
+ if(static_cast<int>((base>>3)+index)>=31)
throw out_of_range("make_indexed_attribute");
return static_cast<VertexAttribute>(base+index*8);
#include "buffer.h"
#include "error.h"
#include "gl.h"
+#include "misc.h"
#include "vertexarray.h"
#include "vertexsetup.h"
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;
{
if(a)
{
- if(!a->get_buffer())
+ if(!verify_array(*a))
throw invalid_argument("VertexSetup::set_instance_array");
static Require req(ARB_instanced_arrays);
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<int>(get_attribute_semantic(*a))>=max_attribs)
+ return false;
+
+ return true;
+}
+
unsigned VertexSetup::get_attribs(const VertexFormat &fmt)
{
unsigned mask = 0;
const Buffer *get_index_buffer() const { return index_buffer; }
private:
+ static bool verify_array(const VertexArray &);
static unsigned get_attribs(const VertexFormat &);
static unsigned get_update_mask(unsigned, const VertexFormat &, const VertexArray &);
void update(unsigned) const;