Have add new osg::CopyOp which replaces last nights osg::Cloner, the new
class now combines Cloner and DeepCopy into one class. Cloner and DeepCopy will be removed in next commit. Also have added osgcopy app to Demos which shows how the CopyOp have be subclassed to create users own specific handling of copying. Have fixed copy constructor problems in GeoSet which fix the deep copy problem experienced yesterday.
This commit is contained in:
74
src/osg/CopyOp.cpp
Normal file
74
src/osg/CopyOp.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <osg/CopyOp>
|
||||
#include <osg/Node>
|
||||
#include <osg/StateSet>
|
||||
#include <osg/Texture>
|
||||
#include <osg/Drawable>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
Referenced* CopyOp::operator() (const Referenced* ref) const
|
||||
{
|
||||
return const_cast<Referenced*>(ref);
|
||||
}
|
||||
|
||||
Object* CopyOp::operator() (const Object* obj) const
|
||||
{
|
||||
if (obj && _flags&DEEP_COPY_OBJECTS)
|
||||
return obj->clone(*this);
|
||||
else return const_cast<Object*>(obj);
|
||||
}
|
||||
|
||||
Node* CopyOp::operator() (const Node* node) const
|
||||
{
|
||||
if (node && _flags&DEEP_COPY_NODES)
|
||||
return dynamic_cast<Node*>(node->clone(*this));
|
||||
else
|
||||
return const_cast<Node*>(node);
|
||||
}
|
||||
|
||||
Drawable* CopyOp::operator() (const Drawable* drawable) const
|
||||
{
|
||||
if (drawable && _flags&DEEP_COPY_DRAWABLES)
|
||||
return dynamic_cast<Drawable*>(drawable->clone(*this));
|
||||
else
|
||||
return const_cast<Drawable*>(drawable);
|
||||
}
|
||||
|
||||
StateSet* CopyOp::operator() (const StateSet* stateset) const
|
||||
{
|
||||
if (stateset && _flags&DEEP_COPY_STATESETS)
|
||||
return dynamic_cast<StateSet*>(stateset->clone(*this));
|
||||
else
|
||||
return const_cast<StateSet*>(stateset);
|
||||
}
|
||||
|
||||
StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
|
||||
{
|
||||
if (attr && _flags&DEEP_COPY_STATEATTRIBUTES)
|
||||
{
|
||||
const Texture* text = dynamic_cast<const Texture*>(attr);
|
||||
if (text)
|
||||
{
|
||||
return operator()(text);
|
||||
}
|
||||
else
|
||||
return dynamic_cast<StateAttribute*>(attr->clone(*this));
|
||||
}
|
||||
else
|
||||
return const_cast<StateAttribute*>(attr);
|
||||
}
|
||||
|
||||
Texture* CopyOp::operator() (const Texture* text) const
|
||||
{
|
||||
if (text && _flags&DEEP_COPY_TEXTURES)
|
||||
return dynamic_cast<Texture*>(text->clone(*this));
|
||||
else
|
||||
return const_cast<Texture*>(text);
|
||||
}
|
||||
|
||||
Image* CopyOp::operator() (const Image* image) const
|
||||
{
|
||||
if (image && _flags&DEEP_COPY_IMAGES)
|
||||
return dynamic_cast<Image*>(image->clone(*this));
|
||||
else return const_cast<Image*>(image);
|
||||
}
|
||||
@@ -66,8 +66,8 @@ GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
|
||||
_flat_shaded_skip = geoset._flat_shaded_skip;
|
||||
if (geoset._primLengths)
|
||||
{
|
||||
_primLengths = new int [_primlength];
|
||||
memcpy(_primLengths,geoset._primLengths,_primlength);
|
||||
_primLengths = new int [_numprims];
|
||||
memcpy(_primLengths,geoset._primLengths,_numprims*sizeof(int));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,7 +79,7 @@ GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
|
||||
if (geoset._coords)
|
||||
{
|
||||
_coords = new Vec3 [_numcoords];
|
||||
memcpy(_coords,geoset._coords,_numcoords);
|
||||
memcpy(_coords,geoset._coords,_numcoords*sizeof(Vec3));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -92,7 +92,7 @@ GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
|
||||
if (geoset._normals)
|
||||
{
|
||||
_normals = new Vec3 [_numnormals];
|
||||
memcpy(_normals,geoset._normals,_numnormals);
|
||||
memcpy(_normals,geoset._normals,_numnormals*sizeof(Vec3));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -105,7 +105,7 @@ GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
|
||||
if (geoset._colors)
|
||||
{
|
||||
_colors = new Vec4 [_numcolors];
|
||||
memcpy(_colors,geoset._colors,_numcolors);
|
||||
memcpy(_colors,geoset._colors,_numcolors*sizeof(Vec4));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -118,7 +118,7 @@ GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner):
|
||||
if (geoset._tcoords)
|
||||
{
|
||||
_tcoords = new Vec2 [_numtcoords];
|
||||
memcpy(_tcoords,geoset._tcoords,_numtcoords);
|
||||
memcpy(_tcoords,geoset._tcoords,_numtcoords*sizeof(Vec2));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ Geode::Geode(const Geode& geode,const Cloner& cloner):
|
||||
++itr)
|
||||
{
|
||||
Drawable* drawable = cloner(itr->get());
|
||||
if (drawable) _drawables.push_back(drawable);
|
||||
if (drawable) addDrawable(drawable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ Group::Group(const Group& group,const Cloner& cloner):
|
||||
++itr)
|
||||
{
|
||||
Node* child = cloner(itr->get());
|
||||
if (child) _children.push_back(child);
|
||||
if (child) addChild(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ C++FILES = \
|
||||
ClipPlane.cpp \
|
||||
ColorMask.cpp \
|
||||
ColorMatrix.cpp \
|
||||
CopyOp.cpp \
|
||||
CullFace.cpp\
|
||||
Depth.cpp \
|
||||
DisplaySettings.cpp\
|
||||
@@ -75,9 +76,9 @@ TARGET_INCLUDE_FILES = \
|
||||
osg/ClippingVolume\
|
||||
osg/ColorMask\
|
||||
osg/ColorMatrix\
|
||||
osg/CopyOp\
|
||||
osg/CullFace\
|
||||
osg/Depth\
|
||||
osg/DeepCopy\
|
||||
osg/DisplaySettings\
|
||||
osg/Drawable\
|
||||
osg/EarthSky\
|
||||
@@ -114,7 +115,6 @@ TARGET_INCLUDE_FILES = \
|
||||
osg/Plane\
|
||||
osg/Quat\
|
||||
osg/Referenced\
|
||||
osg/ShallowCopy\
|
||||
osg/State\
|
||||
osg/StateAttribute\
|
||||
osg/StateSet\
|
||||
|
||||
@@ -27,9 +27,9 @@ Node::Node(const Node& node,const Cloner& cloner):
|
||||
_name(node._name),
|
||||
_parents(), // leave empty as parentList is managed by Group.
|
||||
_appCallback(node._appCallback),
|
||||
_numChildrenRequiringAppTraversal(node._numChildrenRequiringAppTraversal),
|
||||
_numChildrenRequiringAppTraversal(0), // assume no children yet.
|
||||
_cullingActive(node._cullingActive),
|
||||
_numChildrenWithCullingDisabled(node._numChildrenWithCullingDisabled),
|
||||
_numChildrenWithCullingDisabled(0), // assume no children yet.
|
||||
_userData(cloner(node._userData.get())),
|
||||
_nodeMask(node._nodeMask),
|
||||
_descriptions(node._descriptions),
|
||||
|
||||
@@ -23,11 +23,17 @@ StateSet::StateSet()
|
||||
|
||||
StateSet::StateSet(const StateSet& rhs,const Cloner& cloner):Object(rhs,cloner)
|
||||
{
|
||||
// shallow copy right now, we should go through each attribute and
|
||||
// use the cloner instead of attribute list copy.. on the TODO list. Robert. Jan 2002.
|
||||
|
||||
_modeList = rhs._modeList;
|
||||
_attributeList = rhs._attributeList;
|
||||
|
||||
for(AttributeList::const_iterator itr=rhs._attributeList.begin();
|
||||
itr!=rhs._attributeList.end();
|
||||
++itr)
|
||||
{
|
||||
StateAttribute::Type type = itr->first;
|
||||
const RefAttributePair& rap = itr->second;
|
||||
StateAttribute* attr = cloner(rap.first.get());
|
||||
if (attr) _attributeList[type]=RefAttributePair(attr,rap.second);
|
||||
}
|
||||
|
||||
_renderingHint = rhs._renderingHint;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user