Fix wrong buffer size and factorize state changes.

This commit is contained in:
Vincent Lejeune 2014-05-11 02:13:04 +02:00
parent b286069108
commit 325ec8e754
2 changed files with 10 additions and 6 deletions

View File

@ -208,24 +208,28 @@ void IrrDriver::renderGLSL(float dt)
{
const std::map<video::SColor, std::vector<float>>& lines = debug_drawer->getLines();
std::map<video::SColor, std::vector<float>>::const_iterator it;
glUseProgram(UtilShader::ColoredLine::Program);
glBindVertexArray(UtilShader::ColoredLine::vao);
glBindBuffer(GL_ARRAY_BUFFER, UtilShader::ColoredLine::vbo);
for (it = lines.begin(); it != lines.end(); it++)
{
UtilShader::ColoredLine::setUniforms(it->first);
for (int i = 0; i < it->second.size(); i += 6 * 1024)
{
unsigned count = MIN2(it->second.size() - i, 6 * 1024);
glBindVertexArray(UtilShader::ColoredLine::vao);
glBindBuffer(GL_ARRAY_BUFFER, UtilShader::ColoredLine::vbo);
glBufferSubData(GL_ARRAY_BUFFER, 0, count, &(it->second.data()[i]));
glUseProgram(UtilShader::ColoredLine::Program);
UtilShader::ColoredLine::setUniforms(it->first);
glDrawArrays(GL_LINES, 0, count / 6);
glDrawArrays(GL_LINES, 0, count / 3);
/* draw3DLine(core::vector3df(it->second[i], it->second[i + 1], it->second[i + 2]),
core::vector3df(it->second[i + 3], it->second[i + 4], it->second[i + 5]),
it->first);*/
}
}
glUseProgram(0);
glBindVertexArray(0);
}
}

View File

@ -421,7 +421,7 @@ namespace UtilShader
glBindVertexArray(vao);
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 6 * 1024, 0, GL_DYNAMIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, 6 * 1024 * sizeof(float), 0, GL_DYNAMIC_DRAW);
GLuint attrib_position = glGetAttribLocation(Program, "Position");
glEnableVertexAttribArray(attrib_position);
glVertexAttribPointer(attrib_position, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);