Jump to content
  • Advertisement
Sign in to follow this  
hksduhksdu

SetMaterial & SetTexture

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!