VertexBuffer
This commit is contained in:
parent
f3fe4c3713
commit
9ae205ac82
6 changed files with 95 additions and 1 deletions
19
Engine/src/Engine/Graphics/VertexBuffer.cpp
Normal file
19
Engine/src/Engine/Graphics/VertexBuffer.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
Engine/src/Engine/Graphics/VertexBuffer.h
Normal file
20
Engine/src/Engine/Graphics/VertexBuffer.h
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ namespace Light {
|
||||||
void glRenderCommand::ClearBackBuffer()
|
void glRenderCommand::ClearBackBuffer()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
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)
|
void glRenderCommand::Draw(unsigned int count)
|
||||||
|
|
30
Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp
Normal file
30
Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include "ltpch.h"
|
||||||
|
#include "glVertexBuffer.h"
|
||||||
|
|
||||||
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h
Normal file
20
Engine/src/Platform/GraphicsAPI/OpenGL/glVertexBuffer.h
Normal file
|
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,11 @@ Pos=276,-1
|
||||||
Size=521,536
|
Size=521,536
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
|
[Window][Dear ImGui Metrics/Debugger]
|
||||||
|
Pos=263,318
|
||||||
|
Size=346,290
|
||||||
|
Collapsed=0
|
||||||
|
|
||||||
[Table][0xC9935533,3]
|
[Table][0xC9935533,3]
|
||||||
Column 0 Weight=1.0000
|
Column 0 Weight=1.0000
|
||||||
Column 1 Weight=1.0000
|
Column 1 Weight=1.0000
|
||||||
|
|
Loading…
Add table
Reference in a new issue