X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.cpp;h=52d17c055319464479f8d1d7b248044de024cf52;hb=82426ae2997d2b21703d2d5afb631a84736e975f;hp=e52a19f81d2c4898681f2213adfa4dc0e2b6fde2;hpb=7caa2326d25d4fc5ba98318dfccb508bb3e16820;p=blank.git diff --git a/src/chunk.cpp b/src/chunk.cpp index e52a19f..52d17c0 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -111,20 +111,21 @@ glm::mat4 Chunk::Transform(const Pos &offset) const { } -int Chunk::VertexCount() const { - int count = 0; +void Chunk::Update() { + int vtx_count = 0, idx_count = 0; for (const auto &block : blocks) { - count += Type(block).shape->VertexCount(); + const Shape *shape = Type(block).shape; + vtx_count += shape->VertexCount(); + idx_count += shape->VertexIndexCount(); } - return count; -} - -void Chunk::Update() { model.Clear(); - model.Reserve(VertexCount()); + model.Reserve(vtx_count, idx_count); + Model::Index vtx_counter = 0; for (size_t i = 0; i < Size(); ++i) { - Type(blocks[i]).FillModel(ToCoords(i), model); + const BlockType &type = Type(blocks[i]); + type.FillModel(model, ToCoords(i), vtx_counter); + vtx_counter += type.shape->VertexCount(); } model.Invalidate();