Added support for parents to Drawables.
Bumped up version numbers in prep for 0.8.44.
This commit is contained in:
parent
4c5fcd3f61
commit
2075eb0100
2
Makefile
2
Makefile
@ -4,7 +4,7 @@ MAKE_PREP = Make/makedefs Make/makerules
|
||||
|
||||
DIRS = src
|
||||
|
||||
VERSION = osg-0.8.43
|
||||
VERSION = osg-0.8.44
|
||||
|
||||
ifeq (IRIX|IRIX64,true)
|
||||
export OSGHOME = `pwd`
|
||||
|
@ -21,6 +21,7 @@ class Statistics;
|
||||
class Vec2;
|
||||
class Vec3;
|
||||
class Vec4;
|
||||
class Node;
|
||||
|
||||
// this is define to alter the way display lists are compiled inside the
|
||||
// the draw method, it has been found that the NVidia drivers fail completely
|
||||
@ -61,6 +62,36 @@ class SG_EXPORT Drawable : public Object
|
||||
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Drawable*>(obj)!=NULL; }
|
||||
virtual const char* className() const { return "Drawable"; }
|
||||
|
||||
|
||||
/** 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(const 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(const int i) const { return _parents[i]; }
|
||||
|
||||
/**
|
||||
* Get the number of parents of node.
|
||||
* @return the number of parents of this node.
|
||||
*/
|
||||
inline const int getNumParents() const { return _parents.size(); }
|
||||
|
||||
|
||||
|
||||
/** Set the StateSet attached to the Drawable.
|
||||
Previously attached StateSet are automatically unreferenced on
|
||||
assignment of a new drawstate.*/
|
||||
@ -101,7 +132,7 @@ class SG_EXPORT Drawable : public Object
|
||||
/** 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.*/
|
||||
inline void dirtyBound() { _bbox_computed = false; }
|
||||
void dirtyBound();
|
||||
|
||||
/** get bounding box of geoset.
|
||||
* Note, now made virtual to make it possible to implement user-drawn
|
||||
@ -227,6 +258,13 @@ class SG_EXPORT Drawable : public Object
|
||||
implemented by subclasses.*/
|
||||
virtual const bool computeBound() const = 0;
|
||||
|
||||
void addParent(osg::Node* node);
|
||||
void removeParent(osg::Node* node);
|
||||
|
||||
ParentList _parents;
|
||||
friend class Node;
|
||||
friend class Geode;
|
||||
|
||||
ref_ptr<StateSet> _dstate;
|
||||
|
||||
bool _supportsDisplayList;
|
||||
|
@ -210,6 +210,9 @@ class SG_EXPORT Node : public Object
|
||||
|
||||
std::string _name;
|
||||
|
||||
void addParent(osg::Group* node);
|
||||
void removeParent(osg::Group* node);
|
||||
|
||||
ParentList _parents;
|
||||
friend class osg::Group;
|
||||
|
||||
|
@ -9,9 +9,6 @@ DIRS += osgtext
|
||||
# comment out if you don't have support for networking.
|
||||
DIRS += osgcluster
|
||||
|
||||
# comment out if you don't have the wxWindows installed.
|
||||
# DIRS += wxsgv
|
||||
|
||||
all :
|
||||
for f in $(DIRS) ; do cd $$f; $(MAKE) || exit 1; cd ..; done
|
||||
|
||||
|
@ -6,9 +6,6 @@ DIRS = osg osgDB osgUtil osgGLUT
|
||||
# comment out if you don't have the freetype and GLU1.3 library installed.
|
||||
DIRS += osgText
|
||||
|
||||
# comment out if you don't have the wxWindows installed.
|
||||
# DIRS += osgWX
|
||||
|
||||
DIRS += Demos
|
||||
DIRS += osgPlugins
|
||||
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <osg/Drawable>
|
||||
#include <osg/State>
|
||||
#include <osg/Notify>
|
||||
#include <osg/Node>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
@ -26,6 +29,7 @@ Drawable::Drawable()
|
||||
|
||||
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
||||
Object(drawable,copyop),
|
||||
_parents(), // leave empty as parentList is managed by Geode
|
||||
_dstate(copyop(drawable._dstate.get())),
|
||||
_supportsDisplayList(drawable._supportsDisplayList),
|
||||
_useDisplayList(drawable._useDisplayList),
|
||||
@ -40,6 +44,33 @@ Drawable::~Drawable()
|
||||
dirtyDisplayList();
|
||||
}
|
||||
|
||||
void Drawable::addParent(osg::Node* node)
|
||||
{
|
||||
_parents.push_back(node);
|
||||
}
|
||||
|
||||
void Drawable::removeParent(osg::Node* node)
|
||||
{
|
||||
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
|
||||
if (pitr!=_parents.end()) _parents.erase(pitr);
|
||||
}
|
||||
|
||||
void Drawable::dirtyBound()
|
||||
{
|
||||
if (_bbox_computed)
|
||||
{
|
||||
_bbox_computed = false;
|
||||
|
||||
// dirty parent bounding sphere's to ensure that all are valid.
|
||||
for(ParentList::iterator itr=_parents.begin();
|
||||
itr!=_parents.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->dirtyBound();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Drawable::compile(State& state)
|
||||
{
|
||||
|
@ -24,47 +24,72 @@ Geode::Geode(const Geode& geode,const CopyOp& copyop):
|
||||
|
||||
Geode::~Geode()
|
||||
{
|
||||
// ref_ptr<> automactially decrements the reference count of all drawables.
|
||||
// remove reference to this from children's parent lists.
|
||||
for(DrawableList::iterator itr=_drawables.begin();
|
||||
itr!=_drawables.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->removeParent(this);
|
||||
}
|
||||
}
|
||||
|
||||
const bool Geode::addDrawable( Drawable *gset )
|
||||
const bool Geode::addDrawable( Drawable *drawable )
|
||||
{
|
||||
if (gset && !containsDrawable(gset))
|
||||
if (drawable && !containsDrawable(drawable))
|
||||
{
|
||||
// note ref_ptr<> automatically handles incrementing gset's reference count.
|
||||
_drawables.push_back(gset);
|
||||
// note ref_ptr<> automatically handles incrementing drawable's reference count.
|
||||
_drawables.push_back(drawable);
|
||||
|
||||
// register as parent of drawable.
|
||||
drawable->addParent(this);
|
||||
|
||||
dirtyBound();
|
||||
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
const bool Geode::removeDrawable( Drawable *gset )
|
||||
const bool Geode::removeDrawable( Drawable *drawable )
|
||||
{
|
||||
DrawableList::iterator itr = findDrawable(gset);
|
||||
DrawableList::iterator itr = findDrawable(drawable);
|
||||
if (itr!=_drawables.end())
|
||||
{
|
||||
// note ref_ptr<> automatically handles decrementing gset's reference count.
|
||||
// remove this Geode from the child parent list.
|
||||
drawable->removeParent(this);
|
||||
|
||||
// note ref_ptr<> automatically handles decrementing drawable's reference count.
|
||||
_drawables.erase(itr);
|
||||
|
||||
dirtyBound();
|
||||
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
|
||||
const bool Geode::replaceDrawable( Drawable *origGset, Drawable *newGset )
|
||||
const bool Geode::replaceDrawable( Drawable *origDrawable, Drawable *newDrawable )
|
||||
{
|
||||
if (newGset==NULL || origGset==newGset) return false;
|
||||
if (newDrawable==NULL || origDrawable==newDrawable) return false;
|
||||
|
||||
DrawableList::iterator itr = findDrawable(origGset);
|
||||
DrawableList::iterator itr = findDrawable(origDrawable);
|
||||
if (itr!=_drawables.end())
|
||||
{
|
||||
|
||||
// remove from origDrawable's parent list.
|
||||
origDrawable->removeParent(this);
|
||||
|
||||
// note ref_ptr<> automatically handles decrementing origGset's reference count,
|
||||
// and inccrementing newGset's reference count.
|
||||
*itr = newGset;
|
||||
*itr = newDrawable;
|
||||
|
||||
// register as parent of child.
|
||||
newDrawable->addParent(this);
|
||||
|
||||
dirtyBound();
|
||||
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
|
@ -27,14 +27,12 @@ Group::Group(const Group& group,const CopyOp& copyop):
|
||||
|
||||
Group::~Group()
|
||||
{
|
||||
|
||||
// remove reference to this from children's parent lists.
|
||||
for(ChildList::iterator itr=_children.begin();
|
||||
itr!=_children.end();
|
||||
++itr)
|
||||
{
|
||||
Node* child = itr->get();
|
||||
ParentList::iterator pitr = std::find(child->_parents.begin(),child->_parents.end(),this);
|
||||
if (pitr!=child->_parents.end()) child->_parents.erase(pitr);
|
||||
(*itr)->removeParent(this);
|
||||
}
|
||||
|
||||
}
|
||||
@ -59,7 +57,7 @@ bool Group::addChild( Node *child )
|
||||
_children.push_back(child);
|
||||
|
||||
// register as parent of child.
|
||||
child->_parents.push_back(this);
|
||||
child->addParent(this);
|
||||
|
||||
dirtyBound();
|
||||
|
||||
@ -95,8 +93,7 @@ bool Group::removeChild( Node *child )
|
||||
if (itr!=_children.end())
|
||||
{
|
||||
// remove this group from the child parent list.
|
||||
ParentList::iterator pitr = std::find(child->_parents.begin(),child->_parents.end(),this);
|
||||
if (pitr!=child->_parents.end()) child->_parents.erase(pitr);
|
||||
child->removeParent(this);
|
||||
|
||||
// could now require app traversal thanks to the new subgraph,
|
||||
// so need to check and update if required.
|
||||
@ -136,15 +133,15 @@ bool Group::replaceChild( Node *origNode, Node *newNode )
|
||||
ChildList::iterator itr = findNode(origNode);
|
||||
if (itr!=_children.end())
|
||||
{
|
||||
ParentList::iterator pitr = std::find(origNode->_parents.begin(),origNode->_parents.end(),this);
|
||||
if (pitr!=origNode->_parents.end()) origNode->_parents.erase(pitr);
|
||||
// first remove for origNode's parent list.
|
||||
origNode->removeParent(this);
|
||||
|
||||
// note ref_ptr<> automatically handles decrementing origNode's reference count,
|
||||
// and inccrementing newNode's reference count.
|
||||
*itr = newNode;
|
||||
|
||||
// register as parent of child.
|
||||
newNode->_parents.push_back(this);
|
||||
newNode->addParent(this);
|
||||
|
||||
dirtyBound();
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include <osg/Node>
|
||||
#include <osg/Group>
|
||||
#include <osg/NodeVisitor>
|
||||
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <algorithm>
|
||||
@ -41,6 +40,16 @@ Node::~Node()
|
||||
{
|
||||
}
|
||||
|
||||
void Node::addParent(osg::Group* node)
|
||||
{
|
||||
_parents.push_back(node);
|
||||
}
|
||||
|
||||
void Node::removeParent(osg::Group* node)
|
||||
{
|
||||
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
|
||||
if (pitr!=_parents.end()) _parents.erase(pitr);
|
||||
}
|
||||
|
||||
void Node::accept(NodeVisitor& nv)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgDBGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgGLUTGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgTextGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgUtilGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const char* osgWXGetVersion()
|
||||
{
|
||||
return "0.8.43";
|
||||
return "0.8.44";
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user