From 83b0a31b765348116c079b585ee997b1b5c9d355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Fri, 27 Aug 2021 18:28:16 +0200 Subject: [PATCH] Canvas cameras are slave cameras instead of scene graph cameras This was a long-standing issue where Canvas cameras were rendered multiple times, once per slave camera. In the case of the Classic pipeline they were being rendered twice. Making them slave cameras has the issue of them not being shared across GraphicsContexts anymore, so it's not possible to see Canvas displays in extra CameraGroup windows. This is fixed by using OSG context sharing feature and sharing the initial windows' context with all subsequent windows. --- src/Viewer/WindowBuilder.cxx | 5 +++++ src/Viewer/renderer.cxx | 18 ++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Viewer/WindowBuilder.cxx b/src/Viewer/WindowBuilder.cxx index 90eaac00a..4bedcd77e 100644 --- a/src/Viewer/WindowBuilder.cxx +++ b/src/Viewer/WindowBuilder.cxx @@ -249,6 +249,11 @@ GraphicsWindow* WindowBuilder::buildWindow(const SGPropertyNode* winNode, bool i return result; } auto traits = new GraphicsContext::Traits(*defaultTraits); + + // Attempt to share context with the window that was created first + if (!wsa->windows.empty()) + traits->sharedContext = wsa->windows.front()->gc; + int traitsSet = setFromProperty(traits->hostName, winNode, "host-name"); traitsSet |= setFromProperty(traits->displayNum, winNode, "display"); traitsSet |= setFromProperty(traits->screenNum, winNode, "screen"); diff --git a/src/Viewer/renderer.cxx b/src/Viewer/renderer.cxx index 87c568f47..419c01697 100644 --- a/src/Viewer/renderer.cxx +++ b/src/Viewer/renderer.cxx @@ -1106,13 +1106,27 @@ FGRenderer::setEventHandler(FGEventHandler* eventHandler_) void FGRenderer::addCamera(osg::Camera* camera, bool useSceneData) { - _viewerSceneRoot->addChild(camera); + osg::Camera *guiCamera = getGUICamera(CameraGroup::getDefault()); + osg::GraphicsContext *gc = guiCamera->getGraphicsContext(); + camera->setGraphicsContext(gc); + if (composite_viewer) { + composite_viewer->getView(0)->addSlave(camera, false); + } else { + viewer->addSlave(camera, false); + } } void FGRenderer::removeCamera(osg::Camera* camera) { - _viewerSceneRoot->removeChild(camera); + if (composite_viewer) { + unsigned int index = composite_viewer->getView(0) + ->findSlaveIndexForCamera(camera); + composite_viewer->getView(0)->removeSlave(index); + } else { + unsigned int index = viewer->findSlaveIndexForCamera(camera); + viewer->removeSlave(index); + } } void