More clean up for synch with 0.8.42

This commit is contained in:
Don BURNS
2001-09-19 21:19:47 +00:00
parent 2462c6273c
commit 7e81f6cfa6
292 changed files with 39673 additions and 0 deletions

195
include/osg/BoundsChecking Normal file
View File

@@ -0,0 +1,195 @@
#ifndef OSG_BOUNDSCHECKING
#define OSG_BOUNDSCHECKING 1
#include <osg/Notify>
namespace osg {
/** if value is greater than or equal to minValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class T>
inline void clampGEQUAL(T& value,const T minValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clampping to "<<minValue<<"."<<endl;
value = minValue;
}
}
/** if value is less than or equal to maxValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class T>
inline void clampLEQUAL(T& value,const T maxValue,const char* valueName)
{
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clampping to "<<maxValue<<"."<<endl;
value = maxValue;
}
}
/** if value is between or equal to minValue and maxValue do nothing - legal value,
* otherise clamp value to specified to range and return warning
* with valueName specifying which variable was clamped. Equivilant to
* calling clampGEQUAL(value,minValue,valueName); clampLEQUAL(value,maxValue,valueName); */
template <class T>
inline void clampBetweenRange(T& value,const T minValue,const T maxValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clampping to "<<minValue<<"."<<endl;
value = minValue;
}
else
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clampping to "<<maxValue<<"."<<endl;
value = maxValue;
}
}
/** if array element value[i] is greater than or equal to minValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArrayElementGEQUAL(A& value,const unsigned int i,const T minValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clampping to "<<minValue<<"."<<endl;
value[i] = minValue;
}
}
/** if array element value[i] is less than or equal to maxValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArrayElementLEQUAL(A& value,const unsigned int i,const T maxValue,const char* valueName)
{
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clampping to "<<maxValue<<"."<<endl;
value = maxValue;
}
}
/** if array element value[i] is between or equal to minValue and maxValue do nothing - legal value,
* otherise clamp value to specified to range and return warning
* with valueName specifying which variable was clamped. Equivilant to
* calling clampGEQUAL(value,minValue,valueName); clampLEQUAL(value,maxValue,valueName); */
template <class A, class T>
inline void clampArrayElementBetweenRange(A& value,const unsigned int i,const T minValue,const T maxValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clampping to "<<minValue<<"."<<endl;
value[i] = minValue;
}
else
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clampping to "<<maxValue<<"."<<endl;
value[i] = maxValue;
}
}
/** if array elements are greater than or equal to minValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArrayElementsGEQUAL(A& value,const unsigned int first,const unsigned int last,const T minValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementGEQUAL(value,i,minValue,valueName);
}
/** if array elements are less than or equal to maxValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArrayElementsLEQUAL(A& value,const unsigned int first,const unsigned int last,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementLEQUAL(value,i,maxValue,valueName);
}
/** if array elements are between or equal to minValue and maxValue do nothing - legal value,
* otherise clamp value to specified to range and return warning
* with valueName specifying which variable was clamped. Equivilant to
* calling clampGEQUAL(value,minValue,valueName); clampLEQUAL(value,maxValue,valueName); */
template <class A, class T>
inline void clampArrayElementsBetweenRange(A& value,const unsigned int first,const unsigned int last,const T minValue,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementBetweenRange(value,i,minValue,maxValue,valueName);
}
/** if array4 elements are greater than or equal to minValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArray3GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,2u,minValue,valueName);
}
/** if array4 elements are is less than or equal to maxValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArray3LEQUAL(A& value,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,2u,maxValue,valueName);
}
/** if array4 elements are between or equal to minValue and maxValue do nothing - legal value,
* otherise clamp value to specified to range and return warning
* with valueName specifying which variable was clamped. Equivilant to
* calling clampGEQUAL(value,minValue,valueName); clampLEQUAL(value,maxValue,valueName); */
template <class A, class T>
inline void clampArray3BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,2u,minValue,maxValue,valueName);
}
/** if array4 elements are greater than or equal to minValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArray4GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,3u,minValue,valueName);
}
/** if array4 elements are is less than or equal to maxValue do nothing - legal value,
* otherise clamp value to specified maximum value and return warning
* with valueName specifying which variable was clamped.*/
template <class A, class T>
inline void clampArray4LEQUAL(A& value,const unsigned int first,const unsigned int last,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,3u,maxValue,valueName);
}
/** if array4 elements are between or equal to minValue and maxValue do nothing - legal value,
* otherise clamp value to specified to range and return warning
* with valueName specifying which variable was clamped. Equivilant to
* calling clampGEQUAL(value,minValue,valueName); clampLEQUAL(value,maxValue,valueName); */
template <class A, class T>
inline void clampArray4BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,3u,minValue,maxValue,valueName);
}
};
#endif

72
include/osg/ClipPlane Normal file
View File

@@ -0,0 +1,72 @@
#ifndef OSG_CLIPPLANE
#define OSG_CLIPPLANE 1
#include <osg/Plane>
#include <osg/StateAttribute>
#include <osg/StateSet>
namespace osg {
/** ClipPlane state class which encapsulates OpenGL glClipPlane() functionality.*/
class SG_EXPORT ClipPlane : public StateAttribute
{
public :
ClipPlane();
/** return a shallow copy of a node, with Object* return type.*/
virtual Object* clone() const { return new ClipPlane(); }
/** return true if this and obj are of the same kind of object.*/
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ClipPlane*>(obj)!=NULL; }
/** return the name of the node's class type.*/
virtual const char* className() const { return "ClipPlane"; }
virtual const Type getType() const { return (Type)(CLIPPLANE+_clipPlaneNum); }
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
{
ds.setMode((GLMode)(GL_CLIP_PLANE0+_clipPlaneNum),value);
}
/** Set the clip plane, using a Vec4 to define plane. */
void setClipPlane(const Vec4& plane);
/** Set the clip plane, using a Plane to define plane. */
void setClipPlane(const Plane& plane);
/** Set the clip plane, using a double[4] to define plane. */
void setClipPlane(const double* plane);
/** Get the clip plane, values entered into a Vec4 passed to the getClipPlane. */
void getClipPlane(Vec4& plane) const;
/** Get the clip plane, values entered into a Plane passed to the getClipPlane. */
void getClipPlane(Plane& plane) const;
/** Get the clip plane, values entered into a double[4] passed to the getClipPlane. */
void getClipPlane(double* plane) const;
/** Set the clip plane number. */
void setClipPlaneNum(const unsigned int num);
/** Get the clip plane number. */
const unsigned int getClipPlaneNum() const;
/** Apply the clip plane's state to the OpenGL state machine. */
virtual void apply(State& state) const;
protected :
virtual ~ClipPlane();
double* _clipPlane;
unsigned int _clipPlaneNum;
};
};
#endif

177
include/osg/ClippingVolume Normal file
View File

