This is not OpenGL related, but since everybody is talking shaders let’s change subjects a little bit… In my engine, per frame, I use 3 quicksorts to group faces with the same shader. But I’m gruping, not sorting, so there must be a better way to do it without using quicksort. What I need is simply an algorithm to group stuff faster than quicksort. I can’t find anything like that, so can anyone help me?
Why not make all like type surfaces there own objects. That way when you set your shader you can draw one object per different shader. That’s what I do…but not for shaders, I don’t know shaders yet; I do it for like type surfaces.
If your number of objects is reasonable, you can build a list of visible objects. Then iterate over the list, once per shader, and draw only the objects that use the currently bound shader. When compared to the cost of transform and rendering (and physics/simulation) a few extra passes over your list is probably never going to show up in a profile.
On the other hand, because this traversal is so comparatively cheap, you might as well use the qsorts that you’ve already implemented. I doubt it’ll be a performance problem. Has it shown up in a profiler yet? (There’s an evaluation copy of VTune on the Intel developer site, for example)