From 325ec8e754833b94db159a27203262bef7e44faf Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sun, 11 May 2014 02:13:04 +0200 Subject: [PATCH] Fix wrong buffer size and factorize state changes. --- src/graphics/render.cpp | 14 +++++++++----- src/graphics/shaders.cpp | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index 69592b111..4b42bd5a9 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -208,24 +208,28 @@ void IrrDriver::renderGLSL(float dt) { const std::map>& lines = debug_drawer->getLines(); std::map>::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); } } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index d804c00c2..3288c97ff 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -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);