Riyyi
5 years ago
2 changed files with 102 additions and 0 deletions
@ -0,0 +1,58 @@
|
||||
#include <glad/glad.h> |
||||
|
||||
#include "inferno/render/buffer.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
VertexBuffer::VertexBuffer(float* vertices, size_t size) |
||||
{ |
||||
glCreateBuffers(1, &m_id); |
||||
this->bind(); |
||||
|
||||
// Upload data to the GPU
|
||||
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW); |
||||
} |
||||
|
||||
VertexBuffer::~VertexBuffer() |
||||
{ |
||||
glDeleteBuffers(1, &m_id); |
||||
} |
||||
|
||||
void VertexBuffer::bind() const |
||||
{ |
||||
glBindBuffer(GL_ARRAY_BUFFER, m_id); |
||||
} |
||||
|
||||
void VertexBuffer::unbind() const |
||||
{ |
||||
glBindBuffer(GL_ARRAY_BUFFER, 0); |
||||
} |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size) : |
||||
m_count(size / sizeof(uint32_t)) |
||||
{ |
||||
glCreateBuffers(1, &m_id); |
||||
this->bind(); |
||||
|
||||
// Upload data to the GPU
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW); |
||||
} |
||||
|
||||
IndexBuffer::~IndexBuffer() |
||||
{ |
||||
glDeleteBuffers(1, &m_id); |
||||
} |
||||
|
||||
void IndexBuffer::bind() const |
||||
{ |
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id); |
||||
} |
||||
|
||||
void IndexBuffer::unbind() const |
||||
{ |
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
#ifndef BUFFER_H |
||||
#define BUFFER_H |
||||
|
||||
#include <cstddef> // std::size_t |
||||
#include <cstdint> // std::uint32_t |
||||
|
||||
namespace Inferno { |
||||
|
||||
// GPU memory which holds the raw vertex data
|
||||
class VertexBuffer { |
||||
public: |
||||
VertexBuffer(float* vertices, size_t size); |
||||
~VertexBuffer(); |
||||
|
||||
void bind() const; |
||||
void unbind() const; |
||||
|
||||
private: |
||||
uint32_t m_id; |
||||
}; |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
// Vertices order of rendering
|
||||
class IndexBuffer { |
||||
public: |
||||
IndexBuffer(uint32_t* indices, size_t size); |
||||
~IndexBuffer(); |
||||
|
||||
void bind() const; |
||||
void unbind() const; |
||||
|
||||
// -----------------------------------------
|
||||
|
||||
inline uint32_t getCount() const { return m_count; } |
||||
|
||||
private: |
||||
uint32_t m_id; |
||||
uint32_t m_count; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // BUFFER_H
|
Loading…
Reference in new issue