]> git.tdb.fi Git - libs/gl.git/commitdiff
Use the same index type for all of a Mesh's batches
authorMikko Rasa <tdb@tdb.fi>
Sun, 5 Sep 2021 11:10:32 +0000 (14:10 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 5 Sep 2021 11:10:32 +0000 (14:10 +0300)
In Vulkan the index type goes in the pipeline state object.

source/core/batch.cpp
source/core/mesh.cpp

index 51746b37178a6345ca3e3ff1982a6bcdf7333e88..ebd7b049125137d2fb89f9d40255d44a139f5b8c 100644 (file)
@@ -65,6 +65,8 @@ Batch::~Batch()
 
 void Batch::set_index_type(DataType t)
 {
+       if(t==index_type)
+               return;
        if(t!=UNSIGNED_SHORT && t!=UNSIGNED_INT)
                throw invalid_argument("Batch::set_data_type");
        if(t==UNSIGNED_SHORT && max_index>0xFFFE)
index 4414a90e6577910e7881dee65877134e7cd1ba69..38642d4e26ee7459896429a03775eba3736f1700 100644 (file)
@@ -146,6 +146,19 @@ void Mesh::add_batch(const Batch &b)
                        batches.back().use_buffer(ibuf, prev);
        }
 
+       DataType existing_type = batches.front().get_index_type();
+       DataType added_type = batches.back().get_index_type();
+       if(existing_type!=added_type)
+       {
+               if(get_type_size(existing_type)>get_type_size(added_type))
+                       batches.back().set_index_type(existing_type);
+               else
+               {
+                       for(vector<Batch>::iterator i=batches.begin(); i!=batches.end(); ++i)
+                               i->set_index_type(added_type);
+               }
+       }
+
        check_buffers(INDEX_BUFFER);
 }