@@ -0,0 +1,177 @@
#ifndef OSG_CLIPPINGVOLUME
#define OSG_CLIPPINGVOLUME 1
#include <osg/Plane>
#include <vector>
namespace osg {
/** A ClippingVolume class for represecting convex clipping volumes made up.*/
class SG_EXPORT ClippingVolume
{
public:
typedef std::vector<osg::Plane> PlaneList;
inline ClippingVolume() {setupMask();}
inline ClippingVolume(const ClippingVolume& cv) : _localMask(cv._localMask), _planeList(cv._planeList) {}
inline ClippingVolume(const PlaneList& pl) : _planeList(pl) {setupMask();}
inline ~ClippingVolume() {}
inline void clear() { _planeList.clear(); setupMask(); }
inline ClippingVolume& operator = (const ClippingVolume& cv)
{
if (&cv==this) return *this;
_localMask = cv._localMask;
_planeList = cv._planeList;
return *this;
}
inline void set(const ClippingVolume& cs) { _planeList = cs._planeList; setupMask(); }
inline void set(const PlaneList& pl) { _planeList = pl; setupMask(); }
inline void add(const osg::Plane& pl) { _planeList.push_back(pl); setupMask(); }
inline PlaneList& getPlaneList() { return _planeList; }
inline const PlaneList& getPlaneList() const { return _planeList; }
inline void setupMask()
{
_localMask = 0;
for(unsigned int i=0;i<_planeList.size();++i)
{
_localMask = (_localMask<<1) | 1;
}
}
/** Check whether a vertex is contained with clipping set.*/
inline const bool contains(const osg::Vec3& v) const
{
for(PlaneList::const_iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
if (itr->distance(v)<0.0f) return false;
}
return true;
}
/** Check whether any part of a bounding sphere is contained within clipping set.
Using a mask to determine which planes should be used for the check, and
modifying the mask to turn off planes which wouldn't contribute to clipping
of any internal objects. This feature is used in osgUtil::CullVisitor
to prevent redundent plane checking.*/
inline const bool contains(const osg::BoundingSphere& bs,unsigned int& mask) const
{
if (!(mask & _localMask)) return true;
unsigned int selector_mask = 0x1;
for(PlaneList::const_iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
if (mask&selector_mask)
{
int res=itr->intersect(bs);
if (res<0) return false; // outside clipping set.
else if (res>0) mask ^= selector_mask; // subsequent checks against this plane not required.
}
selector_mask <<= 1;
}
return true;
}
/** Check whether any part of a bounding sphere is contained within clipping set.*/
inline const bool contains(const osg::BoundingSphere& bs) const
{
for(PlaneList::const_iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
if (itr->intersect(bs)<0) return false; // outside clipping set.
}
return true;
}
/** Check whether any part of a bounding box is contained within clipping set.
Using a mask to determine which planes should be used for the check, and
modifying the mask to turn off planes which wouldn't contribute to clipping
of any internal objects. This feature is used in osgUtil::CullVisitor
to prevent redundent plane checking.*/
inline const bool contains(const osg::BoundingBox& bb,unsigned int& mask) const
{
if (!(mask & _localMask)) return true;
unsigned int selector_mask = 0x1;
for(PlaneList::const_iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
if (mask&selector_mask)
{
int res=itr->intersect(bb);
if (res<0) return false; // outside clipping set.
else if (res>0) mask ^= selector_mask; // subsequent checks against this plane not required.
}
selector_mask <<= 1;
}
return true;
}
/** Check whether any part of a bounding box is contained within clipping set.*/
inline const bool contains(const osg::BoundingBox& bb) const
{
for(PlaneList::const_iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
if (itr->intersect(bb)<0) return false; // outside clipping set.
}
return true;
}
/** Transform the clipping set by matrix. Note, this operations carries out
* the calculation of the inverse of the matrix since to transforms
* planes must be multiplied my the inverse transposed. This
* make this operation expensive. If the inverse has been already
* calculated elsewhere then use transformProvidingInverse() instead.
* See http://www.worldserver.com/turk/computergraphics/NormalTransformations.pdf*/
inline void transform(const osg::Matrix& matrix)
{
osg::Matrix inverse;
inverse.invert(matrix);
transformProvidingInverse(inverse);
}
/** Transform the clipping set by provide a pre inverted matrix.
* see transform for details. */
inline void transformProvidingInverse(const osg::Matrix& matrix)
{
for(PlaneList::iterator itr=_planeList.begin();
itr!=_planeList.end();
++itr)
{
itr->transformProvidingInverse(matrix);
}
}
protected:
unsigned int _localMask;
PlaneList _planeList;
};
}; // end of namespace
#endif

56
include/osg/ColorMask Normal file
View File

@@ -0,0 +1,56 @@
#ifndef OSG_COLORMASK
#define OSG_COLORMASK 1
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Types>
namespace osg {
/** Encapsulte OpenGL glColorMaskFunc/Op/Mask functions.
*/
class SG_EXPORT ColorMask : public StateAttribute
{
public :
ColorMask();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ColorMask*>(obj)!=0L; }
virtual Object* clone() const { return new ColorMask(); }
virtual const char* className() const { return "ColorMask"; }
virtual const Type getType() const { return COLORMASK; }
inline void setMask(bool red,bool green,bool blue,bool alpha)
{
_red = red;
_green = green;
_blue = blue;
_alpha = alpha;
}
inline const bool getRedMask() const { return _red; }
inline const bool getGreenMask() const { return _green; }
inline const bool getBlueMask() const { return _blue; }
inline const bool getAlphaMask() const { return _alpha; }
virtual void apply(State& state) const;
protected:
virtual ~ColorMask();
bool _red;
bool _green;
bool _blue;
bool _alpha;
};
};
#endif

75
include/osg/Depth Normal file
View File

@@ -0,0 +1,75 @@
#ifndef OSG_DEPTH
#define OSG_DEPTH 1
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Types>
namespace osg {
/** Encapsulte OpenGL glDepthFunc/Mask/Range functions.
*/
class SG_EXPORT Depth : public StateAttribute
{
public :
Depth();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Depth*>(obj)!=0L; }
virtual Object* clone() const { return new Depth(); }
virtual const char* className() const { return "Depth"; }
virtual const Type getType() const { return DEPTH; }
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
{
ds.setMode(GL_DEPTH_TEST,value);
}
enum Function
{
NEVER = GL_NEVER,
LESS = GL_LESS,
EQUAL = GL_EQUAL,
LEQUAL = GL_LEQUAL,
GREATER = GL_GREATER,
NOTEQUAL = GL_NOTEQUAL,
GEQUAL = GL_GEQUAL,
ALWAYS = GL_ALWAYS
};
inline void setFunction(const Function func) { _func = func; }
inline const Function getFunction() const { return _func; }
inline void setWriteMask(const bool mask) { _depthWriteMask = mask; }
inline const bool getWriteMask() const { return _depthWriteMask; }
inline void setRange(const double zNear, const double zFar)
{
_zNear = zNear;
_zFar = zFar;
}
inline const double getZNear() const { return _zNear; }
inline const double getZFar() const { return _zFar; }
virtual void apply(State& state) const;
protected:
virtual ~Depth();
Function _func;
bool _depthWriteMask;
double _zNear;
double _zFar;
};
};
#endif

174
include/osg/Drawable Normal file
View File

