SetMaterial & SetTexture
Hi,
I would like to know if this will slow down the rendering loop or not. Assuming I have a sorted list of materials; 10 red, 5 yellow, and 16 blue. If they are not sorted, there will be a big performance problem because of too many SetMaterial switches. My question is, after sorted, there are only three switches. However, for 10 red, I am still doing:
// For red
for(int i=0;i<10;i++){
g->SetMaterial(Red);
g->....draw the mesh here;
}
In this case, does that 9 extra SetMaterial actually count as switches so it will degrade the performance like unsorted list?
Thank you very much,
Andy
If it's not a pure device, it might have redundant state change checks, but I wouldn't rely on it. What you really ought to do is code some sort of render queue system that does the sort, then binds each material/texture and renders everything that's using it.
Thank you for replying. My SceneManager is using SceneGraph as the data structure. So when SceneManager is rendering the meshes under a group, every leaf(mesh) has their own SetMaterial and SetTexture even though some of them are using the same ones. So if I am not using RenderQueue, how do I counter this?
Thanks in advance,
Andy
Thanks in advance,
Andy
The cheap, slightly hackish way is to simply keep track of what texture and material you're using, and do the check yourself.
Althouhg I would encourage you to try a queueing mechanism...it's like a breath of fresh air.
Althouhg I would encourage you to try a queueing mechanism...it's like a breath of fresh air.
One of the important functions of a good SceneGraph is to group the entities together, based upon their material properties. I group objects in the following order:
- Shader
- Textures
- Non-Matrix Constants
- Matrix Constants
This way, I can batch objects quickly and efficiently. You do not want to put all the objects into one queue, then have an algorithm that linerarlly sorts them - this takes up too much time (especially if you have lots of objects and critera to sort upon). If you code a good scene graph that can categorize nodes efficiently, you will be much better off.
- Shader
- Textures
- Non-Matrix Constants
- Matrix Constants
This way, I can batch objects quickly and efficiently. You do not want to put all the objects into one queue, then have an algorithm that linerarlly sorts them - this takes up too much time (especially if you have lots of objects and critera to sort upon). If you code a good scene graph that can categorize nodes efficiently, you will be much better off.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement