Moved the new osg::IndexedGeometry class over the top of the the existing

osg::Geometry class, and removed the temporary IndexedGeometry.  Port the rest
of the OSG across to account for the change in method calls -
osg::Geometry::addPrimitive(..) becomes osg::addPrimitiveSet(..)
This commit is contained in:
Robert Osfield
2002-10-02 13:12:16 +00:00
parent 29e998c1f8
commit 0a5ed26940
40 changed files with 934 additions and 2903 deletions

View File

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

View File

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

View File

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

View File

@@ -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<Array> > 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<Array>, ref_ptr<IndexArray> > 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<PrimitiveSet> > PrimitiveList;
typedef std::vector< ref_ptr<PrimitiveSet> > 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<Vec3Array> _vertexArray;
ref_ptr<IndexArray> _vertexIndices;
AttributeBinding _normalBinding;
mutable AttributeBinding _normalBinding;
ref_ptr<Vec3Array> _normalArray;
ref_ptr<IndexArray> _normalIndices;
AttributeBinding _colorBinding;
mutable AttributeBinding _colorBinding;
ref_ptr<Array> _colorArray;
ref_ptr<IndexArray> _colorIndices;
AttributeBinding _secondaryColorBinding;
mutable AttributeBinding _secondaryColorBinding;
ref_ptr<Array> _secondaryColorArray;
ref_ptr<IndexArray> _secondaryColorIndices;
AttributeBinding _fogCoordBinding;
mutable AttributeBinding _fogCoordBinding;
ref_ptr<FloatArray> _fogCoordArray;
ref_ptr<IndexArray> _fogCoordIndices;
TexCoordArrayList _texCoordList;
mutable bool _fastPathComputed;
mutable bool _fastPath;
};

View File

@@ -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 <osg/Drawable>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Array>
#include <osg/PrimitiveSet>
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<const IndexedGeometry*>(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<Array>, ref_ptr<IndexArray> > 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<PrimitiveSet> > 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<Vec3Array> _vertexArray;
ref_ptr<IndexArray> _vertexIndices;
AttributeBinding _normalBinding;
ref_ptr<Vec3Array> _normalArray;
ref_ptr<IndexArray> _normalIndices;
AttributeBinding _colorBinding;
ref_ptr<Array> _colorArray;
ref_ptr<IndexArray> _colorIndices;
AttributeBinding _secondaryColorBinding;
ref_ptr<Array> _secondaryColorArray;
ref_ptr<IndexArray> _secondaryColorIndices;
AttributeBinding _fogCoordBinding;
ref_ptr<FloatArray> _fogCoordArray;
ref_ptr<IndexArray> _fogCoordIndices;
TexCoordArrayList _texCoordList;
};
}
#endif

View File

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

View File

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

View File

@@ -7,6 +7,7 @@
#include <osg/PolygonStipple>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgGA/TrackballManipulator>
@@ -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 );

View File

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

View File

@@ -84,7 +84,7 @@ Node *makeSky( void )
drawElements->push_back((i+0)*19+j);
}
geom->addPrimitive(drawElements);
geom->addPrimitiveSet(drawElements);
}
geom->setVertexArray( &coords );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -9,11 +9,8 @@
#include <osg/Notify>
#include <osg/Geometry>
#include <osg/IndexedGeometry>
#include <osg/ShadeModel>
//#include <osg/mem_ptr>
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<ShadeModel*>(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<IndexedGeometry> 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<ShadeModel*>(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()
}

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,951 +0,0 @@
#include <osg/GLExtensions>
#include <osg/IndexedGeometry>
#include <osg/Notify>
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<Vec3Array*>(copyop(geometry._vertexArray.get()))),
_normalBinding(geometry._normalBinding),
_normalArray(dynamic_cast<Vec3Array*>(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<FloatArray*>(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<DrawMultiTexCoord> > DrawTexCoordList;
DrawTexCoordList drawTexCoordList;
drawTexCoordList.reserve(_texCoordList.size());
// fallback if multitexturing not supported.
ref_ptr<DrawTexCoord> 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<const DrawArrays*>(primitiveset);
glBegin(mode);
unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount();
for(unsigned int vindex=drawArray->getFirst();vindex<indexEnd;)
{
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;
primCount<primLength;
++primCount)
{
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::DrawArrayLengthsPrimitiveType):
{
const DrawArrayLengths* drawArrayLengths = static_cast<const DrawArrayLengths*>(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;
primCount<localPrimLength;
++primCount)
{
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);
++count,++vindex;
}
}
glEnd();
}
break;
}
case(PrimitiveSet::DrawElementsUBytePrimitiveType):
{
if (primLength==0) primLength=primitiveset->getNumIndices();
const DrawElementsUByte* drawElements = static_cast<const DrawElementsUByte*>(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;
primCount<primLength;
++primCount)
{
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);
++primItr;
}
}
glEnd();
break;
}
case(PrimitiveSet::DrawElementsUShortPrimitiveType):
{
if (primLength==0) primLength=primitiveset->getNumIndices();
const DrawElementsUShort* drawElements = static_cast<const DrawElementsUShort*>(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;
primCount<primLength;
++primCount)
{
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);
++primItr;
}
}
glEnd();
break;
}
case(PrimitiveSet::DrawElementsUIntPrimitiveType):
{
if (primLength==0) primLength=primitiveset->getNumIndices();
const DrawElementsUInt* drawElements = static_cast<const DrawElementsUInt*>(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;
primCount<primLength;
++primCount)
{
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);
++primItr;
}
}
glEnd();
break;
}
default:
{
break;
}
}
}
}
}
void IndexedGeometry::accept(AttributeFunctor& af)
{
if (_vertexArray.valid() && !_vertexArray->empty())
{
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"<<std::endl;
return;
}
switch(_normalBinding)
{
case(BIND_OFF):
if (_normalArray.valid()) _normalArray = 0;
break;
case(BIND_OVERALL):
if (!_normalArray.valid())
{
_normalBinding = BIND_OFF;
}
else if (_normalArray->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.
}

View File

@@ -39,7 +39,6 @@ CXXFILES =\
Image.cpp\
Impostor.cpp\
ImpostorSprite.cpp\
IndexedGeometry.cpp\
LOD.cpp\
Light.cpp\
LightModel.cpp\

View File

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

View File

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

View File

@@ -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;j<vindex.size();j++) {
indices[j]=vindex[j];
}
geometry->addPrimitive(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,vindex.size(),indices));
geometry->addPrimitiveSet(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,vindex.size(),indices));
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,3 @@
#if 1
#include <osg/Geometry>
#include <osgDB/Registry>
@@ -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<Geometry&>(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<const Geometry&>(obj);
const Geometry::PrimitiveList& primitives = geom.getPrimitiveList();
const Geometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();
if (!primitives.empty())
{
fw.indent() << "Primitives "<<primitives.size()<<std::endl;
fw.indent() << "PrimitiveSets "<<primitives.size()<<std::endl;
fw.indent() << "{"<<std::endl;
fw.moveIn();
for(Geometry::PrimitiveList::const_iterator itr=primitives.begin();
for(Geometry::PrimitiveSetList::const_iterator itr=primitives.begin();
itr!=primitives.end();
++itr)
{
@@ -811,6 +810,11 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
Array_writeLocalData(fw,vertices.begin(),vertices.end(),1);
}
if (geom.getVertexIndices())
{
fw.indent()<<"VertexIndices ";
Array_writeLocalData(*geom.getVertexIndices(),fw);
}
if (geom.getNormalArray())
{
@@ -823,6 +827,11 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
Array_writeLocalData(fw,normals.begin(),normals.end(),1);
}
if (geom.getNormalIndices())
{
fw.indent()<<"NormalIndices ";
Array_writeLocalData(*geom.getNormalIndices(),fw);
}
if (geom.getColorArray())
{
@@ -830,6 +839,11 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
fw.indent()<<"ColorArray ";
Array_writeLocalData(*geom.getColorArray(),fw);
}
if (geom.getColorIndices())
{
fw.indent()<<"ColorIndices ";
Array_writeLocalData(*geom.getColorIndices(),fw);
}
if (geom.getSecondaryColorArray())
{
@@ -837,6 +851,11 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
fw.indent()<<"SecondaryColorArray ";
Array_writeLocalData(*geom.getSecondaryColorArray(),fw);
}
if (geom.getSecondaryColorIndices())
{
fw.indent()<<"SecondayColorIndices ";
Array_writeLocalData(*geom.getSecondaryColorIndices(),fw);
}
if (geom.getFogCoordArray())
{
@@ -846,15 +865,26 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
fw.indent()<<"FogCoordArray "<<fogcoords.size()<<std::endl;
Array_writeLocalData(fw,fogcoords.begin(),fogcoords.end());
}
if (geom.getFogCoordIndices())
{
fw.indent()<<"FogCoordIndices ";
Array_writeLocalData(*geom.getFogCoordIndices(),fw);
}
const Geometry::TexCoordArrayList& tcal=geom.getTexCoordArrayList();
for(unsigned int i=0;i<tcal.size();++i)
{
if (tcal[i].valid())
if (tcal[i].first.valid())
{
fw.indent()<<"TexCoordArray "<<i<<" ";
Array_writeLocalData(*(tcal[i]),fw);
Array_writeLocalData(*(tcal[i].first),fw);
}
if (tcal[i].second.valid())
{
fw.indent()<<"TexCoordIndices "<<i<<" ";
Array_writeLocalData(*(tcal[i].second),fw);
}
}
@@ -867,6 +897,7 @@ bool Geometry_matchBindingTypeStr(const char* str,Geometry::AttributeBinding& mo
if (strcmp(str,"OFF")==0) mode = Geometry::BIND_OFF;
else if (strcmp(str,"OVERALL")==0) mode = Geometry::BIND_OVERALL;
else if (strcmp(str,"PER_PRIMITIVE")==0) mode = Geometry::BIND_PER_PRIMITIVE;
else if (strcmp(str,"PER_PRIMITIVE_SET")==0) mode = Geometry::BIND_PER_PRIMITIVE_SET;
else if (strcmp(str,"PER_VERTEX")==0) mode = Geometry::BIND_PER_VERTEX;
else return false;
return true;
@@ -877,11 +908,12 @@ const char* Geometry_getBindingTypeStr(Geometry::AttributeBinding mode)
{
switch(mode)
{
case (Geometry::BIND_OVERALL) : return "OVERALL";
case (Geometry::BIND_PER_PRIMITIVE) : return "PER_PRIMITIVE";
case (Geometry::BIND_PER_VERTEX) : return "PER_VERTEX";
case (Geometry::BIND_OFF) :
default : return "OFF";
case (Geometry::BIND_OVERALL) : return "OVERALL";
case (Geometry::BIND_PER_PRIMITIVE) : return "PER_PRIMITIVE";
case (Geometry::BIND_PER_PRIMITIVE_SET) : return "PER_PRIMITIVE_SET";
case (Geometry::BIND_PER_VERTEX) : return "PER_VERTEX";
case (Geometry::BIND_OFF) :
default : return "OFF";
}
}
@@ -919,4 +951,3 @@ const char* Geometry_getPrimitiveModeStr(GLenum mode)
default : return "UnknownPrimitveType";
}
}
#endif

View File

@@ -1,930 +0,0 @@
#include <osg/IndexedGeometry>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
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<IndexedGeometry&>(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<class Iterator>
void IG_Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8)
{
fw.indent() << "{"<<std::endl;
fw.moveIn();
int column=0;
for(Iterator itr=first;
itr!=last;
++itr)
{
if (column==0) fw.indent();
fw << *itr;
++column;
if (column==noItemsPerLine)
{
fw << std::endl;
column = 0;
}
else
{
fw << " ";
}
}
if (column!=0) fw << std::endl;
fw.moveOut();
fw.indent()<<"}"<<std::endl;
}
bool IG_Array_writeLocalData(const Array& array,Output& fw)
{
switch(array.getType())
{
case(Array::ByteArrayType):
{
const ByteArray& carray = static_cast<const ByteArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::ShortArrayType):
{
const ShortArray& carray = static_cast<const ShortArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::IntArrayType):
{
const IntArray& carray = static_cast<const IntArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::UByteArrayType):
{
const UByteArray& carray = static_cast<const UByteArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::UShortArrayType):
{
const UShortArray& carray = static_cast<const UShortArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::UIntArrayType):
{
const UIntArray& carray = static_cast<const UIntArray&>(array);
fw<<array.className()<<" "<<carray.size()<<" ";
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::UByte4ArrayType):
{
const UByte4Array& carray = static_cast<const UByte4Array&>(array);
fw<<array.className()<<" "<<carray.size()<<" ";
IG_Array_writeLocalData(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::FloatArrayType):
{
const FloatArray& carray = static_cast<const FloatArray&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end());
return true;
}
break;
case(Array::Vec2ArrayType):
{
const Vec2Array& carray = static_cast<const Vec2Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::Vec3ArrayType):
{
const Vec3Array& carray = static_cast<const Vec3Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::Vec4ArrayType):
{
const Vec4Array& carray = static_cast<const Vec4Array&>(array);
fw<<array.className()<<" "<<carray.size()<<std::endl;
IG_Array_writeLocalData(fw,carray.begin(),carray.end(),1);
return true;
}
break;
case(Array::ArrayType):
default:
return false;
}
}
bool IG_Primitive_readLocalData(Input& fr,osg::IndexedGeometry& geom)
{
bool iteratorAdvanced = false;
if (fr.matchSequence("DrawArrays %w %i %i"))
{
GLenum mode;
IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
int first;
fr[2].getInt(first);
int count;
fr[3].getInt(count);
geom.addPrimitiveSet(osgNew DrawArrays(mode,first,count));
fr += 4;
iteratorAdvanced = true;
}
else if (fr.matchSequence("DrawArrayLengths %w %i %i {"))
{
int entry = fr[1].getNoNestedBrackets();
GLenum mode;
IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode);
int first;
fr[2].getInt(first);
int capacity;
fr[3].getInt(capacity);
fr += 5;
DrawArrayLengths* prim = osgNew DrawArrayLengths;
prim->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<const DrawArrays&>(prim);
fw<<cprim.className()<<" "<<IndexedGeometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.getCount()<<std::endl;
return true;
}
break;
case(PrimitiveSet::DrawArrayLengthsPrimitiveType):
{
const DrawArrayLengths& cprim = static_cast<const DrawArrayLengths&>(prim);
fw<<cprim.className()<<" "<<IndexedGeometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.getFirst()<<" "<<cprim.size()<<std::endl;
IG_Array_writeLocalData(fw,cprim.begin(),cprim.end());
return true;
}
break;
case(PrimitiveSet::DrawElementsUBytePrimitiveType):
{
const DrawElementsUByte& cprim = static_cast<const DrawElementsUByte&>(prim);
fw<<cprim.className()<<" "<<IndexedGeometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
IG_Array_writeLocalData(fw,cprim.begin(),cprim.end());
return true;
}
break;
case(PrimitiveSet::DrawElementsUShortPrimitiveType):
{
const DrawElementsUShort& cprim = static_cast<const DrawElementsUShort&>(prim);
fw<<cprim.className()<<" "<<IndexedGeometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
IG_Array_writeLocalData(fw,cprim.begin(),cprim.end());
return true;
}
break;
case(PrimitiveSet::DrawElementsUIntPrimitiveType):
{
const DrawElementsUInt& cprim = static_cast<const DrawElementsUInt&>(prim);
fw<<cprim.className()<<" "<<IndexedGeometry_getPrimitiveModeStr(cprim.getMode())<<" "<<cprim.size()<<std::endl;
IG_Array_writeLocalData(fw,cprim.begin(),cprim.end());
return true;
}
break;
default:
return false;
}
}
bool IndexedGeometry_writeLocalData(const Object& obj, Output& fw)
{
const IndexedGeometry& geom = static_cast<const IndexedGeometry&>(obj);
const IndexedGeometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList();
if (!primitives.empty())
{
fw.indent() << "PrimitiveSets "<<primitives.size()<<std::endl;
fw.indent() << "{"<<std::endl;
fw.moveIn();
for(IndexedGeometry::PrimitiveSetList::const_iterator itr=primitives.begin();
itr!=primitives.end();
++itr)
{
fw.indent();
IG_Primitive_writeLocalData(**itr,fw);
}
fw.moveOut();
fw.indent() << "}"<<std::endl;
}
if (geom.getVertexArray())
{
const Vec3Array& vertices = *geom.getVertexArray();
fw.indent()<<"VertexArray "<<vertices.size()<<std::endl;
IG_Array_writeLocalData(fw,vertices.begin(),vertices.end(),1);
}
if (geom.getNormalArray())
{
fw.indent()<<"NormalBinding "<<IndexedGeometry_getBindingTypeStr(geom.getNormalBinding())<<std::endl;
const Vec3Array& normals = *geom.getNormalArray();
fw.indent()<<"NormalArray "<<normals.size()<<std::endl;
IG_Array_writeLocalData(fw,normals.begin(),normals.end(),1);
}
if (geom.getColorArray())
{
fw.indent()<<"ColorBinding "<<IndexedGeometry_getBindingTypeStr(geom.getColorBinding())<<std::endl;
fw.indent()<<"ColorArray ";
IG_Array_writeLocalData(*geom.getColorArray(),fw);
}
if (geom.getSecondaryColorArray())
{
fw.indent()<<"SecondaryColorBinding "<<IndexedGeometry_getBindingTypeStr(geom.getSecondaryColorBinding())<<std::endl;
fw.indent()<<"SecondaryColorArray ";
IG_Array_writeLocalData(*geom.getSecondaryColorArray(),fw);
}
if (geom.getFogCoordArray())
{
fw.indent()<<"FogCoordBinding "<<IndexedGeometry_getBindingTypeStr(geom.getFogCoordBinding())<<std::endl;
const FloatArray& fogcoords = *geom.getFogCoordArray();
fw.indent()<<"FogCoordArray "<<fogcoords.size()<<std::endl;
IG_Array_writeLocalData(fw,fogcoords.begin(),fogcoords.end());
}
const IndexedGeometry::TexCoordArrayList& tcal=geom.getTexCoordArrayList();
for(unsigned int i=0;i<tcal.size();++i)
{
if (tcal[i].first.valid())
{
fw.indent()<<"TexCoordArray "<<i<<" ";
IG_Array_writeLocalData(*(tcal[i].first),fw);
}
}
return true;
}
bool IndexedGeometry_matchBindingTypeStr(const char* str,IndexedGeometry::AttributeBinding& mode)
{
if (strcmp(str,"OFF")==0) mode = IndexedGeometry::BIND_OFF;
else if (strcmp(str,"OVERALL")==0) mode = IndexedGeometry::BIND_OVERALL;
else if (strcmp(str,"PER_PRIMITIVE")==0) mode = IndexedGeometry::BIND_PER_PRIMITIVE;
else if (strcmp(str,"PER_VERTEX")==0) mode = IndexedGeometry::BIND_PER_VERTEX;
else return false;
return true;
}
const char* IndexedGeometry_getBindingTypeStr(IndexedGeometry::AttributeBinding mode)
{
switch(mode)
{
case (IndexedGeometry::BIND_OVERALL) : return "OVERALL";
case (IndexedGeometry::BIND_PER_PRIMITIVE) : return "PER_PRIMITIVE";
case (IndexedGeometry::BIND_PER_VERTEX) : return "PER_VERTEX";
case (IndexedGeometry::BIND_OFF) :
default : return "OFF";
}
}
bool IndexedGeometry_matchPrimitiveModeStr(const char* str,GLenum& mode)
{
if (strcmp(str,"POINTS")==0) mode = PrimitiveSet::POINTS;
else if (strcmp(str,"LINES")==0) mode = PrimitiveSet::LINES;
else if (strcmp(str,"LINE_STRIP")==0) mode = PrimitiveSet::LINE_STRIP;
else if (strcmp(str,"LINE_LOOP")==0) mode = PrimitiveSet::LINE_LOOP;
else if (strcmp(str,"TRIANGLES")==0) mode = PrimitiveSet::TRIANGLES;
else if (strcmp(str,"TRIANGLE_STRIP")==0) mode = PrimitiveSet::TRIANGLE_STRIP;
else if (strcmp(str,"TRIANGLE_FAN")==0) mode = PrimitiveSet::TRIANGLE_FAN;
else if (strcmp(str,"QUADS")==0) mode = PrimitiveSet::QUADS;
else if (strcmp(str,"QUAD_STRIP")==0) mode = PrimitiveSet::QUAD_STRIP;
else if (strcmp(str,"POLYGON")==0) mode = PrimitiveSet::POLYGON;
else return false;
return true;
}
const char* IndexedGeometry_getPrimitiveModeStr(GLenum mode)
{
switch(mode)
{
case (PrimitiveSet::POINTS) : return "POINTS";
case (PrimitiveSet::LINES) : return "LINES";
case (PrimitiveSet::LINE_STRIP) : return "LINE_STRIP";
case (PrimitiveSet::LINE_LOOP) : return "LINE_LOOP";
case (PrimitiveSet::TRIANGLES) : return "TRIANGLES";
case (PrimitiveSet::TRIANGLE_STRIP) : return "TRIANGLE_STRIP";
case (PrimitiveSet::TRIANGLE_FAN) : return "TRIANGLE_FAN";
case (PrimitiveSet::QUADS) : return "QUADS";
case (PrimitiveSet::QUAD_STRIP) : return "QUAD_STRIP";
case (PrimitiveSet::POLYGON) : return "POLYGON";
default : return "UnknownPrimitveType";
}
}

