openframeworks/openFrameworks — pull request #2694 by tgfrerer (2013-11-27 11:00:29+00:00)
Title: feature add read-only access to current Matrix Stack

this is a clean PR and a replacement for PR #2479.

Original PR message:

having access to the matrix stack is really useful - the canonical example would be: if you want to push a normalMatrix to the shader (calculated once per frame on the CPU, used as a const many many times on the GPU):

ofMatrix4x4 modelViewMatrix = ofGetGLProgrammableRenderer()->getCurrentMatrix(OF_MATRIX_MODELVIEW);
ofMatrix4x4 normalMatrix = ofMatrix4x4::getTransposedOf(modelViewMatrix.getInverse());
mShd1.setUniformMatrix4f("normalMatrix", normalMatrix);

Otherwise, you'd have to calculate the normal matrix in the vertex shader (per-vertex) or even in the fragment shader (per pixel!):

mat4 normalMatrix = transpose(inverse(modelViewMatrix));

Matrix inverses are amongst the most costly GLSL operations.