Added osg::CullSettings class as a way of collecting all the various
settings related to the cull traversal in one place, so we can keep APIs for settings these values more consistent.
This commit is contained in:
parent
7596b3b361
commit
5836d60fbd
@ -191,6 +191,10 @@ SOURCE=..\..\src\osg\CullStack.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\CullSettings.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Depth.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -575,6 +579,10 @@ SOURCE=..\..\Include\Osg\CullStack
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\CullSettings
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Depth
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <osgDB/ReadFile>
|
||||
#include <osgUtil/Optimizer>
|
||||
#include <osgProducer/Viewer>
|
||||
#include <osg/CoordinateSystemNode>
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
@ -84,10 +85,23 @@ int main( int argc, char **argv )
|
||||
osgUtil::Optimizer optimizer;
|
||||
optimizer.optimize(loadedModel.get());
|
||||
|
||||
#if 0
|
||||
osg::CoordinateSystemNode* csn = new osg::CoordinateSystemNode;
|
||||
csn->addChild(loadedModel.get());
|
||||
csn->setEllipsoidModel(new osg::EllipsoidModel());
|
||||
|
||||
osg::NodePath nodepath;
|
||||
nodepath.push_back(csn);
|
||||
|
||||
viewer.setCoordindateSystemNodePath(nodepath);
|
||||
|
||||
// set the scene to render
|
||||
viewer.setSceneData(csn);
|
||||
#else
|
||||
|
||||
viewer.setSceneData(loadedModel.get());
|
||||
|
||||
#endif
|
||||
// create the windows and run the threads.
|
||||
viewer.realize();
|
||||
|
||||
|
181
include/osg/CullSettings
Normal file
181
include/osg/CullSettings
Normal file
@ -0,0 +1,181 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSG_CULLSETTINGS
|
||||
#define OSG_CULLSETTINGS 1
|
||||
|
||||
#include <osg/Matrix>
|
||||
#include <osg/ClearNode>
|
||||
|
||||
namespace osg {
|
||||
|
||||
class SG_EXPORT CullSettings
|
||||
{
|
||||
public:
|
||||
|
||||
CullSettings() { setDefaults(); }
|
||||
|
||||
CullSettings(const CullSettings& cs) { setCullSettings(cs); }
|
||||
~CullSettings() {}
|
||||
|
||||
CullSettings& operator = (const CullSettings& settings)
|
||||
{
|
||||
if (this==&settings) return *this;
|
||||
setCullSettings(settings);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void setDefaults();
|
||||
|
||||
void setCullSettings(const CullSettings& settings);
|
||||
|
||||
/** Switch the creation of Impostors on or off.
|
||||
* Setting active to false forces the CullVisitor to use the Impostor
|
||||
* LOD children for rendering. Setting active to true forces the
|
||||
* CullVisitor to create the appropriate pre-rendering stages which
|
||||
* render to the ImpostorSprite's texture.*/
|
||||
void setImpostorsActive(bool active) { _impostorActive = active; }
|
||||
|
||||
/** Get whether impostors are active or not. */
|
||||
bool getImpostorsActive() const { return _impostorActive; }
|
||||
|
||||
/** Set the impostor error threshold.
|
||||
* Used in calculation of whether impostors remain valid.*/
|
||||
void setImpostorPixelErrorThreshold(float numPixels) { _impostorPixelErrorThreshold=numPixels; }
|
||||
|
||||
/** Get the impostor error threshold.*/
|
||||
float getImpostorPixelErrorThreshold() const { return _impostorPixelErrorThreshold; }
|
||||
|
||||
/** Set whether ImpostorSprite's should be placed in a depth sorted bin for rendering.*/
|
||||
void setDepthSortImpostorSprites(bool doDepthSort) { _depthSortImpostorSprites = doDepthSort; }
|
||||
|
||||
/** Get whether ImpostorSprite's are depth sorted bin for rendering.*/
|
||||
bool setDepthSortImpostorSprites() const { return _depthSortImpostorSprites; }
|
||||
|
||||
/** Set the number of frames that an ImpostorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
void setNumberOfFrameToKeepImpostorSprites(int numFrames) { _numFramesToKeepImpostorSprites = numFrames; }
|
||||
|
||||
/** Get the number of frames that an ImpostorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
int getNumberOfFrameToKeepImpostorSprites() const { return _numFramesToKeepImpostorSprites; }
|
||||
|
||||
enum ComputeNearFarMode
|
||||
{
|
||||
DO_NOT_COMPUTE_NEAR_FAR = 0,
|
||||
COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES,
|
||||
COMPUTE_NEAR_FAR_USING_PRIMITIVES
|
||||
};
|
||||
|
||||
void setComputeNearFarMode(ComputeNearFarMode cnfm) { _computeNearFar=cnfm; }
|
||||
ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
|
||||
|
||||
void setNearFarRatio(double ratio) { _nearFarRatio = ratio; }
|
||||
double getNearFarRatio() const { return _nearFarRatio; }
|
||||
|
||||
enum CullingModeValues
|
||||
{
|
||||
NO_CULLING = 0x0,
|
||||
VIEW_FRUSTUM_SIDES_CULLING = 0x1,
|
||||
NEAR_PLANE_CULLING = 0x2,
|
||||
FAR_PLANE_CULLING = 0x4,
|
||||
VIEW_FRUSTUM_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
|
||||
NEAR_PLANE_CULLING|
|
||||
FAR_PLANE_CULLING,
|
||||
SMALL_FEATURE_CULLING = 0x8,
|
||||
SHADOW_OCCLUSION_CULLING = 0x10,
|
||||
DEFAULT_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
|
||||
SMALL_FEATURE_CULLING|
|
||||
SHADOW_OCCLUSION_CULLING,
|
||||
ENABLE_ALL_CULLING = VIEW_FRUSTUM_CULLING|
|
||||
SMALL_FEATURE_CULLING|
|
||||
SHADOW_OCCLUSION_CULLING
|
||||
};
|
||||
|
||||
typedef unsigned int CullingMode;
|
||||
|
||||
/** Set the culling mode for the CullVisitor to use.*/
|
||||
void setCullingMode(CullingMode mode) { _cullingMode = mode; }
|
||||
|
||||
/** Returns the current CullingMode.*/
|
||||
CullingMode getCullingMode() const { return _cullingMode; }
|
||||
|
||||
|
||||
void setCullMask(const osg::Node::NodeMask nm) { _cullMask = nm; }
|
||||
osg::Node::NodeMask getCullMask() const { return _cullMask; }
|
||||
|
||||
void setCullMaskLeft(const osg::Node::NodeMask nm) { _cullMaskLeft = nm; }
|
||||
osg::Node::NodeMask getCullMaskLeft() const { return _cullMaskLeft; }
|
||||
|
||||
void setCullMaskRight(const osg::Node::NodeMask nm) { _cullMaskRight = nm; }
|
||||
osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; }
|
||||
|
||||
/** Set the LOD bias for the CullVisitor to use.*/
|
||||
void setLODScale(float bias) { _LODScale = bias; }
|
||||
|
||||
/** Get the LOD bias.*/
|
||||
float getLODScale() const { return _LODScale; }
|
||||
|
||||
/** Set the Small Feature Culling Pixel Size.*/
|
||||
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
|
||||
|
||||
/** Get the Small Feature Culling Pixel Size.*/
|
||||
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
|
||||
|
||||
|
||||
|
||||
/** Callback for overriding the CullVisitor's default clamping of the projection matrix to computed near and far values.
|
||||
* Note, both Matrixf and Matrixd versions of clampProjectionMatrixImplementation must be implemented as the CullVisitor
|
||||
* can target either Matrix data type, configured at compile time.*/
|
||||
struct ClampProjectionMatrixCallback : public osg::Referenced
|
||||
{
|
||||
virtual bool clampProjectionMatrixImplementation(osg::Matrixf& projection, double znear, double zfar) const = 0;
|
||||
virtual bool clampProjectionMatrixImplementation(osg::Matrixd& projection, double znear, double zfar) const = 0;
|
||||
};
|
||||
|
||||
/** set the ClampProjectionMatrixCallback.*/
|
||||
void setClampProjectionMatrixCallback(ClampProjectionMatrixCallback* cpmc) { _clampProjectionMatrixCallback = cpmc; }
|
||||
/** get the non const ClampProjectionMatrixCallback.*/
|
||||
ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() { return _clampProjectionMatrixCallback.get(); }
|
||||
/** get the const ClampProjectionMatrixCallback.*/
|
||||
const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); }
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
ComputeNearFarMode _computeNearFar;
|
||||
CullingMode _cullingMode;
|
||||
float _LODScale;
|
||||
float _smallFeatureCullingPixelSize;
|
||||
|
||||
ref_ptr<ClampProjectionMatrixCallback> _clampProjectionMatrixCallback;
|
||||
double _nearFarRatio;
|
||||
bool _impostorActive;
|
||||
bool _depthSortImpostorSprites;
|
||||
float _impostorPixelErrorThreshold;
|
||||
int _numFramesToKeepImpostorSprites;
|
||||
|
||||
Node::NodeMask _cullMask;
|
||||
Node::NodeMask _cullMaskLeft;
|
||||
Node::NodeMask _cullMaskRight;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -15,6 +15,7 @@
|
||||
#define OSG_CULLSTACK 1
|
||||
|
||||
#include <osg/CullingSet>
|
||||
#include <osg/CullSettings>
|
||||
#include <osg/Viewport>
|
||||
#include <osg/fast_back_stack>
|
||||
|
||||
@ -22,7 +23,7 @@ namespace osg {
|
||||
|
||||
/** A CullStack class which accumulates the current project, modelview matrices
|
||||
and the CullingSet. */
|
||||
class SG_EXPORT CullStack
|
||||
class SG_EXPORT CullStack : public osg::CullSettings
|
||||
{
|
||||
|
||||
public:
|
||||
@ -34,28 +35,6 @@ class SG_EXPORT CullStack
|
||||
|
||||
typedef std::vector<ShadowVolumeOccluder> OccluderList;
|
||||
|
||||
enum CullingModeValues
|
||||
{
|
||||
NO_CULLING = 0x0,
|
||||
VIEW_FRUSTUM_SIDES_CULLING = 0x1,
|
||||
NEAR_PLANE_CULLING = 0x2,
|
||||
FAR_PLANE_CULLING = 0x4,
|
||||
VIEW_FRUSTUM_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
|
||||
NEAR_PLANE_CULLING|
|
||||
FAR_PLANE_CULLING,
|
||||
SMALL_FEATURE_CULLING = 0x8,
|
||||
SHADOW_OCCLUSION_CULLING = 0x10,
|
||||
DEFAULT_CULLING = VIEW_FRUSTUM_SIDES_CULLING|
|
||||
SMALL_FEATURE_CULLING|
|
||||
SHADOW_OCCLUSION_CULLING,
|
||||
ENABLE_ALL_CULLING = VIEW_FRUSTUM_CULLING|
|
||||
SMALL_FEATURE_CULLING|
|
||||
SHADOW_OCCLUSION_CULLING
|
||||
};
|
||||
|
||||
typedef unsigned int CullingMode;
|
||||
|
||||
|
||||
void reset();
|
||||
|
||||
void setOccluderList(const ShadowVolumeOccluderList& svol) { _occluderList = svol; }
|
||||
@ -74,19 +53,6 @@ class SG_EXPORT CullStack
|
||||
inline float getFrustumVolume() { if (_frustumVolume<0.0f) computeFrustumVolume(); return _frustumVolume; }
|
||||
|
||||
|
||||
/** Sets the current CullingMode.*/
|
||||
void setCullingMode(CullingMode mode) { _cullingMode = mode; }
|
||||
|
||||
/** Returns the current CullingMode.*/
|
||||
CullingMode getCullingMode() const { return _cullingMode; }
|
||||
|
||||
void setLODScale(float bias) { _LODScale = bias; }
|
||||
float getLODScale() const { return _LODScale; }
|
||||
|
||||
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
|
||||
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
|
||||
|
||||
|
||||
/** Compute the pixel of an object at position v, with specified radius.*/
|
||||
float pixelSize(const Vec3& v,float radius) const
|
||||
{
|
||||
@ -179,10 +145,6 @@ class SG_EXPORT CullStack
|
||||
void pushCullingSet();
|
||||
void popCullingSet();
|
||||
|
||||
CullingMode _cullingMode;
|
||||
float _LODScale;
|
||||
float _smallFeatureCullingPixelSize;
|
||||
|
||||
// base set of shadow volume occluder to use in culling.
|
||||
ShadowVolumeOccluderList _occluderList;
|
||||
|
||||
|
@ -59,7 +59,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
virtual CullVisitor* cloneType() const { return new CullVisitor(); }
|
||||
|
||||
virtual void reset();
|
||||
|
||||
|
||||
virtual osg::Vec3 getEyePoint() const { return getEyeLocal(); }
|
||||
virtual float getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const;
|
||||
virtual float getDistanceFromEyePoint(const osg::Vec3& pos, bool withLODScale) const;
|
||||
@ -82,52 +82,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
void setClearNode(const osg::ClearNode* earthSky) { _clearNode = earthSky; }
|
||||
const osg::ClearNode* getClearNode() const { return _clearNode.get(); }
|
||||
|
||||
|
||||
/** Switch the creation of Impostors on or off.
|
||||
* Setting active to false forces the CullVisitor to use the Impostor
|
||||
* LOD children for rendering. Setting active to true forces the
|
||||
* CullVisitor to create the appropriate pre-rendering stages which
|
||||
* render to the ImpostorSprite's texture.*/
|
||||
void setImpostorsActive(bool active) { _impostorActive = active; }
|
||||
|
||||
/** Get whether impostors are active or not. */
|
||||
bool getImpostorsActive() const { return _impostorActive; }
|
||||
|
||||
/** Set the impostor error threshold.
|
||||
* Used in calculation of whether impostors remain valid.*/
|
||||
void setImpostorPixelErrorThreshold(float numPixels) { _impostorPixelErrorThreshold=numPixels; }
|
||||
|
||||
/** Get the impostor error threshold.*/
|
||||
float getImpostorPixelErrorThreshold() const { return _impostorPixelErrorThreshold; }
|
||||
|
||||
/** Set whether ImpostorSprite's should be placed in a depth sorted bin for rendering.*/
|
||||
void setDepthSortImpostorSprites(bool doDepthSort) { _depthSortImpostorSprites = doDepthSort; }
|
||||
|
||||
/** Get whether ImpostorSprite's are depth sorted bin for rendering.*/
|
||||
bool setDepthSortImpostorSprites() const { return _depthSortImpostorSprites; }
|
||||
|
||||
/** Set the number of frames that an ImpostorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
void setNumberOfFrameToKeepImpostorSprites(int numFrames) { _numFramesToKeepImpostorSprites = numFrames; }
|
||||
|
||||
/** Get the number of frames that an ImpostorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
int getNumberOfFrameToKeepImpostorSprites() const { return _numFramesToKeepImpostorSprites; }
|
||||
|
||||
enum ComputeNearFarMode
|
||||
{
|
||||
DO_NOT_COMPUTE_NEAR_FAR = 0,
|
||||
COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES,
|
||||
COMPUTE_NEAR_FAR_USING_PRIMITIVES
|
||||
};
|
||||
|
||||
void setComputeNearFarMode(ComputeNearFarMode cnfm) { _computeNearFar=cnfm; }
|
||||
ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
|
||||
|
||||
void setNearFarRatio(float ratio) { _nearFarRatio = ratio; }
|
||||
float getNearFarRatio() const { return _nearFarRatio; }
|
||||
|
||||
|
||||
/** Push state set on the current state group.
|
||||
* If the state exists in a child state group of the current
|
||||
* state group then move the current state group to that child.
|
||||
@ -219,22 +173,6 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
virtual void popProjectionMatrix();
|
||||
|
||||
|
||||
/** Callback for overriding the CullVisitor's default clamping of the projection matrix to computed near and far values.
|
||||
* Note, both Matrixf and Matrixd versions of clampProjectionMatrixImplementation must be implemented as the CullVisitor
|
||||
* can target either Matrix data type, configured at compile time.*/
|
||||
struct ClampProjectionMatrixCallback : public osg::Referenced
|
||||
{
|
||||
virtual bool clampProjectionMatrixImplementation(osg::Matrixf& projection, double znear, double zfar) const = 0;
|
||||
virtual bool clampProjectionMatrixImplementation(osg::Matrixd& projection, double znear, double zfar) const = 0;
|
||||
};
|
||||
|
||||
/** set the ClampProjectionMatrixCallback.*/
|
||||
void setClampProjectionMatrixCallback(ClampProjectionMatrixCallback* cpmc) { _clampProjectionMatrixCallback = cpmc; }
|
||||
/** get the non const ClampProjectionMatrixCallback.*/
|
||||
ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() { return _clampProjectionMatrixCallback.get(); }
|
||||
/** get the const ClampProjectionMatrixCallback.*/
|
||||
const ClampProjectionMatrixCallback* getClampProjectionMatrixCallback() const { return _clampProjectionMatrixCallback.get(); }
|
||||
|
||||
/** CullVisitor's default clamping of the projection float matrix to computed near and far values.
|
||||
* Note, do not call this method directly, use clampProjectionMatrix(..) instead, unless you want to bypass the callback.*/
|
||||
virtual bool clampProjectionMatrixImplementation(osg::Matrixf& projection, double znear, double zfar) const;
|
||||
@ -314,27 +252,18 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
|
||||
* to generate the impostor texture. */
|
||||
osg::ImpostorSprite* createImpostorSprite(osg::Impostor& node);
|
||||
|
||||
osg::ref_ptr<const osg::ClearNode> _clearNode;
|
||||
|
||||
osg::ref_ptr<RenderGraph> _rootRenderGraph;
|
||||
RenderGraph* _currentRenderGraph;
|
||||
|
||||
osg::ref_ptr<RenderStage> _rootRenderStage;
|
||||
RenderBin* _currentRenderBin;
|
||||
|
||||
ComputeNearFarMode _computeNearFar;
|
||||
|
||||
value_type _nearFarRatio;
|
||||
value_type _computed_znear;
|
||||
value_type _computed_zfar;
|
||||
|
||||
osg::ref_ptr<ClampProjectionMatrixCallback> _clampProjectionMatrixCallback;
|
||||
|
||||
osg::ref_ptr<const osg::ClearNode> _clearNode;
|
||||
|
||||
bool _impostorActive;
|
||||
bool _depthSortImpostorSprites;
|
||||
float _impostorPixelErrorThreshold;
|
||||
int _numFramesToKeepImpostorSprites;
|
||||
|
||||
|
||||
typedef std::vector< osg::ref_ptr<RenderLeaf> > RenderLeafList;
|
||||
RenderLeafList _reuseRenderLeafList;
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/DisplaySettings>
|
||||
#include <osg/CollectOccludersVisitor>
|
||||
|
||||
#include <osg/CullSettings>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
@ -31,7 +31,7 @@ namespace osgUtil {
|
||||
* camera (modelview+projection matrices), global state, lights and the scene itself. Provides
|
||||
* methods for setting up the view and rendering it.
|
||||
*/
|
||||
class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
class OSGUTIL_EXPORT SceneView : public osg::Referenced, public osg::CullSettings
|
||||
{
|
||||
public:
|
||||
|
||||
@ -211,17 +211,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
void getViewMatrixAsLookAt(osg::Vec3& eye,osg::Vec3& center,osg::Vec3& up,float lookDistance=1.0f);
|
||||
|
||||
|
||||
/** Set the draw buffer value used at the start of each frame draw. Note, overridden in quad buffer stereo mode */
|
||||
void setDrawBufferValue( GLenum drawBufferValue )
|
||||
{
|
||||
_drawBufferValue = drawBufferValue;
|
||||
}
|
||||
|
||||
/** Get the draw buffer value used at the start of each frame draw. */
|
||||
GLenum getDrawBufferValue() const
|
||||
{
|
||||
return _drawBufferValue;
|
||||
}
|
||||
|
||||
|
||||
void setInitVisitor(osg::NodeVisitor* av) { _initVisitor = av; }
|
||||
@ -277,39 +266,18 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
const osgUtil::RenderStage* getRenderStageRight() const { return _renderStageRight.get(); }
|
||||
|
||||
|
||||
void setCullMask(const osg::Node::NodeMask nm) { _cullMask = nm; }
|
||||
osg::Node::NodeMask getCullMask() const { return _cullMask; }
|
||||
/** Set the draw buffer value used at the start of each frame draw. Note, overridden in quad buffer stereo mode */
|
||||
void setDrawBufferValue( GLenum drawBufferValue )
|
||||
{
|
||||
_drawBufferValue = drawBufferValue;
|
||||
}
|
||||
|
||||
void setCullMaskLeft(const osg::Node::NodeMask nm) { _cullMaskLeft = nm; }
|
||||
osg::Node::NodeMask getCullMaskLeft() const { return _cullMaskLeft; }
|
||||
/** Get the draw buffer value used at the start of each frame draw. */
|
||||
GLenum getDrawBufferValue() const
|
||||
{
|
||||
return _drawBufferValue;
|
||||
}
|
||||
|
||||
void setCullMaskRight(const osg::Node::NodeMask nm) { _cullMaskRight = nm; }
|
||||
osg::Node::NodeMask getCullMaskRight() const { return _cullMaskRight; }
|
||||
|
||||
|
||||
/** Set the LOD bias for the CullVisitor to use.*/
|
||||
void setLODScale(float bias) { _LODScale = bias; }
|
||||
|
||||
/** Get the LOD bias.*/
|
||||
float getLODScale() const { return _LODScale; }
|
||||
|
||||
/** Set the Small Feature Culling Pixel Size.*/
|
||||
void setSmallFeatureCullingPixelSize(float value) { _smallFeatureCullingPixelSize=value; }
|
||||
|
||||
/** Get the Small Feature Culling Pixel Size.*/
|
||||
float getSmallFeatureCullingPixelSize() const { return _smallFeatureCullingPixelSize; }
|
||||
|
||||
/** Set the culling mode for the CullVisitor to use.*/
|
||||
void setCullingMode(osg::CullStack::CullingMode mode) { _cullingMode = mode; }
|
||||
|
||||
/** Returns the current CullingMode.*/
|
||||
osg::CullStack::CullingMode getCullingMode() const { return _cullingMode; }
|
||||
|
||||
/** Set the ComputeNearFarMode for the CullVisitor to use.*/
|
||||
void setComputeNearFarMode(CullVisitor::ComputeNearFarMode cnfm) { _computeNearFar=cnfm; }
|
||||
|
||||
/** Get the ComputeNearFarMode.*/
|
||||
CullVisitor::ComputeNearFarMode getComputeNearFarMode() const { return _computeNearFar;}
|
||||
|
||||
/** FusionDistanceMode is used only when working in stereo.*/
|
||||
enum FusionDistanceMode
|
||||
@ -340,6 +308,19 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
/** get whether the draw method should call renderer->prioritizeTexture.*/
|
||||
bool getPrioritizeTextures() const { return _prioritizeTextures; }
|
||||
|
||||
/** callback for overidding the default method for compute the offset projection and view matrices.*/
|
||||
struct ComputeStereoMatricesCallback : public osg::Referenced
|
||||
{
|
||||
virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0;
|
||||
virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0;
|
||||
|
||||
virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0;
|
||||
virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0;
|
||||
};
|
||||
|
||||
void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; }
|
||||
ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() { return _computeStereoMatricesCallback.get(); }
|
||||
const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); }
|
||||
|
||||
/** Calculate, via glUnProject, the object coordinates of a window point.
|
||||
Note, current implementation requires that SceneView::draw() has been previously called
|
||||
@ -377,19 +358,6 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
|
||||
|
||||
|
||||
/** callback for overidding the default method for compute the offset projection and view matrices.*/
|
||||
struct ComputeStereoMatricesCallback : public osg::Referenced
|
||||
{
|
||||
virtual osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const = 0;
|
||||
virtual osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const = 0;
|
||||
|
||||
virtual osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const = 0;
|
||||
virtual osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const = 0;
|
||||
};
|
||||
|
||||
void setComputeStereoMatricesCallback(ComputeStereoMatricesCallback* callback) { _computeStereoMatricesCallback=callback; }
|
||||
ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() { return _computeStereoMatricesCallback.get(); }
|
||||
const ComputeStereoMatricesCallback* getComputeStereoMatricesCallback() const { return _computeStereoMatricesCallback.get(); }
|
||||
|
||||
inline osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const
|
||||
{
|
||||
@ -454,31 +422,25 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
|
||||
void clearArea(int x,int y,int width,int height,const osg::Vec4& color);
|
||||
|
||||
osg::ref_ptr<osg::Node> _sceneData;
|
||||
osg::ref_ptr<osg::StateSet> _globalStateSet;
|
||||
osg::ref_ptr<osg::StateSet> _localStateSet;
|
||||
osg::ref_ptr<osg::Light> _light;
|
||||
osg::ref_ptr<osg::State> _state;
|
||||
|
||||
osg::Matrixd _projectionMatrix;
|
||||
osg::Matrixd _viewMatrix;
|
||||
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
|
||||
osg::ref_ptr<osg::State> _state;
|
||||
|
||||
bool _initCalled;
|
||||
osg::ref_ptr<osg::NodeVisitor> _initVisitor;
|
||||
osg::ref_ptr<osg::NodeVisitor> _updateVisitor;
|
||||
osg::Node::NodeMask _cullMask;
|
||||
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitor;
|
||||
osg::ref_ptr<osgUtil::RenderGraph> _rendergraph;
|
||||
osg::ref_ptr<osgUtil::RenderStage> _renderStage;
|
||||
|
||||
osg::ref_ptr<ComputeStereoMatricesCallback> _computeStereoMatricesCallback;
|
||||
|
||||
osg::Node::NodeMask _cullMaskLeft;
|
||||
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorLeft;
|
||||
osg::ref_ptr<osgUtil::RenderGraph> _rendergraphLeft;
|
||||
osg::ref_ptr<osgUtil::RenderStage> _renderStageLeft;
|
||||
|
||||
osg::Node::NodeMask _cullMaskRight;
|
||||
osg::ref_ptr<osgUtil::CullVisitor> _cullVisitorRight;
|
||||
osg::ref_ptr<osgUtil::RenderGraph> _rendergraphRight;
|
||||
osg::ref_ptr<osgUtil::RenderStage> _renderStageRight;
|
||||
@ -486,14 +448,15 @@ class OSGUTIL_EXPORT SceneView : public osg::Referenced
|
||||
osg::ref_ptr<osg::CollectOccludersVisitor> _collectOccludersVisistor;
|
||||
|
||||
osg::ref_ptr<osg::FrameStamp> _frameStamp;
|
||||
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> _sceneData;
|
||||
osg::ref_ptr<osg::StateSet> _globalStateSet;
|
||||
osg::ref_ptr<osg::Light> _light;
|
||||
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
|
||||
|
||||
osg::Vec4 _clearColor;
|
||||
|
||||
CullVisitor::ComputeNearFarMode _computeNearFar;
|
||||
osg::CullStack::CullingMode _cullingMode;
|
||||
float _LODScale;
|
||||
float _smallFeatureCullingPixelSize;
|
||||
|
||||
FusionDistanceMode _fusionDistanceMode;
|
||||
float _fusionDistanceValue;
|
||||
|
53
src/osg/CullSettings.cpp
Normal file
53
src/osg/CullSettings.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osg/CullSettings>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
void CullSettings::setDefaults()
|
||||
{
|
||||
_cullingMode = DEFAULT_CULLING;
|
||||
_LODScale = 1.0f;
|
||||
_smallFeatureCullingPixelSize = 2.0f;
|
||||
|
||||
_computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
|
||||
_nearFarRatio = 0.0005f;
|
||||
_impostorActive = true;
|
||||
_depthSortImpostorSprites = false;
|
||||
_impostorPixelErrorThreshold = 4.0f;
|
||||
_numFramesToKeepImpostorSprites = 10;
|
||||
_cullMask = 0xffffffff;
|
||||
_cullMaskLeft = 0xffffffff;
|
||||
_cullMaskRight = 0xffffffff;
|
||||
|
||||
// override during testing
|
||||
_computeNearFar = COMPUTE_NEAR_FAR_USING_PRIMITIVES;
|
||||
_nearFarRatio = 0.0005f;
|
||||
}
|
||||
|
||||
void CullSettings::setCullSettings(const CullSettings& settings)
|
||||
{
|
||||
_computeNearFar = settings._computeNearFar;
|
||||
_nearFarRatio = settings._nearFarRatio;
|
||||
_impostorActive = settings._impostorActive;
|
||||
_depthSortImpostorSprites = settings._depthSortImpostorSprites;
|
||||
_impostorPixelErrorThreshold = settings._impostorPixelErrorThreshold;
|
||||
_numFramesToKeepImpostorSprites = settings._numFramesToKeepImpostorSprites;
|
||||
_cullMask = settings._cullMask;
|
||||
_cullMaskLeft = settings._cullMaskLeft;
|
||||
_cullMaskRight = settings._cullMaskRight;
|
||||
_cullingMode = settings._cullingMode;
|
||||
_LODScale = settings._LODScale;
|
||||
_smallFeatureCullingPixelSize = settings._smallFeatureCullingPixelSize;
|
||||
}
|
@ -17,9 +17,6 @@ using namespace osg;
|
||||
|
||||
CullStack::CullStack()
|
||||
{
|
||||
_cullingMode = DEFAULT_CULLING;
|
||||
_LODScale = 1.0f;
|
||||
_smallFeatureCullingPixelSize = 2.0f;
|
||||
_frustumVolume=-1.0f;
|
||||
_bbCornerNear = 0;
|
||||
_bbCornerFar = 7;
|
||||
|
@ -25,6 +25,7 @@ CXXFILES =\
|
||||
CullFace.cpp\
|
||||
CullingSet.cpp\
|
||||
CullStack.cpp\
|
||||
CullSettings.cpp\
|
||||
Depth.cpp\
|
||||
DisplaySettings.cpp\
|
||||
Drawable.cpp\
|
||||
|
@ -95,14 +95,8 @@ CullVisitor::CullVisitor():
|
||||
NodeVisitor(CULL_VISITOR,TRAVERSE_ACTIVE_CHILDREN),
|
||||
_currentRenderGraph(NULL),
|
||||
_currentRenderBin(NULL),
|
||||
_computeNearFar(COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES),
|
||||
_nearFarRatio(0.0005f),
|
||||
_computed_znear(FLT_MAX),
|
||||
_computed_zfar(-FLT_MAX),
|
||||
_impostorActive(true),
|
||||
_depthSortImpostorSprites(false),
|
||||
_impostorPixelErrorThreshold(4.0f),
|
||||
_numFramesToKeepImpostorSprites(10),
|
||||
_currentReuseRenderLeafIndex(0)
|
||||
{
|
||||
_impostorSpriteManager = new ImpostorSpriteManager;
|
||||
|
@ -36,12 +36,6 @@ SceneView::SceneView(DisplaySettings* ds)
|
||||
|
||||
_clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);
|
||||
|
||||
_computeNearFar = CullVisitor::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
|
||||
//_computeNearFar = CullVisitor::COMPUTE_NEAR_FAR_USING_PRIMITIVES;
|
||||
|
||||
_cullingMode = osg::CullStack::DEFAULT_CULLING;
|
||||
_LODScale = 1.0f;
|
||||
_smallFeatureCullingPixelSize = 3.0f;
|
||||
|
||||
_fusionDistanceMode = PROPORTIONAL_TO_SCREEN_DISTANCE;
|
||||
_fusionDistanceValue = 1.0f;
|
||||
@ -54,9 +48,6 @@ SceneView::SceneView(DisplaySettings* ds)
|
||||
|
||||
_initCalled = false;
|
||||
|
||||
_cullMask = 0xffffffff;
|
||||
_cullMaskLeft = 0xffffffff;
|
||||
_cullMaskRight = 0xffffffff;
|
||||
|
||||
_drawBufferValue = GL_BACK;
|
||||
|
||||
@ -71,6 +62,8 @@ SceneView::~SceneView()
|
||||
|
||||
void SceneView::setDefaults()
|
||||
{
|
||||
CullSettings::setDefaults();
|
||||
|
||||
_projectionMatrix.makePerspective(50.0f,1.4f,1.0f,10000.0f);
|
||||
_viewMatrix.makeIdentity();
|
||||
|
||||
@ -134,10 +127,6 @@ void SceneView::setDefaults()
|
||||
_globalStateSet->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
|
||||
|
||||
_clearColor.set(0.2f, 0.2f, 0.4f, 1.0f);
|
||||
|
||||
_cullMask = 0xffffffff;
|
||||
_cullMaskLeft = 0xffffffff;
|
||||
_cullMaskRight = 0xffffffff;
|
||||
}
|
||||
|
||||
void SceneView::init()
|
||||
@ -485,6 +474,8 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
||||
|
||||
if (!_collectOccludersVisistor) _collectOccludersVisistor = new osg::CollectOccludersVisitor;
|
||||
|
||||
_collectOccludersVisistor->setCullSettings(*this);
|
||||
|
||||
_collectOccludersVisistor->reset();
|
||||
|
||||
_collectOccludersVisistor->setFrameStamp(_frameStamp.get());
|
||||
@ -528,10 +519,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
|
||||
cullVisitor->setTraversalNumber(_frameStamp->getFrameNumber());
|
||||
}
|
||||
|
||||
cullVisitor->setCullingMode(_cullingMode);
|
||||
cullVisitor->setComputeNearFarMode(_computeNearFar);
|
||||
cullVisitor->setLODScale(_LODScale);
|
||||
cullVisitor->setSmallFeatureCullingPixelSize(_smallFeatureCullingPixelSize);
|
||||
cullVisitor->setCullSettings(*this);
|
||||
|
||||
cullVisitor->setClearNode(NULL); // reset earth sky on each frame.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user