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 {
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Leaf Node for grouping Drawables.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
class SG_EXPORT Geode : public Node
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
META_Node(Geode);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Add Drawable to Geode.
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset is not NULL and is not contained in Geode then increment its
|
2001-09-20 05:08:56 +08:00
|
|
|
* reference count, add it to the drawables list and dirty the bounding
|
2001-01-11 00:32:10 +08:00
|
|
|
* sphere to force it to recompute on next getBound() and return true for success.
|
|
|
|
* Otherwise return false.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool addDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Remove Drawable from Geode.
|
2001-01-11 00:32:10 +08:00
|
|
|
* If gset is contained in Geode then remove it from the geoset
|
|
|
|
* list and decrement its reference count, and dirty the
|
|
|
|
* bounding sphere to force it to recompute on next getBound() and
|
|
|
|
* return true for success. If gset is not found then return false
|
|
|
|
* and do not change the reference count of gset.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool removeDrawable( Drawable *drawable );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** Replace specified Drawable with another Drawable.
|
2001-01-11 00:32:10 +08:00
|
|
|
* 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.
|
2001-09-20 05:08:56 +08:00
|
|
|
* If origDrawable is not found then return false and do not
|
2001-01-11 00:32:10 +08:00
|
|
|
* add newGset. If newGset is NULL then return false and do
|
|
|
|
* not remove origGset.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** return the number of geoset's.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumDrawables() const { return _drawables.size(); }
|
|
|
|
|
|
|
|
/** return geoset at position i.*/
|
|
|
|
inline Drawable* getDrawable( const int i ) { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** return geoset at position i.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const Drawable* getDrawable( const int i ) const { return _drawables[i].get(); }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-22 10:42:08 +08:00
|
|
|
/** return true if geoset is contained within Geode.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const 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;
|
|
|
|
}
|
|
|
|
|
2001-09-29 04:10:41 +08:00
|
|
|
/** return the iterator position for specified Drawable.
|
2001-01-11 00:32:10 +08:00
|
|
|
* return _geoset.end() if gset not is contained in Geode.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline DrawableList::iterator findDrawable(const Drawable* gset)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
for (DrawableList::iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->get()==gset) return itr;
|
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
return _drawables.end();
|
|
|
|
}
|
|
|
|
|
2001-09-29 04:10:41 +08:00
|
|
|
/** return the const_iterator position for specified Drawable.
|
2001-09-20 05:08:56 +08:00
|
|
|
* return _geoset.end() if gset not is contained in Geode.
|
|
|
|
*/
|
|
|
|
inline DrawableList::const_iterator findDrawable(const Drawable* gset) const
|
|
|
|
{
|
|
|
|
|
|
|
|
for (DrawableList::const_iterator itr=_drawables.begin();
|
|
|
|
itr!=_drawables.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
if (itr->get()==gset) return itr;
|
|
|
|
}
|
|
|
|
return _drawables.end();
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
|
2001-09-29 04:10:41 +08:00
|
|
|
/** compile OpenGL Display List for each geoset.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void compileDrawables(State& state);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~Geode();
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool computeBound() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
DrawableList _drawables;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|