From Farshid Lashkari, "I noticed that osg::State::getInitialViewMatrix returns the monocular view matrix when rendering in stereo. I've made some changes to osgUtil::RenderStage & SceneView so that it will return the correct view matrix depending on which eye is currently being rendered." & "I made a small change to the previous patch so that osg::State::getInitialViewMatrix works correctly with pre/post render stages as well."

This commit is contained in:
Robert Osfield
2010-04-19 14:49:42 +00:00
parent c091b5c2d1
commit b1658ee6df
4 changed files with 12 additions and 3 deletions

View File

@@ -87,6 +87,12 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
/** Get the viewport. */
osg::Viewport* getViewport() { return _viewport.get(); }
/** Set the initial view matrix.*/
void setInitialViewMatrix(const osg::RefMatrix* matrix) { _initialViewMatrix = matrix; }
/** Get the initial view matrix.*/
const osg::RefMatrix* getInitialViewMatrix() { return _initialViewMatrix.get(); }
/** Set the clear mask used in glClear(..).
* Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. */
@@ -263,6 +269,7 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin
// viewport x,y,width,height.
osg::ref_ptr<osg::Viewport> _viewport;
osg::ref_ptr<const osg::RefMatrix> _initialViewMatrix;
GLenum _drawBuffer;
bool _drawBufferApplyMask;

View File

@@ -1323,7 +1323,8 @@ void CullVisitor::apply(osg::Camera& camera)
osg::Viewport* viewport = camera.getViewport()!=0 ? camera.getViewport() : previous_stage->getViewport();
rtts->setViewport( viewport );
// set initial view matrix
rtts->setInitialViewMatrix(modelview);
// set up to charge the same PositionalStateContainer is the parent previous stage.
osg::Matrix inheritedMVtolocalMV;

View File

@@ -1096,6 +1096,8 @@ void RenderStage::draw(osg::RenderInfo& renderInfo,RenderLeaf*& previous)
{
if (_stageDrawnThisFrame) return;
if(_initialViewMatrix.valid()) renderInfo.getState()->setInitialViewMatrix(_initialViewMatrix.get());
// push the stages camera so that drawing code can query it
if (_camera) renderInfo.pushCamera(_camera);

View File

@@ -932,6 +932,7 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
// achieves a certain amount of frame cohereancy of memory allocation.
rendergraph->clean();
renderStage->setInitialViewMatrix(mv.get());
renderStage->setViewport(viewport);
renderStage->setClearColor(_camera->getClearColor());
renderStage->setClearDepth(_camera->getClearDepth());
@@ -1062,8 +1063,6 @@ void SceneView::draw()
// assume the the draw which is about to happen could generate GL objects that need flushing in the next frame.
_requiresFlush = true;
state->setInitialViewMatrix(new osg::RefMatrix(getViewMatrix()));
RenderLeaf* previous = NULL;
if (_displaySettings.valid() && _displaySettings->getStereo())
{