SFML community forums

Help => Graphics => Topic started by: JunkerKun on July 28, 2013, 05:20:29 pm

Title: sf::RenderTexture as a normal texture?
Post by: JunkerKun on July 28, 2013, 05:20:29 pm
Hello.

Is it a good idea to keep RenderTexture in a memory and use it as a normal Texture after everything needed had been drawn to it?

I mean, I need to create a sprite made of two other sprites. To not just draw two sprites on top of each other (I need the sprite to be half-transparent and not being able to see a bottom sprite throught the top one) I want to render them both in a RenderTexture and use it as a Texture.

Should I keep the RenderTexture or just render sprites to it in a real time? I don't think the second is a good idea since it may be a lot of sprites like that on the screen.

Is there any other way to do that?
Title: Re: sf::RenderTexture as a normal texture?
Post by: eXpl0it3r on July 28, 2013, 07:14:10 pm
From what I understand on what's going on in the background, it's totally okay to keep the RenderTexture around and use its texture. In an abstract way you can look at Texture and RenderTexture as the same thing, with the difference that the RenderTexture provides functions to change itself on the GPU memory.
Title: Re: sf::RenderTexture as a normal texture?
Post by: Nexus on July 28, 2013, 07:25:42 pm
However, if you don't change the render texture anymore, I recommend to store a separate texture.

sf::RenderTexture is a relatively expensive resource, since it uses an OpenGL texture, a framebuffer object (and with the current implementation even an own context if I remember correctly). Thus, for storage only you should definitely prefer sf::Texture.
Title: Re: sf::RenderTexture as a normal texture?
Post by: JunkerKun on July 28, 2013, 09:40:03 pm
Okay then, I'll use sf::Texture.
Thanks guys!
Title: Re: sf::RenderTexture as a normal texture?
Post by: ahnonay on July 28, 2013, 09:41:54 pm
You would have to use sf::RenderTexture::getTexture(), which only returns a reference to the RenderTexture's internal Texture. So to retain the Texture after the RenderTexture has been destroyed, you must make a copy of it, which is a rather slow operation.
So I think you might as well just keep your RenderTexture in memory.
Title: Re: sf::RenderTexture as a normal texture?
Post by: JunkerKun on August 02, 2013, 09:15:37 pm
You would have to use sf::RenderTexture::getTexture(), which only returns a reference to the RenderTexture's internal Texture. So to retain the Texture after the RenderTexture has been destroyed, you must make a copy of it, which is a rather slow operation.
So I think you might as well just keep your RenderTexture in memory.

I need to copy the texture only when loading actually. But thanks for the advice anyway.