@@ -0,0 +1,174 @@
#ifndef OSG_DRAWABLE
#define OSG_DRAWABLE 1
#include <osg/BoundingBox>
#include <osg/StateSet>
#include <osg/State>
#include <osg/Types>
#include <vector>
#include <map>
#include <set>
namespace osg {
/** Pure virtual base class for drawable Geomtery. Contains no drawing primitives
directly, these are provided by subclasses such as GeoSet. State attributes
for a Drawable are maintained in StateSet which the Drawable maintains
a referenced counted pointer to. Both Drawable's and StateSet's can
be shared for optimal memory usage and graphics performance.
*/
class SG_EXPORT Drawable : public Object
{
public:
Drawable();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Drawable*>(obj)!=NULL; }
virtual const char* className() const { return "Drawable"; }
/** Set the StateSet attached to the Drawable.
Previously attached StateSet are automatically unreferenced on
assignment of a new drawstate.*/
inline void setStateSet(StateSet *state) { _dstate = state; }
/** Get the attached StateSet.*/
inline StateSet* getStateSet() { return _dstate.get();}
/** Get the attached const StateSet.*/
inline const StateSet* getStateSet() const { return _dstate.get();}
/** Set the drawable to it can or cannot be used inconjunction with OpenGL
* display lists. With set to true, calls to Drawable::setUseDisplayList,
* whereas when set to false, no display lists can be created and calls
* to setUseDisplayList are ignored, and a warning is produced. The later
* is typically used to guard against the switching on of display lists
* on objects with dynamic internal data such as continuous Level of Detail
* algorithms.*/
void setSupportsDisplayList(const bool flag);
/** Get whether display lists are supportd for this drawable instance.*/
inline const bool getSupportsDisplayList() const { return _supportsDisplayList; }
/** When set to true, force the draw method to use OpenGL Display List for rendering.
If false rendering directly. If the display list has not been already
compile the next call to draw will automatically create the display list.*/
void setUseDisplayList(const bool flag);
/** Return whether OpenGL display lists are being used for rendering.*/
inline const bool getUseDisplayList() const { return _useDisplayList; }
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
void dirtyDisplayList();
inline void dirtyBound() { _bbox_computed = false; }
/** get bounding box of geoset.
* Note, now made virtual to make it possible to implement user-drawn
* objects albeit so what crudely, to be improved later.
*/
inline const BoundingBox& getBound() const
{
if( !_bbox_computed)
computeBound();
return _bbox;
}
/** draw OpenGL primitives.
* If the drawable has _useDisplayList set to true then use an OpenGL display
* list, automatically compiling one if required.
* Otherwise call drawImmediateMode().
* Note, draw method should not be overriden in subclasses as it
* manages the optional display list.
*/
inline void draw(State& state)
{
if (_useDisplayList)
{
// get the contextID (user defined ID of 0 upwards) for the
// current OpenGL context.
uint contextID = state.getContextID();
// fill in array if required.
while (_globjList.size()<=contextID) _globjList.push_back(0);
// get the globj for the current contextID.
uint& globj = _globjList[contextID];
// call the globj if already set otherwise comple and execute.
if( globj != 0 )
{
glCallList( globj );
}
else if (_useDisplayList)
{
globj = glGenLists( 1 );
glNewList( globj, GL_COMPILE_AND_EXECUTE );
drawImmediateMode(state);
glEndList();
}
}
else
{
// draw object as nature intended..
drawImmediateMode(state);
}
}
/** Immediately compile this drawable into an OpenGL Display List.
Note, operation is ignored if _useDisplayList to false.*/
void compile(State& state);
/** draw directly ignoring an OpenGL display list which could be attached.
* This is the internal draw method which does the drawing itself,
* and is the method to override when deriving from Drawable.
*/
virtual void drawImmediateMode(State& state) = 0;
/** use deleteDisplayList instead of glDeleteList to allow
* OpenGL display list to cached until they can be deleted
* by the OpenGL context in which they were created, specified
* by contextID.*/
static void deleteDisplayList(uint contextID,uint globj);
/** flush all the cached display list which need to be deleted
* in the OpenGL context related to contextID.*/
static void flushDeletedDisplayLists(uint contextID);
protected:
Drawable(const Drawable&):Object() {}
Drawable& operator = (const Drawable&) { return *this;}
virtual ~Drawable();
/** compute the bounding box of the drawable. Method must be
implementated by subclasses.*/
virtual const bool computeBound() const = 0;
ref_ptr<StateSet> _dstate;
bool _supportsDisplayList;
bool _useDisplayList;
typedef std::vector<uint> GLObjectList;
mutable GLObjectList _globjList;
mutable BoundingBox _bbox;
mutable bool _bbox_computed;
// static cache of deleted display lists which can only
// by completely deleted once the appropriate OpenGL context
// is set.
typedef std::map<uint,std::set<uint> > DeletedDisplayListCache;
static DeletedDisplayListCache s_deletedDisplayListCache;
};
};
#endif

42
include/osg/FrontFace Normal file
View File

@@ -0,0 +1,42 @@
#ifndef OSG_FRONTFACE
#define OSG_FRONTFACE 1
#include <osg/StateAttribute>
#include <osg/GL>
namespace osg {
/** Class to specifies the orientation of front-facing polygons.
*/
class SG_EXPORT FrontFace : public StateAttribute
{
public :
FrontFace();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const FrontFace*>(obj)!=0L; }
virtual Object* clone() const { return new FrontFace(); }
virtual const char* className() const { return "FrontFace"; }
virtual const Type getType() const { return FRONTFACE; }
enum Mode {
CLOCKWISE = GL_CW,
COUNTER_CLOCKWISE = GL_CCW
};
inline void setMode(const Mode mode) { _mode = mode; }
inline const Mode getMode() const { return _mode; }
virtual void apply(State& state) const;
protected:
virtual ~FrontFace();
Mode _mode;
};
};
#endif

21
include/osg/GLExtensions Normal file
View File

@@ -0,0 +1,21 @@
#ifndef OSG_GLEXTENSIONS
#define OSG_GLEXTENSIONS 1
#include <osg/Export>
namespace osg {
/** return true if OpenGL "extension" is supported.
* note: Must only called within a valid OpenGL context,
* undefined behaviour may occur otherwise.
*/
SG_EXPORT extern const bool isGLExtensionSupported(const char *extension);
/** return the address of the specified OpenGL function.
* return NULL if function not supported by OpenGL library.
*/
SG_EXPORT extern void* getGLExtensionFuncPtr(const char *funcName);
};
#endif

100
include/osg/Impostor Normal file
View File

