aboutsummaryrefslogtreecommitdiff
path: root/source/CpuMesh.cpp
diff options
context:
space:
mode:
authorhnOsmium0001 <[email protected]>2022-04-17 20:08:57 -0700
committerhnOsmium0001 <[email protected]>2022-04-17 20:08:57 -0700
commitd43508ba4843801cbbf1f42a27af260d4eef5701 (patch)
tree39c51368cfe8ec097c08f198877cf07e9ff835ee /source/CpuMesh.cpp
parent509201784d6525fc26345e55a56ab81e4a7616b3 (diff)
Initial work on sprites and texture system
Diffstat (limited to 'source/CpuMesh.cpp')
-rw-r--r--source/CpuMesh.cpp76
1 files changed, 36 insertions, 40 deletions
diff --git a/source/CpuMesh.cpp b/source/CpuMesh.cpp
index 8e65395..15b0f54 100644
--- a/source/CpuMesh.cpp
+++ b/source/CpuMesh.cpp
@@ -1,58 +1,54 @@
#include "CpuMesh.hpp"
-bool CpuMesh::IsEmpty() const {
- return !mVertexFormat->elements.empty();
-}
+#include <cstring>
-std::byte* CpuMesh::GetVertices() const {
- return mVertexData.get();
+StandardCpuMesh::StandardCpuMesh()
+ : mGpuMesh(new GpuMesh()) {
+ mGpuMesh->vertFormat = gVformatStandard;
+ mGpuMesh->vertBufBindings.SetBinding(0, new GpuVertexBuffer());
+ mGpuMesh->vertBufBindings.SetBinding(1, new GpuVertexBuffer());
+ mGpuMesh->indexBuf.Attach(new GpuIndexBuffer());
}
-int CpuMesh::GetVertexNumBytes() const {
- return mVertexByteCount;
+StandardCpuMesh::~StandardCpuMesh() {
+ delete mData;
}
-std::byte* CpuMesh::GetIndices() const {
- return mIndexData.get();
+void StandardCpuMesh::CreateCpuData() {
+ if (!mData) {
+ mData = new StandardCpuMeshData();
+ }
}
-int CpuMesh::GetIndexNumBytes() const {
- return mIndexCount * Tags::SizeOf(mIndexType);
+GpuVertexBuffer* StandardCpuMesh::GetPosBuffer() const {
+ return mGpuMesh->vertBufBindings.bindings[0].Get();
}
-GpuMesh* CpuMesh::SyncToGpuCreate() const {
- if (IsEmpty()) return nullptr;
-
- auto vertexBuffer = new GpuVertexBuffer();
- vertexBuffer->Upload(mVertexData.get(), GetVertexNumBytes());
+GpuVertexBuffer* StandardCpuMesh::GetExtraBuffer() const {
+ return mGpuMesh->vertBufBindings.bindings[1].Get();
+}
- auto bindings = new BufferBindings();
- for (auto& elm : mVertexFormat->elements) {
- bindings->SetBinding(elm.bindingIndex, vertexBuffer);
+bool StandardCpuMesh::UpdatePositions(glm::vec3* pos, size_t count, size_t startVertIndex) {
+ if (mData) {
+ std::memcpy(&mData->vertPositions[startVertIndex], pos, count * sizeof(glm::vec3));
}
-
- auto indexBuffer = new GpuIndexBuffer();
- indexBuffer->Upload(mIndexData.get(), mIndexType, mIndexCount);
-
- return new GpuMesh(mVertexFormat.Get(), bindings, indexBuffer);
+ auto posBuf = GetPosBuffer();
+ glBindBuffer(GL_ARRAY_BUFFER, posBuf->handle);
+ glBufferSubData(GL_ARRAY_BUFFER, startVertIndex * mGpuMesh->vertFormat->vertexSize, count * sizeof(glm::vec3), pos);
+ return true;
}
-void CpuMesh::SyncToGpu(GpuMesh& mesh) const {
- if (IsEmpty()) return;
-
- auto& oldFormat = mesh.vertFormat;
- auto& newFormat = this->mVertexFormat;
- if (oldFormat != newFormat) {
- auto buffer = new GpuVertexBuffer();
- buffer->Upload(mVertexData.get(), GetVertexNumBytes());
-
- mesh.vertBufBindings->Clear();
- for (auto& elm : newFormat->elements) {
- mesh.vertBufBindings->SetBinding(elm.bindingIndex, buffer);
- }
+bool StandardCpuMesh::UpdateColors(RgbaColor* color, size_t count, size_t starVertIndex) {
+ if (!mData) return false;
+ // TODO
+}
- oldFormat = newFormat;
- }
+bool StandardCpuMesh::UpdateNormals(glm::vec2* normals, size_t count, size_t startVertIndex) {
+ if (!mData) return false;
+ // TODO
+}
- mesh.indexBuf->Upload(mIndexData.get(), mIndexType, mIndexCount);
+bool StandardCpuMesh::UpdateIndices(uint32_t* indices, size_t count, size_t startVertIndex) {
+ if (!mData) return false;
+ // TODO
}