SFML community forums
Help => General => Topic started by: ChonDee 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)
-
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.
-
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?
-
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).