@@ -0,0 +1,100 @@
#ifndef OSG_IMPOSTOR
#define OSG_IMPOSTOR 1
#include <osg/LOD>
#include <osg/ImpostorSprite>
namespace osg {
/** Impostor - is a form of Level Of Detail group node which allows both switching
* between children depending on distance from eye point and image caching.
*
* The principle behind Imposters is that they cache an image of real geometry and then the image is drawn
* in subsequent frames instead of the real geometry. Its a bit like a
* Billboard *but* is updated at runtime and w.r.t view point. By drawing
* just the texture mapped quad you can cut down scene complexity and
* improve performance.
*
* For more details have a look at:
*
* http://grail.cs.washington.edu/projects/hic/
*
* The OSG doesn't implement exactly the same technique as above, but its
* should be a good starting place. The OSG's impostors are much less
* intrusive since you don't need to restructure your whole scene to use
* them.
*
* All you need to do to use Impostors is to set up the visible
* range values for each LOD child of the Impostor, as per osg::LOD,
* and set an Impostor threshold to tell the renderer at what distance
* the Impsotor's image caching should cut in. The osg::CullVisitor
* automatically handles all the setting of pre-rendering stages to
* calculate the required ImpostorSprites (which encapsulates the image
* cache and quad), and updates them as the view point changes. If you
* use osg::SceneView/CullVisitor all the complexity of supporting
* Impostor will be nicely hidden away.
*
* TODO:
* Various improvements are planned for the Impostor-
* 1) Estimation of how many frames an ImpostorSprite will be reused, if
* it won't be used more often than a minimum threshold then do not create
* ImpostorSprite - use the real geometry.
* 2) Sharing of texture memory between ImpostorSprites.
* 3) Simple 3D geometry for ImpostorSprite's rather than Billboarding.
* 4) Shrinking of the ImpostorSprite size to more closely fit the underlying
* geometry.
*/
class SG_EXPORT Impostor : public LOD
{
public :
Impostor();
virtual Object* clone() const { return new Impostor(); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Impostor*>(obj)!=NULL; }
virtual const char* className() const { return "Impostor"; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
typedef std::vector< ref_ptr<ImpostorSprite> > ImpostorSpriteList;
/** Set the Impostor threshold distance.
* For eye points further than this threshold the Imposter is used if appropriate,
* otherwise the LOD children as chosen as per a standard LOD node.*/
inline void setImpostorThreshold(float distance) { _impostorThreshold = distance; }
/** Set the Impostor threshold distance relative to the node's bounding
* sphere's radius.*/
inline void setImpostorThresholdToBound(float ratio=1.0f) { _impostorThreshold = getBound().radius()*ratio; }
/* Get the Impostor threshold disntance.*/
inline const float getImpostorThreshold() const { return _impostorThreshold; }
/* Get the Impostor threshold disntance squared.*/
inline const float getImpostorThreshold2() const { return _impostorThreshold*_impostorThreshold; }
/** Find the ImposterSprite which fits the current eye point best.*/
ImpostorSprite* findBestImpostorSprite(const osg::Vec3& currLocalEyePoint);
/** Add an ImpostorSprite to the Impostor.*/
void addImpostorSprite(ImpostorSprite* is);
/** Get the list of ImpostorSprites attached to this Impostor.*/
inline ImpostorSpriteList& getImpostorSpriteList() { return _impostorSpriteList; }
/** Get a const list of ImpostorSprites attached to this const Impostor.*/
inline const ImpostorSpriteList& getImpostorSpriteList() const { return _impostorSpriteList; }
protected :
virtual ~Impostor() {}
virtual const bool computeBound() const;
ImpostorSpriteList _impostorSpriteList;
float _impostorThreshold;
};
};
#endif

176
include/osg/ImpostorSprite Normal file
View File

@@ -0,0 +1,176 @@
#ifndef OSG_ImpostorSprite
#define OSG_ImpostorSprite 1
#include <osg/Vec2>
#include <osg/BoundingSphere>
#include <osg/Drawable>
#include <osg/Camera>
#include <osg/ImpostorSprite>
namespace osg {
class Texture;
class Impostor;
class ImpostorSpriteManager;
/** An ImposterSprite is a textured quad which is rendered in place a
* 3D geometry. The ImposterSprite is generated by rendering the original
* 3D geometry to a texture as an image cache. The ImpostorSprite is
* automatiacally generatated by the osgUtil::CullVisitor so it not
* necessary to deal with it directly.
*/
class SG_EXPORT ImpostorSprite : public Drawable
{
public:
ImpostorSprite();
virtual Object* clone() 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"; }
/** Set the parent, which must be an Impostor.
* Unlike conventional Drawables, ImpostorSprite's can only ever have
* one parent.
*/
void setParent(Impostor* parent) { _parent = parent; }
/** Get the parent, which is an Impostor. */
Impostor* getParent() { return _parent; }
/** Get the const parent, which is an Impostor. */
const Impostor* getParent() const { return _parent; }
/** Set the eye point for when the ImpsotorSprite was snapped.*/
inline void setStoredLocalEyePoint(const Vec3& v) { _storedLocalEyePoint=v; }
/** Get the eye point for when the ImpsotorSprite was snapped.*/
inline const Vec3& getStoredLocalEyePoint() const { return _storedLocalEyePoint; }
/** Set the frame number for when the ImpostorSprite was last used in rendering.*/
inline void setLastFrameUsed(const int frameNumber) { _lastFrameUsed = frameNumber; }
/** Get the frame number for when the ImpostorSprite was last used in rendering.*/
inline int getLastFrameUsed() const { return _lastFrameUsed; }
/** Get the coordinates of the corners of the quad.
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
*/
inline Vec3* getCoords() { return _coords; }
/** Get the const coordinates of the corners of the quad.
*/
inline const Vec3* getCoords() const { return _coords; }
/** Get the texture coordinates of the corners of the quad.
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
*/
inline Vec2* getTexCoords() { return _texcoords; }
/** Get the const texture coordinates of the corners of the quad.*/
inline const Vec2* getTexCoords() const { return _texcoords; }
/** Get the control coordinates of the corners of the quad.
* The control coordinates are the cornders of the quad projected
* out onto the front face of bounding box which enclosed the impostor
* geometry when it was pre-rendered into the impostor sprite's texture.
* At the point of creation/or update of the impostor sprite the control
* coords will lie ontop of the coorners of the quad in screen space - with a pixel error
* or zero. Once the camera moves relative to the impostor sprite the
* control coords will nolonger lie ontop of the corners of the quad in
* screen space - a pixel error will have accumulated. This pixel error
* can then be used to dertermine whether the impostor needs to be updated.
* Stored in the order, [0] - top_left, [1] - bottom_left, [2] - bottom_right, [3] - top_left.
*/
inline Vec3* getControlCoords() { return _controlcoords; }
/** Get the const control coordinates of the corners of the quad.*/
inline const Vec3* getControlCoords() const { return _controlcoords; }
/** calculate the pixel error value for current camera position and object position.*/
const float calcPixelError(const Camera& camera,const int* viewport,const osg::Matrix* matrix) const;
void setTexture(Texture* tex,int s,int t);
Texture* getTexture() { return _texture; }
const Texture* getTexture() const { return _texture; }
const int s() const { return _s; }
const int t() const { return _t; }
/** draw ImpostorSprite directly. */
virtual void drawImmediateMode(State& state);
protected:
ImpostorSprite(const ImpostorSprite&):Drawable() {}
ImpostorSprite& operator = (const ImpostorSprite&) { return *this;}
virtual ~ImpostorSprite();
virtual const bool computeBound() const;
Impostor* _parent;
friend ImpostorSpriteManager;
// support for a double linked list managed by the
// ImposotorSpriteManager.
ImpostorSpriteManager* _ism;
ImpostorSprite* _previous;
ImpostorSprite* _next;
int _lastFrameUsed;
Vec3 _storedLocalEyePoint;
Vec3 _coords[4];
Vec2 _texcoords[4];
Vec3 _controlcoords[4];
Texture* _texture;
int _s;
int _t;
};
/** Helper class for managing the reuse of ImpostorSprite resources.*/
class SG_EXPORT ImpostorSpriteManager : public Referenced
{
public:
ImpostorSpriteManager();
const bool empty() const { return _first==0; }
ImpostorSprite* first() { return _first; }
ImpostorSprite* last() { return _last; }
void push_back(ImpostorSprite* is);
void remove(ImpostorSprite* is);
ImpostorSprite* createOrReuseImpostorSprite(int s,int t,int frameNumber);
protected:
~ImpostorSpriteManager();
ImpostorSprite* _first;
ImpostorSprite* _last;
};
};
#endif

60
include/osg/LineSegment Normal file
View File

@@ -0,0 +1,60 @@
#ifndef OSG_LINESEGMENT
#define OSG_LINESEGMENT 1
#include <osg/Matrix>
#include <osg/BoundingBox>
#include <osg/BoundingSphere>
namespace osg {
/** LineSegmentment class for representing a line segment.*/
class SG_EXPORT LineSegment : public Referenced
{
public:
LineSegment() {};
LineSegment(const LineSegment& seg) : Referenced(),_s(seg._s),_e(seg._e) {}
LineSegment(const Vec3& s,const Vec3& e) : _s(s),_e(e) {}
virtual ~LineSegment() {}
LineSegment& operator = (const LineSegment& seg) { _s = seg._s; _e = seg._e; return *this; }
inline void set(const Vec3& s,const Vec3& e) { _s=s; _e=e; }
inline Vec3& start() { return _s; }
inline const Vec3& start() const { return _s; }
inline Vec3& end() { return _e; }
inline const Vec3& end() const { return _e; }
/** return true if segment intersects BoundingBox.*/
const bool intersect(const BoundingBox& bb) const;
/** return true if segment intersects BoundingSphere and return the intersection ratio's.*/
const bool intersect(const BoundingBox& bb,float& r1,float& r2) const;
/** return true if segment intersects BoundingSphere.*/
const bool intersect(const BoundingSphere& bs) const;
/** return true if segment intersects BoundingSphere and return the intersection ratio's.*/
const bool intersect(const BoundingSphere& bs,float& r1,float& r2) const;
/** return true if segment intersects triangle and set ratio long segment. */
const bool intersect(const Vec3& v1,const Vec3& v2,const Vec3& v3,float& r);
/** post multiply a segment by matrix.*/
inline void mult(const LineSegment& seg,const Matrix& m) { _s = seg._s*m; _e = seg._e*m; }
/** pre multiply a segment by matrix.*/
inline void mult(const Matrix& m,const LineSegment& seg) { _s = m*seg._s; _e = m*seg._e; }
protected:
static const bool intersectAndClip(Vec3& s,Vec3& e,const BoundingBox& bb);
Vec3 _s;
Vec3 _e;
};
};
#endif

37
include/osg/MemoryAdapter Normal file
View File

@@ -0,0 +1,37 @@
#ifndef OSG_MEMORYADAPTER
#define OSG_MEMORYADAPTER 1
#include <osg/Referenced>
namespace osg {
/** Class for adapting the memory management of external data.
* Typically used to specify the memory management of user data
* which can be attached to osg::Node.
*/
class SG_EXPORT MemoryAdapter : public Referenced
{
public:
MemoryAdapter() {}
/** Increment the reference count of the userData.*/
virtual void ref_data(void* /*userData*/) = 0;
/** Decrement the reference count of the userData.
Is usually implemented such that if reference count
is decremented to zero the userData should be
deleted. However, this is entirely up to the
discression of the user who is extending this base class.*/
virtual void unref_data(void* /*userData*/) = 0;
/** not current used, but will be used in future.*/
virtual void* clone_data(void* /*userData*/) { return 0L; }
protected:
virtual ~MemoryAdapter() {}
};
};
#endif

165
include/osg/Plane Normal file
View File

@@ -0,0 +1,165 @@
#ifndef OSG_PLANE
#define OSG_PLANE 1
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Matrix>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
namespace osg {
/** A plane class. It can be used to represent an infinite plane.*/
class SG_EXPORT Plane
{
public:
inline Plane():_fv(0.0f,0.0f,0.0f,0.0f) { _lowerBBCorner = 0; _upperBBCorner = 0; }
inline Plane(const Plane& pl):_fv(pl._fv) { calculateUpperLowerBBCorners(); }
inline Plane(const float a,const float b,const float c,const float d):_fv(a,b,c,d) { calculateUpperLowerBBCorners(); }
inline Plane(const Vec4& vec):_fv(vec) { calculateUpperLowerBBCorners(); }
inline Plane(const Vec3& norm,const float d):_fv(norm[0],norm[1],norm[2],d) { calculateUpperLowerBBCorners(); }
inline Plane(const Vec3& v1, const Vec3& v2, const Vec3& v3) { set(v1,v2,v3); calculateUpperLowerBBCorners(); }
inline Plane& operator = (const Plane& pl)
{
if (&pl==this) return *this;
_fv = pl._fv;
_lowerBBCorner = pl._lowerBBCorner;
_upperBBCorner = pl._upperBBCorner;
return *this;
}
inline void set(const Plane& pl) { _fv = pl._fv; calculateUpperLowerBBCorners(); }
inline void set(const float a,const float b,const float c,const float d) { _fv.set(a,b,c,d); calculateUpperLowerBBCorners(); }
inline void set(const Vec4& vec) { _fv = vec; calculateUpperLowerBBCorners(); }
inline void set(const Vec3& norm,const float d) { _fv.set(norm[0],norm[1],norm[2],d); calculateUpperLowerBBCorners(); }
inline void set(const Vec3& v1, const Vec3& v2, const Vec3& v3)
{
osg::Vec3 norm = (v2-v1)^(v3-v2);
float length = norm.length();
if (length>1e-6) norm/= length;
else norm.set(0.0f,0.0f,0.0f);
_fv.set(norm[0],norm[1],norm[2],-(v1*norm));
calculateUpperLowerBBCorners();
}
inline void makeUnitLength()
{
float length = sqrtf(_fv[0]*_fv[0] + _fv[1]*_fv[1]+ _fv[2]*_fv[2]);
_fv /= length;
}
/** calculate the upper and lower bounding box corners to be used
* in the intersect(BoundingBox&) method for speeding calculations.*/
inline void calculateUpperLowerBBCorners()
{
_upperBBCorner = (_fv.x()>=0.0f?1:0) |
(_fv.y()>=0.0f?2:0) |
(_fv.z()>=0.0f?4:0);
_lowerBBCorner = (~_upperBBCorner)&7;
}
inline const bool valid() const { return _fv[0]==0.0f && _fv[1]==0.0f && _fv[2]==0.0f; }
inline Vec4& asVec4() { return _fv; }
inline const Vec4& asVec4() const { return _fv; }
inline float& operator [] (const int i) { return _fv[i]; }
inline float operator [] (const int i) const { return _fv[i]; }
/** calculate the distance between a point and the plane.*/
inline const float distance(const osg::Vec3& v) const
{
return _fv[0]*v.x()+
_fv[1]*v.y()+
_fv[2]*v.z()+
_fv[3];
}
/** interesection test between plane and bounding sphere.
return 1 if the bs is completely above plane,
return 0 if the bs intersects the plane,
return -1 if the bs is completely below the plane.*/
inline const int intersect(const BoundingSphere& bs) const
{
float d = distance(bs.center());
if (d>bs.radius()) return 1;
else if (d<-bs.radius()) return -1;
else return 0;
}
/** interesection test between plane and bounding sphere.
return 1 if the bs is completely above plane,
return 0 if the bs intersects the plane,
return -1 if the bs is completely below the plane.*/
inline const int intersect(const BoundingBox& bb) const
{
// if lowest point above plane than all above.
if (distance(bb.corner(_lowerBBCorner))>0.0f) return 1;
// if highest point is below plane then all below.
if (distance(bb.corner(_upperBBCorner))<0.0f) return -1;
// d_lower<=0.0f && d_upper>=0.0f
// therefore must be crossing plane.
return 0;
}
/** Transform the plane by matrix. Note, this operations carries out
* the calculation of the inverse of the matrix since to transforms
* planes must be multiplied my the inverse transposed. This
* make this operation expensive. If the inverse has been already
* calculated elsewhere then use transformProvidingInverse() instead.
* See http://www.worldserver.com/turk/computergraphics/NormalTransformations.pdf*/
inline void transform(const osg::Matrix& matrix)
{
osg::Matrix inverse;
inverse.invert(matrix);
transformProvidingInverse(inverse);
}
/** Transform the plane by provide a pre inverted matrix.
* see transform for details. */
inline void transformProvidingInverse(const osg::Matrix& matrix)
{
// note pre multiplications, which effectively transposes matrix.
_fv = matrix * _fv;
makeUnitLength();
calculateUpperLowerBBCorners();
}
friend inline ostream& operator << (ostream& output, const Plane& pl);
protected:
Vec4 _fv;
// variables cached to optimize calcs against bounding boxes.
unsigned int _upperBBCorner;
unsigned int _lowerBBCorner;
};
inline ostream& operator << (ostream& output, const Plane& pl)
{
output << pl._fv[0] << " "
<< pl._fv[1] << " "
<< pl._fv[2] << " "
<< pl._fv[3];
return output; // to enable cascading
}
}; // end of namespace
#endif

54
include/osg/PolygonMode Normal file
View File

@@ -0,0 +1,54 @@
#ifndef OSG_POLYGONMODE
#define OSG_POLYGONMODE 1
#include <osg/StateAttribute>
#include <osg/GL>
namespace osg {
/** Class to for setting OpenGL's polygon culling mode.
*/
class SG_EXPORT PolygonMode : public StateAttribute
{
public :
PolygonMode();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const PolygonMode*>(obj)!=0L; }
virtual Object* clone() const { return new PolygonMode(); }
virtual const char* className() const { return "PolygonMode"; }
virtual const Type getType() const { return POLYGONMODE; }
enum Face {
FRONT,
BACK,
FRONT_AND_BACK
};
enum Mode {
POINT = GL_POINT,
LINE = GL_LINE,
FILL = GL_FILL
};
void setMode(const Face face,const Mode mode);
const Mode getMode(const Face face) const;
inline const bool getFrontAndBack() const { return _frontAndBack; }
virtual void apply(State& state) const;
protected:
virtual ~PolygonMode();
bool _frontAndBack;
Mode _modeFront;
Mode _modeBack;
};
};
#endif

