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

Author Topic: Dereferencing sf::RenderTexture::GetTexture()'s return value  (Read 3250 times)

0 Members and 1 Guest are viewing this topic.

zeocyte

  • Newbie
  • *
  • Posts: 9
    • View Profile
Dereferencing sf::RenderTexture::GetTexture()'s return value
« on: December 23, 2011, 09:19:44 am »
This suggestion is just for convenience. Perhaps we could an overloaded version of sf::RenderTexture's GetTexture() which returns a copy of sf::RenderTexture's texture.

Please note that we will not be wasting resources when done in this way for we can "recycle" an sf::RenderTexture (in other words, use it to create another texture). But then we will have to modify sf::RenderTexture::Create() to free the previous resources used (I have looked into the code).

Hoping for Laurent's very kind consideration.  :wink:
Everything is predetermined.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Dereferencing sf::RenderTexture::GetTexture()'s return value
« Reply #1 on: December 23, 2011, 09:27:06 am »
As long as sf::Texture is copyable, you can create copies even if a reference is returned.
Code: [Select]
sf::Texture copy = renderTexture.GetTexture();
Or did I totally misunderstand your request?
Laurent Gomila - SFML developer

zeocyte

  • Newbie
  • *
  • Posts: 9
    • View Profile
Dereferencing sf::RenderTexture::GetTexture()'s return value
« Reply #2 on: December 23, 2011, 09:30:45 am »
I had recently looked into the = operator of sf::Texture and it "returns" a reference and not a copy. In my suggestion, it implies that we can use just one instance of sf::RenderTexture to create many instances of sf::Texture. We cannot do this however, if GetTexture() returns only references.
Everything is predetermined.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Dereferencing sf::RenderTexture::GetTexture()'s return value
« Reply #3 on: December 23, 2011, 09:51:12 am »
Quote
I had recently looked into the = operator of sf::Texture and it "returns" a reference and not a copy

Every operator = returns a reference, it's the standard prototype. It doesn't mean that they don't do their job correctly. If you think about it, it would make no sense if it returned a copy.

Textures are copyable, so you can... copy them, it works. Stop looking at the code and making false assumptions about it, just trust me (or read more C++ books if you don't) ;)
Laurent Gomila - SFML developer