diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index da476f182..9538af1e6 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -361,6 +361,10 @@ SOURCE=..\..\Include\Osg\CullFace # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\DeepCopy +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\Depth # End Source File # Begin Source File @@ -521,6 +525,10 @@ SOURCE=..\..\Include\Osg\ShadeModel # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\ShallowCopy +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\State # End Source File # Begin Source File diff --git a/include/osg/AlphaFunc b/include/osg/AlphaFunc index ce2860bc5..5febf589f 100644 --- a/include/osg/AlphaFunc +++ b/include/osg/AlphaFunc @@ -19,6 +19,12 @@ class SG_EXPORT AlphaFunc : public StateAttribute AlphaFunc(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + AlphaFunc(const AlphaFunc& af,const Cloner& cloner=ShallowCopy()): + StateAttribute(af,cloner), + _comparisonFunc(af._comparisonFunc), + _referenceValue(af._referenceValue) {} + META_StateAttribute(AlphaFunc,ALPHAFUNC); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Billboard b/include/osg/Billboard index 8c46994f5..6444b856d 100644 --- a/include/osg/Billboard +++ b/include/osg/Billboard @@ -25,6 +25,9 @@ class SG_EXPORT Billboard : public Geode Billboard(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Billboard(const Billboard&,const Cloner& cloner=ShallowCopy()); + META_Node(Billboard); /** Set the billboard rotation mode. */ diff --git a/include/osg/ClipPlane b/include/osg/ClipPlane index fa7c45308..ef1451227 100644 --- a/include/osg/ClipPlane +++ b/include/osg/ClipPlane @@ -17,6 +17,17 @@ class SG_EXPORT ClipPlane : public StateAttribute public : ClipPlane(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + ClipPlane(const ClipPlane& cp,const Cloner& cloner=ShallowCopy()): + StateAttribute(cp,cloner) + { + _clipPlane[0]=cp._clipPlane[0]; + _clipPlane[1]=cp._clipPlane[1]; + _clipPlane[2]=cp._clipPlane[2]; + _clipPlane[3]=cp._clipPlane[3]; + _clipPlaneNum=cp._clipPlaneNum; + } META_StateAttribute(ClipPlane, (Type)(CLIPPLANE+_clipPlaneNum)); diff --git a/include/osg/ColorMask b/include/osg/ColorMask index 85097e1b2..98e005e77 100644 --- a/include/osg/ColorMask +++ b/include/osg/ColorMask @@ -19,6 +19,14 @@ class SG_EXPORT ColorMask : public StateAttribute ColorMask(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + ColorMask(const ColorMask& cm,const Cloner& cloner=ShallowCopy()): + StateAttribute(cm,cloner), + _red(cm._red), + _green(cm._green), + _blue(cm._blue), + _alpha(cm._alpha) {} META_StateAttribute(ColorMask, COLORMASK); diff --git a/include/osg/ColorMatrix b/include/osg/ColorMatrix index 27df0e7c6..ff617bb70 100644 --- a/include/osg/ColorMatrix +++ b/include/osg/ColorMatrix @@ -14,7 +14,13 @@ namespace osg { class SG_EXPORT ColorMatrix : public StateAttribute { public : - ColorMatrix( void ); + + ColorMatrix(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + ColorMatrix(const ColorMatrix& cm,const Cloner& cloner=ShallowCopy()): + StateAttribute(cm,cloner), + _matrix(cm._matrix) {} META_StateAttribute(ColorMatrix, COLORMATRIX); diff --git a/include/osg/CullFace b/include/osg/CullFace index c28c67f1e..9b637d01b 100644 --- a/include/osg/CullFace +++ b/include/osg/CullFace @@ -19,6 +19,11 @@ class SG_EXPORT CullFace : public StateAttribute CullFace(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + CullFace(const CullFace& cf,const Cloner& cloner=ShallowCopy()): + StateAttribute(cf,cloner), + _mode(cf._mode) {} + META_StateAttribute(CullFace, CULLFACE); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/DeepCopy b/include/osg/DeepCopy new file mode 100644 index 000000000..9befac5f0 --- /dev/null +++ b/include/osg/DeepCopy @@ -0,0 +1,58 @@ +//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 +#include +#include + +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 diff --git a/include/osg/Depth b/include/osg/Depth index aab002bd0..d67ff55ed 100644 --- a/include/osg/Depth +++ b/include/osg/Depth @@ -20,6 +20,15 @@ class SG_EXPORT Depth : public StateAttribute Depth(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Depth(const Depth& dp,const Cloner& cloner=ShallowCopy()): + StateAttribute(dp,cloner), + _func(dp._func), + _depthWriteMask(dp._depthWriteMask), + _zNear(dp._zNear), + _zFar(dp._zFar) {} + + META_StateAttribute(Depth, DEPTH); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Drawable b/include/osg/Drawable index 934003ae9..9e6bdae46 100644 --- a/include/osg/Drawable +++ b/include/osg/Drawable @@ -55,6 +55,16 @@ class SG_EXPORT Drawable : public Object Drawable(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Drawable(const Drawable& drawable,const Cloner& cloner=ShallowCopy()): + Object(drawable,cloner), + _dstate(cloner(drawable._dstate.get())), + _supportsDisplayList(drawable._supportsDisplayList), + _useDisplayList(drawable._useDisplayList), + _globjList(drawable._globjList), + _bbox(drawable._bbox), + _bbox_computed(drawable._bbox_computed) {} + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* className() const { return "Drawable"; } diff --git a/include/osg/EarthSky b/include/osg/EarthSky index 85b95a37f..38af2727e 100644 --- a/include/osg/EarthSky +++ b/include/osg/EarthSky @@ -26,6 +26,12 @@ class SG_EXPORT EarthSky : public Group EarthSky(); + EarthSky(const EarthSky& es, const Cloner& cloner=ShallowCopy()): + Group(es,cloner), + _requiresClear(es._requiresClear), + _clearColor(es._clearColor) {} + + META_Node(EarthSky); /** Sets the flag which control whether a glClear is required at the beginning of each frame. */ diff --git a/include/osg/Fog b/include/osg/Fog index 46d8f8bf7..afbceb43c 100644 --- a/include/osg/Fog +++ b/include/osg/Fog @@ -20,6 +20,15 @@ class SG_EXPORT Fog : public StateAttribute Fog(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Fog(const Fog& fog,const Cloner& cloner=ShallowCopy()): + StateAttribute(fog,cloner), + _mode(fog._mode), + _density(fog._density), + _start(fog._start), + _end(fog._end), + _color(fog._color) {} + META_StateAttribute(Fog,FOG); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/FrontFace b/include/osg/FrontFace index 17094a7ca..21c88bf17 100644 --- a/include/osg/FrontFace +++ b/include/osg/FrontFace @@ -18,6 +18,11 @@ class SG_EXPORT FrontFace : public StateAttribute FrontFace(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + FrontFace(const FrontFace& ff,const Cloner& cloner=ShallowCopy()): + StateAttribute(ff,cloner), + _mode(ff._mode) {} + META_StateAttribute(FrontFace, FRONTFACE); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/GeoSet b/include/osg/GeoSet index df34024e9..78badea32 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -146,8 +146,16 @@ class SG_EXPORT GeoSet : public Drawable }; GeoSet(); - virtual Object* clone() const { return new GeoSet(); } + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + GeoSet(const GeoSet& geoset,const Cloner& cloner=ShallowCopy()); + + virtual Object* cloneType() const { return new GeoSet(); } + + virtual Object* clone(const Cloner& cloner) const { return new GeoSet(*this,cloner); } + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* className() const { return "GeoSet"; } @@ -165,7 +173,6 @@ class SG_EXPORT GeoSet : public Drawable void computeNumVerts() const; /** get the number of coords required by the defined primitives. */ - // inline const int getNumCoords() const inline const int getNumCoords() const { if( _numcoords == 0 ) computeNumVerts(); return _numcoords; } /** get a pointer to Vec3 coord array. */ diff --git a/include/osg/Geode b/include/osg/Geode index 142712541..cf7f196c0 100644 --- a/include/osg/Geode +++ b/include/osg/Geode @@ -20,6 +20,9 @@ class SG_EXPORT Geode : public Node Geode(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Geode(const Geode&,const Cloner& cloner=ShallowCopy()); + META_Node(Geode); /** Add Drawable to Geode. diff --git a/include/osg/Group b/include/osg/Group index f39bdfb08..49368ae08 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -22,6 +22,9 @@ class SG_EXPORT Group : public Node Group(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Group(const Group&,const Cloner& cloner=ShallowCopy()); + META_Node(Group); virtual void traverse(NodeVisitor& nv); diff --git a/include/osg/Image b/include/osg/Image index 369d04280..e4e805e73 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -20,8 +20,12 @@ class SG_EXPORT Image : public Object public : Image(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Image(const Image& image,const Cloner& cloner=ShallowCopy()); - virtual Object* clone() const { return new Image(); } + virtual Object* cloneType() const { return new Image(); } + virtual Object* clone(const Cloner& cloner) const { return new Image(*this,cloner); } virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=0; } virtual const char* className() const { return "Image"; } diff --git a/include/osg/Impostor b/include/osg/Impostor index dc2edfb0d..5e9ee235e 100644 --- a/include/osg/Impostor +++ b/include/osg/Impostor @@ -53,6 +53,11 @@ class SG_EXPORT Impostor : public LOD public : Impostor(); + Impostor(const Impostor& es, const Cloner& cloner=ShallowCopy()): + LOD(es,cloner), + _impostorSpriteList(), + _impostorThreshold(es._impostorThreshold) {} + META_Node(Impostor); typedef std::vector< ref_ptr > ImpostorSpriteList; diff --git a/include/osg/ImpostorSprite b/include/osg/ImpostorSprite index bbe8e7a2f..2fecde36b 100644 --- a/include/osg/ImpostorSprite +++ b/include/osg/ImpostorSprite @@ -30,7 +30,13 @@ class SG_EXPORT ImpostorSprite : public Drawable public: ImpostorSprite(); - virtual Object* clone() const { return new ImpostorSprite(); } + + /** Clone an object of the same type as an ImpostorSprite.*/ + virtual Object* cloneType() const { return new ImpostorSprite(); } + + /** Clone on ImpostorSprite just returns a clone of type, + * since it is not appropriate to share data of an ImpostorSprite.*/ + virtual Object* clone(const Cloner&) const { return new ImpostorSprite(); } virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* className() const { return "ImpostorSprite"; } diff --git a/include/osg/LOD b/include/osg/LOD index 3192de489..e258bf55c 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -26,8 +26,12 @@ namespace osg { class SG_EXPORT LOD : public Group { public : + LOD() {} + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + LOD(const LOD&,const Cloner& cloner=ShallowCopy()); + META_Node(LOD); virtual void traverse(NodeVisitor& nv); diff --git a/include/osg/Light b/include/osg/Light index d7f2e733b..bec6ee195 100644 --- a/include/osg/Light +++ b/include/osg/Light @@ -18,6 +18,21 @@ class SG_EXPORT Light : public StateAttribute public : Light(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Light(const Light& light,const Cloner& cloner=ShallowCopy()): + StateAttribute(light,cloner), + _lightnum(light._lightnum), + _ambient(light._ambient), + _diffuse(light._diffuse), + _specular(light._specular), + _position(light._position), + _direction(light._direction), + _constant_attenuation(light._constant_attenuation), + _linear_attenuation(light._linear_attenuation), + _quadratic_attenuation(light._quadratic_attenuation), + _spot_exponent(light._spot_exponent), + _spot_cutoff(light._spot_cutoff) {} META_StateAttribute(Light, (Type)(LIGHT_0+_lightnum)); diff --git a/include/osg/LightSource b/include/osg/LightSource index bfff7320e..dd012f18d 100644 --- a/include/osg/LightSource +++ b/include/osg/LightSource @@ -18,6 +18,10 @@ class SG_EXPORT LightSource : public Node LightSource(); + LightSource(const LightSource& es, const Cloner& cloner=ShallowCopy()): + Node(es,cloner), + _light(dynamic_cast(cloner(es._light.get()))) {} + META_Node(LightSource); /** Set the attached light.*/ diff --git a/include/osg/LineWidth b/include/osg/LineWidth index c992c52e3..02c30f5a4 100644 --- a/include/osg/LineWidth +++ b/include/osg/LineWidth @@ -17,6 +17,11 @@ class SG_EXPORT LineWidth : public StateAttribute LineWidth(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + LineWidth(const LineWidth& lw,const Cloner& cloner=ShallowCopy()): + StateAttribute(lw,cloner), + _width(lw._width) {} + META_StateAttribute(LineWidth, LINEWIDTH); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Material b/include/osg/Material index 307237673..49a674073 100644 --- a/include/osg/Material +++ b/include/osg/Material @@ -18,6 +18,26 @@ class SG_EXPORT Material : public StateAttribute Material(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Material(const Material& mat,const Cloner& cloner=ShallowCopy()): + StateAttribute(mat,cloner), + _colorMode(mat._colorMode), + _ambientFrontAndBack(mat._ambientFrontAndBack), + _ambientFront(mat._ambientFront), + _ambientBack(mat._ambientBack), + _diffuseFrontAndBack(mat._diffuseFrontAndBack), + _diffuseFront(mat._diffuseFront), + _diffuseBack(mat._diffuseBack), + _specularFrontAndBack(mat._specularFrontAndBack), + _specularFront(mat._specularFront), + _specularBack(mat._specularBack), + _emissionFrontAndBack(mat._emissionFrontAndBack), + _emissionFront(mat._emissionFront), + _emissionBack(mat._emissionBack), + _shininessFrontAndBack(mat._shininessFrontAndBack), + _shininessFront(mat._shininessFront), + _shininessBack(mat._shininessBack) {} META_StateAttribute(Material, MATERIAL); diff --git a/include/osg/Matrix b/include/osg/Matrix index 5732b193f..6d34937ed 100644 --- a/include/osg/Matrix +++ b/include/osg/Matrix @@ -20,16 +20,19 @@ class SG_EXPORT Matrix : public Object public: - META_Object(Matrix); - Matrix(); - Matrix( const Matrix& other ); + Matrix( const Matrix& other); explicit Matrix( float const * const def ); Matrix( float a00, float a01, float a02, float a03, float a10, float a11, float a12, float a13, float a20, float a21, float a22, float a23, float a30, float a31, float a32, float a33); + virtual Object* cloneType() const { return new Matrix(); } \ + virtual Object* clone(const Cloner&) const { return new Matrix(*this); } \ + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } \ + virtual const char* className() const { return "Matrix"; } + virtual ~Matrix() {} Matrix& operator = (const Matrix& ); diff --git a/include/osg/Node b/include/osg/Node index 10e30739a..1fd4b9741 100644 --- a/include/osg/Node +++ b/include/osg/Node @@ -23,7 +23,8 @@ class Group; * and accept methods. Use when subclassing from Node to make it * more convinient to define the required pure virtual methods.*/ #define META_Node(name) \ - virtual osg::Object* clone() const { return new name (); } \ + virtual osg::Object* cloneType() const { return new name (); } \ + virtual osg::Object* clone(const osg::Cloner& cloner) const { return new name (*this,cloner); } \ virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ virtual const char* className() const { return #name; } \ virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) nv.apply(*this); } \ @@ -41,8 +42,14 @@ class SG_EXPORT Node : public Object bounding sphere dirty flag to true.*/ Node(); - /** return a shallow copy of a node, with Object* return type.*/ - virtual Object* clone() const { return new Node(); } + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Node(const Node&,const Cloner& cloner=ShallowCopy()); + + /** clone the an object of the same type as the node.*/ + virtual Object* cloneType() const { return new Node(); } + + /** return a clone of a node, with Object* return type.*/ + virtual Object* clone(const Cloner& cloner) const { return new Node(*this,cloner); } /** return true if this and obj are of the same kind of object.*/ virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } @@ -74,7 +81,7 @@ class SG_EXPORT Node : public Object /** Get the a copy of parent list of node. A copy is returned to * prevent modification of the parent list.*/ -// inline ParentList getParents() { return _parents; } + inline ParentList getParents() { return _parents; } inline Group* getParent(const int i) { return _parents[i]; } /** diff --git a/include/osg/Object b/include/osg/Object index 72dd3e4a2..bfb141a88 100644 --- a/include/osg/Object +++ b/include/osg/Object @@ -6,6 +6,7 @@ #define OSG_OBJECT 1 #include +#include namespace osg { @@ -13,10 +14,11 @@ namespace osg { * Use when subclassing from Object to make it more convinient to define * the standard pure virtual clone, isSameKindAs and className methods * which are required for all Object subclasses.*/ -#define META_Object(name) \ - virtual osg::Object* clone() const { return new name (); } \ - virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ - virtual const char* className() const { return #name; } +#define META_Object(T) \ + virtual osg::Object* cloneType() const { return new T (); } \ + virtual osg::Object* clone(const osg::Cloner& cloner) const { return new T (*this,cloner); } \ + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ + virtual const char* className() const { return #T; } /** Base class/standard interface for objects which require IO support, @@ -26,15 +28,25 @@ namespace osg { class SG_EXPORT Object : public Referenced { public: + + /** Construct an object. Note Object is a pure virtual base class and therefore cannot be constructed on its own, only derived classes which override the clone and className methods are concrete classes and can be constructed.*/ Object() {} - /** return a shallow copy of a node, with Object* return type. + /** Copy constructor, optional Cloner object can be used to control + * shallow vs deep copying of dynamic data.*/ + Object(const Object&,const Cloner& cloner=ShallowCopy()); + + /** Clone the type of an object, with Object* return type. Must be defined by derived classes.*/ - virtual Object* clone() const = 0; + virtual Object* cloneType() const = 0; + + /** Clone the an object, with Object* return type. + Must be defined by derived classes.*/ + virtual Object* clone(const Cloner&) const = 0; virtual bool isSameKindAs(const Object*) const { return true; } @@ -55,8 +67,7 @@ class SG_EXPORT Object : public Referenced private: - /** disallow any form of deep copy.*/ - Object(Object&): Referenced() {} + /** disallow any copy operator.*/ Object& operator = (const Object&) { return *this; } }; diff --git a/include/osg/Point b/include/osg/Point index b620ed5a6..b60cb5fe8 100644 --- a/include/osg/Point +++ b/include/osg/Point @@ -18,6 +18,13 @@ class SG_EXPORT Point : public StateAttribute Point(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Point(const Point& point,const Cloner& cloner=ShallowCopy()): + StateAttribute(point,cloner), + _size(point._size), + _fadeThresholdSize(point._fadeThresholdSize), + _distanceAttenuation(point._distanceAttenuation) {} + META_StateAttribute(Point, POINT); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/PolygonMode b/include/osg/PolygonMode index f719f903e..293a93f06 100644 --- a/include/osg/PolygonMode +++ b/include/osg/PolygonMode @@ -18,6 +18,13 @@ class SG_EXPORT PolygonMode : public StateAttribute PolygonMode(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + PolygonMode(const PolygonMode& pm,const Cloner& cloner=ShallowCopy()): + StateAttribute(pm,cloner), + _frontAndBack(pm._frontAndBack), + _modeFront(pm._modeFront), + _modeBack(pm._modeBack) {} + META_StateAttribute(PolygonMode, POLYGONMODE); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/PolygonOffset b/include/osg/PolygonOffset index f46bc26c0..d13b38b90 100644 --- a/include/osg/PolygonOffset +++ b/include/osg/PolygonOffset @@ -17,6 +17,12 @@ class SG_EXPORT PolygonOffset : public StateAttribute PolygonOffset(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + PolygonOffset(const PolygonOffset& po,const Cloner& cloner=ShallowCopy()): + StateAttribute(po,cloner), + _factor(po._factor), + _units(po._units) {} + META_StateAttribute(PolygonOffset, POLYGONOFFSET); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/PositionAttitudeTransform b/include/osg/PositionAttitudeTransform index acfca0f25..4eb9ce35f 100644 --- a/include/osg/PositionAttitudeTransform +++ b/include/osg/PositionAttitudeTransform @@ -19,6 +19,12 @@ class SG_EXPORT PositionAttitudeTransform : public Transform public : PositionAttitudeTransform(); + PositionAttitudeTransform(const PositionAttitudeTransform& pat,const Cloner& cloner=ShallowCopy()): + Transform(pat,cloner), + _position(pat._position), + _attitude(pat._attitude) {} + + META_Node(PositionAttitudeTransform); diff --git a/include/osg/ShadeModel b/include/osg/ShadeModel index b684db274..26128c42d 100644 --- a/include/osg/ShadeModel +++ b/include/osg/ShadeModel @@ -19,6 +19,12 @@ class SG_EXPORT ShadeModel : public StateAttribute ShadeModel(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + ShadeModel(const ShadeModel& sm,const Cloner& cloner=ShallowCopy()): + StateAttribute(sm,cloner), + _mode(sm._mode) {} + + META_StateAttribute(ShadeModel, SHADEMODEL); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/ShallowCopy b/include/osg/ShallowCopy new file mode 100644 index 000000000..80f4df750 --- /dev/null +++ b/include/osg/ShallowCopy @@ -0,0 +1,41 @@ +//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_SHALLOWCOPY +#define OSG_SHALLOWCOPY 1 + +namespace osg { + +class Referenced; +class Object; +class Image; +class Texture; +class StateSet; +class StateAttribute; +class Node; +class Drawable; + +/** 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 Cloner +{ + virtual ~Cloner() {} + + virtual Referenced* operator() (const Referenced* ref) const { return const_cast(ref); } + virtual Object* operator() (const Object* obj) const { return const_cast(obj); } + virtual Node* operator() (const Node* node) const { return const_cast(node); } + virtual Drawable* operator() (const Drawable* drawable) const { return const_cast(drawable); } + virtual StateSet* operator() (const StateSet* stateset) const { return const_cast(stateset); } + virtual StateAttribute* operator() (const StateAttribute* attr) const { return const_cast(attr); } + virtual Texture* operator() (const Texture* text) const { return const_cast(text); } + virtual Image* operator() (const Image* image) const { return const_cast(image); } +}; + +/** Convenience typedef so that users can use the more logical ShallowCopy in their own code.*/ +typedef Cloner ShallowCopy; + +}; + +#endif diff --git a/include/osg/State b/include/osg/State index c01338c44..19ed151dd 100644 --- a/include/osg/State +++ b/include/osg/State @@ -181,7 +181,7 @@ class SG_EXPORT State : public Referenced { if (as.last_applied_attribute != attribute) { - if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast(attribute->clone()); + if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast(attribute->cloneType()); as.last_applied_attribute = attribute; attribute->apply(*this); diff --git a/include/osg/StateAttribute b/include/osg/StateAttribute index c4a6bf800..6a0d843d5 100644 --- a/include/osg/StateAttribute +++ b/include/osg/StateAttribute @@ -22,8 +22,9 @@ class StateSet; * the standard pure virtual methods which are required for all Object * subclasses.*/ #define META_StateAttribute(name,type) \ - virtual Object* clone() const { return new name (); } \ - virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } \ + virtual osg::Object* cloneType() const { return new name(); } \ + virtual osg::Object* clone(const osg::Cloner& cloner) const { return new name (*this,cloner); } \ + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ virtual const char* className() const { return #name; } \ virtual const Type getType() const { return type; } @@ -147,9 +148,18 @@ class SG_EXPORT StateAttribute : public Object }; StateAttribute() {} + + StateAttribute(const StateAttribute& sa,const Cloner& cloner=ShallowCopy()): + Object(sa,cloner) {} + - /** return a shallow copy of a node, with Object* return type.*/ - virtual Object* clone() const = 0; + /** Clone the type of an attribute, with Object* return type. + Must be defined by derived classes.*/ + virtual Object* cloneType() const = 0; + + /** Clone an attribute, with Object* return type. + Must be defined by derived classes.*/ + virtual Object* clone(const Cloner&) const = 0; /** return true if this and obj are of the same kind of object.*/ virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } diff --git a/include/osg/StateSet b/include/osg/StateSet index 33995ffe0..da60c8fce 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -28,9 +28,10 @@ class SG_EXPORT StateSet : public Object StateSet(); - StateSet(const StateSet&); + StateSet(const StateSet&,const Cloner& cloner=ShallowCopy()); - virtual Object* clone() const { return new StateSet(); } + virtual Object* cloneType() const { return new StateSet(); } + virtual Object* clone(const Cloner& cloner) const { return new StateSet(*this,cloner); } virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* className() const { return "StateSet"; } diff --git a/include/osg/Statistics b/include/osg/Statistics index 0bb9a17c1..c14d7b0f1 100644 --- a/include/osg/Statistics +++ b/include/osg/Statistics @@ -5,7 +5,7 @@ #ifndef OSGUTIL_STATISTICS #define OSGUTIL_STATISTICS 1 -#include +#include namespace osg { @@ -22,7 +22,7 @@ namespace osg { * each trifan or tristrip = (length-2) triangles and so on. */ -class SG_EXPORT Statistics : public osg::Object +class SG_EXPORT Statistics : public osg::Referenced { public: @@ -52,9 +52,6 @@ class SG_EXPORT Statistics : public osg::Object ~Statistics() {}; // no dynamic allocations, so no need to free - virtual osg::Object* clone() const { return new Statistics(); } - virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } - virtual const char* className() const { return "Statistics"; } enum statsType { diff --git a/include/osg/Stencil b/include/osg/Stencil index 41114e183..e19db2a41 100644 --- a/include/osg/Stencil +++ b/include/osg/Stencil @@ -20,6 +20,18 @@ class SG_EXPORT Stencil : public StateAttribute Stencil(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Stencil(const Stencil& stencil,const Cloner& cloner=ShallowCopy()): + StateAttribute(stencil,cloner), + _func(stencil._func), + _funcRef(stencil._funcRef), + _funcMask(stencil._funcMask), + _sfail(stencil._sfail), + _zfail(stencil._zfail), + _zpass(stencil._zpass), + _writeMask(stencil._writeMask) {} + + META_StateAttribute(Stencil, STENCIL); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Switch b/include/osg/Switch index eb1d7f4d2..d3c0d242a 100644 --- a/include/osg/Switch +++ b/include/osg/Switch @@ -31,6 +31,9 @@ class SG_EXPORT Switch : public Group Switch(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Switch(const Switch&,const Cloner& cloner=ShallowCopy()); + META_Node(Switch); virtual void traverse(NodeVisitor& nv); diff --git a/include/osg/TexEnv b/include/osg/TexEnv index 77f746480..4a3ef0a71 100644 --- a/include/osg/TexEnv +++ b/include/osg/TexEnv @@ -15,7 +15,13 @@ class SG_EXPORT TexEnv : public StateAttribute { public : - TexEnv( void ); + TexEnv(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + TexEnv(const TexEnv& texenv,const Cloner& cloner=ShallowCopy()): + StateAttribute(texenv,cloner), + _mode(texenv._mode) {} + META_StateAttribute(TexEnv, TEXENV); diff --git a/include/osg/TexGen b/include/osg/TexGen index df3545dcf..cfd996d34 100644 --- a/include/osg/TexGen +++ b/include/osg/TexGen @@ -16,7 +16,16 @@ class SG_EXPORT TexGen : public StateAttribute { public : - TexGen( void ); + TexGen(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + TexGen(const TexGen& texgen,const Cloner& cloner=ShallowCopy()): + StateAttribute(texgen,cloner), + _mode(texgen._mode), + _plane_s(texgen._plane_s), + _plane_t(texgen._plane_t), + _plane_r(texgen._plane_r), + _plane_q(texgen._plane_q) {} META_StateAttribute(TexGen, TEXGEN); diff --git a/include/osg/TexMat b/include/osg/TexMat index 94bf31644..d17afb933 100644 --- a/include/osg/TexMat +++ b/include/osg/TexMat @@ -14,7 +14,13 @@ namespace osg { class SG_EXPORT TexMat : public StateAttribute { public : - TexMat( void ); + + TexMat(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + TexMat(const TexMat& texmat,const Cloner& cloner=ShallowCopy()): + StateAttribute(texmat,cloner), + _matrix(texmat._matrix) {} META_StateAttribute(TexMat, TEXMAT); diff --git a/include/osg/Texture b/include/osg/Texture index b7e489c84..c18fa60a9 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -69,6 +69,27 @@ class SG_EXPORT Texture : public StateAttribute Texture(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Texture(const Texture& text,const Cloner& cloner=ShallowCopy()): + StateAttribute(text,cloner), + _handleList(text._handleList), + _modifiedTag(text._modifiedTag), + _textureObjectSize(text._textureObjectSize), + _image(cloner(text._image.get())), + _textureUnit(text._textureUnit), + _wrap_s(text._wrap_s), + _wrap_t(text._wrap_t), + _wrap_r(text._wrap_r), + _min_filter(text._min_filter), + _mag_filter(text._mag_filter), + _internalFormatMode(text._internalFormatMode), + _internalFormatValue(text._internalFormatValue), + _textureWidth(text._textureWidth), + _textureHeight(text._textureHeight), + _subloadMode(text._subloadMode), + _subloadOffsX(text._subloadOffsX), + _subloadOffsY(text._subloadOffsY) {} + META_StateAttribute(Texture,(Type)(TEXTURE_0+_textureUnit)); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Transform b/include/osg/Transform index 7585d3970..c1fe993ea 100644 --- a/include/osg/Transform +++ b/include/osg/Transform @@ -26,7 +26,12 @@ namespace osg { class SG_EXPORT Transform : public Group { public : + Transform(); + + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Transform(const Transform&,const Cloner& cloner=ShallowCopy()); + Transform(const Matrix& matix); META_Node(Transform); diff --git a/include/osg/Transparency b/include/osg/Transparency index a31974e39..e51454f98 100644 --- a/include/osg/Transparency +++ b/include/osg/Transparency @@ -17,6 +17,12 @@ class SG_EXPORT Transparency : public StateAttribute Transparency(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Transparency(const Transparency& trans,const Cloner& cloner=ShallowCopy()): + StateAttribute(trans,cloner), + _source_factor(trans._source_factor), + _destination_factor(trans._destination_factor) {} + META_StateAttribute(Transparency,TRANSPARENCY); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osg/Viewport b/include/osg/Viewport index 2e8d4e3e2..29c06fefb 100644 --- a/include/osg/Viewport +++ b/include/osg/Viewport @@ -20,6 +20,14 @@ class SG_EXPORT Viewport : public StateAttribute Viewport(); + /** Copy constructor using Cloner to manage deep vs shallow copy.*/ + Viewport(const Viewport& vp,const Cloner& cloner=ShallowCopy()): + StateAttribute(vp,cloner), + _x(vp._x), + _y(vp._y), + _width(vp._width), + _height(vp._height) {} + META_StateAttribute(Viewport,VIEWPORT); /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ diff --git a/include/osgText/Font b/include/osgText/Font index d2d25159e..348b2905d 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -33,189 +33,207 @@ class FTFont; namespace osgText { -/////////////////////////////////////////////////////////////////////////////// -// Font - FontBaseClass +/** META_Font macro define the standard clone, isSameKindAs, + * className and getType methods. + * Use when subclassing from Object to make it more convinient to define + * the standard pure virtual methods which are required for all Object + * subclasses.*/ +#define META_Font(name) \ + virtual osg::Object* cloneType() const { return new name(); } \ + virtual osg::Object* clone(const osg::Cloner& cloner) const { return new name (*this,cloner); } \ + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ + virtual const char* className() const { return #name; } \ + + + class OSGTEXT_EXPORT Font : public osg::Object { -public: + public: - Font(); + Font(); + Font(const Font& font,const osg::Cloner& cloner=osg::ShallowCopy()): + Object(font,cloner), + _init(false), + _created(false), + _font(0L), + _fontName(font._fontName), + _pointSize(font._pointSize), + _res(font._res), + _textureSize(font._textureSize) + {} + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* className() const { return "Font"; } - bool open(const char* font); - bool open(const std::string& font); - - virtual bool create(osg::State& state,int pointSize, const unsigned int res = 72 ); - virtual bool create(osg::State& state); - virtual void output(osg::State& state,const char* text); + bool open(const char* font); + bool open(const std::string& font); - virtual bool isOk(void) const { return _init; } - virtual bool isCreated(void) const { return isOk() && _created; } + virtual bool create(osg::State& state,int pointSize, const unsigned int res = 72 ); + virtual bool create(osg::State& state); + virtual void output(osg::State& state,const char* text); - virtual float getWidth(const char* text) const; - virtual int getHeight() const; - virtual int getDescender() const; - virtual int getAscender() const; + virtual bool isOk(void) const { return _init; } + virtual bool isCreated(void) const { return isOk() && _created; } - int getPointSize(void) const { return _pointSize; } - int getTextureSize(void) const { return _textureSize; } - const std::string& getFontName(); + virtual float getWidth(const char* text) const; + virtual int getHeight() const; + virtual int getDescender() const; + virtual int getAscender() const; - FTFont* getFont(void) { return _font; } + int getPointSize(void) const { return _pointSize; } + int getTextureSize(void) const { return _textureSize; } + const std::string& getFontName(); -protected: + FTFont* getFont(void) { return _font; } - virtual ~Font(); + protected: - virtual void clear(); + virtual ~Font(); - virtual FTFont* createFontObj(void)=0; + virtual void clear(); - bool init(const std::string& font); + virtual FTFont* createFontObj(void)=0; - bool _init; - bool _created; + bool init(const std::string& font); - FTFont* _font; - std::string _fontName; - int _pointSize; - int _res; - int _textureSize; + bool _init; + bool _created; + + FTFont* _font; + std::string _fontName; + int _pointSize; + int _res; + int _textureSize; }; -// Font -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// RasterFont + class OSGTEXT_EXPORT RasterFont:public Font { -public: - RasterFont():Font(){;} - RasterFont(const std::string& font):Font(){;} + public: -protected: + RasterFont():Font(){} + RasterFont(const RasterFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + Font(font,cloner) {} + RasterFont(const std::string& font):Font() {} + + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* className() const { return "RasterFont"; } + + protected: }; -// RasterFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// VectorFont + class OSGTEXT_EXPORT VectorFont:public Font { -public: - VectorFont():Font(){;} - VectorFont(const std::string& font):Font(){;} + public: + VectorFont():Font(){} + VectorFont(const VectorFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + Font(font,cloner) {} + VectorFont(const std::string& font):Font(){} -protected: - double _precision; + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* className() const { return "VectorFont"; } + + protected: + double _precision; }; -// VectorFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// BitmapFont + class OSGTEXT_EXPORT BitmapFont:public RasterFont { -public: + public: - BitmapFont() {;} - - BitmapFont(const std::string& font, - int point_size); - - META_Object(BitmapFont); + BitmapFont() {} + BitmapFont(const BitmapFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + RasterFont(font,cloner) {} + BitmapFont(const std::string& font, + int point_size); -protected: + META_Font(BitmapFont); + + protected: - virtual FTFont* createFontObj(void); + virtual FTFont* createFontObj(void); }; -// BitmapFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// PixmapFont class OSGTEXT_EXPORT PixmapFont:public RasterFont { -public: + public: - PixmapFont() {;} - - PixmapFont(const std::string& font, - int point_size); - - META_Object(PixmapFont); + PixmapFont() {} + PixmapFont(const PixmapFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + RasterFont(font,cloner) {} -protected: + PixmapFont(const std::string& font, + int point_size); - virtual FTFont* createFontObj(void); + META_Font(PixmapFont); + + protected: + + virtual FTFont* createFontObj(void); }; -// PixmapFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// TextureFont class OSGTEXT_EXPORT TextureFont:public RasterFont { -public: + public: - TextureFont() {;} - - TextureFont(const std::string& font, - int point_size); + TextureFont() {} + TextureFont(const TextureFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + RasterFont(font,cloner) {} - TextureFont(const std::string& font, - int point_size, - int textureSize ); - - META_Object(TextureFont); + TextureFont(const std::string& font, + int point_size); -protected: + TextureFont(const std::string& font, + int point_size, + int textureSize ); - virtual FTFont* createFontObj(void); + META_Font(TextureFont); + + protected: + + virtual FTFont* createFontObj(void); }; -// PixmapFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// OutlineFont class OSGTEXT_EXPORT OutlineFont:public VectorFont { -public: + public: - OutlineFont() {;} - - OutlineFont(const std::string& font, - int point_size, - double precision); - - META_Object(OutlineFont); + OutlineFont() {} + OutlineFont(const OutlineFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + VectorFont(font,cloner) {} -protected: + OutlineFont(const std::string& font, + int point_size, + double precision); - virtual FTFont* createFontObj(void); + META_Font(OutlineFont); + + protected: + + virtual FTFont* createFontObj(void); }; -// OutlineFont -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -// PolygonFont class OSGTEXT_EXPORT PolygonFont:public VectorFont { public: - PolygonFont() {;} + PolygonFont() {} + PolygonFont(const PolygonFont& font,const osg::Cloner& cloner=osg::ShallowCopy()): + VectorFont(font,cloner) {} PolygonFont(const std::string& font, int point_size, @@ -225,15 +243,14 @@ public: int point_size, double precision); - META_Object(PolygonFont); + META_Font(PolygonFont); protected: virtual FTFont* createFontObj(void); }; -// PolygonFont -/////////////////////////////////////////////////////////////////////////////// + }; diff --git a/include/osgText/Paragraph b/include/osgText/Paragraph index 2b2803a20..a57f1961d 100644 --- a/include/osgText/Paragraph +++ b/include/osgText/Paragraph @@ -15,6 +15,7 @@ class OSGTEXT_EXPORT Paragraph : public osg::Geode public: Paragraph(); + Paragraph(const Paragraph& paragraph,const osg::Cloner& cloner=osg::ShallowCopy()); Paragraph(const osg::Vec3& position,const std::string& text,osgText::Font* font); META_Node(Paragraph) diff --git a/include/osgText/Text b/include/osgText/Text index 657fecacc..c8e0975bc 100644 --- a/include/osgText/Text +++ b/include/osgText/Text @@ -35,105 +35,108 @@ namespace osgText { class OSGTEXT_EXPORT Text : public osg::Drawable { -public: + public: - enum AlignmentType - { // from left to right, top to bottom - LEFT_TOP, - LEFT_CENTER, - LEFT_BOTTOM, + enum AlignmentType + { // from left to right, top to bottom + LEFT_TOP, + LEFT_CENTER, + LEFT_BOTTOM, - CENTER_TOP, - CENTER_CENTER, - CENTER_BOTTOM, + CENTER_TOP, + CENTER_CENTER, + CENTER_BOTTOM, - RIGHT_TOP, - RIGHT_CENTER, - RIGHT_BOTTOM, - }; + RIGHT_TOP, + RIGHT_CENTER, + RIGHT_BOTTOM, + }; - enum BoundingBoxType - { - GEOMETRY, - GLYPH, - }; + enum BoundingBoxType + { + GEOMETRY, + GLYPH, + }; - enum DrawModeType - { // from left to right, top to bottom - TEXT = 1<<0, - BOUNDINGBOX = 1<<1, - ALIGNEMENT = 1<<2, - DEFAULT = TEXT, - }; + enum DrawModeType + { // from left to right, top to bottom + TEXT = 1<<0, + BOUNDINGBOX = 1<<1, + ALIGNEMENT = 1<<2, + DEFAULT = TEXT, + }; - Text(); - Text(Font* font); + Text(); + Text(const Text& text,const osg::Cloner& cloner=osg::ShallowCopy()); + Text(Font* font); - META_Object(Text); + virtual osg::Object* cloneType() const { return new Text(); } + virtual osg::Object* clone(const osg::Cloner& cloner) const { return new Text(*this,cloner); } + virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* className() const { return "Text"; } - void setPosition(const osg::Vec2& pos); - void setPosition(const osg::Vec3& pos); - const osg::Vec3& getPosition() const { return _pos; } - void setDrawMode(int mode) { _drawMode=mode; } - int getDrawMode() const { return _drawMode; } + void setPosition(const osg::Vec2& pos); + void setPosition(const osg::Vec3& pos); + const osg::Vec3& getPosition() const { return _pos; } - void setBoundingBox(int mode); - int getBoundingBox() const { return _boundingBoxType; } + void setDrawMode(int mode) { _drawMode=mode; } + int getDrawMode() const { return _drawMode; } - void setAlignment(int alignment); - int getAlignment() const { return _alignment; } + void setBoundingBox(int mode); + int getBoundingBox() const { return _boundingBoxType; } - void setFont(Font* font); - Font* getFont() { return _font.get(); } - const Font* getFont() const { return _font.get(); } + void setAlignment(int alignment); + int getAlignment() const { return _alignment; } - void setText(const char* text) { _text=text; } - void setText(const std::string& text) { _text=text; } - const std::string& getText() const { return _text; } + void setFont(Font* font); + Font* getFont() { return _font.get(); } + const Font* getFont() const { return _font.get(); } - virtual void drawImmediateMode(osg::State& state); - virtual void drawBoundingBox(void); - virtual void drawAlignment(void); - - const osg::Vec3& getAlignmentPos() const { return _alignmentPos; }; + void setText(const char* text) { _text=text; } + void setText(const std::string& text) { _text=text; } + const std::string& getText() const { return _text; } - -protected: + virtual void drawImmediateMode(osg::State& state); + virtual void drawBoundingBox(void); + virtual void drawAlignment(void); - enum FontType - { - UNDEF, - BITMAP, - PIXMAP, - OUTLINE, - POLYGON, - TEXTURE, - }; - - virtual ~Text(); + const osg::Vec3& getAlignmentPos() const { return _alignmentPos; }; - virtual void setDefaults(void); - virtual const bool computeBound(void) const; - virtual void calcBounds(osg::Vec3* min,osg::Vec3* max) const; - void initAlignment(osg::Vec3* min,osg::Vec3* max); - bool initAlignment(void); - osg::ref_ptr _font; + protected: - bool _init; - bool _initAlignment; - std::string _text; - int _fontType; - int _alignment; - int _drawMode; - int _boundingBoxType; - - osg::Vec3 _pos; - osg::Vec3 _alignmentPos; + enum FontType + { + UNDEF, + BITMAP, + PIXMAP, + OUTLINE, + POLYGON, + TEXTURE, + }; + + virtual ~Text(); + + virtual void setDefaults(void); + virtual const bool computeBound(void) const; + virtual void calcBounds(osg::Vec3* min,osg::Vec3* max) const; + void initAlignment(osg::Vec3* min,osg::Vec3* max); + bool initAlignment(void); + + osg::ref_ptr _font; + + bool _init; + bool _initAlignment; + std::string _text; + int _fontType; + int _alignment; + int _drawMode; + int _boundingBoxType; + + osg::Vec3 _pos; + osg::Vec3 _alignmentPos; }; -// Text -/////////////////////////////////////////////////////////////////////////////// }; diff --git a/include/osgUtil/RenderBin b/include/osgUtil/RenderBin index e4051a54a..6b6f8d286 100644 --- a/include/osgUtil/RenderBin +++ b/include/osgUtil/RenderBin @@ -35,7 +35,8 @@ class OSGUTIL_EXPORT RenderBin : public osg::Object RenderBin(); - virtual osg::Object* clone() const { return new RenderBin(); } + virtual osg::Object* cloneType() const { return new RenderBin(); } + virtual osg::Object* clone(const osg::Cloner&) const { return new RenderBin(); } // note only implements a clone of type. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } virtual const char* className() const { return "RenderBin"; } diff --git a/include/osgUtil/RenderStage b/include/osgUtil/RenderStage index 8cbe10ada..e387def60 100644 --- a/include/osgUtil/RenderStage +++ b/include/osgUtil/RenderStage @@ -28,7 +28,8 @@ class OSGUTIL_EXPORT RenderStage : public RenderBin RenderStage(); - virtual osg::Object* clone() const { return new RenderStage(); } + virtual osg::Object* cloneType(const osg::Cloner&) const { return new RenderStage(); } + virtual osg::Object* clone(const osg::Cloner&) const { return new RenderStage(); } // note only implements a clone of type. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } virtual const char* className() const { return "RenderStage"; } diff --git a/include/osgUtil/RenderStageLighting b/include/osgUtil/RenderStageLighting index 7301a8cd9..77796ce90 100644 --- a/include/osgUtil/RenderStageLighting +++ b/include/osgUtil/RenderStageLighting @@ -23,7 +23,8 @@ class OSGUTIL_EXPORT RenderStageLighting : public osg::Object RenderStageLighting(); - virtual osg::Object* clone() const { return new RenderStageLighting(); } + virtual osg::Object* cloneType() const { return new RenderStageLighting(); } + virtual osg::Object* clone(const osg::Cloner&) const { return new RenderStageLighting(); } // note only implements a clone of type. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } virtual const char* className() const { return "RenderStageLighting"; } diff --git a/include/osgUtil/RenderToTextureStage b/include/osgUtil/RenderToTextureStage index 15666cbeb..259a7520f 100644 --- a/include/osgUtil/RenderToTextureStage +++ b/include/osgUtil/RenderToTextureStage @@ -20,7 +20,10 @@ class OSGUTIL_EXPORT RenderToTextureStage : public RenderStage RenderToTextureStage(); - virtual osg::Object* clone() const { return new RenderToTextureStage(); } + + + virtual osg::Object* cloneType() const { return new RenderToTextureStage(); } + virtual osg::Object* clone(const osg::Cloner&) const { return new RenderToTextureStage(); } // note only implements a clone of type. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=0L; } virtual const char* className() const { return "RenderToTextureStage"; } diff --git a/src/Demos/osgscribe/osgscribe.cpp b/src/Demos/osgscribe/osgscribe.cpp index 5631737d1..af213df33 100644 --- a/src/Demos/osgscribe/osgscribe.cpp +++ b/src/Demos/osgscribe/osgscribe.cpp @@ -124,9 +124,7 @@ int main( int argc, char **argv ) // run optimization over the scene graph osgUtil::Optimizer optimzer; -// turn off temporarily since the above single child decorator group gets -// removed as the optimizer assumes its redundent. Will fix next. Robert. -// optimzer.optimize(rootnode); + optimzer.optimize(rootnode); // add a viewport to the viewer and attach the scene graph. viewer.addViewport( rootnode ); diff --git a/src/osg/Billboard.cpp b/src/osg/Billboard.cpp index 5fae55fe2..c37bec515 100644 --- a/src/osg/Billboard.cpp +++ b/src/osg/Billboard.cpp @@ -14,6 +14,12 @@ Billboard::Billboard() setCachedMode(); } +Billboard::Billboard(const Billboard& billboard,const Cloner& cloner): + Geode(billboard,cloner), + _mode(billboard._mode), + _axis(billboard._axis), + _positionList(billboard._positionList), + _cachedMode(billboard._cachedMode) {} Billboard::~Billboard() { @@ -91,7 +97,7 @@ const bool Billboard::removeDrawable( Drawable *gset ) return false; } -void Billboard::calcTransform(const Vec3& eye_local, const Vec3& up_local, const Vec3& pos_local, Matrix& mat) const +void Billboard::calcTransform(const Vec3& eye_local, const Vec3& /*up_local*/, const Vec3& pos_local, Matrix& mat) const { Vec3 ev(pos_local-eye_local); switch(_cachedMode) diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index 9455698e6..9940a96eb 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -49,6 +49,97 @@ GeoSet::GeoSet() } + +GeoSet::GeoSet(const GeoSet& geoset,const Cloner& cloner): + Drawable(geoset,cloner) +{ + // ensure that the num of vertices etc have been set up before we copy. + geoset.computeNumVerts(); + + _adf = geoset._adf; + + _numprims = geoset._numprims; + _primtype = geoset._primtype; + _needprimlen = geoset._needprimlen; + _oglprimtype = geoset._oglprimtype; + _primlength = geoset._primlength; + _flat_shaded_skip = geoset._flat_shaded_skip; + if (geoset._primLengths) + { + _primLengths = new int [_primlength]; + memcpy(_primLengths,geoset._primLengths,_primlength); + } + else + { + _primLengths = 0L; + } + + _numcoords = geoset._numcoords; + _cindex = geoset._cindex; + if (geoset._coords) + { + _coords = new Vec3 [_numcoords]; + memcpy(_coords,geoset._coords,_numcoords); + } + else + { + _coords = 0L; + } + + _normal_binding = geoset._normal_binding; + _numnormals = geoset._numnormals; + _nindex = geoset._nindex; + if (geoset._normals) + { + _normals = new Vec3 [_numnormals]; + memcpy(_normals,geoset._normals,_numnormals); + } + else + { + _normals = 0L; + } + + _color_binding = geoset._color_binding; + _numcolors = geoset._numcolors; + _colindex = geoset._colindex; + if (geoset._colors) + { + _colors = new Vec4 [_numcolors]; + memcpy(_colors,geoset._colors,_numcolors); + } + else + { + _colors = 0L; + } + + _texture_binding = geoset._texture_binding; + _numtcoords = geoset._numtcoords; + _tindex = geoset._tindex; + if (geoset._tcoords) + { + _tcoords = new Vec2 [_numtcoords]; + memcpy(_tcoords,geoset._tcoords,_numtcoords); + } + else + { + _tcoords = 0L; + } + + _iaindex = geoset._iaindex; + _iaformat = geoset._iaformat; + _ogliaformat = geoset._ogliaformat; + _fast_path = geoset._fast_path; + if (geoset._iarray) + { + _iarray = 0L; + osg::notify(osg::WARN)<<"Warning :: GeoSet copy constructor error, copying of interleaved arrays unsupported."<get()); + if (drawable) _drawables.push_back(drawable); + } +} Geode::~Geode() { diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 012345b1c..66f93b5a9 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -13,6 +13,17 @@ Group::Group() { } +Group::Group(const Group& group,const Cloner& cloner): + Node(group,cloner) +{ + for(ChildList::const_iterator itr=group._children.begin(); + itr!=group._children.end(); + ++itr) + { + Node* child = cloner(itr->get()); + if (child) _children.push_back(child); + } +} Group::~Group() { diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 49e7a8364..6bab583a5 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -26,6 +26,30 @@ Image::Image() _modifiedTag = 0; } +Image::Image(const Image& image,const Cloner& cloner): + Object(image,cloner), + _fileName(image._fileName), + _s(image._s), _t(image._t), _r(image._r), + _internalFormat(image._internalFormat), + _pixelFormat(image._pixelFormat), + _dataType(image._dataType), + _packing(image._packing), + _data(0L), + _modifiedTag(image._modifiedTag) +{ + if (image._data) + { + int num_components = + _pixelFormat == GL_LUMINANCE ? 1 : + _pixelFormat == GL_LUMINANCE_ALPHA ? 2 : + _pixelFormat == GL_RGB ? 3 : + _pixelFormat == GL_RGBA ? 4 : 4; + + int size = _s*_t*_r*num_components; + _data = (unsigned char*) malloc(size); + memcpy(_data,image._data,size); + } +} Image::~Image() { diff --git a/src/osg/ImpostorSprite.cpp b/src/osg/ImpostorSprite.cpp index 32e4bd51d..038477ca3 100644 --- a/src/osg/ImpostorSprite.cpp +++ b/src/osg/ImpostorSprite.cpp @@ -29,12 +29,9 @@ ImpostorSprite::ImpostorSprite() _texture = NULL; _s = 0; - _t = 0; - - + _t = 0; } - ImpostorSprite::~ImpostorSprite() { if (_ism) diff --git a/src/osg/LOD.cpp b/src/osg/LOD.cpp index ebfe6d230..f3c7e6f51 100644 --- a/src/osg/LOD.cpp +++ b/src/osg/LOD.cpp @@ -4,6 +4,15 @@ using namespace osg; +LOD::LOD(const LOD& lod,const Cloner& cloner): + Group(lod,cloner), + _rangeList(lod._rangeList), + _rangeList2(lod._rangeList2), + _center(lod._center) +{ +} + + void LOD::traverse(NodeVisitor& nv) { switch(nv.getTraversalMode()) diff --git a/src/osg/Makefile b/src/osg/Makefile index 99eb6ea02..683094a1e 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -77,6 +77,7 @@ TARGET_INCLUDE_FILES = \ osg/ColorMatrix\ osg/CullFace\ osg/Depth\ + osg/DeepCopy\ osg/DisplaySettings\ osg/Drawable\ osg/EarthSky\ @@ -113,6 +114,7 @@ TARGET_INCLUDE_FILES = \ osg/Plane\ osg/Quat\ osg/Referenced\ + osg/ShallowCopy\ osg/State\ osg/StateAttribute\ osg/StateSet\ diff --git a/src/osg/Matrix.cpp b/src/osg/Matrix.cpp index 685dad7a3..962169c65 100644 --- a/src/osg/Matrix.cpp +++ b/src/osg/Matrix.cpp @@ -26,7 +26,7 @@ using namespace osg; Matrix::Matrix() : Object(), fully_realized(false) {} -Matrix::Matrix( const Matrix& other ) : Object() +Matrix::Matrix( const Matrix& other) : Object() { set( (const float *) other._mat ); } diff --git a/src/osg/Node.cpp b/src/osg/Node.cpp index 4b3f15b4f..7977c3659 100644 --- a/src/osg/Node.cpp +++ b/src/osg/Node.cpp @@ -20,6 +20,22 @@ Node::Node() } +Node::Node(const Node& node,const Cloner& cloner): + Object(node,cloner), + _bsphere(_bsphere), + _bsphere_computed(node._bsphere_computed), + _name(node._name), + _parents(), // leave empty as parentList is managed by Group. + _appCallback(node._appCallback), + _numChildrenRequiringAppTraversal(node._numChildrenRequiringAppTraversal), + _cullingActive(node._cullingActive), + _numChildrenWithCullingDisabled(node._numChildrenWithCullingDisabled), + _userData(cloner(node._userData.get())), + _nodeMask(node._nodeMask), + _descriptions(node._descriptions), + _dstate(cloner(node._dstate.get())) +{ +} Node::~Node() { diff --git a/src/osg/Object.cpp b/src/osg/Object.cpp index 50bc920e4..3d9bfd975 100644 --- a/src/osg/Object.cpp +++ b/src/osg/Object.cpp @@ -2,4 +2,5 @@ using namespace osg; -// no non inline functions yet for Object... +Object::Object(const Object&,const Cloner&): + Referenced() {} diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index 62b498a20..0846a2f3c 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -21,8 +21,11 @@ StateSet::StateSet() setRendingBinToInherit(); } -StateSet::StateSet(const StateSet& rhs):Object() +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; diff --git a/src/osg/Switch.cpp b/src/osg/Switch.cpp index 1dc5a68b2..620895021 100644 --- a/src/osg/Switch.cpp +++ b/src/osg/Switch.cpp @@ -13,6 +13,11 @@ Switch::Switch() _value = ALL_CHILDREN_OFF; } +Switch::Switch(const Switch& sw,const Cloner& cloner): + Group(sw,cloner), + _value(sw._value) +{ +} void Switch::traverse(NodeVisitor& nv) { diff --git a/src/osg/Transform.cpp b/src/osg/Transform.cpp index b21234c3c..415eeef10 100644 --- a/src/osg/Transform.cpp +++ b/src/osg/Transform.cpp @@ -16,6 +16,16 @@ Transform::Transform() _worldToLocalDirty = false; } +Transform::Transform(const Transform& transform,const Cloner& cloner): + Group(transform,cloner), + _type(transform._type), + _mode(transform._mode), + _localToWorldDirty(transform._localToWorldDirty), + _localToWorld(transform._localToWorld), + _worldToLocalDirty(transform._worldToLocalDirty), + _worldToLocal(transform._localToWorld) +{ +} Transform::Transform(const Matrix& mat ) { diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 23827f4ad..f2529dc6a 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -328,7 +328,7 @@ osg::Object* Registry::readObjectOfType(const osg::Object& compObj,Input& fr) fr+=2; const DotOsgWrapper::Associates& assoc = wrapper->getAssociates(); - osg::Object* obj = proto->clone(); + osg::Object* obj = proto->cloneType(); while(!fr.eof() && fr[0].getNoNestedBrackets()>entry) { @@ -396,7 +396,7 @@ osg::Object* Registry::readObject(DotOsgWrapperMap& dowMap,Input& fr) fr+=2; const DotOsgWrapper::Associates& assoc = wrapper->getAssociates(); - osg::Object* obj = proto->clone(); + osg::Object* obj = proto->cloneType(); while(!fr.eof() && fr[0].getNoNestedBrackets()>entry) { diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 2fa5431ce..d56995167 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -96,8 +96,8 @@ open(const std::string& font) { clear(); - std::string filename = findFontFile(font); - if (filename.empty()) return false; + std::string filename = findFontFile(font); + if (filename.empty()) return false; _font=createFontObj(); if( _font!=NULL && _font->Open(filename.c_str()) ) @@ -110,9 +110,10 @@ open(const std::string& font) return false; } -bool Font:: -open(const char* font) - { return open(std::string(font)); } +bool Font::open(const char* font) +{ + return open(std::string(font)); +} bool Font:: create(osg::State& state,int pointSize,const unsigned int res) @@ -123,8 +124,7 @@ create(osg::State& state,int pointSize,const unsigned int res) return create(state); } -bool Font:: -create(osg::State& state) +bool Font::create(osg::State& state) { if(_init) { @@ -143,8 +143,7 @@ create(osg::State& state) return false; } -void Font:: -output(osg::State& state,const char* text) +void Font::output(osg::State& state,const char* text) { if(_created) _font->render(text,state.getContextID()); @@ -152,8 +151,7 @@ output(osg::State& state,const char* text) create(state,_pointSize); } -void Font:: -clear() +void Font::clear() { _init=false; diff --git a/src/osgText/Paragraph.cpp b/src/osgText/Paragraph.cpp index f2a37eb09..51e0caf16 100644 --- a/src/osgText/Paragraph.cpp +++ b/src/osgText/Paragraph.cpp @@ -8,6 +8,16 @@ Paragraph::Paragraph() _maxCharsPerLine = 80; } +Paragraph::Paragraph(const Paragraph& paragraph,const osg::Cloner& cloner): + Geode(paragraph,cloner), + _position(paragraph._position), + _text(paragraph._text), + _font(dynamic_cast(cloner(paragraph._font.get()))), + _alignment(paragraph._alignment), + _maxCharsPerLine(paragraph._maxCharsPerLine) +{ +} + Paragraph::Paragraph(const osg::Vec3& position,const std::string& text,osgText::Font* font) { _maxCharsPerLine = 80; diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index 39087aeb9..083aea4d9 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -30,14 +30,27 @@ using namespace osgText; /////////////////////////////////////////////////////////////////////////////// // Text -Text:: -Text() +Text::Text() { setDefaults(); } -Text:: -Text(Font* font) +Text::Text(const Text& text,const osg::Cloner& cloner): + Drawable(text,cloner), + _font(dynamic_cast(cloner(text._font.get()))), + _init(text._init), + _initAlignment(text._initAlignment), + _text(text._text), + _fontType(text._fontType), + _alignment(text._alignment), + _drawMode(text._drawMode), + _boundingBoxType(text._boundingBoxType), + _pos(text._pos), + _alignmentPos(text._alignmentPos) +{ +} + +Text::Text(Font* font) { setDefaults(); @@ -60,8 +73,8 @@ Text(Font* font) } } -Text:: -~Text() + +Text::~Text() { } diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index df3b1e677..1f282bbe0 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -553,7 +553,12 @@ void Optimizer::RemoveRedundentNodesVisitor::apply(osg::Group& group) { if (group.getNumParents()>0 && group.getNumChildren()<=1) { - _redundentNodeList.insert(&group); + if (!group.getUserData() && + !group.getAppCallback() && + !group.getStateSet()) + { + _redundentNodeList.insert(&group); + } } } traverse(group); diff --git a/src/osgUtil/RenderBin.cpp b/src/osgUtil/RenderBin.cpp index 6881d69c1..ac0932f87 100644 --- a/src/osgUtil/RenderBin.cpp +++ b/src/osgUtil/RenderBin.cpp @@ -29,7 +29,7 @@ RenderBin* RenderBin::createRenderBin(const std::string& binName) // cout << "creating RB "<find(binName); - if (itr != renderBinPrototypeList()->end()) return dynamic_cast(itr->second->clone()); + if (itr != renderBinPrototypeList()->end()) return dynamic_cast(itr->second->cloneType()); else return NULL; }