Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Expensiveness of changing the texture [solved]  (Read 1471 times)

0 Members and 1 Guest are viewing this topic.

mSamyel

  • Newbie
  • *
  • Posts: 2
    • View Profile
Expensiveness of changing the texture [solved]
« 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~
« Last Edit: January 26, 2014, 08:46:13 am by mSamyel »

krzat

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Expensiveness of changing texture
« Reply #1 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.
« Last Edit: January 26, 2014, 09:28:17 am by krzat »
SFML.Utils - useful extensions for SFML.Net

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Expensiveness of changing texture
« Reply #2 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  ;)
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

mSamyel

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Expensiveness of changing texture
« Reply #3 on: January 26, 2014, 08:33:55 am »
Understood :) Thank you very much!

 

anything