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

Author Topic: Efficient way to work ontop of a static image each frame  (Read 1066 times)

0 Members and 1 Guest are viewing this topic.

cwkx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Efficient way to work ontop of a static image each frame
« on: April 23, 2012, 01:02:19 pm »
Hi,

I'm doing something which is similar, but not quite the same as, rendering a movie.

Every frame, I need to override pixel data with CPU operations on top of a read-only sf::Image "staticImage" (this never changes over all frames) - e.g. i'm looking to copy, change, and send the data of the static image extremely efficiently.

Currently i'm just doing:
   
Code: [Select]
dynamicImage.create(staticImage.getWidth(), staticImage.getHeight(), sf::Color(0,0,0,0));
dynamicImage.copy(staticImage, 0, 0);

dynamicImage.setPixel(...);

dynamicTexture.loadFromImage(dynamicImage);


- Could anyone help explain to me to a faster way to do this: I looked at sf::RenderTexture but wasn't sure whether or how I could use this in my situation. I'd like to support larger images, e.g. 8192 x 8192, but currently copying in the way above is about 1 FPS for such sizes.

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Efficient way to work ontop of a static image each frame
« Reply #1 on: April 23, 2012, 01:04:13 pm »
Don't use sf::Image, setPixel is too slow. Use your own raw array of pixels.

Then use Texture::update instead of Texture::loadFromImage to update the texture.
Laurent Gomila - SFML developer

cwkx

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Efficient way to work ontop of a static image each frame
« Reply #2 on: April 23, 2012, 02:10:35 pm »
Thanks for the suggestion! I'll experiment with this.