From 4e34cadee2709abba5ce5bc2e58a61e81be1ae30 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 13 May 2013 09:18:37 +0000 Subject: [PATCH] Added to Viewer::realize() automatic setup using Keystone when available and enabled, and when no other window setup has been selected. --- examples/osgkeystone/osgkeystone.cpp | 2 +- include/osgViewer/View | 2 +- src/osgViewer/View.cpp | 3 ++- src/osgViewer/Viewer.cpp | 26 +++++++++++++++++++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/examples/osgkeystone/osgkeystone.cpp b/examples/osgkeystone/osgkeystone.cpp index 8aedcc90e..56d89e7de 100644 --- a/examples/osgkeystone/osgkeystone.cpp +++ b/examples/osgkeystone/osgkeystone.cpp @@ -100,7 +100,7 @@ int main( int argc, char **argv ) if (ds->getStereo()) { - viewer.setUpViewForStereo(ds); + viewer.setUpViewForStereo(); } else { diff --git a/include/osgViewer/View b/include/osgViewer/View index 4eb6b7c0e..bd2aa0802 100644 --- a/include/osgViewer/View +++ b/include/osgViewer/View @@ -263,7 +263,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter osg::Camera* assignRenderToTextureCamera(osg::GraphicsContext* gc, int width, int height, osg::Texture* texture); osg::Camera* assignKeystoneDistortionCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, osg::Texture* texture, Keystone* keystone); osg::Camera* assignStereoCamera(osg::DisplaySettings* ds, osg::GraphicsContext* gc, int x, int y, int width, int height, GLenum buffer, double eyeScale); - void setUpViewForStereo(osg::DisplaySettings* ds); + void setUpViewForStereo(); void setUpViewForKeystone(Keystone* keystone); struct StereoSlaveCallback : public osg::View::Slave::UpdateSlaveCallback diff --git a/src/osgViewer/View.cpp b/src/osgViewer/View.cpp index a9f94901a..69ead6aaa 100644 --- a/src/osgViewer/View.cpp +++ b/src/osgViewer/View.cpp @@ -2490,8 +2490,9 @@ static const GLubyte patternCheckerboard[] = { 0xAA, 0xAA, 0xAA, 0xAA}; -void View::setUpViewForStereo(osg::DisplaySettings* ds) +void View::setUpViewForStereo() { + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); if (!ds->getStereo()) return; ds->setUseSceneViewForStereoHint(false); diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index aaf04cc03..04af076d7 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -464,13 +464,29 @@ void Viewer::realize() if (screenNum>=0) setUpViewInWindow(x, y, width, height, screenNum); else setUpViewInWindow(x,y,width,height); } - else if (screenNum>=0) - { - setUpViewOnSingleScreen(screenNum); - } else { - setUpViewAcrossAllScreens(); + osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance().get(); + if (ds->getKeystoneHint() && !ds->getKeystoneFileNames().empty()) osgViewer::Keystone::loadKeystoneFiles(ds); + bool useKeystones = ds->getKeystoneHint() && !ds->getKeystones().empty(); + + if (ds->getStereo() && (!ds->getUseSceneViewForStereoHint() || useKeystones)) + { + setUpViewForStereo(); + } + else if (useKeystones) + { + osgViewer::Keystone* keystone = dynamic_cast(ds->getKeystones().front().get()); + setUpViewForKeystone(keystone); + } + else if (screenNum>=0) + { + setUpViewOnSingleScreen(screenNum); + } + else + { + setUpViewAcrossAllScreens(); + } } }