   Help! Sort the render objects based on material
  as I try to sort my objects before rendering based on material.(to reduce the device state change when it is rending!)But I really don't known how to do it.could someone help me?Which data structor should I take and What shall I focus on?thx   
  You could sort things by shader and then for each shader sort by textures used.If you're using a texture atlas then texture changes wouldn't be a problem so sorting by shader would be a good approach to keep state changes down to a minimum.Don't forget to render semi-transparent objects over the top of the rest of the scene.   ;  Here's a great article on how it's done in a couple of games (God of War I believe).  http://realtimecollisiondetection.net/blog/?p=86You could also just create an integer index for each material.  Each mesh would reference it's index.  Sort meshes based on this integer.  Or just give each mesh a pointer to a material and sort on the pointer's value.Cheers, Bob   ;Quote:Original post by ScourageHere's a great article on how it's done in a couple of games (God of War I believe).  http://realtimecollisiondetection.net/blog/?p=86I was going to recommend the same link, but this one is also useful:http://home.comcast.net/~tom_forsyth/blog.wiki.html#[[Renderstate%20change%20costs]];  thx everybody!sorry,maybe I haven't describe my problem clarity.let me once again:now My objects have a pointer for its material. and I wanna sort the obejct by the material.and then my problem is I don't know how to use the material value.if there are to object A and B. they have thier won material MA,MB. then,I want to get the way to compare the MA and MB.could you gave me some ways or datastructurs to do this work? I really cann't deal with this.thx everyone   ;  Use bucket sort. Give each material an unique interger id. For each id create a bucket which is infact just an array of pointers to render objects. Each frame clear the bucket counters, then start culling your object (=ignore objects you dont want to render). For each object you want to render, get the material id, access the according bucket (array look-up, where id = index) and add the render object to the bucket (bucketArray[bucketCounter++]=renderObject).After all objects has been culled or added to an bucket, start rendering the buckets, where you only need to update the render state once per bucket.Simple and effective.--Ashaman;  I use std::map for the bucket sorting.  But I've never done any testing to see if that is a bad choice or not.   