132
include/osg/StateAttribute Normal file
View File

@@ -0,0 +1,132 @@
#ifndef OSG_STATEATTRIBUTE
#define OSG_STATEATTRIBUTE 1
#include <osg/Object>
#include <osg/GL>
namespace osg {
// forward declare State & StateSet
class State;
class StateSet;
/** Base class for state attribues.
*/
class SG_EXPORT StateAttribute : public Object
{
public :
/** GLMode is the value used in glEnable/glDisable(mode) */
typedef GLenum GLMode;
/** GLModeValue is used to specified whether an mode is enabled (ON) or disabled (OFF).
* GLMoveValue is also used to speficy the override behavior of modes from parent to children.
* See enum Value description for more details.*/
typedef unsigned int GLModeValue;
/** Override is used to specified the override behavior of StateAttributes
* from from parent to children.
* See enum Value description for more details.*/
typedef unsigned int OverrideValue;
/** list values which can be used in to set either GLModeValues
* or OverrideValues. When using in conjection with GLModeValues
* all Values have meaning. When using in conjection with
* StateAttribute OverrideValue only OFF,OVERRIDE and INHERIT
* are meaningful. However, they are useful when using GLModeValue
* and OverrideValue in conjunction with each other as when using
* StateSet::setAttributeAndModes(..).*/
enum Values
{
/** means that associated GLMode and Override is disabled.*/
OFF = 0x0,
/** means that associated GLMode is enabled and Override is disabled.*/
ON = 0x1,
/** Overriding of GLMode's or StateAttributes is enabled.*/
OVERRIDE = 0x2,
/** means that associated GLMode is disabled and Override is enabled.*/
OVERRIDE_OFF = 0x2,
/** means that associated GLMode and Override is enabled.*/
OVERRIDE_ON = 0x3,
/** means that GLMode or StateAttribute should in inherited from above.*/
INHERIT = 0x4
};
/** Values of StateAttribute::Type used to aid identification
* of diffenent StateAttribute subclasses. Each subclass defines
* it own value in the virtual Type getType() method. When
* extending the osg's StateAttribute's simply define your
* own Type value which is unique, using the StateAttribute::Type
* enum as a guide of what values to use. If your new subclass
* needs to override a standard StateAttriubte then simple use
* that types value. */
enum Type
{
ALPHAFUNC =1,
ANTIALIAS =2,
COLORTABLE =3,
CULLFACE =4,
FOG =5,
FRONTFACE =6,
LIGHTING =7,
MATERIAL =8,
POINT =9,
POLYGONMODE =10,
POLYGONOFFSET =11,
TEXENV =12,
TEXGEN =13,
TEXMAT =14,
TEXTURE =15,
TEXTURE_0 =TEXTURE+0,
TEXTURE_1 =TEXTURE+1,
TEXTURE_2 =TEXTURE+2,
TEXTURE_3 =TEXTURE+3,
TRANSPARENCY =19,
STENCIL =20,
COLORMASK =21,
CLIPPLANE =23,
CLIPPLANE_0 =CLIPPLANE+0,
CLIPPLANE_1 =CLIPPLANE+1,
CLIPPLANE_2 =CLIPPLANE+2,
CLIPPLANE_3 =CLIPPLANE+3,
CLIPPLANE_4 =CLIPPLANE+4,
CLIPPLANE_5 =CLIPPLANE+5,
DEPTH =29
};
StateAttribute() {}
/** return a shallow copy of a node, with Object* return type.*/
virtual Object* clone() 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; }
/** return the name of the attribute's class type.*/
virtual const char* className() const { return "StateAttribute"; }
/** return the Type idenitifer of the attribute's class type.*/
virtual const Type getType() const = 0;
virtual void setStateSetModes(StateSet&,const GLModeValue) const
{
// default to no GLMode's assocated with use of the StateAttribute.
}
/** apply the OpenGL state attributes.
* The global state for the current OpenGL context is passed
* in to allow the StateAttribute to obtain details on the
* the current context and state.
*/
virtual void apply(State&) const = 0 ;
/** default to nothing to compile - all state is applied immediately. */
virtual void compile(State&) const {};
protected:
virtual ~StateAttribute() {}
};
};
#endif

