From 6955c16bb123f3b795186c99442dc4d92be0ebc9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 5 Sep 2021 14:10:32 +0300 Subject: [PATCH] Use the same index type for all of a Mesh's batches In Vulkan the index type goes in the pipeline state object. --- source/core/batch.cpp | 2 ++ source/core/mesh.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/source/core/batch.cpp b/source/core/batch.cpp index 51746b37..ebd7b049 100644 --- a/source/core/batch.cpp +++ b/source/core/batch.cpp @@ -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) diff --git a/source/core/mesh.cpp b/source/core/mesh.cpp index 4414a90e..38642d4e 100644 --- a/source/core/mesh.cpp +++ b/source/core/mesh.cpp @@ -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::iterator i=batches.begin(); i!=batches.end(); ++i) + i->set_index_type(added_type); + } + } + check_buffers(INDEX_BUFFER); } -- 2.45.2