diff options
Diffstat (limited to 'source/Mesh.cpp')
-rw-r--r-- | source/Mesh.cpp | 130 |
1 files changed, 43 insertions, 87 deletions
diff --git a/source/Mesh.cpp b/source/Mesh.cpp index 5b4f708..244e2e3 100644 --- a/source/Mesh.cpp +++ b/source/Mesh.cpp @@ -1,98 +1,54 @@ #include "Mesh.hpp" -#include <algorithm> +#include <cstring> -GpuVertexBuffer::GpuVertexBuffer() { - glGenBuffers(1, &handle); -} +// 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()); +// } -GpuVertexBuffer::~GpuVertexBuffer() { - glDeleteBuffers(1, &handle); -} +// StandardCpuMesh::~StandardCpuMesh() { +// delete mData; +// } -void GpuVertexBuffer::Upload(const std::byte* data, size_t sizeInBytes) { - glBindBuffer(GL_ARRAY_BUFFER, handle); - glBufferData(GL_ARRAY_BUFFER, sizeInBytes, data, GL_DYNAMIC_DRAW); -} +// void StandardCpuMesh::CreateCpuData() { +// if (!mData) { +// mData = new StandardCpuMeshData(); +// } +// } -GpuIndexBuffer::GpuIndexBuffer() { - glGenBuffers(1, &handle); -} +// GpuVertexBuffer* StandardCpuMesh::GetPosBuffer() const { +// return mGpuMesh->vertBufBindings.bindings[0].Get(); +// } -GpuIndexBuffer::~GpuIndexBuffer() { - glDeleteBuffers(1, &handle); -} +// GpuVertexBuffer* StandardCpuMesh::GetExtraBuffer() const { +// return mGpuMesh->vertBufBindings.bindings[1].Get(); +// } -void GpuIndexBuffer::Upload(const std::byte* data, size_t count) { - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * Tags::SizeOf(indexType), data, GL_DYNAMIC_DRAW); -} +// 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 posBuf = GetPosBuffer(); +// glBindBuffer(GL_ARRAY_BUFFER, posBuf->handle); +// glBufferSubData(GL_ARRAY_BUFFER, startVertIndex * mGpuMesh->vertFormat->vertexSize, count * sizeof(glm::vec3), pos); +// return true; +// } -void GpuIndexBuffer::Upload(const std::byte* data, Tags::IndexType type, size_t count) { - indexType = type; - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, handle); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * Tags::SizeOf(type), data, GL_DYNAMIC_DRAW); -} +// bool StandardCpuMesh::UpdateColors(RgbaColor* color, size_t count, size_t starVertIndex) { +// if (!mData) return false; +// // TODO +// } -int BufferBindings::GetMaxBindingIndex() const { - return bindings.size() - 1; -} +// bool StandardCpuMesh::UpdateNormals(glm::vec2* normals, size_t count, size_t startVertIndex) { +// if (!mData) return false; +// // TODO +// } -GpuVertexBuffer* BufferBindings::GetBinding(int index) const { - if (index >= 0 && index < bindings.size()) { - return bindings[index].Get(); - } else { - return nullptr; - } -} - -void BufferBindings::SetBinding(int index, GpuVertexBuffer* buffer) { - int maxBindingIndex = GetMaxBindingIndex(); - if (index > maxBindingIndex) { - int countDelta = index - maxBindingIndex; - bindings.resize(bindings.size() + countDelta); - } - - bindings[index].Attach(buffer); - if (index == maxBindingIndex && buffer == nullptr) { - bindings.pop_back(); - } -} - -void BufferBindings::Clear() { - bindings.clear(); -} - -int VertexElementFormat::GetStride() const { - return Tags::SizeOf(type); -} - -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)); -} - -void VertexFormat::RemoveElement(int index) { - auto& element = elements[index]; - vertexSize -= element.GetStride(); - elements.erase(elements.begin() + index); -} - -GpuMesh::GpuMesh() { -} - -GpuMesh::~GpuMesh() { -} - -bool GpuMesh::IsEmpty() const { - return vertFormat == nullptr || indexBuf == nullptr; -} +// bool StandardCpuMesh::UpdateIndices(uint32_t* indices, size_t count, size_t startVertIndex) { +// if (!mData) return false; +// // TODO +// } |