171
include/osg/StateSet Normal file
View File

@@ -0,0 +1,171 @@
#ifndef OSG_STATESET
#define OSG_STATESET 1
#include <osg/Object>
#include <osg/StateAttribute>
#include <osg/ref_ptr>
#include <map>
#include <vector>
#include <string>
namespace osg {
/**
Encapsulates OpenGL state modes and attributes.
Used to specificy textures etc of osg::Drawable's which hold references
to a single osg::StateSet. StateSet can be shared between Drawable's
and is recommend if possible as it minimize expensive state changes
in the graphics pipeline.
*/
class SG_EXPORT StateSet : public Object
{
public :
StateSet();
virtual Object* clone() const { return new StateSet(); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
virtual const char* className() const { return "StateSet"; }
/** set all the modes to on or off so that it defines a
complete state, typically used for a default global state.*/
void setGlobalDefaults();
/** set all the modes to inherit, typically used to signifiy
nodes which inherit all of their modes for the global state.*/
void setAllToInherit();
/** a container to map GLModes to their respective GLModeValues.*/
typedef std::map<StateAttribute::GLMode,StateAttribute::GLModeValue> ModeList;
/** set this StateSet to contain specified GLMode and value.*/
void setMode(const StateAttribute::GLMode mode, const StateAttribute::GLModeValue value);
/** set this StateSet to inherit specified GLMode type from parents.
* has the effect of deleting any GlMode of specified type from StateSet.*/
void setModeToInherit(const StateAttribute::GLMode mode);
/** get specified GLModeValue for specified GLMode.
* returns INHERIT if no GLModeValue is contained within StateSet.*/
const StateAttribute::GLModeValue getMode(const StateAttribute::GLMode mode) const;
/** return the list of all GLModes contained in this StateSet.*/
inline ModeList& getModeList() { return _modeList; }
/** return the const list of all GLModes contained in this const StateSet.*/
inline const ModeList& getModeList() const { return _modeList; }
/** simple pairing between an attribute and its override flag.*/
typedef std::pair<ref_ptr<StateAttribute>,StateAttribute::OverrideValue> RefAttributePair;
/** a container to map StateAttribyte::Types to their respective RefAttributePair.*/
typedef std::map<StateAttribute::Type,RefAttributePair> AttributeList;
/** set this StateSet to contain specified attribute and override flag.*/
void setAttribute(StateAttribute *attribute, const StateAttribute::OverrideValue value=StateAttribute::OFF);
/** set this StateSet to contain specified attribute and set the associated GLMode's to specifed value.*/
void setAttributeAndModes(StateAttribute *attribute, const StateAttribute::GLModeValue value=StateAttribute::ON);
/** set this StateSet to inherit specified attribute type from parents.
* has the effect of deleting any state attributes of specified type from StateSet.*/
void setAttributeToInherit(const StateAttribute::Type type);
/** get specified StateAttribute for specified type.
* returns NULL if no type is contained within StateSet.*/
const StateAttribute* getAttribute(const StateAttribute::Type type) const;
/** get specified RefAttributePair for specified type.
* returns NULL if no type is contained within StateSet.*/
const RefAttributePair* getAttributePair(const StateAttribute::Type type) const;
/** return the list of all StateAttributes contained in this StateSet.*/
inline AttributeList& getAttributeList() { return _attributeList; }
/** return the const list of all StateAttributes contained in this const StateSet.*/
inline const AttributeList& getAttributeList() const { return _attributeList; }
/** tempory type def to support tempory method getModeVector.*/
typedef std::vector<std::pair<StateAttribute::GLMode,StateAttribute::GLModeValue> > ModeVector;
/** get method which copies this StateSet's osg::GLModeValues's into
* a std::vector. method is overlaps on the propper get method -
* getModeList and only exists to get round a crash under Windows.
* Will be removed once problem is fixed.*/
const ModeVector getModeVector() const;
/** tempory type def to support tempory method getAttributeVector.*/
typedef std::vector<const StateAttribute*> AttributeVector;
/** get method which copies this StateSet's osg::StateAttribute's into
* a std::vector. method is overlaps on the propper get method -
* getAttributeList and only exists to get round a crash under Windows.
* Will be removed once problem is fixed.*/
const AttributeVector getAttributeVector() const;
enum RenderingHint
{
DEFAULT_BIN = 0,
OPAQUE_BIN = 1,
TRANSPARENT_BIN = 2
};
/** set the RenderingHint of the StateSet.
* RenderingHint is used by osgUtil::Renderer to determine which
* draw bin to drop associated osg::Drawables in. For opaque
* objects OPAQUE_BIN would typical used, which TRANSPARENT_BIN
* should be used for objects which need to be depth sorted.*/
void setRenderingHint(const int hint);
/** get the RenderingHint of the StateSet.*/
inline const int getRenderingHint() const { return _renderingHint; }
enum RenderBinMode
{
INHERIT_RENDERBIN_DETAILS,
USE_RENDERBIN_DETAILS,
OVERRIDE_RENDERBIN_DETAILS,
ENCLOSE_RENDERBIN_DETAILS
};
/** set the render bin details.*/
void setRenderBinDetails(const int binNum,const std::string& binName,const RenderBinMode mode=USE_RENDERBIN_DETAILS);
/** set the render bin details to inherit.*/
void setRendingBinToInherit();
/** get the render bin mode.*/
inline const RenderBinMode getRenderBinMode() const { return _binMode; }
/** get whether the render bin details are set and should be used.*/
inline const bool useRenderBinDetails() const { return _binMode!=INHERIT_RENDERBIN_DETAILS; }
/** get the render bin number.*/
inline const int getBinNumber() const { return _binNum; }
/** get the render bin name.*/
inline const std::string& getBinName() const { return _binName; }
/** call compile on all StateAttributes contained within this StateSet.*/
void compile(State& state) const;
protected :
virtual ~StateSet();
StateSet(const StateSet&):Object() {}
StateSet& operator = (const StateSet&) { return *this; }
ModeList _modeList;
AttributeList _attributeList;
int _renderingHint;
RenderBinMode _binMode;
int _binNum;
std::string _binName;
};
};
#endif

114
include/osg/Stencil Normal file
View File

@@ -0,0 +1,114 @@
#ifndef OSG_STENCIL
#define OSG_STENCIL 1
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Types>
namespace osg {
/** Encapsulte OpenGL glStencilFunc/Op/Mask functions.
*/
class SG_EXPORT Stencil : public StateAttribute
{
public :
Stencil();
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Stencil*>(obj)!=0L; }
virtual Object* clone() const { return new Stencil(); }
virtual const char* className() const { return "Stencil"; }
virtual const Type getType() const { return STENCIL; }
virtual void setStateSetModes(StateSet& ds,const GLModeValue value) const
{
ds.setMode(GL_STENCIL_TEST,value);
}
enum Function
{
NEVER = GL_NEVER,
LESS = GL_LESS,
EQUAL = GL_EQUAL,
LEQUAL = GL_LEQUAL,
GREATER = GL_GREATER,
NOTEQUAL = GL_NOTEQUAL,
GEQUAL = GL_GEQUAL,
ALWAYS = GL_ALWAYS
};
inline void setFunction(const Function func,int ref,uint mask)
{
_func = func;
_funcRef = ref;
_funcMask = mask;
}
inline const Function getFunction() const { return _func; }
inline const int getFunctionRef() const { return _funcRef; }
inline const uint getFunctionMask() const { return _funcMask; }
enum Operation
{
KEEP = GL_KEEP,
ZERO = GL_ZERO,
REPLACE = GL_REPLACE,
INCR = GL_INCR,
DECR = GL_DECR,
INVERT = GL_INVERT
};
/** set the operations to apply when the various stencil and depth
* tests fail or pass. First paramater is to control the operation
* when the stencil test fails. The second paramter is to control the
* operatiorn when the stencil test passes, but depth test fails. The
* third parameter controls the operation when both the stencil test
* and depth pass. Ordering of parameter is the same as if using
* glStencilOp(,,).*/
inline void setOperation(const Operation sfail, const Operation zfail, const Operation zpass)
{
_sfail = sfail;
_zfail = zfail;
_zpass = zpass;
}
/** get the operation when the stencil test fails.*/
inline const Operation getStencilFailOperation() const { return _sfail; }
/** get the operation when the stencil test passes but the depth test fails*/
inline const Operation getStencilPassAndDepthFailOperation() const { return _zfail; }
/** get the operation when both the stencil test and the depth test pass*/
inline const Operation getStencilPassAndDepthPassOperation() const { return _zpass; }
inline void setWriteMask(uint mask) { _writeMask = mask; }
inline const uint getWriteMask() const { return _writeMask; }
virtual void apply(State& state) const;
protected:
virtual ~Stencil();
Function _func;
int _funcRef;
uint _funcMask;
Operation _sfail;
Operation _zfail;
Operation _zpass;
uint _writeMask;
};
};
#endif

