2018-09-05 15:47:09 +00:00
|
|
|
#include "MyBatch.h"
|
|
|
|
|
2018-09-07 04:41:34 +00:00
|
|
|
void MyBatch::setup_element_buffers()
|
|
|
|
{
|
2018-09-07 15:45:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), NULL, GL_STREAM_DRAW);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[OFFSET_VBO_INDEX]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_offset_elements.size() * sizeof(MyBatchTestShaderProgram::Offset), NULL, GL_STREAM_DRAW);
|
2018-09-07 04:41:34 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 20:26:50 +00:00
|
|
|
void MyBatch::setup_vao()
|
|
|
|
{
|
2018-09-07 04:41:34 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
|
2018-09-05 20:26:50 +00:00
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
2018-09-07 15:45:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
2018-09-07 04:41:34 +00:00
|
|
|
glEnableVertexAttribArray(1);
|
|
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
2018-09-07 15:45:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[OFFSET_VBO_INDEX]);
|
|
|
|
glEnableVertexAttribArray(2);
|
|
|
|
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
2018-09-07 04:41:34 +00:00
|
|
|
|
2018-09-07 15:45:32 +00:00
|
|
|
glVertexAttribDivisor(0, 0); // Only need to send the mesh data once (This should probably be done every time)
|
2018-09-07 04:41:34 +00:00
|
|
|
glVertexAttribDivisor(1, 1); // Send the color data for each instance drawn
|
2018-09-07 15:45:32 +00:00
|
|
|
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
|
2018-09-07 04:41:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyBatch::update_element_buffers()
|
|
|
|
{
|
|
|
|
// TODO: There are probably better ways to do this. Should check with the old engine to see what I did there.
|
2018-09-07 15:45:32 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), NULL, GL_STREAM_DRAW);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, m_color_elements.size() * sizeof(MyBatchTestShaderProgram::Color), m_color_elements.data());
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[OFFSET_VBO_INDEX]);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, m_offset_elements.size() * sizeof(MyBatchTestShaderProgram::Offset), NULL, GL_STREAM_DRAW);
|
|
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, m_offset_elements.size() * sizeof(MyBatchTestShaderProgram::Offset), m_offset_elements.data());
|
2018-09-05 20:26:50 +00:00
|
|
|
}
|
|
|
|
|