1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Split CIndexBuffer from CMeshBuffer

This commit is contained in:
sfan5 2024-08-27 17:40:29 +02:00
parent 5d6e15bc49
commit 47e4c33a50
13 changed files with 197 additions and 104 deletions

View file

@ -179,6 +179,7 @@ void Clouds::updateMesh()
auto *mb = m_meshbuffer.get();
auto &vertices = mb->Vertices->Data;
auto &indices = mb->Indices->Data;
{
const u32 vertex_count = num_faces_to_draw * 16 * m_cloud_radius_i * m_cloud_radius_i;
const u32 quad_count = vertex_count / 4;
@ -186,7 +187,7 @@ void Clouds::updateMesh()
// reserve memory
vertices.reserve(vertex_count);
mb->Indices.reserve(index_count);
indices.reserve(index_count);
}
#define GETINDEX(x, z, radius) (((z)+(radius))*(radius)*2 + (x)+(radius))
@ -323,18 +324,18 @@ void Clouds::updateMesh()
const u32 index_count = quad_count * 6;
// rewrite index array as needed
if (mb->getIndexCount() > index_count) {
mb->Indices.resize(index_count);
indices.resize(index_count);
mb->setDirty(scene::EBT_INDEX);
} else if (mb->getIndexCount() < index_count) {
const u32 start = mb->getIndexCount() / 6;
assert(start * 6 == mb->getIndexCount());
for (u32 k = start; k < quad_count; k++) {
mb->Indices.push_back(4 * k + 0);
mb->Indices.push_back(4 * k + 1);
mb->Indices.push_back(4 * k + 2);
mb->Indices.push_back(4 * k + 2);
mb->Indices.push_back(4 * k + 3);
mb->Indices.push_back(4 * k + 0);
indices.push_back(4 * k + 0);
indices.push_back(4 * k + 1);
indices.push_back(4 * k + 2);
indices.push_back(4 * k + 2);
indices.push_back(4 * k + 3);
indices.push_back(4 * k + 0);
}
mb->setDirty(scene::EBT_INDEX);
}