SFML community forums

Help => Graphics => Topic started by: unlight on February 19, 2019, 11:23:12 pm

Title: Superfluous Transformations in Sprite Batch
Post by: unlight on February 19, 2019, 11:23:12 pm
Hi guys,

I am currently looking to write a Sprite Batch class to assist in rendering a large number of sprites and would like some advice so that I don't needlessly double up on transform calculations.

My approach is to write a custom Sprite class that inherits only from Transformable (not Drawable) and provides a function to get it's (untransformed) vertices. I would also write a Sprite Batch class with an "addToBatch" function that takes a custom Sprite object. The Sprite Batch would get the Sprites vertices and its Transform, apply the transform and store the resulting vertices in a Vertex Array (or Vertex Buffer).

The Sprite Batch itself would inherit from Transformable and Drawable so that it can be rendered as though it were a native SFML entity. Within the inherited draw function, it would send set the Render State's Texture and draw a bunch of Sprites in a single draw call. This seems straight forward, but I noticed in the source code for Render Target, that the Render State's Transform is applied to all of the vertices before drawing. This would mean that all vertices have had two transformations applied in total. Is this something that would be detrimental to performance?  Or am I being overly paranoid?
Title: Re: Superfluous Transformations in Sprite Batch
Post by: Hapax on February 24, 2019, 11:48:44 pm
Try it ;)

I presume that that second transformation would actually be a "no-transformation"? This would therefore be multiplied with the identity matrix. Anyway, this transformation matrix is sent directly to OpenGL; it is there that those final transformations would be applied.

I wouldn't expect it to be noticeably detrimental to performance, especially since OpenGL will always have some transformation.
Title: Re: Superfluous Transformations in Sprite Batch
Post by: unlight on February 27, 2019, 02:11:52 pm
Oh nice, I didn't realise that the final transformation was applied through OpenGL. Thank you very much for the reply!