OGRECave / ogre-next

aka ogre v2 - scene-oriented, flexible 3D C++ engine
https://ogrecave.github.io/ogre-next/api/latest
Other
1.06k stars 227 forks source link

How to know when rendering to texture is done #412

Open ChenTianSky opened 1 year ago

ChenTianSky commented 1 year ago

Hello. I would like to ask, in ogre, how do I know that the current frame has been rendered by the gpu? For example, when I render to the texture, how do I know that the GPU has finished rendering, and I need to sample it back to do other processing at this time. I tried Ogre::FrameListener, but frameRenderingQueued doesn't sync gpu rendering complete event

darksylinc commented 1 year ago

Hi!

Depending on what you want do:

To answer your question specifically: See VaoManager::getFrameCount, VaoManager::waitForSpecificFrameToFinish and VaoManager::isFrameFinished

What I suspect you probably want: If you want to download the data back for processing, you can use an AsyncTextureTicket. See the manual.

The code in Image2::copyContentsToMemory and Image2::convertFromTexture show how to deal with every single edge case.

When you call asyncTicket->map( ... ) it will stall until the rendering & transfer to CPU is done. If you do not wish to stall, you can call asyncTicket->queryIsTransferDone() to see if it's done transferring. If it returns true, asyncTicket->map( ... ) will return immediately.

The most efficient way to do it (e.g. video streaming) is to wait vaoManager->getDynamicBufferMultiplier() frames (e.g. if it returns 2, download() the data immediately but call map/queryIsTransferDone after the next time frameRenderingQueued gets called, if it returns 3, wait another frameRenderingQueued call).

ChenTianSky commented 1 year ago

Hi! I don't want to copy data from the gpu back to the cpu, I just want to strictly control the frame rate. For example, I have an external program that uses shared texture technology. I set this texture as a rendering texture in the ogre application. I want to know when ogre finishes rendering this frame. Because after rendering, my ogre application will notify the external program to process this frame. After the external program has finished processing, it will tell the ogre program. At this time, the ogre program will start rendering the next frame, and so on. But I found that ogre's rendering is performed asynchronously, and I don't want to spend the cost of copying data every time I render synchronously If ogre provides such a method, please let me know, thank you very much