2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2005-01-27 21:15:21 +08:00
|
|
|
* 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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2005-01-27 21:15:21 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-01-27 21:15:21 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_GEODE
|
|
|
|
#define OSG_GEODE 1
|
|
|
|
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/NodeVisitor>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/Drawable>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** A \c Geode is a "geometry node", that is, a leaf node on the scene graph
|
|
|
|
* that can have "renderable things" attached to it. In OSG, renderable things
|
|
|
|
* are represented by objects from the \c Drawable class, so a \c Geode is a
|
|
|
|
* \c Node whose purpose is grouping <tt>Drawable</tt>s.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT Geode : public Node
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
typedef std::vector< ref_ptr<Drawable> > DrawableList;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
Geode();
|
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Geode(const Geode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Node(osg, Geode);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-05-15 13:47:14 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Add a \c Drawable to the \c Geode.
|
|
|
|
* If \c drawable is not \c NULL and is not contained in the \c Geode
|
|
|
|
* then increment its reference count, add it to the drawables list and
|
|
|
|
* dirty the bounding sphere to force it to be recomputed on the next
|
|
|
|
* call to \c getBound().
|
|
|
|
* @param drawable The \c Drawable to be added to the \c Geode.
|
|
|
|
* @return \c true for success; \c false otherwise.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool addDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Remove a \c Drawable from the \c Geode.
|
|
|
|
* Equivalent to <tt>removeDrawable(getDrawableIndex(drawable)</tt>.
|
|
|
|
* @param drawable The drawable to be removed.
|
|
|
|
* @return \c true if at least one \c Drawable was removed. \c false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
virtual bool removeDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Remove <tt>Drawable</tt>(s) from the specified position in
|
|
|
|
* <tt>Geode</tt>'s drawable list.
|
|
|
|
* @param i The index of the first \c Drawable to remove.
|
|
|
|
* @param numDrawablesToRemove The number of <tt>Drawable</tt> to
|
|
|
|
* remove.
|
|
|
|
* @return \c true if at least one \c Drawable was removed. \c false
|
|
|
|
* otherwise.
|
|
|
|
*/
|
2006-05-02 17:45:31 +08:00
|
|
|
virtual bool removeDrawables(unsigned int i,unsigned int numDrawablesToRemove=1);
|
2002-12-08 05:18:12 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Replace specified Drawable with another Drawable.
|
2005-01-27 21:15:21 +08:00
|
|
|
* Equivalent to <tt>setDrawable(getDrawableIndex(origDraw),newDraw)</tt>,
|
|
|
|
* see docs for \c setDrawable() for further details on implementation.
|
|
|
|
*/
|
2002-11-19 00:14:00 +08:00
|
|
|
virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Set \c Drawable at position \c i.
|
|
|
|
* Decrement the reference count origGSet and increments the
|
|
|
|
* reference count of newGset, and dirty the bounding sphere
|
|
|
|
* to force it to recompute on next getBound() and returns true.
|
|
|
|
* If origDrawable is not found then return false and do not
|
|
|
|
* add newGset. If newGset is NULL then return false and do
|
|
|
|
* not remove origGset.
|
|
|
|
* @return \c true if set correctly, \c false on failure
|
|
|
|
* (if node==NULL || i is out of range).
|
|
|
|
*/
|
2002-11-19 00:14:00 +08:00
|
|
|
virtual bool setDrawable( unsigned int i, Drawable* drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the number of <tt>Drawable</tt>s currently attached to the
|
|
|
|
* \c Geode.
|
|
|
|
*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline unsigned int getNumDrawables() const { return _drawables.size(); }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the \c Drawable at position \c i.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline Drawable* getDrawable( unsigned int i ) { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return the \c Drawable at position \c i.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline const Drawable* getDrawable( unsigned int i ) const { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Return \c true if a given \c Drawable is contained within \c Geode.*/
|
2002-09-02 20:31:35 +08:00
|
|
|
inline bool containsDrawable(const Drawable* gset) const
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
for (DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->get()==gset) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Get the index number of \c drawable.
|
|
|
|
* @return A value between 0 and <tt>getNumDrawables()-1</tt> if
|
|
|
|
* \c drawable is found; if not found, then
|
|
|
|
* <tt>getNumDrawables()</tt> is returned.
|
|
|
|
*/
|
|
|
|
inline unsigned int getDrawableIndex( const Drawable* drawable ) const
|
2002-11-19 00:14:00 +08:00
|
|
|
{
|
|
|
|
for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum)
|
|
|
|
{
|
2005-01-27 21:15:21 +08:00
|
|
|
if (_drawables[drawableNum]==drawable) return drawableNum;
|
2002-11-19 00:14:00 +08:00
|
|
|
}
|
2005-01-27 21:15:21 +08:00
|
|
|
return _drawables.size(); // drawable not found.
|
2002-11-19 00:14:00 +08:00
|
|
|
}
|
|
|
|
|
2005-05-15 13:47:14 +08:00
|
|
|
/** Get the list of drawables.*/
|
|
|
|
const DrawableList& getDrawableList() const { return _drawables; }
|
|
|
|
|
2005-01-27 21:15:21 +08:00
|
|
|
/** Compile OpenGL Display List for each drawable.*/
|
2006-11-14 20:51:31 +08:00
|
|
|
void compileDrawables(RenderInfo& renderInfo);
|
2005-01-27 21:15:21 +08:00
|
|
|
|
|
|
|
/** Return the Geode's bounding box, which is the union of all the
|
2004-04-22 18:47:12 +08:00
|
|
|
* bounding boxes of the geode's drawables.*/
|
|
|
|
inline const BoundingBox& getBoundingBox() const
|
|
|
|
{
|
2005-05-12 22:03:22 +08:00
|
|
|
if(!_boundingSphereComputed) getBound();
|
2004-04-22 18:47:12 +08:00
|
|
|
return _bbox;
|
|
|
|
}
|
2005-01-27 21:15:21 +08:00
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
virtual BoundingSphere computeBound() const;
|
|
|
|
|
2007-01-05 00:49:58 +08:00
|
|
|
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
|
|
|
|
virtual void setThreadSafeRefUnref(bool threadSafe);
|
|
|
|
|
2007-01-04 22:11:51 +08:00
|
|
|
/** Resize any per context GLObject buffers to specified size. */
|
|
|
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
|
|
|
|
2005-05-08 04:47:09 +08:00
|
|
|
/** If State is non-zero, this function releases any associated OpenGL objects for
|
2007-12-11 01:30:18 +08:00
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objects
|
2005-05-08 04:47:09 +08:00
|
|
|
* for all graphics contexts. */
|
|
|
|
virtual void releaseGLObjects(osg::State* = 0) const;
|
|
|
|
|
2005-05-12 22:03:22 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Geode();
|
|
|
|
|
|
|
|
|
2004-04-22 18:47:12 +08:00
|
|
|
mutable osg::BoundingBox _bbox;
|
2002-05-29 07:43:22 +08:00
|
|
|
DrawableList _drawables;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|