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

Author Topic: Performance: scaling size VS switching textures around  (Read 2823 times)

0 Members and 1 Guest are viewing this topic.

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Performance: scaling size VS switching textures around
« on: January 24, 2012, 08:08:21 am »
I understand that between Draw calls if sprites are drawn from different textures, it takes a performance hit, since opengl has to bind to another texture every time.

I am wondering what is more expensive when I want to use the same sprites, but different sizes. Should I pre-make my textures separately, such that SFML/opengl doesn't need to scale them, or should I just scale the same texture, as the texture switching between each Draw call might cost more than the scaling?

(In a context where 300-500 3x3 to 30x30 particles are drawn each frame)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Performance: scaling size VS switching textures around
« Reply #1 on: January 24, 2012, 08:26:47 am »
Scaling a sprite doesn't cost anything. Every entity is transformed by a matrix on the GPU, whether it is the identity or a scaling matrix doesn't make any difference.

But, changing the current transform matrix takes time too.

So the best solution would be to move / resize all your particles with the CPU, put them into a vertex array (latest SFML 2) and draw that with one OpenGL call.
Laurent Gomila - SFML developer

ChonDee

  • Jr. Member
  • **
  • Posts: 62
    • View Profile
Performance: scaling size VS switching textures around
« Reply #2 on: January 24, 2012, 08:51:29 am »
Quote from: "Laurent"
Scaling a sprite doesn't cost anything. Every entity is transformed by a matrix on the GPU, whether it is the identity or a scaling matrix doesn't make any difference.

But, changing the current transform matrix takes time too.

So the best solution would be to move / resize all your particles with the CPU, put them into a vertex array (latest SFML 2) and draw that with one OpenGL call.


Thanks for the fast reply,I'll use one base size texture then. I'll look into the vertex arrays now, I haven't used that before.

EDIT:
A similar question. If there are same sprites that I want to draw, but different color, is it expensive to do Sprite.SetColor compared to dealing with a Sprite set to a pre-colored texture?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Performance: scaling size VS switching textures around
« Reply #3 on: January 24, 2012, 09:03:01 am »
Quote
A similar question. If there are same sprites that I want to draw, but different color, is it expensive to do Sprite.SetColor compared to dealing with a Sprite set to a pre-colored texture?

SetColor is cheap, it assigns the color to the 4 vertices of the sprite (which live in system memory).
Laurent Gomila - SFML developer