From 430c8606e945e0759f3e22108c766854be572311 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 2 Oct 2001 11:36:14 +0000 Subject: [PATCH] Added osg::EarthSky node to the core osg library, and added support for it into osgUtil::SceneView, osg::CullVisitor, osgPlugin/osg and updated the hangglide demo to use the new earth sky node. --- VisualStudio/osg/osg.dsp | 8 ++++++++ include/osg/NodeVisitor | 2 ++ include/osgUtil/CullVisitor | 12 +++++++++++- src/Demos/hangglide/hangglide.cpp | 13 +++++++------ src/osg/Makefile | 2 ++ src/osgPlugins/osg/Makefile | 1 + src/osgUtil/CullVisitor.cpp | 18 +++++++++++++++++- src/osgUtil/SceneView.cpp | 19 +++++++++++++++++++ 8 files changed, 67 insertions(+), 8 deletions(-) diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 62ca3a3af..8f04ce0f4 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -134,6 +134,10 @@ SOURCE=..\..\src\osg\Drawable.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osg\EarthSky.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osg\Fog.cpp # End Source File # Begin Source File @@ -334,6 +338,10 @@ SOURCE=..\..\Include\Osg\Drawable # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\EarthSky +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\Export # End Source File # Begin Source File diff --git a/include/osg/NodeVisitor b/include/osg/NodeVisitor index 8bb05034b..93290b41f 100644 --- a/include/osg/NodeVisitor +++ b/include/osg/NodeVisitor @@ -15,6 +15,7 @@ class LOD; class Sequence; class Switch; class Impostor; +class EarthSky; /** Visitor for type safe operations on osg::Node's. Based on GOF's Visitor pattern.*/ @@ -128,6 +129,7 @@ class SG_EXPORT NodeVisitor : public Referenced virtual void apply(Sequence& node) { apply((Group&)node); } virtual void apply(LOD& node) { apply((Group&)node); } virtual void apply(Impostor& node) { apply((LOD&)node); } + virtual void apply(EarthSky& node) { apply((Group&)node); } protected: diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 28118d30b..929c1a841 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -47,12 +48,19 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor virtual void apply(osg::Transform& node); virtual void apply(osg::Switch& node); virtual void apply(osg::LOD& node); + virtual void apply(osg::EarthSky& node); virtual void apply(osg::Impostor& node); - void setCamera(const osg::Camera& camera); + + void setCamera(const osg::Camera& camera); const osg::Camera* getCamera() const { return _camera.get(); } + + void setEarthSky(const osg::EarthSky* earthSky) { _earthSky = earthSky; } + const osg::EarthSky* getEarthSky() const { return _earthSky.get(); } + + void setLODBias(const float bias) { _LODBias = bias; } const float getLODBias() const { return _LODBias; } @@ -279,6 +287,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor float _calculated_zfar; osg::ref_ptr _camera; + + osg::ref_ptr _earthSky; TransparencySortMode _tsm; diff --git a/src/Demos/hangglide/hangglide.cpp b/src/Demos/hangglide/hangglide.cpp index 8bd0d5cb1..6a1317f66 100644 --- a/src/Demos/hangglide/hangglide.cpp +++ b/src/Demos/hangglide/hangglide.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -130,9 +131,13 @@ int main( int argc, char **argv ) // model and clear the color and depth buffer for us, by using // osg::Depth, and setting their bin numbers to less than 0, // to force them to draw before the rest of the scene. + + osg::EarthSky* earthSky = new osg::EarthSky; + earthSky->setRequiresClear(false); // we've got base and sky to do it. + earthSky->addChild(makeSky()); // bin number -2 so drawn first. + earthSky->addChild(makeBase()); // bin number -1 so draw second. - group->addChild(makeSky()); // bin number -2 so drawn first. - group->addChild(makeBase()); // bin number -1 so draw second. + group->addChild(earthSky); // the rest of the scene drawn after the base and sky above. group->addChild(makeTrees()); // will drop into a transparent, depth sorted bin (1) @@ -158,10 +163,6 @@ int main( int argc, char **argv ) osgUtil::SceneView* sv = viewer.getViewportSceneView(0); - // switch off the render stages clear mask as we use the earth/sky - // to clear it for us, see above. - sv->getRenderStage()->setClearMask(0); - viewer.run(); return 0; diff --git a/src/osg/Makefile b/src/osg/Makefile index 436afee15..0aeb4c65c 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -12,6 +12,7 @@ C++FILES = \ CullFace.cpp\ Depth.cpp \ Drawable.cpp\ + EarthSky.cpp\ Fog.cpp\ FrameStamp.cpp\ FrontFace.cpp\ @@ -69,6 +70,7 @@ TARGET_INCLUDE_FILES = \ osg/CullFace\ osg/Depth\ osg/Drawable\ + osg/EarthSky\ osg/Export\ osg/Fog\ osg/FrameStamp\ diff --git a/src/osgPlugins/osg/Makefile b/src/osgPlugins/osg/Makefile index 625c38349..f34335896 100644 --- a/src/osgPlugins/osg/Makefile +++ b/src/osgPlugins/osg/Makefile @@ -9,6 +9,7 @@ C++FILES = \ CullFace.cpp\ Depth.cpp\ Drawable.cpp\ + EarthSky.cpp\ Fog.cpp\ FrontFace.cpp\ Geode.cpp\ diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 77b23b94a..c99a7e75c 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -645,6 +644,23 @@ void CullVisitor::apply(LOD& node) _cullingModeStack.pop_back(); } +void CullVisitor::apply(osg::EarthSky& node) +{ + // simply override the current earth sky. + setEarthSky(&node); + + // push the node's state. + StateSet* node_state = node.getStateSet(); + if (node_state) pushStateSet(node_state); + + traverse(node); + + // pop the node's state off the render graph stack. + if (node_state) popStateSet(); + +} + + void CullVisitor::apply(Impostor& node) { const BoundingSphere& bs = node.getBound(); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 8a9c81b0e..82540c032 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -135,6 +135,7 @@ void SceneView::cull() _cullVisitor->setLODBias(_lodBias); _cullVisitor->setCamera(*_camera); _cullVisitor->setViewport(_viewport.get()); + _cullVisitor->setEarthSky(NULL); // reset earth sky on each frame. _renderStage->reset(); @@ -170,6 +171,24 @@ void SceneView::cull() _renderStage->sort(); + const osg::EarthSky* earthSky = _cullVisitor->getEarthSky(); + if (earthSky) + { + if (earthSky->getRequiresClear()) + { + _renderStage->setClearColor(earthSky->getClearColor()); + // really should set clear mask here, but what to? Need + // to consider the stencil and accumulation buffers.. + // will defer to later. Robert Osfield. October 2001. + } + else + { + // we have an earth sky implementation to do the work for use + // so we don't need to clear. + _renderStage->setClearMask(0); + } + } + // prune out any empty RenderGraph children. // note, this would be not required if the _renderGraph had been // reset at the start of each frame (see top of this method) but