LukasBanana / LLGL

Low Level Graphics Library (LLGL) is a thin abstraction layer for the modern graphics APIs OpenGL, Direct3D, Vulkan, and Metal
BSD 3-Clause "New" or "Revised" License
2.03k stars 135 forks source link

Implementing a GPU-to-CPU Image Readback Functionality #88

Closed lemoon closed 1 year ago

lemoon commented 1 year ago

Hi,all. Currently, there is a need to develop a mechanism to read the rendered images from the GPU back to the CPU, similar to the functionality provided by glReadPixels in OpenGL. This feature would enable efficient data transfer and processing between the GPU and CPU, allowing for further analysis, manipulation, or storage of the rendered images on the CPU side.

LukasBanana commented 1 year ago

Hi,

the primary function in LLGL to retrieve texture data from the GPU is RenderSystem::ReadTexture. You can either render into a texture directly using a RenderTarget or read from the framebuffer (similar to glReadPixels) by copying the contents of the framebuffer into a texture using CopyTextureFromFramebuffer. Either way you will have to work with an instance of the Texture interface.

You can also take a look at how ExampleBase does it: First capture the frame via CaptureFramebuffer, then save the texture to a PNG file in SaveTextureWithRenderer.

Hope that answers your questions. Laura

lemoon commented 1 year ago

Hi,

the primary function in LLGL to retrieve texture data from the GPU is RenderSystem::ReadTexture. You can either render into a texture directly using a RenderTarget or read from the framebuffer (similar to glReadPixels) by copying the contents of the framebuffer into a texture using CopyTextureFromFramebuffer. Either way you will have to work with an instance of the Texture interface.

You can also take a look at how ExampleBase does it: First capture the frame via CaptureFramebuffer, then save the texture to a PNG file in SaveTextureWithRenderer.

Hope that answers your questions. Laura

Thank you, this is very helpful to me.

And i found an unfinished implementation here (https://github.com/LukasBanana/LLGL/blob/master/sources/Renderer/OpenGL/Texture/GLTexture.cpp#L834), could this cause some platforms to not correctly read GPU data?

LukasBanana commented 1 year ago

This is not implemented for OpenGLES yet but desktop OpenGL is fine. It shouldn't take too long to implement it for GLES, though.

LukasBanana commented 1 year ago

@lemoon did you run into this exception or how did you find this unimplemented function? In other words, how urgent do you need this functionality for GLES?

LukasBanana commented 1 year ago

Can this ticket be closed or is there still an issue with reading back framebuffer data?

lemoon commented 1 year ago

@lemoon did you run into this exception or how did you find this unimplemented function? In other words, how urgent do you need this functionality for GLES?

Hi, LukasBanana. I expect to run on multiple platforms, including Android, MacOS, Windows, iOS, and Linux. So there is a high probability that this feature will be used on some low-end devices.

lemoon commented 1 year ago

Can this ticket be closed or is there still an issue with reading back framebuffer data?

You can close this issue for now, and I will provide specific feedback based on the specific scenario in the future.