SFML community forums

Help => Graphics => Topic started by: binbinhfr on April 25, 2020, 07:36:09 pm

Title: Texture instance copy ?
Post by: binbinhfr on April 25, 2020, 07:36:09 pm
Hi,

I'm not sure about this one, because I know that textures are stored into GPU memory.
so if I write
(click to show/hide)

is it ok for sprite1 ?
does the texture::operator= really duplicate textures in GPU memory ?

And what about the return of RenderTexture::GetTexture(), if I use it once the render texture is destroyed ? My tests show s that it seems to work, but I wonder if it is intended/safe or just a memory shadow ?
Title: Re: Texture instance copy ?
Post by: Laurent on April 25, 2020, 07:59:13 pm
Quote
is it ok for sprite1 ?
Yes.

Quote
does the texture::operator= really duplicate textures in GPU memory ?
Yes.

Quote
And what about the return of RenderTexture::GetTexture(), if I use it once the render texture is destroyed ?
If you copy it then it's safe, if you keep a reference on it then you have UB, like with any other destroyed variable that you'd try to access through a pointer or reference.
Title: Re: Texture instance copy ?
Post by: binbinhfr on April 25, 2020, 08:41:14 pm
If you copy it then it's safe, if you keep a reference on it then you have UB, like with any other destroyed variable that you'd try to access through a pointer or reference.

OK. thx. I was using the reference copy, and the UB was positive, thats' why I was confused. So I will correct this.