[osg-users] Vec3Array instantiation

Filip Arlet filip89 at seznam.cz
Thu Apr 7 02:33:25 PDT 2016


Hi,

Simply you can't do it. They are completle different smart pointers. shared_ptr has outside reference counting and ref_ptr has inside reference counting in osg::Referenced class. Basically you would need to call ref() everytime you create or copy shared_ptr and call unref() (unref_nodelete()) every time shared_ptr is destroyed. And use custom deleter (void custom_del(osg::Referenced* referenced) { referenced->unref(); ??}. But I dont think it will work. Your main problem is that those pointer types have no idea about each other. If your osg::Referenced ref counter drop to zero, your object gets deleted, but you can still have some shared_ptr around with bad data and vice versa, if your shared_ptr gets deleted, you can still have some ref_ptrs in osg classes.

But what I can recommend is this:
subclass osg::Drawable (or Geometry) if you look into osg/Geometry.cpp all functions that accepts arrays (drawImplementation, acceptPrimitiveFunctor, computeBounds, ... ) can use float* values  ...basically glVertexPointer doesnt care about your array type. You can create your custom class without Array Pointers, but with your own shared_ptrs.


Code:

class MyDrawable : public osg::Drawable
{
MyDrawable(std::shared_ptr<MyCustomArrayType> arr) :
m_arr(arr)
{}
private:
std::shared_ptr<MyCustomArrayType> m_arr;
}




Then you would have to look at each virtual function of osg::Drawable and implement it (its not so hard, just take a look at osg::Geometry, how its done - but instead of osg::VecArrays you will use your Array). Of course you dont need to implement all of them.

Cheers,
Filip

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66764#66764








More information about the osg-users mailing list