5db5ce971c
Also added a copy pre-build even for .h files into the include directory for charcoal and charcoal-builtin
50 lines
2.5 KiB
C++
50 lines
2.5 KiB
C++
#include "MyBatch.h"
|
|
|
|
void MyBatch::setup_element_buffers()
|
|
{
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
|
glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), NULL, GL_STREAM_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[POSEABLE_VBO_INDEX]);
|
|
glBufferData(GL_ARRAY_BUFFER, m_poseable_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW);
|
|
}
|
|
|
|
void MyBatch::setup_vao()
|
|
{
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_vertex_vbo);
|
|
glEnableVertexAttribArray(0);
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
|
glEnableVertexAttribArray(1);
|
|
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, NULL);
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[POSEABLE_VBO_INDEX]);
|
|
glEnableVertexAttribArray(2);
|
|
glEnableVertexAttribArray(3);
|
|
glEnableVertexAttribArray(4);
|
|
glEnableVertexAttribArray(5);
|
|
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(0 * sizeof(vec4)));
|
|
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(1 * sizeof(vec4)));
|
|
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(2 * sizeof(vec4)));
|
|
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(Poseable), (void*)(3 * sizeof(vec4)));
|
|
|
|
glVertexAttribDivisor(0, 0); // Only need to send the mesh data once (This should probably be done every time)
|
|
glVertexAttribDivisor(1, 1); // Send the color data for each instance drawn
|
|
glVertexAttribDivisor(2, 1); // Send the offset data for each instance drawn
|
|
glVertexAttribDivisor(3, 1); // Send the offset data for each instance drawn
|
|
glVertexAttribDivisor(4, 1); // Send the offset data for each instance drawn
|
|
glVertexAttribDivisor(5, 1); // Send the offset data for each instance drawn
|
|
}
|
|
|
|
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.
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[COLOR_VBO_INDEX]);
|
|
glBufferData(GL_ARRAY_BUFFER, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), NULL, GL_STREAM_DRAW);
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, m_color_elements.size() * sizeof(MySimpleShaderProgram::Color), m_color_elements.data());
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_element_buffers[POSEABLE_VBO_INDEX]);
|
|
glBufferData(GL_ARRAY_BUFFER, m_poseable_elements.size() * sizeof(Poseable), NULL, GL_STREAM_DRAW);
|
|
glBufferSubData(GL_ARRAY_BUFFER, 0, m_poseable_elements.size() * sizeof(Poseable), m_poseable_elements.data());
|
|
}
|
|
|