[osg-users] Frame Count/Threading Models

paul1492 at yahoo.com paul1492 at yahoo.com
Wed Nov 4 06:20:40 PST 2009

I was using glXWaitVideoSyncSGI() in a Pre Draw Callback (the place I need it to be) to get the current Frame Count from the video card. I've recently found out that this Frame Count number from this function can be incorrect when I'm reading textures from the GPU to the CPU or writing textures from the CPU to the GPU. In particular, I would see about 100ms between calls to glXWaitVideoSyncSGI but the frame counter returned would either be consecutive (i.e. no missed frames) or skipping one number (i.e. one missed frame). I'm running at 60 Hz (16ms frames).

Therefore, I'm now trying to use glXQueryFrameCountNV() (I have G-SYNC II card and have enabled Frame Lock). It would appear I need to call this when I have a valid Graphics Context. I assume this isn't normally the case in a PreDrawCallback.  I've had to do this in the PreDrawCallback:
            if (camera.getGraphicsContext() &&
                camera.getGraphicsContext()->valid() &&
                osg::GraphicsContext* gc = const_cast<osg::GraphicsContext*>(camera.getGraphicsContext());
followed by my call to glXQueryFrameCountNV().

However, to make this work, I've had to set my osgViewer's threading model to SingleThreaded. If I don't do this I usually see a "Xlib: unexpected async reply (sequence 0x6a)!" message followed by a segmentation fault.

What am I doing wrong? Is there some better way to do something in a valid graphics context when not in a draw callback?

Paul P.


More information about the osg-users mailing list