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

Author Topic: Superfluous Transformations in Sprite Batch  (Read 1817 times)

0 Members and 1 Guest are viewing this topic.

unlight

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Superfluous Transformations in Sprite Batch
« 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?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Superfluous Transformations in Sprite Batch
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

unlight

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: Superfluous Transformations in Sprite Batch
« Reply #2 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!