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

Author Topic: RenderStates const ref in draw()  (Read 1075 times)

0 Members and 1 Guest are viewing this topic.

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
RenderStates const ref in draw()
« on: May 10, 2023, 06:05:30 pm »
Regarding SFML master (v3-WIP).

I noticed that render states in the virtual draw method of a drawable is now a const reference (instead of by value) and I wonder what the reason behind this decision was as I can't find any information or discussion yet other than an old post saying that it wouldn't happen ;)

Old post: https://en.sfml-dev.org/forums/index.php?topic=17102.0

To be clear, I'm not at all saying it's a wrong decision (just because I had to modify lots of code ;D) but wondered why the decision was changed. Maybe now it's better to be (possibly) more optimised over simplicity?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Thrasher

  • Moderator
  • Jr. Member
  • *****
  • Posts: 53
    • View Profile
Re: RenderStates const ref in draw()
« Reply #1 on: May 10, 2023, 07:44:30 pm »
https://github.com/SFML/SFML/pull/2008

The previous version meant all draw calls necessarily copied RenderStates. Now that copy only happens when required. You have to explicitly make a copy if you want a copy but you're not forced to pay the price of that copy if you don't need it.

Hapax

  • Hero Member
  • *****
  • Posts: 3360
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: RenderStates const ref in draw()
« Reply #2 on: May 10, 2023, 09:16:12 pm »
That's what I presumed - optimising for speed rather than simplicity. That does sound like I meant it negatively but I think it's a good choice here with a choice that happens every single draw call. It's trivial to make a copy if one needs it anyway; it's just a new habit to get into (since I almost always do make that copy).

I only noticed it when it refused to compile and wanted to know if it was a decision that's been made for SFML3 or it's being tried out so I think you've answered that now, so thank you. :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything