sort by depth, what about shaders?

I have this huge list of billboards that needs to be rendered every frame. The list is sorted by depth for correct blending.

But now some of the objects have a vertex program for effects; so there could be hundreds of gl calls to enable/bind/disable the vertex programs. Is this an issue to toggle them so often? I cannot think of a trick to have the list depth-sorted while still minimizing these calls.

The same is also for texture switches, I have minimized this by having multiple objects in a single texture “sheet” but if there are still say 20 switches this is really bad, no?

Yup that could be bad, you’re going to have to figure out how to optimize based on the slowest mode switch to the fasters, perhaps compromising on depth sorting or being smart about where you can sort by state and where you can’t.

I just added some code to log things, and found out I have actually well over 300 texture switches due to those many objects each using a different texture.

I don’t notice too much slowdown on my ATI but I guess it wouldn’t perform so well on older cards?

I realize this problem is not OpenGL specific but if anyone had an idea how to state-sort objects in a scene but at the same time having correct depth sorting (crucial for blending), I would be very grateful.