Browse Source

Add option to create dynamic VertexBuffer

master
Riyyi 4 years ago
parent
commit
a45dd7cc03
  1. 21
      inferno/src/inferno/render/buffer.cpp
  2. 3
      inferno/src/inferno/render/buffer.h

21
inferno/src/inferno/render/buffer.cpp

@ -115,6 +115,17 @@ namespace Inferno {
// -----------------------------------------
VertexBuffer::VertexBuffer(size_t size)
{
glGenBuffers(1, &m_id);
this->bind();
// Reserve data on the GPU
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW);
this->unbind();
}
VertexBuffer::VertexBuffer(float* vertices, size_t size)
{
glGenBuffers(1, &m_id);
@ -141,6 +152,16 @@ namespace Inferno {
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void VertexBuffer::uploadData(const void* data, uint32_t size)
{
this->bind();
// Upload data to the GPU
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data);
this->unbind();
}
// -----------------------------------------
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size) :

3
inferno/src/inferno/render/buffer.h

@ -81,12 +81,15 @@ namespace Inferno {
// GPU memory which holds raw vertex data
class VertexBuffer {
public:
VertexBuffer(size_t size);
VertexBuffer(float* vertices, size_t size);
~VertexBuffer();
void bind() const;
void unbind() const;
void uploadData(const void* data, uint32_t size);
inline const BufferLayout& getLayout() const { return m_layout; }
inline void setLayout(const BufferLayout& layout) { m_layout = layout; }

Loading…
Cancel
Save