From: Mikko Rasa Date: Sun, 5 Sep 2021 11:34:04 +0000 (+0300) Subject: Store index type in VertexSetup X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=73567be7cd9e01e620cb2a8fa0ca381723b9a71f;p=libs%2Fgl.git Store index type in VertexSetup --- diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index 38642d4e..77da81eb 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -89,7 +89,6 @@ void Mesh::check_buffers(unsigned mask) ibuf = new Buffer; if(!batches.empty()) batches.front().change_buffer(ibuf); - vtx_setup.set_index_buffer(*ibuf); dirty |= INDEX_BUFFER; #ifdef DEBUG @@ -97,6 +96,9 @@ void Mesh::check_buffers(unsigned mask) vbuf->set_debug_name(debug_name+" [IBO]"); #endif } + + if(!batches.empty()) + vtx_setup.set_index_buffer(*ibuf, batches.front().get_index_type()); } } diff --git a/source/core/vertexsetup.cpp b/source/core/vertexsetup.cpp index f077ad2e..86c9f0f2 100644 --- a/source/core/vertexsetup.cpp +++ b/source/core/vertexsetup.cpp @@ -23,7 +23,8 @@ VertexSetup::VertexSetup(): dirty(0), vertex_array(0), inst_array(0), - index_buffer(0) + index_buffer(0), + index_type(UNSIGNED_SHORT) { static Require req(ARB_vertex_array_object); if(ARB_direct_state_access) @@ -86,9 +87,10 @@ void VertexSetup::set_instance_array(const VertexArray &a) dirty |= INSTANCE_ARRAY; } -void VertexSetup::set_index_buffer(const Buffer &ibuf) +void VertexSetup::set_index_buffer(const Buffer &ibuf, DataType itype) { index_buffer = &ibuf; + index_type = itype; dirty |= INDEX_BUFFER; } diff --git a/source/core/vertexsetup.h b/source/core/vertexsetup.h index 7eb903ae..756f5bc0 100644 --- a/source/core/vertexsetup.h +++ b/source/core/vertexsetup.h @@ -1,6 +1,7 @@ #ifndef MSP_GL_VERTEXSETUP_H_ #define MSP_GL_VERTEXSETUP_H_ +#include "datatype.h" #include "vertexformat.h" namespace Msp { @@ -30,6 +31,7 @@ private: const VertexArray *inst_array; VertexFormat inst_format; const Buffer *index_buffer; + DataType index_type; public: VertexSetup(); @@ -40,10 +42,11 @@ public: void set_vertex_array(const VertexArray &); void set_instance_array(const VertexArray &); - void set_index_buffer(const Buffer &); + void set_index_buffer(const Buffer &, DataType); const VertexArray *get_vertex_array() const { return vertex_array; } const VertexArray *get_instance_array() const { return inst_array; } const Buffer *get_index_buffer() const { return index_buffer; } + DataType get_index_type() const { return index_type; } private: static bool verify_format(const VertexFormat &); diff --git a/source/render/instancearray.cpp b/source/render/instancearray.cpp index 11279f76..039a50ec 100644 --- a/source/render/instancearray.cpp +++ b/source/render/instancearray.cpp @@ -51,10 +51,12 @@ InstanceArray::InstanceArray(const Object &o): instance_buffer = new Buffer; instance_data->use_buffer(instance_buffer); + const Mesh *mesh = object.get_mesh(); + vtx_setup = new VertexSetup; - vtx_setup->set_format_instanced(object.get_mesh()->get_vertices().get_format(), fmt); - vtx_setup->set_vertex_array(object.get_mesh()->get_vertices()); - vtx_setup->set_index_buffer(*object.get_mesh()->get_index_buffer()); + 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