Added new osg::Projection node, and osgUtil::NewCullVisitor which are work
in progress for the new support for controlling the projection matrix from within the scene graph. Also Added osg::State::getClippingVolume(), getProjectionMatrix() and getModelViewMatrix() with allows drawables to access the current projection, and model view matrices and the view frustum in local coords to the drawable.
This commit is contained in:
parent
2786e4c083
commit
3351306d80
@ -10,16 +10,16 @@ C++ = g++
|
||||
YFLAGS = -d
|
||||
LCINCS += -I/usr/X11R6/include
|
||||
LC++INCS += ${LCINCS}
|
||||
#CFLAGS = -O2 -W -Wall $(LCINCS)
|
||||
CFLAGS = -g -DOSG_USE_MEMORY_MANAGER -W -Wall $(LCINCS)
|
||||
CFLAGS = -O2 -W -Wall $(LCINCS)
|
||||
#CFLAGS = -g -DOSG_USE_MEMORY_MANAGER -W -Wall $(LCINCS)
|
||||
C++FLAGS = ${CFLAGS}
|
||||
CPPFLAGS = ${CFLAGS}
|
||||
|
||||
SO_EXT = so
|
||||
DL_EXT = so
|
||||
|
||||
#LDFLAGS = -O2 -W -Wall -L/usr/X11R6/lib
|
||||
LDFLAGS = -g -W -Wall -L/usr/X11R6/lib
|
||||
LDFLAGS = -O2 -W -Wall -L/usr/X11R6/lib
|
||||
#LDFLAGS = -g -W -Wall -L/usr/X11R6/lib
|
||||
|
||||
LINKERARGS = -Xlinker
|
||||
DYNAMICLIBRARYLIB = -ldl
|
||||
|
@ -269,6 +269,10 @@ SOURCE=..\..\src\osg\PositionAttitudeTransform.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Projection.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osg\Quat.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -549,6 +553,10 @@ SOURCE=..\..\Include\Osg\PositionAttitudeTransform
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Projection
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\Osg\Quat
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -109,6 +109,10 @@ SOURCE=..\..\src\osgUtil\CullVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\NewCullVisitor.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\osgUtil\DepthSortedBin.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -225,6 +229,10 @@ SOURCE=..\..\Include\osgUtil\CullVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\NewCullVisitor
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Include\osgUtil\DepthSortedBin
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -243,20 +243,12 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
const Matrix& getModelViewMatrix() const;
|
||||
|
||||
|
||||
/** Switch on/off the use of the near clipping plane which creating the
|
||||
* getClippingVolume(), uses the camera _znear value for the position of the
|
||||
* near clipping plane. By default this value is off.*/
|
||||
void setUseNearClippingPlane(const bool use);
|
||||
/** get whether the ClippingVolume uses a near clipping plane.*/
|
||||
const bool getUseNearClippingPlane() const { return _useNearClippingPlane; }
|
||||
|
||||
|
||||
/** Switch on/off the use of the far clipping plane which creating the
|
||||
/** Switch on/off the use of the near and far clipping plane which creating the
|
||||
* getClippingVolume(), uses the camera _zfar value for the position
|
||||
* of the far clipping plane. By default this value is off.*/
|
||||
void setUseFarClippingPlane(const bool use);
|
||||
/** Get whether the ClippingVolume uses a far clipping plane.*/
|
||||
const bool getUseFarClippingPlane() const { return _useFarClippingPlane; }
|
||||
void setUseNearAndFarClippingPlanes(const bool use);
|
||||
/** Get whether the ClippingVolume uses a near and far clipping planes.*/
|
||||
const bool getUseNearAndFarClippingPlanes() const { return _useNearAndFarClippingPlanes; }
|
||||
|
||||
/** get the view frustum clipping in model coordinates */
|
||||
const ClippingVolume& getClippingVolume() const;
|
||||
@ -348,9 +340,8 @@ class SG_EXPORT Camera: public osg::Referenced
|
||||
ref_ptr<Matrix> _eyeToModelTransform;
|
||||
ref_ptr<Matrix> _modelToEyeTransform;
|
||||
|
||||
// flags to determine if near and far clipping planes are required.
|
||||
bool _useNearClippingPlane;
|
||||
bool _useFarClippingPlane;
|
||||
// flag to determine if near and far clipping planes are required.
|
||||
bool _useNearAndFarClippingPlanes;
|
||||
|
||||
// cached matrix and clipping volume derived from above settings.
|
||||
mutable bool _dirty;
|
||||
|
@ -36,6 +36,29 @@ class SG_EXPORT ClippingVolume
|
||||
_planeList = cv._planeList;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Create a ClippingVolume with is cube, centered at 0,0,0, with sides of 2 units.*/
|
||||
void setToUnitFrustum()
|
||||
{
|
||||
_planeList.clear();
|
||||
_planeList.push_back(Plane(1.0f,0.0f,0.0f,1.0f)); // left plane.
|
||||
_planeList.push_back(Plane(-1.0f,0.0f,0.0f,1.0f)); // right plane.
|
||||
_planeList.push_back(Plane(0.0f,1.0f,0.0f,1.0f)); // bottom plane.
|
||||
_planeList.push_back(Plane(0.0f,-1.0f,0.0f,1.0f)); // top plane.
|
||||
_planeList.push_back(Plane(0.0f,0.0f,-1.0f,1.0f)); // near plane
|
||||
_planeList.push_back(Plane(0.0f,0.0f,1.0f,1.0f)); // far plane
|
||||
setupMask();
|
||||
}
|
||||
|
||||
void setToUnitFrustumWithoutNearFar()
|
||||
{
|
||||
_planeList.clear();
|
||||
_planeList.push_back(Plane(1.0f,0.0f,0.0f,1.0f)); // left plane.
|
||||
_planeList.push_back(Plane(-1.0f,0.0f,0.0f,1.0f)); // right plane.
|
||||
_planeList.push_back(Plane(0.0f,1.0f,0.0f,1.0f)); // bottom plane.
|
||||
_planeList.push_back(Plane(0.0f,-1.0f,0.0f,1.0f)); // top plane.
|
||||
setupMask();
|
||||
}
|
||||
|
||||
inline void set(const ClippingVolume& cs) { _planeList = cs._planeList; setupMask(); }
|
||||
|
||||
|
@ -16,6 +16,7 @@ class Billboard;
|
||||
class LightSource;
|
||||
class Group;
|
||||
class Transform;
|
||||
class Projection;
|
||||
class LOD;
|
||||
class Switch;
|
||||
class Impostor;
|
||||
@ -170,6 +171,7 @@ class SG_EXPORT NodeVisitor : public Referenced
|
||||
virtual void apply(LightSource& node){ apply((Node&)node); }
|
||||
|
||||
virtual void apply(Group& node) { apply((Node&)node); }
|
||||
virtual void apply(Projection& node) { apply((Group&)node); }
|
||||
virtual void apply(Transform& node) { apply((Group&)node); }
|
||||
virtual void apply(Switch& node) { apply((Group&)node); }
|
||||
virtual void apply(LOD& node) { apply((Group&)node); }
|
||||
|
52
include/osg/Projection
Normal file
52
include/osg/Projection
Normal file
@ -0,0 +1,52 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSG_PROJECTION
|
||||
#define OSG_PROJECTION 1
|
||||
|
||||
#include <osg/Group>
|
||||
#include <osg/Matrix>
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Projection nodes set up the frustum/orthographic projection used when rendering the scene .
|
||||
*/
|
||||
class SG_EXPORT Projection : public Group
|
||||
{
|
||||
public :
|
||||
|
||||
|
||||
Projection();
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
Projection(const Projection&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
Projection(const Matrix& matix);
|
||||
|
||||
META_Node(Projection);
|
||||
|
||||
/** Set the transform's matrix.*/
|
||||
void setMatrix(const Matrix& mat) { (*_matrix) = mat; }
|
||||
|
||||
/** Get the transform's matrix. */
|
||||
inline const Matrix& getMatrix() const { return *_matrix; }
|
||||
|
||||
/** preMult transform.*/
|
||||
void preMult(const Matrix& mat) { _matrix->preMult(mat); }
|
||||
|
||||
/** postMult transform.*/
|
||||
void postMult(const Matrix& mat) { _matrix->postMult(mat); }
|
||||
|
||||
|
||||
protected :
|
||||
|
||||
virtual ~Projection();
|
||||
|
||||
ref_ptr<Matrix> _matrix;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -66,12 +66,6 @@ class SG_EXPORT Transform : public Group
|
||||
/** Get the transform mode.*/
|
||||
inline const MatrixMode getMatrixMode() const { return _mode; }
|
||||
|
||||
/** Does the tranform set up the projection matrix.*/
|
||||
inline const bool isProjectionTransform() const { return _mode==PROJECTION; }
|
||||
|
||||
/** Does the tranform set up the modelview matrix.*/
|
||||
inline const bool isModelViewTransform() const { return _mode!=PROJECTION; }
|
||||
|
||||
/** Callback attached to an Transform to specifiy how to compute the modelview or projection transformation
|
||||
* for the transform below the Transform node.*/
|
||||
struct ComputeTransformCallback : public osg::Referenced
|
||||
|
@ -23,6 +23,7 @@ class OSGUTIL_EXPORT CullViewState : public osg::Referenced
|
||||
|
||||
CullViewState();
|
||||
|
||||
osg::ref_ptr<osg::Matrix> _projection;
|
||||
osg::ref_ptr<osg::Matrix> _matrix;
|
||||
osg::ref_ptr<osg::Matrix> _inverse;
|
||||
osg::Vec3 _eyePoint;
|
||||
|
@ -54,6 +54,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
|
||||
virtual void apply(osg::Group& node);
|
||||
virtual void apply(osg::Transform& node);
|
||||
virtual void apply(osg::Projection& node);
|
||||
virtual void apply(osg::Switch& node);
|
||||
virtual void apply(osg::LOD& node);
|
||||
virtual void apply(osg::EarthSky& node);
|
||||
@ -128,9 +129,11 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
/** Get the viewport. */
|
||||
osg::Viewport* getViewport() { return _viewport.get(); }
|
||||
|
||||
inline void pushCullViewState() { pushCullViewState(NULL,NULL); }
|
||||
void pushCullViewState(osg::Matrix* matrix);
|
||||
void pushCullViewState(osg::Matrix* matrix,osg::Matrix* inverse);
|
||||
inline void pushCullViewState() { pushCullViewState_ModelView(NULL,NULL); }
|
||||
|
||||
void pushCullViewState_Projection(osg::Matrix* matrix);
|
||||
void pushCullViewState_ModelView(osg::Matrix* matrix);
|
||||
void pushCullViewState_ModelView(osg::Matrix* matrix,osg::Matrix* inverse);
|
||||
|
||||
void popCullViewState();
|
||||
|
||||
@ -284,7 +287,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
_currentRenderBin->addRenderGraph(_currentRenderGraph);
|
||||
}
|
||||
//_currentRenderGraph->addLeaf(new RenderLeaf(drawable,matrix));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,matrix));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,_cvs->_projection.get(),matrix));
|
||||
}
|
||||
|
||||
/** Add a drawable and depth to current render graph.*/
|
||||
@ -298,7 +301,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
_currentRenderBin->addRenderGraph(_currentRenderGraph);
|
||||
}
|
||||
//_currentRenderGraph->addLeaf(new RenderLeaf(drawable,matrix,depth));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,matrix,depth));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,_cvs->_projection.get(),matrix,depth));
|
||||
}
|
||||
|
||||
/** Add a light to current render graph.*/
|
||||
@ -379,7 +382,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
RenderLeafList _reuseRenderLeafList;
|
||||
unsigned int _currentReuseRenderLeafIndex;
|
||||
|
||||
inline RenderLeaf* createOrReuseRenderLeaf(osg::Drawable* drawable,osg::Matrix* matrix, float depth=0.0f)
|
||||
inline RenderLeaf* createOrReuseRenderLeaf(osg::Drawable* drawable,osg::Matrix* projection,osg::Matrix* matrix, float depth=0.0f)
|
||||
{
|
||||
// skip of any already reused renderleaf.
|
||||
while (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size() &&
|
||||
@ -394,12 +397,12 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
if (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size())
|
||||
{
|
||||
RenderLeaf* renderleaf = _reuseRenderLeafList[_currentReuseRenderLeafIndex++].get();
|
||||
renderleaf->set(drawable,matrix,depth);
|
||||
renderleaf->set(drawable,projection,matrix,depth);
|
||||
return renderleaf;
|
||||
}
|
||||
|
||||
// otherwise need to create new renderleaf.
|
||||
RenderLeaf* renderleaf = new RenderLeaf(drawable,matrix,depth);
|
||||
RenderLeaf* renderleaf = new RenderLeaf(drawable,projection,matrix,depth);
|
||||
_reuseRenderLeafList.push_back(renderleaf);
|
||||
++_currentReuseRenderLeafIndex;
|
||||
return renderleaf;
|
||||
|
391
include/osgUtil/NewCullVisitor
Normal file
391
include/osgUtil/NewCullVisitor
Normal file
@ -0,0 +1,391 @@
|
||||
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
||||
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
||||
//as published by the Free Software Foundation.
|
||||
|
||||
#ifndef OSGUTIL_NEWCULLVISITOR
|
||||
#define OSGUTIL_NEWCULLVISITOR 1
|
||||
|
||||
#include <osg/NodeVisitor>
|
||||
#include <osg/BoundingSphere>
|
||||
#include <osg/BoundingBox>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/Drawable>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/State>
|
||||
#include <osg/Camera>
|
||||
#include <osg/Impostor>
|
||||
#include <osg/EarthSky>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgUtil/RenderGraph>
|
||||
#include <osgUtil/RenderStage>
|
||||
#include <osgUtil/CullViewState>
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <osg/Vec3>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
/**
|
||||
* Basic NodeVisitor implementation for rendering a scene.
|
||||
* This visitor traverses the scene graph, collecting transparent and
|
||||
* opaque osg::Drawables into a depth sorted transparent bin and a state
|
||||
* sorted opaque bin. The opaque bin is rendered first, and then the
|
||||
* transparent bin in rendered in order from the furthest osg::Drawable
|
||||
* from the eye to the one nearest the eye.
|
||||
*/
|
||||
class OSGUTIL_EXPORT NewCullVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
||||
NewCullVisitor();
|
||||
virtual ~NewCullVisitor();
|
||||
|
||||
virtual NewCullVisitor* cloneType() const { return new NewCullVisitor(); }
|
||||
|
||||
virtual void reset();
|
||||
|
||||
virtual void apply(osg::Node&);
|
||||
virtual void apply(osg::Geode& node);
|
||||
virtual void apply(osg::Billboard& node);
|
||||
virtual void apply(osg::LightSource& node);
|
||||
|
||||
virtual void apply(osg::Group& node);
|
||||
virtual void apply(osg::Transform& node);
|
||||
virtual void apply(osg::Projection& 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);
|
||||
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; }
|
||||
|
||||
/** Switch the creation of Impostors on or off.
|
||||
* Setting active to false forces the NewCullVisitor to use the Impostor
|
||||
* LOD children for rendering. Setting active to true forces the
|
||||
* NewCullVisitor to create the appropriate pre-rendering stages which
|
||||
* render to the ImpostorSprite's texture.*/
|
||||
void setImpostorsActive(const bool active) { _impostorActive = active; }
|
||||
|
||||
/** Get whether impostors are active or not. */
|
||||
const bool getImpostorsActive() const { return _impostorActive; }
|
||||
|
||||
/** Set the impostor error threshold.
|
||||
* Used in calculation of whether impostors remain valid.*/
|
||||
void setImpostorPixelErrorThreshold(const float numPixels) { _impostorPixelErrorThreshold=numPixels; }
|
||||
|
||||
/** Get the impostor error threshold.*/
|
||||
const float getImpostorPixelErrorThreshold() const { return _impostorPixelErrorThreshold; }
|
||||
|
||||
/** Set whether ImpsotorSprite's should be placed in a depth sorted bin for rendering.*/
|
||||
void setDepthSortImpostorSprites(const bool doDepthSort) { _depthSortImpostorSprites = doDepthSort; }
|
||||
|
||||
/** Get whether ImpsotorSprite's are depth sorted bin for rendering.*/
|
||||
const bool setDepthSortImpostorSprites() const { return _depthSortImpostorSprites; }
|
||||
|
||||
/** Set the number of frames that an ImpsotorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
void setNumberOfFrameToKeepImpostorSprites(const int numFrames) { _numFramesToKeepImpostorSprites = numFrames; }
|
||||
|
||||
/** Get the number of frames that an ImpsotorSprite's is kept whilst not being beyond,
|
||||
* before being recycled.*/
|
||||
const int getNumberOfFrameToKeepImpostorSprites() const { return _numFramesToKeepImpostorSprites; }
|
||||
|
||||
enum TransparencySortMode {
|
||||
LOOK_VECTOR_DISTANCE,
|
||||
OBJECT_EYE_POINT_DISTANCE
|
||||
};
|
||||
|
||||
void setTransparencySortMode(TransparencySortMode tsm) { _tsm = tsm; }
|
||||
|
||||
/** Sets the current CullingMode.*/
|
||||
void setCullingMode(CullViewState::CullingMode mode);
|
||||
|
||||
/** Returns the current CullingMode.*/
|
||||
CullViewState::CullingMode getCullingMode() const;
|
||||
|
||||
|
||||
/** Set the viewport.
|
||||
* Used to enable the NewCullVisitor can make decision
|
||||
* such as based on viewport dimensions.*/
|
||||
void setViewport(osg::Viewport* viewport) { _viewport = viewport; }
|
||||
|
||||
/** Get the const viewport. */
|
||||
const osg::Viewport* getViewport() const { return _viewport.get(); }
|
||||
|
||||
/** Get the viewport. */
|
||||
osg::Viewport* getViewport() { return _viewport.get(); }
|
||||
|
||||
inline void pushCullViewState() { pushCullViewState_ModelView(NULL,NULL); }
|
||||
|
||||
void pushCullViewState_Projection(osg::Matrix* matrix);
|
||||
void pushCullViewState_ModelView(osg::Matrix* matrix);
|
||||
void pushCullViewState_ModelView(osg::Matrix* matrix,osg::Matrix* inverse);
|
||||
|
||||
void popCullViewState();
|
||||
|
||||
/** 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.
|
||||
* Otherwise, create a new state group for the state set, add
|
||||
* it to the current state group then move the current state
|
||||
* group pointer to the new state group.
|
||||
*/
|
||||
inline void pushStateSet(const osg::StateSet* ss)
|
||||
{
|
||||
_currentRenderGraph = _currentRenderGraph->find_or_insert(ss);
|
||||
if (ss->useRenderBinDetails())
|
||||
{
|
||||
_currentRenderBin = _currentRenderBin->find_or_insert(ss->getBinNumber(),ss->getBinName());
|
||||
}
|
||||
}
|
||||
|
||||
/** Pop the top state set and hence associated state group.
|
||||
* Move the current state group to the parent of the popped
|
||||
* state group.
|
||||
*/
|
||||
inline void popStateSet()
|
||||
{
|
||||
if (_currentRenderGraph->_stateset->useRenderBinDetails())
|
||||
{
|
||||
_currentRenderBin = _currentRenderBin->_parent;
|
||||
}
|
||||
_currentRenderGraph = _currentRenderGraph->_parent;
|
||||
}
|
||||
|
||||
void setRenderGraph(RenderGraph* rg)
|
||||
{
|
||||
_rootRenderGraph = rg;
|
||||
_currentRenderGraph = rg;
|
||||
}
|
||||
|
||||
RenderGraph* getRenderGraph()
|
||||
{
|
||||
return _rootRenderGraph.get();
|
||||
}
|
||||
|
||||
void setRenderStage(RenderStage* rg)
|
||||
{
|
||||
_rootRenderStage = rg;
|
||||
_currentRenderBin = rg;
|
||||
}
|
||||
|
||||
RenderStage* getRenderStage()
|
||||
{
|
||||
return _rootRenderStage.get();
|
||||
}
|
||||
|
||||
const float getCalculatedNearPlane() const { return _calculated_znear; }
|
||||
|
||||
const float getCalculatedFarPlane() const { return _calculated_zfar; }
|
||||
|
||||
protected:
|
||||
|
||||
/** prevent unwanted copy construction.*/
|
||||
NewCullVisitor(const NewCullVisitor&):osg::NodeVisitor() {}
|
||||
|
||||
/** prevent unwanted copy operator.*/
|
||||
NewCullVisitor& operator = (const NewCullVisitor&) { return *this; }
|
||||
|
||||
inline osg::Matrix* getCurrentMatrix()
|
||||
{
|
||||
return _cvs->_matrix.get();
|
||||
}
|
||||
|
||||
|
||||
inline osg::Matrix* getInverseCurrentMatrix()
|
||||
{
|
||||
return _cvs->_inverse.get();
|
||||
}
|
||||
|
||||
inline const osg::Vec3& getEyeLocal() const
|
||||
{
|
||||
return _cvs->_eyePoint;
|
||||
}
|
||||
|
||||
inline const osg::Vec3& getUpLocal() const
|
||||
{
|
||||
return _cvs->_upVector;
|
||||
}
|
||||
|
||||
inline const osg::Vec3& getCenterLocal() const
|
||||
{
|
||||
return _cvs->_centerPoint;
|
||||
}
|
||||
|
||||
|
||||
inline const osg::Vec3& getLookVectorLocal() const
|
||||
{
|
||||
return _cvs->_lookVector;
|
||||
}
|
||||
|
||||
|
||||
inline bool isCulled(const osg::BoundingSphere& sp,CullViewState::CullingMode& mode) const
|
||||
{
|
||||
return _cvs->isCulled(sp,mode);
|
||||
}
|
||||
|
||||
inline const bool isCulled(const osg::BoundingBox& bb,const CullViewState::CullingMode mode) const
|
||||
{
|
||||
return _cvs->isCulled(bb,mode);
|
||||
}
|
||||
|
||||
void updateCalculatedNearFar(const osg::BoundingBox& bb);
|
||||
|
||||
void updateCalculatedNearFar(const osg::Vec3& pos);
|
||||
|
||||
/**calculates near for "global" vertex in scene*/
|
||||
double calculateZNear(const osg::Vec3& position, const osg::Vec3& eye, const osg::Vec3& look);
|
||||
|
||||
|
||||
/** Add a drawable to current render graph.*/
|
||||
inline void addDrawable(osg::Drawable* drawable,osg::Matrix* matrix)
|
||||
{
|
||||
if (_currentRenderGraph->leaves_empty())
|
||||
{
|
||||
// this is first leaf to be added to RenderGraph
|
||||
// and therefore should not already know to current render bin,
|
||||
// so need to add it.
|
||||
_currentRenderBin->addRenderGraph(_currentRenderGraph);
|
||||
}
|
||||
//_currentRenderGraph->addLeaf(new RenderLeaf(drawable,matrix));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,_cvs->_projection.get(),matrix));
|
||||
}
|
||||
|
||||
/** Add a drawable and depth to current render graph.*/
|
||||
inline void addDrawableAndDepth(osg::Drawable* drawable,osg::Matrix* matrix,const float depth)
|
||||
{
|
||||
if (_currentRenderGraph->leaves_empty())
|
||||
{
|
||||
// this is first leaf to be added to RenderGraph
|
||||
// and therefore should not already know to current render bin,
|
||||
// so need to add it.
|
||||
_currentRenderBin->addRenderGraph(_currentRenderGraph);
|
||||
}
|
||||
//_currentRenderGraph->addLeaf(new RenderLeaf(drawable,matrix,depth));
|
||||
_currentRenderGraph->addLeaf(createOrReuseRenderLeaf(drawable,_cvs->_projection.get(),matrix,depth));
|
||||
}
|
||||
|
||||
/** Add a light to current render graph.*/
|
||||
inline void addLight(osg::Light* light,osg::Matrix* matrix)
|
||||
{
|
||||
_currentRenderBin->_stage->addLight(light,matrix);
|
||||
}
|
||||
|
||||
/** create an impostor sprite by setting up a pre-rendering stage
|
||||
* to generate the impostor texture. */
|
||||
osg::ImpostorSprite* createImpostorSprite(osg::Impostor& node);
|
||||
|
||||
typedef std::vector< osg::ref_ptr<CullViewState> > CullViewStateStack;
|
||||
CullViewStateStack _viewStateStack;
|
||||
osg::ref_ptr<CullViewState> _tvs;
|
||||
osg::ref_ptr<CullViewState> _cvs;
|
||||
|
||||
osg::ref_ptr<RenderGraph> _rootRenderGraph;
|
||||
RenderGraph* _currentRenderGraph;
|
||||
|
||||
osg::ref_ptr<RenderStage> _rootRenderStage;
|
||||
RenderBin* _currentRenderBin;
|
||||
|
||||
std::vector<CullViewState::CullingMode> _cullingModeStack;
|
||||
|
||||
float _LODBias;
|
||||
|
||||
float _calculated_znear;
|
||||
float _calculated_zfar;
|
||||
|
||||
osg::ref_ptr<const osg::Camera> _camera;
|
||||
|
||||
osg::ref_ptr<const osg::EarthSky> _earthSky;
|
||||
|
||||
TransparencySortMode _tsm;
|
||||
|
||||
// viewport x,y,width,height respectively.
|
||||
osg::ref_ptr<osg::Viewport> _viewport;
|
||||
|
||||
bool _impostorActive;
|
||||
bool _depthSortImpostorSprites;
|
||||
float _impostorPixelErrorThreshold;
|
||||
int _numFramesToKeepImpostorSprites;
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Matrix> > MatrixList;
|
||||
MatrixList _reuseMatrixList;
|
||||
unsigned int _currentReuseMatrixIndex;
|
||||
|
||||
inline osg::Matrix* createOrReuseMatrix()
|
||||
{
|
||||
// skip of any already reused matrix.
|
||||
while (_currentReuseMatrixIndex<_reuseMatrixList.size() &&
|
||||
_reuseMatrixList[_currentReuseMatrixIndex]->referenceCount()>1)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning:createOrReuseMatrix() skipping multiply refrenced entry."<< std::endl;
|
||||
++_currentReuseMatrixIndex;
|
||||
}
|
||||
|
||||
// if still within list, element must be singularly referenced
|
||||
// there return it to be reused.
|
||||
if (_currentReuseMatrixIndex<_reuseMatrixList.size())
|
||||
{
|
||||
osg::Matrix* matrix = _reuseMatrixList[_currentReuseMatrixIndex++].get();
|
||||
matrix->makeIdentity();
|
||||
return matrix;
|
||||
}
|
||||
|
||||
// otherwise need to create new matrix.
|
||||
osg::Matrix* matrix = new osg::Matrix();
|
||||
_reuseMatrixList.push_back(matrix);
|
||||
++_currentReuseMatrixIndex;
|
||||
return matrix;
|
||||
}
|
||||
|
||||
typedef std::vector< osg::ref_ptr<RenderLeaf> > RenderLeafList;
|
||||
RenderLeafList _reuseRenderLeafList;
|
||||
unsigned int _currentReuseRenderLeafIndex;
|
||||
|
||||
inline RenderLeaf* createOrReuseRenderLeaf(osg::Drawable* drawable,osg::Matrix* projection,osg::Matrix* matrix, float depth=0.0f)
|
||||
{
|
||||
// skip of any already reused renderleaf.
|
||||
while (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size() &&
|
||||
_reuseRenderLeafList[_currentReuseRenderLeafIndex]->referenceCount()>1)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning:createOrReuseRenderLeaf() skipping multiply refrenced entry."<< std::endl;
|
||||
++_currentReuseRenderLeafIndex;
|
||||
}
|
||||
|
||||
// if still within list, element must be singularly referenced
|
||||
// there return it to be reused.
|
||||
if (_currentReuseRenderLeafIndex<_reuseRenderLeafList.size())
|
||||
{
|
||||
RenderLeaf* renderleaf = _reuseRenderLeafList[_currentReuseRenderLeafIndex++].get();
|
||||
renderleaf->set(drawable,projection,matrix,depth);
|
||||
return renderleaf;
|
||||
}
|
||||
|
||||
// otherwise need to create new renderleaf.
|
||||
RenderLeaf* renderleaf = new RenderLeaf(drawable,projection,matrix,depth);
|
||||
_reuseRenderLeafList.push_back(renderleaf);
|
||||
++_currentReuseRenderLeafIndex;
|
||||
return renderleaf;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::ImpostorSpriteManager> _impostorSpriteManager;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -24,18 +24,20 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
public:
|
||||
|
||||
|
||||
inline RenderLeaf(osg::Drawable* drawable,osg::Matrix* matrix, float depth=0.0f):
|
||||
inline RenderLeaf(osg::Drawable* drawable,osg::Matrix* projection,osg::Matrix* modelview, float depth=0.0f):
|
||||
_parent(NULL),
|
||||
_drawable(drawable),
|
||||
_matrix(matrix),
|
||||
_projection(projection),
|
||||
_modelview(modelview),
|
||||
_depth(depth) {}
|
||||
|
||||
|
||||
inline void set(osg::Drawable* drawable,osg::Matrix* matrix, float depth=0.0f)
|
||||
inline void set(osg::Drawable* drawable,osg::Matrix* projection,osg::Matrix* modelview, float depth=0.0f)
|
||||
{
|
||||
_parent = NULL;
|
||||
_drawable = drawable;
|
||||
_matrix = matrix;
|
||||
_projection = projection,
|
||||
_modelview = modelview,
|
||||
_depth = depth;
|
||||
}
|
||||
|
||||
@ -43,7 +45,8 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
{
|
||||
_parent = NULL;
|
||||
_drawable = NULL;
|
||||
_matrix = NULL;
|
||||
_projection = NULL;
|
||||
_modelview = NULL;
|
||||
_depth = 0.0f;
|
||||
}
|
||||
|
||||
@ -57,7 +60,8 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
|
||||
RenderGraph* _parent;
|
||||
osg::Drawable* _drawable;
|
||||
osg::ref_ptr<osg::Matrix> _matrix;
|
||||
osg::ref_ptr<osg::Matrix> _projection;
|
||||
osg::ref_ptr<osg::Matrix> _modelview;
|
||||
float _depth;
|
||||
|
||||
private:
|
||||
@ -66,7 +70,8 @@ class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
|
||||
RenderLeaf():
|
||||
_parent(NULL),
|
||||
_drawable(NULL),
|
||||
_matrix(NULL),
|
||||
_projection(NULL),
|
||||
_modelview(NULL),
|
||||
_depth(0.0f) {}
|
||||
|
||||
/// disallow copy construction.
|
||||
|
@ -12,10 +12,14 @@
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/DisplaySettings>
|
||||
|
||||
#include <osgUtil/CullVisitor>
|
||||
|
||||
//#include <osgUtil/CullVisitor>
|
||||
#include <osgUtil/NewCullVisitor>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
typedef NewCullVisitor CullVisitor;
|
||||
|
||||
/**
|
||||
* SceneView is literally a view of a scene, encapsulating the
|
||||
* camera, global state, lights and the scene itself. Provides
|
||||
|
@ -28,8 +28,7 @@ Camera::Camera(DisplaySettings* ds)
|
||||
_center.set(0.0f,0.0f,-1.0f);
|
||||
_up.set(0.0f,1.0f,0.0f);
|
||||
|
||||
_useNearClippingPlane = false;
|
||||
_useFarClippingPlane = false;
|
||||
_useNearAndFarClippingPlanes = false;
|
||||
|
||||
_useEyeOffset = false;
|
||||
_eyeOffset.set(0.0f,0.0f,0.0f);
|
||||
@ -88,14 +87,13 @@ void Camera::copy(const Camera& camera)
|
||||
_modelToEyeTransform = camera._modelToEyeTransform;
|
||||
|
||||
// flags to determine if near and far clipping planes are required.
|
||||
_useNearClippingPlane = camera._useNearClippingPlane;
|
||||
_useFarClippingPlane = camera._useFarClippingPlane;
|
||||
_useNearAndFarClippingPlanes = camera._useNearAndFarClippingPlanes;
|
||||
|
||||
// cached matrix and clipping volume derived from above settings.
|
||||
_dirty = false;// camera._dirty;
|
||||
_projectionMatrix = NULL; //camera._projectionMatrix;
|
||||
_modelViewMatrix = NULL; //camera._modelViewMatrix;
|
||||
// _clippingVolume = camera._clippingVolume;
|
||||
_clippingVolume = camera._clippingVolume;
|
||||
|
||||
_mp = NULL;
|
||||
_inversemp = NULL;
|
||||
@ -588,20 +586,11 @@ const Matrix& Camera::getModelViewMatrix() const
|
||||
return *_modelViewMatrix;
|
||||
}
|
||||
|
||||
void Camera::setUseNearClippingPlane(const bool use)
|
||||
void Camera::setUseNearAndFarClippingPlanes(const bool use)
|
||||
{
|
||||
if (_useNearClippingPlane != use)
|
||||
if (_useNearAndFarClippingPlanes != use)
|
||||
{
|
||||
_useNearClippingPlane = use;
|
||||
_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::setUseFarClippingPlane(const bool use)
|
||||
{
|
||||
if (_useFarClippingPlane != use)
|
||||
{
|
||||
_useFarClippingPlane = use;
|
||||
_useNearAndFarClippingPlanes = use;
|
||||
_dirty = true;
|
||||
}
|
||||
}
|
||||
@ -739,57 +728,56 @@ void Camera::calculateMatricesAndClippingVolume() const
|
||||
}
|
||||
|
||||
|
||||
_clippingVolume.clear();
|
||||
// _clippingVolume.clear();
|
||||
//
|
||||
// // set the clipping volume.
|
||||
// switch(_projectionType)
|
||||
// {
|
||||
// case(ORTHO):
|
||||
// case(ORTHO2D):
|
||||
// {
|
||||
// }
|
||||
// break;
|
||||
// case(FRUSTUM):
|
||||
// case(PERSPECTIVE):
|
||||
// {
|
||||
// // calculate the frustum normals, postive pointing inwards.
|
||||
// // left clipping plane
|
||||
// // note, _left,_right,_top and _bottom are already devided
|
||||
// // by _zNear so no need to take into account for normal
|
||||
// // calculations.
|
||||
// Vec3 leftNormal (1.0f,0.0f,left);
|
||||
// leftNormal.normalize();
|
||||
// _clippingVolume.add(Plane(leftNormal,0.0f));
|
||||
//
|
||||
//
|
||||
// Vec3 rightNormal (-1.0f,0.0f,-right);
|
||||
// rightNormal.normalize();
|
||||
// _clippingVolume.add(Plane(rightNormal,0.0f));
|
||||
//
|
||||
// Vec3 bottomNormal(0.0f,1.0f,bottom);
|
||||
// bottomNormal.normalize();
|
||||
// _clippingVolume.add(Plane(bottomNormal,0.0f));
|
||||
//
|
||||
// Vec3 topNormal(0.0f,-1.0f,-top);
|
||||
// topNormal.normalize();
|
||||
// _clippingVolume.add(Plane(topNormal,0.0f));
|
||||
//
|
||||
// if (_useNearClippingPlane)
|
||||
// {
|
||||
// _clippingVolume.add(Plane(0.0f,0.0f,-1.0f,-_zNear));
|
||||
// }
|
||||
//
|
||||
// if (_useFarClippingPlane)
|
||||
// {
|
||||
// _clippingVolume.add(Plane(0.0f,0.0f,1.0f,_zFar));
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// break;
|
||||
//
|
||||
// }
|
||||
|
||||
// set the clipping volume.
|
||||
switch(_projectionType)
|
||||
{
|
||||
case(ORTHO):
|
||||
case(ORTHO2D):
|
||||
{
|
||||
}
|
||||
break;
|
||||
case(FRUSTUM):
|
||||
case(PERSPECTIVE):
|
||||
{
|
||||
// calculate the frustum normals, postive pointing inwards.
|
||||
// left clipping plane
|
||||
// note, _left,_right,_top and _bottom are already devided
|
||||
// by _zNear so no need to take into account for normal
|
||||
// calculations.
|
||||
Vec3 leftNormal (1.0f,0.0f,left);
|
||||
leftNormal.normalize();
|
||||
_clippingVolume.add(Plane(leftNormal,0.0f));
|
||||
|
||||
|
||||
Vec3 rightNormal (-1.0f,0.0f,-right);
|
||||
rightNormal.normalize();
|
||||
_clippingVolume.add(Plane(rightNormal,0.0f));
|
||||
|
||||
Vec3 bottomNormal(0.0f,1.0f,bottom);
|
||||
bottomNormal.normalize();
|
||||
_clippingVolume.add(Plane(bottomNormal,0.0f));
|
||||
|
||||
Vec3 topNormal(0.0f,-1.0f,-top);
|
||||
topNormal.normalize();
|
||||
_clippingVolume.add(Plane(topNormal,0.0f));
|
||||
|
||||
if (_useNearClippingPlane)
|
||||
{
|
||||
_clippingVolume.add(Plane(0.0f,0.0f,-1.0f,-_zNear));
|
||||
}
|
||||
|
||||
if (_useFarClippingPlane)
|
||||
{
|
||||
_clippingVolume.add(Plane(0.0f,0.0f,1.0f,_zFar));
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
_clippingVolume.transformProvidingInverse(*_modelViewMatrix);
|
||||
|
||||
if (!_mp.valid()) _mp = osgNew Matrix;
|
||||
_mp->mult(*_modelViewMatrix,*_projectionMatrix);
|
||||
@ -800,6 +788,18 @@ void Camera::calculateMatricesAndClippingVolume() const
|
||||
notify(WARN)<<"Warning: Camera::calculateMatricesAndClippingVolume() failed to invert _mp"<<std::endl;
|
||||
}
|
||||
|
||||
// set up clipping volume.
|
||||
if (_useNearAndFarClippingPlanes)
|
||||
{
|
||||
_clippingVolume.setToUnitFrustum();
|
||||
}
|
||||
else
|
||||
{
|
||||
_clippingVolume.setToUnitFrustumWithoutNearFar();
|
||||
}
|
||||
_clippingVolume.transformProvidingInverse(*_mp);
|
||||
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
||||
|
@ -47,6 +47,7 @@ C++FILES = \
|
||||
PolygonMode.cpp\
|
||||
PolygonOffset.cpp\
|
||||
PositionAttitudeTransform.cpp\
|
||||
Projection.cpp\
|
||||
Quat.cpp\
|
||||
ShadeModel.cpp\
|
||||
State.cpp\
|
||||
@ -121,6 +122,7 @@ TARGET_INCLUDE_FILES = \
|
||||
osg/PolygonOffset\
|
||||
osg/PositionAttitudeTransform\
|
||||
osg/Plane\
|
||||
osg/Projection\
|
||||
osg/Quat\
|
||||
osg/Referenced\
|
||||
osg/ShadeModel\
|
||||
|
24
src/osg/Projection.cpp
Normal file
24
src/osg/Projection.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <osg/Projection>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Projection::Projection()
|
||||
{
|
||||
_matrix = osgNew Matrix;
|
||||
}
|
||||
|
||||
Projection::Projection(const Projection& projection,const CopyOp& copyop):
|
||||
Group(projection,copyop),
|
||||
_matrix(osgNew Matrix(*projection._matrix))
|
||||
{
|
||||
}
|
||||
|
||||
Projection::Projection(const Matrix& mat )
|
||||
{
|
||||
_matrix = osgNew Matrix(mat);
|
||||
}
|
||||
|
||||
|
||||
Projection::~Projection()
|
||||
{
|
||||
}
|
@ -569,3 +569,11 @@ void State::haveAppliedAttribute(const StateAttribute::Type type)
|
||||
as.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
ClippingVolume State::getClippingVolume() const
|
||||
{
|
||||
ClippingVolume cv;
|
||||
cv.setToUnitFrustum();
|
||||
cv.transformProvidingInverse((*_modelView)*(*_projection));
|
||||
return cv;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ using namespace osgUtil;
|
||||
|
||||
CullViewState::CullViewState()
|
||||
{
|
||||
_projection = NULL;
|
||||
_matrix = NULL;
|
||||
_inverse = NULL;
|
||||
_ratio2 = 0.002f*0.002f;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <osg/Transform>
|
||||
#include <osg/Projection>
|
||||
#include <osg/Geode>
|
||||
#include <osg/LOD>
|
||||
#include <osg/Billboard>
|
||||
@ -60,6 +61,7 @@ class PrintVisitor : public NodeVisitor
|
||||
|
||||
virtual void apply(Group& node) { apply((Node&)node); }
|
||||
virtual void apply(Transform& node) { apply((Group&)node); }
|
||||
virtual void apply(Projection& node) { apply((Group&)node); }
|
||||
virtual void apply(Switch& node) { apply((Group&)node); }
|
||||
virtual void apply(LOD& node) { apply((Group&)node); }
|
||||
virtual void apply(Impostor& node) { apply((LOD&)node); }
|
||||
@ -487,19 +489,26 @@ void CullVisitor::setCamera(const Camera& camera)
|
||||
|
||||
}
|
||||
|
||||
void CullVisitor::pushCullViewState(Matrix* matrix)
|
||||
void CullVisitor::pushCullViewState_Projection(Matrix* matrix)
|
||||
{
|
||||
std::cout<<"CullVisitor::pushCullViewState_Projection(Matrix* matrix) not properly implemented yet..."<<std::endl;
|
||||
pushCullViewState_ModelView(NULL,NULL);
|
||||
}
|
||||
|
||||
|
||||
void CullVisitor::pushCullViewState_ModelView(Matrix* matrix)
|
||||
{
|
||||
if (matrix)
|
||||
{
|
||||
osg::Matrix* inverse = osgNew osg::Matrix;
|
||||
inverse->invert(*matrix);
|
||||
pushCullViewState(matrix,inverse);
|
||||
pushCullViewState_ModelView(matrix,inverse);
|
||||
}
|
||||
else
|
||||
pushCullViewState(NULL,NULL);
|
||||
pushCullViewState_ModelView(NULL,NULL);
|
||||
}
|
||||
|
||||
void CullVisitor::pushCullViewState(Matrix* matrix,osg::Matrix* inverse)
|
||||
void CullVisitor::pushCullViewState_ModelView(Matrix* matrix,osg::Matrix* inverse)
|
||||
{
|
||||
|
||||
osg::ref_ptr<CullViewState> nvs = osgNew CullViewState;
|
||||
@ -1117,27 +1126,46 @@ void CullVisitor::apply(Transform& node)
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
bool isModelView = node.isModelViewTransform();
|
||||
if (isModelView)
|
||||
{
|
||||
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix();
|
||||
ref_ptr<osg::Matrix> inverse = createOrReuseMatrix();
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
node.getWorldToLocalMatrix(*inverse,this);
|
||||
pushCullViewState(matrix.get(),inverse.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::WARN)<<"Warning: Projection Transform in scene graph has been ignored, not fully implemented yet."<<std::endl;
|
||||
}
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix();
|
||||
ref_ptr<osg::Matrix> inverse = createOrReuseMatrix();
|
||||
node.getLocalToWorldMatrix(*matrix,this);
|
||||
node.getWorldToLocalMatrix(*inverse,this);
|
||||
pushCullViewState_ModelView(matrix.get(),inverse.get());
|
||||
|
||||
traverse(node);
|
||||
|
||||
if (isModelView)
|
||||
{
|
||||
popCullViewState();
|
||||
}
|
||||
popCullViewState();
|
||||
|
||||
// pop the node's state off the render graph stack.
|
||||
if (node_state) popStateSet();
|
||||
|
||||
// pop the culling mode.
|
||||
_cullingModeStack.pop_back();
|
||||
}
|
||||
|
||||
void CullVisitor::apply(Projection& node)
|
||||
{
|
||||
// return if object's bounding sphere is culled.
|
||||
CullViewState::CullingMode mode = _cullingModeStack.back();
|
||||
|
||||
if (!node.getCullingActive()) mode = 0;
|
||||
else if (node.getNumChildrenWithCullingDisabled()==0 &&
|
||||
isCulled(node.getBound(),mode)) return;
|
||||
|
||||
// push the culling mode.
|
||||
_cullingModeStack.push_back(mode);
|
||||
|
||||
// push the node's state.
|
||||
StateSet* node_state = node.getStateSet();
|
||||
if (node_state) pushStateSet(node_state);
|
||||
|
||||
ref_ptr<osg::Matrix> matrix = createOrReuseMatrix();
|
||||
*matrix = node.getMatrix();
|
||||
pushCullViewState_Projection(matrix.get());
|
||||
|
||||
traverse(node);
|
||||
|
||||
popCullViewState();
|
||||
|
||||
// pop the node's state off the render graph stack.
|
||||
if (node_state) popStateSet();
|
||||
@ -1398,7 +1426,7 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
|
||||
|
||||
// pushing the cull view state will update it so it takes
|
||||
// into account the new camera orientation.
|
||||
pushCullViewState(rotate_matrix);
|
||||
pushCullViewState_ModelView(rotate_matrix);
|
||||
|
||||
// what shall we do about the near far?
|
||||
// we could need to save the near and far, or switch it off.
|
||||
|
@ -5,6 +5,7 @@ C++FILES = \
|
||||
AppVisitor.cpp\
|
||||
CameraManipulator.cpp\
|
||||
CullVisitor.cpp\
|
||||
NewCullVisitor.cpp\
|
||||
CullViewState.cpp\
|
||||
DisplayListVisitor.cpp\
|
||||
DisplayRequirementsVisitor.cpp\
|
||||
@ -46,6 +47,7 @@ TARGET_INCLUDE_FILES = \
|
||||
osgUtil/AppVisitor\
|
||||
osgUtil/CameraManipulator\
|
||||
osgUtil/CullVisitor\
|
||||
osgUtil/NewCullVisitor\
|
||||
osgUtil/CullViewState\
|
||||
osgUtil/DepthSortedBin\
|
||||
osgUtil/DisplayListVisitor\
|
||||
|
1297
src/osgUtil/NewCullVisitor.cpp
Normal file
1297
src/osgUtil/NewCullVisitor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -185,7 +185,7 @@ bool RenderBin::getStats(osg::Statistics* primStats)
|
||||
RenderLeaf* rl = dw_itr->get();
|
||||
Drawable* dw= rl->_drawable;
|
||||
primStats->addOpaque(); // number of geosets
|
||||
if (rl->_matrix.get()) primStats->addMatrix(); // number of matrices
|
||||
if (rl->_modelview.get()) primStats->addMatrix(); // number of matrices
|
||||
if (dw) { // then tot up the types 1-14
|
||||
// commenting out as having intrusive stats in base classes is
|
||||
// undersirable.
|
||||
|
@ -30,7 +30,8 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
|
||||
|
||||
}
|
||||
|
||||
state.applyModelViewMatrix(_matrix.get());
|
||||
//state.applyProjectionMatrix(_projection.get());
|
||||
state.applyModelViewMatrix(_modelview.get());
|
||||
|
||||
_drawable->draw(state);
|
||||
}
|
||||
@ -41,7 +42,8 @@ void RenderLeaf::render(State& state,RenderLeaf* previous)
|
||||
// send state changes and matrix changes to OpenGL.
|
||||
state.apply(_parent->_stateset.get());
|
||||
|
||||
state.applyModelViewMatrix(_matrix.get());
|
||||
//state.applyProjectionMatrix(_projection.get());
|
||||
state.applyModelViewMatrix(_modelview.get());
|
||||
|
||||
_drawable->draw(state);
|
||||
}
|
||||
|
@ -250,10 +250,10 @@ void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor
|
||||
cullVisitor->setRenderGraph(rendergraph);
|
||||
cullVisitor->setRenderStage(renderStage);
|
||||
|
||||
// SandB
|
||||
//now make it compute "clipping directions" needed for detailed culling
|
||||
if(cullVisitor->getDetailedCulling())
|
||||
cullVisitor->calcClippingDirections();//only once pre frame
|
||||
// // SandB
|
||||
// //now make it compute "clipping directions" needed for detailed culling
|
||||
// if(cullVisitor->getDetailedCulling())
|
||||
// cullVisitor->calcClippingDirections();//only once pre frame
|
||||
|
||||
renderStage->reset();
|
||||
|
||||
@ -285,7 +285,7 @@ void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor
|
||||
if (_globalState.valid()) cullVisitor->pushStateSet(_globalState.get());
|
||||
|
||||
|
||||
cullVisitor->pushCullViewState(modelview);
|
||||
cullVisitor->pushCullViewState_ModelView(modelview);
|
||||
|
||||
|
||||
// traverse the scene graph to generate the rendergraph.
|
||||
@ -331,13 +331,13 @@ void SceneView::cullStage(osg::Camera* camera, osgUtil::CullVisitor* cullVisitor
|
||||
_far_plane *= 1.05;
|
||||
_near_plane *= 0.95;
|
||||
|
||||
// if required clamp the near plane to prevent negative or near zero
|
||||
// near planes.
|
||||
if(!cullVisitor->getDetailedCulling())
|
||||
{
|
||||
// // if required clamp the near plane to prevent negative or near zero
|
||||
// // near planes.
|
||||
// if(!cullVisitor->getDetailedCulling())
|
||||
// {
|
||||
float min_near_plane = _far_plane*0.0005f;
|
||||
if (_near_plane<min_near_plane) _near_plane=min_near_plane;
|
||||
}
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user