i'll paste it in for ease:
"Good state sorting generally requires both a preprocessing and a realtime pass. Your objects or instances should be presorted by material (or shader/parameters, if you use a shader based approach). This is only needed, if an object is built from more than a single material, but this is often the case. Let's call those presorted object parts 'subobjects'. Each subobject has a unique material (or shader-parameter pair), several subobjects form an object. You only store the object in the scenegraph. The object contains a pointer to its child subobjects.
In realtime, as soon as an object is considered visible, you process all subobjects. Here, you have several possibilities. You could add the subobjects to material lists, as sBibi suggested. A hashing algorithm could help, if you have a large number of materials. This approach usually works well, if you work with simple materials, but has a huge drawback on complex material or shader based approaches. Imagine having several subobjects of the same shader (material class), but different parameters. For example, you have 6 subobjects with the shader 'diffuse texture'. 3 have texture "bricks", and 3 have the texture "wood". Since all have the same material class, they will all be added to the same list. That is OK so far. But as there is no inherent order in which they will be processed (viewpoint dependent), they could be added to the material list in any order. Imagine this situation:
List(diffuse texture) -> SubObj0(wood) -> SubObj2(bricks) -> SubObj3(wood) -> SubObj4(bricks) -> ...
As you can see, all diffuse texture subobjects are grouped, reducing state changes. But their parameter (the texture) is not, requiring a texture bind at every subobject. Not good.
An alternative is to sort (radix/merge/quicksort) by material and parameter(s) every frame. That will cost more performance, but can be very worthwhile on complex scenes with many different materials. In this case, you only have one single render list (instead of multiple ones as above), where you simply dump all visible subobjects. It doesn't have to be a linked list, a simple array will do. Then, just before rendering, you sort the whole list by shader/paramater:
List before sorting (same order as above):
List after sorting:
The parameters are now also grouped, reducing the number of required state changes even more."
Yann L - http://www.gamedev.net/community/forums/to...topic_id=183462