Added support for shallow and deep copy of nodes, drawables and state, via a

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
This commit is contained in:
Robert Osfield 2002-01-28 21:17:01 +00:00
parent 7f65110322
commit f612924a45
74 changed files with 898 additions and 263 deletions

View File

@ -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

View File

@ -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.*/

View File

@ -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. */

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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.*/

58
include/osg/DeepCopy Normal file
View File

@ -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 <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

View File

@ -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.*/

View File

@ -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<const Drawable*>(obj)!=NULL; }
virtual const char* className() const { return "Drawable"; }

View File

@ -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. */

View File

@ -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.*/

View File

@ -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.*/

View File

@ -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<const GeoSet*>(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. */

View File

@ -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.

View File

@ -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);

View File

@ -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<const Image*>(obj)!=0; }
virtual const char* className() const { return "Image"; }

View File

@ -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<ImpostorSprite> > ImpostorSpriteList;

View File

@ -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<const ImpostorSprite*>(obj)!=NULL; }
virtual const char* className() const { return "ImpostorSprite"; }

View File

@ -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);

View File

@ -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));

View File

@ -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<osg::Light*>(cloner(es._light.get()))) {}
META_Node(LightSource);
/** Set the attached light.*/

View File

@ -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.*/

View File

@ -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);

View File

@ -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<const Matrix*>(obj)!=NULL; } \
virtual const char* className() const { return "Matrix"; }
virtual ~Matrix() {}
Matrix& operator = (const Matrix& );

View File

@ -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<const name *>(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<const Node*>(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]; }
/**

View File

@ -6,6 +6,7 @@
#define OSG_OBJECT 1
#include <osg/Referenced>
#include <osg/ShallowCopy>
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<const name *>(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<const T *>(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; }
};

View File

@ -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.*/

View File

@ -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.*/

View File

@ -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.*/

View File

@ -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);

View File

@ -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.*/

41
include/osg/ShallowCopy Normal file
View File

@ -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<Referenced*>(ref); }
virtual Object* operator() (const Object* obj) const { return const_cast<Object*>(obj); }
virtual Node* operator() (const Node* node) const { return const_cast<Node*>(node); }
virtual Drawable* operator() (const Drawable* drawable) const { return const_cast<Drawable*>(drawable); }
virtual StateSet* operator() (const StateSet* stateset) const { return const_cast<StateSet*>(stateset); }
virtual StateAttribute* operator() (const StateAttribute* attr) const { return const_cast<StateAttribute*>(attr); }
virtual Texture* operator() (const Texture* text) const { return const_cast<Texture*>(text); }
virtual Image* operator() (const Image* image) const { return const_cast<Image*>(image); }
};
/** Convenience typedef so that users can use the more logical ShallowCopy in their own code.*/
typedef Cloner ShallowCopy;
};
#endif

View File

@ -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<StateAttribute*>(attribute->clone());
if (!as.global_default_attribute.valid()) as.global_default_attribute = dynamic_cast<StateAttribute*>(attribute->cloneType());
as.last_applied_attribute = attribute;
attribute->apply(*this);

View File

@ -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<const name *>(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<const name *>(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<const StateAttribute*>(obj)!=NULL; }

View File

@ -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<const StateSet*>(obj)!=NULL; }
virtual const char* className() const { return "StateSet"; }

View File

@ -5,7 +5,7 @@
#ifndef OSGUTIL_STATISTICS
#define OSGUTIL_STATISTICS 1
#include <osg/Object>
#include <osg/Referenced>
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<const Statistics*>(obj)!=0L; }
virtual const char* className() const { return "Statistics"; }
enum statsType
{

View File

@ -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.*/

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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.*/

View File

@ -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);

View File

@ -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.*/

View File

@ -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.*/

View File

@ -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<const name *>(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<const Font *>(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<const RasterFont *>(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<const VectorFont *>(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
///////////////////////////////////////////////////////////////////////////////
};

View File

@ -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)

View File

@ -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<const Text*>(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> _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> _font;
bool _init;
bool _initAlignment;
std::string _text;
int _fontType;
int _alignment;
int _drawMode;
int _boundingBoxType;
osg::Vec3 _pos;
osg::Vec3 _alignmentPos;
};
// Text
///////////////////////////////////////////////////////////////////////////////
};

View File

@ -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<const RenderBin*>(obj)!=0L; }
virtual const char* className() const { return "RenderBin"; }

View File

@ -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<const RenderStage*>(obj)!=0L; }
virtual const char* className() const { return "RenderStage"; }

View File

@ -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<const RenderStageLighting*>(obj)!=0L; }
virtual const char* className() const { return "RenderStageLighting"; }

View File

@ -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<const RenderToTextureStage*>(obj)!=0L; }
virtual const char* className() const { return "RenderToTextureStage"; }

View File

@ -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 );

View File

@ -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)

View File

@ -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."<<endl;
}
else
{
_iarray = 0L;
}
}
#define INDEX_ARRAY_DELETE(A) if (A._is_ushort) ushortList.insert(A._ptr._ushort); else uintList.insert(A._ptr._uint);
void GeoSet::AttributeDeleteFunctor::operator() (GeoSet* gset)

View File

@ -10,6 +10,17 @@ Geode::Geode()
{
}
Geode::Geode(const Geode& geode,const Cloner& cloner):
Node(geode,cloner)
{
for(DrawableList::const_iterator itr=geode._drawables.begin();
itr!=geode._drawables.end();
++itr)
{
Drawable* drawable = cloner(itr->get());
if (drawable) _drawables.push_back(drawable);
}
}
Geode::~Geode()
{

View File

@ -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()
{

View File

@ -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()
{

View File

@ -29,12 +29,9 @@ ImpostorSprite::ImpostorSprite()
_texture = NULL;
_s = 0;
_t = 0;
_t = 0;
}
ImpostorSprite::~ImpostorSprite()
{
if (_ism)

View File

@ -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())

View File

@ -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\

View File

@ -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 );
}

View File

@ -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()
{

View File

@ -2,4 +2,5 @@
using namespace osg;
// no non inline functions yet for Object...
Object::Object(const Object&,const Cloner&):
Referenced() {}

View File

@ -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;

View File

@ -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)
{

View File

@ -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 )
{

View File

@ -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)
{

View File

@ -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;

View File

@ -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<Font*>(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;

View File

@ -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<Font*>(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()
{
}

View File

@ -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);

View File

@ -29,7 +29,7 @@ RenderBin* RenderBin::createRenderBin(const std::string& binName)
// cout << "creating RB "<<binName<<std::endl;
RenderBinPrototypeList::iterator itr = renderBinPrototypeList()->find(binName);
if (itr != renderBinPrototypeList()->end()) return dynamic_cast<RenderBin*>(itr->second->clone());
if (itr != renderBinPrototypeList()->end()) return dynamic_cast<RenderBin*>(itr->second->cloneType());
else return NULL;
}