2001-10-04 23:12:57 +08:00
|
|
|
//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.
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_GEOSET
|
|
|
|
#define OSG_GEOSET 1
|
|
|
|
|
2002-04-14 06:19:29 +08:00
|
|
|
#include <osg/Drawable>
|
2001-01-11 00:32:10 +08:00
|
|
|
#include <osg/Vec2>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** Encapsulates OpenGL drawing primitives, geometry and
|
|
|
|
optional binding of normal, color and texture coordinates. Used
|
|
|
|
for representing the visible objects in the scene. State attributes
|
2001-09-20 05:08:56 +08:00
|
|
|
for a GeoSet are maintained in StateSet which the GeoSet maintains
|
|
|
|
a referenced counted pointer to. Both GeoSet's and StateSet's can
|
2001-01-11 00:32:10 +08:00
|
|
|
be shared for optimal memory usage and graphics performance.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
class SG_EXPORT GeoSet : public Drawable
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2001-12-05 06:57:40 +08:00
|
|
|
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
enum PrimitiveType {
|
|
|
|
NO_TYPE,
|
|
|
|
POINTS,
|
|
|
|
LINES,
|
|
|
|
LINE_STRIP,
|
|
|
|
FLAT_LINE_STRIP,
|
|
|
|
LINE_LOOP,
|
|
|
|
TRIANGLES,
|
|
|
|
TRIANGLE_STRIP,
|
|
|
|
FLAT_TRIANGLE_STRIP,
|
|
|
|
TRIANGLE_FAN,
|
|
|
|
FLAT_TRIANGLE_FAN,
|
|
|
|
QUADS,
|
|
|
|
QUAD_STRIP,
|
|
|
|
POLYGON
|
|
|
|
};
|
|
|
|
|
|
|
|
enum BindingType {
|
|
|
|
BIND_OFF,
|
|
|
|
BIND_OVERALL,
|
|
|
|
BIND_PERPRIM,
|
|
|
|
BIND_PERVERTEX,
|
|
|
|
BIND_DEFAULT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum InterleaveArrayType {
|
|
|
|
IA_OFF,
|
|
|
|
IA_V2F,
|
|
|
|
IA_V3F,
|
|
|
|
IA_C4UB_V2F,
|
|
|
|
IA_C4UB_V3F,
|
|
|
|
IA_C3F_V3F,
|
|
|
|
IA_N3F_V3F,
|
|
|
|
IA_C4F_N3F_V3F,
|
|
|
|
IA_T2F_V3F,
|
|
|
|
IA_T4F_V4F,
|
|
|
|
IA_T2F_C4UB_V3F,
|
|
|
|
IA_T2F_C3F_V3F,
|
|
|
|
IA_T2F_N3F_V3F,
|
|
|
|
IA_T2F_C4F_N3F_V3F,
|
|
|
|
IA_T4F_C4F_N3F_V4F
|
|
|
|
};
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
struct IndexPointer
|
|
|
|
{
|
|
|
|
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable uint _size;
|
2001-09-20 05:08:56 +08:00
|
|
|
bool _is_ushort;
|
|
|
|
union
|
|
|
|
{
|
|
|
|
ushort* _ushort;
|
|
|
|
uint* _uint;
|
|
|
|
} _ptr;
|
|
|
|
|
|
|
|
IndexPointer() { _size=0;_is_ushort=true;_ptr._ushort = (ushort*)0; }
|
|
|
|
|
|
|
|
inline const bool operator == (const IndexPointer& ip) const
|
|
|
|
{
|
|
|
|
return _size == ip._size &&
|
|
|
|
_is_ushort == ip._is_ushort &&
|
|
|
|
_ptr._ushort == ip._ptr._ushort;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const bool valid() const
|
|
|
|
{
|
|
|
|
return _ptr._ushort != (ushort*)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const bool null() const
|
|
|
|
{
|
|
|
|
return _ptr._ushort == (ushort*)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setToNull()
|
|
|
|
{
|
|
|
|
_size = 0;
|
|
|
|
_is_ushort = true;
|
|
|
|
_ptr._ushort = (ushort*)0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set(uint size,ushort* data)
|
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
_is_ushort = true;
|
|
|
|
_ptr._ushort = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set(const uint size,uint* data)
|
|
|
|
{
|
|
|
|
_size = size;
|
|
|
|
_is_ushort = false;
|
|
|
|
_ptr._uint = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const uint maxIndex() const
|
|
|
|
{
|
|
|
|
uint max = 0;
|
|
|
|
if (_is_ushort)
|
|
|
|
{
|
|
|
|
for(uint ai = 0; ai < _size; ai++ )
|
|
|
|
if( _ptr._ushort[ai] > max ) max = _ptr._ushort[ai];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(uint ai = 0; ai < _size; ai++ )
|
|
|
|
if( _ptr._uint[ai] > max ) max = _ptr._uint[ai];
|
|
|
|
}
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const uint operator [] (const uint pos) const
|
|
|
|
{
|
|
|
|
if (_is_ushort) return _ptr._ushort[pos];
|
|
|
|
else return _ptr._uint[pos];
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
GeoSet();
|
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-01-29 22:04:06 +08:00
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
GeoSet(const GeoSet& geoset,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-03-27 07:52:52 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew GeoSet(); }
|
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-03-27 07:52:52 +08:00
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew GeoSet(*this,copyop); }
|
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const GeoSet*>(obj)!=NULL; }
|
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
2002-01-29 05:17:01 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const char* className() const { return "GeoSet"; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
// data access methods.
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setNumPrims( const int n ) { _numprims = n; }
|
|
|
|
inline const int getNumPrims() const { return _numprims; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void setPrimType( const PrimitiveType type );
|
|
|
|
inline const PrimitiveType getPrimType() const { return _primtype; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setPrimLengths( int *lens ) { _primLengths = lens; }
|
|
|
|
inline int *getPrimLengths() { return _primLengths; }
|
|
|
|
inline const int *getPrimLengths() const { return _primLengths; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-10-13 19:16:10 +08:00
|
|
|
void computeNumVerts() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** get the number of coords required by the defined primitives. */
|
2001-10-13 19:16:10 +08:00
|
|
|
inline const int getNumCoords() const
|
2001-10-13 15:24:25 +08:00
|
|
|
{ if( _numcoords == 0 ) computeNumVerts(); return _numcoords; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get a pointer to Vec3 coord array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline Vec3* getCoords() { return _coords; }
|
|
|
|
/** get a const pointer to Vec3 coord array. */
|
|
|
|
inline const Vec3* getCoords() const { return _coords; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the number of indices required by the defined primitives. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumCoordIndices() const { return _cindex._size; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the coord index array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline IndexPointer& getCoordIndices() { return _cindex; }
|
|
|
|
/** get the const coord index array. */
|
|
|
|
inline const IndexPointer& getCoordIndices() const { return _cindex; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the coords (i.e the geometry) of the geoset.*/
|
|
|
|
void setCoords( Vec3 *cp );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** set the coords (i.e the geometry) and ushort indices of the geoset.
|
|
|
|
To reduce memory footprint and bandwidth for small datasets it is
|
2001-09-29 04:10:41 +08:00
|
|
|
recommended the ushort indices are used instead of unit indices.*/
|
2001-01-11 00:32:10 +08:00
|
|
|
void setCoords( Vec3 *cp, ushort *ci );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** set the coords (i.e the geometry) and uint indices of the geoset.
|
|
|
|
Unless your data set exceeds 65536 indices prefer ushort indices
|
2001-09-29 04:10:41 +08:00
|
|
|
over uint indices, only use this unit indices version if necessary.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setCoords( Vec3 *cp, uint *ci );
|
|
|
|
/** set the coords (i.e the geometry) and indices of the geoset.*/
|
|
|
|
void setCoords( Vec3 *cp, IndexPointer& ip );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** get the number of normals required by the defined primitives and normals binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumNormals() const { return _numnormals; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get a pointer to Vec3 normal array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline Vec3* getNormals() { return _normals; }
|
|
|
|
/** get a const pointer to Vec3 normal array. */
|
|
|
|
inline const Vec3* getNormals() const { return _normals; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the number of normal indices required by the defined primitives and normals binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline int getNumNormalIndices() const { return _nindex._size; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the normal index array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline IndexPointer& getNormalIndices() { return _nindex; }
|
|
|
|
/** get the const normal index array. */
|
|
|
|
inline const IndexPointer& getNormalIndices() const { return _nindex; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the normals of the geoset.*/
|
|
|
|
void setNormals( Vec3 *np );
|
|
|
|
/** set the normals and normal indices of the geoset.*/
|
|
|
|
void setNormals( Vec3 *np, ushort *ni );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** set the normals and normal indices of the geoset.*/
|
|
|
|
void setNormals( Vec3 *np, uint *ni );
|
|
|
|
/** set the normals and normal indices of the geoset.*/
|
|
|
|
void setNormals( Vec3 *np, IndexPointer& ip );
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the normals binding to the vertices/primitives/overall.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setNormalBinding( const BindingType binding );
|
|
|
|
inline const BindingType getNormalBinding() const { return _normal_binding; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** get the number of colors required by the defined primitives and color binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumColors() const { return _numcolors; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get a pointer to Vec4 color array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline Vec4* getColors() { return _colors; }
|
|
|
|
/** get a pointer to Vec4 color array. */
|
|
|
|
inline const Vec4* getColors() const { return _colors; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the number of colors indices required by the defined primitives and color binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline int getNumColorIndices() const { return _colindex._size; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the color index array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline IndexPointer& getColorIndices() { return _colindex; }
|
|
|
|
/** get the const color index array. */
|
|
|
|
inline const IndexPointer& getColorIndices() const { return _colindex; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the colors of the geoset.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setColors( Vec4 *cp );
|
|
|
|
/** set the colors and color indices of the geoset.*/
|
|
|
|
void setColors( Vec4 *cp, ushort *li );
|
|
|
|
/** set the colors and color indices of the geoset.*/
|
|
|
|
void setColors( Vec4 *cp, uint *li );
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the colors and color indices of the geoset.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setColors( Vec4 *cp, IndexPointer& ip );
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the color binding to the vertices/primitives/overall.*/
|
2002-03-19 05:56:00 +08:00
|
|
|
void setColorBinding( const BindingType binding );
|
2001-09-20 05:08:56 +08:00
|
|
|
inline BindingType getColorBinding() const { return _color_binding; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumTextureCoords() const { return _numtcoords; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get a pointer to Vec4 color array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline Vec2* getTextureCoords() { return _tcoords; }
|
|
|
|
/** get a pointer to Vec4 color array. */
|
|
|
|
inline const Vec2* getTextureCoords() const { return _tcoords; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int getNumTextureIndices() const { return _tindex._size; }
|
|
|
|
/** get the texture index array. */
|
|
|
|
inline IndexPointer& getTextureIndices() { return _tindex; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** get the texture index array. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const IndexPointer& getTextureIndices() const { return _tindex; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the texture coords of the geoset.*/
|
|
|
|
void setTextureCoords( Vec2 *tc );
|
|
|
|
/** set the texture coords and texture coord indices of the geoset.*/
|
|
|
|
void setTextureCoords( Vec2 *tc, ushort *ti );
|
2001-09-20 05:08:56 +08:00
|
|
|
/** set the texture coords and texture coord indices of the geoset.*/
|
|
|
|
void setTextureCoords( Vec2 *tc, uint *ti );
|
|
|
|
/** set the texture coords and texture indices of the geoset.*/
|
|
|
|
void setTextureCoords( Vec2 *tc, IndexPointer& ip );
|
2001-01-11 00:32:10 +08:00
|
|
|
/** set the texture coord binding to the vertices/primitives/overall.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
void setTextureBinding( const BindingType binding );
|
|
|
|
inline const BindingType getTextureBinding() const { return _texture_binding; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
/** get the number of texture coords required by the defined primitives and textures binding.*/
|
|
|
|
inline const int getNumInterleavedCoords() const { return _numcoords; }
|
|
|
|
/** get a pointer to interleaved float array. */
|
|
|
|
inline void* getInterleavedArray() { return _iarray; }
|
|
|
|
/** get a const pointer to interleaved float array. */
|
|
|
|
inline const void* getInterleavedArray() const { return _iarray; }
|
|
|
|
/** get the number of texture coord indices required by the defined primitives and texture binding.*/
|
2001-10-10 22:38:12 +08:00
|
|
|
inline const int getNumInterleavedIndices() const { return _iaindex._size; }
|
2001-09-20 05:08:56 +08:00
|
|
|
/** get the texture index array. */
|
|
|
|
inline IndexPointer& getInterleavedIndices() { return _iaindex; }
|
|
|
|
/** get the interleaved index array. */
|
|
|
|
inline const IndexPointer& getInterleavedIndices() const { return _iaindex; }
|
|
|
|
/** get the interleaved array storage format. */
|
2001-12-12 20:55:01 +08:00
|
|
|
inline const InterleaveArrayType getInterleavedFormat() const { return _iaformat; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
/** set the interleaved arrays of the geoset.*/
|
|
|
|
void setInterleavedArray( const InterleaveArrayType format, float *ia );
|
|
|
|
void setInterleavedArray( const InterleaveArrayType format, float *ia, ushort *iai );
|
|
|
|
void setInterleavedArray( const InterleaveArrayType format, float *ia, uint *iai );
|
|
|
|
void setInterleavedArray( const InterleaveArrayType format, float *ia, IndexPointer& iai );
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** draw geoset 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 GeoSet for user-drawn objects.
|
|
|
|
*/
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual void drawImmediateMode(State& state);
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
const bool check() const;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-05 06:57:40 +08:00
|
|
|
|
|
|
|
/** function object which is used to handling the clean up of attribute arrays
|
|
|
|
* associated with GeoSet's. A default is provided which assumes that all
|
|
|
|
* momory attached to the GeoSet is owned by this GeoSet and can be deleted
|
|
|
|
* using delete []. If this is not the cause derive your own AttributeDeleteFunctor
|
|
|
|
* a specify your own memory deletion operation.*/
|
|
|
|
struct AttributeDeleteFunctor : public osg::Referenced
|
|
|
|
{
|
|
|
|
// see GeoSet.cpp for implemention.
|
|
|
|
virtual void operator() (GeoSet* gset);
|
|
|
|
};
|
|
|
|
|
|
|
|
/** set an alternative AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
|
|
|
void setAttributeDeleteFunctor(AttributeDeleteFunctor* adf) { _adf = adf; }
|
|
|
|
|
|
|
|
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
|
|
|
AttributeDeleteFunctor* getAttributeDeleteFunctor() { return _adf.get(); }
|
|
|
|
|
|
|
|
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
|
|
|
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
|
|
|
|
|
|
|
|
|
2001-10-23 06:02:47 +08:00
|
|
|
/** Statistics collection for each drawable- 26.09.01
|
|
|
|
*/
|
|
|
|
bool getStats(Statistics &);
|
|
|
|
|
2001-10-13 04:05:55 +08:00
|
|
|
|
|
|
|
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
|
2001-10-13 19:16:10 +08:00
|
|
|
virtual AttributeBitMask suppportsAttributeOperation() const;
|
2001-10-13 04:05:55 +08:00
|
|
|
|
|
|
|
/** return the attributes successully applied in applyAttributeUpdate.*/
|
2001-10-13 19:16:10 +08:00
|
|
|
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf);
|
2001-10-13 04:05:55 +08:00
|
|
|
|
|
|
|
|
2001-12-05 06:57:40 +08:00
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
GeoSet& operator = (const GeoSet&) { return *this;}
|
|
|
|
|
|
|
|
virtual ~GeoSet();
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual const bool computeBound() const;
|
|
|
|
|
2001-12-05 06:57:40 +08:00
|
|
|
ref_ptr<AttributeDeleteFunctor> _adf;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
int _numprims;
|
|
|
|
PrimitiveType _primtype;
|
|
|
|
int _needprimlen;
|
|
|
|
unsigned int _oglprimtype;
|
|
|
|
int *_primLengths;
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable unsigned char _primlength;
|
2001-01-11 00:32:10 +08:00
|
|
|
unsigned char _flat_shaded_skip;
|
|
|
|
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable int _numcoords;
|
2001-09-20 05:08:56 +08:00
|
|
|
Vec3 *_coords;
|
|
|
|
IndexPointer _cindex;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
BindingType _normal_binding;
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable int _numnormals;
|
2001-09-20 05:08:56 +08:00
|
|
|
Vec3 *_normals;
|
|
|
|
IndexPointer _nindex;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
BindingType _color_binding;
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable int _numcolors;
|
2001-09-20 05:08:56 +08:00
|
|
|
Vec4 *_colors;
|
|
|
|
IndexPointer _colindex;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
BindingType _texture_binding;
|
2001-10-13 19:16:10 +08:00
|
|
|
mutable int _numtcoords;
|
2001-09-20 05:08:56 +08:00
|
|
|
Vec2 *_tcoords;
|
|
|
|
IndexPointer _tindex;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void *_iarray;
|
|
|
|
IndexPointer _iaindex;
|
|
|
|
InterleaveArrayType _iaformat;
|
|
|
|
unsigned int _ogliaformat;
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-12-05 06:57:40 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
int _fast_path;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
void set_fast_path( void );
|
|
|
|
void draw_fast_path( void );
|
|
|
|
void draw_alternate_path( void );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Template function for iterating through a GeoSet operating on triangles
|
|
|
|
with templated functor. Function automatically decomposes quads and polygons
|
|
|
|
into sub triangles which are passed onto functor.*/
|
|
|
|
template<class T>
|
|
|
|
void for_each_triangle(GeoSet& gset,T& op)
|
|
|
|
{
|
|
|
|
switch(gset.getPrimType())
|
|
|
|
{
|
|
|
|
case(GeoSet::TRIANGLE_STRIP):
|
|
|
|
case(GeoSet::FLAT_TRIANGLE_STRIP):
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices().valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices()._is_ushort)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
ushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
ushort* iend = iptr+primLength;
|
|
|
|
for(int j = 2; j < primLength; j++ )
|
|
|
|
{
|
|
|
|
if( !(j%2) )
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
|
|
|
else
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+1)]);
|
|
|
|
++iptr;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint* iptr = gset.getCoordIndices()._ptr._uint;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
uint* iend = iptr+primLength;
|
|
|
|
for(int j = 2; j < primLength; j++ )
|
|
|
|
{
|
|
|
|
if( !(j%2) )
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
|
|
|
else
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+1)]);
|
|
|
|
++iptr;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
Vec3* vend = vptr+primLength;
|
|
|
|
for(int j = 2; j < primLength; j++ )
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if( !(j%2) )
|
|
|
|
op(*(vptr),*(vptr+1),*(vptr+2));
|
|
|
|
else
|
|
|
|
op(*(vptr),*(vptr+2),*(vptr+1));
|
2001-01-11 00:32:10 +08:00
|
|
|
++vptr;
|
|
|
|
}
|
|
|
|
vptr=vend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case(GeoSet::TRIANGLES):
|
|
|
|
{
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices().valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices()._is_ushort)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
ushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
|
|
|
iptr+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint* iptr = gset.getCoordIndices()._ptr._uint;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
|
|
|
iptr+=3;
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(*(vptr),*(vptr+1),*(vptr+2));
|
|
|
|
vptr+=3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case(GeoSet::QUAD_STRIP):
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices().valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices()._is_ushort)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
ushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
ushort* iend = iptr+primLength;
|
|
|
|
for(int j = 3; j < primLength; j+=2 )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
2002-01-02 18:49:26 +08:00
|
|
|
op(vptr[*(iptr+1)],vptr[*(iptr+3)],vptr[*(iptr+2)]);
|
2001-09-20 05:08:56 +08:00
|
|
|
iptr+=2;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint* iptr = gset.getCoordIndices()._ptr._uint;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
uint* iend = iptr+primLength;
|
|
|
|
for(int j = 3; j < primLength; j+=2 )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
2002-01-02 18:49:26 +08:00
|
|
|
op(vptr[*(iptr+1)],vptr[*(iptr+3)],vptr[*(iptr+2)]);
|
2001-09-20 05:08:56 +08:00
|
|
|
iptr+=2;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
Vec3* vend = vptr+primLength;
|
|
|
|
for(int j = 3; j < primLength; j+=2 )
|
|
|
|
{
|
|
|
|
op(*(vptr),*(vptr+1),*(vptr+2));
|
2002-01-02 18:49:26 +08:00
|
|
|
op(*(vptr+1),*(vptr+3),*(vptr+2));
|
2001-01-11 00:32:10 +08:00
|
|
|
vptr+=2;
|
|
|
|
}
|
|
|
|
vptr=vend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case(GeoSet::QUADS):
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices().valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices()._is_ushort)
|
|
|
|
{
|
|
|
|
ushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
2002-01-02 18:49:26 +08:00
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+3)]);
|
2001-09-20 05:08:56 +08:00
|
|
|
iptr+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
uint* iptr = gset.getCoordIndices()._ptr._uint;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+1)],vptr[*(iptr+2)]);
|
2002-01-02 18:49:26 +08:00
|
|
|
op(vptr[*(iptr)],vptr[*(iptr+2)],vptr[*(iptr+3)]);
|
2001-09-20 05:08:56 +08:00
|
|
|
iptr+=4;
|
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
op(*(vptr),*(vptr+1),*(vptr+2));
|
2002-01-02 18:49:26 +08:00
|
|
|
op(*(vptr),*(vptr+2),*(vptr+3));
|
2001-01-11 00:32:10 +08:00
|
|
|
vptr+=4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
2001-12-31 04:03:42 +08:00
|
|
|
case(GeoSet::FLAT_TRIANGLE_FAN):
|
2001-01-11 00:32:10 +08:00
|
|
|
case(GeoSet::TRIANGLE_FAN):
|
|
|
|
case(GeoSet::POLYGON):
|
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices().valid())
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
if (gset.getCoordIndices()._is_ushort)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
ushort* iptr = gset.getCoordIndices()._ptr._ushort;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
if (primLength>0)
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
2001-09-20 05:08:56 +08:00
|
|
|
const Vec3& start = vptr[*(iptr)];
|
|
|
|
ushort* iend = iptr+primLength;
|
2001-01-11 00:32:10 +08:00
|
|
|
++iptr;
|
2001-09-20 05:08:56 +08:00
|
|
|
for(int j = 2; j < primLength; ++j )
|
|
|
|
{
|
|
|
|
op(start,vptr[*(iptr)],vptr[*(iptr+1)]);
|
|
|
|
++iptr;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint* iptr = gset.getCoordIndices()._ptr._uint;
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
if (primLength>0)
|
|
|
|
{
|
|
|
|
const Vec3& start = vptr[*(iptr)];
|
|
|
|
uint* iend = iptr+primLength;
|
|
|
|
++iptr;
|
|
|
|
for(int j = 2; j < primLength; ++j )
|
|
|
|
{
|
|
|
|
op(start,vptr[*(iptr)],vptr[*(iptr+1)]);
|
|
|
|
++iptr;
|
|
|
|
}
|
|
|
|
iptr=iend;
|
2001-01-11 00:32:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vec3* vptr = gset.getCoords();
|
|
|
|
const int numPrim = gset.getNumPrims();
|
|
|
|
for(int i=0; i<numPrim; ++i )
|
|
|
|
{
|
|
|
|
const int primLength = gset.getPrimLengths()[i];
|
|
|
|
if (primLength>0)
|
|
|
|
{
|
|
|
|
const Vec3& start = *vptr;
|
|
|
|
Vec3* vend = vptr+primLength;
|
|
|
|
++vptr;
|
|
|
|
for(int j = 2; j < primLength; ++j)
|
|
|
|
{
|
|
|
|
op(start,*(vptr),*(vptr+1));
|
|
|
|
++vptr;
|
|
|
|
}
|
|
|
|
vptr = vend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-02-14 06:52:07 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
#endif
|