copy constructor which takes an optional Cloner object, and the old osg::Object::clone() has changed so that it now requires a Cloner as paramter. This is passed on to the copy constructor to help control the shallow vs deep copying. The old functionality of clone() which was clone of type has been renamed to cloneType(). Updated all of the OSG to work with these new conventions, implemention all the required copy constructors etc. A couple of areas will do shallow copies by design, a couple of other still need to be updated to do either shallow or deep. Neither of the shallow or deep copy operations have been tested yet, only the old functionality of the OSG has been checked so far, such running the viewer on various demo datasets. Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which was not checking that Group didn't have have any attached StateSet's, Callbacks or UserData. These checks have now been added, which fixes a bug which was revealled by the new osgscribe demo, this related to removal of group acting as state decorator. method
59 lines
2.3 KiB
Plaintext
59 lines
2.3 KiB
Plaintext
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
//as published by the Free Software Foundation.
|
|
|
|
#ifndef OSG_DEEPWCOPY
|
|
#define OSG_DEEPWCOPY 1
|
|
|
|
#include <osg/Node>
|
|
#include <osg/StateSet>
|
|
#include <osg/Texture>
|
|
|
|
namespace osg {
|
|
|
|
|
|
/** Cloner Functor used to control the whether shallow or deep copy is used
|
|
* during copy construction and clone operation. The base Cloner acts as
|
|
* a shallow copy simply passing back the same pointer as passed in.*/
|
|
struct DeepCopy : public Cloner
|
|
{
|
|
|
|
enum CopyOptions
|
|
{
|
|
DEEP_COPY_OBJECTS = 1,
|
|
DEEP_COPY_NODES = 2,
|
|
DEEP_COPY_DRAWABLES = 4,
|
|
DEEP_COPY_STATESETS = 8,
|
|
DEEP_COPY_STATEATTRIBUTES = 16,
|
|
DEEP_COPY_TEXTURES = 32,
|
|
DEEP_COPY_IMAGES = 64,
|
|
DEEP_COPY_ALL = 0xffffffff
|
|
};
|
|
|
|
typedef unsigned int CopyFlags;
|
|
|
|
DeepCopy(CopyFlags flags=DEEP_COPY_NODES):_flags(flags) {}
|
|
|
|
virtual ~DeepCopy() {};
|
|
|
|
// note can't clone a refernced object since it doens't have clone
|
|
// method so we have to assume shallow copy and pass back the pointer.
|
|
virtual Referenced* operator() (const Referenced* ref) const { return ref; }
|
|
|
|
virtual Object* operator() (const Object* obj) const { if (obj && _flags&DEEP_COPY_OBJECTS) return obj->clone(*this); else return NULL; }
|
|
virtual Node* operator() (const Node* node) const { if (obj && _flags&DEEP_COPY_NODES) return node->clone(*this); }
|
|
virtual Drawable* operator() (const Drawable* drawable) const { if (drawable && _flags&DEEP_COPY_DRAWABLES) return drawable->clone(*this); }
|
|
virtual StateSet* operator() (const StateSet* stateset) const { if (stateset && _flags&DEEP_COPY_STATESETS) return stateset->clone(*this); }
|
|
virtual StateAttribute* operator() (const StateAttribute* attr) const { if (attr && _flags&DEEP_COPY_STATEATTRIBUTES) return attr->clone(*this); }
|
|
virtual Texture* operator() (const Texture* text) const { if (text && _flags&DEEP_COPY_TEXTURES) return text->clone(*this); }
|
|
virtual Image* operator() (const Image* image) const { if (image && _flags&DEEP_COPY_IMAGES) return image->clone(*this); }
|
|
|
|
protected:
|
|
|
|
CopyFlags _flags;
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|