Skip to main content
Sign in
Snippets Groups Projects
Commit ed66d77b authored by Anakin's avatar Anakin
Browse files

still trying to draw instanced

parent 8a36fe10
No related branches found
No related tags found
No related merge requests found
......@@ -94,7 +94,7 @@ private:
void startGLEW();
void setCallbackFunctions();
glm::mat4 getMVPMatrix();
glm::mat4 getMVPMatrix(unsigned int index);
////////////////////////////////////////////////////////////////////////////////////////////
......
......
......@@ -12,12 +12,12 @@ layout(location = 2) in mat4 mvp;
out vec2 UV;
// Values that stay constant for the whole mesh.
//uniform mat4 MVP;
uniform mat4 MVP;
void main(){
// Output position of the vertex, in clip space : MVP * position
gl_Position = mvp * vec4(vertexPosition_modelspace, 1);
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
UV = vertexUV;
......
......
......@@ -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);
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, 0, vModels.front()->meshSize, 1);
glDrawArraysInstanced(GL_TRIANGLES, instanceOffset, vModels[modelIndex]->meshSize, vModels.size());
instanceOffset += vModels[modelIndex]->meshSize;
}
glfwSwapBuffers(pWindow);
glfwPollEvents();
......
......
......@@ -38,7 +38,7 @@ int main(int argc, char** argv)
openGL:
scene->loadMsh("..\\Release\\Msh\\cubeTrans.msh");
scene->loadMsh("..\\Release\\Msh\\houseWOnull.msh");
do {
scene->updateScene();
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment