Commit 1cbc9336 authored by Anakin's avatar Anakin

fixing some problems,

trying to draw instanced,
now it crashes
parent 9c12598b
......@@ -92,15 +92,27 @@ void OpenGLController::processInit()
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, gluiInstanceBufferID);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 0));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 4));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 8));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 12));
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GLfloat) * 0));
glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GLfloat) * 4));
glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GLfloat) * 8));
glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GLfloat) * 12));
glBindBuffer(GL_ARRAY_BUFFER, 0);
// enable position, UV and mvp
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4);
glEnableVertexAttribArray(5);
// MPV only once per instance
glVertexAttribDivisor(2, 1);
glVertexAttribDivisor(3, 1);
glVertexAttribDivisor(4, 1);
glVertexAttribDivisor(5, 1);
// get the painter ready
try
{
......@@ -251,10 +263,13 @@ void OpenGLController::updateScene()
// use shader prgm
glUseProgram(gluiShaderPrgmID);
// tell shader transformation
//glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix()[0][0]);
// fill vector with MVPs of all Models (only 1 for testing)
std::vector<glm::mat4> mvpMatrices;
mvpMatrices.push_back(getMVPMatrix());
// give the MVPs to the shader
glBindBuffer(GL_UNIFORM_BUFFER, gluiInstanceBufferID);
glBufferData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * 1, NULL, GL_STREAM_DRAW);
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * mvpMatrices.size(), NULL, mvpMatrices.data());
glBindBuffer(GL_UNIFORM_BUFFER, 0);
// bind texture in texture unit 0
......@@ -263,8 +278,8 @@ void OpenGLController::updateScene()
// tell sampler to use texture unit 0
glUniform1i(gluiSamplerID, 0);
//draw objects
glDrawArrays(GL_TRIANGLES, 0, vModels.front()->meshSize);
//draw objects hardcoded only 1 instance for testing
glDrawArraysInstanced(GL_TRIANGLES, 0, vModels.front()->meshSize, 1);
glfwSwapBuffers(pWindow);
glfwPollEvents();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment