From 9ae205ac82f0659f85f55931dc09cbe565fb0da8 Mon Sep 17 00:00:00 2001 From: Light3039 Date: Fri, 28 May 2021 05:12:23 +0430 Subject: [PATCH] VertexBuffer --- Engine/src/Engine/Graphics/VertexBuffer.cpp | 19 ++++++++++++ Engine/src/Engine/Graphics/VertexBuffer.h | 20 +++++++++++++ .../GraphicsAPI/OpenGL/glRenderCommand.cpp | 2 +- .../GraphicsAPI/OpenGL/glVertexBuffer.cpp | 30 +++++++++++++++++++ .../GraphicsAPI/OpenGL/glVertexBuffer.h | 20 +++++++++++++ Sandbox/imgui.ini | 5 ++++ 6 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 Engine/src/Engine/Graphics/VertexBuffer.cpp create mode 100644 Engine/src/Engine/Graphics/VertexBuffer.h create mode 100644 Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp create mode 100644 Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h diff --git a/Engine/src/Engine/Graphics/VertexBuffer.cpp b/Engine/src/Engine/Graphics/VertexBuffer.cpp new file mode 100644 index 0000000..9fd8774 --- /dev/null +++ b/Engine/src/Engine/Graphics/VertexBuffer.cpp @@ -0,0 +1,19 @@ +#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/Engine/Graphics/VertexBuffer.h b/Engine/src/Engine/Graphics/VertexBuffer.h new file mode 100644 index 0000000..9dcd904 --- /dev/null +++ b/Engine/src/Engine/Graphics/VertexBuffer.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Base.h" + +namespace Light { + + class VertexBuffer + { + public: + static VertexBuffer* Create(unsigned int count, float* vertices); + + + virtual void Bind() = 0; + virtual void UnBind() = 0; + + protected: + VertexBuffer() = default; + }; + +} \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp index 286b63f..93f1c3d 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp @@ -19,7 +19,7 @@ namespace Light { void glRenderCommand::ClearBackBuffer() { glClear(GL_COLOR_BUFFER_BIT); - glClearColor(0.32f, 0.65f, 0.892f, 1.0f); + glClearColor(0.25f, 0.45f, 0.91f, 1.0f); } void glRenderCommand::Draw(unsigned int count) diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp new file mode 100644 index 0000000..a0d89cd --- /dev/null +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp @@ -0,0 +1,30 @@ +#include "ltpch.h" +#include "glVertexBuffer.h" + +#include + +namespace Light { + + glVertexBuffer::glVertexBuffer(unsigned int count, float* vertices) + { + glCreateBuffers(1, &m_BufferID); + glBindBuffer(GL_ARRAY_BUFFER, m_BufferID); + glBufferData(GL_ARRAY_BUFFER, count * sizeof(float), vertices, GL_STATIC_DRAW); + } + + glVertexBuffer::~glVertexBuffer() + { + glDeleteBuffers(1, &m_BufferID); + } + + void glVertexBuffer::Bind() + { + glBindBuffer(GL_ARRAY_BUFFER, m_BufferID); + } + + void glVertexBuffer::UnBind() + { + glBindBuffer(GL_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/glVertexBuffer.h new file mode 100644 index 0000000..a2f0e8d --- /dev/null +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h @@ -0,0 +1,20 @@ +#pragma once + +#include "Base.h" +#include "Graphics/VertexBuffer.h" + +namespace Light { + + class glVertexBuffer : public VertexBuffer + { + private: + unsigned int m_BufferID; + public: + glVertexBuffer(unsigned int count, float* vertices); + ~glVertexBuffer(); + + void Bind() override; + void UnBind() override; + }; + +} \ No newline at end of file diff --git a/Sandbox/imgui.ini b/Sandbox/imgui.ini index b8157e5..5f92ce0 100644 --- a/Sandbox/imgui.ini +++ b/Sandbox/imgui.ini @@ -8,6 +8,11 @@ Pos=276,-1 Size=521,536 Collapsed=0 +[Window][Dear ImGui Metrics/Debugger] +Pos=263,318 +Size=346,290 +Collapsed=0 + [Table][0xC9935533,3] Column 0 Weight=1.0000 Column 1 Weight=1.0000