Hiya,

Typically I use osg::ref_ptr<> to let osg handle reference counting.
Right now I'm trying to create a 'rendering engine' for another
library with osg. The idea for the other library is to maintain an API
that allows different rendering engines -- osg, ogre, vtk, etc. The
other library has virtual methods that are called when objects need to
be added and removed from the scene, ie:

void RemoveObjectFromScene(SomeStruct &myStruct)

The objects can be thought of as having a 1:1 relation with osg nodes.
I'd like to maintain a reference to the osg node corresponding to the
object so I don't have to traverse the scene graph to find a given
node (there are a lot of objects and this would get way too expensive
I think). I can modify SomeStruct as long as its library-agnostic --
so no osg specific stuff goes in there. Could I use a void * or
something similar to store a reference?

SomeStruct
{
   void * mysteryPtr;
}

{
    osg::ref_ptr<osg::Node> myNode = new osg::node;   // 1 ref to myNode
    m_persistant_root_node->addChild(myNode);   // 2 refs to myNode

    mysteryPtr = myNode.get();   // 2 refs to myNode (no change!)
}
    // 1 refs to myNode since ref_ptr has gone out of scope as long as
m_persistent_root_node is alive
    // mysteryPtr has NO bearing to any ref counting, except for the
fact that's its a valid pointer to osg::node as
    // long as we have > 0 refs to it

I'd be very grateful if someone could verify the above logic. If I'm
in the wrong here, I'd appreciate any advice pointing me in the right
direction.


Regards,

Preet
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to