X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Finstancearray.h;h=e6f8690c68cd5b2000d25f9bb7d770f063fcc1f4;hb=e70662d7812464159f2e47f4bebb69d88f89ae93;hp=8f5c73225519a374623c818b6298cdc55a308471;hpb=5bb193f930fb8738d099d630c4d625d82c1215b5;p=libs%2Fgl.git diff --git a/source/render/instancearray.h b/source/render/instancearray.h index 8f5c7322..e6f8690c 100644 --- a/source/render/instancearray.h +++ b/source/render/instancearray.h @@ -2,6 +2,7 @@ #define MSP_GL_INSTANCEARRAY_H_ #include +#include #include "programdata.h" #include "renderable.h" #include "vertexarray.h" @@ -15,12 +16,16 @@ class Object; class ObjectInstance; /** -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 +class InstanceArray: public Renderable, public NonCopyable { public: template @@ -40,10 +45,10 @@ private: const Object &object; std::vector instances; VertexArray instance_data; - Buffer *instance_buffer; + Buffer *instance_buffer = 0; VertexSetup vtx_setup; - int matrix_location; - unsigned matrix_offset; + int matrix_location = -1; + unsigned matrix_offset = 0; public: InstanceArray(const Object &); @@ -51,6 +56,8 @@ public: 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 T &append(); private: