2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* 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>
|
2014-06-06 00:26:13 +08:00
|
|
|
#include <osg/Callback>
|
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); \
|
2012-03-22 01:36:20 +08:00
|
|
|
}
|
2002-01-29 20:52:04 +08:00
|
|
|
|
2011-04-29 00:33:14 +08:00
|
|
|
COPY_OP( Object, DEEP_COPY_OBJECTS )
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-11-22 01:17:11 +08:00
|
|
|
Node* CopyOp::operator() (const Node* node) const
|
|
|
|
{
|
|
|
|
if (!node) return 0;
|
|
|
|
|
|
|
|
const Drawable* drawable = node->asDrawable();
|
|
|
|
if (drawable) return operator()(drawable);
|
|
|
|
else if (_flags&DEEP_COPY_NODES) return osg::clone(node, *this);
|
|
|
|
else return const_cast<Node*>(node);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2012-03-22 01:36:20 +08:00
|
|
|
else
|
2002-08-25 03:39:39 +08:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2014-06-06 00:26:13 +08:00
|
|
|
Callback* CopyOp::operator() (const Callback* nc) const
|
2009-06-18 18:01:39 +08:00
|
|
|
{
|
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
|
2014-06-06 00:26:13 +08:00
|
|
|
Callback* first = osg::clone(nc, *this);
|
2011-04-29 00:33:14 +08:00
|
|
|
if (!first) return 0;
|
|
|
|
|
2009-06-18 18:01:39 +08:00
|
|
|
first->setNestedCallback(0);
|
|
|
|
nc = nc->getNestedCallback();
|
2012-03-22 01:36:20 +08:00
|
|
|
while (nc)
|
2009-06-18 18:01:39 +08:00
|
|
|
{
|
2014-06-06 00:26:13 +08:00
|
|
|
Callback* ucb = osg::clone(nc, *this);
|
2011-04-29 00:33:14 +08:00
|
|
|
if (ucb)
|
|
|
|
{
|
|
|
|
ucb->setNestedCallback(0);
|
|
|
|
first->addNestedCallback(ucb);
|
|
|
|
}
|
2009-06-18 18:01:39 +08:00
|
|
|
nc = nc->getNestedCallback();
|
|
|
|
}
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
else
|
2014-06-06 00:26:13 +08:00
|
|
|
return const_cast<Callback*>(nc);
|
2009-06-18 18:01:39 +08:00
|
|
|
}
|