This commit is contained in:
Robert Osfield
2014-05-14 10:19:43 +00:00
parent 12a737ae02
commit 4174d72a52
37 changed files with 244 additions and 397 deletions

View File

@@ -271,6 +271,12 @@ class OSG_EXPORT CullingSet : public Referenced
return false;
}
inline bool isCulled(const Bound& bound)
{
if (bound.bb) return isCulled(*bound.bb);
else return isCulled(*bound.bs);
}
inline void pushCurrentMask()
{
_frustum.pushCurrentMask();

View File

@@ -59,7 +59,7 @@ class OSG_EXPORT DrawPixels : public Drawable
virtual void drawImplementation(RenderInfo& renderInfo) const;
virtual BoundingBox computeBound() const;
virtual BoundingBox computeBoundingBox() const;
protected:

View File

@@ -19,6 +19,7 @@
#include <osg/BufferObject>
#include <osg/PrimitiveSet>
#include <osg/RenderInfo>
#include <osg/Node>
#ifndef GL_NV_occlusion_query
@@ -90,7 +91,7 @@ class ArrayDispatchers;
* <tt>Geode</tt>s, so that the same geometry (loaded to memory just once) can
* be used in different parts of the scene graph.
*/
class OSG_EXPORT Drawable : public Object
class OSG_EXPORT Drawable : public Node
{
public:
@@ -103,9 +104,7 @@ class OSG_EXPORT Drawable : public Object
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Drawable(const Drawable& drawable,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Drawable*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "Drawable"; }
META_Node(osg, Drawable);
/** Convert 'this' into a Geometry pointer if Drawable is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<Geometry*>(this).*/
@@ -115,94 +114,44 @@ class OSG_EXPORT Drawable : public Object
* Equivalent to dynamic_cast<const Geometry*>(this).*/
virtual const Geometry* asGeometry() const { return 0; }
/** Visitor Pattern : calls the apply method of a NodeVisitor with this drawable's type.*/
virtual void accept(NodeVisitor& nv);
/** Compute the DataVariance based on an assessment of callback etc.*/
virtual void computeDataVariance();
/** A vector of osg::Node pointers which is used to store the parent(s) of drawable.*/
typedef std::vector<Node*> ParentList;
/** Get the parent list of drawable. */
inline const ParentList& getParents() const { return _parents; }
/** Get the a copy of parent list of node. A copy is returned to
* prevent modification of the parent list.*/
inline ParentList getParents() { return _parents; }
/** Get a single parent of Drawable.
* @param i index of the parent to get.
* @return the parent i.
*/
inline Node* getParent(unsigned int i) { return _parents[i]; }
/** Get a single const parent of Drawable.
* @param i index of the parent to get.
* @return the parent i.
*/
inline const Node* getParent(unsigned int i) const { return _parents[i]; }
/**
* Get the number of parents of node.
* @return the number of parents of this node.
*/
inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
/** Get the list of matrices that transform this node from local coordinates to world coordinates.
* The optional Node* haltTraversalAtNode allows the user to prevent traversal beyond a specifed node. */
MatrixList getWorldMatrices(const osg::Node* haltTraversalAtNode=0) const;
/** Set the StateSet attached to the Drawable.
Previously attached StateSet are automatically unreferenced on
assignment of a new drawstate.*/
void setStateSet(StateSet* stateset);
/** Get the attached StateSet.*/
inline StateSet* getStateSet() { return _stateset.get();}
/** Get the attached const StateSet.*/
inline const StateSet* getStateSet() const { return _stateset.get();}
/** Get the attached const StateSet,
* if one is not already attached create one,
* attach it to the drawable and return a pointer to it.*/
StateSet* getOrCreateStateSet();
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
void setInitialBound(const osg::BoundingBox& bbox) { _initialBound = bbox; dirtyBound(); }
/** Set the initial bounding volume to use when computing the overall bounding volume.*/
const BoundingBox& getInitialBound() const { return _initialBound; }
/** Dirty the bounding box, forcing a computeBound() on the next call
* to getBound(). Should be called in the internal geometry of the Drawable
* is modified.*/
void dirtyBound();
/** Get BoundingBox of Drawable.
* If the BoundingBox is not up to date then its updated via an internal call to computeBond().
*/
inline const BoundingBox& getBound() const
inline const BoundingBox& getBoundingBox() const
{
if(!_boundingBoxComputed)
if(!_boundingSphereComputed)
{
_boundingBox = _initialBound;
if (_computeBoundCallback.valid())
_boundingBox.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingBox.expandBy(computeBound());
_boundingBox.expandBy(computeBoundingBox());
_boundingBoxComputed = true;
_boundingSphereComputed = true;
}
return _boundingBox;
}
/** Compute the bounding sphere around Drawables's geometry.*/
virtual BoundingSphere computeBound() const;
/** Compute the bounding box around Drawables's geometry.*/
virtual BoundingBox computeBound() const;
virtual BoundingBox computeBoundingBox() const;
/** Callback to allow users to override the default computation of bounding volume. */
struct ComputeBoundingBoxCallback : public osg::Object
@@ -418,7 +367,7 @@ class OSG_EXPORT Drawable : public Object
* drawImplementation(RenderInfo&) is called from the draw(RenderInfo&) method, with the draw method handling management of OpenGL display lists,
* and drawImplementation(RenderInfo&) handling the actual drawing itself.
* @param renderInfo The osg::RenderInfo object that encapsulates the current rendering information including the osg::State OpenGL state for the current graphics context. */
virtual void drawImplementation(RenderInfo& renderInfo) const = 0;
virtual void drawImplementation(RenderInfo& /*renderInfo*/) const {}
/** Return a OpenGL display list handle a newly generated or reused from display list cache. */
@@ -810,20 +759,13 @@ class OSG_EXPORT Drawable : public Object
virtual ~Drawable();
/** set the bounding box .*/
void setBound(const BoundingBox& bb) const;
void addParent(osg::Node* node);
void removeParent(osg::Node* node);
ParentList _parents;
friend class Node;
friend class Geode;
friend class StateSet;
ref_ptr<StateSet> _stateset;
BoundingBox _initialBound;
ref_ptr<ComputeBoundingBoxCallback> _computeBoundCallback;
mutable BoundingBox _boundingBox;
@@ -840,14 +782,7 @@ class OSG_EXPORT Drawable : public Object
mutable GLObjectList _globjList;
ref_ptr<UpdateCallback> _updateCallback;
unsigned int _numChildrenRequiringUpdateTraversal;
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
unsigned int getNumChildrenRequiringUpdateTraversal() const { return _numChildrenRequiringUpdateTraversal; }
ref_ptr<EventCallback> _eventCallback;
unsigned int _numChildrenRequiringEventTraversal;
void setNumChildrenRequiringEventTraversal(unsigned int num);
unsigned int getNumChildrenRequiringEventTraversal() const { return _numChildrenRequiringEventTraversal; }
ref_ptr<CullCallback> _cullCallback;
ref_ptr<DrawCallback> _drawCallback;

View File

@@ -18,6 +18,7 @@
#include <osg/Object>
#include <osg/StateSet>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/NodeCallback>
#include <string>
@@ -49,6 +50,46 @@ typedef std::vector< NodePath > NodePathList;
/** A vector of NodePath, typically used to describe all the paths from a node to the potential root nodes it has.*/
typedef std::vector< Matrix > MatrixList;
#ifdef OSG_USE_BOUND
struct Bound
{
Bound():
bb(0),
bs(0) {}
Bound(const osg::BoundingSphere& bs):
bb(0),
bs(&bs) {}
Bound(const osg::BoundingBox& bb):
bb(&bb),
bs(0) {}
Bound(const osg::BoundingSphere& bs, const osg::BoundingBox& bb):
bb(&bb),
bs(&bs) {}
const osg::BoundingBox* bb;
const osg::BoundingSphere* bs;
bool valid() const { return bs ? bs->valid() : false; }
const osg::Vec3& center() const { return bs->center(); }
float radius() const { return bs->radius(); }
float xMin() const { return bb->xMin(); }
float yMin() const { return bb->yMin(); }
float zMin() const { return bb->zMin(); }
float xMax() const { return bb->xMax(); }
float yMax() const { return bb->yMax(); }
float zMax() const { return bb->zMax(); }
operator const osg::BoundingBox& () const { return *bb; }
operator const osg::BoundingSphere& () const { return *bs; }
};
#endif
/** META_Node macro define the standard clone, isSameKindAs, className
* and accept methods. Use when subclassing from Node to make it
* more convenient to define the required pure virtual methods.*/
@@ -395,7 +436,23 @@ class OSG_EXPORT Node : public Object
/** Get the bounding sphere of node.
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
inline const BoundingSphere& getBound() const
#ifdef OSG_USE_BOUND
inline Bound getBound() const
{
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
if (_computeBoundCallback.valid())
_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());
_boundingSphereComputed = true;
}
return Bound(_boundingSphere);
}
#else
inline BoundingSphere getBound() const
{
if(!_boundingSphereComputed)
{
@@ -409,7 +466,7 @@ class OSG_EXPORT Node : public Object
}
return _boundingSphere;
}
#endif
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding

View File

@@ -21,6 +21,7 @@
#include <osg/Matrix>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/Node>
#include <vector>
@@ -321,6 +322,13 @@ class OSG_EXPORT Plane
}
#ifdef OSG_USE_BOUND
inline int intersect(const Bound& bound) const
{
if (bound.bb) return intersect(*bound.bb);
else return intersect(*bound.bs);
}
#endif
/** Transform the plane by matrix. Note, this operation carries out
* the calculation of the inverse of the matrix since a plane
* must be multiplied by the inverse transposed to transform it. This

View File

@@ -289,6 +289,14 @@ class OSG_EXPORT Polytope
return true;
}
#ifdef OSG_USE_BOUND
inline bool contains(const osg::Bound& bound)
{
if (bound.bb) return contains(*bound.bb);
else return contains(*bound.bs);
}
#endif
/** Check whether all of vertex list is contained with clipping set.*/
inline bool containsAllOf(const std::vector<Vec3>& vertices)
{

View File

@@ -181,7 +181,7 @@ class OSG_EXPORT ShapeDrawable : public Drawable
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf) const;
virtual BoundingBox computeBound() const;
virtual BoundingBox computeBoundingBox() const;
protected:

View File

@@ -243,7 +243,7 @@ namespace osgParticle
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
#ifdef OSGPARTICLE_USE_ReadWriteMutex
typedef OpenThreads::ReadWriteMutex ReadWriterMutex;

View File

@@ -69,7 +69,7 @@ class OSGSHADOW_EXPORT OccluderGeometry : public osg::Drawable
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
/** Compute the bounding box around occluder geometry.*/
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
typedef std::vector<osg::Vec3> Vec3List;
typedef std::vector<GLuint> UIntList;
@@ -240,7 +240,7 @@ class OSGSHADOW_EXPORT ShadowVolumeGeometry : public osg::Drawable
virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
/** Compute the bounding box around occluder geometry.*/
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
public:

View File

@@ -149,7 +149,7 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
// for debugging purposes.
osg::Vec4 _color;
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
/** Set the camera node to use for pre rendering the impostor sprite's texture.*/
void setCamera(osg::Camera* camera) { _camera = camera; }

View File

@@ -113,7 +113,7 @@ class OSGTEXT_EXPORT Text3D : public osgText::TextBase
// // forcefully unloaded.
friend class Font;
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
protected:

View File

@@ -264,7 +264,7 @@ public:
virtual void releaseGLObjects(osg::State* state=0) const;
virtual osg::BoundingBox computeBound() const;
virtual osg::BoundingBox computeBoundingBox() const;
protected: