PDA

View Full Version : Matrix stacks in OpenGL 3.x



M/\dm/\n
11-12-2009, 05:47 PM
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?

marshats
11-12-2009, 07:56 PM
There was another post on the same topic (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=266620#Post2666 20).

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 (http://glm.g-truc.net/) and I am starting to no longer miss the old way of doing matrix operations :) GLM has some nice samples (http://www.g-truc.net/post-0204.html) 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?

dpoon
11-12-2009, 10:30 PM
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.

DmitryM
11-13-2009, 06:48 AM
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).