2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-01-29 20:52:04 +08:00
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/StateSet>
|
2002-08-28 23:28:11 +08:00
|
|
|
#include <osg/Texture>
|
2002-01-29 20:52:04 +08:00
|
|
|
#include <osg/Drawable>
|
2002-07-26 05:50:08 +08:00
|
|
|
#include <osg/Array>
|
2002-09-20 22:51:59 +08:00
|
|
|
#include <osg/PrimitiveSet>
|
2002-10-30 21:27:15 +08:00
|
|
|
#include <osg/Shape>
|
2009-10-22 18:33:16 +08:00
|
|
|
#include <osg/StateAttribute>
|
2002-01-29 20:52:04 +08:00
|
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
2004-04-02 23:45:34 +08:00
|
|
|
#define COPY_OP( TYPE, FLAG ) \
|
|
|
|
TYPE* CopyOp::operator() (const TYPE* obj) const \
|
|
|
|
{ \
|
|
|
|
if (obj && _flags&FLAG) \
|
2011-04-29 00:33:14 +08:00
|
|
|
return osg::clone(obj, *this); \
|
2004-04-02 23:45:34 +08:00
|
|
|
else \
|
|
|
|
return const_cast<TYPE*>(obj); \
|
|
|
|
}
|
2002-01-29 20:52:04 +08:00
|
|
|
|
2011-04-29 00:33:14 +08:00
|
|
|
COPY_OP( Object, DEEP_COPY_OBJECTS )
|
|
|
|
COPY_OP( Node, DEEP_COPY_NODES )
|
|
|
|
COPY_OP( StateSet, DEEP_COPY_STATESETS )
|
|
|
|
COPY_OP( Image, DEEP_COPY_IMAGES )
|
|
|
|
COPY_OP( Uniform, DEEP_COPY_UNIFORMS )
|
|
|
|
COPY_OP( StateAttributeCallback, DEEP_COPY_CALLBACKS )
|
|
|
|
COPY_OP( Drawable, DEEP_COPY_DRAWABLES )
|
|
|
|
COPY_OP( Texture, DEEP_COPY_TEXTURES )
|
|
|
|
COPY_OP( Array, DEEP_COPY_ARRAYS )
|
|
|
|
COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES )
|
|
|
|
COPY_OP( Shape, DEEP_COPY_SHAPES )
|
2002-01-29 20:52:04 +08:00
|
|
|
|
2004-04-02 23:45:34 +08:00
|
|
|
Referenced* CopyOp::operator() (const Referenced* ref) const
|
2002-01-29 20:52:04 +08:00
|
|
|
{
|
2004-04-02 23:45:34 +08:00
|
|
|
return const_cast<Referenced*>(ref);
|
2002-01-29 20:52:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
|
|
|
|
{
|
|
|
|
if (attr && _flags&DEEP_COPY_STATEATTRIBUTES)
|
|
|
|
{
|
2002-08-28 23:28:11 +08:00
|
|
|
const Texture* textbase = dynamic_cast<const Texture*>(attr);
|
2002-08-25 03:39:39 +08:00
|
|
|
if (textbase)
|
2002-01-29 20:52:04 +08:00
|
|
|
{
|
2002-08-25 03:39:39 +08:00
|
|
|
return operator()(textbase);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-29 00:33:14 +08:00
|
|
|
return osg::clone(attr, *this);
|
2002-01-29 20:52:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return const_cast<StateAttribute*>(attr);
|
|
|
|
}
|
|
|
|
|
2009-06-18 18:01:39 +08:00
|
|
|
NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
|
|
|
|
{
|
2009-10-22 18:33:16 +08:00
|
|
|
if (nc && _flags&DEEP_COPY_CALLBACKS)
|
2009-06-18 18:01:39 +08:00
|
|
|
{
|
|
|
|
// deep copy the full chain of callback
|
2011-04-29 00:33:14 +08:00
|
|
|
osg::NodeCallback* first = osg::clone(nc, *this);
|
|
|
|
if (!first) return 0;
|
|
|
|
|
2009-06-18 18:01:39 +08:00
|
|
|
first->setNestedCallback(0);
|
|
|
|
nc = nc->getNestedCallback();
|
|
|
|
while (nc)
|
|
|
|
{
|
2011-04-29 00:33:14 +08:00
|
|
|
osg::NodeCallback* ucb = osg::clone(nc, *this);
|
|
|
|
if (ucb)
|
|
|
|
{
|
|
|
|
ucb->setNestedCallback(0);
|
|
|
|
first->addNestedCallback(ucb);
|
|
|
|
}
|
2009-06-18 18:01:39 +08:00
|
|
|
nc = nc->getNestedCallback();
|
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return const_cast<NodeCallback*>(nc);
|
|
|
|
}
|