1

How is the array of pixels, that is passed to the update method in the Texture class (SFML), managed memory-wise? These are some of my guesses:

  1. A weak pointer is saved inside the texture instance; which means that it is necessary to keep a pointer to the array of pixels of your own and manage it yourself.

  2. The array is copied and managed by the texture (which also means that every time the update method is called again, the previous one is deallocated).

The second guess would justify this for updating a texture multiple times:

auto newPixels = new sf::Uint8[WIDTH * HEIGHT * 4];
... //do stuff to pixels
texture.update(newPixels);

Where the pixels are reallocated every time the texture is updated. Otherwise (if the pixels are just stored as a weak pointer and not managed/deallocated/allocated) a different approach would be necessary, where the pixels are managed by the user...

Thanks in advance for any answers :)

nvoigt
  • 75,013
  • 26
  • 93
  • 142
Dincio
  • 1,010
  • 1
  • 13
  • 25

1 Answers1

0

SFML is open source. You don't need to take guesses or ask here. You can just read it for yourself:

https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/Texture.cpp#L390

Specifically, the pointer is passed to the glTexSubImage2D OpenGL method.

nvoigt
  • 75,013
  • 26
  • 93
  • 142