GSoC project: Sprite engine overhaul - Weekly A&O report #3
Time for this weeks A&O report.
As indicated by last weeks objectives, I've started reducing the Fixed Function Pipeline (FFP) code,
which became obsolete with GL2 and finally deprecated with GL3/GLES2.
In particular I refactored pretty much all of the matrix related code.
So for me it was just doing some applied linear algebra that week.
OpenGL1 had a so called Matrix stack functioning like this:
Backs up the current matrix.
Most GL implementations don't provide pusing more than 16 times, however Hedgewars required only one time.
Restores the most recently pushed matrix.
Sets the current matrix to identity (1)
glScale, glTranslate, glRotate, glOrtho2d, (gl utility funcs gluPerspective gluOrtho):
Multiply the current matrix with specific matrices thus chaining the mapping.
These functions allowed for easy chaining of transformations like:
glRotate(), glTranslate(), glScale() would first rotate the object around its center
then move it along the rotated coordinate system and then scale the object.
As already stated this functionality became completley stripped at some point.
So I either had to emulate existing functionality with an own matrix stack and replacement versions of all the above functions, or I could explicitly calculate matrices
The later option was quite a nice way to go, as Hedgewars first of all just uses 2d transforms
and futhermore all of them were composed like "translate rotate translate".
Thus replacing the reoccuring pattern of:
glPushMatrix() glTranslate(x, y, 0) glRotate(angle, 0, 0, 1); glTranslate(s, t, 0);
m = calculate(x, y, angle, s, t); glLoadMatrix(m);
was a quite straight way to go, as opposed to use full blown matrix multiplications.
To keep the impact of the changeset low I decided to not have some god-function as calculate() above,
but provided utility funcs that semantically mimic the initial variant, operating on a global variable.
Thus the final code now looks like:
SetOffset(x, y); SetRotation(angle); AddOffset(s, t); UpdateModelview;
Optimally the Reset wouldnt be required, but I couldnt get it changed thus far yet, due to how the rendering funcs are used.
By next week you might already expect an initial GL2 version.
I'll probably go in two steps here though.
The initial version would use a plain compatibility shader using ftransform() and fixed function pipeline as well as the ffp passed glColor.
After this s accomplished I'll replace both, the tinting (which already has a shared update point with the tint() function) and the matrix
related code, which became one with UpdateModelview, with uniforms.
Once this is done we should have GL3 and ES2 compatibility for most parts.