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

Author Topic: Accessing raw pixel data  (Read 2660 times)

0 Members and 1 Guest are viewing this topic.

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Accessing raw pixel data
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Accessing raw pixel data
« Reply #1 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.
Laurent Gomila - SFML developer

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Accessing raw pixel data
« Reply #2 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Accessing raw pixel data
« Reply #3 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.
Laurent Gomila - SFML developer

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
Accessing raw pixel data
« Reply #4 on: December 17, 2008, 08:30:49 am »
Great, thank you for your assistance! :mrgreen:

 

anything