diff --git a/Engine/src/Engine/Graphics/Buffers.cpp b/Engine/src/Engine/Graphics/Buffers.cpp new file mode 100644 index 0000000..947ea50 --- /dev/null +++ b/Engine/src/Engine/Graphics/Buffers.cpp @@ -0,0 +1,34 @@ +#include "ltpch.h" +#include "Buffers.h" +#include "OpenGL/glBuffers.h" + +#include "GraphicsContext.h" + +namespace Light { + + + VertexBuffer* VertexBuffer::Create(unsigned int count, float* vertices) + { + switch (GraphicsContext::GetGraphicsAPI()) + { + case GraphicsAPI::OpenGL: + return new glVertexBuffer(count, vertices); + default: + LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI()); + return nullptr; + } + } + + IndexBuffer* IndexBuffer::Create(unsigned int count, unsigned int* indices) + { + switch (GraphicsContext::GetGraphicsAPI()) + { + case GraphicsAPI::OpenGL: + return new glIndexBuffer(count, indices); + default: + LT_ENGINE_ASSERT(false, "IndexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI()); + return nullptr; + } + } + +} \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/VertexBuffer.h b/Engine/src/Engine/Graphics/Buffers.h similarity index 55% rename from Engine/src/Engine/Graphics/VertexBuffer.h rename to Engine/src/Engine/Graphics/Buffers.h index 9dcd904..33245d5 100644 --- a/Engine/src/Engine/Graphics/VertexBuffer.h +++ b/Engine/src/Engine/Graphics/Buffers.h @@ -9,7 +9,6 @@ namespace Light { public: static VertexBuffer* Create(unsigned int count, float* vertices); - virtual void Bind() = 0; virtual void UnBind() = 0; @@ -17,4 +16,16 @@ namespace Light { VertexBuffer() = default; }; + class IndexBuffer + { + public: + static IndexBuffer* Create(unsigned int count, unsigned int* indices); + + virtual void Bind() = 0; + virtual void UnBind() = 0; + + protected: + IndexBuffer() = default; + }; + } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/VertexBuffer.cpp b/Engine/src/Engine/Graphics/VertexBuffer.cpp deleted file mode 100644 index 9fd8774..0000000 --- a/Engine/src/Engine/Graphics/VertexBuffer.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "ltpch.h" -#include "VertexBuffer.h" -#include "OpenGL/glVertexBuffer.h" - -#include "GraphicsContext.h" - -namespace Light { - - - VertexBuffer* VertexBuffer::Create(unsigned int count, float* vertices) - { - switch (GraphicsContext::GetGraphicsAPI()) - { - case GraphicsAPI::OpenGL: - return new glVertexBuffer(count, vertices); - } - } - -} \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp similarity index 50% rename from Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp rename to Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp index a0d89cd..5ab8cdf 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp @@ -1,5 +1,5 @@ #include "ltpch.h" -#include "glVertexBuffer.h" +#include "glBuffers.h" #include @@ -27,4 +27,27 @@ namespace Light { glBindBuffer(GL_ARRAY_BUFFER, NULL); } + glIndexBuffer::glIndexBuffer(unsigned int count, unsigned int* indices) + { + glCreateBuffers(1, &m_BufferID); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), indices, GL_STATIC_DRAW); + + } + + glIndexBuffer::~glIndexBuffer() + { + glDeleteBuffers(1, &m_BufferID); + } + + void glIndexBuffer::Bind() + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_BufferID); + } + + void glIndexBuffer::UnBind() + { + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL); + } + } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h similarity index 51% rename from Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h rename to Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h index a2f0e8d..f7a8765 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h @@ -1,7 +1,7 @@ #pragma once #include "Base.h" -#include "Graphics/VertexBuffer.h" +#include "Graphics/Buffers.h" namespace Light { @@ -9,6 +9,7 @@ namespace Light { { private: unsigned int m_BufferID; + public: glVertexBuffer(unsigned int count, float* vertices); ~glVertexBuffer(); @@ -16,5 +17,18 @@ namespace Light { void Bind() override; void UnBind() override; }; + + class glIndexBuffer : public IndexBuffer + { + private: + unsigned int m_BufferID; + + public: + glIndexBuffer(unsigned int count, unsigned int* indices); + ~glIndexBuffer(); + + void Bind() override; + void UnBind() override; + }; } \ No newline at end of file