fixing some problems,

trying to draw instanced,
now it crashes
This commit is contained in:
Anakin 2016-11-05 11:53:49 +01:00
parent 9c12598bf5
commit 1cbc9336fe
1 changed files with 24 additions and 9 deletions

View File

@ -92,15 +92,27 @@ void OpenGLController::processInit()
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, gluiInstanceBufferID); glBindBuffer(GL_ARRAY_BUFFER, gluiInstanceBufferID);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GL_FLOAT) * 0)); 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(GL_FLOAT) * 4)); 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(GL_FLOAT) * 8)); 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(GL_FLOAT) * 12)); glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (void*)(sizeof(GLfloat) * 12));
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
// enable position, UV and mvp
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1); 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 // get the painter ready
try try
{ {
@ -251,10 +263,13 @@ void OpenGLController::updateScene()
// use shader prgm // use shader prgm
glUseProgram(gluiShaderPrgmID); glUseProgram(gluiShaderPrgmID);
// tell shader transformation // fill vector with MVPs of all Models (only 1 for testing)
//glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix()[0][0]); std::vector<glm::mat4> mvpMatrices;
mvpMatrices.push_back(getMVPMatrix());
// give the MVPs to the shader
glBindBuffer(GL_UNIFORM_BUFFER, gluiInstanceBufferID); 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); glBindBuffer(GL_UNIFORM_BUFFER, 0);
// bind texture in texture unit 0 // bind texture in texture unit 0
@ -263,8 +278,8 @@ void OpenGLController::updateScene()
// tell sampler to use texture unit 0 // tell sampler to use texture unit 0
glUniform1i(gluiSamplerID, 0); glUniform1i(gluiSamplerID, 0);
//draw objects //draw objects hardcoded only 1 instance for testing
glDrawArrays(GL_TRIANGLES, 0, vModels.front()->meshSize); glDrawArraysInstanced(GL_TRIANGLES, 0, vModels.front()->meshSize, 1);
glfwSwapBuffers(pWindow); glfwSwapBuffers(pWindow);
glfwPollEvents(); glfwPollEvents();