From 8547536387c2c60d6bb9d7351393bb23af9f65cb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 26 Mar 2010 11:09:10 +0000 Subject: [PATCH] From Jean-Sebastien Guay, "When the StatsHandler tries to find a context to add itself to, it will first look for a GraphicsWindow, and if none is found it will look for a GraphicsContext. This enables apps that do all their rendering to offscreen contexts (pbuffer) to still use the StatsHandler." --- src/osgViewer/StatsHandler.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/osgViewer/StatsHandler.cpp b/src/osgViewer/StatsHandler.cpp index e181c5e00..93e3bd20c 100644 --- a/src/osgViewer/StatsHandler.cpp +++ b/src/osgViewer/StatsHandler.cpp @@ -260,21 +260,35 @@ void StatsHandler::reset() void StatsHandler::setUpHUDCamera(osgViewer::ViewerBase* viewer) { - osgViewer::GraphicsWindow* window = dynamic_cast(_camera->getGraphicsContext()); + // Try GraphicsWindow first so we're likely to get the main viewer window + osg::GraphicsContext* context = dynamic_cast(_camera->getGraphicsContext()); - if (!window) + if (!context) { osgViewer::Viewer::Windows windows; viewer->getWindows(windows); - if (windows.empty()) return; + if (!windows.empty()) context = windows.front(); + else + { + // No GraphicsWindows were found, so let's try to find a GraphicsContext + context = _camera->getGraphicsContext(); - window = windows.front(); + if (!context) + { + osgViewer::Viewer::Contexts contexts; + viewer->getContexts(contexts); + + if (contexts.empty()) return; + + context = contexts.front(); + } + } } - _camera->setGraphicsContext(window); + _camera->setGraphicsContext(context); - _camera->setViewport(0, 0, window->getTraits()->width, window->getTraits()->height); + _camera->setViewport(0, 0, context->getTraits()->width, context->getTraits()->height); _camera->setRenderOrder(osg::Camera::POST_RENDER, 10);