SFML community forums

General => Feature requests => Topic started by: zeocyte on December 23, 2011, 09:19:44 am

Title: Dereferencing sf::RenderTexture::GetTexture()'s return value
Post by: zeocyte 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:
Title: Dereferencing sf::RenderTexture::GetTexture()'s return value
Post by: Laurent 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?
Title: Dereferencing sf::RenderTexture::GetTexture()'s return value
Post by: zeocyte 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.
Title: Dereferencing sf::RenderTexture::GetTexture()'s return value
Post by: Laurent 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) ;)