SFML community forums

Help => Graphics => Topic started by: mSamyel on January 25, 2014, 10:05:15 pm

Title: Expensiveness of changing the texture [solved]
Post by: mSamyel on January 25, 2014, 10:05:15 pm
Hello everyone!

I am creating my first game in SFML and I am curious about one sentence in the sprite tutorial:
Quote
changing the current texture is an expensive operation for the graphics card

Now, I have a drawing engine class, which contains a vector of textures (I use different textures for images with different subimage size to make picking subimage easier for me) and it has a Draw() function which other objects can call and it will create a new sprite, assign it one of the textures, cut out the rectangle of the subimage and draw it on the window surface.

Now I wonder if the setTexture() function causes the operation of which the tutorial speaks (changing the current texture)... and if I should rather predefine sprites and assign a texture to them in advance. Or is my approach ok and not too resource-wasting?

Thank you for your time~
Title: Re: Expensiveness of changing texture
Post by: krzat on January 25, 2014, 11:55:14 pm
No. It means that GPU has to do extra work every time texture being drawn changes. For example this:
window.draw(sprite1);
window.draw(sprite1);
window.draw(sprite2); //GPU changes current texture
 
May be slower than this:
Previous will be faster than the following
window.draw(sprite1);
window.draw(sprite2);  //GPU changes current texture
window.draw(sprite1);  //GPU changes current texture
 
Assuming sprite2 uses different texture than sprite1.

EDIT: @zsbzsb: Good catch, thanks.
Title: Re: Expensiveness of changing texture
Post by: zsbzsb on January 25, 2014, 11:58:44 pm
No. It means that GPU has to do extra work every time texture being drawn changes. For example this:
window.draw(sprite1);
window.draw(sprite1);
window.draw(sprite2); //GPU changes current texture
 
May be slower than this:
Previous will be faster than the following
window.draw(sprite1);
window.draw(sprite2);  //GPU changes current texture
window.draw(sprite1);  //GPU changes current texture
 
Assuming sprite2 uses different texture than sprite1.

Fixed for you  ;)
Title: Re: Expensiveness of changing texture
Post by: mSamyel on January 26, 2014, 08:33:55 am
Understood :) Thank you very much!