|
|
|
@@ -188,7 +188,7 @@ void OpenGLController::setCallbackFunctions()
|
|
|
|
|
glfwSetKeyCallback(pWindow, keyPress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glm::mat4 OpenGLController::getMVPMatrix()
|
|
|
|
|
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
|
|
|
|
{
|
|
|
|
|
// Projection
|
|
|
|
|
glm::mat4 m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView);
|
|
|
|
@@ -202,7 +202,7 @@ glm::mat4 OpenGLController::getMVPMatrix()
|
|
|
|
|
|
|
|
|
|
// Model
|
|
|
|
|
//TODO for all
|
|
|
|
|
glm::mat4 m4x4Model = vModels.front()->m4x4Translation;
|
|
|
|
|
glm::mat4 m4x4Model = vModels[index]->m4x4Translation;
|
|
|
|
|
|
|
|
|
|
// User controlled rotation
|
|
|
|
|
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
|
|
|
@@ -266,23 +266,28 @@ void OpenGLController::updateScene()
|
|
|
|
|
// use shader prgm
|
|
|
|
|
glUseProgram(gluiShaderPrgmID);
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * mvpMatrices.size(), NULL, mvpMatrices.data());
|
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
|
|
// bind texture in texture unit 0
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
|
|
|
|
// tell sampler to use texture unit 0
|
|
|
|
|
glUniform1i(gluiSamplerID, 0);
|
|
|
|
|
|
|
|
|
|
//draw objects hardcoded only 1 instance for testing
|
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, 0, vModels.front()->meshSize, 1);
|
|
|
|
|
int instanceOffset(0);
|
|
|
|
|
|
|
|
|
|
for (unsigned int modelIndex = 0; modelIndex < vModels.size(); modelIndex++)
|
|
|
|
|
{
|
|
|
|
|
// give the MVPs to the shader
|
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, gluiInstanceBufferID);
|
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), NULL, &getMVPMatrix(0));
|
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
|
|
//glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
|
|
|
|
|
|
|
|
|
|
//draw objects hardcoded only 1 instance for testing
|
|
|
|
|
glDrawArraysInstanced(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize, vModels.size());
|
|
|
|
|
|
|
|
|
|
instanceOffset += vModels[modelIndex]->meshSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glfwSwapBuffers(pWindow);
|
|
|
|
|
glfwPollEvents();
|
|
|
|
|