2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 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>
|
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) \
|
|
|
|
return dynamic_cast<TYPE*>( obj->clone(*this) ); \
|
|
|
|
else \
|
|
|
|
return const_cast<TYPE*>(obj); \
|
|
|
|
}
|
2002-01-29 20:52:04 +08:00
|
|
|
|
2004-04-02 23:45:34 +08:00
|
|
|
COPY_OP( Object, DEEP_COPY_OBJECTS );
|
|
|
|
COPY_OP( Node, DEEP_COPY_NODES );
|
|
|
|
COPY_OP( Drawable, DEEP_COPY_DRAWABLES );
|
|
|
|
COPY_OP( StateSet, DEEP_COPY_STATESETS );
|
|
|
|
COPY_OP( Texture, DEEP_COPY_TEXTURES );
|
|
|
|
COPY_OP( Image, DEEP_COPY_IMAGES );
|
|
|
|
COPY_OP( Array, DEEP_COPY_DRAWABLES );
|
|
|
|
COPY_OP( PrimitiveSet, DEEP_COPY_PRIMITIVES );
|
|
|
|
COPY_OP( Shape, DEEP_COPY_SHAPES );
|
2005-04-23 06:45:39 +08:00
|
|
|
COPY_OP( Uniform, DEEP_COPY_UNIFORMS );
|
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
|
|
|
|
{
|
2002-08-28 23:28:11 +08:00
|
|
|
return dynamic_cast<StateAttribute*>(attr->clone(*this));
|
2002-01-29 20:52:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return const_cast<StateAttribute*>(attr);
|
|
|
|
}
|
|
|
|
|
2002-10-30 21:27:15 +08:00
|
|
|
|