From a2ec7dabd48a70ea69623406ddd0f8f97af403c8 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 12 Aug 2025 18:12:37 +0200 Subject: [add]: Start of a basic rendering backend --- src/Rendering/VertexBuffer.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/Rendering/VertexBuffer.h (limited to 'src/Rendering/VertexBuffer.h') 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 +#include + +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 + void Push(uint32_t count) + { + static_assert(false); + } + + template<> + void Push(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 count) + { + m_Elements.push_back({ 0x1405, count, 0, m_Stride }); // GL_UNSIGNED_INT + m_Stride += count * VertexBufferElement::GetSizeOfType(0x1405); + } + + template<> + void Push(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& GetElements() const { return m_Elements; } + inline uint32_t GetStride() const { return m_Stride; } + + private: + std::vector 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); + }; +}; -- cgit v1.3