I'm kind of new to openGL and GLSL, so I"m not that familiar with all the proper uses yet. Like glUniform.
So here's my sitiuation: I'm currently working on a game engine that uses openGL.
I've made a DisplayObject that can render out 3D object from data stored in VBO's and a GLSL shader. It also uses a home-made matrix class for storing model-view, normal and modelview-projection matrices which the GLSL shader can use.
I"m currently reading through the OpenGL Shading Language book (orange book) and in there the writers state that uniform attributes should only be used with data that doesn't change frequently. So what I did is declare the matrices in the shader as uniforms and made a neat updateMatrices() function for my DisplayObject class that is called everytime a transformation is done to the object (for example when it translates or rotates). This function updates the matrices and then sends the new information to the GLSL shader using glUniform. Now this all works just fine when using one object, but when I introduce a second object or more, all the objects are snapped to the coordinates and orientation of the object that did the last transformation.
After some time of debugging I was able to fix this by calling chop the glUniform calls out of updateMatrices and call just before every object is drawn instead. Even though this works, I'm really doubting if I did the right thing here, because what I'm now doing is sending matrix data to the shader even though the values didn't change.
void DisplayObject::render()
{
if ( readyToRender )
{
glBindVertexArray(vaoName);
/* send new matrices to the shaderprogram */
glUniformMatrix4fv(glGetUniformLocation(program, "mvMatrix"), 1, GL_FALSE, modelmatrix.data);
glUniformMatrix4fv(glGetUniformLocation(program, "normMatrix"), 1, GL_FALSE, normalMatrix.data);
/* send new modelview-projection matrix to the shaderprogram */
modelmatrix = modelmatrix * *projectionmatrix;
glUniformMatrix4fv(glGetUniformLocation(program, "mvpMatrix"), 1, GL_FALSE, modelmatrix.data);
glDrawElements(GL_TRIANGLES, bufferSize[index], GL_UNSIGNED_INT, 0);
}
}So my question now is: am I doing the right thing and if not: how do you guys suggest I should send the matrix data to the shader?
Many thanks in advance ;)






