X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Frender%2Finstancearray.cpp;h=293fa6cdad8e1ee55384df261a50f22b58997a25;hp=028af3ad1ca088e2b92eabfb9765c01a30367f6b;hb=d493917dbc215cd6ba3f8773a52a289d9f14380d;hpb=ea7832c7c1ffab00cc1168bc8c41375fdd0eae86 diff --git a/source/render/instancearray.cpp b/source/render/instancearray.cpp index 028af3ad..293fa6cd 100644 --- a/source/render/instancearray.cpp +++ b/source/render/instancearray.cpp @@ -44,17 +44,20 @@ InstanceArray::InstanceArray(const Object &o): if(ARB_vertex_array_object && ARB_instanced_arrays && ARB_draw_instanced) { - instance_data = new VertexArray((ATTRIB4,matrix_location, ATTRIB4,matrix_location+1, ATTRIB4,matrix_location+2)); + instance_data = new VertexArray((RAW_ATTRIB4,matrix_location, RAW_ATTRIB4,matrix_location+1, RAW_ATTRIB4,matrix_location+2)); const VertexFormat &fmt = instance_data->get_format(); - matrix_offset = fmt.offset(make_indexed_attribute(ATTRIB4, matrix_location)); + matrix_offset = fmt.offset((RAW_ATTRIB4,matrix_location)); - instance_buffer = new Buffer(ARRAY_BUFFER); + instance_buffer = new Buffer; instance_data->use_buffer(instance_buffer); + const Mesh *mesh = object.get_mesh(); + vtx_setup = new VertexSetup; - vtx_setup->set_vertex_array(object.get_mesh()->get_vertices()); - vtx_setup->set_index_buffer(*object.get_mesh()->get_index_buffer()); - vtx_setup->set_instance_array(instance_data); + vtx_setup->set_format_instanced(mesh->get_vertices().get_format(), fmt); + vtx_setup->set_vertex_array(mesh->get_vertices()); + vtx_setup->set_index_buffer(*mesh->get_index_buffer(), mesh->get_batches().front().get_index_type()); + vtx_setup->set_instance_array(*instance_data); } else static Require req(ARB_vertex_shader); @@ -62,7 +65,7 @@ InstanceArray::InstanceArray(const Object &o): InstanceArray::~InstanceArray() { - for(std::vector::iterator i=instances.begin(); i!=instances.end(); ++i) + for(vector::iterator i=instances.begin(); i!=instances.end(); ++i) delete *i; delete vtx_setup; delete instance_data; @@ -81,7 +84,7 @@ void InstanceArray::append(ObjectInstance *inst) if(instance_buffer->get_size()>0 && instance_buffer->get_size()use_buffer(instance_buffer); } } @@ -107,12 +110,12 @@ void InstanceArray::update_instance_matrix(unsigned index) const Matrix &m = *instances[index]->get_matrix(); - float *d = instance_data->modify(instances.size()-1); + float *d = reinterpret_cast(instance_data->modify(instances.size()-1)+matrix_offset); for(unsigned i=0; i<12; ++i) - d[matrix_offset+i] = m(i/4, i%4); + d[i] = m(i/4, i%4); } -void InstanceArray::render(Renderer &renderer, const Tag &tag) const +void InstanceArray::render(Renderer &renderer, Tag tag) const { if(instances.empty()) return;