SFML community forums

Help => Graphics => Topic started by: Core Xii on December 16, 2008, 01:43:50 pm

Title: Accessing raw pixel data
Post by: Core Xii on December 16, 2008, 01:43:50 pm
I'd like to use a software renderer, how would I go about accessing raw pixel data? Is sf::Image's SetPixel() fast enough for going through the entire image every frame?
Title: Accessing raw pixel data
Post by: Laurent on December 16, 2008, 10:48:18 pm
It depends. For some applications, SFML might be enough to do software rendering. But for advanced rendering, there's no point and you will get better performances not using it.

Anyway, you can still do everything in memory and just upload your final bunch of pixels to the video memory with Image::LoadFromPixels. Should be fast enough, especially if the dimensions never change.
Title: Accessing raw pixel data
Post by: Core Xii on December 16, 2008, 11:34:17 pm
Quote from: "Laurent"
Anyway, you can still do everything in memory and just upload your final bunch of pixels to the video memory with Image::LoadFromPixels. Should be fast enough, especially if the dimensions never change.


That was my first thought, but the documentation said that loading an Image is slow. I suppose it's sufficiently fast, then? I presume it copies the data? And I should proceed to draw it as a Sprite?
Title: Accessing raw pixel data
Post by: Laurent on December 17, 2008, 07:47:23 am
Quote
That was my first thought, but the documentation said that loading an Image is slow

That's true, the three slower things are:
1- Accessing the pixels from a file on the disk
2- Creating an OpenGL texture
3- Uploading all the pixels in video memory

Since you're not using 1, and that 2 is optimized (i.e. skipped) when the same Image instance is reused with the same dimensions, your only concern is 3, which is optimized enough for real-time update.

Quote
I presume it copies the data?

Yes, both to system and video memory. In the future, there should be an option to skip the system memory copy when it's not necessary.

Quote
And I should proceed to draw it as a Sprite?

Absolutely.
Title: Accessing raw pixel data
Post by: Core Xii on December 17, 2008, 08:30:49 am
Great, thank you for your assistance! :mrgreen: