Shaders and matrix usage, best practice

Started by
2 comments, last by V-man 13 years, 2 months ago
Coming from working with XNA for over a year I'm now starting a project using OpenTK and am after some advice on best practice regarding matrix usage in shaders.

In XNA, it's common to pass a complete set of World, View and Projection matrices into shaders and have them transform vertex positions by the WVP in the vertex function. I'm wondering if this is a good thing to do in OpenGL given the fact that it has the ability to use matrix stack? Are there any underlying performance benefits from using the OpenGL matrix stack VS passing in absolute WVP matrices into my shaders?

Thanks
Advertisement
Nope no performance benefit, just use your own WVP matrices. The matrix stack is a relic of time long gone, it doesn't really serve a purpose anymore, so it's deprecated now. Uniform matrix uploads are what you want to be doing.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

Nope no performance benefit, just use your own WVP matrices. The matrix stack is a relic of time long gone, it doesn't really serve a purpose anymore, so it's deprecated now. Uniform matrix uploads are what you want to be doing.


Thanks, much appreciated :)
http://www.opengl.org/wiki/FAQ#glTranslate.2C_glRotate.2C_glScale
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement