diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index a6c3926f2..8e3f76b80 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -209,10 +209,6 @@ SOURCE=..\..\src\osg\Geometry.cpp # End Source File # Begin Source File -SOURCE=..\..\src\osg\IndexedGeometry.cpp -# End Source File -# Begin Source File - SOURCE=..\..\src\osg\GeoSet.cpp # End Source File # Begin Source File diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index da27e5ca7..17a27e09f 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -158,10 +158,6 @@ SOURCE=..\..\..\src\osgPlugins\osg\Geometry.cpp # End Source File # Begin Source File -SOURCE=..\..\..\src\osgPlugins\osg\IndexedGeometry.cpp -# End Source File -# Begin Source File - SOURCE=..\..\..\src\osgPlugins\osg\Group.cpp # End Source File # Begin Source File diff --git a/include/osg/GeoSet b/include/osg/GeoSet index b680a8e9a..8e2d53e10 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -15,7 +15,6 @@ namespace osg { // forward declare so that we don't need to include the header. class Geometry; -class IndexedGeometry; /** Note, osg::GeoSet is now deprecated, please use osg::Geometry instead. osg::GeoSet will be kept through to the beta release for @@ -339,9 +338,6 @@ class SG_EXPORT GeoSet : public Drawable /** convinience function for converting GeoSet's to equivilant Geometry nodes.*/ Geometry* convertToGeometry(); - /** convinience function for converting GeoSet's to equivilant IndexedGeometry nodes.*/ - IndexedGeometry* convertToIndexedGeometry(); - protected: GeoSet& operator = (const GeoSet&) { return *this;} diff --git a/include/osg/Geometry b/include/osg/Geometry index 317267155..221e67cfc 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -37,6 +37,7 @@ class SG_EXPORT Geometry : public Drawable { BIND_OFF=0, BIND_OVERALL, + BIND_PER_PRIMITIVE_SET, BIND_PER_PRIMITIVE, BIND_PER_VERTEX }; @@ -45,32 +46,48 @@ class SG_EXPORT Geometry : public Drawable Vec3Array* getVertexArray() { return _vertexArray.get(); } const Vec3Array* getVertexArray() const { return _vertexArray.get(); } + void setVertexIndices(IndexArray* array) { _vertexIndices = array; _fastPathComputed=false; dirtyDisplayList(); dirtyBound(); } + IndexArray* getVertexIndices() { return _vertexIndices.get(); } + const IndexArray* getVertexIndices() const { return _vertexIndices.get(); } - void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); } + + void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); _fastPathComputed=false; } AttributeBinding getNormalBinding() const { return _normalBinding; } - void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; dirtyDisplayList(); } + void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; _fastPathComputed=false; dirtyDisplayList(); } Vec3Array* getNormalArray() { return _normalArray.get(); } const Vec3Array* getNormalArray() const { return _normalArray.get(); } + void setNormalIndices(IndexArray* array) { _normalIndices = array; _fastPathComputed=false; dirtyDisplayList(); } + IndexArray* getNormalIndices() { return _normalIndices.get(); } + const IndexArray* getNormalIndices() const { return _normalIndices.get(); } - void setColorBinding(AttributeBinding ab) { _colorBinding = ab; } + + void setColorBinding(AttributeBinding ab) { _colorBinding = ab; _fastPathComputed=false;} AttributeBinding getColorBinding() const { return _colorBinding; } - void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; dirtyDisplayList(); } + void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; _fastPathComputed=false; dirtyDisplayList(); } Array* getColorArray() { return _colorArray.get(); } const Array* getColorArray() const { return _colorArray.get(); } + void setColorIndices(IndexArray* array) { _colorIndices = array; _fastPathComputed=false; dirtyDisplayList(); } + IndexArray* getColorIndices() { return _colorIndices.get(); } + const IndexArray* getColorIndices() const { return _colorIndices.get(); } - void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; } + + void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; _fastPathComputed=false;} AttributeBinding getSecondaryColorBinding() const { return _secondaryColorBinding; } - void setSecondaryColorArray(Array* array) { _secondaryColorArray = array; if (!_secondaryColorArray.valid()) _secondaryColorBinding=BIND_OFF; dirtyDisplayList(); } + void setSecondaryColorArray(Array* array) { _secondaryColorArray = array; if (!_secondaryColorArray.valid()) _secondaryColorBinding=BIND_OFF; _fastPathComputed=false; dirtyDisplayList(); } Array* getSecondaryColorArray() { return _secondaryColorArray.get(); } const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); } + void setSecondaryColorIndices(IndexArray* array) { _secondaryColorIndices = array; _fastPathComputed=false; dirtyDisplayList(); } + IndexArray* getSecondaryColorIndices() { return _secondaryColorIndices.get(); } + const IndexArray* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); } - void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; } + + void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; _fastPathComputed=false;} AttributeBinding getFogCoordBinding() const { return _fogCoordBinding; } void setFogCoordArray(FloatArray* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); } @@ -78,33 +95,49 @@ class SG_EXPORT Geometry : public Drawable const FloatArray* getFogCoordArray() const { return _fogCoordArray.get(); } - typedef std::vector< ref_ptr > TexCoordArrayList; + void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); } + IndexArray* getFogCoordIndices() { return _fogCoordIndices.get(); } + const IndexArray* getFogCoordIndices() const { return _fogCoordIndices.get(); } + + + + typedef std::pair< ref_ptr, ref_ptr > TexCoordArrayPair; + typedef std::vector< TexCoordArrayPair > TexCoordArrayList; void setTexCoordArray(unsigned int unit,Array*); Array* getTexCoordArray(unsigned int unit); const Array* getTexCoordArray(unsigned int unit) const; + void setTexCoordIndices(unsigned int unit,IndexArray*); + IndexArray* getTexCoordIndices(unsigned int unit); + const IndexArray* getTexCoordIndices(unsigned int unit) const; + unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); } TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; } const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; } - typedef std::vector< ref_ptr > PrimitiveList; + typedef std::vector< ref_ptr > PrimitiveSetList; - void setPrimitiveList(const PrimitiveList& primitives) { _primitives = primitives; dirtyDisplayList(); } - PrimitiveList& getPrimitiveList() { return _primitives; } - const PrimitiveList& getPrimitiveList() const { return _primitives; } + void setPrimitiveSetList(const PrimitiveSetList& primitives) { _primitives = primitives; dirtyDisplayList(); dirtyBound(); } + PrimitiveSetList& getPrimitiveSetList() { return _primitives; } + const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; } - unsigned int getNumPrimitives() const { return _primitives.size(); } - PrimitiveSet* getPrimitive(unsigned int pos) { return _primitives[pos].get(); } - const PrimitiveSet* getPrimitive(unsigned int pos) const { return _primitives[pos].get(); } + unsigned int getNumPrimitiveSets() const { return _primitives.size(); } + PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); } + const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); } - void addPrimitive(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); } + void addPrimitiveSet(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); dirtyBound(); } + + /** return true if OpenGL fast paths will be used with drawing this Geometry. + * Fast paths use vertex arrays, and glDrawArrays/glDrawElements. Slow paths + * use glBegin()/glVertex.../glEnd(). Use of per primtive bindings or per vertex indexed + * arrays will drop the rendering path off the fast path.*/ + bool areFastPathsUsed() const; bool verifyBindings() const; - void computeCorrectBindingsAndArraySizes(); @@ -126,23 +159,31 @@ class SG_EXPORT Geometry : public Drawable virtual ~Geometry(); - PrimitiveList _primitives; + PrimitiveSetList _primitives; ref_ptr _vertexArray; + ref_ptr _vertexIndices; - AttributeBinding _normalBinding; + mutable AttributeBinding _normalBinding; ref_ptr _normalArray; + ref_ptr _normalIndices; - AttributeBinding _colorBinding; + mutable AttributeBinding _colorBinding; ref_ptr _colorArray; + ref_ptr _colorIndices; - AttributeBinding _secondaryColorBinding; + mutable AttributeBinding _secondaryColorBinding; ref_ptr _secondaryColorArray; + ref_ptr _secondaryColorIndices; - AttributeBinding _fogCoordBinding; + mutable AttributeBinding _fogCoordBinding; ref_ptr _fogCoordArray; + ref_ptr _fogCoordIndices; TexCoordArrayList _texCoordList; + + mutable bool _fastPathComputed; + mutable bool _fastPath; }; diff --git a/include/osg/IndexedGeometry b/include/osg/IndexedGeometry deleted file mode 100644 index 366605df8..000000000 --- a/include/osg/IndexedGeometry +++ /dev/null @@ -1,185 +0,0 @@ -//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield -//Distributed under the terms of the GNU Library General Public License (LGPL) -//as published by the Free Software Foundation. - -#ifndef OSG_INDEXEDGEOMETRY -#define OSG_INDEXEDGEOMETRY 1 - -#include -#include -#include -#include -#include -#include - -namespace osg { - - -class SG_EXPORT IndexedGeometry : public Drawable -{ - public: - - IndexedGeometry(); - - /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ - IndexedGeometry(const IndexedGeometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY); - - virtual Object* cloneType() const { return osgNew IndexedGeometry(); } - virtual Object* clone(const CopyOp& copyop) const { return osgNew IndexedGeometry(*this,copyop); } - virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } - virtual const char* libraryName() const { return "osg"; } - virtual const char* className() const { return "IndexedGeometry"; } - - virtual IndexedGeometry* asIndexedGeometry() { return this; } - virtual const IndexedGeometry* asIndexedGeometry() const { return this; } - - enum AttributeBinding - { - BIND_OFF=0, - BIND_OVERALL, - BIND_PER_PRIMITIVE_SET, - BIND_PER_PRIMITIVE, - BIND_PER_VERTEX - }; - - void setVertexArray(Vec3Array* array) { _vertexArray = array; dirtyDisplayList(); dirtyBound(); } - Vec3Array* getVertexArray() { return _vertexArray.get(); } - const Vec3Array* getVertexArray() const { return _vertexArray.get(); } - - void setVertexIndices(IndexArray* array) { _vertexIndices = array; dirtyDisplayList(); dirtyBound(); } - IndexArray* getVertexIndices() { return _vertexIndices.get(); } - const IndexArray* getVertexIndices() const { return _vertexIndices.get(); } - - - void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; dirtyDisplayList(); } - AttributeBinding getNormalBinding() const { return _normalBinding; } - - void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; dirtyDisplayList(); } - Vec3Array* getNormalArray() { return _normalArray.get(); } - const Vec3Array* getNormalArray() const { return _normalArray.get(); } - - void setNormalIndices(IndexArray* array) { _normalIndices = array; dirtyDisplayList(); } - IndexArray* getNormalIndices() { return _normalIndices.get(); } - const IndexArray* getNormalIndices() const { return _normalIndices.get(); } - - - void setColorBinding(AttributeBinding ab) { _colorBinding = ab; } - AttributeBinding getColorBinding() const { return _colorBinding; } - - void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; dirtyDisplayList(); } - Array* getColorArray() { return _colorArray.get(); } - const Array* getColorArray() const { return _colorArray.get(); } - - void setColorIndices(IndexArray* array) { _colorIndices = array; dirtyDisplayList(); } - IndexArray* getColorIndices() { return _colorIndices.get(); } - const IndexArray* getColorIndices() const { return _colorIndices.get(); } - - - void setSecondaryColorBinding(AttributeBinding ab) { _secondaryColorBinding = ab; } - AttributeBinding getSecondaryColorBinding() const { return _secondaryColorBinding; } - - void setSecondaryColorArray(Array* array) { _secondaryColorArray = array; if (!_secondaryColorArray.valid()) _secondaryColorBinding=BIND_OFF; dirtyDisplayList(); } - Array* getSecondaryColorArray() { return _secondaryColorArray.get(); } - const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); } - - void setSecondaryColorIndices(IndexArray* array) { _secondaryColorIndices = array; dirtyDisplayList(); } - IndexArray* getSecondaryColorIndices() { return _secondaryColorIndices.get(); } - const IndexArray* getSecondaryColorIndices() const { return _secondaryColorIndices.get(); } - - - void setFogCoordBinding(AttributeBinding ab) { _fogCoordBinding = ab; } - AttributeBinding getFogCoordBinding() const { return _fogCoordBinding; } - - void setFogCoordArray(FloatArray* array) { _fogCoordArray = array; if (!_fogCoordArray.valid()) _fogCoordBinding=BIND_OFF; dirtyDisplayList(); } - FloatArray* getFogCoordArray() { return _fogCoordArray.get(); } - const FloatArray* getFogCoordArray() const { return _fogCoordArray.get(); } - - - void setFogCoordIndices(IndexArray* array) { _fogCoordIndices = array; dirtyDisplayList(); } - IndexArray* getFogCoordIndices() { return _fogCoordIndices.get(); } - const IndexArray* getFogCoordIndices() const { return _fogCoordIndices.get(); } - - - - typedef std::pair< ref_ptr, ref_ptr > TexCoordArrayPair; - typedef std::vector< TexCoordArrayPair > TexCoordArrayList; - - - void setTexCoordArray(unsigned int unit,Array*); - Array* getTexCoordArray(unsigned int unit); - const Array* getTexCoordArray(unsigned int unit) const; - - void setTexCoordIndices(unsigned int unit,IndexArray*); - IndexArray* getTexCoordIndices(unsigned int unit); - const IndexArray* getTexCoordIndices(unsigned int unit) const; - - unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); } - TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; } - const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; } - - - typedef std::vector< ref_ptr > PrimitiveSetList; - - void setPrimitiveSetList(const PrimitiveSetList& primitives) { _primitives = primitives; dirtyDisplayList(); dirtyBound(); } - PrimitiveSetList& getPrimitiveSetList() { return _primitives; } - const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; } - - unsigned int getNumPrimitiveSet() const { return _primitives.size(); } - PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); } - const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); } - - void addPrimitiveSet(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); dirtyBound(); } - - - bool verifyBindings() const; - - void computeCorrectBindingsAndArraySizes(); - - - /** draw IndexedGeometry 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 IndexedGeometry for user-drawn objects. - */ - 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: - - IndexedGeometry& operator = (const IndexedGeometry&) { return *this;} - - virtual ~IndexedGeometry(); - - PrimitiveSetList _primitives; - - ref_ptr _vertexArray; - ref_ptr _vertexIndices; - - AttributeBinding _normalBinding; - ref_ptr _normalArray; - ref_ptr _normalIndices; - - AttributeBinding _colorBinding; - ref_ptr _colorArray; - ref_ptr _colorIndices; - - AttributeBinding _secondaryColorBinding; - ref_ptr _secondaryColorArray; - ref_ptr _secondaryColorIndices; - - AttributeBinding _fogCoordBinding; - ref_ptr _fogCoordArray; - ref_ptr _fogCoordIndices; - - TexCoordArrayList _texCoordList; - -}; - - -} - -#endif diff --git a/src/Demos/osgbillboard/osgbillboard.cpp b/src/Demos/osgbillboard/osgbillboard.cpp index a2dd1b9ec..f4a589d15 100644 --- a/src/Demos/osgbillboard/osgbillboard.cpp +++ b/src/Demos/osgbillboard/osgbillboard.cpp @@ -54,7 +54,7 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const (*tcoords)[3].set(0.0f,1.0f); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); if (image) { @@ -98,7 +98,7 @@ osg::Drawable* createAxis(const osg::Vec3& corner,const osg::Vec3& xdir,const os geom->setColorArray(color); geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); osg::StateSet* stateset = new osg::StateSet; osg::LineWidth* linewidth = new osg::LineWidth(); diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index 01033069c..f54b42578 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -82,12 +82,12 @@ osg::Geode* createGeometryCube() // set up the primitives - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,4,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,8,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,12,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,16,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,20,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,4,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,8,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,12,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,16,4)); + cube->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::POLYGON,20,4)); // set up coords. diff --git a/src/Demos/osggeometry/osggeometry.cpp b/src/Demos/osggeometry/osggeometry.cpp index 6c471cb8f..eb4a62d3d 100644 --- a/src/Demos/osggeometry/osggeometry.cpp +++ b/src/Demos/osggeometry/osggeometry.cpp @@ -7,6 +7,7 @@ #include #include +#include #include @@ -116,7 +117,7 @@ osg::Node* createScene() // in this case is POINTS (which has the same value GL_POINTS), the second // parameter is the index position into the vertex array of the first point // to draw, and the third parameter is the number of points to draw. - pointsGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,vertices->size())); + pointsGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,vertices->size())); // add the points geomtry to the geode. @@ -161,7 +162,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8)); + linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8)); // add the points geomtry to the geode. @@ -203,7 +204,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,5)); + linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,5)); // add the points geomtry to the geode. @@ -250,7 +251,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,numCoords)); + linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,numCoords)); // add the points geomtry to the geode. @@ -322,7 +323,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords)); printTriangles("Polygon",*polyGeom); @@ -369,7 +370,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords)); printTriangles("Quads",*polyGeom); @@ -418,7 +419,7 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,numCoords)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,numCoords)); printTriangles("Quads strip",*polyGeom); @@ -486,9 +487,9 @@ osg::Node* createScene() // This time we simply use primitive, and hardwire the number of coords to use // since we know up front, - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6)); - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,6,6)); - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,12,5)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,6)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,6,6)); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,12,5)); // polygon stipple osg::StateSet* stateSet = new osg::StateSet(); @@ -604,7 +605,7 @@ osg::Node* createBackground() // contains unsigned char indicies, UShortDrawElements which contains unsigned short indices, // and UIntDrawElements whcih contains ... unsigned int indices. // The first parameter to DrawElements is - polyGeom->addPrimitive(new osg::DrawElementsUShort(osg::PrimitiveSet::QUADS,numIndices,myIndices)); + polyGeom->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::QUADS,numIndices,myIndices)); // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture2D StateAttribute. @@ -662,6 +663,8 @@ int main( int argc, char **argv ) root->addChild( createScene() ); root->addChild( createBackground() ); + osgDB::writeNodeFile(*root,"geoemtry.osg"); + // add model to viewer. viewer.addViewport( root ); diff --git a/src/Demos/osghangglide/base.cpp b/src/Demos/osghangglide/base.cpp index e4a4e27e7..9775ad7a5 100644 --- a/src/Demos/osghangglide/base.cpp +++ b/src/Demos/osghangglide/base.cpp @@ -46,7 +46,7 @@ Node *makeBase( void ) geom->setColorArray( colors ); geom->setColorBinding( Geometry::BIND_OVERALL ); - geom->addPrimitive( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) ); + geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) ); Texture2D *tex = new Texture2D; diff --git a/src/Demos/osghangglide/sky.cpp b/src/Demos/osghangglide/sky.cpp index 140185e9a..a24a9a004 100644 --- a/src/Demos/osghangglide/sky.cpp +++ b/src/Demos/osghangglide/sky.cpp @@ -84,7 +84,7 @@ Node *makeSky( void ) drawElements->push_back((i+0)*19+j); } - geom->addPrimitive(drawElements); + geom->addPrimitiveSet(drawElements); } geom->setVertexArray( &coords ); diff --git a/src/Demos/osghangglide/tank.cpp b/src/Demos/osghangglide/tank.cpp index f5f1454f3..b6e404477 100644 --- a/src/Demos/osghangglide/tank.cpp +++ b/src/Demos/osghangglide/tank.cpp @@ -102,7 +102,7 @@ Node *makeTank( void ) c++; } - gset->addPrimitive( new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,0,c) ); + gset->addPrimitiveSet( new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,0,c) ); // create the top of the tank. @@ -144,7 +144,7 @@ Node *makeTank( void ) for( i = 0; i < c; i++ ) conv( vc[i], *mat, vc[i] ); - gset->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c)); + gset->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c)); diff --git a/src/Demos/osghangglide/terrain.cpp b/src/Demos/osghangglide/terrain.cpp index 17aa89195..6d9b8eb14 100644 --- a/src/Demos/osghangglide/terrain.cpp +++ b/src/Demos/osghangglide/terrain.cpp @@ -106,7 +106,7 @@ Node *makeTerrain( void ) elements->push_back((i+0)*n+j); elements->push_back((i+1)*n+j); } - geom->addPrimitive(elements); + geom->addPrimitiveSet(elements); } diff --git a/src/Demos/osghangglide/trees.cpp b/src/Demos/osghangglide/trees.cpp index 94161060b..c38abb8ff 100644 --- a/src/Demos/osghangglide/trees.cpp +++ b/src/Demos/osghangglide/trees.cpp @@ -183,7 +183,7 @@ static Geometry *makeTree( _tree *tree, StateSet *dstate ) geom->setColorArray( &l ); geom->setColorBinding( Geometry::BIND_OVERALL ); - geom->addPrimitive( new DrawArrays(PrimitiveSet::QUADS,0,4) ); + geom->addPrimitiveSet( new DrawArrays(PrimitiveSet::QUADS,0,4) ); geom->setStateSet( dstate ); diff --git a/src/Demos/osglight/osglight.cpp b/src/Demos/osglight/osglight.cpp index 9fea4db53..b555dafa5 100644 --- a/src/Demos/osglight/osglight.cpp +++ b/src/Demos/osglight/osglight.cpp @@ -132,7 +132,7 @@ osg::Node* createLights(osg::BoundingBox& bb,osg::StateSet* rootStateSet) osg::Vec3Array* vertices = new osg::Vec3Array; vertices->push_back(osg::Vec3(0.0,0.0,0.0)); marker->setVertexArray(vertices); - marker->addPrimitive(new osg::DrawArrays(GL_POINTS,0,1)); + marker->addPrimitiveSet(new osg::DrawArrays(GL_POINTS,0,1)); osg::StateSet* stateset = new osg::StateSet; osg::Point* point = new osg::Point; @@ -200,7 +200,7 @@ osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec quadstrip->push_back((row+1)*noXSteps+col); quadstrip->push_back(row*noXSteps+col); } - geom->addPrimitive(quadstrip); + geom->addPrimitiveSet(quadstrip); } // create the normals. diff --git a/src/Demos/osgoccluder/osgoccluder.cpp b/src/Demos/osgoccluder/osgoccluder.cpp index 46bf756e2..eab08ac1c 100644 --- a/src/Demos/osgoccluder/osgoccluder.cpp +++ b/src/Demos/osgoccluder/osgoccluder.cpp @@ -250,7 +250,7 @@ osg::Node* createOccluder(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); osg::Geode* geode = osgNew osg::Geode; geode->addDrawable(geom); diff --git a/src/Demos/osgprerender/osgprerender.cpp b/src/Demos/osgprerender/osgprerender.cpp index 4a50eda86..7c7326c5a 100644 --- a/src/Demos/osgprerender/osgprerender.cpp +++ b/src/Demos/osgprerender/osgprerender.cpp @@ -518,7 +518,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph) polyGeom->setColorArray(colors); polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); - polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size())); + polyGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size())); // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture StateAttribute. diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index e709389d8..20d6e5f0e 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -92,7 +92,7 @@ osg::Drawable* createMirrorSurface(float xMin,float xMax,float yMin,float yMax,f geom->setColorArray(colours); geom->setColorBinding(osg::Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/Demos/osgtexture2D/osgtexture2D.cpp b/src/Demos/osgtexture2D/osgtexture2D.cpp index 9d46b65e0..e086ef5a9 100644 --- a/src/Demos/osgtexture2D/osgtexture2D.cpp +++ b/src/Demos/osgtexture2D/osgtexture2D.cpp @@ -122,7 +122,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) (*tcoords)[3].set(textureCoordMax,textureCoordMax); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/Demos/osgtexture3D/osgtexture3D.cpp b/src/Demos/osgtexture3D/osgtexture3D.cpp index a142f05c6..bcb39d635 100644 --- a/src/Demos/osgtexture3D/osgtexture3D.cpp +++ b/src/Demos/osgtexture3D/osgtexture3D.cpp @@ -166,7 +166,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) (*tcoords)[3].set(textureCoordMax,textureCoordMax); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/Demos/sgv/sgv.cpp b/src/Demos/sgv/sgv.cpp index b5de87732..f50c952b3 100644 --- a/src/Demos/sgv/sgv.cpp +++ b/src/Demos/sgv/sgv.cpp @@ -140,8 +140,8 @@ int main( int argc, char **argv ) osgUtil::RenderStage* renderstage = viewer.getViewportSceneView(0)->getRenderStage(); if (renderstage) { - renderstage->setSortLocalCallback(new MySortCallback); -// renderstage->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK); +// renderstage->setSortLocalCallback(new MySortCallback); + renderstage->setSortMode(osgUtil::RenderBin::SORT_FRONT_TO_BACK); } diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index 115a909be..fb5ac45e1 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -9,11 +9,8 @@ #include #include -#include #include -//#include - using namespace osg; GeoSet::GeoSet() @@ -945,19 +942,13 @@ Geometry* GeoSet::convertToGeometry() { // will need to add flat shading to primitive. - StateSet* stateset = geom->getStateSet(); - if (!stateset) - { - stateset = osgNew StateSet; - geom->setStateSet(stateset); - } + StateSet* stateset = geom->getOrCreateStateSet(); ShadeModel* shademodel = dynamic_cast(stateset->getAttribute(StateAttribute::SHADEMODEL)); if (!shademodel) { shademodel = osgNew osg::ShadeModel; - stateset->setAttribute(shademodel,StateAttribute::OVERRIDE); + stateset->setAttribute(shademodel); } - shademodel->setMode( ShadeModel::FLAT ); } @@ -999,378 +990,6 @@ Geometry* GeoSet::convertToGeometry() break; } - - if (_fast_path) - { - // will easily convert into a Geometry. - - if (_coords) geom->setVertexArray(osgNew Vec3Array(_numcoords,_coords)); - - if (_normals) geom->setNormalArray(osgNew Vec3Array(_numnormals,_normals)); - - if (_colors) geom->setColorArray(osgNew Vec4Array(_numcolors,_colors)); - - if (_tcoords) geom->setTexCoordArray(0,osgNew Vec2Array(_numtcoords,_tcoords)); - - if( _needprimlen ) // LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP, - // TRIANGLE_FAN, QUAD_STRIP, POLYGONS - { - int index = 0; - if( _primLengths == (int *)0 ) - { - return 0; - } - - if( _cindex.valid() ) - { - - for( int i = 0; i < _numprims; i++ ) - { - DrawElementsUShort* n = new DrawElementsUShort; - geom->addPrimitive(n); - - if (_cindex._is_ushort) - geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] )); - else - geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _primLengths[i], &_cindex._ptr._uint[index] )); - - index += _primLengths[i]; - } - } - else - { - if (_numprims==1) - { - DrawArrays* da = new DrawArrays(_oglprimtype,0,_primLengths[0]); - geom->addPrimitive(da); - } - else - { - DrawArrayLengths* dal = new DrawArrayLengths(_oglprimtype,0,_numprims); - geom->addPrimitive(dal); - for( int i = 0; i < _numprims; i++ ) - { - (*dal)[i] = _primLengths[i]; - index += _primLengths[i]; - } - } - - } - - } - else // POINTS, LINES, TRIANGLES, QUADS - { - if( _cindex.valid()) - { - if (_cindex._is_ushort) - geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort )); - else - geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint )); - } - else - geom->addPrimitive(new DrawArrays( (GLenum)_oglprimtype, 0, _numcoords )); - } - - - } - else if( _needprimlen ) - { - // slow path, and needing handling of primlen array. - // - // LINE_STRIP, LINE_LOOP, TRIANGLE_STRIP, - // TRIANGLE_FAN, QUAD_STRIP, POLYGONS - // FLAT_LINE_STRIP, FLAT_TRIANGLE_STRIP, FLAT_TRIANGLE_FAN - - int i, j; - int index = 0; - int ai = 0; - int ci = 0; - int ni = 0; - int ti = 0; - - if( _primLengths == (int *)0 ) - { - return 0; - } - - - Vec3Array* coords = osgNew Vec3Array; - Vec3Array* normals = 0; - Vec4Array* colors = 0; - Vec2Array* texcoords = 0; - - if (_colors) colors = osgNew Vec4Array; - if (_normals) normals = osgNew Vec3Array; - if (_tcoords) texcoords = osgNew Vec2Array; - - geom->setVertexArray(coords); - geom->setColorArray(colors); - geom->setNormalArray(normals); - geom->setTexCoordArray(0,texcoords); - - if (_color_binding == BIND_OVERALL) - { - if( _colindex.valid() ) - colors->push_back( _colors[_colindex[0]] ); - else - colors->push_back( _colors[0] ); - } - - if (_normal_binding == BIND_OVERALL) - { - if( _nindex.valid() ) - normals->push_back( _normals[0] ); - else - normals->push_back( _normals[0] ); - } - - for( i = 0; i < _numprims; i++ ) - { - if (_color_binding == BIND_PERPRIM && colors) - { - if( _colindex.valid() ) - colors->push_back( _colors[_colindex[ci++]] ); - else - colors->push_back( _colors[ci++] ); - } - - if (_normal_binding == BIND_PERPRIM && normals) - { - if( _nindex.valid() ) - normals->push_back( _normals[_nindex[ni++]] ); - else - normals->push_back( _normals[ni++] ); - } - - unsigned int first = coords->size(); - unsigned int count = 0; - - - for( j = 0; j < _primLengths[i]; j++ ) - { - if( j >= _flat_shaded_skip ) - { - if( _color_binding == BIND_PERVERTEX && colors) - { - if( (_colindex.valid()) ) - colors->push_back( _colors[_colindex[ci++]] ); - else - colors->push_back( _colors[ci++] ); - } - - if( _normal_binding == BIND_PERVERTEX && normals) - { - if(_nindex.valid()) - normals->push_back( _normals[_nindex[ni++]] ); - else - normals->push_back( _normals[ni++] ); - } - } - else - { - // note don't increment ci & ni as we want to make multiple copies it when in _flat_shaded_skip - if( _color_binding == BIND_PERVERTEX && colors) - { - if( (_colindex.valid()) ) - colors->push_back( _colors[_colindex[ci]] ); - else - colors->push_back( _colors[ci] ); - } - - if( _normal_binding == BIND_PERVERTEX && normals ) - { - if(_nindex.valid()) - normals->push_back( _normals[_nindex[ni]] ); - else - normals->push_back( _normals[ni] ); - } - } - - if( _texture_binding == BIND_PERVERTEX && texcoords) - { - if( _tindex.valid() ) - texcoords->push_back( _tcoords[_tindex[ti++]] ); - else - texcoords->push_back( _tcoords[ti++] ); - } - - if( _cindex.valid() ) - coords->push_back( _coords[_cindex[ai++]] ); - else - coords->push_back( _coords[ai++] ); - - ++count; - - } - - geom->addPrimitive(osgNew DrawArrays(_oglprimtype,first,count)); - - index += _primLengths[i]; - } - - - } - else - { - // POINTS, LINES, TRIANGLES, QUADS - - Vec3Array* coords = osgNew Vec3Array; - Vec3Array* normals = 0; - Vec4Array* colors = 0; - Vec2Array* texcoords = 0; - - if (_colors) colors = osgNew Vec4Array; - if (_normals) normals = osgNew Vec3Array; - if (_tcoords) texcoords = osgNew Vec2Array; - - geom->setVertexArray(coords); - geom->setColorArray(colors); - geom->setNormalArray(normals); - geom->setTexCoordArray(0,texcoords); - - if (_color_binding == BIND_OVERALL) - { - if( _colindex.valid() ) - colors->push_back( _colors[_colindex[0]] ); - else - colors->push_back( _colors[0] ); - } - - if (_normal_binding == BIND_OVERALL) - { - if( _nindex.valid() ) - normals->push_back( _normals[_nindex[0]] ); - else - normals->push_back( _normals[0] ); - } - - for(int i = 0; i < _numprims; i++ ) - { - if (_color_binding == BIND_PERPRIM && colors) - { - if( _colindex.valid() ) - colors->push_back( _colors[_colindex[i]] ); - else - colors->push_back( _colors[i] ); - } - - if (_normal_binding == BIND_PERPRIM && normals) - { - if( _nindex.valid() ) - normals->push_back( _normals[_nindex[i]] ); - else - normals->push_back( _normals[i] ); - } - - unsigned int first = coords->size(); - unsigned int count = 0; - - for(int j = 0; j < _primlength; j++ ) - { - if( _color_binding == BIND_PERVERTEX && colors) - { - if( (_colindex.valid()) ) - colors->push_back( _colors[_colindex[i*_primlength+j]] ); - else - colors->push_back( _colors[i*_primlength+j] ); - } - - if( _normal_binding == BIND_PERVERTEX && normals ) - { - if(_nindex.valid()) - normals->push_back( _normals[_nindex[i*_primlength+j]] ); - else - normals->push_back( _normals[i*_primlength+j] ); - } - - if( _texture_binding == BIND_PERVERTEX && texcoords) - { - if( _tindex.valid() ) - texcoords->push_back( _tcoords[_tindex[i*_primlength+j]] ); - else - texcoords->push_back( _tcoords[i*_primlength+j] ); - } - - if( _cindex.valid() ) - coords->push_back( _coords[_cindex[i*_primlength+j]] ); - else - coords->push_back( _coords[i*_primlength+j] ); - - ++count; - } - - geom->addPrimitive(osgNew DrawArrays(_oglprimtype,first,count)); - - } - - } - - - return geom.take(); - - -} - -IndexedGeometry* GeoSet::convertToIndexedGeometry() -{ - set_fast_path(); - computeNumVerts(); - - ref_ptr geom = osgNew IndexedGeometry; - geom->setStateSet(getStateSet()); - - if (_flat_shaded_skip) - { - // will need to add flat shading to primitive. - - StateSet* stateset = geom->getOrCreateStateSet(); - ShadeModel* shademodel = dynamic_cast(stateset->getAttribute(StateAttribute::SHADEMODEL)); - if (!shademodel) - { - shademodel = osgNew osg::ShadeModel; - stateset->setAttribute(shademodel); - } - shademodel->setMode( ShadeModel::FLAT ); - } - - switch(_normal_binding) - { - case(BIND_OFF): - geom->setNormalBinding(IndexedGeometry::BIND_OFF); - break; - case(BIND_OVERALL): - geom->setNormalBinding(IndexedGeometry::BIND_OVERALL); - break; - case(BIND_PERPRIM): - geom->setNormalBinding(IndexedGeometry::BIND_PER_PRIMITIVE); - break; - case(BIND_PERVERTEX): - geom->setNormalBinding(IndexedGeometry::BIND_PER_VERTEX); - break; - default: - geom->setNormalBinding(IndexedGeometry::BIND_OFF); - break; - } - - switch(_color_binding) - { - case(BIND_OFF): - geom->setColorBinding(IndexedGeometry::BIND_OFF); - break; - case(BIND_OVERALL): - geom->setColorBinding(IndexedGeometry::BIND_OVERALL); - break; - case(BIND_PERPRIM): - geom->setColorBinding(IndexedGeometry::BIND_PER_PRIMITIVE); - break; - case(BIND_PERVERTEX): - geom->setColorBinding(IndexedGeometry::BIND_PER_VERTEX); - break; - default: - geom->setColorBinding(IndexedGeometry::BIND_OFF); - break; - } - if (_coords) { geom->setVertexArray(osgNew Vec3Array(_numcoords,_coords)); @@ -1542,6 +1161,3 @@ IndexedGeometry* GeoSet::convertToIndexedGeometry() } - - - diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 7f111b37d..499dc8aef 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -4,12 +4,190 @@ using namespace osg; +class DrawVertex +{ + public: + + DrawVertex(const Vec3Array* vertices,const IndexArray* indices): + _vertices(vertices), + _indices(indices) {} + + void operator () (unsigned int pos) + { + if (_indices) glVertex3fv((*_vertices)[_indices->index(pos)].ptr()); + else glVertex3fv((*_vertices)[pos].ptr()); + } + + const Vec3Array* _vertices; + const IndexArray* _indices; +}; + +class DrawNormal +{ + public: + + DrawNormal(const Vec3Array* normals,const IndexArray* indices): + _normals(normals), + _indices(indices) {} + + void operator () (unsigned int pos) + { + if (_indices) glNormal3fv((*_normals)[_indices->index(pos)].ptr()); + else glNormal3fv((*_normals)[pos].ptr()); + } + + const Vec3Array* _normals; + const IndexArray* _indices; +}; + +class DrawColor : public osg::ConstValueVisitor +{ + public: + + DrawColor(const Array* colors,const IndexArray* indices): + _colors(colors), + _indices(indices) {} + + void operator () (unsigned int pos) + { + if (_indices) _colors->accept(_indices->index(pos),*this); + else _colors->accept(pos,*this); + } + + virtual void apply(const UByte4& v) { glColor4ubv(v.ptr()); } + virtual void apply(const Vec3& v) { glColor3fv(v.ptr()); } + virtual void apply(const Vec4& v) { glColor4fv(v.ptr()); } + + const Array* _colors; + const IndexArray* _indices; +}; + +class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor +{ + public: + + DrawTexCoord(const Array* texcoords,const IndexArray* indices): + _texcoords(texcoords), + _indices(indices) {} + + void operator () (unsigned int pos) + { + if (_indices) _texcoords->accept(_indices->index(pos),*this); + else _texcoords->accept(pos,*this); + } + + virtual void apply(const GLfloat& v){ glTexCoord1f(v); } + virtual void apply(const Vec2& v) { glTexCoord2fv(v.ptr()); } + virtual void apply(const Vec3& v) { glTexCoord3fv(v.ptr()); } + virtual void apply(const Vec4& v) { glTexCoord4fv(v.ptr()); } + + const Array* _texcoords; + const IndexArray* _indices; +}; + +typedef void (APIENTRY * MultiTexCoord1fProc) (GLenum target,GLfloat coord); +typedef void (APIENTRY * MultiTexCoordfvProc) (GLenum target,const GLfloat* coord); +class DrawMultiTexCoord : public osg::Referenced, public osg::ConstValueVisitor +{ + public: + + DrawMultiTexCoord(GLenum target,const Array* texcoords,const IndexArray* indices, + MultiTexCoord1fProc glMultiTexCoord1f, + MultiTexCoordfvProc glMultiTexCoord2fv, + MultiTexCoordfvProc glMultiTexCoord3fv, + MultiTexCoordfvProc glMultiTexCoord4fv): + _target(target), + _texcoords(texcoords), + _indices(indices), + _glMultiTexCoord1f(glMultiTexCoord1f), + _glMultiTexCoord2fv(glMultiTexCoord2fv), + _glMultiTexCoord3fv(glMultiTexCoord3fv), + _glMultiTexCoord4fv(glMultiTexCoord4fv) {} + + void operator () (unsigned int pos) + { + if (_indices) _texcoords->accept(_indices->index(pos),*this); + else _texcoords->accept(pos,*this); + } + + virtual void apply(const GLfloat& v){ _glMultiTexCoord1f(_target,v); } + virtual void apply(const Vec2& v) { _glMultiTexCoord2fv(_target,v.ptr()); } + virtual void apply(const Vec3& v) { _glMultiTexCoord3fv(_target,v.ptr()); } + virtual void apply(const Vec4& v) { _glMultiTexCoord4fv(_target,v.ptr()); } + + GLenum _target; + const Array* _texcoords; + const IndexArray* _indices; + MultiTexCoord1fProc _glMultiTexCoord1f; + MultiTexCoordfvProc _glMultiTexCoord2fv; + MultiTexCoordfvProc _glMultiTexCoord3fv; + MultiTexCoordfvProc _glMultiTexCoord4fv; +}; + + +typedef void (APIENTRY * SecondaryColor3ubvProc) (const GLubyte* coord); +typedef void (APIENTRY * SecondaryColor3fvProc) (const GLfloat* coord); +class DrawSecondaryColor : public osg::ConstValueVisitor +{ + public: + + DrawSecondaryColor(const Array* colors,const IndexArray* indices, + SecondaryColor3ubvProc sc3ubv,SecondaryColor3fvProc sc3fv): + _colors(colors), + _indices(indices), + _glSecondaryColor3ubv(sc3ubv), + _glSecondaryColor3fv(sc3fv) {} + + void operator () (unsigned int pos) + { + if (_indices) _colors->accept(_indices->index(pos),*this); + else _colors->accept(pos,*this); + } + + virtual void apply(const UByte4& v) { _glSecondaryColor3ubv(v.ptr()); } + virtual void apply(const Vec3& v) { _glSecondaryColor3fv(v.ptr()); } + virtual void apply(const Vec4& v) { _glSecondaryColor3fv(v.ptr()); } + + const Array* _colors; + const IndexArray* _indices; + + SecondaryColor3ubvProc _glSecondaryColor3ubv; + SecondaryColor3fvProc _glSecondaryColor3fv; +}; + +typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); +class DrawFogCoord : public osg::ConstValueVisitor +{ + public: + + DrawFogCoord(const FloatArray* fogcoords,const IndexArray* indices, + FogCoordProc fogCoordProc): + _fogcoords(fogcoords), + _indices(indices), + _glFogCoord1fv(fogCoordProc) {} + + void operator () (unsigned int pos) + { + if (_indices) _glFogCoord1fv(&(*_fogcoords)[_indices->index(pos)]); + else _glFogCoord1fv(&(*_fogcoords)[pos]); + } + + const FloatArray* _fogcoords; + const IndexArray* _indices; + + FogCoordProc _glFogCoord1fv; +}; + + Geometry::Geometry() { _normalBinding = BIND_OFF; _colorBinding = BIND_OFF; _secondaryColorBinding = BIND_OFF; _fogCoordBinding = BIND_OFF; + + _fastPathComputed = false; + _fastPath = false; } Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): @@ -22,9 +200,11 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): _secondaryColorBinding(geometry._secondaryColorBinding), _secondaryColorArray(copyop(geometry._secondaryColorArray.get())), _fogCoordBinding(geometry._fogCoordBinding), - _fogCoordArray(dynamic_cast(copyop(geometry._fogCoordArray.get()))) + _fogCoordArray(dynamic_cast(copyop(geometry._fogCoordArray.get()))), + _fastPathComputed(geometry._fastPathComputed), + _fastPath(geometry._fastPath) { - for(PrimitiveList::const_iterator pitr=geometry._primitives.begin(); + for(PrimitiveSetList::const_iterator pitr=geometry._primitives.begin(); pitr!=geometry._primitives.end(); ++pitr) { @@ -36,7 +216,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): titr!=geometry._texCoordList.end(); ++titr) { - _texCoordList.push_back(copyop(titr->get())); + _texCoordList.push_back(*titr); } } @@ -48,335 +228,612 @@ Geometry::~Geometry() void Geometry::setTexCoordArray(unsigned int unit,Array* array) { if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1,0); + _texCoordList.resize(unit+1); - _texCoordList[unit] = array; + _texCoordList[unit].first = array; dirtyDisplayList(); } Array* Geometry::getTexCoordArray(unsigned int unit) { - if (unit<_texCoordList.size()) return _texCoordList[unit].get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); else return 0; } const Array* Geometry::getTexCoordArray(unsigned int unit) const { - if (unit<_texCoordList.size()) return _texCoordList[unit].get(); + if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); else return 0; } -void Geometry::drawImmediateMode(State& state) +void Geometry::setTexCoordIndices(unsigned int unit,IndexArray* array) { - if (!_vertexArray.valid()) return; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up the vertex arrays. - // - state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer()); - + if (_texCoordList.size()<=unit) + _texCoordList.resize(unit+1); + + _texCoordList[unit].second = array; + + dirtyDisplayList(); +} + +IndexArray* Geometry::getTexCoordIndices(unsigned int unit) +{ + if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); + else return 0; +} + +const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const +{ + if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); + else return 0; +} + +bool Geometry::areFastPathsUsed() const +{ + if (_fastPathComputed) return _fastPath; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up texture coordinates. - // - unsigned int i; - for(i=0;i<_texCoordList.size();++i) - { - Array* array = _texCoordList[i].get(); - if (array) - state.setTexCoordPointer(i,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - else - state.disableTexCoordPointer(i); - } - state.disableTexCoordPointersAboveAndIncluding(i); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // set up normals if required. // - Vec3* normalPointer = 0; - if (_normalArray.valid() && !_normalArray->empty()) normalPointer = &(_normalArray->front()); - - AttributeBinding normalBinding = _normalBinding; - if (normalBinding!=BIND_OFF && !normalPointer) + if (!_normalArray.valid() || + _normalArray->empty() || + (_normalIndices.valid() && _normalIndices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - normalBinding = BIND_OFF; - } - - switch (normalBinding) - { - case(BIND_OFF): - state.disableNormalPointer(); - break; - case(BIND_OVERALL): - state.disableNormalPointer(); - glNormal3fv(reinterpret_cast(normalPointer)); - break; - case(BIND_PER_PRIMITIVE): - state.disableNormalPointer(); - break; - case(BIND_PER_VERTEX): - state.setNormalPointer(GL_FLOAT,0,normalPointer); - break; + _normalBinding = BIND_OFF; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // - // Set up color if required. + // set up colours.. // - // set up colors, complicated by the fact that the color array - // might be bound in 4 different ways, and be represented as 3 different data types - - // Vec3, Vec4 or UByte4 Arrays. - // - const unsigned char* colorPointer = 0; - unsigned int colorStride = 0; - Array::Type colorType = Array::ArrayType; - if (_colorArray.valid()) - { - colorType = _colorArray->getType(); - switch(colorType) - { - case(Array::UByte4ArrayType): - { - colorPointer = reinterpret_cast(_colorArray->getDataPointer()); - colorStride = 4; - break; - } - case(Array::Vec3ArrayType): - { - colorPointer = reinterpret_cast(_colorArray->getDataPointer()); - colorStride = 12; - break; - } - case(Array::Vec4ArrayType): - { - colorPointer = reinterpret_cast(_colorArray->getDataPointer()); - colorStride = 16; - break; - } - default: - break; - } - } - - - AttributeBinding colorBinding = _colorBinding; - if (colorBinding!=BIND_OFF && !colorPointer) + if (!_colorArray.valid() || + _colorArray->getNumElements()==0 || + (_colorIndices.valid() && _colorIndices->getNumElements()==0) ) { // switch off if not supported or have a valid data. - colorBinding = BIND_OFF; + _colorBinding = BIND_OFF; } - switch (colorBinding) - { - case(BIND_OFF): - state.disableColorPointer(); - break; - case(BIND_OVERALL): - state.disableColorPointer(); - if (colorPointer) - { - switch(colorType) - { - case(Array::UByte4ArrayType): - glColor4ubv(reinterpret_cast(colorPointer)); - break; - case(Array::Vec3ArrayType): - glColor3fv(reinterpret_cast(colorPointer)); - break; - case(Array::Vec4ArrayType): - glColor4fv(reinterpret_cast(colorPointer)); - break; - default: - break; - } - } - break; - case(BIND_PER_PRIMITIVE): - state.disableColorPointer(); - break; - case(BIND_PER_VERTEX): - state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,colorPointer); - } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Set up secondary color if required. // - // set up colors, complicated by the fact that the color array - // might be bound in 4 different ways, and be represented as 3 different data types - - // Vec3, Vec4 or UByte4 Arrays. - const unsigned char* secondaryColorPointer = 0; - unsigned int secondaryColorStride = 0; - Array::Type secondaryColorType = Array::ArrayType; - if (_secondaryColorArray.valid()) + if (!_secondaryColorArray.valid() || + _secondaryColorArray->getNumElements()==0 || + (_secondaryColorIndices.valid() && _secondaryColorIndices->getNumElements()==0) ) { - secondaryColorType = _secondaryColorArray->getType(); - switch(secondaryColorType) + // switch off if not supported or have a valid data. + _secondaryColorBinding = BIND_OFF; + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up fog coord if required. + // + if (!_fogCoordArray.valid() || + _fogCoordArray->getNumElements()==0 || + (_fogCoordIndices.valid() && _fogCoordIndices->getNumElements()==0) ) + { + // switch off if not supported or have a valid data. + _fogCoordBinding = BIND_OFF; + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // check to see if fast path can be used. + // + _fastPath = true; + if (_normalBinding==BIND_PER_PRIMITIVE || (_normalBinding==BIND_PER_VERTEX && _normalIndices.valid())) _fastPath = false; + else if (_colorBinding==BIND_PER_PRIMITIVE || (_colorBinding==BIND_PER_VERTEX && _colorIndices.valid())) _fastPath = false; + else if (_secondaryColorBinding==BIND_PER_PRIMITIVE || (_secondaryColorBinding==BIND_PER_VERTEX && _secondaryColorIndices.valid())) _fastPath = false; + else if (_fogCoordBinding==BIND_PER_PRIMITIVE || (_fogCoordBinding==BIND_PER_VERTEX && _fogCoordIndices.valid())) _fastPath = false; + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up tex coords if required. + // + for(unsigned int unit=0;unit!=_texCoordList.size();++unit) + { + const TexCoordArrayPair& texcoordPair = _texCoordList[unit]; + if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) { - case(Array::UByte4ArrayType): + if (texcoordPair.second.valid()) { - secondaryColorPointer = reinterpret_cast(_secondaryColorArray->getDataPointer()); - secondaryColorStride = 4; - break; + if (texcoordPair.second->getNumElements()>0) + { + _fastPath = false; + } } - case(Array::Vec3ArrayType): - { - secondaryColorPointer = reinterpret_cast(_secondaryColorArray->getDataPointer()); - secondaryColorStride = 12; - break; - } - default: - break; } } + + _fastPathComputed = true; + + return _fastPath; +} + +void Geometry::drawImmediateMode(State& state) +{ + if (!_vertexArray.valid() || _vertexArray->getNumElements()==0) return; + if (_vertexIndices.valid() && _vertexIndices->getNumElements()==0) return; - typedef void (APIENTRY * SecondaryColor3ubvProc) (const GLubyte* coord); - typedef void (APIENTRY * SecondaryColor3fvProc) (const GLfloat* coord); + // set up extensions. static SecondaryColor3ubvProc s_glSecondaryColor3ubv = (SecondaryColor3ubvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT"); static SecondaryColor3fvProc s_glSecondaryColor3fv = (SecondaryColor3fvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3fv","glSecondaryColor3fvEXT"); + static FogCoordProc s_glFogCoordfv = + (FogCoordProc) osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT"); + + DrawNormal drawNormal(_normalArray.get(),_normalIndices.get()); + DrawColor drawColor(_colorArray.get(),_colorIndices.get()); + DrawSecondaryColor drawSecondaryColor(_secondaryColorArray.get(),_secondaryColorIndices.get(), + s_glSecondaryColor3ubv,s_glSecondaryColor3fv); + DrawFogCoord drawFogCoord(_fogCoordArray.get(),_fogCoordIndices.get(), + s_glFogCoordfv); + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up secondary color if required. + // AttributeBinding secondaryColorBinding = _secondaryColorBinding; - if (secondaryColorBinding!=BIND_OFF && (!secondaryColorPointer || !s_glSecondaryColor3ubv || !s_glSecondaryColor3fv)) + if (secondaryColorBinding!=BIND_OFF && (!s_glSecondaryColor3ubv || s_glSecondaryColor3fv)) { // switch off if not supported or have a valid data. secondaryColorBinding = BIND_OFF; } - - switch (secondaryColorBinding) - { - case(BIND_OFF): - state.disableSecondaryColorPointer(); - break; - case(BIND_OVERALL): - state.disableSecondaryColorPointer(); - if (secondaryColorPointer) - { - switch(secondaryColorType) - { - case(Array::UByte4ArrayType): - s_glSecondaryColor3ubv(reinterpret_cast(secondaryColorPointer)); - break; - case(Array::Vec3ArrayType): - s_glSecondaryColor3fv(reinterpret_cast(secondaryColorPointer)); - break; - default: - break; - } - } - break; - case(BIND_PER_PRIMITIVE): - state.disableSecondaryColorPointer(); - break; - case(BIND_PER_VERTEX): - state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,secondaryColorPointer); - } - - + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Set up fog coord if required. // - - GLfloat* fogCoordPointer = 0; - if (_fogCoordArray.valid() && !_fogCoordArray->empty()) fogCoordPointer = &(_fogCoordArray->front()); - - typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); - static FogCoordProc s_glFogCoordfv = - (FogCoordProc) osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT"); - - AttributeBinding fogCoordBinding = _fogCoordBinding; - if (fogCoordBinding!=BIND_OFF && (!fogCoordPointer || !s_glFogCoordfv)) + if (fogCoordBinding!=BIND_OFF && !s_glFogCoordfv) { - // swithc off if not supported or have a valid data. + // switch off if not supported or have a valid data. fogCoordBinding = BIND_OFF; } - - switch (fogCoordBinding) + + unsigned int normalIndex = 0; + unsigned int colorIndex = 0; + unsigned int secondaryColorIndex = 0; + unsigned int fogCoordIndex = 0; + + if (areFastPathsUsed()) { - case(BIND_OFF): + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // fast path. + // + + state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer()); + + if (_normalBinding==BIND_PER_VERTEX) + state.setNormalPointer(GL_FLOAT,0,_normalArray->getDataPointer()); + else + state.disableNormalPointer(); + + if (_colorBinding==BIND_PER_VERTEX) + state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,_colorArray->getDataPointer()); + else + state.disableColorPointer(); + + if (secondaryColorBinding==BIND_PER_VERTEX) + state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,_secondaryColorArray->getDataPointer()); + else + state.disableSecondaryColorPointer(); + + if (fogCoordBinding==BIND_PER_VERTEX) + state.setFogCoordPointer(GL_FLOAT,0,_fogCoordArray->getDataPointer()); + else state.disableFogCoordPointer(); - break; - case(BIND_OVERALL): - state.disableFogCoordPointer(); - s_glFogCoordfv(fogCoordPointer); - break; - case(BIND_PER_PRIMITIVE): - state.disableFogCoordPointer(); - break; - case(BIND_PER_VERTEX): - state.setFogCoordPointer(GL_FLOAT,0,fogCoordPointer); - break; + + unsigned int unit; + for(unit=0;unit<_texCoordList.size();++unit) + { + Array* array = _texCoordList[unit].first.get(); + if (array) + state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); + else + state.disableTexCoordPointer(unit); + } + state.disableTexCoordPointersAboveAndIncluding(unit); + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // pass the overall binding values onto OpenGL. + // + if (_normalBinding==BIND_OVERALL) drawNormal(normalIndex++); + if (_colorBinding==BIND_OVERALL) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // draw the primitives themselves. + // + for(PrimitiveSetList::iterator itr=_primitives.begin(); + itr!=_primitives.end(); + ++itr) + { + + if (_normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); + + (*itr)->draw(); + + } + } - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - - for(PrimitiveList::iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - if (normalBinding==BIND_PER_PRIMITIVE) + else + { + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // slow path. + // + + + // Set up tex coords if required. + static MultiTexCoord1fProc s_glMultiTexCoord1f = + (MultiTexCoord1fProc) osg::getGLExtensionFuncPtr("glMultiTexCoord1f","glMultiTexCoord1fARB"); + static MultiTexCoordfvProc s_glMultiTexCoord2fv = + (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord2fv","glMultiTexCoord2fvARB"); + static MultiTexCoordfvProc s_glMultiTexCoord3fv = + (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord3fv","glMultiTexCoord3fvARB"); + static MultiTexCoordfvProc s_glMultiTexCoord4fv = + (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord4fv","glMultiTexCoord4fvARB"); + + + typedef std::vector< ref_ptr > DrawTexCoordList; + DrawTexCoordList drawTexCoordList; + drawTexCoordList.reserve(_texCoordList.size()); + + // fallback if multitexturing not supported. + ref_ptr drawTextCoord; + + if (s_glMultiTexCoord2fv) { - glNormal3fv((const GLfloat *)normalPointer++); - } - - if (colorBinding==BIND_PER_PRIMITIVE) - { - switch(colorType) + // multitexture supported.. + for(unsigned int unit=0;unit!=_texCoordList.size();++unit) { - case(Array::UByte4ArrayType): - glColor4ubv(reinterpret_cast(colorPointer)); - break; - case(Array::Vec3ArrayType): - glColor3fv(reinterpret_cast(colorPointer)); - break; - case(Array::Vec4ArrayType): - glColor4fv(reinterpret_cast(colorPointer)); - break; - default: - break; + const TexCoordArrayPair& texcoordPair = _texCoordList[unit]; + if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) + { + if (texcoordPair.second.valid()) + { + if (texcoordPair.second->getNumElements()>0) + { + drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),texcoordPair.second.get(), + s_glMultiTexCoord1f, + s_glMultiTexCoord2fv, + s_glMultiTexCoord3fv, + s_glMultiTexCoord4fv)); + + } + } + else + { + drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),0, + s_glMultiTexCoord1f, + s_glMultiTexCoord2fv, + s_glMultiTexCoord3fv, + s_glMultiTexCoord4fv)); + } + } + } + } + else + { + if (!_texCoordList.empty()) + { + const TexCoordArrayPair& texcoordPair = _texCoordList[0]; + if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) + { + if (texcoordPair.second.valid()) + { + if (texcoordPair.second->getNumElements()>0) + { + drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),texcoordPair.second.get()); + } + } + else + { + drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),0); + } + } + } - colorPointer += colorStride; } - if (secondaryColorBinding==BIND_PER_PRIMITIVE) - { - switch(secondaryColorType) - { - case(Array::UByte4ArrayType): - s_glSecondaryColor3ubv(reinterpret_cast(secondaryColorPointer)); - break; - case(Array::Vec3ArrayType): - s_glSecondaryColor3fv(reinterpret_cast(secondaryColorPointer)); - break; - default: - break; - } - secondaryColorPointer += secondaryColorStride; - } + // disable all the vertex arrays in the slow path as we are + // sending everything using glVertex etc. + state.disableAllVertexArrays(); - if (fogCoordBinding==BIND_PER_PRIMITIVE) + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // pass the overall binding values onto OpenGL. + // + if (_normalBinding==BIND_OVERALL) drawNormal(normalIndex++); + if (_colorBinding==BIND_OVERALL) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); + + + // set up vertex functor. + DrawVertex drawVertex(_vertexArray.get(),_vertexIndices.get()); + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // draw the primitives themselves. + // + for(PrimitiveSetList::iterator itr=_primitives.begin(); + itr!=_primitives.end(); + ++itr) { - s_glFogCoordfv(fogCoordPointer++); - } + if (_normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); - (*itr)->draw(); + PrimitiveSet* primitiveset = itr->get(); + GLenum mode=primitiveset->getMode(); + + unsigned int primLength; + switch(mode) + { + case(GL_POINTS): primLength=1; break; + case(GL_LINES): primLength=2; break; + case(GL_TRIANGLES): primLength=3; break; + case(GL_QUADS): primLength=4; break; + default: primLength=0; break; // compute later when =0. + } + + + // draw primtives by the more flexible "slow" path, + // sending OpenGL glBegin/glVertex.../glEnd(). + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + if (primLength==0) primLength=primitiveset->getNumIndices(); + + const DrawArrays* drawArray = static_cast(primitiveset); + glBegin(mode); + + unsigned int primCount=0; + unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); + vindex(primitiveset); + unsigned int vindex=drawArrayLengths->getFirst(); + for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); + primItr!=drawArrayLengths->end(); + ++primItr) + { + unsigned int localPrimLength; + if (primLength==0) localPrimLength=*primItr; + else localPrimLength=primLength; + + glBegin(mode); + + for(GLsizei primCount=0;primCount<*primItr;++primCount) + { + if ((primCount%localPrimLength)==0) + { + if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); + } + + if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); + if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); + + for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); + texItr!=drawTexCoordList.end(); + ++texItr) + { + (*(*texItr))(vindex); + } + if (drawTextCoord.valid()) (*drawTextCoord)(vindex); + + drawVertex(vindex); + + ++vindex; + } + + glEnd(); + + } + break; + } + case(PrimitiveSet::DrawElementsUBytePrimitiveType): + { + if (primLength==0) primLength=primitiveset->getNumIndices(); + + const DrawElementsUByte* drawElements = static_cast(primitiveset); + glBegin(mode); + + unsigned int primCount=0; + for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount,++primItr) + { + + if ((primCount%primLength)==0) + { + if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); + } + + unsigned int vindex=*primItr; + + if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); + if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); + + for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); + texItr!=drawTexCoordList.end(); + ++texItr) + { + (*(*texItr))(vindex); + } + if (drawTextCoord.valid()) (*drawTextCoord)(vindex); + + drawVertex(vindex); + } + + glEnd(); + break; + } + case(PrimitiveSet::DrawElementsUShortPrimitiveType): + { + if (primLength==0) primLength=primitiveset->getNumIndices(); + + const DrawElementsUShort* drawElements = static_cast(primitiveset); + glBegin(mode); + + unsigned int primCount=0; + for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount,++primItr) + { + + if ((primCount%primLength)==0) + { + if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); + } + + unsigned int vindex=*primItr; + + if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); + if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); + + for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); + texItr!=drawTexCoordList.end(); + ++texItr) + { + (*(*texItr))(vindex); + } + if (drawTextCoord.valid()) (*drawTextCoord)(vindex); + + drawVertex(vindex); + } + + glEnd(); + break; + } + case(PrimitiveSet::DrawElementsUIntPrimitiveType): + { + if (primLength==0) primLength=primitiveset->getNumIndices(); + + const DrawElementsUInt* drawElements = static_cast(primitiveset); + glBegin(mode); + + unsigned int primCount=0; + for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount,++primItr) + { + + if ((primCount%primLength)==0) + { + if (_normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); + if (_colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); + if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); + if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); + } + + unsigned int vindex=*primItr; + + if (_normalBinding==BIND_PER_VERTEX) drawNormal(vindex); + if (_colorBinding==BIND_PER_VERTEX) drawColor(vindex); + if (secondaryColorBinding==BIND_PER_VERTEX) drawSecondaryColor(vindex); + if (fogCoordBinding==BIND_PER_VERTEX) drawFogCoord(vindex); + + for(DrawTexCoordList::iterator texItr=drawTexCoordList.begin(); + texItr!=drawTexCoordList.end(); + ++texItr) + { + (*(*texItr))(vindex); + } + if (drawTextCoord.valid()) (*drawTextCoord)(vindex); + + drawVertex(vindex); + } + + glEnd(); + break; + } + default: + { + break; + } + } + } } } @@ -402,7 +859,7 @@ void Geometry::accept(PrimitiveFunctor& functor) functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front())); - for(PrimitiveList::iterator itr=_primitives.begin(); + for(PrimitiveSetList::iterator itr=_primitives.begin(); itr!=_primitives.end(); ++itr) { @@ -411,26 +868,6 @@ void Geometry::accept(PrimitiveFunctor& functor) } -// just use the base Drawable's PrimitiveFunctor based implementation. -// const bool Geometry::computeBound() const -// { -// _bbox.init(); -// -// const Vec3Array* coords = dynamic_cast(_vertexArray.get()); -// if (coords) -// { -// for(Vec3Array::const_iterator itr=coords->begin(); -// itr!=coords->end(); -// ++itr) -// { -// _bbox.expandBy(*itr); -// } -// } -// _bbox_computed = true; -// -// return _bbox.valid(); -// } - bool Geometry::verifyBindings() const { switch(_normalBinding) @@ -442,6 +879,7 @@ bool Geometry::verifyBindings() const if (!_normalArray.valid()) return false; if (_normalArray->getNumElements()!=1) return false; break; + case(BIND_PER_PRIMITIVE_SET): case(BIND_PER_PRIMITIVE): if (!_normalArray.valid()) return false; if (_normalArray->getNumElements()!=_primitives.size()) return false; @@ -452,7 +890,7 @@ bool Geometry::verifyBindings() const if (!_normalArray.valid()) return false; if (_normalArray->getNumElements()!=_vertexArray->getNumElements()) return false; } - else if (_normalArray.valid() && _normalArray->getNumElements()>0) return false; + else if (_normalArray.valid() && _normalArray->getNumElements()==0) return false; break; } @@ -465,6 +903,7 @@ bool Geometry::verifyBindings() const if (!_colorArray.valid()) return false; if (_colorArray->getNumElements()!=1) return false; break; + case(BIND_PER_PRIMITIVE_SET): case(BIND_PER_PRIMITIVE): if (!_colorArray.valid()) return false; if (_colorArray->getNumElements()!=_primitives.size()) return false; @@ -475,7 +914,7 @@ bool Geometry::verifyBindings() const if (!_colorArray.valid()) return false; if (_colorArray->getNumElements()!=_vertexArray->getNumElements()) return false; } - else if (_colorArray.valid() && _colorArray->getNumElements()>0) return false; + else if (_colorArray.valid() && _colorArray->getNumElements()==0) return false; break; } @@ -483,12 +922,12 @@ bool Geometry::verifyBindings() const itr!=_texCoordList.end(); ++itr) { - const Array* array = itr->get(); + const Array* array = itr->first.get(); if (_vertexArray.valid()) { if (array && array->getNumElements()!=_vertexArray->getNumElements()) return false; } - else if (array && array->getNumElements()>0) return false; + else if (array && array->getNumElements()==0) return false; } return true; @@ -539,6 +978,7 @@ void Geometry::computeCorrectBindingsAndArraySizes() _normalArray->erase(_normalArray->begin()+1,_normalArray->end()); } break; + case(BIND_PER_PRIMITIVE_SET): case(BIND_PER_PRIMITIVE): if (!_normalArray.valid()) { diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index f835f40f1..931d58796 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -527,7 +527,7 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t) geom->setColorArray(colours); geom->setColorBinding(Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew DrawArrays(PrimitiveSet::QUADS,0,4)); + geom->addPrimitiveSet(osgNew DrawArrays(PrimitiveSet::QUADS,0,4)); // set up the geode. osg::Geode* geode = osgNew osg::Geode; diff --git a/src/osg/IndexedGeometry.cpp b/src/osg/IndexedGeometry.cpp deleted file mode 100644 index 11af1d75b..000000000 --- a/src/osg/IndexedGeometry.cpp +++ /dev/null @@ -1,951 +0,0 @@ -#include -#include -#include - -using namespace osg; - -class DrawVertex -{ - public: - - DrawVertex(const Vec3Array* vertices,const IndexArray* indices): - _vertices(vertices), - _indices(indices) {} - - void operator () (unsigned int pos) - { - if (_indices) glVertex3fv((*_vertices)[_indices->index(pos)].ptr()); - else glVertex3fv((*_vertices)[pos].ptr()); - } - - const Vec3Array* _vertices; - const IndexArray* _indices; -}; - -class DrawNormal -{ - public: - - DrawNormal(const Vec3Array* normals,const IndexArray* indices): - _normals(normals), - _indices(indices) {} - - void operator () (unsigned int pos) - { - if (_indices) glNormal3fv((*_normals)[_indices->index(pos)].ptr()); - else glNormal3fv((*_normals)[pos].ptr()); - } - - const Vec3Array* _normals; - const IndexArray* _indices; -}; - -class DrawColor : public osg::ConstValueVisitor -{ - public: - - DrawColor(const Array* colors,const IndexArray* indices): - _colors(colors), - _indices(indices) {} - - void operator () (unsigned int pos) - { - if (_indices) _colors->accept(_indices->index(pos),*this); - else _colors->accept(pos,*this); - } - - virtual void apply(const UByte4& v) { glColor4ubv(v.ptr()); } - virtual void apply(const Vec3& v) { glColor3fv(v.ptr()); } - virtual void apply(const Vec4& v) { glColor4fv(v.ptr()); } - - const Array* _colors; - const IndexArray* _indices; -}; - -class DrawTexCoord : public osg::Referenced, public osg::ConstValueVisitor -{ - public: - - DrawTexCoord(const Array* texcoords,const IndexArray* indices): - _texcoords(texcoords), - _indices(indices) {} - - void operator () (unsigned int pos) - { - if (_indices) _texcoords->accept(_indices->index(pos),*this); - else _texcoords->accept(pos,*this); - } - - virtual void apply(const GLfloat& v){ glTexCoord1f(v); } - virtual void apply(const Vec2& v) { glTexCoord2fv(v.ptr()); } - virtual void apply(const Vec3& v) { glTexCoord3fv(v.ptr()); } - virtual void apply(const Vec4& v) { glTexCoord4fv(v.ptr()); } - - const Array* _texcoords; - const IndexArray* _indices; -}; - -typedef void (APIENTRY * MultiTexCoord1fProc) (GLenum target,GLfloat coord); -typedef void (APIENTRY * MultiTexCoordfvProc) (GLenum target,const GLfloat* coord); -class DrawMultiTexCoord : public osg::Referenced, public osg::ConstValueVisitor -{ - public: - - DrawMultiTexCoord(GLenum target,const Array* texcoords,const IndexArray* indices, - MultiTexCoord1fProc glMultiTexCoord1f, - MultiTexCoordfvProc glMultiTexCoord2fv, - MultiTexCoordfvProc glMultiTexCoord3fv, - MultiTexCoordfvProc glMultiTexCoord4fv): - _target(target), - _texcoords(texcoords), - _indices(indices), - _glMultiTexCoord1f(glMultiTexCoord1f), - _glMultiTexCoord2fv(glMultiTexCoord2fv), - _glMultiTexCoord3fv(glMultiTexCoord3fv), - _glMultiTexCoord4fv(glMultiTexCoord4fv) {} - - void operator () (unsigned int pos) - { - if (_indices) _texcoords->accept(_indices->index(pos),*this); - else _texcoords->accept(pos,*this); - } - - virtual void apply(const GLfloat& v){ _glMultiTexCoord1f(_target,v); } - virtual void apply(const Vec2& v) { _glMultiTexCoord2fv(_target,v.ptr()); } - virtual void apply(const Vec3& v) { _glMultiTexCoord3fv(_target,v.ptr()); } - virtual void apply(const Vec4& v) { _glMultiTexCoord4fv(_target,v.ptr()); } - - GLenum _target; - const Array* _texcoords; - const IndexArray* _indices; - MultiTexCoord1fProc _glMultiTexCoord1f; - MultiTexCoordfvProc _glMultiTexCoord2fv; - MultiTexCoordfvProc _glMultiTexCoord3fv; - MultiTexCoordfvProc _glMultiTexCoord4fv; -}; - - -typedef void (APIENTRY * SecondaryColor3ubvProc) (const GLubyte* coord); -typedef void (APIENTRY * SecondaryColor3fvProc) (const GLfloat* coord); -class DrawSecondaryColor : public osg::ConstValueVisitor -{ - public: - - DrawSecondaryColor(const Array* colors,const IndexArray* indices, - SecondaryColor3ubvProc sc3ubv,SecondaryColor3fvProc sc3fv): - _colors(colors), - _indices(indices), - _glSecondaryColor3ubv(sc3ubv), - _glSecondaryColor3fv(sc3fv) {} - - void operator () (unsigned int pos) - { - if (_indices) _colors->accept(_indices->index(pos),*this); - else _colors->accept(pos,*this); - } - - virtual void apply(const UByte4& v) { _glSecondaryColor3ubv(v.ptr()); } - virtual void apply(const Vec3& v) { _glSecondaryColor3fv(v.ptr()); } - virtual void apply(const Vec4& v) { _glSecondaryColor3fv(v.ptr()); } - - const Array* _colors; - const IndexArray* _indices; - - SecondaryColor3ubvProc _glSecondaryColor3ubv; - SecondaryColor3fvProc _glSecondaryColor3fv; -}; - -typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); -class DrawFogCoord : public osg::ConstValueVisitor -{ - public: - - DrawFogCoord(const FloatArray* fogcoords,const IndexArray* indices, - FogCoordProc fogCoordProc): - _fogcoords(fogcoords), - _indices(indices), - _glFogCoord1fv(fogCoordProc) {} - - void operator () (unsigned int pos) - { - if (_indices) _glFogCoord1fv(&(*_fogcoords)[_indices->index(pos)]); - else _glFogCoord1fv(&(*_fogcoords)[pos]); - } - - const FloatArray* _fogcoords; - const IndexArray* _indices; - - FogCoordProc _glFogCoord1fv; -}; - - -IndexedGeometry::IndexedGeometry() -{ - _normalBinding = BIND_OFF; - _colorBinding = BIND_OFF; - _secondaryColorBinding = BIND_OFF; - _fogCoordBinding = BIND_OFF; -} - -IndexedGeometry::IndexedGeometry(const IndexedGeometry& geometry,const CopyOp& copyop): - Drawable(geometry,copyop), - _vertexArray(dynamic_cast(copyop(geometry._vertexArray.get()))), - _normalBinding(geometry._normalBinding), - _normalArray(dynamic_cast(copyop(geometry._normalArray.get()))), - _colorBinding(geometry._colorBinding), - _colorArray(copyop(geometry._colorArray.get())), - _secondaryColorBinding(geometry._secondaryColorBinding), - _secondaryColorArray(copyop(geometry._secondaryColorArray.get())), - _fogCoordBinding(geometry._fogCoordBinding), - _fogCoordArray(dynamic_cast(copyop(geometry._fogCoordArray.get()))) -{ - for(PrimitiveSetList::const_iterator pitr=geometry._primitives.begin(); - pitr!=geometry._primitives.end(); - ++pitr) - { - PrimitiveSet* primitive = copyop(pitr->get()); - if (primitive) _primitives.push_back(primitive); - } - - for(TexCoordArrayList::const_iterator titr=geometry._texCoordList.begin(); - titr!=geometry._texCoordList.end(); - ++titr) - { - _texCoordList.push_back(*titr); - } -} - -IndexedGeometry::~IndexedGeometry() -{ - // no need to delete, all automatically handled by ref_ptr :-) -} - -void IndexedGeometry::setTexCoordArray(unsigned int unit,Array* array) -{ - if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1); - - _texCoordList[unit].first = array; - - dirtyDisplayList(); -} - -Array* IndexedGeometry::getTexCoordArray(unsigned int unit) -{ - if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); - else return 0; -} - -void IndexedGeometry::setTexCoordIndices(unsigned int unit,IndexArray* array) -{ - if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1); - - _texCoordList[unit].second = array; - - dirtyDisplayList(); -} - -IndexArray* IndexedGeometry::getTexCoordIndices(unsigned int unit) -{ - if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); - else return 0; -} - -const IndexArray* IndexedGeometry::getTexCoordIndices(unsigned int unit) const -{ - if (unit<_texCoordList.size()) return _texCoordList[unit].second.get(); - else return 0; -} - -void IndexedGeometry::drawImmediateMode(State& state) -{ - if (!_vertexArray.valid() || _vertexArray->getNumElements()==0) return; - if (_vertexIndices.valid() && _vertexIndices->getNumElements()==0) return; - - // set up extensions. - static SecondaryColor3ubvProc s_glSecondaryColor3ubv = - (SecondaryColor3ubvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT"); - static SecondaryColor3fvProc s_glSecondaryColor3fv = - (SecondaryColor3fvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3fv","glSecondaryColor3fvEXT"); - - static FogCoordProc s_glFogCoordfv = - (FogCoordProc) osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT"); - - static MultiTexCoord1fProc s_glMultiTexCoord1f = - (MultiTexCoord1fProc) osg::getGLExtensionFuncPtr("glMultiTexCoord1f","glMultiTexCoord1fARB"); - static MultiTexCoordfvProc s_glMultiTexCoord2fv = - (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord2fv","glMultiTexCoord2fvARB"); - static MultiTexCoordfvProc s_glMultiTexCoord3fv = - (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord3fv","glMultiTexCoord3fvARB"); - static MultiTexCoordfvProc s_glMultiTexCoord4fv = - (MultiTexCoordfvProc) osg::getGLExtensionFuncPtr("glMultiTexCoord4fv","glMultiTexCoord4fvARB"); - - DrawVertex drawVertex(_vertexArray.get(),_vertexIndices.get()); - DrawNormal drawNormal(_normalArray.get(),_normalIndices.get()); - DrawColor drawColor(_colorArray.get(),_colorIndices.get()); - DrawSecondaryColor drawSecondaryColor(_secondaryColorArray.get(),_secondaryColorIndices.get(), - s_glSecondaryColor3ubv,s_glSecondaryColor3fv); - DrawFogCoord drawFogCoord(_fogCoordArray.get(),_fogCoordIndices.get(), - s_glFogCoordfv); - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up normals if required. - // - unsigned int normalIndex = 0; - AttributeBinding normalBinding = _normalBinding; - if (!_normalArray.valid() || - _normalArray->empty() || - (_normalIndices.valid() && _normalIndices->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - normalBinding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up colours.. - // - unsigned int colorIndex = 0; - AttributeBinding colorBinding = _colorBinding; - if (!_colorArray.valid() || - _colorArray->getNumElements()==0 || - (_colorIndices.valid() && _colorIndices->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - colorBinding = BIND_OFF; - } - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up secondary color if required. - // - unsigned int secondaryColorIndex = 0; - AttributeBinding secondaryColorBinding = _secondaryColorBinding; - if (!_secondaryColorArray.valid() || - _secondaryColorArray->getNumElements()==0 || - !s_glSecondaryColor3ubv || - !s_glSecondaryColor3fv || - (_secondaryColorIndices.valid() && _secondaryColorIndices->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - secondaryColorBinding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up fog coord if required. - // - unsigned int fogCoordIndex = 0; - AttributeBinding fogCoordBinding = _fogCoordBinding; - if (!_fogCoordArray.valid() || - _fogCoordArray->getNumElements()==0 || - !s_glFogCoordfv || - (_fogCoordIndices.valid() && _fogCoordIndices->getNumElements()==0) ) - { - // switch off if not supported or have a valid data. - fogCoordBinding = BIND_OFF; - } - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // check to see if fast path can be used. - // - bool fastPath = true; - if (normalBinding==BIND_PER_PRIMITIVE || (normalBinding==BIND_PER_VERTEX && _normalIndices.valid())) fastPath = false; - else if (colorBinding==BIND_PER_PRIMITIVE || (colorBinding==BIND_PER_VERTEX && _colorIndices.valid())) fastPath = false; - else if (secondaryColorBinding==BIND_PER_PRIMITIVE || (secondaryColorBinding==BIND_PER_VERTEX && _secondaryColorIndices.valid())) fastPath = false; - else if (fogCoordBinding==BIND_PER_PRIMITIVE || (fogCoordBinding==BIND_PER_VERTEX && _fogCoordIndices.valid())) fastPath = false; - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up tex coords if required. - // - typedef std::vector< ref_ptr > DrawTexCoordList; - DrawTexCoordList drawTexCoordList; - drawTexCoordList.reserve(_texCoordList.size()); - - // fallback if multitexturing not supported. - ref_ptr drawTextCoord; - - if (s_glMultiTexCoord2fv) - { - // multitexture supported.. - for(unsigned int unit=0;unit!=_texCoordList.size();++unit) - { - TexCoordArrayPair& texcoordPair = _texCoordList[unit]; - if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) - { - if (texcoordPair.second.valid()) - { - if (texcoordPair.second->getNumElements()>0) - { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),texcoordPair.second.get(), - s_glMultiTexCoord1f, - s_glMultiTexCoord2fv, - s_glMultiTexCoord3fv, - s_glMultiTexCoord4fv)); - - fastPath = false; - } - } - else - { - drawTexCoordList.push_back(new DrawMultiTexCoord(GL_TEXTURE0+unit,texcoordPair.first.get(),0, - s_glMultiTexCoord1f, - s_glMultiTexCoord2fv, - s_glMultiTexCoord3fv, - s_glMultiTexCoord4fv)); - } - } - } - } - else - { - if (!_texCoordList.empty()) - { - TexCoordArrayPair& texcoordPair = _texCoordList[0]; - if (texcoordPair.first.valid() && texcoordPair.first->getNumElements()>0) - { - if (texcoordPair.second.valid()) - { - if (texcoordPair.second->getNumElements()>0) - { - drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),texcoordPair.second.get()); - - fastPath = false; - } - } - else - { - drawTextCoord = new DrawTexCoord(texcoordPair.first.get(),0); - } - } - - } - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // set up vertex arrays if appropriate. - // - if (fastPath) - { - state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer()); - - if (normalBinding==BIND_PER_VERTEX) - state.setNormalPointer(GL_FLOAT,0,_normalArray->getDataPointer()); - else - state.disableNormalPointer(); - - if (colorBinding==BIND_PER_VERTEX) - state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,_colorArray->getDataPointer()); - else - state.disableColorPointer(); - - if (secondaryColorBinding==BIND_PER_VERTEX) - state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,_secondaryColorArray->getDataPointer()); - else - state.disableSecondaryColorPointer(); - - if (fogCoordBinding==BIND_PER_VERTEX) - state.setFogCoordPointer(GL_FLOAT,0,_fogCoordArray->getDataPointer()); - else - state.disableFogCoordPointer(); - - unsigned int unit; - for(unit=0;unit<_texCoordList.size();++unit) - { - Array* array = _texCoordList[unit].first.get(); - if (array) - state.setTexCoordPointer(unit,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); - else - state.disableTexCoordPointer(unit); - } - state.disableTexCoordPointersAboveAndIncluding(unit); - } - else - { - // disable all the vertex arrays in the slow path as we are - // sending everything using glVertex etc. - state.disableAllVertexArrays(); - } - - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // pass the overall binding values onto OpenGL. - // - if (normalBinding==BIND_OVERALL) drawNormal(normalIndex++); - if (colorBinding==BIND_OVERALL) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_OVERALL) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_OVERALL) drawFogCoord(fogCoordIndex++); - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - for(PrimitiveSetList::iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - if (normalBinding==BIND_PER_PRIMITIVE_SET) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE_SET) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) drawFogCoord(fogCoordIndex++); - - if (fastPath) - { - (*itr)->draw(); - } - else - { - PrimitiveSet* primitiveset = itr->get(); - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - switch(mode) - { - case(GL_POINTS): primLength=1; break; - case(GL_LINES): primLength=2; break; - case(GL_TRIANGLES): primLength=3; break; - case(GL_QUADS): primLength=4; break; - default: primLength=0; break; // compute later when =0. - } - - - // draw primtives by the more flexible "slow" path, - // sending OpenGL glBegin/glVertex.../glEnd(). - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawArrays* drawArray = static_cast(primitiveset); - glBegin(mode); - - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst();vindex(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - unsigned int localPrimLength; - if (primLength==0) localPrimLength=*primItr; - else localPrimLength=primLength; - - glBegin(mode); - - for(GLsizei count=0;count<*primItr;) - { - if (normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - - for(unsigned int primCount=0; - primCountgetNumIndices(); - - const DrawElementsUByte* drawElements = static_cast(primitiveset); - glBegin(mode); - - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ) - { - - if (normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - - for(unsigned int primCount=0; - primCountgetNumIndices(); - - const DrawElementsUShort* drawElements = static_cast(primitiveset); - glBegin(mode); - - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - - if (normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - - for(unsigned int primCount=0; - primCountgetNumIndices(); - - const DrawElementsUInt* drawElements = static_cast(primitiveset); - glBegin(mode); - - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - - if (normalBinding==BIND_PER_PRIMITIVE) drawNormal(normalIndex++); - if (colorBinding==BIND_PER_PRIMITIVE) drawColor(colorIndex++); - if (secondaryColorBinding==BIND_PER_PRIMITIVE) drawSecondaryColor(secondaryColorIndex++); - if (fogCoordBinding==BIND_PER_PRIMITIVE) drawFogCoord(fogCoordIndex++); - - for(unsigned int primCount=0; - primCountempty()) - { - af.apply(VERTICES,_vertexArray->size(),&(_vertexArray->front())); - } - - if (_normalArray.valid() && !_normalArray->empty()) - { - af.apply(NORMALS,_normalArray->size(),&(_normalArray->front())); - } - // need to add other attriubtes -} - -void IndexedGeometry::accept(PrimitiveFunctor& functor) -{ - if (!_vertexArray.valid() || _vertexArray->empty()) return; - - functor.setVertexArray(_vertexArray->size(),&(_vertexArray->front())); - - for(PrimitiveSetList::iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - (*itr)->accept(functor); - } - -} - -bool IndexedGeometry::verifyBindings() const -{ - switch(_normalBinding) - { - case(BIND_OFF): - if (_normalArray.valid() && _normalArray->getNumElements()>0) return false; - break; - case(BIND_OVERALL): - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=1) return false; - break; - case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=_primitives.size()) return false; - break; - case(BIND_PER_VERTEX): - if (_vertexArray.valid()) - { - if (!_normalArray.valid()) return false; - if (_normalArray->getNumElements()!=_vertexArray->getNumElements()) return false; - } - else if (_normalArray.valid() && _normalArray->getNumElements()==0) return false; - break; - } - - switch(_colorBinding) - { - case(BIND_OFF): - if (_colorArray.valid() && _colorArray->getNumElements()>0) return false; - break; - case(BIND_OVERALL): - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=1) return false; - break; - case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=_primitives.size()) return false; - break; - case(BIND_PER_VERTEX): - if (_vertexArray.valid()) - { - if (!_colorArray.valid()) return false; - if (_colorArray->getNumElements()!=_vertexArray->getNumElements()) return false; - } - else if (_colorArray.valid() && _colorArray->getNumElements()==0) return false; - break; - } - - for(TexCoordArrayList::const_iterator itr=_texCoordList.begin(); - itr!=_texCoordList.end(); - ++itr) - { - const Array* array = itr->first.get(); - if (_vertexArray.valid()) - { - if (array && array->getNumElements()!=_vertexArray->getNumElements()) return false; - } - else if (array && array->getNumElements()==0) return false; - } - - return true; -} - -void IndexedGeometry::computeCorrectBindingsAndArraySizes() -{ - if (verifyBindings()) return; - - if (!_vertexArray.valid() || _vertexArray->empty()) - { - // no vertex array so switch everything off. - - _vertexArray = 0; - - _colorArray = 0; - _colorBinding = BIND_OFF; - - _normalArray = 0; - _normalBinding = BIND_OFF; - - _texCoordList.clear(); - - notify(INFO)<<"Info: remove redundent attribute arrays from empty osg::IndexedGeometry"<getNumElements()==0) - { - _normalArray = 0; - _normalBinding = BIND_OFF; - } - else if (_normalArray->getNumElements()>1) - { - // trim the array down to 1 element long. - _normalArray->erase(_normalArray->begin()+1,_normalArray->end()); - } - break; - case(BIND_PER_PRIMITIVE_SET): - case(BIND_PER_PRIMITIVE): - if (!_normalArray.valid()) - { - _normalBinding = BIND_OFF; - } - else if (_normalArray->getNumElements()<_primitives.size()) - { - _normalArray = 0; - _normalBinding = BIND_OFF; - } - else if (_normalArray->getNumElements()>_primitives.size()) - { - // trim the array down to size of the number of primitives. - _normalArray->erase(_normalArray->begin()+_primitives.size(),_normalArray->end()); - } - break; - case(BIND_PER_VERTEX): - if (!_normalArray.valid()) - { - _normalBinding = BIND_OFF; - } - else if (_normalArray->getNumElements()<_vertexArray->getNumElements()) - { - _normalArray = 0; - _normalBinding = BIND_OFF; - } - else if (_normalArray->getNumElements()>_vertexArray->getNumElements()) - { - // trim the array down to size of the number of primitives. - _normalArray->erase(_normalArray->begin()+_vertexArray->getNumElements(),_normalArray->end()); - } - break; - } - - // TODO colours and tex coords. - -} diff --git a/src/osg/Makefile b/src/osg/Makefile index 094a4ce27..d35574bbe 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -39,7 +39,6 @@ CXXFILES =\ Image.cpp\ Impostor.cpp\ ImpostorSprite.cpp\ - IndexedGeometry.cpp\ LOD.cpp\ Light.cpp\ LightModel.cpp\ diff --git a/src/osgPlugins/flt/GeoSetBuilder.cpp b/src/osgPlugins/flt/GeoSetBuilder.cpp index 638ffb8dc..e26eca21e 100644 --- a/src/osgPlugins/flt/GeoSetBuilder.cpp +++ b/src/osgPlugins/flt/GeoSetBuilder.cpp @@ -187,7 +187,7 @@ void DynGeoSet::addToGeometry(osg::Geometry* geom) if (_primtype!=osg::PrimitiveSet::POLYGON) { - geom->addPrimitive(new osg::DrawArrays(_primtype,indexBase,_coordList.size())); + geom->addPrimitiveSet(new osg::DrawArrays(_primtype,indexBase,_coordList.size())); } else { @@ -195,7 +195,7 @@ void DynGeoSet::addToGeometry(osg::Geometry* geom) itr!=_primLenList.end(); ++itr) { - geom->addPrimitive(new osg::DrawArrays(_primtype,indexBase,*itr)); + geom->addPrimitiveSet(new osg::DrawArrays(_primtype,indexBase,*itr)); indexBase += *itr; } } diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 459893f87..0afd8ad29 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -1796,16 +1796,16 @@ void ConvertFromFLT::visitMeshPrimitive ( osg::Group &parent, MeshPrimitiveRecor switch ( mesh->getData()->primitiveType ) { case MeshPrimitiveRecord::TRIANGLE_STRIP: - geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,0,mesh->getNumVertices()) ); + geometry->addPrimitiveSet ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::TRIANGLE_FAN: - geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,0,mesh->getNumVertices()) ); + geometry->addPrimitiveSet ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::QUADRILATERAL_STRIP: - geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,mesh->getNumVertices()) ); + geometry->addPrimitiveSet ( new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::INDEXED_POLYGON: - geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,mesh->getNumVertices()) ); + geometry->addPrimitiveSet ( new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,mesh->getNumVertices()) ); break; default: assert ( 0 ); // What type is this? diff --git a/src/osgPlugins/iv/osgvisitor.cpp b/src/osgPlugins/iv/osgvisitor.cpp index f0128c4ee..797a51cac 100644 --- a/src/osgPlugins/iv/osgvisitor.cpp +++ b/src/osgPlugins/iv/osgvisitor.cpp @@ -291,7 +291,7 @@ void OSGVisitor::applyIndexedFaceSet(IndexedFaceSet *ifs) { for (i=1;i<=4;i++) { osg::PrimitiveSet *p=generatePrimitive(polys,i); if (p!=0) { - geometry->addPrimitive(p); + geometry->addPrimitiveSet(p); } } TextureCoordList tcoord; @@ -348,7 +348,7 @@ void OSGVisitor::applyIndexedTriStripSet(IndexedTriStripSet *its) { for (j=0;jaddPrimitive(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,vindex.size(),indices)); + geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,vindex.size(),indices)); } diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 5909348a2..e5dacaabb 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -603,7 +603,7 @@ osg::Drawable* ReaderWriter3DS::createDrawable(Lib3dsMesh *m,FaceList& faceLis *(index_itr++) = orig2NewMapping[face.points[2]]; } - geom->addPrimitive(elements); + geom->addPrimitiveSet(elements); return geom; } diff --git a/src/osgPlugins/lwo/Lwo2Layer.cpp b/src/osgPlugins/lwo/Lwo2Layer.cpp index 6ae750540..15215a6b3 100644 --- a/src/osgPlugins/lwo/Lwo2Layer.cpp +++ b/src/osgPlugins/lwo/Lwo2Layer.cpp @@ -157,7 +157,7 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count ) (*texcoords).push_back(uv); } } - geometry->addPrimitive(osgNew DrawArrays(PrimitiveSet::POLYGON, + geometry->addPrimitiveSet(osgNew DrawArrays(PrimitiveSet::POLYGON, (*coords).size() - (*pol_itr)->size(), (*pol_itr)->size())); } diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index f3117c82d..c99a76af8 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -233,7 +233,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string break; } - gc._geom->addPrimitive(osgNew osg::DrawArrays(mode,gc._coordCount,face.index_cnt)); + gc._geom->addPrimitiveSet(osgNew osg::DrawArrays(mode,gc._coordCount,face.index_cnt)); gc._coordCount += face.index_cnt; // From the spec_low.lxt : diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index cab4e6914..17dac2681 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -207,7 +207,7 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable(GLMmodel* obj, osg::Geometry* geom = new osg::Geometry; // primitives are only triangles - geom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,ntris*3)); + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,ntris*3)); // the following code for mapping the coords, normals and texcoords // is complicated greatly by the need to create separate out the diff --git a/src/osgPlugins/osg/Geometry.cpp b/src/osgPlugins/osg/Geometry.cpp index 7d509087b..e9936716a 100644 --- a/src/osgPlugins/osg/Geometry.cpp +++ b/src/osgPlugins/osg/Geometry.cpp @@ -1,5 +1,3 @@ -#if 1 - #include #include @@ -23,7 +21,7 @@ Array* Array_readLocalData(Input& fr); bool Primitive_readLocalData(Input& fr,osg::Geometry& geom); -// register the read and write functions with the osgDB::Registry. +//register the read and write functions with the osgDB::Registry. RegisterDotOsgWrapperProxy g_GeometryFuncProxy ( osgNew osg::Geometry, @@ -40,14 +38,15 @@ bool Geometry_readLocalData(Object& obj, Input& fr) Geometry& geom = static_cast(obj); - if (fr.matchSequence("Primitives %i {")) + bool matchedFirst = false; + if ((matchedFirst=fr.matchSequence("Primitives %i {")) || fr.matchSequence("PrimitiveSets %i {") ) { int entry = fr[1].getNoNestedBrackets(); int capacity; fr[1].getInt(capacity); - Geometry::PrimitiveList& primitives = geom.getPrimitiveList(); + Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); if (capacity>0) primitives.reserve(capacity); @@ -594,7 +593,7 @@ bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) int count; fr[3].getInt(count); - geom.addPrimitive(osgNew DrawArrays(mode,first,count)); + geom.addPrimitiveSet(osgNew DrawArrays(mode,first,count)); fr += 4; @@ -632,7 +631,7 @@ bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) } ++fr; - geom.addPrimitive(prim); + geom.addPrimitiveSet(prim); iteratorAdvanced = true; } @@ -663,7 +662,7 @@ bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) } ++fr; - geom.addPrimitive(prim); + geom.addPrimitiveSet(prim); iteratorAdvanced = true; } @@ -694,7 +693,7 @@ bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) } ++fr; - geom.addPrimitive(prim); + geom.addPrimitiveSet(prim); iteratorAdvanced = true; } @@ -725,7 +724,7 @@ bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) } ++fr; - geom.addPrimitive(prim); + geom.addPrimitiveSet(prim); iteratorAdvanced = true; } @@ -786,13 +785,13 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw) { const Geometry& geom = static_cast(obj); - const Geometry::PrimitiveList& primitives = geom.getPrimitiveList(); + const Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); if (!primitives.empty()) { - fw.indent() << "Primitives "< - -#include -#include -#include - -using namespace osg; -using namespace osgDB; - -// forward declare functions to use later. -bool IndexedGeometry_readLocalData(Object& obj, Input& fr); -bool IndexedGeometry_writeLocalData(const Object& obj, Output& fw); - -bool IndexedGeometry_matchBindingTypeStr(const char* str,IndexedGeometry::AttributeBinding& mode); -const char* IndexedGeometry_getBindingTypeStr(IndexedGeometry::AttributeBinding mode); - -bool IndexedGeometry_matchPrimitiveModeStr(const char* str,GLenum& mode); -const char* IndexedGeometry_getPrimitiveModeStr(GLenum mode); - -Array* IG_Array_readLocalData(Input& fr); - -bool IG_Primitive_readLocalData(Input& fr,osg::IndexedGeometry& geom); - -// register the read and write functions with the osgDB::Registry. -// RegisterDotOsgWrapperProxy g_GeometryFuncProxy -// ( -// osgNew osg::IndexedGeometry, -// "Geometry", -// "Object Drawable Geometry", -// &IndexedGeometry_readLocalData, -// &IndexedGeometry_writeLocalData, -// DotOsgWrapper::READ_AND_WRITE -// ); - -RegisterDotOsgWrapperProxy g_IndexedGeometryFuncProxy -( - osgNew osg::IndexedGeometry, - "IndexedGeometry", - "Object Drawable IndexedGeometry", - &IndexedGeometry_readLocalData, - &IndexedGeometry_writeLocalData, - DotOsgWrapper::READ_AND_WRITE -); - -bool IndexedGeometry_readLocalData(Object& obj, Input& fr) -{ - bool iteratorAdvanced = false; - - IndexedGeometry& geom = static_cast(obj); - - bool matchedFirst = false; - if ((matchedFirst=fr.matchSequence("Primitives %i {")) || fr.matchSequence("PrimitivesSet %i {") ) - { - int entry = fr[1].getNoNestedBrackets(); - - int capacity; - fr[1].getInt(capacity); - - IndexedGeometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); - if (capacity>0) primitives.reserve(capacity); - - - fr += 3; - - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - if (!IG_Primitive_readLocalData(fr,geom)) ++fr; - } - - ++fr; - - iteratorAdvanced = true; - - } - - if (fr.matchSequence("VertexArray %i {")) - { - - int entry = fr[0].getNoNestedBrackets(); - - int capacity; - fr[1].getInt(capacity); - - Vec3Array* vertices = osgNew Vec3Array; - vertices->reserve(capacity); - - fr += 3; - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - Vec3 v; - if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) - { - fr += 3; - vertices->push_back(v); - } - else - { - ++fr; - } - } - - geom.setVertexArray(vertices); - - iteratorAdvanced = true; - ++fr; - - - } - - IndexedGeometry::AttributeBinding normalBinding=IndexedGeometry::BIND_OFF; - if (fr[0].matchWord("NormalBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),normalBinding)) - { - geom.setNormalBinding(normalBinding); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("NormalArray %i {")) - { - int entry = fr[0].getNoNestedBrackets(); - - int capacity; - fr[1].getInt(capacity); - - Vec3Array* normals = osgNew Vec3Array; - normals->reserve(capacity); - - fr += 3; - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - Vec3 v; - if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) - { - fr += 3; - normals->push_back(v); - } - else - { - ++fr; - } - } - - geom.setNormalArray(normals); - - iteratorAdvanced = true; - ++fr; - } - - IndexedGeometry::AttributeBinding colorBinding=IndexedGeometry::BIND_OFF; - if (fr[0].matchWord("ColorBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),colorBinding)) - { - geom.setColorBinding(colorBinding); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("ColorArray %w %i {")) - { - ++fr; - Array* colors = IG_Array_readLocalData(fr); - if (colors) - { - geom.setColorArray(colors); - iteratorAdvanced = true; - } - } - - IndexedGeometry::AttributeBinding secondaryColorBinding=IndexedGeometry::BIND_OFF; - if (fr[0].matchWord("SecondaryColorBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding)) - { - geom.setSecondaryColorBinding(secondaryColorBinding); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("SecondaryColorArray %w %i {")) - { - ++fr; - Array* colors = IG_Array_readLocalData(fr); - if (colors) - { - geom.setSecondaryColorArray(colors); - iteratorAdvanced = true; - } - } - - - - IndexedGeometry::AttributeBinding fogCoordBinding=IndexedGeometry::BIND_OFF; - if (fr[0].matchWord("FogCoordBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding)) - { - geom.setFogCoordBinding(fogCoordBinding); - fr+=2; - iteratorAdvanced = true; - } - - if (fr.matchSequence("FogCoordArray %i {")) - { - int entry = fr[0].getNoNestedBrackets(); - - int capacity; - fr[1].getInt(capacity); - - FloatArray* fogcoords = osgNew FloatArray; - fogcoords->reserve(capacity); - - fr += 3; - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - float fc; - if (fr[0].getFloat(fc)) - { - ++fr; - fogcoords->push_back(fc); - } - else - { - ++fr; - } - } - - geom.setFogCoordArray(fogcoords); - - iteratorAdvanced = true; - ++fr; - } - - if (fr.matchSequence("TexCoordArray %i %w %i {")) - { - int unit=0; - fr[1].getInt(unit); - - fr+=2; - Array* texcoords = IG_Array_readLocalData(fr); - if (texcoords) - { - geom.setTexCoordArray(unit,texcoords); - iteratorAdvanced = true; - } - - } - - return iteratorAdvanced; -} - - -Array* IG_Array_readLocalData(Input& fr) -{ - int entry = fr[0].getNoNestedBrackets(); - - const char* arrayName = fr[0].getStr(); - - unsigned int capacity = 0; - fr[1].getUInt(capacity); - ++fr; - - fr += 2; - - if (strcmp(arrayName,"ByteArray")==0) - { - ByteArray* array = osgNew ByteArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - int int_value; - if (fr[0].getInt(int_value)) - { - ++fr; - array->push_back(int_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"ShortArray")==0) - { - ShortArray* array = osgNew ShortArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - int int_value; - if (fr[0].getInt(int_value)) - { - ++fr; - array->push_back(int_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"IntArray")==0) - { - IntArray* array = osgNew IntArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - int int_value; - if (fr[0].getInt(int_value)) - { - ++fr; - array->push_back(int_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"UByteArray")==0) - { - UByteArray* array = osgNew UByteArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int uint_value; - if (fr[0].getUInt(uint_value)) - { - ++fr; - array->push_back(uint_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"UShortArray")==0) - { - UShortArray* array = osgNew UShortArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int uint_value; - if (fr[0].getUInt(uint_value)) - { - ++fr; - array->push_back(uint_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"UIntArray")==0) - { - UIntArray* array = osgNew UIntArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int uint_value; - if (fr[0].getUInt(uint_value)) - { - ++fr; - array->push_back(uint_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"UByte4Array")==0) - { - UByte4Array* array = osgNew UByte4Array; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int r,g,b,a; - if (fr[0].getUInt(r) && - fr[1].getUInt(g) && - fr[2].getUInt(b) && - fr[3].getUInt(a)) - { - ++fr; - array->push_back(osg::UByte4(r,g,b,a)); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"FloatArray")==0) - { - FloatArray* array = osgNew FloatArray; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - float float_value; - if (fr[0].getFloat(float_value)) - { - ++fr; - array->push_back(float_value); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"Vec2Array")==0) - { - Vec2Array* array = osgNew Vec2Array; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - Vec2 v; - if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y())) - { - fr += 2; - array->push_back(v); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"Vec3Array")==0) - { - Vec3Array* array = osgNew Vec3Array; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - Vec3 v; - if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) - { - fr += 3; - array->push_back(v); - } - else ++fr; - } - ++fr; - return array; - } - else if (strcmp(arrayName,"Vec4Array")==0) - { - Vec4Array* array = osgNew Vec4Array; - array->reserve(capacity); - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - Vec4 v; - if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()) && fr[3].getFloat(v.w())) - { - fr += 4; - array->push_back(v); - } - else ++fr; - } - ++fr; - return array; - } - - return 0; -} - - -template -void IG_Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8) -{ - fw.indent() << "{"<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<(array); - fw<setMode(mode); - prim->setFirst(first); - prim->reserve(capacity); - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int i; - if (fr[0].getUInt(i)) - { - prim->push_back(i); - ++fr; - } - } - ++fr; - - geom.addPrimitiveSet(prim); - - iteratorAdvanced = true; - } - else if (fr.matchSequence("DrawElementsUByte %w %i {")) - { - int entry = fr[1].getNoNestedBrackets(); - - GLenum mode; - IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); - - int capacity; - fr[2].getInt(capacity); - - fr += 4; - - DrawElementsUByte* prim = osgNew DrawElementsUByte; - prim->setMode(mode); - prim->reserve(capacity); - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int i; - if (fr[0].getUInt(i)) - { - prim->push_back(i); - ++fr; - } - } - ++fr; - - geom.addPrimitiveSet(prim); - - iteratorAdvanced = true; - } - else if (fr.matchSequence("DrawElementsUShort %w %i {")) - { - int entry = fr[1].getNoNestedBrackets(); - - GLenum mode; - IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); - - int capacity; - fr[2].getInt(capacity); - - fr += 4; - - DrawElementsUShort* prim = osgNew DrawElementsUShort; - prim->setMode(mode); - prim->reserve(capacity); - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int i; - if (fr[0].getUInt(i)) - { - prim->push_back(i); - ++fr; - } - } - ++fr; - - geom.addPrimitiveSet(prim); - - iteratorAdvanced = true; - } - else if (fr.matchSequence("DrawElementsUInt %w %i {")) - { - int entry = fr[1].getNoNestedBrackets(); - - GLenum mode; - IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); - - int capacity; - fr[2].getInt(capacity); - - fr += 4; - - DrawElementsUInt* prim = osgNew DrawElementsUInt; - prim->setMode(mode); - prim->reserve(capacity); - - while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) - { - unsigned int i; - if (fr[0].getUInt(i)) - { - prim->push_back(i); - ++fr; - } - } - ++fr; - - geom.addPrimitiveSet(prim); - - iteratorAdvanced = true; - } - - return iteratorAdvanced; -} - -bool IG_Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw) -{ - - switch(prim.getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - const DrawArrays& cprim = static_cast(prim); - fw<(prim); - fw<(prim); - fw<(prim); - fw<(prim); - fw<(obj); - - const IndexedGeometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); - if (!primitives.empty()) - { - fw.indent() << "PrimitiveSets "<addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLES,0,numPrims*3)); + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLES,0,numPrims*3)); } break; case trpgGeometry::TriStrips: @@ -267,7 +267,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) int first=0; for(int i=0;iaddPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,first,primitives[i])); + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,first,primitives[i])); first += primitives[i]; } @@ -286,7 +286,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) int i; for(i=0;iaddPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,first,primitives[i])); + geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,first,primitives[i])); first += primitives[i]; } diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 04ab9fcd3..f32bf1bcf 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -16,8 +15,7 @@ using namespace osgUtil; -//#define CONVERT_GEOSET_TO_GEOMETRY -//#define CONVERT_GEOSET_TO_INDEXEDGEOMETRY +// #define CONVERT_GEOSET_TO_GEOMETRY //////////////////////////////////////////////////////////////////////////// // Overall Optimizetion function. @@ -63,7 +61,7 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) } -#if defined(CONVERT_GEOSET_TO_GEOMETRY) || defined(CONVERT_GEOSET_TO_INDEXEDGEOMETRY) +#if defined(CONVERT_GEOSET_TO_GEOMETRY) // convert the old style GeoSet to Geometry ConvertGeoSetsToGeometryVisitor cgtg; node->accept(cgtg); @@ -133,33 +131,17 @@ void Optimizer::ConvertGeoSetsToGeometryVisitor::apply(osg::Geode& geode) osg::GeoSet* geoset = dynamic_cast(geode.getDrawable(i)); if (geoset) { - #if defined(CONVERT_GEOSET_TO_GEOMETRY) - - osg::Geometry* geom = geoset->convertToGeometry(); - if (geom) - { - std::cout<<"Successfully converted GeoSet to Geometry"<convertToGeometry(); + if (geom) + { + std::cout<<"Successfully converted GeoSet to Geometry"<convertToIndexedGeometry(); - if (geom) - { - std::cout<<"Successfully converted GeoSet to IndexedGeometry"<getNumPrimitives()>0) + for(unsigned int i=0; + igetNumPrimitiveSets() && igetNumPrimitiveSets(); + ++i) { - if (rhs->getNumPrimitives()>0) - { - if (lhs->getPrimitive(0)->getType()getPrimitive(0)->getType()) return true; - else if (rhs->getPrimitive(0)->getType()getPrimitive(0)->getType()) return false; - - if (lhs->getPrimitive(0)->getMode()getPrimitive(0)->getMode()) return true; - else if (rhs->getPrimitive(0)->getMode()getPrimitive(0)->getMode()) return false; - - } - return false; + if (lhs->getPrimitiveSet(i)->getType()getPrimitiveSet(i)->getType()) return true; + else if (rhs->getPrimitiveSet(i)->getType()getPrimitiveSet(i)->getType()) return false; + + if (lhs->getPrimitiveSet(i)->getMode()getPrimitiveSet(i)->getMode()) return true; + else if (rhs->getPrimitiveSet(i)->getMode()getPrimitiveSet(i)->getMode()) return false; + } - else if (rhs->getNumPrimitives()>0) return true; - return false; + return lhs->getNumPrimitiveSets()getNumPrimitiveSets(); } }; @@ -1207,8 +1186,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); if (geom) { - osg::Geometry::PrimitiveList& primitives = geom->getPrimitiveList(); - for(osg::Geometry::PrimitiveList::iterator itr=primitives.begin(); + osg::Geometry::PrimitiveSetList& primitives = geom->getPrimitiveSetList(); + for(osg::Geometry::PrimitiveSetList::iterator itr=primitives.begin(); itr!=primitives.end(); ++itr) { @@ -1235,9 +1214,9 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) osg::Geometry* geom = dynamic_cast(geode.getDrawable(i)); if (geom) { - if (geom->getNumPrimitives()>0) + if (geom->getNumPrimitiveSets()>0) { - osg::Geometry::PrimitiveList& primitives = geom->getPrimitiveList(); + osg::Geometry::PrimitiveSetList& primitives = geom->getPrimitiveSetList(); unsigned int primNo=0; while(primNo+1get(); primitive->offsetIndices(base); } - lhs.getPrimitiveList().insert(lhs.getPrimitiveList().end(),rhs.getPrimitiveList().begin(),rhs.getPrimitiveList().end()); + lhs.getPrimitiveSetList().insert(lhs.getPrimitiveSetList().end(), + rhs.getPrimitiveSetList().begin(),rhs.getPrimitiveSetList().end()); return true; } diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index 4e78d4969..d5cc49618 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -71,8 +71,8 @@ struct SmoothTriangleFunctor void SmoothingVisitor::smooth(osg::Geometry& geom) { - Geometry::PrimitiveList& primitives = geom.getPrimitiveList(); - Geometry::PrimitiveList::iterator itr; + Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); + Geometry::PrimitiveSetList::iterator itr; unsigned int numSurfacePrimitives=0; for(itr=primitives.begin(); itr!=primitives.end(); diff --git a/src/osgUtil/Tesselator.cpp b/src/osgUtil/Tesselator.cpp index e9178075b..fea633efc 100644 --- a/src/osgUtil/Tesselator.cpp +++ b/src/osgUtil/Tesselator.cpp @@ -135,12 +135,12 @@ class InsertNewVertices : public osg::ArrayVisitor void Tesselator::retesselatePolygons(osg::Geometry& geom) { Vec3Array* vertices = geom.getVertexArray(); - if (!vertices || vertices->empty() || geom.getPrimitiveList().empty()) return; + if (!vertices || vertices->empty() || geom.getPrimitiveSetList().empty()) return; - int noPrimitiveAtStart = geom.getPrimitiveList().size(); + int noPrimitiveAtStart = geom.getPrimitiveSetList().size(); for(int primNo=0;primNogetMode()==osg::PrimitiveSet::POLYGON) { beginTesselation(); @@ -230,9 +230,9 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) tcalItr!=tcal.end(); ++tcalItr) { - if (tcalItr->valid()) + if (tcalItr->first.valid()) { - arrays.push_back(tcalItr->get()); + arrays.push_back(tcalItr->first.get()); } } @@ -305,7 +305,7 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) if (primItr==_primList.begin()) { // first new primitive so overwrite the previous polygon. - geom.getPrimitiveList()[primNo] = elements; + geom.getPrimitiveSetList()[primNo] = elements; if (normals) { norm=(*normals)[iprim]; // GWM Sep 2002 the flat shaded normal } @@ -313,7 +313,7 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) else { // subsequence primitives add to the back of the primitive list. - geom.addPrimitive(elements); + geom.addPrimitiveSet(elements); if (normals) normals->push_back(norm); // GWM Sep 2002 add flat shaded normal for new facet } iprim++; // GWM Sep 2002 count which normal we should use diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp index 82c04e4e4..a69adcf85 100644 --- a/src/osgUtil/TriStripVisitor.cpp +++ b/src/osgUtil/TriStripVisitor.cpp @@ -40,8 +40,8 @@ void TriStripVisitor::stripify(Geometry& geom) unsigned int numSurfacePrimitives = 0; unsigned int numNonSurfacePrimitives = 0; - Geometry::PrimitiveList& primitives = geom.getPrimitiveList(); - Geometry::PrimitiveList::iterator itr; + Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); + Geometry::PrimitiveSetList::iterator itr; for(itr=primitives.begin(); itr!=primitives.end(); ++itr) @@ -67,7 +67,7 @@ void TriStripVisitor::stripify(Geometry& geom) TriangleFunctor taf; - Geometry::PrimitiveList new_primitives; + Geometry::PrimitiveSetList new_primitives; new_primitives.reserve(primitives.size()); for(itr=primitives.begin(); @@ -199,7 +199,7 @@ void TriStripVisitor::stripify(Geometry& geom) triangles->push_back(leftoverFaces[i]->m_v2); } } - geom.setPrimitiveList(new_primitives); + geom.setPrimitiveSetList(new_primitives); } }