]> git.tdb.fi Git - libs/gl.git/commitdiff
Store index type in VertexSetup
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Sep 2021 11:34:04 +0000 (14:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Sep 2021 11:34:04 +0000 (14:34 +0300)
source/core/mesh.cpp
source/core/vertexsetup.cpp
source/core/vertexsetup.h
source/render/instancearray.cpp

index 38642d4e26ee7459896429a03775eba3736f1700..77da81ebec4a3e51d286dc5477142a46191c9cf0 100644 (file)
@@ -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());
        }
 }
 
index f077ad2e00260ac675efcd191a214b8820eb3554..86c9f0f237f5cbc9c178da7ebcf082a99454fc9c 100644 (file)
@@ -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;
 }
 
index 7eb903aeae9f819e43258c0b510bfebba638c73f..756f5bc03644990990aafb1f360c1cebb9b6bfe0 100644 (file)
@@ -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 &);
index 11279f76262fe60882df087e91d50d84d43a173b..039a50ecde32a7500850ca107f040169fe0b5692 100644 (file)
@@ -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