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

Author Topic: Update a texture subrect with an image subrect  (Read 1853 times)

0 Members and 1 Guest are viewing this topic.

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Update a texture subrect with an image subrect
« on: May 25, 2012, 02:45:39 am »
I'm using SFML2 and trying to update a texture subrect with an image subrect.
That way I keep a "dirty rectangle" and a cache of pixels (sf::Image) of the same size as the final texture and only update the necessary parts of the sf::Texture if needed.
(Sort of what sf::Sprite::SetPixel did on SFML1.6)

Now, I don't see a way of doing it with SFML2.

Shouldn't there be a method for what I'm asking?
Something like
sf::Texture::update(sf::Image &img, int imgX, int imgY, int txX, int txY, int width, int height);
or
sf::Texture::update(sf::Uint8 *imgPixels, int imgX, int imgY, int txX, int txY, int width, int height);

Am I missing a way?

Thanks!
« Last Edit: May 25, 2012, 07:59:47 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Update a texture subrect with an image subrect
« Reply #1 on: May 25, 2012, 08:03:19 am »
You're right, there's no such function. All the update overloads use the full source of pixels. The reason is that it's not efficient to extract a sub-region of an image, it requires to allocate a temporary array, copy the pixels to it, and free it after the update. Or, you can avoid duplicating the sub-image by calling update for each row.

Anyway, this choice is left to the user, which has more knowledge than SFML about the pixel source and can therefore use the most optimized solution for his use case.
Laurent Gomila - SFML developer

nitram_cero

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Re: Update a texture subrect with an image subrect
« Reply #2 on: May 25, 2012, 11:19:24 am »
Exactly, I was trying to avoid the temporary buffering.
But you're right, OpenGL doesn't have such function per se.

Thanks!