#include <vector>
#include "programdata.h"
#include "renderable.h"
+#include "vertexarray.h"
+#include "vertexsetup.h"
namespace Msp {
namespace GL {
class Buffer;
class Object;
class ObjectInstance;
-class VertexArray;
-class VertexSetup;
/**
-Renders multiple instances of an Object in an efficient manner. If instanced
-rendering is supported, only one draw call per Batch needs to be issued.
+Renders multiple instances of an Object in an efficient manner.
-Changing the Mesh of the Object while an InstanceArray exists is not supported.
+The instance specific transform is passed to the shader in an attribute with
+the name instance_transform. The attribute should have the type vec4[3]. Each
+elements of the array corresponds to a row of the transform matrix.
+
+If the Mesh or Technique of the Object is changed during the lifetime of the
+InstanceArray, behaviour is undefined.
*/
class InstanceArray: public Renderable
{
private:
const Object &object;
std::vector<ObjectInstance *> instances;
- VertexArray *instance_data;
- Buffer *instance_buffer;
- VertexSetup *vtx_setup;
- int matrix_location;
- unsigned matrix_offset;
+ VertexArray instance_data;
+ Buffer *instance_buffer = 0;
+ VertexSetup vtx_setup;
+ int matrix_location = -1;
+ unsigned matrix_offset = 0;
public:
InstanceArray(const Object &);
void set_matrix_attribute(const std::string &);
+ /** Adds a new instance to the array. The instance class must have a
+ constructor taking a const reference to Object as its sole parameter. */
template<typename T = ObjectInstance>
T &append();
private:
public:
void remove(ObjectInstance &);
- virtual void render(Renderer &, const Tag &) const;
+ virtual void render(Renderer &, Tag) const;
};
template<typename T>