46
include/osg/Transform Normal file
View File

@@ -0,0 +1,46 @@
#ifndef OSG_TRANSFORM
#define OSG_TRANSFORM 1
#include <osg/Group>
#include <osg/Matrix>
namespace osg {
/** Transform - is group which all children
are transformed by the the Transform's osg::Matrix. Typical uses
of the Transform is for positioning objects within a scene or
producing trakerball functionality or for animatiion.
*/
class SG_EXPORT Transform : public Group
{
public :
Transform();
Transform(const Matrix& matix);
virtual Object* clone() const { return new Transform(); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Transform*>(obj)!=NULL; }
virtual const char* className() const { return "Transform"; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
void setMatrix(const Matrix& mat );
inline Matrix& getMatrix() { return *_matrix; }
inline const Matrix& getMatrix() const { return *_matrix; }
void preMult( const Matrix& mat );
void preScale( const float sx, const float sy, const float sz );
void preTranslate( const float tx, const float ty, const float tz );
void preRotate( const float deg, const float x, const float y, const float z );
protected :
virtual ~Transform();
virtual const bool computeBound() const;
ref_ptr<Matrix> _matrix;
};
};
#endif

202
include/osg/mem_ptr Normal file
View File

@@ -0,0 +1,202 @@
#ifndef OSG_MEM_PTR
#define OSG_MEM_PTR 1
#include <osg/ref_ptr>
#include <osg/MemoryAdapter>
#include <map>
namespace osg {
/** Smart pointer for handling memory pointers via associated memory adapter.*/
template<class T>
class mem_ptr
{
public:
mem_ptr() :_ptr(0L),_ma(0L) {}
mem_ptr(T* t,MemoryAdapter* ma):_ptr(t),_ma(ma)
{
if (_ptr && _ma.valid()) _ma->ref_data(_ptr);
}
mem_ptr(const mem_ptr& rp):_ptr(rp._ptr),_ma(rp._ma)
{
if (_ptr && _ma.valid()) _ma->unref_data(_ptr);
}
~mem_ptr()
{
if (_ptr && _ma.valid()) _ma->ref_data(_ptr);
}
inline mem_ptr& operator = (const mem_ptr& rp)
{
if (_ptr==rp._ptr) return *this;
if (_ptr && _ma.valid()) _ma->unref_data(_ptr);
_ptr = rp._ptr;
_ma = rp._ma;
if (_ptr && _ma.valid()) _ma->ref_data(_ptr);
return *this;
}
inline void set(T* t,MemoryAdapter* ma)
{
if (_ptr==t)
{
if (_ma==ma) return;
if (ma)
{
ma->ref(_ptr);
if (_ma.valid()) _ma->unref_data(_ptr);
}
_ma = ma;
}
else
{
if (_ptr && _ma.valid()) _ma->unref_data(_ptr);
_ptr = t;
_ma = rp._ma;
if (_ptr && _ma.valid()) _ma->ref_data(_ptr);
}
}
inline const bool operator == (const mem_ptr& rp) const
{
return (_ptr==rp._ptr);
}
inline const bool operator == (const T* ptr) const
{
return (_ptr==ptr);
}
inline const bool operator != (const mem_ptr& rp) const
{
return (_ptr!=rp._ptr);
}
inline const bool operator != (const T* ptr) const
{
return (_ptr!=ptr);
}
inline T& operator*() { return *_ptr; }
inline const T& operator*() const { return *_ptr; }
inline T* operator->() { return _ptr; }
inline const T* operator->() const { return _ptr; }
inline const bool operator!() const { return _ptr==0L; }
inline const bool valid() const { return _ptr!=0L; }
inline T* get() { return _ptr; }
inline const T* get() const { return _ptr; }
private:
T* _ptr;
ref_ptr<MemoryAdapter> _ma;
};
// /** Exprimental memory adapter implmentation.*/
// template<class T>
// class CppMemoryAdapter : public MemoryAdapter
// {
// public:
//
// virtual void ref_data(void* userData)
// {
// ++_memoryMap[(T*)userData];
// }
//
// virtual void unref_data(void* userData)
// {
// --_memoryMap[(T*)userData];
// if (_memoryMap[(T*)userData]<=0) delete userData;
// _memoryMap.erase((T*)userData);
// }
//
// protected:
//
// static std::map<T*,int> _memoryMap;
//
// };
//
// /** Exprimental memory adapter implmentation.*/
// class NewMemoryAdapter : public MemoryAdapter
// {
// public:
//
// static MemoryAdapter* instance();
//
// virtual void ref_data(void* userData)
// {
// ++_memoryMap[userData];
// }
//
// virtual void unref_data(void* userData)
// {
// --_memoryMap[userData];
// if (_memoryMap[userData]<=0) delete userData;
// _memoryMap.erase(userData);
// }
//
// protected:
//
// NewMemoryAdapter() {}
// NewMemoryAdapter(NewMemoryAdapter&):MemoryAdapter() {}
// ~NewMemoryAdapter() {}
//
// std::map<void*,int> _memoryMap;
//
// };
//
// /** Exprimental memory adapter implmentation.*/
// template<class T>
// class newMemoryAdapter : public MemoryAdapter
// {
// public:
//
// static newMemoryAdapter<T>* instance()
// {
// static ref_ptr<newMemoryAdapter<T> > s_newMemoryAdapter = new newMemoryAdapter<T>();
// return s_newMemoryAdapter.get();
// }
//
// T* allocate(int no) { cout<<"Allocating Memory"<<endl;return new T[no]; }
//
// virtual void ref_data(void* userData)
// {
// cout<<"Incrementing Memory"<<endl;
// ++_memoryMap[(T*)userData];
// }
//
// virtual void unref_data(void* userData)
// {
// cout<<"Decrementing Memory"<<endl;
// --_memoryMap[(T*)userData];
// if (_memoryMap[(T*)userData]<=0)
// {
// cout<<"Deleting Memory"<<endl;
// delete (T*)userData;
// }
// _memoryMap.erase((T*)userData);
// }
//
// protected:
//
// newMemoryAdapter() {cout<<"*** Constructing nMA"<<endl;}
// newMemoryAdapter(newMemoryAdapter&):MemoryAdapter() {}
// ~newMemoryAdapter() {cout<<"*** Destructing nMA"<<endl;}
//
// std::map<T*,int> _memoryMap;
//
// };
};
#endif

87
include/osg/ref_ptr Normal file
View File

@@ -0,0 +1,87 @@
#ifndef OSG_REF_PTR
#define OSG_REF_PTR 1
namespace osg {
/** Smart pointer for handling referenced counted objects.*/
template<class T>
class ref_ptr
{
public:
ref_ptr() :_ptr(0L) {}
ref_ptr(T* t):_ptr(t) { if (_ptr) _ptr->ref(); }
ref_ptr(const ref_ptr& rp):_ptr(rp._ptr) { if (_ptr) _ptr->ref(); }
~ref_ptr() { if (_ptr) _ptr->unref(); }
inline ref_ptr& operator = (const ref_ptr& rp)
{
if (_ptr==rp._ptr) return *this;
if (_ptr) _ptr->unref();
_ptr = rp._ptr;
if (_ptr) _ptr->ref();
return *this;
}
inline ref_ptr& operator = (T* ptr)
{
if (_ptr==ptr) return *this;
if (_ptr) _ptr->unref();
_ptr = ptr;
if (_ptr) _ptr->ref();
return *this;
}
inline const bool operator == (const ref_ptr& rp) const
{
return (_ptr==rp._ptr);
}
inline const bool operator == (const T* ptr) const
{
return (_ptr==ptr);
}
inline const bool operator != (const ref_ptr& rp) const
{
return (_ptr!=rp._ptr);
}
inline const bool operator != (const T* ptr) const
{
return (_ptr!=ptr);
}
inline const bool operator < (const ref_ptr& rp) const
{
return (_ptr<rp._ptr);
}
inline const bool operator < (const T* ptr) const
{
return (_ptr<ptr);
}
inline T& operator*() { return *_ptr; }
inline const T& operator*() const { return *_ptr; }
inline T* operator->() { return _ptr; }
inline const T* operator->() const { return _ptr; }
inline const bool operator!() const { return _ptr==0L; }
inline const bool valid() const { return _ptr!=0L; }
inline T* get() { return _ptr; }
inline const T* get() const { return _ptr; }
private:
T* _ptr;
};
};
#endif