X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Frender%2Finstancearray.h;h=d793ce2ed229cd8159ac9fc2504c9c1d0472a854;hb=9e63512930bc7dace6dc169c65161961e5dcfcf6;hp=6a598b5854f3183e290896eb052708f32c0f98a6;hpb=233dff2a6c552e08da832496aecd88ef4f8948f1;p=libs%2Fgl.git diff --git a/source/render/instancearray.h b/source/render/instancearray.h index 6a598b58..d793ce2e 100644 --- a/source/render/instancearray.h +++ b/source/render/instancearray.h @@ -4,6 +4,8 @@ #include #include "programdata.h" #include "renderable.h" +#include "vertexarray.h" +#include "vertexsetup.h" namespace Msp { namespace GL { @@ -11,14 +13,16 @@ 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 { @@ -39,11 +43,11 @@ public: private: const Object &object; std::vector 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 &); @@ -51,6 +55,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: