Jump to content

Texture::GetPixels()


SpiderPig
 Share

Recommended Posts

Now that I have this working I want to get the pixels of the texture rendered from the camera...

 

//Setup
auto texture = CreateTextureBuffer(512, 512);
auto cam2 = CreateCamera(world);
cam2->SetRenderTarget(texture);

//Loop
auto my_precious = texture->give_me_pixels()

 

I can see SetPixels() and SetSubPixles() but no GetPixels().  Can it be done yet?

Link to comment
Share on other sites

Textures do not store their pixel data in system memory. They just load it up and send it to the GPU. The Pixmap class is meant for loading and manipulating image data on the CPU.

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
  • 3 months later...
On 5/15/2022 at 8:40 PM, Josh said:

If you retrieve a texture from the GPU into system memory, that will be extremely slow.

I'm thinking about giving this a go as it's not really a real time application I want this for.  How slow do you think this could be though for a 512x512 image rendered with a camera?  1FPS?

Link to comment
Share on other sites

I have done something similar for my PBRGenerator, and will post the class to download data from the gpu soon. Syncing memory is always at a cost this goes for downloading and uploading the data. There are some tricks you can use to increase the speed a lot, but most of the time you just use staging buffers (these are buffers which are bound to eaither gpu or cpu sepending on the direction you want to transfer the data) 

  1. create a buffer object 
  2. map the buffer to the memory
  3. commit the upload or download commands
  4. unmap the buffer and retrieve the data (the buffer can be still mapped)

There are muliple ways to retrieve data from the gpu. The slowest is to use vkCmdCopyImage, then vkCmdBlitImage (slightly faster and already does format conversion and filtering, is not available for all formats). The fastest way is to use vkCmdCopyBuffer, this copies the pure gpu memory of a bound resource into the host memory. This is mostly used for data readbacks for compute shaders (shader storage buffers), but also useful for image synchronsation. 

The usage of snycing between gpu and host should be used carefully, it can slow down an application fast, and should only be considered for debugging or useful info, lets say a generated water heightmap, where you want the to calculate eg: the height an object is on. 

This being said, it would be nice to get access to the index or vertex buffer elements of a specific surface (speaking of particle systems etc.) ;)

 

  • Thanks 1
  • Windows 10 Pro 64-Bit-Version
  • NVIDIA Geforce 1080 TI
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...