still trying to draw instanced
This commit is contained in:
parent
8a36fe10b1
commit
ed66d77b69
|
@ -94,7 +94,7 @@ private:
|
||||||
void startGLEW();
|
void startGLEW();
|
||||||
void setCallbackFunctions();
|
void setCallbackFunctions();
|
||||||
|
|
||||||
glm::mat4 getMVPMatrix();
|
glm::mat4 getMVPMatrix(unsigned int index);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -12,12 +12,12 @@ layout(location = 2) in mat4 mvp;
|
||||||
out vec2 UV;
|
out vec2 UV;
|
||||||
|
|
||||||
// Values that stay constant for the whole mesh.
|
// Values that stay constant for the whole mesh.
|
||||||
//uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
|
|
||||||
// Output position of the vertex, in clip space : MVP * position
|
// 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;
|
UV = vertexUV;
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ void OpenGLController::setCallbackFunctions()
|
||||||
glfwSetKeyCallback(pWindow, keyPress);
|
glfwSetKeyCallback(pWindow, keyPress);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 OpenGLController::getMVPMatrix()
|
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
|
||||||
{
|
{
|
||||||
// Projection
|
// Projection
|
||||||
glm::mat4 m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView);
|
glm::mat4 m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView);
|
||||||
|
@ -202,7 +202,7 @@ glm::mat4 OpenGLController::getMVPMatrix()
|
||||||
|
|
||||||
// Model
|
// Model
|
||||||
//TODO for all
|
//TODO for all
|
||||||
glm::mat4 m4x4Model = vModels.front()->m4x4Translation;
|
glm::mat4 m4x4Model = vModels[index]->m4x4Translation;
|
||||||
|
|
||||||
// User controlled rotation
|
// User controlled rotation
|
||||||
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
|
||||||
|
@ -266,23 +266,28 @@ void OpenGLController::updateScene()
|
||||||
// use shader prgm
|
// use shader prgm
|
||||||
glUseProgram(gluiShaderPrgmID);
|
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
|
// bind texture in texture unit 0
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
glBindTexture(GL_TEXTURE_2D, gluiTextureID);
|
||||||
// tell sampler to use texture unit 0
|
// tell sampler to use texture unit 0
|
||||||
glUniform1i(gluiSamplerID, 0);
|
glUniform1i(gluiSamplerID, 0);
|
||||||
|
|
||||||
//draw objects hardcoded only 1 instance for testing
|
int instanceOffset(0);
|
||||||
glDrawArraysInstanced(GL_TRIANGLES, 0, vModels.front()->meshSize, 1);
|
|
||||||
|
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);
|
glfwSwapBuffers(pWindow);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
|
@ -38,7 +38,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
openGL:
|
openGL:
|
||||||
|
|
||||||
scene->loadMsh("..\\Release\\Msh\\cubeTrans.msh");
|
scene->loadMsh("..\\Release\\Msh\\houseWOnull.msh");
|
||||||
|
|
||||||
do {
|
do {
|
||||||
scene->updateScene();
|
scene->updateScene();
|
||||||
|
|
Loading…
Reference in New Issue