diff options
| author | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-08-12 18:12:37 +0200 |
| commit | a2ec7dabd48a70ea69623406ddd0f8f97af403c8 (patch) | |
| tree | 52d71b51753b88473607f5e97f8bc15bdb5ad7d3 /src/Rendering/VertexBuffer.h | |
| parent | 16dff443789c7f1461b46ce52966972ae14c042b (diff) | |
[add]: Start of a basic rendering backend
Diffstat (limited to 'src/Rendering/VertexBuffer.h')
| -rw-r--r-- | src/Rendering/VertexBuffer.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/Rendering/VertexBuffer.h b/src/Rendering/VertexBuffer.h new file mode 100644 index 0000000..807e1be --- /dev/null +++ b/src/Rendering/VertexBuffer.h @@ -0,0 +1,73 @@ +#pragma once + +#include <cstdint> +#include <vector> + +namespace Donut +{ + struct VertexBufferElement + { + uint32_t type; + uint32_t count; + uint8_t normalized; + uint32_t offset; + + static uint32_t GetSizeOfType(uint32_t type); + }; + + class VertexBufferLayout + { + public: + VertexBufferLayout() = default; + ~VertexBufferLayout() = default; + + template<typename T> + void Push(uint32_t count) + { + static_assert(false); + } + + template<> + void Push<float>(uint32_t count) + { + m_Elements.push_back({ 0x1406, count, 0, m_Stride }); // GL_FLOAT + m_Stride += count * VertexBufferElement::GetSizeOfType(0x1406); + } + + template<> + void Push<uint32_t>(uint32_t count) + { + m_Elements.push_back({ 0x1405, count, 0, m_Stride }); // GL_UNSIGNED_INT + m_Stride += count * VertexBufferElement::GetSizeOfType(0x1405); + } + + template<> + void Push<uint8_t>(uint32_t count) + { + m_Elements.push_back({ 0x1401, count, 1, m_Stride }); // GL_UNSIGNED_BYTE + m_Stride += count * VertexBufferElement::GetSizeOfType(0x1401); + } + + inline const std::vector<VertexBufferElement>& GetElements() const { return m_Elements; } + inline uint32_t GetStride() const { return m_Stride; } + + private: + std::vector<VertexBufferElement> m_Elements; + uint32_t m_Stride = 0; + }; + + class VertexBuffer + { + public: + virtual ~VertexBuffer() = default; + + virtual void Bind() const = 0; + virtual void Unbind() const = 0; + virtual void SetData(const void* data, uint32_t size) = 0; + + virtual const VertexBufferLayout& GetLayout() const = 0; + virtual void SetLayout(const VertexBufferLayout& layout) = 0; + + static VertexBuffer* Create(const void* data, uint32_t size); + }; +}; |
