diff options
author | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-04-17 20:08:57 -0700 |
commit | 5424a1d5434e3ddd911a504719918c2df027e2fd (patch) | |
tree | 6275aab13140d81dcc46c8290e73ac9a8bbb5605 /source/CpuMesh.cpp | |
parent | afcac59c7d04f4337d6b04ebed8cac7e871ccc50 (diff) |
Changeset: 8 Initial work on sprites and texture system
Diffstat (limited to 'source/CpuMesh.cpp')
-rw-r--r-- | source/CpuMesh.cpp | 76 |
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 } |