Archived

This topic is now archived and is closed to further replies.

frequent calls to glBindTexture() and D3DDevice8->SetTexture ()

This topic is 5807 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

Hello, This question relates to both D3D and OGL so I though I ask here. I was wandering if there is any performance hit involved with calling any of these functions, ie glBindTexture() and D3DDevice8->SetTexture(), even if we are setting the same texture over and over. I ask this because I have a wrapper class for both OGL and D3D. There is a method named RenderPrimitive, to which I pass all the required textures for the primitive (ie Base texture, lightmap...). which means I have to set these texture everytime this method is called. Plus at the end I render dynamic lights as overlay texures (ie using alpha blending). Now that''s quite a few calls to glBindTexture or SetTexture. Is this advisable or are there any ways around it. I tried making a few methods like SetTexture() and SetLightmap() for my wrapper class, allowing the user to set the textures themselves, so if a change of texture is not needed, fewer calls are made, but that has its own complications. Note that RenderPrimitive() is called, say once for every patch in the terrain, or once per mesh in a model. Any thoughts or suggestions is greatly appreciated. Thanks, Poya

Share this post


Link to post
Share on other sites
Reading the debug output messages from D3D I''ve noticed that calling SetTexture repeatedly invokes the response "Ignoring Render State Change", (or words to that effect), so it''s obviously doing some checking before making the call to hardware.

I don''t know if this checking is only limited only to the debug DX libraries, but I would doubt it.

Regards

Matt



Share this post


Link to post
Share on other sites
OpenGL also does this redundant state check, but either OpenGL or D3D: you''ll still have overhead. Function call, the checking itself, perhaps some more processing. You should avoid it, whenever possible, esp. doing it on a per-face base is a bad idea. You will lose performance. If this performance hit is acceptable for your specific application is another question, though. A simple solution would be to do the checking yourself. Remember the currently active texture state, and compare it to the texture of the face. Call BindTexture / SetTexture only if it changed. A simple compare would be the only overhead involved.

Share this post


Link to post
Share on other sites