Matrix stacks in OpenGL 3.x

Hello,

This is probably not a very advanced topic, but then again, I’m starting a bigger project and I would like to hear opinions from people who are into OpenGL coding for good and could give me a very good advise.

What I’m looking into is how to go around missing matrix stacks in GL3.

The first quick idea was to create a class that would hold:
vector<matrices> //vector of all matrices
vector<premultipliedmodelview> //premultiplied MV
vector<premultipliedinversemodelview> //premultiplied inverse MV
+
matrix4x4projection

But then again, I wasn’t coding some time and I’m missing all those practical skills in geometry shaders, so I have no idea if this scheme won’t backfire at me later on when I’ll have to code some advanced effects.

So what do you guys recommend, should I head this way, or do you do all matrix algebra in shaders nowadays, including inverse transformations?

Or maybe there is a industry accepted library that you would recommend me to use instead of writing my own?

There was another post on the same topic.

This problem of replacing important functionality deprecated by GL3 is still new and libraries are developing to fill the need. You will still need to do matrix operations but send the final values to the shaders.

I have been using GLM Mathematics and I am starting to no longer miss the old way of doing matrix operations :slight_smile: GLM has some nice samples based on GL3 and GLM that are a good start. You may get some benefit studying how this library deals with just the questions you ask. It is nice that it already has all the matrix/vector/ortho operations in the library for you.

PS Are you developing on linux or windows or Mac or other?

You could try implementing your own matrix stack that replicates the functionality of the fixed function OpenGL matrix stack. For ideas on how to implement this I’d suggest looking at the Mesa3D source code.

I’m starting a bigger project and I would like to hear opinions from people who are into OpenGL coding for good and could give me a very good advise.

OpenGL matrix stack is just a way to organize your spatial transformation data.
Once you established the spatial class structure - you only need some auto-shader-parameters binding mechanics to pass the transform information to shaders that require it.

Here’s how I deal with spatial data:
http://code.google.com/p/kri/wiki/SpatialHierarchy

I’m actually passing such transforms as:
model->world
camera->world
light->world

Then I do some inverses and combinations in the vertex shader to get the final set of transforms.
It’s quite cheap in case of proposed spatial structure (using quaternions).