|
|
@ -1,166 +1,247 @@ |
|
|
|
#include "glad/glad.h" |
|
|
|
#include "glad/glad.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "ruc/meta/assert.h" |
|
|
|
|
|
|
|
#include "inferno/core.h" |
|
|
|
#include "inferno/core.h" |
|
|
|
#include "inferno/io/log.h" |
|
|
|
#include "inferno/io/log.h" |
|
|
|
#include "inferno/render/buffer.h" |
|
|
|
#include "inferno/render/buffer.h" |
|
|
|
|
|
|
|
#include "ruc/meta/assert.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace Inferno { |
|
|
|
namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
BufferElement::BufferElement(BufferElementType type, std::string name, bool normalized) : |
|
|
|
BufferElement::BufferElement(BufferElementType type, std::string name, bool normalized) |
|
|
|
m_type(type), |
|
|
|
: m_type(type) |
|
|
|
m_name(name), |
|
|
|
, m_name(name) |
|
|
|
m_size(BufferElement::getTypeSize(type)), |
|
|
|
, m_size(BufferElement::getTypeSize(type)) |
|
|
|
m_normalized(normalized) |
|
|
|
, m_normalized(normalized) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeSize() const |
|
|
|
uint32_t BufferElement::getTypeSize() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return BufferElement::getTypeSize(m_type); |
|
|
|
return BufferElement::getTypeSize(m_type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeCount() const |
|
|
|
uint32_t BufferElement::getTypeCount() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return BufferElement::getTypeCount(m_type); |
|
|
|
return BufferElement::getTypeCount(m_type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeGL() const |
|
|
|
uint32_t BufferElement::getTypeGL() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return BufferElement::getTypeGL(m_type); |
|
|
|
return BufferElement::getTypeGL(m_type); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeSize(const BufferElementType type) |
|
|
|
uint32_t BufferElement::getTypeSize(const BufferElementType type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
|
case BufferElementType::None: return 0; |
|
|
|
case BufferElementType::None: |
|
|
|
case BufferElementType::Bool: return sizeof(bool); |
|
|
|
return 0; |
|
|
|
case BufferElementType::Bool2: return sizeof(bool) * 2; |
|
|
|
case BufferElementType::Bool: |
|
|
|
case BufferElementType::Bool3: return sizeof(bool) * 3; |
|
|
|
return sizeof(bool); |
|
|
|
case BufferElementType::Bool4: return sizeof(bool) * 4; |
|
|
|
case BufferElementType::Bool2: |
|
|
|
case BufferElementType::Int: return sizeof(int32_t); |
|
|
|
return sizeof(bool) * 2; |
|
|
|
case BufferElementType::Int2: return sizeof(int32_t) * 2; |
|
|
|
case BufferElementType::Bool3: |
|
|
|
case BufferElementType::Int3: return sizeof(int32_t) * 3; |
|
|
|
return sizeof(bool) * 3; |
|
|
|
case BufferElementType::Int4: return sizeof(int32_t) * 4; |
|
|
|
case BufferElementType::Bool4: |
|
|
|
case BufferElementType::Uint: return sizeof(uint32_t); |
|
|
|
return sizeof(bool) * 4; |
|
|
|
case BufferElementType::Uint2: return sizeof(uint32_t) * 2; |
|
|
|
case BufferElementType::Int: |
|
|
|
case BufferElementType::Uint3: return sizeof(uint32_t) * 3; |
|
|
|
return sizeof(int32_t); |
|
|
|
case BufferElementType::Uint4: return sizeof(uint32_t) * 4; |
|
|
|
case BufferElementType::Int2: |
|
|
|
case BufferElementType::Float: return sizeof(float); |
|
|
|
return sizeof(int32_t) * 2; |
|
|
|
case BufferElementType::Vec2: return sizeof(float) * 2; |
|
|
|
case BufferElementType::Int3: |
|
|
|
case BufferElementType::Vec3: return sizeof(float) * 3; |
|
|
|
return sizeof(int32_t) * 3; |
|
|
|
case BufferElementType::Vec4: return sizeof(float) * 4; |
|
|
|
case BufferElementType::Int4: |
|
|
|
case BufferElementType::Double: return sizeof(double); |
|
|
|
return sizeof(int32_t) * 4; |
|
|
|
case BufferElementType::Double2: return sizeof(double); |
|
|
|
case BufferElementType::Uint: |
|
|
|
case BufferElementType::Double3: return sizeof(double); |
|
|
|
return sizeof(uint32_t); |
|
|
|
case BufferElementType::Double4: return sizeof(double); |
|
|
|
case BufferElementType::Uint2: |
|
|
|
case BufferElementType::Mat2: return sizeof(float) * 2 * 2; |
|
|
|
return sizeof(uint32_t) * 2; |
|
|
|
case BufferElementType::Mat3: return sizeof(float) * 3 * 3; |
|
|
|
case BufferElementType::Uint3: |
|
|
|
case BufferElementType::Mat4: return sizeof(float) * 4 * 4; |
|
|
|
return sizeof(uint32_t) * 3; |
|
|
|
case BufferElementType::DoubleMat2: return sizeof(double) * 2 * 2; |
|
|
|
case BufferElementType::Uint4: |
|
|
|
case BufferElementType::DoubleMat3: return sizeof(double) * 3 * 3; |
|
|
|
return sizeof(uint32_t) * 4; |
|
|
|
case BufferElementType::DoubleMat4: return sizeof(double) * 4 * 4; |
|
|
|
case BufferElementType::Float: |
|
|
|
|
|
|
|
return sizeof(float); |
|
|
|
|
|
|
|
case BufferElementType::Vec2: |
|
|
|
|
|
|
|
return sizeof(float) * 2; |
|
|
|
|
|
|
|
case BufferElementType::Vec3: |
|
|
|
|
|
|
|
return sizeof(float) * 3; |
|
|
|
|
|
|
|
case BufferElementType::Vec4: |
|
|
|
|
|
|
|
return sizeof(float) * 4; |
|
|
|
|
|
|
|
case BufferElementType::Double: |
|
|
|
|
|
|
|
return sizeof(double); |
|
|
|
|
|
|
|
case BufferElementType::Double2: |
|
|
|
|
|
|
|
return sizeof(double); |
|
|
|
|
|
|
|
case BufferElementType::Double3: |
|
|
|
|
|
|
|
return sizeof(double); |
|
|
|
|
|
|
|
case BufferElementType::Double4: |
|
|
|
|
|
|
|
return sizeof(double); |
|
|
|
|
|
|
|
case BufferElementType::Mat2: |
|
|
|
|
|
|
|
return sizeof(float) * 2 * 2; |
|
|
|
|
|
|
|
case BufferElementType::Mat3: |
|
|
|
|
|
|
|
return sizeof(float) * 3 * 3; |
|
|
|
|
|
|
|
case BufferElementType::Mat4: |
|
|
|
|
|
|
|
return sizeof(float) * 4 * 4; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat2: |
|
|
|
|
|
|
|
return sizeof(double) * 2 * 2; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat3: |
|
|
|
|
|
|
|
return sizeof(double) * 3 * 3; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat4: |
|
|
|
|
|
|
|
return sizeof(double) * 4 * 4; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType size!"); |
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType size!"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeCount(const BufferElementType type) |
|
|
|
uint32_t BufferElement::getTypeCount(const BufferElementType type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
|
case BufferElementType::None: return 0; |
|
|
|
case BufferElementType::None: |
|
|
|
case BufferElementType::Bool: return 1; |
|
|
|
return 0; |
|
|
|
case BufferElementType::Bool2: return 2; |
|
|
|
case BufferElementType::Bool: |
|
|
|
case BufferElementType::Bool3: return 3; |
|
|
|
return 1; |
|
|
|
case BufferElementType::Bool4: return 4; |
|
|
|
case BufferElementType::Bool2: |
|
|
|
case BufferElementType::Int: return 1; |
|
|
|
return 2; |
|
|
|
case BufferElementType::Int2: return 2; |
|
|
|
case BufferElementType::Bool3: |
|
|
|
case BufferElementType::Int3: return 3; |
|
|
|
return 3; |
|
|
|
case BufferElementType::Int4: return 4; |
|
|
|
case BufferElementType::Bool4: |
|
|
|
case BufferElementType::Uint: return 1; |
|
|
|
return 4; |
|
|
|
case BufferElementType::Uint2: return 2; |
|
|
|
case BufferElementType::Int: |
|
|
|
case BufferElementType::Uint3: return 3; |
|
|
|
return 1; |
|
|
|
case BufferElementType::Uint4: return 4; |
|
|
|
case BufferElementType::Int2: |
|
|
|
case BufferElementType::Float: return 1; |
|
|
|
return 2; |
|
|
|
case BufferElementType::Vec2: return 2; |
|
|
|
case BufferElementType::Int3: |
|
|
|
case BufferElementType::Vec3: return 3; |
|
|
|
return 3; |
|
|
|
case BufferElementType::Vec4: return 4; |
|
|
|
case BufferElementType::Int4: |
|
|
|
case BufferElementType::Double: return 1; |
|
|
|
return 4; |
|
|
|
case BufferElementType::Double2: return 2; |
|
|
|
case BufferElementType::Uint: |
|
|
|
case BufferElementType::Double3: return 3; |
|
|
|
return 1; |
|
|
|
case BufferElementType::Double4: return 4; |
|
|
|
case BufferElementType::Uint2: |
|
|
|
case BufferElementType::Mat2: return 2 * 2; |
|
|
|
return 2; |
|
|
|
case BufferElementType::Mat3: return 3 * 3; |
|
|
|
case BufferElementType::Uint3: |
|
|
|
case BufferElementType::Mat4: return 4 * 4; |
|
|
|
return 3; |
|
|
|
case BufferElementType::DoubleMat2: return 2 * 2; |
|
|
|
case BufferElementType::Uint4: |
|
|
|
case BufferElementType::DoubleMat3: return 3 * 3; |
|
|
|
return 4; |
|
|
|
case BufferElementType::DoubleMat4: return 4 * 4; |
|
|
|
case BufferElementType::Float: |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
case BufferElementType::Vec2: |
|
|
|
|
|
|
|
return 2; |
|
|
|
|
|
|
|
case BufferElementType::Vec3: |
|
|
|
|
|
|
|
return 3; |
|
|
|
|
|
|
|
case BufferElementType::Vec4: |
|
|
|
|
|
|
|
return 4; |
|
|
|
|
|
|
|
case BufferElementType::Double: |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
case BufferElementType::Double2: |
|
|
|
|
|
|
|
return 2; |
|
|
|
|
|
|
|
case BufferElementType::Double3: |
|
|
|
|
|
|
|
return 3; |
|
|
|
|
|
|
|
case BufferElementType::Double4: |
|
|
|
|
|
|
|
return 4; |
|
|
|
|
|
|
|
case BufferElementType::Mat2: |
|
|
|
|
|
|
|
return 2 * 2; |
|
|
|
|
|
|
|
case BufferElementType::Mat3: |
|
|
|
|
|
|
|
return 3 * 3; |
|
|
|
|
|
|
|
case BufferElementType::Mat4: |
|
|
|
|
|
|
|
return 4 * 4; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat2: |
|
|
|
|
|
|
|
return 2 * 2; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat3: |
|
|
|
|
|
|
|
return 3 * 3; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat4: |
|
|
|
|
|
|
|
return 4 * 4; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType count!"); |
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType count!"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t BufferElement::getTypeGL(const BufferElementType type) |
|
|
|
uint32_t BufferElement::getTypeGL(const BufferElementType type) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch (type) { |
|
|
|
switch (type) { |
|
|
|
case BufferElementType::None: return GL_NONE; |
|
|
|
case BufferElementType::None: |
|
|
|
case BufferElementType::Bool: return GL_BOOL; |
|
|
|
return GL_NONE; |
|
|
|
case BufferElementType::Bool2: return GL_BOOL; |
|
|
|
case BufferElementType::Bool: |
|
|
|
case BufferElementType::Bool3: return GL_BOOL; |
|
|
|
return GL_BOOL; |
|
|
|
case BufferElementType::Bool4: return GL_BOOL; |
|
|
|
case BufferElementType::Bool2: |
|
|
|
case BufferElementType::Int: return GL_INT; |
|
|
|
return GL_BOOL; |
|
|
|
case BufferElementType::Int2: return GL_INT; |
|
|
|
case BufferElementType::Bool3: |
|
|
|
case BufferElementType::Int3: return GL_INT; |
|
|
|
return GL_BOOL; |
|
|
|
case BufferElementType::Int4: return GL_INT; |
|
|
|
case BufferElementType::Bool4: |
|
|
|
case BufferElementType::Uint: return GL_UNSIGNED_INT; |
|
|
|
return GL_BOOL; |
|
|
|
case BufferElementType::Uint2: return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::Int: |
|
|
|
case BufferElementType::Uint3: return GL_UNSIGNED_INT; |
|
|
|
return GL_INT; |
|
|
|
case BufferElementType::Uint4: return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::Int2: |
|
|
|
case BufferElementType::Float: return GL_FLOAT; |
|
|
|
return GL_INT; |
|
|
|
case BufferElementType::Vec2: return GL_FLOAT; |
|
|
|
case BufferElementType::Int3: |
|
|
|
case BufferElementType::Vec3: return GL_FLOAT; |
|
|
|
return GL_INT; |
|
|
|
case BufferElementType::Vec4: return GL_FLOAT; |
|
|
|
case BufferElementType::Int4: |
|
|
|
case BufferElementType::Double: return GL_DOUBLE; |
|
|
|
return GL_INT; |
|
|
|
case BufferElementType::Double2: return GL_DOUBLE; |
|
|
|
case BufferElementType::Uint: |
|
|
|
case BufferElementType::Double3: return GL_DOUBLE; |
|
|
|
return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::Double4: return GL_DOUBLE; |
|
|
|
case BufferElementType::Uint2: |
|
|
|
case BufferElementType::Mat2: return GL_FLOAT; |
|
|
|
return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::Mat3: return GL_FLOAT; |
|
|
|
case BufferElementType::Uint3: |
|
|
|
case BufferElementType::Mat4: return GL_FLOAT; |
|
|
|
return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::DoubleMat2: return GL_DOUBLE; |
|
|
|
case BufferElementType::Uint4: |
|
|
|
case BufferElementType::DoubleMat3: return GL_DOUBLE; |
|
|
|
return GL_UNSIGNED_INT; |
|
|
|
case BufferElementType::DoubleMat4: return GL_DOUBLE; |
|
|
|
case BufferElementType::Float: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Vec2: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Vec3: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Vec4: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Double: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::Double2: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::Double3: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::Double4: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::Mat2: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Mat3: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::Mat4: |
|
|
|
|
|
|
|
return GL_FLOAT; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat2: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat3: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
|
|
|
|
case BufferElementType::DoubleMat4: |
|
|
|
|
|
|
|
return GL_DOUBLE; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType GL!"); |
|
|
|
VERIFY(false, "BufferElement unknown BufferElementType GL!"); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements) |
|
|
|
BufferLayout::BufferLayout(const std::initializer_list<BufferElement>& elements) |
|
|
|
: m_elements(elements) |
|
|
|
: m_elements(elements) |
|
|
|
{ |
|
|
|
{ |
|
|
|
calculateOffsetsAndStride(); |
|
|
|
calculateOffsetsAndStride(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BufferLayout::calculateOffsetsAndStride() |
|
|
|
void BufferLayout::calculateOffsetsAndStride() |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_stride = 0; |
|
|
|
m_stride = 0; |
|
|
|
for (auto& element : m_elements) { |
|
|
|
for (auto& element : m_elements) { |
|
|
|
element.setOffset(m_stride); |
|
|
|
element.setOffset(m_stride); |
|
|
|
m_stride += element.getSize(); |
|
|
|
m_stride += element.getSize(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
VertexBuffer::VertexBuffer(size_t size) |
|
|
|
VertexBuffer::VertexBuffer(size_t size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glGenBuffers(1, &m_id); |
|
|
|
glGenBuffers(1, &m_id); |
|
|
|
bind(); |
|
|
|
bind(); |
|
|
|
|
|
|
|
|
|
|
@ -168,10 +249,10 @@ namespace Inferno { |
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VertexBuffer::VertexBuffer(float* vertices, size_t size) |
|
|
|
VertexBuffer::VertexBuffer(float* vertices, size_t size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glGenBuffers(1, &m_id); |
|
|
|
glGenBuffers(1, &m_id); |
|
|
|
bind(); |
|
|
|
bind(); |
|
|
|
|
|
|
|
|
|
|
@ -179,38 +260,38 @@ namespace Inferno { |
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW); |
|
|
|
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VertexBuffer::~VertexBuffer() |
|
|
|
VertexBuffer::~VertexBuffer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
glDeleteBuffers(1, &m_id); |
|
|
|
glDeleteBuffers(1, &m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexBuffer::bind() const |
|
|
|
void VertexBuffer::bind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_id); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexBuffer::unbind() const |
|
|
|
void VertexBuffer::unbind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexBuffer::uploadData(const void* data, uint32_t size) |
|
|
|
void VertexBuffer::uploadData(const void* data, uint32_t size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bind(); |
|
|
|
bind(); |
|
|
|
|
|
|
|
|
|
|
|
// Upload data to the GPU
|
|
|
|
// Upload data to the GPU
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data); |
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, size, data); |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size) : |
|
|
|
IndexBuffer::IndexBuffer(uint32_t* indices, size_t size) |
|
|
|
m_count(size / sizeof(uint32_t)) |
|
|
|
: m_count(size / sizeof(uint32_t)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
glCreateBuffers(1, &m_id); |
|
|
|
glCreateBuffers(1, &m_id); |
|
|
|
bind(); |
|
|
|
bind(); |
|
|
|
|
|
|
|
|
|
|
@ -218,47 +299,47 @@ namespace Inferno { |
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW); |
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, indices, GL_STATIC_DRAW); |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
IndexBuffer::~IndexBuffer() |
|
|
|
IndexBuffer::~IndexBuffer() |
|
|
|
{ |
|
|
|
{ |
|
|
|
glDeleteBuffers(1, &m_id); |
|
|
|
glDeleteBuffers(1, &m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IndexBuffer::bind() const |
|
|
|
void IndexBuffer::bind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IndexBuffer::unbind() const |
|
|
|
void IndexBuffer::unbind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
VertexArray::VertexArray() |
|
|
|
VertexArray::VertexArray() |
|
|
|
{ |
|
|
|
{ |
|
|
|
glCreateVertexArrays(1, &m_id); |
|
|
|
glCreateVertexArrays(1, &m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
VertexArray::~VertexArray() |
|
|
|
VertexArray::~VertexArray() |
|
|
|
{ |
|
|
|
{ |
|
|
|
glDeleteVertexArrays(1, &m_id); |
|
|
|
glDeleteVertexArrays(1, &m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexArray::bind() const |
|
|
|
void VertexArray::bind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindVertexArray(m_id); |
|
|
|
glBindVertexArray(m_id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexArray::unbind() const |
|
|
|
void VertexArray::unbind() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
glBindVertexArray(0); |
|
|
|
glBindVertexArray(0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer) |
|
|
|
void VertexArray::addVertexBuffer(std::shared_ptr<VertexBuffer> vertexBuffer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const auto& layout = vertexBuffer->getLayout(); |
|
|
|
const auto& layout = vertexBuffer->getLayout(); |
|
|
|
VERIFY(layout.getElements().size(), "VertexBuffer has no layout"); |
|
|
|
VERIFY(layout.getElements().size(), "VertexBuffer has no layout"); |
|
|
|
|
|
|
|
|
|
|
@ -282,10 +363,10 @@ namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
vertexBuffer->unbind(); |
|
|
|
vertexBuffer->unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VertexArray::setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer) |
|
|
|
void VertexArray::setIndexBuffer(std::shared_ptr<IndexBuffer> indexBuffer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bind(); |
|
|
|
bind(); |
|
|
|
indexBuffer->bind(); |
|
|
|
indexBuffer->bind(); |
|
|
|
|
|
|
|
|
|
|
@ -293,6 +374,6 @@ namespace Inferno { |
|
|
|
|
|
|
|
|
|
|
|
unbind(); |
|
|
|
unbind(); |
|
|
|
indexBuffer->unbind(); |
|
|
|
indexBuffer->unbind(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace Inferno
|
|
|
|
} // namespace Inferno
|
|
|
|