From 386b87d4a065de64e1ce7a2261f67bf09cc8a31b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 11 Feb 2002 19:51:24 +0000 Subject: [PATCH] Cleand up the root Makefile. Moved CullVisitor/RenderStage/RenderStageLighting across to managing lights entirely within RenderStageLighting, and changed the management of modelview matrices so that RenderLeaf now stores the absolute modelview matrix, rather than a model matrix as done previously. The later allows RenderLeaf's to do a glLoadMatrix rather than a glPushMatrix/glMultMatrix/glPopMatrix. --- Makefile | 1 - include/osgUtil/RenderStage | 7 ------ include/osgUtil/RenderStageLighting | 16 -------------- src/osgUtil/RenderLeaf.cpp | 15 ++++++++----- src/osgUtil/RenderStage.cpp | 17 --------------- src/osgUtil/RenderStageLighting.cpp | 12 +++++------ src/osgUtil/SceneView.cpp | 33 +++++++++++++++++++---------- 7 files changed, 37 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index 7bec8de42..c3a140269 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,6 @@ stats : cat include/osgUtil/* src/osgUtil/*.cpp | wc -l cat include/osgDB/* src/osgDB/*.cpp | wc -l cat include/osgGLUT/* src/osgGLUT/*.cpp | wc -l - cat include/osgWX/* src/osgWX/*.cpp | wc -l cat include/osgText/* src/osgText/*.cpp | wc -l cat include/*/* src/*/*.cpp | wc -l cat src/Demos/*/*.cpp | wc -l diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 1e6f8ab9f..c0c06a4f6 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -106,13 +106,6 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin return _renderStageLighting.get(); } - void setLightingMode(RenderStageLighting::Mode mode) { getRenderStageLighting()->setLightingMode(mode); } - RenderStageLighting::Mode getLightingMode() const { return getRenderStageLighting()->getLightingMode(); } - - void setLight(osg::Light* light) { getRenderStageLighting()->setLight(light); } - osg::Light* getLight() { return getRenderStageLighting()->getLight(); } - const osg::Light* getLight() const { return getRenderStageLighting()->getLight(); } - virtual void addLight(osg::Light* light,osg::Matrix* matrix) { getRenderStageLighting()->addLight(light,matrix); diff --git a/include/osgUtil/RenderStageLighting b/include/osgUtil/RenderStageLighting index bafb68bd8..788f7e560 100644 --- a/include/osgUtil/RenderStageLighting +++ b/include/osgUtil/RenderStageLighting @@ -30,19 +30,6 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object virtual void reset(); - enum Mode { - HEADLIGHT, // default - SKY_LIGHT, - NO_SCENEVIEW_LIGHT - }; - - void setLightingMode(Mode mode) { _lightingMode=mode; } - Mode getLightingMode() const { return _lightingMode; } - - void setLight(osg::Light* light) { _light = light; } - osg::Light* getLight() { return _light.get(); } - const osg::Light* getLight() const { return _light.get(); } - typedef std::pair< osg::Light*, osg::ref_ptr > LightMatrixPair; typedef std::vector< LightMatrixPair > LightList; @@ -55,10 +42,7 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object public: - Mode _lightingMode; - osg::ref_ptr _light; LightList _lightList; - protected: diff --git a/src/osgUtil/RenderLeaf.cpp b/src/osgUtil/RenderLeaf.cpp index a3d7c4f18..af29b0e5e 100644 --- a/src/osgUtil/RenderLeaf.cpp +++ b/src/osgUtil/RenderLeaf.cpp @@ -33,12 +33,14 @@ void RenderLeaf::render(State& state,RenderLeaf* previous) Matrix* prev_matrix = previous->_matrix.get(); if (_matrix != prev_matrix) { - if (prev_matrix) glPopMatrix(); if (_matrix.valid()) { - glPushMatrix(); - glMultMatrixf(_matrix->ptr()); + glLoadMatrixf(_matrix->ptr()); + } + else + { + glLoadIdentity(); } } @@ -54,8 +56,11 @@ void RenderLeaf::render(State& state,RenderLeaf* previous) if (_matrix.valid()) { - glPushMatrix(); - glMultMatrixf(_matrix->ptr()); + glLoadMatrixf(_matrix->ptr()); + } + else + { + glLoadIdentity(); } _drawable->draw(state); diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index 8040b989d..54f31f458 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -108,22 +108,6 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous) glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); - Light* light = getLight(); - if (getLightingMode()==RenderStageLighting::HEADLIGHT && light) - { - light->apply(state); - } - - // set up camera modelview. - const Matrix& modelView = _camera->getModelViewMatrix(); - glLoadMatrixf(modelView.ptr()); - - - if (getLightingMode()==RenderStageLighting::SKY_LIGHT && light) - { - light->apply(state); - } - // apply the lights. if (_renderStageLighting.valid()) _renderStageLighting->draw(state,previous); @@ -135,7 +119,6 @@ void RenderStage::draw(osg::State& state,RenderLeaf*& previous) { RenderGraph::moveToRootRenderGraph(state,previous->_parent); state.apply(); - if (previous->_matrix.valid()) glPopMatrix(); previous = NULL; } diff --git a/src/osgUtil/RenderStageLighting.cpp b/src/osgUtil/RenderStageLighting.cpp index 367a18294..9c0be3e80 100644 --- a/src/osgUtil/RenderStageLighting.cpp +++ b/src/osgUtil/RenderStageLighting.cpp @@ -26,7 +26,6 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous) { RenderGraph::moveToRootRenderGraph(state,previous->_parent); state.apply(); - if (previous->_matrix.valid()) glPopMatrix(); previous = NULL; } @@ -40,12 +39,13 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous) Matrix* matrix = (*litr).second.get(); if (matrix != prev_matrix) { - if (prev_matrix) glPopMatrix(); - if (matrix) { - glPushMatrix(); - glMultMatrixf(matrix->ptr()); + glLoadMatrixf(matrix->ptr()); + } + else + { + glLoadIdentity(); } prev_matrix = matrix; @@ -55,7 +55,5 @@ void RenderStageLighting::draw(osg::State& state,RenderLeaf*& previous) litr->first->apply(state); } - // clean up matrix stack. - if (prev_matrix) glPopMatrix(); } diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b888d00cd..b7c0e443d 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -152,6 +152,12 @@ void SceneView::cull() _camera->adjustAspectRatio(_viewport->aspectRatio()); + // comment out reset of rendergraph since clean is more efficient. + // _rendergraph->reset(); + + // use clean of the rendergraph rather than reset, as it is able to + // reuse the structure on the rendergraph in the next frame. This + // achieves a certain amount of frame cohereancy of memory allocation. _rendergraph->clean(); _cullVisitor->reset(); @@ -164,15 +170,17 @@ void SceneView::cull() _cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber()); } - // comment out reset of rendergraph since clean is more efficient. - // _rendergraph->reset(); + // get the camera's modelview + osg::Matrix* modelview = new osg::Matrix(_camera->getModelViewMatrix()); + + + // take a copy of camera, and init it home + osg::Camera* camera = new Camera(*_camera); + camera->home(); - // use clean of the rendergraph rather than reset, as it is able to - // reuse the structure on the rendergraph in the next frame. This - // achieves a certain amount of frame cohereancy of memory allocation. _cullVisitor->setLODBias(_lodBias); - _cullVisitor->setCamera(*_camera); + _cullVisitor->setCamera(*camera); _cullVisitor->setViewport(_viewport.get()); _cullVisitor->setEarthSky(NULL); // reset earth sky on each frame. @@ -184,31 +192,34 @@ void SceneView::cull() _renderStage->reset(); _renderStage->setViewport(_viewport.get()); - _renderStage->setCamera(_camera.get()); + _renderStage->setCamera(camera); _renderStage->setClearColor(_backgroundColor); - _renderStage->setLight(_light.get()); switch(_lightingMode) { case(HEADLIGHT): - _renderStage->setLightingMode(RenderStageLighting::HEADLIGHT); + _renderStage->addLight(_light.get(),NULL); break; case(SKY_LIGHT): - _renderStage->setLightingMode(RenderStageLighting::SKY_LIGHT); + _renderStage->addLight(_light.get(),modelview); break; case(NO_SCENEVIEW_LIGHT): - _renderStage->setLightingMode(RenderStageLighting::NO_SCENEVIEW_LIGHT); break; } if (_globalState.valid()) _cullVisitor->pushStateSet(_globalState.get()); + _cullVisitor->pushCullViewState(modelview); + + // traverse the scene graph to generate the rendergraph. _sceneData->accept(*_cullVisitor); if (_globalState.valid()) _cullVisitor->popStateSet(); + + _cullVisitor->popCullViewState(); // do any state sorting required.