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

Author Topic: Texture instance copy ?  (Read 2557 times)

0 Members and 1 Guest are viewing this topic.

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Texture instance copy ?
« 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Texture instance copy ?
« Reply #1 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.
Laurent Gomila - SFML developer

binbinhfr

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Texture instance copy ?
« Reply #2 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.

 

anything