Changing subjects a little bit

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?


A simple list should be enough.

foreach(mono_shaded_entity e)

I don’t think per-face shading is great, you should split your objects in subobjects based on which shader they use.

What if you just kept three separate groups and inserted the faces into groups as you iterated through the faces?


how small are your lists? … for size < 10-20 you’d probably do better with insert sort or something similiar.

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)

why dont u sort before the scene starts ie not during runtime