aboutsummaryrefslogtreecommitdiff
path: root/source/Mesh.cpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2022-04-17 20:08:57 -0700
committerrtk0c <[email protected]>2022-04-17 20:08:57 -0700
commit5424a1d5434e3ddd911a504719918c2df027e2fd (patch)
tree6275aab13140d81dcc46c8290e73ac9a8bbb5605 /source/Mesh.cpp
parentafcac59c7d04f4337d6b04ebed8cac7e871ccc50 (diff)
Changeset: 8 Initial work on sprites and texture system
Diffstat (limited to 'source/Mesh.cpp')
-rw-r--r--source/Mesh.cpp59
1 files changed, 12 insertions, 47 deletions
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;
}