View File

@@ -21,7 +21,6 @@ CXXFILES =\
Group.cpp\
Image.cpp\
Impostor.cpp\
IndexedGeometry.cpp\
Light.cpp\
LightModel.cpp\
LightSource.cpp\

View File

@@ -253,7 +253,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf)
case trpgGeometry::Triangles:
{
geometry = new Geometry;
geometry->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;i<numPrims;++i)
{
geometry->addPrimitive(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;i<numPrims;++i)
{
geometry->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,first,primitives[i]));
geometry->addPrimitiveSet(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,first,primitives[i]));
first += primitives[i];
}

View File

@@ -5,7 +5,6 @@
#include <osg/Impostor>
#include <osg/Billboard>
#include <osg/Geometry>
#include <osg/IndexedGeometry>
#include <osg/GeoSet>
#include <osg/Notify>
#include <osg/OccluderNode>
@@ -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<osg::GeoSet*>(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"<<std::endl;
geode.replaceDrawable(geoset,geom);
}
else
{
std::cout<<"*** Failed to convert GeoSet to Geometry"<<std::endl;
}
osg::Geometry* geom = geoset->convertToGeometry();
if (geom)
{
std::cout<<"Successfully converted GeoSet to Geometry"<<std::endl;
geode.replaceDrawable(geoset,geom);
}
else
{
std::cout<<"*** Failed to convert GeoSet to Geometry"<<std::endl;
}
#else
osg::IndexedGeometry* geom = geoset->convertToIndexedGeometry();
if (geom)
{
std::cout<<"Successfully converted GeoSet to IndexedGeometry"<<std::endl;
geode.replaceDrawable(geoset,geom);
}
else
{
std::cout<<"*** Failed to convert GeoSet to IndexedGeometry"<<std::endl;
}
#endif
}
}
}
@@ -1135,21 +1117,18 @@ struct LessGeometryPrimitiveType
{
bool operator() (const osg::Geometry* lhs,const osg::Geometry* rhs) const
{
if (lhs->getNumPrimitives()>0)
for(unsigned int i=0;
i<lhs->getNumPrimitiveSets() && i<rhs->getNumPrimitiveSets();
++i)
{
if (rhs->getNumPrimitives()>0)
{
if (lhs->getPrimitive(0)->getType()<rhs->getPrimitive(0)->getType()) return true;
else if (rhs->getPrimitive(0)->getType()<lhs->getPrimitive(0)->getType()) return false;
if (lhs->getPrimitive(0)->getMode()<rhs->getPrimitive(0)->getMode()) return true;
else if (rhs->getPrimitive(0)->getMode()<lhs->getPrimitive(0)->getMode()) return false;
}
return false;
if (lhs->getPrimitiveSet(i)->getType()<rhs->getPrimitiveSet(i)->getType()) return true;
else if (rhs->getPrimitiveSet(i)->getType()<lhs->getPrimitiveSet(i)->getType()) return false;
if (lhs->getPrimitiveSet(i)->getMode()<rhs->getPrimitiveSet(i)->getMode()) return true;
else if (rhs->getPrimitiveSet(i)->getMode()<lhs->getPrimitiveSet(i)->getMode()) return false;
}
else if (rhs->getNumPrimitives()>0) return true;
return false;
return lhs->getNumPrimitiveSets()<rhs->getNumPrimitiveSets();
}
};
@@ -1207,8 +1186,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode)
osg::Geometry* geom = dynamic_cast<osg::Geometry*>(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<osg::Geometry*>(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+1<primitives.size())
{
@@ -1355,15 +1334,16 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom
}
// shift the indices of the incomming primitives to account for the pre exisiting geometry.
for(osg::Geometry::PrimitiveList::iterator primItr=rhs.getPrimitiveList().begin();
primItr!=rhs.getPrimitiveList().end();
for(osg::Geometry::PrimitiveSetList::iterator primItr=rhs.getPrimitiveSetList().begin();
primItr!=rhs.getPrimitiveSetList().end();
++primItr)
{
osg::PrimitiveSet* primitive = primItr->get();
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;
}

View File

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

View File

@@ -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;primNo<noPrimitiveAtStart;++primNo)
{
osg::PrimitiveSet* primitive = geom.getPrimitiveList()[primNo].get();
osg::PrimitiveSet* primitive = geom.getPrimitiveSetList()[primNo].get();
if (primitive->getMode()==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

View File

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