X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fchunk.cpp;h=fbfc8578ac3a93da8eab354ad1e37fa56ee07c5f;hb=d66d14f853f2d05f54076d38c72e53419dfc4cc5;hp=e52a19f81d2c4898681f2213adfa4dc0e2b6fde2;hpb=7caa2326d25d4fc5ba98318dfccb508bb3e16820;p=blank.git diff --git a/src/chunk.cpp b/src/chunk.cpp index e52a19f..fbfc857 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -111,20 +111,28 @@ glm::mat4 Chunk::Transform(const Pos &offset) const { } -int Chunk::VertexCount() const { - int count = 0; - for (const auto &block : blocks) { - count += Type(block).shape->VertexCount(); +void Chunk::CheckUpdate() { + if (dirty) { + Update(); } - return count; + model.CheckUpdate(); } void Chunk::Update() { + int vtx_count = 0, idx_count = 0; + for (const auto &block : blocks) { + const Shape *shape = Type(block).shape; + vtx_count += shape->VertexCount(); + idx_count += shape->VertexIndexCount(); + } 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();