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

Author Topic: sf::RenderTarget::setActive  (Read 4836 times)

0 Members and 1 Guest are viewing this topic.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
sf::RenderTarget::setActive
« on: October 06, 2016, 01:49:59 am »
Continuing from this discussion:

It seems like an inconsistency or at least weirdness that all the subclasses of sf::RenderTarget themselves do expose a setActive method, however sf::RenderTarget does not expose the same itself. This makes it harder to write generic code that is agnostic to the concrete sf::RenderTarget implementation but still has to be interleaved in a reliable way with raw OpenGL rendering.

Conceptually, a render target that can be used for sfml-graphics drawing should also provide the possibility for non-sfml-graphics rendering i.e. OpenGL. Support for this is already partially provided via sf::RenderTarget::pushGLStates, sf::RenderTarget::popGLStates and sf::RenderTarget::resetGLStates, however if one wants to take state management into ones own hands, there is no way to activate the sf::RenderTarget's context otherwise.

What I suggest is exposing a completely identical setActive() method as the subclasses and simply forwarding the call through to whatever concrete class lies underneath via activate() which is already available.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11035
    • View Profile
    • development blog
    • Email
AW: sf::RenderTarget::setActive
« Reply #1 on: October 06, 2016, 02:12:55 am »
Sounds good to me. What was (potentially) the reason why it wasn't added in the beginning?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::RenderTarget::setActive
« Reply #2 on: October 06, 2016, 05:35:03 pm »
Quote
What I suggest is exposing a completely identical setActive() method as the subclasses and simply forwarding the call through to whatever concrete class lies underneath via activate() which is already available.
Why not making setActive virtual directly, and getting rid of activate?

Quote
What was (potentially) the reason why it wasn't added in the beginning?
Most likely for historical reasons. If I remember correctly, when sf::RenderTexture was born it was not supposed to have its own context, thus making setActive a Window (& derived) thing only.
« Last Edit: October 06, 2016, 05:36:44 pm by Laurent »
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::RenderTarget::setActive
« Reply #3 on: October 06, 2016, 07:51:46 pm »
Why not making setActive virtual directly, and getting rid of activate?
For me, it would end up looking really strange implementing a virtual function that dispatches to a sibling class. setActive() is implemented in sf::RenderTexture and sf::Window. sf::RenderWindow just inherits it from sf::Window. This would mean that we would have to override sf::RenderTarget's setActive() in sf::RenderWindow and it would just end up calling setActive() of the sf::Window. Following Herb Sutter's guidelines, making a publicly accessible function virtual isn't something I would take too lightly anyway. ;)
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::RenderTarget::setActive
« Reply #4 on: October 06, 2016, 10:35:03 pm »
We already have the exact same thing with getSize(), by the way.

Quote
Following Herb Sutter's guidelines, making a publicly accessible function virtual isn't something I would take too lightly anyway
In this context I'm totally fine with that. And we already have such functions anyway.
Laurent Gomila - SFML developer

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: sf::RenderTarget::setActive
« Reply #5 on: October 06, 2016, 11:48:35 pm »
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).