feat: use custom buffers
This commit is contained in:
@ -12,18 +12,22 @@ batch::batch() {
|
|||||||
|
|
||||||
void batch::prepare(glm::mat4 *instances, unsigned int count) {
|
void batch::prepare(glm::mat4 *instances, unsigned int count) {
|
||||||
if (!m_instanceBuffer) {
|
if (!m_instanceBuffer) {
|
||||||
m_instanceBuffer = std::make_unique<OpenGL::InstanceBuffer>(GL_DYNAMIC_DRAW);
|
m_instanceBuffer = new OpenGL::InstanceBuffer(GL_DYNAMIC_DRAW);
|
||||||
m_instanceBuffer->Data(nullptr, sizeof(glm::mat4) * count);
|
OpenGL::Buffer::Bind(m_instanceBuffer);
|
||||||
|
OpenGL::Buffer::Data(m_instanceBuffer, nullptr, sizeof(glm::mat4) * count);
|
||||||
|
OpenGL::Buffer::Unbind(m_instanceBuffer);
|
||||||
m_instance_count = count;
|
m_instance_count = count;
|
||||||
} else if (count > m_instance_count) {
|
} else if (count > m_instance_count) {
|
||||||
// Optional: reallocate only if you *really* have more instances than before
|
// Optional: reallocate only if you *really* have more instances than before
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_instance_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_instance_vbo);
|
||||||
m_instanceBuffer->Data(nullptr, sizeof(glm::mat4) * count);
|
OpenGL::Buffer::Bind(m_instanceBuffer);
|
||||||
|
OpenGL::Buffer::Data(m_instanceBuffer, nullptr, sizeof(glm::mat4) * count);
|
||||||
|
OpenGL::Buffer::Unbind(m_instanceBuffer);
|
||||||
m_instance_count = count;
|
m_instance_count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just update the data region — much cheaper
|
// Just update the data region — much cheaper
|
||||||
m_instanceBuffer->SubData(instances, sizeof(glm::mat4) * count, 0);
|
OpenGL::Buffer::SubData(m_instanceBuffer, instances, sizeof(glm::mat4) * count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user