1 #ifndef MSP_GL_INSTANCEARRAY_H_
2 #define MSP_GL_INSTANCEARRAY_H_
5 #include "programdata.h"
6 #include "renderable.h"
7 #include "vertexarray.h"
8 #include "vertexsetup.h"
18 Renders multiple instances of an Object in an efficient manner. If instanced
19 rendering is supported, only one draw call per Batch needs to be issued.
21 Changing the Mesh of the Object while an InstanceArray exists is not supported.
23 class InstanceArray: public Renderable
27 class Instance: public T
34 Instance(const Object &o, InstanceArray &a, unsigned i): T(o), array(a), index(i) { }
36 virtual void set_matrix(const Matrix &);
41 std::vector<ObjectInstance *> instances;
42 VertexArray instance_data;
43 Buffer *instance_buffer;
44 VertexSetup vtx_setup;
46 unsigned matrix_offset;
49 InstanceArray(const Object &);
52 void set_matrix_attribute(const std::string &);
54 template<typename T = ObjectInstance>
57 void append(ObjectInstance *);
58 void update_instance_matrix(unsigned);
60 void remove(ObjectInstance &);
62 virtual void render(Renderer &, Tag) const;
66 T &InstanceArray::append()
68 Instance<T> *inst = new Instance<T>(object, *this, instances.size());
74 void InstanceArray::Instance<T>::set_matrix(const Matrix &m)
77 array.update_instance_matrix(index);