diff --git a/include/osg/ClippingVolume b/include/osg/ClippingVolume index 7fede0ec0..b2ae10d3e 100644 --- a/include/osg/ClippingVolume +++ b/include/osg/ClippingVolume @@ -22,6 +22,11 @@ class SG_EXPORT ClippingVolume inline ClippingVolume() {setupMask();} + inline ClippingVolume(const ClippingVolume& cs, const unsigned int mask) + { + set(cs,mask); + } + inline ClippingVolume(const ClippingVolume& cv) : _localMask(cv._localMask), _planeList(cv._planeList) {} inline ClippingVolume(const PlaneList& pl) : _planeList(pl) {setupMask();} @@ -61,6 +66,19 @@ class SG_EXPORT ClippingVolume setupMask(); } + inline void set(const ClippingVolume& cs, const unsigned int mask) + { + unsigned int selector_mask = 0x1; + for(PlaneList::const_iterator itr=cs._planeList.begin(); + itr!=cs._planeList.end(); + ++itr) + { + if (mask&selector_mask) _planeList.push_back(*itr); + selector_mask <<= 1; + } + setupMask(); + } + inline void set(const ClippingVolume& cs) { _planeList = cs._planeList; setupMask(); } inline void set(const PlaneList& pl) { _planeList = pl; setupMask(); } @@ -93,6 +111,20 @@ class SG_EXPORT ClippingVolume return true; } + inline const bool contains(const osg::Vec3& v,const unsigned int mask) const + { + if (!(mask & _localMask)) return true; + unsigned int selector_mask = 0x1; + for(PlaneList::const_iterator itr=_planeList.begin(); + itr!=_planeList.end(); + ++itr) + { + if (mask&selector_mask && (itr->distance(v)<0.0f)) return false; + selector_mask <<= 1; + } + return true; + } + /** Check whether any part of a bounding sphere is contained within clipping set. Using a mask to determine which planes should be used for the check, and modifying the mask to turn off planes which wouldn't contribute to clipping diff --git a/include/osg/Vec4 b/include/osg/Vec4 index 0edb6fc15..4a561f917 100644 --- a/include/osg/Vec4 +++ b/include/osg/Vec4 @@ -5,7 +5,7 @@ #ifndef OSG_VEC4 #define OSG_VEC4 1 -#include +#include #include @@ -24,11 +24,24 @@ class Vec4 // Methods are defined here so that they are implicitly inlined Vec4() { _v[0]=0.0f; _v[1]=0.0f; _v[2]=0.0f; _v[3]=0.0f;} + Vec4(float x, float y, float z, float w) { - _v[0]=x; _v[1]=y; _v[2]=z; _v[3]=w; + _v[0]=x; + _v[1]=y; + _v[2]=z; + _v[3]=w; } + Vec4(const Vec3& v3,float w) + { + _v[0]=v3[0]; + _v[1]=v3[1]; + _v[2]=v3[2]; + _v[3]=w; + } + + float _v[4]; inline const bool operator == (const Vec4& v) const { return _v[0]==v._v[0] && _v[1]==v._v[1] && _v[2]==v._v[2] && _v[3]==v._v[3]; } @@ -67,15 +80,21 @@ class Vec4 inline float z() const { return _v[2]; } inline float w() const { return _v[3]; } - inline unsigned long asABGR() const { return clampTo((unsigned long)(_v[0]*255),0ul,255ul)<<24 | - clampTo((unsigned long)(_v[1]*255),0ul,255ul)<<16 | - clampTo((unsigned long)(_v[2]*255),0ul,255ul)<<8 | - clampTo((unsigned long)(_v[3]*255),0ul,255ul); } + inline unsigned long asABGR() const + { + return (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f)<<24 | + (unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<16 | + (unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<8 | + (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f); + } - inline unsigned long asRGBA() const { return clampTo((unsigned long)(_v[3]*255),0ul,255ul)<<24 | - clampTo((unsigned long)(_v[2]*255),0ul,255ul)<<16 | - clampTo((unsigned long)(_v[1]*255),0ul,255ul)<<8 | - clampTo((unsigned long)(_v[0]*255),0ul,255ul); } + inline const unsigned long asRGBA() const + { + return (unsigned long)clampTo((_v[3]*255.0f),0.0f,255.0f)<<24 | + (unsigned long)clampTo((_v[2]*255.0f),0.0f,255.0f)<<16 | + (unsigned long)clampTo((_v[1]*255.0f),0.0f,255.0f)<<8 | + (unsigned long)clampTo((_v[0]*255.0f),0.0f,255.0f); + } inline const bool valid() const { return !isNaN(); } diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index 15451a945..d4d1a0631 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -238,6 +238,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor } + osg::ClippingVolume& getCurrentClippingVolume() { return _modelviewClippingVolumeStack.back(); } + inline bool isCulled(const osg::BoundingSphere& sp,CullingMode& mode) { if (!sp.isValid()) return true; @@ -258,7 +260,10 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor return !_modelviewClippingVolumeStack.back().contains(bb,mode); } - void updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable); + const CullingMode getCurrentCullingMode() const { return _cullingModeStack.back(); } + + void updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable) { updateCalculatedNearFar(matrix,drawable.getBound()); } + void updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb); void updateCalculatedNearFar(const osg::Vec3& pos); /** Add a drawable to current render graph.*/ diff --git a/include/osgUtil/RenderGraph b/include/osgUtil/RenderGraph index 6fd3a88e1..1a272e559 100644 --- a/include/osgUtil/RenderGraph +++ b/include/osgUtil/RenderGraph @@ -33,6 +33,8 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced int _depth; ChildList _children; LeafList _leaves; + + osg::ref_ptr _userData; RenderGraph(): @@ -54,6 +56,10 @@ class OSGUTIL_EXPORT RenderGraph : public osg::Referenced RenderGraph* cloneType() const { return new RenderGraph; } + void setUserData(osg::Referenced* obj) { _userData = obj; } + osg::Referenced* getUserData() { return _userData.get(); } + const osg::Referenced* getUserData() const { return _userData.get(); } + /** return true if all of drawables, lights and children are empty.*/ inline const bool empty() const diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 70c6722c3..888024c9a 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -304,9 +304,8 @@ inline float distance(const osg::Vec3& coord,const osg::Matrix& matrix) } -void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::Drawable& drawable) +void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::BoundingBox& bb) { - const osg::BoundingBox& bb = drawable.getBound(); float d_near = distance(bb.corner(_bbCornerNear),matrix); float d_far = distance(bb.corner(_bbCornerFar),matrix); @@ -329,7 +328,6 @@ void CullVisitor::updateCalculatedNearFar(const osg::Matrix& matrix,const osg::D } } - void CullVisitor::updateCalculatedNearFar(const osg::Vec3& pos) { float d;