From d43508ba4843801cbbf1f42a27af260d4eef5701 Mon Sep 17 00:00:00 2001 From: hnOsmium0001 Date: Sun, 17 Apr 2022 20:08:57 -0700 Subject: Initial work on sprites and texture system --- source/Mesh.cpp | 59 ++++++++++++--------------------------------------------- 1 file changed, 12 insertions(+), 47 deletions(-) (limited to 'source/Mesh.cpp') diff --git a/source/Mesh.cpp b/source/Mesh.cpp index 3622d42..5b4f708 100644 --- a/source/Mesh.cpp +++ b/source/Mesh.cpp @@ -69,6 +69,15 @@ int VertexElementFormat::GetStride() const { void VertexFormat::AddElement(VertexElementFormat element) { vertexSize += element.GetStride(); + + int lastIdx = (int)elements.size() - 1; + if (lastIdx >= 0) { + auto& last = elements[lastIdx]; + element.offset = last.offset + last.GetStride(); + } else { + element.offset = 0; + } + elements.push_back(std::move(element)); } @@ -78,56 +87,12 @@ void VertexFormat::RemoveElement(int index) { elements.erase(elements.begin() + index); } -void VertexFormat::Sort() { - std::sort(elements.begin(), elements.end()); -} - -void VertexFormat::CompactBindingIndex() { - if (elements.empty()) { - return; - } - - Sort(); - - int targetIdx = 0; - int lastIdx = elements[0].bindingIndex; - int c = 0; - for (auto& elm : elements) { - if (lastIdx != elm.bindingIndex) { - targetIdx++; - lastIdx = elm.bindingIndex; - } - if (targetIdx != elm.bindingIndex) { - elements[c] = elm; - elements[c].bindingIndex = targetIdx; - } - ++c; - } +GpuMesh::GpuMesh() { } -GpuMesh::GpuMesh(VertexFormat* vertexFormat, BufferBindings* bindings, GpuIndexBuffer* indexBuffer) - : vertFormat(vertexFormat) - , vertBufBindings(bindings) - , indexBuf(indexBuffer) { +GpuMesh::~GpuMesh() { } bool GpuMesh::IsEmpty() const { - return vertFormat != nullptr; -} - -void GpuMesh::SetVertex(VertexFormat* vertexFormat, BufferBindings* bindings) { - vertFormat.Attach(vertexFormat); - vertBufBindings.Attach(bindings); -} - -VertexFormat* GpuMesh::GetVertexFormat() const { - return vertFormat.Get(); -} - -BufferBindings* GpuMesh::GetVertexBufferBindings() const { - return vertBufBindings.Get(); -} - -GpuIndexBuffer* GpuMesh::GetIndexBuffer() const { - return indexBuf.Get(); + return vertFormat == nullptr || indexBuf == nullptr; } -- cgit v1.2.3-70-g09d2