Various updates to operations related to cull traversal.
This commit is contained in:
parent
78b7c375d8
commit
02fc6ad5f8
@ -581,6 +581,10 @@ SOURCE=..\..\Include\Osg\Quat
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osg\fast_back_stack
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\include\osg\ref_ptr
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
67
include/osg/fast_back_stack
Normal file
67
include/osg/fast_back_stack
Normal file
@ -0,0 +1,67 @@
|
||||
//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_FAST_BACK_STACK
|
||||
#define OSG_FAST_BACK_STACK 1
|
||||
|
||||
namespace osg {
|
||||
|
||||
/** Simple stack implementation that keeps the back() cached locally for fast access
|
||||
* rather than at the back of the vector which is the traditional stack implementation.
|
||||
* A conventional std::vector<> stores the rest of the stack. The fast_back_stack
|
||||
* although contains a stl container it only implments the back push_back(),pop_back()
|
||||
* and back() methods so is not as general purpose as stl stack implementation.
|
||||
* The focus of the fast_back_stack is purly to maximize the speed at which the
|
||||
* back can be accessed.*/
|
||||
|
||||
template<class T>
|
||||
class fast_back_stack
|
||||
{
|
||||
public:
|
||||
|
||||
inline fast_back_stack():_value(),_stack(),_size(0) {}
|
||||
|
||||
inline fast_back_stack(const T& value):_value(value),_stack(),_size(1) {}
|
||||
|
||||
inline void clear() { _stack.clear(); _size = 0; }
|
||||
|
||||
inline bool empty() const { return _size==0; }
|
||||
|
||||
inline unsigned int size() const { return _size; }
|
||||
|
||||
inline T& back() { return _value; }
|
||||
|
||||
inline const T& back() const { return _value; }
|
||||
|
||||
inline void push_back(const T& value)
|
||||
{
|
||||
if (_size>0)
|
||||
{
|
||||
_stack.push_back(_value);
|
||||
}
|
||||
_value = value;
|
||||
++_size;
|
||||
}
|
||||
|
||||
inline void pop_back()
|
||||
{
|
||||
if (_size>0)
|
||||
{
|
||||
if (!_stack.empty())
|
||||
{
|
||||
_value = _stack.back();
|
||||
_stack.pop_back();
|
||||
}
|
||||
--_size;
|
||||
} // else error condition.
|
||||
}
|
||||
|
||||
T _value;
|
||||
std::vector<T> _stack;
|
||||
unsigned int _size;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -16,6 +16,8 @@
|
||||
#include <osg/EarthSky>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osg/fast_back_stack>
|
||||
|
||||
#include <osgUtil/RenderGraph>
|
||||
#include <osgUtil/RenderStage>
|
||||
|
||||
@ -329,43 +331,48 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor
|
||||
void popClippingVolume();
|
||||
|
||||
|
||||
typedef std::vector<osg::ClippingVolume> ClippingVolumeStack;
|
||||
typedef std::vector<osg::ref_ptr<osg::Matrix> > MatrixStack;
|
||||
// typedef std::vector<osg::ClippingVolume> ClippingVolumeStack;
|
||||
// typedef std::vector<osg::ref_ptr<osg::Matrix> > MatrixStack;
|
||||
|
||||
MatrixStack _projectionStack;
|
||||
MatrixStack _PW_Stack;
|
||||
ClippingVolumeStack _projectionClippingVolumeStack;
|
||||
typedef osg::fast_back_stack<osg::ClippingVolume> ClippingVolumeStack;
|
||||
typedef osg::fast_back_stack< osg::ref_ptr<osg::Matrix> > MatrixStack;
|
||||
|
||||
MatrixStack _modelviewStack;
|
||||
MatrixStack _MVPW_Stack;
|
||||
ClippingVolumeStack _modelviewClippingVolumeStack;
|
||||
MatrixStack _projectionStack;
|
||||
MatrixStack _PW_Stack;
|
||||
ClippingVolumeStack _projectionClippingVolumeStack;
|
||||
|
||||
MatrixStack _modelviewStack;
|
||||
MatrixStack _MVPW_Stack;
|
||||
ClippingVolumeStack _modelviewClippingVolumeStack;
|
||||
|
||||
bool _windowToModelFactorDirty;
|
||||
float _windowToModelFactor;
|
||||
bool _windowToModelFactorDirty;
|
||||
float _windowToModelFactor;
|
||||
|
||||
typedef std::vector<osg::ref_ptr<osg::Viewport> > ViewportStack;
|
||||
ViewportStack _viewportStack;
|
||||
// typedef std::vector<osg::ref_ptr<osg::Viewport> > ViewportStack;
|
||||
typedef osg::fast_back_stack<osg::ref_ptr<osg::Viewport> > ViewportStack;
|
||||
ViewportStack _viewportStack;
|
||||
|
||||
typedef std::vector<osg::Vec3> EyePointStack;
|
||||
EyePointStack _eyePointStack;
|
||||
// typedef std::vector<osg::Vec3> EyePointStack;
|
||||
typedef osg::fast_back_stack<osg::Vec3> EyePointStack;
|
||||
EyePointStack _eyePointStack;
|
||||
|
||||
typedef std::vector<CullingMode> CullingModeStack;
|
||||
CullingModeStack _cullingModeStack;
|
||||
typedef osg::fast_back_stack<CullingMode> CullingModeStack;
|
||||
CullingModeStack _cullingModeStack;
|
||||
|
||||
unsigned int _bbCornerNear;
|
||||
unsigned int _bbCornerFar;
|
||||
unsigned int _bbCornerNear;
|
||||
unsigned int _bbCornerFar;
|
||||
|
||||
osg::Matrix _identity;
|
||||
osg::Matrix _identity;
|
||||
|
||||
osg::ref_ptr<RenderGraph> _rootRenderGraph;
|
||||
RenderGraph* _currentRenderGraph;
|
||||
osg::ref_ptr<RenderGraph> _rootRenderGraph;
|
||||
RenderGraph* _currentRenderGraph;
|
||||
|
||||
osg::ref_ptr<RenderStage> _rootRenderStage;
|
||||
RenderBin* _currentRenderBin;
|
||||
osg::ref_ptr<RenderStage> _rootRenderStage;
|
||||
RenderBin* _currentRenderBin;
|
||||
|
||||
|
||||
float _LODBias;
|
||||
float _smallFeatureCullingPixelSize;
|
||||
float _LODBias;
|
||||
float _smallFeatureCullingPixelSize;
|
||||
|
||||
|
||||
ComputeNearFarMode _computeNearFar;
|
||||
|
@ -42,7 +42,7 @@ class OSGUTIL_EXPORT DepthSortedBin : public RenderBin
|
||||
virtual ~DepthSortedBin();
|
||||
|
||||
DrawOrder _drawOrder;
|
||||
RenderLeafList _renderLeafList;
|
||||
//RenderLeafList _renderLeafList;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -64,9 +64,7 @@ class OSGUTIL_EXPORT Hit
|
||||
};
|
||||
|
||||
|
||||
/** Basic visitor for ray based collisions of a scene.
|
||||
Note, still in development, current version has not
|
||||
practical functionality!*/
|
||||
/** Basic visitor for ray based collisions of a scene.*/
|
||||
class OSGUTIL_EXPORT IntersectVisitor : public osg::NodeVisitor
|
||||
{
|
||||
public:
|
||||
|
@ -72,6 +72,7 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object
|
||||
RenderStage* _stage;
|
||||
RenderBinList _bins;
|
||||
RenderGraphList _renderGraphList;
|
||||
RenderLeafList _renderLeafList;
|
||||
|
||||
typedef std::map< std::string, osg::ref_ptr<RenderBin> > RenderBinPrototypeList;
|
||||
static RenderBinPrototypeList s_renderBinPrototypeList;
|
||||
|
@ -15,9 +15,17 @@
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace osgUtil {
|
||||
|
||||
struct LeafDepthSortFunctor
|
||||
{
|
||||
const bool operator() (const osg::ref_ptr<RenderLeaf>& lhs,const osg::ref_ptr<RenderLeaf>& rhs)
|
||||
{
|
||||
return (lhs->_depth>rhs->_depth);
|
||||
}
|
||||
};
|
||||
|
||||
class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
|
||||
{
|
||||
@ -34,13 +42,16 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
|
||||
ChildList _children;
|
||||
LeafList _leaves;
|
||||
|
||||
mutable float _averageDistance;
|
||||
|
||||
osg::ref_ptr<osg::Referenced> _userData;
|
||||
|
||||
|
||||
RenderGraph():
|
||||
_parent(NULL),
|
||||
_stateset(NULL),
|
||||
_depth(0)
|
||||
_depth(0),
|
||||
_averageDistance(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -72,6 +83,29 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
|
||||
return _leaves.empty();
|
||||
}
|
||||
|
||||
|
||||
inline const float getAverageDistance() const
|
||||
{
|
||||
if (_averageDistance==FLT_MAX && !_leaves.empty())
|
||||
{
|
||||
_averageDistance = 0.0f;
|
||||
for(LeafList::const_iterator itr=_leaves.begin();
|
||||
itr!=_leaves.end();
|
||||
++itr)
|
||||
{
|
||||
_averageDistance += (*itr)->_depth;
|
||||
}
|
||||
_averageDistance /= (float)_leaves.size();
|
||||
|
||||
}
|
||||
return _averageDistance;
|
||||
}
|
||||
|
||||
inline void sortFrontToBack()
|
||||
{
|
||||
std::sort(_leaves.begin(),_leaves.end(),LeafDepthSortFunctor());
|
||||
}
|
||||
|
||||
/** reset the internal contents of a RenderGraph, including deleting all children.*/
|
||||
void reset();
|
||||
|
||||
@ -101,6 +135,7 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced
|
||||
{
|
||||
if (leaf)
|
||||
{
|
||||
_averageDistance = FLT_MAX; // signify dirty.
|
||||
_leaves.push_back(leaf);
|
||||
leaf->_parent = this;
|
||||
}
|
||||
|
@ -135,8 +135,8 @@ void CullVisitor::reset()
|
||||
_eyePointStack.clear();
|
||||
|
||||
// remove all accept the first element of the stack.
|
||||
_cullingModeStack.erase(_cullingModeStack.begin()+1,_cullingModeStack.end());
|
||||
|
||||
//_cullingModeStack.erase(_cullingModeStack.begin()+1,_cullingModeStack.end());
|
||||
_cullingModeStack.clear();
|
||||
|
||||
// reset the calculated near far planes.
|
||||
_computeNearFar = COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES;
|
||||
|
Loading…
Reference in New Issue
Block a user