Index buffer
This commit is contained in:
parent
9ae205ac82
commit
1e48369bb8
5 changed files with 85 additions and 22 deletions
34
Engine/src/Engine/Graphics/Buffers.cpp
Normal file
34
Engine/src/Engine/Graphics/Buffers.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ namespace Light {
|
||||||
public:
|
public:
|
||||||
static VertexBuffer* Create(unsigned int count, float* vertices);
|
static VertexBuffer* Create(unsigned int count, float* vertices);
|
||||||
|
|
||||||
|
|
||||||
virtual void Bind() = 0;
|
virtual void Bind() = 0;
|
||||||
virtual void UnBind() = 0;
|
virtual void UnBind() = 0;
|
||||||
|
|
||||||
|
@ -17,4 +16,16 @@ namespace Light {
|
||||||
VertexBuffer() = default;
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "ltpch.h"
|
#include "ltpch.h"
|
||||||
#include "glVertexBuffer.h"
|
#include "glBuffers.h"
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
||||||
|
@ -27,4 +27,27 @@ namespace Light {
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, NULL);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
#include "Graphics/VertexBuffer.h"
|
#include "Graphics/Buffers.h"
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ namespace Light {
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
unsigned int m_BufferID;
|
unsigned int m_BufferID;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
glVertexBuffer(unsigned int count, float* vertices);
|
glVertexBuffer(unsigned int count, float* vertices);
|
||||||
~glVertexBuffer();
|
~glVertexBuffer();
|
||||||
|
@ -16,5 +17,18 @@ namespace Light {
|
||||||
void Bind() override;
|
void Bind() override;
|
||||||
void UnBind() 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;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue