From e107c86e1a79debe09255a8c18fc4cb5d3319689 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Nov 2009 12:32:51 +0000 Subject: [PATCH] From Farshid Lashkari, "I noticed that the code for rendering vertical interlace, horizontal interlace, and checkerboard stereo are practically identical, except for the stipple pattern. I combined the code blocks for rendering the 3 stereo modes into a single block. I also fixed a small issue with retrieving stats in checkerboard stereo mode." --- src/osgUtil/SceneView.cpp | 184 ++++---------------------------------- 1 file changed, 16 insertions(+), 168 deletions(-) diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 8c891b60c..18a9a9111 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -1290,6 +1290,8 @@ void SceneView::draw() } break; case(osg::DisplaySettings::VERTICAL_INTERLACE): + case(osg::DisplaySettings::HORIZONTAL_INTERLACE): + case(osg::DisplaySettings::CHECKERBOARD): { #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GL3_AVAILABLE) if( 0 == ( _camera->getInheritanceMask() & DRAW_BUFFER) ) @@ -1338,7 +1340,18 @@ void SceneView::draw() glClear(GL_STENCIL_BUFFER_BIT); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); glStencilFunc(GL_ALWAYS, 1, ~0u); - glPolygonStipple(patternVertEven); + if(_displaySettings->getStereoMode() == osg::DisplaySettings::VERTICAL_INTERLACE) + { + glPolygonStipple(patternVertEven); + } + else if(_displaySettings->getStereoMode() == osg::DisplaySettings::HORIZONTAL_INTERLACE) + { + glPolygonStipple(patternHorzEven); + } + else + { + glPolygonStipple(patternCheckerboard); + } getState()->applyMode(GL_POLYGON_STIPPLE,true); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); @@ -1368,173 +1381,7 @@ void SceneView::draw() _renderStageRight->draw(_renderInfo,previous); glDisable(GL_STENCIL_TEST); #else - osg::notify(osg::NOTICE)<<"Warning: SceneView::draw() - VERTICAL_INTERLACE stereo not supported."<getInheritanceMask() & DRAW_BUFFER) ) - { - _renderStageLeft->setDrawBuffer(_camera->getDrawBuffer()); - _renderStageLeft->setReadBuffer(_camera->getDrawBuffer()); - _renderStageRight->setDrawBuffer(_camera->getDrawBuffer()); - _renderStageRight->setReadBuffer(_camera->getDrawBuffer()); - } - _localStateSet->setAttribute(getViewport()); - - // ensure that all color planes are active. - osg::ColorMask* cmask = static_cast(_localStateSet->getAttribute(osg::StateAttribute::COLORMASK)); - if (cmask) - { - cmask->setMask(true,true,true,true); - } - else - { - cmask = new osg::ColorMask(true,true,true,true); - _localStateSet->setAttribute(cmask); - } - _renderStageLeft->setColorMask(cmask); - _renderStageRight->setColorMask(cmask); - - _renderStageLeft->drawPreRenderStages(_renderInfo,previous); - _renderStageRight->drawPreRenderStages(_renderInfo,previous); - - glEnable(GL_STENCIL_TEST); - - if(_redrawInterlacedStereoStencilMask || - _interlacedStereoStencilWidth != getViewport()->width() || - _interlacedStereoStencilHeight != getViewport()->height() ) - { - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(getViewport()->x(), getViewport()->width(), getViewport()->y(), getViewport()->height(), -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - getViewport()->apply(*state); - getState()->applyMode(GL_LIGHTING,false); - getState()->applyMode(GL_DEPTH_TEST,false); - glStencilMask(~0u); - glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, ~0u); - glPolygonStipple(patternHorzEven); - getState()->applyMode(GL_POLYGON_STIPPLE,true); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - - glRecti(static_cast(getViewport()->x()), - static_cast(getViewport()->y()), - static_cast(getViewport()->width()), - static_cast(getViewport()->height()) ); - - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - getState()->applyMode(GL_POLYGON_STIPPLE,false); - getState()->applyMode(GL_LIGHTING,true); - getState()->applyMode(GL_DEPTH_TEST,true); - - _redrawInterlacedStereoStencilMask = false; - _interlacedStereoStencilWidth = static_cast(getViewport()->width()); - _interlacedStereoStencilHeight = static_cast(getViewport()->height()); - } - - _renderStageLeft->setClearMask(_renderStageLeft->getClearMask() & ~(GL_STENCIL_BUFFER_BIT)); - _renderStageRight->setClearMask(_renderStageRight->getClearMask() & ~(GL_STENCIL_BUFFER_BIT|GL_COLOR_BUFFER_BIT)); - - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, 0, ~0u); - _renderStageLeft->draw(_renderInfo,previous); - - glStencilFunc(GL_NOTEQUAL, 0, ~0u); - _renderStageRight->draw(_renderInfo,previous); - glDisable(GL_STENCIL_TEST); - #else - osg::notify(osg::NOTICE)<<"Warning: SceneView::draw() - HORIZONTAL_INTERLACE stereo not supported."<getInheritanceMask() & DRAW_BUFFER) ) - { - _renderStageLeft->setDrawBuffer(_camera->getDrawBuffer()); - _renderStageLeft->setReadBuffer(_camera->getDrawBuffer()); - _renderStageRight->setDrawBuffer(_camera->getDrawBuffer()); - _renderStageRight->setReadBuffer(_camera->getDrawBuffer()); - } - _localStateSet->setAttribute(getViewport()); - - // ensure that all color planes are active. - osg::ColorMask* cmask = static_cast(_localStateSet->getAttribute(osg::StateAttribute::COLORMASK)); - if (cmask) - { - cmask->setMask(true,true,true,true); - } - else - { - cmask = new osg::ColorMask(true,true,true,true); - _localStateSet->setAttribute(cmask); - } - _renderStageLeft->setColorMask(cmask); - _renderStageRight->setColorMask(cmask); - - _renderStageLeft->drawPreRenderStages(_renderInfo,previous); - _renderStageRight->drawPreRenderStages(_renderInfo,previous); - - glEnable(GL_STENCIL_TEST); - - if(_redrawInterlacedStereoStencilMask || - _interlacedStereoStencilWidth != getViewport()->width() || - _interlacedStereoStencilHeight != getViewport()->height() ) - { - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(getViewport()->x(), getViewport()->width(), getViewport()->y(), getViewport()->height(), -1.0, 1.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - - getViewport()->apply(*state); - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - glStencilMask(~0u); - glClear(GL_STENCIL_BUFFER_BIT); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, ~0u); - glPolygonStipple(patternCheckerboard); - glEnable(GL_POLYGON_STIPPLE); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - - glRecti(static_cast(getViewport()->x()), - static_cast(getViewport()->y()), - static_cast(getViewport()->width()), - static_cast(getViewport()->height()) ); - - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glDisable(GL_POLYGON_STIPPLE); - glEnable(GL_LIGHTING); - glEnable(GL_DEPTH_TEST); - - _redrawInterlacedStereoStencilMask = false; - _interlacedStereoStencilWidth = static_cast(getViewport()->width()); - _interlacedStereoStencilHeight = static_cast(getViewport()->height()); - } - - _renderStageLeft->setClearMask(_renderStageLeft->getClearMask() & ~(GL_STENCIL_BUFFER_BIT)); - _renderStageRight->setClearMask(_renderStageRight->getClearMask() & ~(GL_STENCIL_BUFFER_BIT|GL_COLOR_BUFFER_BIT)); - - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - glStencilFunc(GL_EQUAL, 0, ~0u); - _renderStageLeft->draw(_renderInfo,previous); - - glStencilFunc(GL_NOTEQUAL, 0, ~0u); - _renderStageRight->draw(_renderInfo,previous); - glDisable(GL_STENCIL_TEST); - #else - osg::notify(osg::NOTICE)<<"Warning: SceneView::draw() - CHECKERBOARD stereo not supported."<getStats(stats); bool resultRight = _renderStageRight->getStats(stats);