Rewrote the osg::Drawable::AttributeFunctor and PrimtiveFunctor to make
them more consistent with each other. This does mean an API change, so dependanct code in the OSG has been updated accordingly.
This commit is contained in:
parent
1d9dd54d11
commit
ff8b4c001d
@ -8,7 +8,6 @@
|
|||||||
#include <osg/BoundingBox>
|
#include <osg/BoundingBox>
|
||||||
#include <osg/State>
|
#include <osg/State>
|
||||||
#include <osg/Types>
|
#include <osg/Types>
|
||||||
#include <osg/Vec2>
|
|
||||||
#include <osg/NodeVisitor>
|
#include <osg/NodeVisitor>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -20,6 +19,7 @@ namespace osg {
|
|||||||
class Vec2;
|
class Vec2;
|
||||||
class Vec3;
|
class Vec3;
|
||||||
class Vec4;
|
class Vec4;
|
||||||
|
class UByte4;
|
||||||
class Node;
|
class Node;
|
||||||
|
|
||||||
// this is define to alter the way display lists are compiled inside the
|
// this is define to alter the way display lists are compiled inside the
|
||||||
@ -218,50 +218,54 @@ class SG_EXPORT Drawable : public Object
|
|||||||
* in the OpenGL context related to contextID.*/
|
* in the OpenGL context related to contextID.*/
|
||||||
static void flushDeletedDisplayLists(uint contextID);
|
static void flushDeletedDisplayLists(uint contextID);
|
||||||
|
|
||||||
typedef uint AttributeBitMask;
|
enum AttributeType
|
||||||
|
|
||||||
enum AttributeBitMaskValues
|
|
||||||
{
|
{
|
||||||
COORDS = 0x1,
|
VERTICES,
|
||||||
NORMALS = 0x2,
|
NORMALS,
|
||||||
COLORS = 0x4,
|
COLORS,
|
||||||
TEXTURE_COORDS = 0x8,
|
TEXTURE_COORDS,
|
||||||
TEXTURE_COORDS_0 = TEXTURE_COORDS,
|
TEXTURE_COORDS_0 = TEXTURE_COORDS,
|
||||||
TEXTURE_COORDS_1 = 0x10,
|
TEXTURE_COORDS_1 = TEXTURE_COORDS_0+1,
|
||||||
TEXTURE_COORDS_2 = 0x20,
|
TEXTURE_COORDS_2 = TEXTURE_COORDS_0+2,
|
||||||
TEXTURE_COORDS_3 = 0x40
|
TEXTURE_COORDS_3 = TEXTURE_COORDS_0+3,
|
||||||
|
TEXTURE_COORDS_4 = TEXTURE_COORDS_0+4,
|
||||||
|
TEXTURE_COORDS_5 = TEXTURE_COORDS_0+5,
|
||||||
|
TEXTURE_COORDS_6 = TEXTURE_COORDS_0+6,
|
||||||
|
TEXTURE_COORDS_7 = TEXTURE_COORDS_0+7
|
||||||
|
// only eight texture coord examples provided here, but underlying code can handle any no of texure units,
|
||||||
|
// simply co them as (TEXTURE_COORDS_0+unit).
|
||||||
};
|
};
|
||||||
|
|
||||||
class AttributeFunctor
|
class AttributeFunctor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AttributeFunctor(AttributeBitMask abm):_abm(abm) {}
|
|
||||||
virtual ~AttributeFunctor() {}
|
virtual ~AttributeFunctor() {}
|
||||||
|
|
||||||
void setAttributeBitMask(AttributeBitMask abm) { _abm=abm; }
|
|
||||||
AttributeBitMask getAttributeBitMask() const { return _abm; }
|
|
||||||
|
|
||||||
virtual bool apply(AttributeBitMask,Vec2*,Vec2*) { return false; }
|
|
||||||
virtual bool apply(AttributeBitMask,Vec3*,Vec3*) { return false; }
|
|
||||||
virtual bool apply(AttributeBitMask,Vec4*,Vec4*) { return false; }
|
|
||||||
|
|
||||||
protected:
|
virtual void apply(AttributeType,unsigned int,GLbyte*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,GLshort*) {}
|
||||||
AttributeBitMask _abm;
|
virtual void apply(AttributeType,unsigned int,GLint*) {}
|
||||||
|
|
||||||
|
virtual void apply(AttributeType,unsigned int,GLubyte*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,GLushort*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,GLuint*) {}
|
||||||
|
|
||||||
|
virtual void apply(AttributeType,unsigned int,float*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,Vec2*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,Vec3*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,Vec4*) {}
|
||||||
|
virtual void apply(AttributeType,unsigned int,UByte4*) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** return the attributes supported by applyAttrbuteOperation() as an AttributeBitMask.*/
|
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||||
virtual AttributeBitMask suppportsAttributeOperation() const { return (AttributeBitMask)0; }
|
virtual void accept(AttributeFunctor&) {}
|
||||||
|
|
||||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
|
||||||
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor&) { return 0; }
|
|
||||||
|
|
||||||
|
|
||||||
class PrimitiveFunctor
|
class PrimitiveFunctor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual ~PrimitiveFunctor() {}
|
||||||
|
|
||||||
virtual void setVertexArray(unsigned int count,Vec3* vertices) = 0;
|
virtual void setVertexArray(unsigned int count,Vec3* vertices) = 0;
|
||||||
|
|
||||||
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
|
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0;
|
||||||
@ -276,8 +280,8 @@ class SG_EXPORT Drawable : public Object
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** apply the internal geometry as basic primitives to a PrimitiveFunctor.*/
|
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||||
virtual void applyPrimitiveOperation(PrimitiveFunctor&) {}
|
virtual void accept(PrimitiveFunctor&) {}
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -329,14 +329,11 @@ class SG_EXPORT GeoSet : public Drawable
|
|||||||
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
/** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/
|
||||||
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
|
const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); }
|
||||||
|
|
||||||
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
|
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||||
virtual AttributeBitMask suppportsAttributeOperation() const;
|
virtual void accept(AttributeFunctor& af);
|
||||||
|
|
||||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||||
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf);
|
virtual void accept(PrimitiveFunctor& pf);
|
||||||
|
|
||||||
/** apply the internal geometry as basic primitives to a PrimitiveFunctor.*/
|
|
||||||
virtual void applyPrimitiveOperation(PrimitiveFunctor& functor);
|
|
||||||
|
|
||||||
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
|
/** convinience function for converting GeoSet's to equivilant Geometry nodes.*/
|
||||||
Geometry* convertToGeometry();
|
Geometry* convertToGeometry();
|
||||||
|
@ -91,14 +91,11 @@ class SG_EXPORT Geometry : public Drawable
|
|||||||
*/
|
*/
|
||||||
virtual void drawImmediateMode(State& state);
|
virtual void drawImmediateMode(State& state);
|
||||||
|
|
||||||
|
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||||
|
virtual void accept(AttributeFunctor& af);
|
||||||
|
|
||||||
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
|
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||||
virtual AttributeBitMask suppportsAttributeOperation() const;
|
virtual void accept(PrimitiveFunctor& pf);
|
||||||
|
|
||||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
|
||||||
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf);
|
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(PrimitiveFunctor&);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -116,6 +116,12 @@ class SG_EXPORT ImpostorSprite : public Drawable
|
|||||||
/** draw ImpostorSprite directly. */
|
/** draw ImpostorSprite directly. */
|
||||||
virtual void drawImmediateMode(State& state);
|
virtual void drawImmediateMode(State& state);
|
||||||
|
|
||||||
|
/** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
|
||||||
|
virtual void accept(AttributeFunctor& af);
|
||||||
|
|
||||||
|
/** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
|
||||||
|
virtual void accept(PrimitiveFunctor& pf);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ImpostorSprite(const ImpostorSprite&):Drawable() {}
|
ImpostorSprite(const ImpostorSprite&):Drawable() {}
|
||||||
|
@ -123,7 +123,7 @@ class Primitive : public Object
|
|||||||
|
|
||||||
virtual void draw() const = 0;
|
virtual void draw() const = 0;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor&) {}
|
virtual void accept(Drawable::PrimitiveFunctor&) {}
|
||||||
|
|
||||||
virtual void offsetIndices(int offset) = 0;
|
virtual void offsetIndices(int offset) = 0;
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ class SG_EXPORT DrawArrays : public Primitive
|
|||||||
|
|
||||||
virtual void draw() const;
|
virtual void draw() const;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
||||||
|
|
||||||
virtual void offsetIndices(int offset) { _first += offset; }
|
virtual void offsetIndices(int offset) { _first += offset; }
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ class SG_EXPORT DrawArrayLengths : public Primitive, public VectorSizei
|
|||||||
|
|
||||||
virtual void draw() const;
|
virtual void draw() const;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
||||||
|
|
||||||
virtual void offsetIndices(int offset) { _first += offset; }
|
virtual void offsetIndices(int offset) { _first += offset; }
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ class SG_EXPORT DrawElementsUByte : public Primitive, public VectorUByte
|
|||||||
|
|
||||||
virtual void draw() const ;
|
virtual void draw() const ;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
||||||
|
|
||||||
virtual void offsetIndices(int offset);
|
virtual void offsetIndices(int offset);
|
||||||
};
|
};
|
||||||
@ -304,7 +304,7 @@ class SG_EXPORT DrawElementsUShort : public Primitive, public VectorUShort
|
|||||||
|
|
||||||
virtual void draw() const;
|
virtual void draw() const;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
||||||
|
|
||||||
virtual void offsetIndices(int offset);
|
virtual void offsetIndices(int offset);
|
||||||
};
|
};
|
||||||
@ -341,7 +341,7 @@ class SG_EXPORT DrawElementsUInt : public Primitive, public VectorUInt
|
|||||||
|
|
||||||
virtual void draw() const;
|
virtual void draw() const;
|
||||||
|
|
||||||
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
||||||
|
|
||||||
virtual void offsetIndices(int offset);
|
virtual void offsetIndices(int offset);
|
||||||
};
|
};
|
||||||
|
@ -52,7 +52,7 @@ void printTriangles(const std::string& name, osg::Drawable& drawable)
|
|||||||
std::cout<<name<<std::endl;
|
std::cout<<name<<std::endl;
|
||||||
|
|
||||||
osg::TriangleFunctor<NormalPrint> tf;
|
osg::TriangleFunctor<NormalPrint> tf;
|
||||||
drawable.applyPrimitiveOperation(tf);
|
drawable.accept(tf);
|
||||||
|
|
||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,6 @@ class MyGeometryCallback :
|
|||||||
MyGeometryCallback(const osg::Vec3& o,
|
MyGeometryCallback(const osg::Vec3& o,
|
||||||
const osg::Vec3& x,const osg::Vec3& y,const osg::Vec3& z,
|
const osg::Vec3& x,const osg::Vec3& y,const osg::Vec3& z,
|
||||||
double period,double xphase,double amplitude):
|
double period,double xphase,double amplitude):
|
||||||
osg::Drawable::AttributeFunctor(osg::Drawable::COORDS),
|
|
||||||
_firstCall(true),
|
_firstCall(true),
|
||||||
_startTime(0.0),
|
_startTime(0.0),
|
||||||
_time(0.0),
|
_time(0.0),
|
||||||
@ -234,7 +233,7 @@ class MyGeometryCallback :
|
|||||||
|
|
||||||
_time = referenceTime-_startTime;
|
_time = referenceTime-_startTime;
|
||||||
|
|
||||||
drawable->applyAttributeOperation(*this);
|
drawable->accept(*this);
|
||||||
drawable->dirtyBound();
|
drawable->dirtyBound();
|
||||||
|
|
||||||
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(drawable);
|
osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(drawable);
|
||||||
@ -245,13 +244,14 @@ class MyGeometryCallback :
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool apply(osg::Drawable::AttributeBitMask abm,osg::Vec3* begin,osg::Vec3* end)
|
virtual void apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin)
|
||||||
{
|
{
|
||||||
if (abm == osg::Drawable::COORDS)
|
if (type == osg::Drawable::VERTICES)
|
||||||
{
|
{
|
||||||
const float TwoPI=2.0f*osg::PI;
|
const float TwoPI=2.0f*osg::PI;
|
||||||
const float phase = -_time/_period;
|
const float phase = -_time/_period;
|
||||||
|
|
||||||
|
osg::Vec3* end = begin+count;
|
||||||
for (osg::Vec3* itr=begin;itr<end;++itr)
|
for (osg::Vec3* itr=begin;itr<end;++itr)
|
||||||
{
|
{
|
||||||
osg::Vec3 dv(*itr-_origin);
|
osg::Vec3 dv(*itr-_origin);
|
||||||
@ -265,10 +265,7 @@ class MyGeometryCallback :
|
|||||||
_yAxis*local.y()+
|
_yAxis*local.y()+
|
||||||
_zAxis*local.z();
|
_zAxis*local.z();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _firstCall;
|
bool _firstCall;
|
||||||
|
@ -849,91 +849,79 @@ void GeoSet::setInterleavedArray( const InterleaveArrayType format, float *ia, I
|
|||||||
|
|
||||||
set_fast_path();
|
set_fast_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable::AttributeBitMask GeoSet::suppportsAttributeOperation() const
|
|
||||||
{
|
|
||||||
// we do support coords,normals,texcoords and colors so return true.
|
|
||||||
return COORDS | NORMALS | COLORS | TEXTURE_COORDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
Drawable::AttributeBitMask GeoSet::applyAttributeOperation(AttributeFunctor& auf)
|
void GeoSet::accept(AttributeFunctor& auf)
|
||||||
{
|
{
|
||||||
if (_numcoords == 0) computeNumVerts();
|
if (_numcoords == 0) computeNumVerts();
|
||||||
|
|
||||||
AttributeBitMask amb = auf.getAttributeBitMask();
|
if (_coords && _numcoords)
|
||||||
AttributeBitMask ramb = 0;
|
|
||||||
|
|
||||||
if ((amb & COORDS) && _coords && _numcoords)
|
|
||||||
{
|
{
|
||||||
if (auf.apply(COORDS,_coords,_coords+_numcoords)) ramb = COORDS;
|
auf.apply(VERTICES,_numcoords,_coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((amb & NORMALS) && _normals && _numnormals)
|
if (_normals && _numnormals)
|
||||||
{
|
{
|
||||||
if (auf.apply(NORMALS,_normals,_normals+_numnormals)) ramb = NORMALS;
|
auf.apply(NORMALS,_numnormals,_normals);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((amb & COLORS) && _colors && _numcolors)
|
if (_colors && _numcolors)
|
||||||
{
|
{
|
||||||
if (auf.apply(COLORS,_colors,_colors+_numcolors)) ramb = COLORS;
|
auf.apply(COLORS,_numcolors,_colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((amb & TEXTURE_COORDS) && _tcoords && _numtcoords)
|
if (_tcoords && _numtcoords)
|
||||||
{
|
{
|
||||||
if (auf.apply(TEXTURE_COORDS,_tcoords,_tcoords+_numtcoords)) ramb = TEXTURE_COORDS;
|
auf.apply(TEXTURE_COORDS_0,_numtcoords,_tcoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ramb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GeoSet::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
void GeoSet::accept(PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
// will easily convert into a Geometry.
|
// will easily convert into a Geometry.
|
||||||
|
|
||||||
if (!_coords || !_numcoords) return;
|
if (!_coords || !_numcoords) return;
|
||||||
|
|
||||||
functor.setVertexArray(_numcoords,_coords);
|
functor.setVertexArray(_numcoords,_coords);
|
||||||
|
|
||||||
if( _needprimlen )
|
if( _needprimlen )
|
||||||
|
{
|
||||||
|
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
||||||
|
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
||||||
|
int index = 0;
|
||||||
|
if( _primLengths == (int *)0 )
|
||||||
{
|
{
|
||||||
// LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP,
|
return;
|
||||||
// TRIANGLE_FAN, QUAD_STRIP, POLYGONS
|
|
||||||
int index = 0;
|
|
||||||
if( _primLengths == (int *)0 )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for( int i = 0; i < _numprims; i++ )
|
|
||||||
{
|
|
||||||
if( _cindex.valid() )
|
|
||||||
{
|
|
||||||
|
|
||||||
if (_cindex._is_ushort)
|
|
||||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
|
|
||||||
else
|
|
||||||
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._uint[index] );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
|
|
||||||
|
|
||||||
index += _primLengths[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // POINTS, LINES, TRIANGLES, QUADS
|
|
||||||
|
for( int i = 0; i < _numprims; i++ )
|
||||||
{
|
{
|
||||||
if( _cindex.valid())
|
if( _cindex.valid() )
|
||||||
{
|
{
|
||||||
|
|
||||||
if (_cindex._is_ushort)
|
if (_cindex._is_ushort)
|
||||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort );
|
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] );
|
||||||
else
|
else
|
||||||
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint );
|
functor.drawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._uint[index] );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
functor.drawArrays( (GLenum)_oglprimtype, 0, _numcoords );
|
functor.drawArrays( (GLenum)_oglprimtype, index, _primLengths[i] );
|
||||||
|
|
||||||
|
index += _primLengths[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else // POINTS, LINES, TRIANGLES, QUADS
|
||||||
|
{
|
||||||
|
if( _cindex.valid())
|
||||||
|
{
|
||||||
|
if (_cindex._is_ushort)
|
||||||
|
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort );
|
||||||
|
else
|
||||||
|
functor.drawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
functor.drawArrays( (GLenum)_oglprimtype, 0, _numcoords );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,35 +192,22 @@ void Geometry::drawImmediateMode(State& state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Drawable::AttributeBitMask Geometry::suppportsAttributeOperation() const
|
|
||||||
{
|
|
||||||
// we do support coords,normals,texcoords and colors so return true.
|
|
||||||
return COORDS | NORMALS | COLORS | TEXTURE_COORDS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void Geometry::accept(AttributeFunctor& af)
|
||||||
/** return the attributes successully applied in applyAttributeUpdate.*/
|
|
||||||
Drawable::AttributeBitMask Geometry::applyAttributeOperation(AttributeFunctor& auf)
|
|
||||||
{
|
{
|
||||||
AttributeBitMask amb = auf.getAttributeBitMask();
|
if (_vertexArray.valid() && !_vertexArray->empty())
|
||||||
AttributeBitMask ramb = 0;
|
|
||||||
|
|
||||||
if ((amb & COORDS) && _vertexArray.valid() && !_vertexArray->empty())
|
|
||||||
{
|
{
|
||||||
if (auf.apply(COORDS,&(*(_vertexArray->begin())),&(*(_vertexArray->end())))) ramb = COORDS;
|
af.apply(VERTICES,_vertexArray->size(),&(_vertexArray->front()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((amb & NORMALS) && _normalArray.valid() && !_normalArray->empty())
|
if (_normalArray.valid() && !_normalArray->empty())
|
||||||
{
|
{
|
||||||
if (auf.apply(NORMALS,&(*(_normalArray->begin())),&(*(_normalArray->end())))) ramb = NORMALS;
|
af.apply(NORMALS,_normalArray->size(),&(_normalArray->front()));
|
||||||
}
|
}
|
||||||
|
// need to add other attriubtes
|
||||||
// colors and texture coords to implement...
|
|
||||||
|
|
||||||
return ramb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Geometry::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
void Geometry::accept(PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
if (!_vertexArray.valid() || _vertexArray->empty()) return;
|
if (!_vertexArray.valid() || _vertexArray->empty()) return;
|
||||||
|
|
||||||
@ -230,7 +217,7 @@ void Geometry::applyPrimitiveOperation(PrimitiveFunctor& functor)
|
|||||||
itr!=_primitives.end();
|
itr!=_primitives.end();
|
||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
(*itr)->applyPrimitiveOperation(functor);
|
(*itr)->accept(functor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,20 @@ void ImpostorSprite::setTexture(Texture* tex,int s,int t)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ImpostorSprite::accept(AttributeFunctor& af)
|
||||||
|
{
|
||||||
|
af.apply(VERTICES,4,_coords);
|
||||||
|
af.apply(TEXTURE_COORDS_0,4,_texcoords);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImpostorSprite::accept(PrimitiveFunctor& functor)
|
||||||
|
{
|
||||||
|
functor.setVertexArray(4,_coords);
|
||||||
|
functor.drawArrays( GL_QUADS, 0, 4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// Helper class for managing the reuse of ImpostorSprite resources.
|
// Helper class for managing the reuse of ImpostorSprite resources.
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
@ -267,3 +281,4 @@ ImpostorSprite* ImpostorSpriteManager::createOrReuseImpostorSprite(int s,int t,i
|
|||||||
return is;
|
return is;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ void DrawArrays::draw() const
|
|||||||
glDrawArrays(_mode,_first,_count);
|
glDrawArrays(_mode,_first,_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawArrays::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
void DrawArrays::accept(Drawable::PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
functor.drawArrays(_mode,_first,_count);
|
functor.drawArrays(_mode,_first,_count);
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ void DrawArrayLengths::draw() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawArrayLengths::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
void DrawArrayLengths::accept(Drawable::PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
GLint first = _first;
|
GLint first = _first;
|
||||||
for(VectorSizei::iterator itr=begin();
|
for(VectorSizei::iterator itr=begin();
|
||||||
@ -43,7 +43,7 @@ void DrawElementsUByte::draw() const
|
|||||||
glDrawElements(_mode,size(),GL_UNSIGNED_BYTE,&front());
|
glDrawElements(_mode,size(),GL_UNSIGNED_BYTE,&front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawElementsUByte::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
void DrawElementsUByte::accept(Drawable::PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ void DrawElementsUShort::draw() const
|
|||||||
glDrawElements(_mode,size(),GL_UNSIGNED_SHORT,&front());
|
glDrawElements(_mode,size(),GL_UNSIGNED_SHORT,&front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawElementsUShort::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
void DrawElementsUShort::accept(Drawable::PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ void DrawElementsUInt::draw() const
|
|||||||
glDrawElements(_mode,size(),GL_UNSIGNED_INT,&front());
|
glDrawElements(_mode,size(),GL_UNSIGNED_INT,&front());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawElementsUInt::applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
|
void DrawElementsUInt::accept(Drawable::PrimitiveFunctor& functor)
|
||||||
{
|
{
|
||||||
if (!empty()) functor.drawElements(_mode,size(),&front());
|
if (!empty()) functor.drawElements(_mode,size(),&front());
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ bool IntersectVisitor::intersect(Drawable& drawable)
|
|||||||
|
|
||||||
TriangleFunctor<TriangleIntersect> ti;
|
TriangleFunctor<TriangleIntersect> ti;
|
||||||
ti.set(*sitr->second);
|
ti.set(*sitr->second);
|
||||||
drawable.applyPrimitiveOperation(ti);
|
drawable.accept(ti);
|
||||||
if (ti._hit)
|
if (ti._hit)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -99,8 +99,7 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
|
|||||||
osg::Matrix _m;
|
osg::Matrix _m;
|
||||||
osg::Matrix _im;
|
osg::Matrix _im;
|
||||||
|
|
||||||
TransformFunctor(const osg::Matrix& m):
|
TransformFunctor(const osg::Matrix& m)
|
||||||
osg::Drawable::AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS)
|
|
||||||
{
|
{
|
||||||
_m = m;
|
_m = m;
|
||||||
_im.invert(_m);
|
_im.invert(_m);
|
||||||
@ -108,28 +107,26 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
|
|||||||
|
|
||||||
virtual ~TransformFunctor() {}
|
virtual ~TransformFunctor() {}
|
||||||
|
|
||||||
virtual bool apply(osg::Drawable::AttributeBitMask abm,osg::Vec3* begin,osg::Vec3* end)
|
virtual void apply(osg::Drawable::AttributeType type,unsigned int count,osg::Vec3* begin)
|
||||||
{
|
{
|
||||||
if (abm == osg::Drawable::COORDS)
|
if (type == osg::Drawable::VERTICES)
|
||||||
{
|
{
|
||||||
|
osg::Vec3* end = begin+count;
|
||||||
for (osg::Vec3* itr=begin;itr<end;++itr)
|
for (osg::Vec3* itr=begin;itr<end;++itr)
|
||||||
{
|
{
|
||||||
(*itr) = (*itr)*_m;
|
(*itr) = (*itr)*_m;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else if (abm == osg::Drawable::NORMALS)
|
else if (type == osg::Drawable::NORMALS)
|
||||||
{
|
{
|
||||||
|
osg::Vec3* end = begin+count;
|
||||||
for (osg::Vec3* itr=begin;itr<end;++itr)
|
for (osg::Vec3* itr=begin;itr<end;++itr)
|
||||||
{
|
{
|
||||||
// note post mult by inverse for normals.
|
// note post mult by inverse for normals.
|
||||||
(*itr) = osg::Matrix::transform3x3(_im,(*itr));
|
(*itr) = osg::Matrix::transform3x3(_im,(*itr));
|
||||||
(*itr).normalize();
|
(*itr).normalize();
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -455,7 +452,7 @@ void Optimizer::FlattenStaticTransformsVisitor::doTransform(osg::Object* obj,osg
|
|||||||
if (drawable)
|
if (drawable)
|
||||||
{
|
{
|
||||||
TransformFunctor tf(matrix);
|
TransformFunctor tf(matrix);
|
||||||
drawable->applyAttributeOperation(tf);
|
drawable->accept(tf);
|
||||||
drawable->dirtyBound();
|
drawable->dirtyBound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -498,7 +495,7 @@ void Optimizer::FlattenStaticTransformsVisitor::doTransform(osg::Object* obj,osg
|
|||||||
for(unsigned int i=0;i<billboard->getNumDrawables();++i)
|
for(unsigned int i=0;i<billboard->getNumDrawables();++i)
|
||||||
{
|
{
|
||||||
billboard->setPos(i,billboard->getPos(i)*matrix);
|
billboard->setPos(i,billboard->getPos(i)*matrix);
|
||||||
billboard->getDrawable(i)->applyAttributeOperation(tf);
|
billboard->getDrawable(i)->accept(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
billboard->dirtyBound();
|
billboard->dirtyBound();
|
||||||
@ -717,7 +714,7 @@ void Optimizer::RemoveLowestStaticTransformsVisitor::doTransform(osg::Object* ob
|
|||||||
if (drawable)
|
if (drawable)
|
||||||
{
|
{
|
||||||
TransformFunctor tf(matrix);
|
TransformFunctor tf(matrix);
|
||||||
drawable->applyAttributeOperation(tf);
|
drawable->accept(tf);
|
||||||
drawable->dirtyBound();
|
drawable->dirtyBound();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -760,7 +757,7 @@ void Optimizer::RemoveLowestStaticTransformsVisitor::doTransform(osg::Object* ob
|
|||||||
for(unsigned int i=0;i<billboard->getNumDrawables();++i)
|
for(unsigned int i=0;i<billboard->getNumDrawables();++i)
|
||||||
{
|
{
|
||||||
billboard->setPos(i,billboard->getPos(i)*matrix);
|
billboard->setPos(i,billboard->getPos(i)*matrix);
|
||||||
billboard->getDrawable(i)->applyAttributeOperation(tf);
|
billboard->getDrawable(i)->accept(tf);
|
||||||
}
|
}
|
||||||
|
|
||||||
billboard->dirtyBound();
|
billboard->dirtyBound();
|
||||||
|
@ -191,7 +191,7 @@ bool RenderBin::getStats(osg::Statistics* primStats)
|
|||||||
if (dw)
|
if (dw)
|
||||||
{
|
{
|
||||||
// then tot up the primtive types and no vertices.
|
// then tot up the primtive types and no vertices.
|
||||||
dw->applyPrimitiveOperation(*primStats); // use sub-class to find the stats for each drawable
|
dw->accept(*primStats); // use sub-class to find the stats for each drawable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
somestats=true;
|
somestats=true;
|
||||||
|
@ -111,7 +111,7 @@ void SmoothingVisitor::smooth(osg::Geometry& geom)
|
|||||||
TriangleFunctor<SmoothTriangleFunctor> stf;
|
TriangleFunctor<SmoothTriangleFunctor> stf;
|
||||||
stf.set(&(coords->front()),coords->size(),&(normals->front()));
|
stf.set(&(coords->front()),coords->size(),&(normals->front()));
|
||||||
|
|
||||||
geom.applyPrimitiveOperation(stf);
|
geom.accept(stf);
|
||||||
|
|
||||||
for(nitr= normals->begin();
|
for(nitr= normals->begin();
|
||||||
nitr!=normals->end();
|
nitr!=normals->end();
|
||||||
|
@ -82,7 +82,7 @@ void TriStripVisitor::stripify(Geometry& geom)
|
|||||||
case(Primitive::QUADS):
|
case(Primitive::QUADS):
|
||||||
case(Primitive::QUAD_STRIP):
|
case(Primitive::QUAD_STRIP):
|
||||||
case(Primitive::POLYGON):
|
case(Primitive::POLYGON):
|
||||||
(*itr)->applyPrimitiveOperation(taf);
|
(*itr)->accept(taf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
new_primitives.push_back(*itr);
|
new_primitives.push_back(*itr);
|
||||||
|
Loading…
Reference in New Issue
Block a user