Sign in to follow this  
GodFear

SetTexture() method Enquiry

Recommended Posts

Hello Folks! My first post and a pleasant day to everyone. I'm very new to directx and i do have a couple of questions and i hope someone can enlighten me about it. I understand that defining different textures with a call to SetTexture() can be very expensive. However, if say i repeatedly call SetTexture() but refer to the same texture object, will directx be smart enough to realize i am setting the same texture and it will not process the succeeding calls anymore? I want to use ID3DXSPRITE to draw 2D and on its Draw() method, one of the parameters is a pointer to the texture object i want to use. I believe it internally calls SetTexture() to set the texture object i passed as parameter to Draw() method. If i repeatedly call Draw() but set the same texture object, will ID3DXSPRITE repeatedly call SetTexture() as well? Thank you very much! EDIT: I am using directx 9.0c btw :)

Share this post


Link to post
Share on other sites
Quote:
Original post by GodFear
I understand that defining different textures with a call to SetTexture() can be very expensive. However, if say i repeatedly call SetTexture() but refer to the same texture object, will directx be smart enough to realize i am setting the same texture and it will not process the succeeding calls anymore?
With a device created without the D3DCREATE_PUREDEVICE flag: Yes. If you create a pure-device, it still makes a call to the drvier, but the driver should still filter it out unless it's completely braindead.

Quote:
Original post by GodFear
I want to use ID3DXSPRITE to draw 2D and on its Draw() method, one of the parameters is a pointer to the texture object i want to use. I believe it internally calls SetTexture() to set the texture object i passed as parameter to Draw() method. If i repeatedly call Draw() but set the same texture object, will ID3DXSPRITE repeatedly call SetTexture() as well?
Yes, which is why it's usually a good idea to pass the D3DXSPRITE_SORT_TEXTURE flag to Begin() if you're going to be drawing with more than one texture. You can bitwise-OR that flag with others if you wish to combine them.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by GodFear
I understand that defining different textures with a call to SetTexture() can be very expensive. However, if say i repeatedly call SetTexture() but refer to the same texture object, will directx be smart enough to realize i am setting the same texture and it will not process the succeeding calls anymore?
With a device created without the D3DCREATE_PUREDEVICE flag: Yes. If you create a pure-device, it still makes a call to the drvier, but the driver should still filter it out unless it's completely braindead.

Quote:
Original post by GodFear
I want to use ID3DXSPRITE to draw 2D and on its Draw() method, one of the parameters is a pointer to the texture object i want to use. I believe it internally calls SetTexture() to set the texture object i passed as parameter to Draw() method. If i repeatedly call Draw() but set the same texture object, will ID3DXSPRITE repeatedly call SetTexture() as well?
Yes, which is why it's usually a good idea to pass the D3DXSPRITE_SORT_TEXTURE flag to Begin() if you're going to be drawing with more than one texture. You can bitwise-OR that flag with others if you wish to combine them.


I created my device with D3DCREATE_SOFTWARE_VERTEXPROCESSING, so i guess i should avoid calling SetTexture() if i'll just set the same texture object as it's redundant.

As for ID3DXSPRITE's Draw() method, i am only using a single texture like this:

pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );
pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );
pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );

Does ID3DXSPRITE still call SetTexture repeatedly with my multiple calls to Draw()? If yes, how do i get around it?

Thanks in advance!

Share this post


Link to post
Share on other sites
Quote:
Original post by GodFear
I created my device with D3DCREATE_SOFTWARE_VERTEXPROCESSING, so i guess i should avoid calling SetTexture() if i'll just set the same texture object as it's redundant.
The vertex processing mode doesn't affect what gets cached, just the pure device flag (Which you're not specifying). D3D will buffer SteTexture calls for you, but there can be times it's useful to do in the application.

Quote:
Original post by GodFear
As for ID3DXSPRITE's Draw() method, i am only using a single texture like this:

pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );
pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );
pd3dSprite->Draw( pMyTexture, 0,0,0,0xffffffff );

Does ID3DXSPRITE still call SetTexture repeatedly with my multiple calls to Draw()? If yes, how do i get around it?
No, ID3DXSprite is pretty smart, it'll only call SetTexture() if the texture changes. Internally, it builds a "draw list" and only draws to the device when Flush() or End() is called. When that happens, it'll draw all three sprites with a single DrawIndexedPrimitive() call, and one SetTexture() call.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this