diff --git a/NEWS b/NEWS index dcc40a67b..574b82d1e 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,15 @@ OSG News (most significant items from ChangeLog) ================================================ + Support added for handling different extensions on different graphics + contexts. + + Sort callbacks added to osg::RenderStage. + + Support for multitexturing added to OpenFlight loader. + + Added PolygonStipple class. + 30th August 2002 - OpenSceneGraph-0.9.1.tar.gz >>> Support added for 1D & 3D textures, texture env combiners, secondary color and fog coords, DOFTransform and Sequence nodes. Inventor/VRML and LWO2 loaders added and the a port HP-UX! diff --git a/VisualStudio/osg/osg.dsp b/VisualStudio/osg/osg.dsp index 1c39f6aa7..84c6a7346 100755 --- a/VisualStudio/osg/osg.dsp +++ b/VisualStudio/osg/osg.dsp @@ -209,6 +209,10 @@ 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 @@ -557,6 +561,10 @@ SOURCE=..\..\Include\Osg\Geometry # End Source File # Begin Source File +SOURCE=..\..\Include\Osg\IndexedGeometry +# End Source File +# Begin Source File + SOURCE=..\..\Include\Osg\GeoSet # End Source File # Begin Source File diff --git a/VisualStudio/osgPlugins/osg/dot_osg.dsp b/VisualStudio/osgPlugins/osg/dot_osg.dsp index 17a27e09f..da27e5ca7 100755 --- a/VisualStudio/osgPlugins/osg/dot_osg.dsp +++ b/VisualStudio/osgPlugins/osg/dot_osg.dsp @@ -158,6 +158,10 @@ SOURCE=..\..\..\src\osgPlugins\osg\Geometry.cpp # End Source File # Begin Source File +SOURCE=..\..\..\src\osgPlugins\osg\IndexedGeometry.cpp +# End Source File +# Begin Source File + SOURCE=..\..\..\src\osgPlugins\osg\Group.cpp # End Source File # Begin Source File diff --git a/include/osg/CopyOp b/include/osg/CopyOp index 0b48e694f..ffd986756 100644 --- a/include/osg/CopyOp +++ b/include/osg/CopyOp @@ -19,7 +19,7 @@ class StateAttribute; class Node; class Drawable; class Array; -class Primitive; +class PrimitiveSet; /** Copy Op(erator) used to control the whether shallow or deep copy is used * during copy construction and clone operation.*/ @@ -56,8 +56,8 @@ class SG_EXPORT CopyOp virtual StateAttribute* operator() (const StateAttribute* attr) const; virtual Texture* operator() (const Texture* text) const; virtual Image* operator() (const Image* image) const; - virtual Array* operator() (const Array* image) const; - virtual Primitive* operator() (const Primitive* image) const; + virtual Array* operator() (const Array* array) const; + virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const; protected: diff --git a/include/osg/Geometry b/include/osg/Geometry index 0030bd8c8..317267155 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace osg { @@ -90,17 +90,17 @@ class SG_EXPORT Geometry : public Drawable const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; } - typedef std::vector< ref_ptr > PrimitiveList; + typedef std::vector< ref_ptr > PrimitiveList; void setPrimitiveList(const PrimitiveList& primitives) { _primitives = primitives; dirtyDisplayList(); } PrimitiveList& getPrimitiveList() { return _primitives; } const PrimitiveList& getPrimitiveList() const { return _primitives; } unsigned int getNumPrimitives() const { return _primitives.size(); } - Primitive* getPrimitive(unsigned int pos) { return _primitives[pos].get(); } - const Primitive* getPrimitive(unsigned int pos) const { return _primitives[pos].get(); } + PrimitiveSet* getPrimitive(unsigned int pos) { return _primitives[pos].get(); } + const PrimitiveSet* getPrimitive(unsigned int pos) const { return _primitives[pos].get(); } - void addPrimitive(Primitive* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); } + void addPrimitive(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); } bool verifyBindings() const; diff --git a/include/osg/IndexedGeometry b/include/osg/IndexedGeometry new file mode 100644 index 000000000..904761e4f --- /dev/null +++ b/include/osg/IndexedGeometry @@ -0,0 +1,185 @@ +//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_GEOMETRY +#define OSG_GEOMETRY 1 + +#include +#include +#include +#include +#include +#include + +namespace osg { + + +class SG_EXPORT IndexedGeometry : public Drawable +{ + public: + + IndexedGeometry(); + + /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ + IndexedGeometry(const IndexedGeometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY); + + virtual Object* cloneType() const { return osgNew IndexedGeometry(); } + virtual Object* clone(const CopyOp& copyop) const { return osgNew IndexedGeometry(*this,copyop); } + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual const char* libraryName() const { return "osg"; } + virtual const char* className() const { return "IndexedGeometry"; } + + virtual IndexedGeometry* asIndexedGeometry() { return this; } + virtual const IndexedGeometry* asIndexedGeometry() const { return this; } + + enum AttributeBinding + { + BIND_OFF=0, + BIND_OVERALL, + BIND_PER_PRIMITIVE_SET, + BIND_PER_PRIMITIVE, + BIND_PER_VERTEX + }; + + void setVertexArray(Vec3Array* array) { _vertexArray = array; dirtyDisplayList(); dirtyBound(); } + Vec3Array* getVertexArray() { return _vertexArray.get(); } + const Vec3Array* getVertexArray() const { return _vertexArray.get(); } + + void setVertexIndices(Array* array) { _vertexIndices = array; dirtyDisplayList(); dirtyBound(); } + Array* getVertexIndices() { return _vertexIndices.get(); } + const Array* 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(Array* array) { _normalIndices = array; dirtyDisplayList(); } + Array* getNormalIndices() { return _normalIndices.get(); } + const Array* 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(Array* array) { _colorIndices = array; dirtyDisplayList(); } + Array* getColorIndices() { return _colorIndices.get(); } + const Array* 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(Array* array) { _secondaryColorIndices = array; dirtyDisplayList(); } + Array* getSecondaryColorIndices() { return _secondaryColorIndices.get(); } + const Array* 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(Array* array) { _fogCoordIndices = array; dirtyDisplayList(); } + Array* getFogCoordIndices() { return _fogCoordIndices.get(); } + const Array* getFogCoordIndices() const { return _fogCoordIndices.get(); } + + + + typedef std::pair< ref_ptr, ref_ptr > TexCoordArrayPair; + typedef std::vector< TexCoordArrayPair > TexCoordArrayList; + + + void setTexCoordArray(unsigned int unit,Array*); + Array* getTexCoordArray(unsigned int unit); + const Array* getTexCoordArray(unsigned int unit) const; + + void setTexCoordIndices(unsigned int unit,Array*); + Array* getTexCoordIndices(unsigned int unit); + const Array* getTexCoordIndices(unsigned int unit) const; + + unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); } + TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; } + const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; } + + + typedef std::vector< ref_ptr > PrimitiveSetList; + + void setPrimitiveSetList(const PrimitiveSetList& primitives) { _primitives = primitives; dirtyDisplayList(); dirtyBound(); } + PrimitiveSetList& getPrimitiveSetList() { return _primitives; } + const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; } + + unsigned int getNumPrimitiveSet() const { return _primitives.size(); } + PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); } + const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); } + + void addPrimitiveSet(PrimitiveSet* primitive) { if (primitive) _primitives.push_back(primitive); dirtyDisplayList(); dirtyBound(); } + + + bool verifyBindings() const; + + void computeCorrectBindingsAndArraySizes(); + + + /** draw IndexedGeometry directly ignoring an OpenGL display list which could be attached. + * This is the internal draw method which does the drawing itself, + * and is the method to override when deriving from IndexedGeometry for user-drawn objects. + */ + virtual void drawImmediateMode(State& state); + + /** accept an AttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/ + virtual void accept(AttributeFunctor& af); + + /** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/ + virtual void accept(PrimitiveFunctor& pf); + + protected: + + IndexedGeometry& operator = (const IndexedGeometry&) { return *this;} + + virtual ~IndexedGeometry(); + + PrimitiveSetList _primitives; + + ref_ptr _vertexArray; + ref_ptr _vertexIndices; + + AttributeBinding _normalBinding; + ref_ptr _normalArray; + ref_ptr _normalIndices; + + AttributeBinding _colorBinding; + ref_ptr _colorArray; + ref_ptr _colorIndices; + + AttributeBinding _secondaryColorBinding; + ref_ptr _secondaryColorArray; + ref_ptr _secondaryColorIndices; + + AttributeBinding _fogCoordBinding; + ref_ptr _fogCoordArray; + ref_ptr _fogCoordIndices; + + TexCoordArrayList _texCoordList; + +}; + + +} + +#endif diff --git a/include/osg/Primitive b/include/osg/PrimitiveSet similarity index 84% rename from include/osg/Primitive rename to include/osg/PrimitiveSet index 3adae0213..f9c279b29 100644 --- a/include/osg/Primitive +++ b/include/osg/PrimitiveSet @@ -2,8 +2,8 @@ //Distributed under the terms of the GNU Library General Public License (LGPL) //as published by the Free Software Foundation. -#ifndef OSG_PRIMTIVE -#define OSG_PRIMTIVE 1 +#ifndef OSG_PRIMTIVESET +#define OSG_PRIMTIVESET 1 #include @@ -75,7 +75,7 @@ public: #endif -class Primitive : public Object +class PrimitiveSet : public Object { public: @@ -103,18 +103,18 @@ class Primitive : public Object POLYGON = GL_POLYGON }; - Primitive(Type primType=PrimitiveType,GLenum mode=0): + PrimitiveSet(Type primType=PrimitiveType,GLenum mode=0): _primitiveType(primType), _mode(mode) {} - Primitive(const Primitive& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + PrimitiveSet(const PrimitiveSet& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Object(prim,copyop), _primitiveType(prim._primitiveType), _mode(prim._mode) {} - virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } + virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast(obj)!=NULL; } virtual const char* libraryName() const { return "osg"; } - virtual const char* className() const { return "Primitive"; } + virtual const char* className() const { return "PrimitiveSet"; } Type getType() const { return _primitiveType; } @@ -135,22 +135,26 @@ class Primitive : public Object GLenum _mode; }; -class SG_EXPORT DrawArrays : public Primitive +// temporary addition for backwards compatiblity. +typedef PrimitiveSet Primitive; + + +class SG_EXPORT DrawArrays : public PrimitiveSet { public: DrawArrays(GLenum mode=0): - Primitive(DrawArraysPrimitiveType,mode), + PrimitiveSet(DrawArraysPrimitiveType,mode), _first(0), _count(0) {} DrawArrays(GLenum mode, GLint first, GLsizei count): - Primitive(DrawArraysPrimitiveType,mode), + PrimitiveSet(DrawArraysPrimitiveType,mode), _first(first), _count(count) {} DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Primitive(da,copyop), + PrimitiveSet(da,copyop), _first(da._first), _count(da._count) {} @@ -188,32 +192,32 @@ class SG_EXPORT DrawArrays : public Primitive GLsizei _count; }; -class SG_EXPORT DrawArrayLengths : public Primitive, public VectorSizei +class SG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorSizei { public: DrawArrayLengths(GLenum mode=0): - Primitive(DrawArrayLengthsPrimitiveType,mode), + PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), _first(0) {} DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Primitive(dal,copyop), + PrimitiveSet(dal,copyop), VectorSizei(dal), _first(dal._first) {} DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) : - Primitive(DrawArrayLengthsPrimitiveType,mode), + PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), VectorSizei(ptr,ptr+no), _first(first) {} DrawArrayLengths(GLenum mode,GLint first, unsigned int no) : - Primitive(DrawArrayLengthsPrimitiveType,mode), + PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), VectorSizei(no), _first(first) {} template DrawArrayLengths(GLenum mode, GLint first, InputIterator firstItr,InputIterator lastItr) : - Primitive(DrawArrayLengthsPrimitiveType,mode), + PrimitiveSet(DrawArrayLengthsPrimitiveType,mode), VectorSizei(firstItr,lastItr), _first(first) {} @@ -240,28 +244,28 @@ class SG_EXPORT DrawArrayLengths : public Primitive, public VectorSizei GLint _first; }; -class SG_EXPORT DrawElementsUByte : public Primitive, public VectorUByte +class SG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorUByte { public: DrawElementsUByte(GLenum mode=0): - Primitive(DrawElementsUBytePrimitiveType,mode) {} + PrimitiveSet(DrawElementsUBytePrimitiveType,mode) {} DrawElementsUByte(const DrawElementsUByte& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Primitive(array,copyop), + PrimitiveSet(array,copyop), VectorUByte(array) {} DrawElementsUByte(GLenum mode,unsigned int no,GLubyte* ptr) : - Primitive(DrawElementsUBytePrimitiveType,mode), + PrimitiveSet(DrawElementsUBytePrimitiveType,mode), VectorUByte(ptr,ptr+no) {} DrawElementsUByte(GLenum mode,unsigned int no) : - Primitive(DrawElementsUBytePrimitiveType,mode), + PrimitiveSet(DrawElementsUBytePrimitiveType,mode), VectorUByte(no) {} template DrawElementsUByte(GLenum mode, InputIterator first,InputIterator last) : - Primitive(DrawElementsUBytePrimitiveType,mode), + PrimitiveSet(DrawElementsUBytePrimitiveType,mode), VectorUByte(first,last) {} virtual Object* cloneType() const { return osgNew DrawElementsUByte(); } @@ -280,28 +284,28 @@ class SG_EXPORT DrawElementsUByte : public Primitive, public VectorUByte }; -class SG_EXPORT DrawElementsUShort : public Primitive, public VectorUShort +class SG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorUShort { public: DrawElementsUShort(GLenum mode=0): - Primitive(DrawElementsUShortPrimitiveType,mode) {} + PrimitiveSet(DrawElementsUShortPrimitiveType,mode) {} DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Primitive(array,copyop), + PrimitiveSet(array,copyop), VectorUShort(array) {} DrawElementsUShort(GLenum mode,unsigned int no,GLushort* ptr) : - Primitive(DrawElementsUShortPrimitiveType,mode), + PrimitiveSet(DrawElementsUShortPrimitiveType,mode), VectorUShort(ptr,ptr+no) {} DrawElementsUShort(GLenum mode,unsigned int no) : - Primitive(DrawElementsUShortPrimitiveType,mode), + PrimitiveSet(DrawElementsUShortPrimitiveType,mode), VectorUShort(no) {} template DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) : - Primitive(DrawElementsUShortPrimitiveType,mode), + PrimitiveSet(DrawElementsUShortPrimitiveType,mode), VectorUShort(first,last) {} virtual Object* cloneType() const { return osgNew DrawElementsUShort(); } @@ -319,28 +323,28 @@ class SG_EXPORT DrawElementsUShort : public Primitive, public VectorUShort virtual unsigned int getNumIndices() { return size(); } }; -class SG_EXPORT DrawElementsUInt : public Primitive, public VectorUInt +class SG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorUInt { public: DrawElementsUInt(GLenum mode=0): - Primitive(DrawElementsUIntPrimitiveType,mode) {} + PrimitiveSet(DrawElementsUIntPrimitiveType,mode) {} DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): - Primitive(array,copyop), + PrimitiveSet(array,copyop), VectorUInt(array) {} DrawElementsUInt(GLenum mode,unsigned int no,GLuint* ptr) : - Primitive(DrawElementsUIntPrimitiveType,mode), + PrimitiveSet(DrawElementsUIntPrimitiveType,mode), VectorUInt(ptr,ptr+no) {} DrawElementsUInt(GLenum mode,unsigned int no) : - Primitive(DrawElementsUIntPrimitiveType,mode), + PrimitiveSet(DrawElementsUIntPrimitiveType,mode), VectorUInt(no) {} template DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) : - Primitive(DrawElementsUIntPrimitiveType,mode), + PrimitiveSet(DrawElementsUIntPrimitiveType,mode), VectorUInt(first,last) {} virtual Object* cloneType() const { return osgNew DrawElementsUInt(); } @@ -358,11 +362,6 @@ class SG_EXPORT DrawElementsUInt : public Primitive, public VectorUInt virtual unsigned int getNumIndices() { return size(); } }; -// backwards compatibility with first incarnation of DrawElements nameing convention. -typedef DrawElementsUByte UByteDrawElements; -typedef DrawElementsUShort UShortDrawElements; -typedef DrawElementsUInt UIntDrawElements; - } #endif diff --git a/include/osg/StateSet b/include/osg/StateSet index b7c87e6db..78487a251 100644 --- a/include/osg/StateSet +++ b/include/osg/StateSet @@ -190,7 +190,7 @@ class SG_EXPORT StateSet : public Object void setRenderBinDetails(int binNum,const std::string& binName,RenderBinMode mode=USE_RENDERBIN_DETAILS); /** set the render bin details to inherit.*/ - void setRendingBinToInherit(); + void setRenderBinToInherit(); /** get the render bin mode.*/ inline RenderBinMode getRenderBinMode() const { return _binMode; } diff --git a/include/osgGA/Export b/include/osgGA/Export index f7d93a900..c07418baf 100644 --- a/include/osgGA/Export +++ b/include/osgGA/Export @@ -57,87 +57,87 @@ requests, translating them into calls to the windowing API. */ -/** - -\namespace osgGA::CmdLineArgs - -A collection of utilities for processing command line arguments. - -An osgGA::CmdLineArgs::Processor class is provided, which implements a chain -of responsibilty for handline command line arguments. Each item in the chain -is a subclass of the abstract osgGA::CmdLineArgs::ArgHandler. A number -of ArgHandlers are provided, though the user if free to implement their -own subclasses for specific needs (e.g. to validate an argument which -takes an integer which must be in a specific range). - -Let's look at an example... - -

Example

- -\code - -#include - -int main(int argc, char* argv[]) -{ - using namespace osg; - using namespace osgGA::CmdLineArgs; - - // Create some handlers - ref_ptr helpSwitch(new BoolHandler("[-h]","\t\tPrint this help and exit","-h")); - ref_ptr verboseSwitch(new BoolHandler("[-v]","\t\tActivate verbose output","-v")); - ref_ptr configFile( - new SwitchStringHandler("[-config ", - "\t\tSpecify a config file to load"), "-config"); - - Processor clp; - clp.push_back(helpSwitch.get()); - clp.push_back(verboseSwitch.get()); - clp.push_back(configFile.get()); - - try{ - clp.process(argc,argv); - } - catch(ArgHandlerX& e){ - cerr<wasSpecified()){ - clp.printHelp(cerr); - exit(0); - } - - if(verboseSwitch->wasSpecified()){ - // Activate verbosity... - } - - if(configFile->wasSpecified()){ - loadConfigFile(configFile->getString()); - } - -} - -\endcode - -The processor takes each argument on the command line in turn, and passes it -to the ArgHandler chain. Each ArgHandler is given the opportunity to handle -an argument and - if it requires - any subsequent arguments until the -end of the argument list (it can do this by incrementing the ArgIterator -passed to it. If an ArgHandler handles an argument (e.g. it's looking for -and recognises the argument '-h'), it returns true and further processing of -the argument stops. If an argument is not handled it is passed to the next -handler in the chain, and so on, until it is either handled, or it drops off -the end of the chain. - -A number of pre-written ArgHandlers are supplied. User's may use these -directly, may write their own, or may extend a pre-written ArgHandler to -customise it for their specific needs. - -*/ +// /** +// +// \namespace osgGA::CmdLineArgs +// +// A collection of utilities for processing command line arguments. +// +// An osgGA::CmdLineArgs::Processor class is provided, which implements a chain +// of responsibilty for handline command line arguments. Each item in the chain +// is a subclass of the abstract osgGA::CmdLineArgs::ArgHandler. A number +// of ArgHandlers are provided, though the user if free to implement their +// own subclasses for specific needs (e.g. to validate an argument which +// takes an integer which must be in a specific range). +// +// Let's look at an example... +// +//

Example

+// +// \code +// +// #include +// +// int main(int argc, char* argv[]) +// { +// using namespace osg; +// using namespace osgGA::CmdLineArgs; +// +// // Create some handlers +// ref_ptr helpSwitch(new BoolHandler("[-h]","\t\tPrint this help and exit","-h")); +// ref_ptr verboseSwitch(new BoolHandler("[-v]","\t\tActivate verbose output","-v")); +// ref_ptr configFile( +// new SwitchStringHandler("[-config ", +// "\t\tSpecify a config file to load"), "-config"); +// +// Processor clp; +// clp.push_back(helpSwitch.get()); +// clp.push_back(verboseSwitch.get()); +// clp.push_back(configFile.get()); +// +// try{ +// clp.process(argc,argv); +// } +// catch(ArgHandlerX& e){ +// cerr<wasSpecified()){ +// clp.printHelp(cerr); +// exit(0); +// } +// +// if(verboseSwitch->wasSpecified()){ +// // Activate verbosity... +// } +// +// if(configFile->wasSpecified()){ +// loadConfigFile(configFile->getString()); +// } +// +// } +// +// \endcode +// +// The processor takes each argument on the command line in turn, and passes it +// to the ArgHandler chain. Each ArgHandler is given the opportunity to handle +// an argument and - if it requires - any subsequent arguments until the +// end of the argument list (it can do this by incrementing the ArgIterator +// passed to it. If an ArgHandler handles an argument (e.g. it's looking for +// and recognises the argument '-h'), it returns true and further processing of +// the argument stops. If an argument is not handled it is passed to the next +// handler in the chain, and so on, until it is either handled, or it drops off +// the end of the chain. +// +// A number of pre-written ArgHandlers are supplied. User's may use these +// directly, may write their own, or may extend a pre-written ArgHandler to +// customise it for their specific needs. +// +// */ diff --git a/src/Demos/osgbillboard/osgbillboard.cpp b/src/Demos/osgbillboard/osgbillboard.cpp index fb9e7b47f..07e0d7bda 100644 --- a/src/Demos/osgbillboard/osgbillboard.cpp +++ b/src/Demos/osgbillboard/osgbillboard.cpp @@ -54,7 +54,7 @@ osg::Drawable* createSquare(const osg::Vec3& corner,const osg::Vec3& width,const (*tcoords)[3].set(0.0f,1.0f); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4)); + geom->addPrimitive(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::Primitive::LINES,0,6)); + geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); osg::StateSet* stateset = new osg::StateSet; osg::LineWidth* linewidth = new osg::LineWidth(); diff --git a/src/Demos/osgcube/osgcube.cpp b/src/Demos/osgcube/osgcube.cpp index b7e608acd..01033069c 100644 --- a/src/Demos/osgcube/osgcube.cpp +++ b/src/Demos/osgcube/osgcube.cpp @@ -82,12 +82,12 @@ osg::Geode* createGeometryCube() // set up the primitives - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,0,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,4,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,8,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,12,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,16,4)); - cube->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::POLYGON,20,4)); + 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)); // set up coords. diff --git a/src/Demos/osggeometry/osggeometry.cpp b/src/Demos/osggeometry/osggeometry.cpp index eea8c0da4..20ab1eb1c 100644 --- a/src/Demos/osggeometry/osggeometry.cpp +++ b/src/Demos/osggeometry/osggeometry.cpp @@ -116,7 +116,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::Primitive::POINTS,0,vertices->size())); + pointsGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,vertices->size())); // add the points geomtry to the geode. @@ -161,7 +161,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::Primitive::LINES,0,8)); + linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,8)); // add the points geomtry to the geode. @@ -203,7 +203,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::Primitive::LINE_STRIP,0,5)); + linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,5)); // add the points geomtry to the geode. @@ -250,7 +250,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::Primitive::LINE_LOOP,0,numCoords)); + linesGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,numCoords)); // add the points geomtry to the geode. @@ -322,7 +322,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::Primitive::POLYGON,0,numCoords)); + polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords)); printTriangles("Polygon",*polyGeom); @@ -369,7 +369,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::Primitive::QUADS,0,numCoords)); + polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords)); printTriangles("Quads",*polyGeom); @@ -418,7 +418,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::Primitive::QUAD_STRIP,0,numCoords)); + polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,numCoords)); printTriangles("Quads strip",*polyGeom); @@ -486,9 +486,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::Primitive::TRIANGLES,0,6)); - polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_STRIP,6,6)); - polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLE_FAN,12,5)); + 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)); // polygon stipple osg::StateSet* stateSet = new osg::StateSet(); @@ -604,7 +604,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::UShortDrawElements(osg::Primitive::QUADS,numIndices,myIndices)); + polyGeom->addPrimitive(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. diff --git a/src/Demos/osghangglide/base.cpp b/src/Demos/osghangglide/base.cpp index 20933f11c..e4a4e27e7 100644 --- a/src/Demos/osghangglide/base.cpp +++ b/src/Demos/osghangglide/base.cpp @@ -46,7 +46,7 @@ Node *makeBase( void ) geom->setColorArray( colors ); geom->setColorBinding( Geometry::BIND_OVERALL ); - geom->addPrimitive( new DrawArrays(Primitive::TRIANGLE_FAN,0,19) ); + geom->addPrimitive( new DrawArrays(PrimitiveSet::TRIANGLE_FAN,0,19) ); Texture2D *tex = new Texture2D; diff --git a/src/Demos/osghangglide/sky.cpp b/src/Demos/osghangglide/sky.cpp index 80dc438fa..140185e9a 100644 --- a/src/Demos/osghangglide/sky.cpp +++ b/src/Demos/osghangglide/sky.cpp @@ -75,7 +75,7 @@ Node *makeSky( void ) for( i = 0; i < nlev-1; i++ ) { - UShortDrawElements* drawElements = new UShortDrawElements(Primitive::TRIANGLE_STRIP); + DrawElementsUShort* drawElements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP); drawElements->reserve(38); for( j = 0; j <= 18; j++ ) diff --git a/src/Demos/osghangglide/tank.cpp b/src/Demos/osghangglide/tank.cpp index bbde9caf8..f5f1454f3 100644 --- a/src/Demos/osghangglide/tank.cpp +++ b/src/Demos/osghangglide/tank.cpp @@ -102,7 +102,7 @@ Node *makeTank( void ) c++; } - gset->addPrimitive( new DrawArrays(Primitive::TRIANGLE_STRIP,0,c) ); + gset->addPrimitive( 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(Primitive::TRIANGLE_FAN,prev_c,c-prev_c)); + gset->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,prev_c,c-prev_c)); diff --git a/src/Demos/osghangglide/terrain.cpp b/src/Demos/osghangglide/terrain.cpp index 56327c341..17aa89195 100644 --- a/src/Demos/osghangglide/terrain.cpp +++ b/src/Demos/osghangglide/terrain.cpp @@ -99,7 +99,7 @@ Node *makeTerrain( void ) for( i = 0; i < m-2; i++ ) { - UShortDrawElements* elements = new UShortDrawElements(Primitive::TRIANGLE_STRIP); + DrawElementsUShort* elements = new DrawElementsUShort(PrimitiveSet::TRIANGLE_STRIP); elements->reserve(39*2); for( j = 0; j < n; j++ ) { diff --git a/src/Demos/osghangglide/trees.cpp b/src/Demos/osghangglide/trees.cpp index e3e41d6cc..94161060b 100644 --- a/src/Demos/osghangglide/trees.cpp +++ b/src/Demos/osghangglide/trees.cpp @@ -183,7 +183,7 @@ static Geometry *makeTree( _tree *tree, StateSet *dstate ) geom->setColorArray( &l ); geom->setColorBinding( Geometry::BIND_OVERALL ); - geom->addPrimitive( new DrawArrays(Primitive::QUADS,0,4) ); + geom->addPrimitive( new DrawArrays(PrimitiveSet::QUADS,0,4) ); geom->setStateSet( dstate ); diff --git a/src/Demos/osglight/osglight.cpp b/src/Demos/osglight/osglight.cpp index 48747a7ed..9fea4db53 100644 --- a/src/Demos/osglight/osglight.cpp +++ b/src/Demos/osglight/osglight.cpp @@ -193,7 +193,7 @@ osg::Geometry* createWall(const osg::Vec3& v1,const osg::Vec3& v2,const osg::Vec for(row=0;rowreserve(noXSteps*2); for(unsigned int col=0;colsetColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4)); + geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); osg::Geode* geode = osgNew osg::Geode; geode->addDrawable(geom); @@ -390,7 +390,7 @@ int main( int argc, char **argv ) if (manuallyCreateImpostors) { - viewer.setEventHandler(new OccluderEventHandler(viewer.getViewportSceneView(0),rootnode)); + viewer.addEventHandler(new OccluderEventHandler(viewer.getViewportSceneView(0),rootnode)); } // open the viewer window. diff --git a/src/Demos/osgprerender/osgprerender.cpp b/src/Demos/osgprerender/osgprerender.cpp index 38957ad5c..4a50eda86 100644 --- a/src/Demos/osgprerender/osgprerender.cpp +++ b/src/Demos/osgprerender/osgprerender.cpp @@ -518,7 +518,7 @@ osg::Node* createPreRenderSubGraph(osg::Node* subgraph) polyGeom->setColorArray(colors); polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); - polyGeom->addPrimitive(new osg::DrawArrays(osg::Primitive::QUAD_STRIP,0,vertices->size())); + polyGeom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,vertices->size())); // new we need to add the texture to the Drawable, we do so by creating a // StateSet to contain the Texture StateAttribute. diff --git a/src/Demos/osgreflect/osgreflect.cpp b/src/Demos/osgreflect/osgreflect.cpp index 2f8953861..e709389d8 100644 --- a/src/Demos/osgreflect/osgreflect.cpp +++ b/src/Demos/osgreflect/osgreflect.cpp @@ -92,7 +92,7 @@ osg::Drawable* createMirrorSurface(float xMin,float xMax,float yMin,float yMax,f geom->setColorArray(colours); geom->setColorBinding(osg::Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4)); + geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/Demos/osgsequence/osgsequence.cpp b/src/Demos/osgsequence/osgsequence.cpp index e836b2b22..13d2161f2 100644 --- a/src/Demos/osgsequence/osgsequence.cpp +++ b/src/Demos/osgsequence/osgsequence.cpp @@ -187,7 +187,7 @@ int main( int argc, char **argv ) viewer.addViewport(rootNode); // register additional event handler - viewer.setEventHandler(osgNew MyEventHandler(&seq), 0); + viewer.addEventHandler(osgNew MyEventHandler(&seq), 0); // register trackball, flight and drive. viewer.registerCameraManipulator(new osgGA::TrackballManipulator); diff --git a/src/Demos/osgtexture2D/osgtexture2D.cpp b/src/Demos/osgtexture2D/osgtexture2D.cpp index 04ee5daf8..9d46b65e0 100644 --- a/src/Demos/osgtexture2D/osgtexture2D.cpp +++ b/src/Demos/osgtexture2D/osgtexture2D.cpp @@ -122,7 +122,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) (*tcoords)[3].set(textureCoordMax,textureCoordMax); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4)); + geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/Demos/osgtexture3D/osgtexture3D.cpp b/src/Demos/osgtexture3D/osgtexture3D.cpp index 076b4b610..50b2c379b 100644 --- a/src/Demos/osgtexture3D/osgtexture3D.cpp +++ b/src/Demos/osgtexture3D/osgtexture3D.cpp @@ -164,7 +164,7 @@ osg::Drawable* createSquare(float textureCoordMax=1.0f) (*tcoords)[3].set(textureCoordMax,textureCoordMax); geom->setTexCoordArray(0,tcoords); - geom->addPrimitive(osgNew osg::DrawArrays(osg::Primitive::QUADS,0,4)); + geom->addPrimitive(osgNew osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); return geom; } diff --git a/src/osg/CopyOp.cpp b/src/osg/CopyOp.cpp index f5f54c7e6..f3960fdae 100644 --- a/src/osg/CopyOp.cpp +++ b/src/osg/CopyOp.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include using namespace osg; @@ -85,10 +85,10 @@ Array* CopyOp::operator() (const Array* array) const return const_cast(array); } -Primitive* CopyOp::operator() (const Primitive* primitive) const +PrimitiveSet* CopyOp::operator() (const PrimitiveSet* primitive) const { if (primitive && _flags&DEEP_COPY_PRIMITIVES) - return dynamic_cast(primitive->clone(*this)); + return dynamic_cast(primitive->clone(*this)); else - return const_cast(primitive); + return const_cast(primitive); } diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index 24f326db7..c2408382b 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -1025,13 +1025,13 @@ Geometry* GeoSet::convertToGeometry() for( int i = 0; i < _numprims; i++ ) { - UShortDrawElements* n = new UShortDrawElements; + DrawElementsUShort* n = new DrawElementsUShort; geom->addPrimitive(n); if (_cindex._is_ushort) - geom->addPrimitive(osgNew UShortDrawElements( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] )); + geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _primLengths[i],&_cindex._ptr._ushort[index] )); else - geom->addPrimitive(osgNew UIntDrawElements( (GLenum)_oglprimtype, _primLengths[i], &_cindex._ptr._uint[index] )); + geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _primLengths[i], &_cindex._ptr._uint[index] )); index += _primLengths[i]; } @@ -1062,9 +1062,9 @@ Geometry* GeoSet::convertToGeometry() if( _cindex.valid()) { if (_cindex._is_ushort) - geom->addPrimitive(osgNew UShortDrawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort )); + geom->addPrimitive(osgNew DrawElementsUShort( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._ushort )); else - geom->addPrimitive(osgNew UIntDrawElements( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint )); + geom->addPrimitive(osgNew DrawElementsUInt( (GLenum)_oglprimtype, _cindex._size, _cindex._ptr._uint )); } else geom->addPrimitive(new DrawArrays( (GLenum)_oglprimtype, 0, _numcoords )); diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 9f62e42ec..2e34f30d9 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -28,7 +28,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop): pitr!=geometry._primitives.end(); ++pitr) { - Primitive* primitive = copyop(pitr->get()); + PrimitiveSet* primitive = copyop(pitr->get()); if (primitive) _primitives.push_back(primitive); } diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 8ca5db3ae..f835f40f1 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -527,7 +527,7 @@ Geode* osg::createGeodeForImage(osg::Image* image,float s,float t) geom->setColorArray(colours); geom->setColorBinding(Geometry::BIND_OVERALL); - geom->addPrimitive(osgNew DrawArrays(Primitive::QUADS,0,4)); + geom->addPrimitive(osgNew DrawArrays(PrimitiveSet::QUADS,0,4)); // set up the geode. osg::Geode* geode = osgNew osg::Geode; diff --git a/src/osg/IndexedGeometry.cpp b/src/osg/IndexedGeometry.cpp new file mode 100644 index 000000000..7aa3473e2 --- /dev/null +++ b/src/osg/IndexedGeometry.cpp @@ -0,0 +1,612 @@ +#include +#include +#include + +using namespace osg; + +IndexedGeometry::IndexedGeometry() +{ + _normalBinding = BIND_OFF; + _colorBinding = BIND_OFF; + _secondaryColorBinding = BIND_OFF; + _fogCoordBinding = BIND_OFF; +} + +IndexedGeometry::IndexedGeometry(const IndexedGeometry& geometry,const CopyOp& copyop): + Drawable(geometry,copyop), + _vertexArray(dynamic_cast(copyop(geometry._vertexArray.get()))), + _normalBinding(geometry._normalBinding), + _normalArray(dynamic_cast(copyop(geometry._normalArray.get()))), + _colorBinding(geometry._colorBinding), + _colorArray(copyop(geometry._colorArray.get())), + _secondaryColorBinding(geometry._secondaryColorBinding), + _secondaryColorArray(copyop(geometry._secondaryColorArray.get())), + _fogCoordBinding(geometry._fogCoordBinding), + _fogCoordArray(dynamic_cast(copyop(geometry._fogCoordArray.get()))) +{ + for(PrimitiveSetList::const_iterator pitr=geometry._primitives.begin(); + pitr!=geometry._primitives.end(); + ++pitr) + { + PrimitiveSet* primitive = copyop(pitr->get()); + if (primitive) _primitives.push_back(primitive); + } + + for(TexCoordArrayList::const_iterator titr=geometry._texCoordList.begin(); + titr!=geometry._texCoordList.end(); + ++titr) + { + _texCoordList.push_back(*titr); + } +} + +IndexedGeometry::~IndexedGeometry() +{ + // no need to delete, all automatically handled by ref_ptr :-) +} + +void IndexedGeometry::setTexCoordArray(unsigned int unit,Array* array) +{ + if (_texCoordList.size()<=unit) + _texCoordList.resize(unit+1); + + _texCoordList[unit].first = array; + + dirtyDisplayList(); +} + +Array* IndexedGeometry::getTexCoordArray(unsigned int unit) +{ + if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); + else return 0; +} + +const Array* IndexedGeometry::getTexCoordArray(unsigned int unit) const +{ + if (unit<_texCoordList.size()) return _texCoordList[unit].first.get(); + else return 0; +} + +typedef void (APIENTRY * FogCoordProc) (const GLfloat* coord); +typedef void (APIENTRY * SecondaryColor3ubvProc) (const GLubyte* coord); +typedef void (APIENTRY * SecondaryColor3fvProc) (const GLfloat* coord); + +void IndexedGeometry::drawImmediateMode(State& state) +{ + if (!_vertexArray.valid()) return; + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // set up the vertex arrays. + // + state.setVertexPointer(3,GL_FLOAT,0,_vertexArray->getDataPointer()); + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // set up texture coordinates. + // + unsigned int i; + for(i=0;i<_texCoordList.size();++i) + { + Array* array = _texCoordList[i].first.get(); + if (array) + state.setTexCoordPointer(i,array->getDataSize(),array->getDataType(),0,array->getDataPointer()); + else + state.disableTexCoordPointer(i); + } + state.disableTexCoordPointersAboveAndIncluding(i); + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // +; // set up normals if required. + // + Vec3* normalPointer = 0; + if (_normalArray.valid() && !_normalArray->empty()) normalPointer = &(_normalArray->front()); + + AttributeBinding normalBinding = _normalBinding; + if (normalBinding!=BIND_OFF && !normalPointer) + { + // switch off if not supported or have a valid data. + normalBinding = BIND_OFF; + } + + switch (normalBinding) + { + case(BIND_OFF): + state.disableNormalPointer(); + break; + case(BIND_OVERALL): + state.disableNormalPointer(); + glNormal3fv(reinterpret_cast(normalPointer)); + break; + case(BIND_PER_PRIMITIVE): + state.disableNormalPointer(); + break; + case(BIND_PER_VERTEX): + state.setNormalPointer(GL_FLOAT,0,normalPointer); + break; + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up color if required. + // + // set up colors, complicated by the fact that the color array + // might be bound in 4 different ways, and be represented as 3 different data types - + // Vec3, Vec4 or UByte4 Arrays. + // + const unsigned char* colorPointer = 0; + unsigned int colorStride = 0; + Array::Type colorType = Array::ArrayType; + if (_colorArray.valid()) + { + colorType = _colorArray->getType(); + switch(colorType) + { + case(Array::UByte4ArrayType): + { + colorPointer = reinterpret_cast(_colorArray->getDataPointer()); + colorStride = 4; + break; + } + case(Array::Vec3ArrayType): + { + colorPointer = reinterpret_cast(_colorArray->getDataPointer()); + colorStride = 12; + break; + } + case(Array::Vec4ArrayType): + { + colorPointer = reinterpret_cast(_colorArray->getDataPointer()); + colorStride = 16; + break; + } + default: + break; + } + } + + + AttributeBinding colorBinding = _colorBinding; + if (colorBinding!=BIND_OFF && !colorPointer) + { + // switch off if not supported or have a valid data. + colorBinding = BIND_OFF; + } + + switch (colorBinding) + { + case(BIND_OFF): + state.disableColorPointer(); + break; + case(BIND_OVERALL): + state.disableColorPointer(); + if (colorPointer) + { + switch(colorType) + { + case(Array::UByte4ArrayType): + glColor4ubv(reinterpret_cast(colorPointer)); + break; + case(Array::Vec3ArrayType): + glColor3fv(reinterpret_cast(colorPointer)); + break; + case(Array::Vec4ArrayType): + glColor4fv(reinterpret_cast(colorPointer)); + break; + default: + break; + } + } + break; + case(BIND_PER_PRIMITIVE): + state.disableColorPointer(); + break; + case(BIND_PER_VERTEX): + state.setColorPointer(_colorArray->getDataSize(),_colorArray->getDataType(),0,colorPointer); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up secondary color if required. + // + // set up colors, complicated by the fact that the color array + // might be bound in 4 different ways, and be represented as 3 different data types - + // Vec3, Vec4 or UByte4 Arrays. + const unsigned char* secondaryColorPointer = 0; + unsigned int secondaryColorStride = 0; + Array::Type secondaryColorType = Array::ArrayType; + if (_secondaryColorArray.valid()) + { + secondaryColorType = _secondaryColorArray->getType(); + switch(secondaryColorType) + { + case(Array::UByte4ArrayType): + { + secondaryColorPointer = reinterpret_cast(_secondaryColorArray->getDataPointer()); + secondaryColorStride = 4; + break; + } + case(Array::Vec3ArrayType): + { + secondaryColorPointer = reinterpret_cast(_secondaryColorArray->getDataPointer()); + secondaryColorStride = 12; + break; + } + default: + break; + } + } + + static SecondaryColor3ubvProc s_glSecondaryColor3ubv = + (SecondaryColor3ubvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT"); + static SecondaryColor3fvProc s_glSecondaryColor3fv = + (SecondaryColor3fvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3fv","glSecondaryColor3fvEXT"); + + AttributeBinding secondaryColorBinding = _secondaryColorBinding; + if (secondaryColorBinding!=BIND_OFF && (!secondaryColorPointer || !s_glSecondaryColor3ubv || !s_glSecondaryColor3fv)) + { + // switch off if not supported or have a valid data. + secondaryColorBinding = BIND_OFF; + } + + + switch (secondaryColorBinding) + { + case(BIND_OFF): + state.disableSecondaryColorPointer(); + break; + case(BIND_OVERALL): + state.disableSecondaryColorPointer(); + if (secondaryColorPointer) + { + switch(secondaryColorType) + { + case(Array::UByte4ArrayType): + s_glSecondaryColor3ubv(reinterpret_cast(secondaryColorPointer)); + break; + case(Array::Vec3ArrayType): + s_glSecondaryColor3fv(reinterpret_cast(secondaryColorPointer)); + break; + default: + break; + } + } + break; + case(BIND_PER_PRIMITIVE): + state.disableSecondaryColorPointer(); + break; + case(BIND_PER_VERTEX): + state.setSecondaryColorPointer(_secondaryColorArray->getDataSize(),_secondaryColorArray->getDataType(),0,secondaryColorPointer); + } + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Set up fog coord if required. + // + + GLfloat* fogCoordPointer = 0; + if (_fogCoordArray.valid() && !_fogCoordArray->empty()) fogCoordPointer = &(_fogCoordArray->front()); + + static FogCoordProc s_glFogCoordfv = + (FogCoordProc) osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT"); + + + AttributeBinding fogCoordBinding = _fogCoordBinding; + if (fogCoordBinding!=BIND_OFF && (!fogCoordPointer || !s_glFogCoordfv)) + { + // swithc off if not supported or have a valid data. + fogCoordBinding = BIND_OFF; + } + + switch (fogCoordBinding) + { + case(BIND_OFF): + state.disableFogCoordPointer(); + break; + case(BIND_OVERALL): + state.disableFogCoordPointer(); + s_glFogCoordfv(fogCoordPointer); + break; + case(BIND_PER_PRIMITIVE): + state.disableFogCoordPointer(); + break; + case(BIND_PER_VERTEX): + state.setFogCoordPointer(GL_FLOAT,0,fogCoordPointer); + break; + } + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // draw the primitives themselves. + // + + for(PrimitiveSetList::iterator itr=_primitives.begin(); + itr!=_primitives.end(); + ++itr) + { + if (normalBinding==BIND_PER_PRIMITIVE_SET) + { + glNormal3fv((const GLfloat *)normalPointer++); + } + + if (colorBinding==BIND_PER_PRIMITIVE_SET) + { + switch(colorType) + { + case(Array::UByte4ArrayType): + glColor4ubv(reinterpret_cast(colorPointer)); + break; + case(Array::Vec3ArrayType): + glColor3fv(reinterpret_cast(colorPointer)); + break; + case(Array::Vec4ArrayType): + glColor4fv(reinterpret_cast(colorPointer)); + break; + default: + break; + } + colorPointer += colorStride; + } + + if (secondaryColorBinding==BIND_PER_PRIMITIVE_SET) + { + switch(secondaryColorType) + { + case(Array::UByte4ArrayType): + s_glSecondaryColor3ubv(reinterpret_cast(secondaryColorPointer)); + break; + case(Array::Vec3ArrayType): + s_glSecondaryColor3fv(reinterpret_cast(secondaryColorPointer)); + break; + default: + break; + } + secondaryColorPointer += secondaryColorStride; + } + + if (fogCoordBinding==BIND_PER_PRIMITIVE_SET) + { + s_glFogCoordfv(fogCoordPointer++); + } + + //(*itr)->draw(); + + PrimitiveSet* primitiveset = itr->get(); + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + DrawArrays* drawArray = static_cast(primitiveset); + glBegin(primitiveset->getMode()); + + Vec3* vertices = &(_vertexArray->front()) + drawArray->getFirst(); + int count = drawArray->getCount(); + for(GLsizei ci=0;ciptr()); + ++vertices; + } + + glEnd(); + break; + } + case(PrimitiveSet::DrawArrayLengthsPrimitiveType): + { + //* drawArray = static_cast<*>(primitiveset); + glBegin(primitiveset->getMode()); + glEnd(); + break; + } + case(PrimitiveSet::DrawElementsUBytePrimitiveType): + { + //* drawArray = static_cast<*>(primitiveset); + glBegin(primitiveset->getMode()); + glEnd(); + break; + } + case(PrimitiveSet::DrawElementsUShortPrimitiveType): + { + //* drawArray = static_cast<*>(primitiveset); + glBegin(primitiveset->getMode()); + glEnd(); + break; + } + case(PrimitiveSet::DrawElementsUIntPrimitiveType): + { + //* drawArray = static_cast<*>(primitiveset); + glBegin(primitiveset->getMode()); + 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): + 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): + if (!_colorArray.valid()) return false; + if (_colorArray->getNumElements()!=_primitives.size()) return false; + break; + case(BIND_PER_VERTEX): + if (_vertexArray.valid()) + { + if (!_colorArray.valid()) return false; + if (_colorArray->getNumElements()!=_vertexArray->getNumElements()) return false; + } + else if (_colorArray.valid() && _colorArray->getNumElements()>0) return false; + break; + } + + for(TexCoordArrayList::const_iterator itr=_texCoordList.begin(); + itr!=_texCoordList.end(); + ++itr) + { + const Array* array = itr->first.get(); + if (_vertexArray.valid()) + { + if (array && array->getNumElements()!=_vertexArray->getNumElements()) return false; + } + else if (array && array->getNumElements()>0) return false; + } + + return true; +} + +void IndexedGeometry::computeCorrectBindingsAndArraySizes() +{ + if (verifyBindings()) return; + + if (!_vertexArray.valid() || _vertexArray->empty()) + { + // no vertex array so switch everything off. + + _vertexArray = 0; + + _colorArray = 0; + _colorBinding = BIND_OFF; + + _normalArray = 0; + _normalBinding = BIND_OFF; + + _texCoordList.clear(); + + notify(INFO)<<"Info: remove redundent attribute arrays from empty osg::IndexedGeometry"<getNumElements()==0) + { + _normalArray = 0; + _normalBinding = BIND_OFF; + } + else if (_normalArray->getNumElements()>1) + { + // trim the array down to 1 element long. + _normalArray->erase(_normalArray->begin()+1,_normalArray->end()); + } + break; + case(BIND_PER_PRIMITIVE): + if (!_normalArray.valid()) + { + _normalBinding = BIND_OFF; + } + else if (_normalArray->getNumElements()<_primitives.size()) + { + _normalArray = 0; + _normalBinding = BIND_OFF; + } + else if (_normalArray->getNumElements()>_primitives.size()) + { + // trim the array down to size of the number of primitives. + _normalArray->erase(_normalArray->begin()+_primitives.size(),_normalArray->end()); + } + break; + case(BIND_PER_VERTEX): + if (!_normalArray.valid()) + { + _normalBinding = BIND_OFF; + } + else if (_normalArray->getNumElements()<_vertexArray->getNumElements()) + { + _normalArray = 0; + _normalBinding = BIND_OFF; + } + else if (_normalArray->getNumElements()>_vertexArray->getNumElements()) + { + // trim the array down to size of the number of primitives. + _normalArray->erase(_normalArray->begin()+_vertexArray->getNumElements(),_normalArray->end()); + } + break; + } + + // TODO colours and tex coords. + +} diff --git a/src/osg/Makefile b/src/osg/Makefile index ce73a790e..094a4ce27 100644 --- a/src/osg/Makefile +++ b/src/osg/Makefile @@ -39,6 +39,7 @@ CXXFILES =\ Image.cpp\ Impostor.cpp\ ImpostorSprite.cpp\ + IndexedGeometry.cpp\ LOD.cpp\ Light.cpp\ LightModel.cpp\ @@ -61,7 +62,7 @@ CXXFILES =\ PolygonOffset.cpp\ PolygonStipple.cpp\ PositionAttitudeTransform.cpp\ - Primitive.cpp\ + PrimitiveSet.cpp\ Projection.cpp\ Quat.cpp\ Sequence.cpp\ diff --git a/src/osg/Primitive.cpp b/src/osg/PrimitiveSet.cpp similarity index 98% rename from src/osg/Primitive.cpp rename to src/osg/PrimitiveSet.cpp index 0bd0260c5..96d7c8d7a 100644 --- a/src/osg/Primitive.cpp +++ b/src/osg/PrimitiveSet.cpp @@ -1,4 +1,4 @@ -#include +#include using namespace osg; diff --git a/src/osg/StateSet.cpp b/src/osg/StateSet.cpp index f20100481..1022d1fab 100644 --- a/src/osg/StateSet.cpp +++ b/src/osg/StateSet.cpp @@ -60,7 +60,7 @@ StateSet::StateSet() _renderingHint = DEFAULT_BIN; - setRendingBinToInherit(); + setRenderBinToInherit(); } StateSet::StateSet(const StateSet& rhs,const CopyOp& copyop):Object(rhs,copyop) @@ -341,7 +341,7 @@ void StateSet::setGlobalDefaults() { _renderingHint = DEFAULT_BIN; - setRendingBinToInherit(); + setRenderBinToInherit(); setMode(GL_DEPTH_TEST,StateAttribute::ON); @@ -358,7 +358,7 @@ void StateSet::setAllToInherit() { _renderingHint = DEFAULT_BIN; - setRendingBinToInherit(); + setRenderBinToInherit(); _modeList.clear(); _attributeList.clear(); @@ -775,12 +775,27 @@ void StateSet::setRenderingHint(const int hint) { _renderingHint = hint; // temporary hack to get new render bins working. - if (_renderingHint==TRANSPARENT_BIN) + switch(_renderingHint) { - _binMode = USE_RENDERBIN_DETAILS; - _binNum = 1; - _binName = "DepthSortedBin"; -// _binName = "RenderBin"; + case(TRANSPARENT_BIN): + { + _binMode = USE_RENDERBIN_DETAILS; + _binNum = 1; + _binName = "DepthSortedBin"; + break; + } + case(OPAQUE_BIN): + { + _binMode = USE_RENDERBIN_DETAILS; + _binNum = 0; + _binName = "RenderBin"; + break; + } + default: // DEFAULT_BIN + { + setRenderBinToInherit(); + break; + } } } @@ -791,7 +806,7 @@ void StateSet::setRenderBinDetails(const int binNum,const std::string& binName,c _binName = binName; } -void StateSet::setRendingBinToInherit() +void StateSet::setRenderBinToInherit() { _binMode = INHERIT_RENDERBIN_DETAILS; _binNum = 0; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index a2216ad44..9a9a69dd7 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -558,7 +558,7 @@ void Texture::Extensions::glCompressedTexImage2D(GLenum target, GLint level, GLe if (_glCompressedTexImage2D) { typedef void (APIENTRY * CompressedTexImage2DArbProc) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid *data); - (*((CompressedTexImage2DArbProc)_glCompressedTexImage2D))(target, level, internalformat, width, height, border, imageSize, data); + ((CompressedTexImage2DArbProc)_glCompressedTexImage2D)(target, level, internalformat, width, height, border, imageSize, data); } else { diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index d8389cb08..0944f11cf 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -345,7 +345,7 @@ void Texture3D::Extensions::glTexImage3D( GLenum target, GLint level, GLenum int if (_glTexImage3D) { typedef void (APIENTRY * GLTexImage3DProc) ( GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels); - (*((GLTexImage3DProc)_glTexImage3D))( target, level, internalFormat, width, height, depth, border, format, type, pixels); + ((GLTexImage3DProc)_glTexImage3D)( target, level, internalFormat, width, height, depth, border, format, type, pixels); } else { @@ -358,7 +358,7 @@ void Texture3D::Extensions::glTexSubImage3D( GLenum target, GLint level, GLint x if (_glTexSubImage3D) { typedef void (APIENTRY * GLTexSubImage3DProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels); - (*((GLTexSubImage3DProc)_glTexSubImage3D))( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); + ((GLTexSubImage3DProc)_glTexSubImage3D)( target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); } else { @@ -371,7 +371,7 @@ void Texture3D::Extensions::glCopyTexSubImage3D( GLenum target, GLint level, GLi if (_glCopyTexSubImage3D) { typedef void (APIENTRY * GLCopyTexSubImageProc) ( GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height ); - (*((GLCopyTexSubImageProc)_glCopyTexSubImage3D))(target, level, xoffset, yoffset, zoffset, x, y, width, height); + ((GLCopyTexSubImageProc)_glCopyTexSubImage3D)(target, level, xoffset, yoffset, zoffset, x, y, width, height); } else { @@ -384,7 +384,7 @@ void Texture3D::Extensions::gluBuild3DMipmaps( GLenum target, GLint internalForm if (_gluBuild3DMipmaps) { typedef void (APIENTRY * GLUBuild3DMipMapsProc) ( GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *data); - (*((GLUBuild3DMipMapsProc)_gluBuild3DMipmaps))(target, internalFormat, width, height, depth, format, type, data); + ((GLUBuild3DMipMapsProc)_gluBuild3DMipmaps)(target, internalFormat, width, height, depth, format, type, data); } else { diff --git a/src/osgPlugins/flt/GeoSetBuilder.cpp b/src/osgPlugins/flt/GeoSetBuilder.cpp index f06b0e294..638ffb8dc 100644 --- a/src/osgPlugins/flt/GeoSetBuilder.cpp +++ b/src/osgPlugins/flt/GeoSetBuilder.cpp @@ -76,11 +76,15 @@ void DynGeoSet::append(DynGeoSet* source) break; \ } -const osg::Primitive::Mode NO_PRIMITIVE_TYPE = (osg::Primitive::Mode)0xffff; +const osg::PrimitiveSet::Mode NO_PRIMITIVE_TYPE = (osg::PrimitiveSet::Mode)0xffff; DynGeoSet::DynGeoSet() { - _primtype=NO_PRIMITIVE_TYPE; + _primtype = NO_PRIMITIVE_TYPE; + _normal_binding = osg::Geometry::BIND_OFF; + _color_binding = osg::Geometry::BIND_OFF; + _texture_binding = osg::Geometry::BIND_OFF; + _geom = new osg::Geometry; } @@ -181,7 +185,7 @@ void DynGeoSet::addToGeometry(osg::Geometry* geom) } } - if (_primtype!=osg::Primitive::POLYGON) + if (_primtype!=osg::PrimitiveSet::POLYGON) { geom->addPrimitive(new osg::DrawArrays(_primtype,indexBase,_coordList.size())); } @@ -308,17 +312,17 @@ DynGeoSet* GeoSetBuilder::findMatchingGeoSet() } -osg::Primitive::Mode GeoSetBuilder::findPrimType(const int nVertices) +osg::PrimitiveSet::Mode GeoSetBuilder::findPrimType(const int nVertices) { switch (nVertices) { - case 1: return osg::Primitive::POINTS; - case 2: return osg::Primitive::LINES; - case 3: return osg::Primitive::TRIANGLES; - case 4: return osg::Primitive::QUADS; + case 1: return osg::PrimitiveSet::POINTS; + case 2: return osg::PrimitiveSet::LINES; + case 3: return osg::PrimitiveSet::TRIANGLES; + case 4: return osg::PrimitiveSet::QUADS; } - if (nVertices>=5) return osg::Primitive::POLYGON; + if (nVertices>=5) return osg::PrimitiveSet::POLYGON; return NO_PRIMITIVE_TYPE; } diff --git a/src/osgPlugins/flt/GeoSetBuilder.h b/src/osgPlugins/flt/GeoSetBuilder.h index 95b381887..4e8b1ca41 100644 --- a/src/osgPlugins/flt/GeoSetBuilder.h +++ b/src/osgPlugins/flt/GeoSetBuilder.h @@ -111,8 +111,8 @@ class DynGeoSet : public osg::Referenced osg::Geometry::AttributeBinding getNormalBinding() const { return _normal_binding; } osg::Geometry::AttributeBinding getTextureBinding() const { return _texture_binding; } - void setPrimType(osg::Primitive::Mode type) { _primtype=type; } - osg::Primitive::Mode getPrimType() const { return _primtype; } + void setPrimType(osg::PrimitiveSet::Mode type) { _primtype=type; } + osg::PrimitiveSet::Mode getPrimType() const { return _primtype; } inline void addPrimLen(const int len) { _primLenList.push_back(len); } inline void addCoord(const osg::Vec3& coord) { _coordList.push_back(coord); } @@ -150,7 +150,7 @@ class DynGeoSet : public osg::Referenced osg::ref_ptr _stateset; - osg::Primitive::Mode _primtype; + osg::PrimitiveSet::Mode _primtype; PrimLenList _primLenList; CoordList _coordList; @@ -194,7 +194,7 @@ class GeoSetBuilder void initPrimData(); DynGeoSet* findMatchingGeoSet(); - osg::Primitive::Mode findPrimType(const int nVertices); + osg::PrimitiveSet::Mode findPrimType(const int nVertices); private: diff --git a/src/osgPlugins/flt/Registry.cpp b/src/osgPlugins/flt/Registry.cpp index 9a324ea56..bc2339367 100644 --- a/src/osgPlugins/flt/Registry.cpp +++ b/src/osgPlugins/flt/Registry.cpp @@ -37,8 +37,8 @@ Record* Registry::getPrototype(const int opcode) if (itr != _recordProtoMap.end()) { return (*itr).second.get(); } - osg::notify( osg::WARN ) - << "flt::Registry::addPrototype: Unkown opcode: " << opcode << "\n"; + osg::notify( osg::NOTICE ) + << "flt::Registry::getPrototype: Unkown opcode: " << opcode << "\n"; return NULL; diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 291073aa1..a77cb462e 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -959,17 +959,17 @@ void ConvertFromFLT::setCullFaceAndWireframe ( const SFace *pSFace, osg::StateSe break; case FaceRecord::WIREFRAME_NOT_CLOSED: - dgset->setPrimType(osg::Primitive::LINE_STRIP); + dgset->setPrimType(osg::PrimitiveSet::LINE_STRIP); break; case FaceRecord::WIREFRAME_CLOSED: - dgset->setPrimType(osg::Primitive::LINE_LOOP); + dgset->setPrimType(osg::PrimitiveSet::LINE_LOOP); break; case FaceRecord::OMNIDIRECTIONAL_LIGHT: case FaceRecord::UNIDIRECTIONAL_LIGHT: case FaceRecord::BIDIRECTIONAL_LIGHT: - dgset->setPrimType(osg::Primitive::POINTS); + dgset->setPrimType(osg::PrimitiveSet::POINTS); break; } } @@ -1440,7 +1440,7 @@ int ConvertFromFLT::addVertices(GeoSetBuilder* pBuilder, PrimNodeRecord* primRec if (vertices > 0) { - if (dgset->getPrimType() == osg::Primitive::POINTS) + if (dgset->getPrimType() == osg::PrimitiveSet::POINTS) { for (i=0; i < vertices; i++) dgset->addPrimLen(1); @@ -1672,7 +1672,7 @@ void ConvertFromFLT::visitLightPoint(GeoSetBuilder* pBuilder, LightPointRecord* osg::StateSet* stateSet = dgset->getStateSet(); SLightPoint *pSLightPoint = (SLightPoint*)rec->getData(); - dgset->setPrimType(osg::Primitive::POINTS); + dgset->setPrimType(osg::PrimitiveSet::POINTS); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateSet->setMode(GL_POINT_SMOOTH, osg::StateAttribute::ON); dgset->setColorBinding(osg::Geometry::BIND_PER_VERTEX); @@ -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::Primitive::TRIANGLE_STRIP,0,mesh->getNumVertices()) ); + geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::TRIANGLE_FAN: - geometry->addPrimitive ( new osg::DrawArrays(osg::Primitive::TRIANGLE_FAN,0,mesh->getNumVertices()) ); + geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::QUADRILATERAL_STRIP: - geometry->addPrimitive ( new osg::DrawArrays(osg::Primitive::QUAD_STRIP,0,mesh->getNumVertices()) ); + geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::QUAD_STRIP,0,mesh->getNumVertices()) ); break; case MeshPrimitiveRecord::INDEXED_POLYGON: - geometry->addPrimitive ( new osg::DrawArrays(osg::Primitive::POLYGON,0,mesh->getNumVertices()) ); + geometry->addPrimitive ( new osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,mesh->getNumVertices()) ); break; default: assert ( 0 ); // What type is this? diff --git a/src/osgPlugins/iv/osgvisitor.cpp b/src/osgPlugins/iv/osgvisitor.cpp index 39ecb8a40..f0128c4ee 100644 --- a/src/osgPlugins/iv/osgvisitor.cpp +++ b/src/osgPlugins/iv/osgvisitor.cpp @@ -163,9 +163,9 @@ void OSGVisitor::applySeparator(Separator *sep) } } -osg::Primitive *generatePrimitive(PolygonList &polys, unsigned primsize) { +osg::PrimitiveSet *generatePrimitive(PolygonList &polys, unsigned primsize) { unsigned i,j; - osg::Primitive *p=0; + osg::PrimitiveSet *p=0; // Fisrt of all count the number of polygons unsigned count=0; for (i=0;igetPolygons(); for (i=1;i<=4;i++) { - osg::Primitive *p=generatePrimitive(polys,i); + osg::PrimitiveSet *p=generatePrimitive(polys,i); if (p!=0) { geometry->addPrimitive(p); } @@ -348,7 +348,7 @@ void OSGVisitor::applyIndexedTriStripSet(IndexedTriStripSet *its) { for (j=0;jaddPrimitive(new osg::DrawElementsUShort(osg::Primitive::TRIANGLE_STRIP,vindex.size(),indices)); + geometry->addPrimitive(new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP,vindex.size(),indices)); } diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 855bc1e62..5909348a2 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -589,8 +589,8 @@ osg::Drawable* ReaderWriter3DS::createDrawable(Lib3dsMesh *m,FaceList& faceLis // create primitives int numIndices = faceList.size()*3; - UShortDrawElements* elements = new osg::UShortDrawElements(osg::Primitive::TRIANGLES,numIndices); - UShortDrawElements::iterator index_itr = elements->begin(); + DrawElementsUShort* elements = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES,numIndices); + DrawElementsUShort::iterator index_itr = elements->begin(); for (fitr=faceList.begin(); fitr!=faceList.end(); diff --git a/src/osgPlugins/lwo/Lwo2Layer.cpp b/src/osgPlugins/lwo/Lwo2Layer.cpp index 6f0cd53c9..6ae750540 100644 --- a/src/osgPlugins/lwo/Lwo2Layer.cpp +++ b/src/osgPlugins/lwo/Lwo2Layer.cpp @@ -157,7 +157,7 @@ Lwo2Layer::GenerateGeode( Geode& geode, short tags_count ) (*texcoords).push_back(uv); } } - geometry->addPrimitive(osgNew DrawArrays(Primitive::POLYGON, + geometry->addPrimitive(osgNew DrawArrays(PrimitiveSet::POLYGON, (*coords).size() - (*pol_itr)->size(), (*pol_itr)->size())); } diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index 3e8e7f2af..dcb1a53a6 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -198,26 +198,26 @@ osgDB::ReaderWriter::ReadResult ReaderWriterLWO::readNode_LWO1(const std::string { GeometryCollection& gc = mtgcm[face.material]; - osg::Primitive::Mode mode; + osg::PrimitiveSet::Mode mode; switch(face.index_cnt) { case(0): - mode = osg::Primitive::POINTS; + mode = osg::PrimitiveSet::POINTS; break; case(1): - mode = osg::Primitive::POINTS; + mode = osg::PrimitiveSet::POINTS; break; case(2): - mode = osg::Primitive::LINES; + mode = osg::PrimitiveSet::LINES; break; case(3): - mode = osg::Primitive::TRIANGLES; + mode = osg::PrimitiveSet::TRIANGLES; break; case(4): - mode = osg::Primitive::QUADS; + mode = osg::PrimitiveSet::QUADS; break; default: - mode = osg::Primitive::POLYGON; + mode = osg::PrimitiveSet::POLYGON; break; } diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 24e827ace..cab4e6914 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -207,7 +207,7 @@ osg::Drawable* ReaderWriterOBJ::makeDrawable(GLMmodel* obj, osg::Geometry* geom = new osg::Geometry; // primitives are only triangles - geom->addPrimitive(new osg::DrawArrays(osg::Primitive::TRIANGLES,0,ntris*3)); + geom->addPrimitive(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,ntris*3)); // the following code for mapping the coords, normals and texcoords // is complicated greatly by the need to create separate out the diff --git a/src/osgPlugins/osg/Geometry.cpp b/src/osgPlugins/osg/Geometry.cpp index d838f54e4..7d509087b 100644 --- a/src/osgPlugins/osg/Geometry.cpp +++ b/src/osgPlugins/osg/Geometry.cpp @@ -1,3 +1,5 @@ +#if 1 + #include #include @@ -19,7 +21,7 @@ const char* Geometry_getPrimitiveModeStr(GLenum mode); Array* Array_readLocalData(Input& fr); -bool Primitve_readLocalData(Input& fr,osg::Geometry& geom); +bool Primitive_readLocalData(Input& fr,osg::Geometry& geom); // register the read and write functions with the osgDB::Registry. RegisterDotOsgWrapperProxy g_GeometryFuncProxy @@ -54,7 +56,7 @@ bool Geometry_readLocalData(Object& obj, Input& fr) while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) { - if (!Primitve_readLocalData(fr,geom)) ++fr; + if (!Primitive_readLocalData(fr,geom)) ++fr; } ++fr; @@ -577,7 +579,7 @@ bool Array_writeLocalData(const Array& array,Output& fw) } -bool Primitve_readLocalData(Input& fr,osg::Geometry& geom) +bool Primitive_readLocalData(Input& fr,osg::Geometry& geom) { bool iteratorAdvanced = false; if (fr.matchSequence("DrawArrays %w %i %i")) @@ -731,19 +733,19 @@ bool Primitve_readLocalData(Input& fr,osg::Geometry& geom) return iteratorAdvanced; } -bool Primitve_writeLocalData(const Primitive& prim,Output& fw) +bool Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw) { switch(prim.getType()) { - case(Primitive::DrawArraysPrimitiveType): + case(PrimitiveSet::DrawArraysPrimitiveType): { const DrawArrays& cprim = static_cast(prim); fw<(prim); fw<(prim); fw<(prim); fw<(prim); fw< + +#include +#include +#include + +using namespace osg; +using namespace osgDB; + +// forward declare functions to use later. +bool IndexedGeometry_readLocalData(Object& obj, Input& fr); +bool IndexedGeometry_writeLocalData(const Object& obj, Output& fw); + +bool IndexedGeometry_matchBindingTypeStr(const char* str,IndexedGeometry::AttributeBinding& mode); +const char* IndexedGeometry_getBindingTypeStr(IndexedGeometry::AttributeBinding mode); + +bool IndexedGeometry_matchPrimitiveModeStr(const char* str,GLenum& mode); +const char* IndexedGeometry_getPrimitiveModeStr(GLenum mode); + +Array* IG_Array_readLocalData(Input& fr); + +bool IG_Primitive_readLocalData(Input& fr,osg::IndexedGeometry& geom); + +// register the read and write functions with the osgDB::Registry. +// RegisterDotOsgWrapperProxy g_GeometryFuncProxy +// ( +// osgNew osg::IndexedGeometry, +// "Geometry", +// "Object Drawable Geometry", +// &IndexedGeometry_readLocalData, +// &IndexedGeometry_writeLocalData, +// DotOsgWrapper::READ_AND_WRITE +// ); + +RegisterDotOsgWrapperProxy g_IndexedGeometryFuncProxy +( + osgNew osg::IndexedGeometry, + "IndexedGeometry", + "Object Drawable IndexedGeometry", + &IndexedGeometry_readLocalData, + &IndexedGeometry_writeLocalData, + DotOsgWrapper::READ_AND_WRITE +); + +bool IndexedGeometry_readLocalData(Object& obj, Input& fr) +{ + bool iteratorAdvanced = false; + + IndexedGeometry& geom = static_cast(obj); + + bool matchedFirst = false; + if ((matchedFirst=fr.matchSequence("Primitives %i {")) || fr.matchSequence("PrimitivesSet %i {") ) + { + int entry = fr[1].getNoNestedBrackets(); + + int capacity; + fr[1].getInt(capacity); + + IndexedGeometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); + if (capacity>0) primitives.reserve(capacity); + + + fr += 3; + + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + if (!IG_Primitive_readLocalData(fr,geom)) ++fr; + } + + ++fr; + + iteratorAdvanced = true; + + } + + if (fr.matchSequence("VertexArray %i {")) + { + + int entry = fr[0].getNoNestedBrackets(); + + int capacity; + fr[1].getInt(capacity); + + Vec3Array* vertices = osgNew Vec3Array; + vertices->reserve(capacity); + + fr += 3; + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec3 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) + { + fr += 3; + vertices->push_back(v); + } + else + { + ++fr; + } + } + + geom.setVertexArray(vertices); + + iteratorAdvanced = true; + ++fr; + + + } + + IndexedGeometry::AttributeBinding normalBinding=IndexedGeometry::BIND_OFF; + if (fr[0].matchWord("NormalBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),normalBinding)) + { + geom.setNormalBinding(normalBinding); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("NormalArray %i {")) + { + int entry = fr[0].getNoNestedBrackets(); + + int capacity; + fr[1].getInt(capacity); + + Vec3Array* normals = osgNew Vec3Array; + normals->reserve(capacity); + + fr += 3; + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec3 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) + { + fr += 3; + normals->push_back(v); + } + else + { + ++fr; + } + } + + geom.setNormalArray(normals); + + iteratorAdvanced = true; + ++fr; + } + + IndexedGeometry::AttributeBinding colorBinding=IndexedGeometry::BIND_OFF; + if (fr[0].matchWord("ColorBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),colorBinding)) + { + geom.setColorBinding(colorBinding); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("ColorArray %w %i {")) + { + ++fr; + Array* colors = IG_Array_readLocalData(fr); + if (colors) + { + geom.setColorArray(colors); + iteratorAdvanced = true; + } + } + + IndexedGeometry::AttributeBinding secondaryColorBinding=IndexedGeometry::BIND_OFF; + if (fr[0].matchWord("SecondaryColorBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),secondaryColorBinding)) + { + geom.setSecondaryColorBinding(secondaryColorBinding); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("SecondaryColorArray %w %i {")) + { + ++fr; + Array* colors = IG_Array_readLocalData(fr); + if (colors) + { + geom.setSecondaryColorArray(colors); + iteratorAdvanced = true; + } + } + + + + IndexedGeometry::AttributeBinding fogCoordBinding=IndexedGeometry::BIND_OFF; + if (fr[0].matchWord("FogCoordBinding") && IndexedGeometry_matchBindingTypeStr(fr[1].getStr(),fogCoordBinding)) + { + geom.setFogCoordBinding(fogCoordBinding); + fr+=2; + iteratorAdvanced = true; + } + + if (fr.matchSequence("FogCoordArray %i {")) + { + int entry = fr[0].getNoNestedBrackets(); + + int capacity; + fr[1].getInt(capacity); + + FloatArray* fogcoords = osgNew FloatArray; + fogcoords->reserve(capacity); + + fr += 3; + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + float fc; + if (fr[0].getFloat(fc)) + { + ++fr; + fogcoords->push_back(fc); + } + else + { + ++fr; + } + } + + geom.setFogCoordArray(fogcoords); + + iteratorAdvanced = true; + ++fr; + } + + if (fr.matchSequence("TexCoordArray %i %w %i {")) + { + int unit=0; + fr[1].getInt(unit); + + fr+=2; + Array* texcoords = IG_Array_readLocalData(fr); + if (texcoords) + { + geom.setTexCoordArray(unit,texcoords); + iteratorAdvanced = true; + } + + } + + return iteratorAdvanced; +} + + +Array* IG_Array_readLocalData(Input& fr) +{ + int entry = fr[0].getNoNestedBrackets(); + + const char* arrayName = fr[0].getStr(); + + unsigned int capacity = 0; + fr[1].getUInt(capacity); + ++fr; + + fr += 2; + + if (strcmp(arrayName,"ByteArray")==0) + { + ByteArray* array = osgNew ByteArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + int int_value; + if (fr[0].getInt(int_value)) + { + ++fr; + array->push_back(int_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"ShortArray")==0) + { + ShortArray* array = osgNew ShortArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + int int_value; + if (fr[0].getInt(int_value)) + { + ++fr; + array->push_back(int_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"IntArray")==0) + { + IntArray* array = osgNew IntArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + int int_value; + if (fr[0].getInt(int_value)) + { + ++fr; + array->push_back(int_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"UByteArray")==0) + { + UByteArray* array = osgNew UByteArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int uint_value; + if (fr[0].getUInt(uint_value)) + { + ++fr; + array->push_back(uint_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"UShortArray")==0) + { + UShortArray* array = osgNew UShortArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int uint_value; + if (fr[0].getUInt(uint_value)) + { + ++fr; + array->push_back(uint_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"UIntArray")==0) + { + UIntArray* array = osgNew UIntArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int uint_value; + if (fr[0].getUInt(uint_value)) + { + ++fr; + array->push_back(uint_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"UByte4Array")==0) + { + UByte4Array* array = osgNew UByte4Array; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int r,g,b,a; + if (fr[0].getUInt(r) && + fr[1].getUInt(g) && + fr[2].getUInt(b) && + fr[3].getUInt(a)) + { + ++fr; + array->push_back(osg::UByte4(r,g,b,a)); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"FloatArray")==0) + { + FloatArray* array = osgNew FloatArray; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + float float_value; + if (fr[0].getFloat(float_value)) + { + ++fr; + array->push_back(float_value); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"Vec2Array")==0) + { + Vec2Array* array = osgNew Vec2Array; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec2 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y())) + { + fr += 2; + array->push_back(v); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"Vec3Array")==0) + { + Vec3Array* array = osgNew Vec3Array; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec3 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z())) + { + fr += 3; + array->push_back(v); + } + else ++fr; + } + ++fr; + return array; + } + else if (strcmp(arrayName,"Vec4Array")==0) + { + Vec4Array* array = osgNew Vec4Array; + array->reserve(capacity); + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + Vec4 v; + if (fr[0].getFloat(v.x()) && fr[1].getFloat(v.y()) && fr[2].getFloat(v.z()) && fr[3].getFloat(v.w())) + { + fr += 4; + array->push_back(v); + } + else ++fr; + } + ++fr; + return array; + } + + return 0; +} + + +template +void IG_Array_writeLocalData(Output& fw, Iterator first, Iterator last,int noItemsPerLine=8) +{ + fw.indent() << "{"<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<(array); + fw<setMode(mode); + prim->setFirst(first); + prim->reserve(capacity); + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int i; + if (fr[0].getUInt(i)) + { + prim->push_back(i); + ++fr; + } + } + ++fr; + + geom.addPrimitiveSet(prim); + + iteratorAdvanced = true; + } + else if (fr.matchSequence("DrawElementsUByte %w %i {")) + { + int entry = fr[1].getNoNestedBrackets(); + + GLenum mode; + IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); + + int capacity; + fr[2].getInt(capacity); + + fr += 4; + + DrawElementsUByte* prim = osgNew DrawElementsUByte; + prim->setMode(mode); + prim->reserve(capacity); + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int i; + if (fr[0].getUInt(i)) + { + prim->push_back(i); + ++fr; + } + } + ++fr; + + geom.addPrimitiveSet(prim); + + iteratorAdvanced = true; + } + else if (fr.matchSequence("DrawElementsUShort %w %i {")) + { + int entry = fr[1].getNoNestedBrackets(); + + GLenum mode; + IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); + + int capacity; + fr[2].getInt(capacity); + + fr += 4; + + DrawElementsUShort* prim = osgNew DrawElementsUShort; + prim->setMode(mode); + prim->reserve(capacity); + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int i; + if (fr[0].getUInt(i)) + { + prim->push_back(i); + ++fr; + } + } + ++fr; + + geom.addPrimitiveSet(prim); + + iteratorAdvanced = true; + } + else if (fr.matchSequence("DrawElementsUInt %w %i {")) + { + int entry = fr[1].getNoNestedBrackets(); + + GLenum mode; + IndexedGeometry_matchPrimitiveModeStr(fr[1].getStr(),mode); + + int capacity; + fr[2].getInt(capacity); + + fr += 4; + + DrawElementsUInt* prim = osgNew DrawElementsUInt; + prim->setMode(mode); + prim->reserve(capacity); + + while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) + { + unsigned int i; + if (fr[0].getUInt(i)) + { + prim->push_back(i); + ++fr; + } + } + ++fr; + + geom.addPrimitiveSet(prim); + + iteratorAdvanced = true; + } + + return iteratorAdvanced; +} + +bool IG_Primitive_writeLocalData(const PrimitiveSet& prim,Output& fw) +{ + + switch(prim.getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + const DrawArrays& cprim = static_cast(prim); + fw<(prim); + fw<(prim); + fw<(prim); + fw<(prim); + fw<(obj); + + const IndexedGeometry::PrimitiveSetList& primitives = geom.getPrimitiveSetList(); + if (!primitives.empty()) + { + fw.indent() << "PrimitiveSets "<addPrimitive(new DrawArrays(Primitive::TRIANGLES,0,numPrims*3)); + geometry->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLES,0,numPrims*3)); } break; case trpgGeometry::TriStrips: @@ -267,7 +267,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) int first=0; for(int i=0;iaddPrimitive(new DrawArrays(Primitive::TRIANGLE_STRIP,first,primitives[i])); + geometry->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_STRIP,first,primitives[i])); first += primitives[i]; } @@ -286,7 +286,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) int i; for(i=0;iaddPrimitive(new DrawArrays(Primitive::TRIANGLE_FAN,first,primitives[i])); + geometry->addPrimitive(new DrawArrays(PrimitiveSet::TRIANGLE_FAN,first,primitives[i])); first += primitives[i]; } diff --git a/src/osgText/Text.cpp b/src/osgText/Text.cpp index deb55dbd8..4ec4f3e52 100644 --- a/src/osgText/Text.cpp +++ b/src/osgText/Text.cpp @@ -181,6 +181,10 @@ void Text::drawImmediateMode(State& state) if(!_initAlignment) initAlignment(); + + // we must disable all the vertex arrays to prevent any state + // propagating into text. + state.disableAllVertexArrays(); // draw boundingBox if(_drawMode & BOUNDINGBOX) diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 96536ea5e..4b7c18b52 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -1189,16 +1189,16 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) itr!=primitives.end(); ++itr) { - osg::Primitive* prim = itr->get(); - if (prim->getMode()==osg::Primitive::POLYGON) + osg::PrimitiveSet* prim = itr->get(); + if (prim->getMode()==osg::PrimitiveSet::POLYGON) { if (prim->getNumIndices()==3) { - prim->setMode(osg::Primitive::TRIANGLES); + prim->setMode(osg::PrimitiveSet::TRIANGLES); } else if (prim->getNumIndices()==4) { - prim->setMode(osg::Primitive::QUADS); + prim->setMode(osg::PrimitiveSet::QUADS); } } } @@ -1218,8 +1218,8 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) unsigned int primNo=0; while(primNo+1getMode()) { - case(osg::Primitive::POINTS): - case(osg::Primitive::LINES): - case(osg::Primitive::TRIANGLES): - case(osg::Primitive::QUADS): + case(osg::PrimitiveSet::POINTS): + case(osg::PrimitiveSet::LINES): + case(osg::PrimitiveSet::TRIANGLES): + case(osg::PrimitiveSet::QUADS): combine = true; break; } @@ -1244,19 +1244,19 @@ bool Optimizer::MergeGeometryVisitor::mergeGeode(osg::Geode& geode) switch(lhs->getType()) { - case(osg::Primitive::DrawArraysPrimitiveType): + case(osg::PrimitiveSet::DrawArraysPrimitiveType): combine = mergePrimitive(*(static_cast(lhs)),*(static_cast(rhs))); break; - case(osg::Primitive::DrawArrayLengthsPrimitiveType): + case(osg::PrimitiveSet::DrawArrayLengthsPrimitiveType): combine = mergePrimitive(*(static_cast(lhs)),*(static_cast(rhs))); break; - case(osg::Primitive::DrawElementsUBytePrimitiveType): + case(osg::PrimitiveSet::DrawElementsUBytePrimitiveType): combine = mergePrimitive(*(static_cast(lhs)),*(static_cast(rhs))); break; - case(osg::Primitive::DrawElementsUShortPrimitiveType): + case(osg::PrimitiveSet::DrawElementsUShortPrimitiveType): combine = mergePrimitive(*(static_cast(lhs)),*(static_cast(rhs))); break; - case(osg::Primitive::DrawElementsUIntPrimitiveType): + case(osg::PrimitiveSet::DrawElementsUIntPrimitiveType): combine = mergePrimitive(*(static_cast(lhs)),*(static_cast(rhs))); break; default: @@ -1336,7 +1336,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom primItr!=rhs.getPrimitiveList().end(); ++primItr) { - osg::Primitive* primitive = primItr->get(); + osg::PrimitiveSet* primitive = primItr->get(); primitive->offsetIndices(base); } diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index d64a9f422..4e78d4969 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -80,12 +80,12 @@ void SmoothingVisitor::smooth(osg::Geometry& geom) { switch((*itr)->getMode()) { - case(Primitive::TRIANGLES): - case(Primitive::TRIANGLE_STRIP): - case(Primitive::TRIANGLE_FAN): - case(Primitive::QUADS): - case(Primitive::QUAD_STRIP): - case(Primitive::POLYGON): + case(PrimitiveSet::TRIANGLES): + case(PrimitiveSet::TRIANGLE_STRIP): + case(PrimitiveSet::TRIANGLE_FAN): + case(PrimitiveSet::QUADS): + case(PrimitiveSet::QUAD_STRIP): + case(PrimitiveSet::POLYGON): ++numSurfacePrimitives; break; default: diff --git a/src/osgUtil/Tesselator.cpp b/src/osgUtil/Tesselator.cpp index 686d74ae6..e9178075b 100644 --- a/src/osgUtil/Tesselator.cpp +++ b/src/osgUtil/Tesselator.cpp @@ -140,15 +140,15 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) int noPrimitiveAtStart = geom.getPrimitiveList().size(); for(int primNo=0;primNogetMode()==osg::Primitive::POLYGON) + osg::PrimitiveSet* primitive = geom.getPrimitiveList()[primNo].get(); + if (primitive->getMode()==osg::PrimitiveSet::POLYGON) { beginTesselation(); beginContour(); switch(primitive->getType()) { - case(osg::Primitive::DrawArraysPrimitiveType): + case(osg::PrimitiveSet::DrawArraysPrimitiveType): { osg::DrawArrays* drawArray = static_cast(primitive); unsigned int first = drawArray->getFirst(); @@ -159,7 +159,7 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) } break; } - case(osg::Primitive::DrawElementsUBytePrimitiveType): + case(osg::PrimitiveSet::DrawElementsUBytePrimitiveType): { osg::DrawElementsUByte* drawElements = static_cast(primitive); for(osg::DrawElementsUByte::iterator indexItr=drawElements->begin(); @@ -170,7 +170,7 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) } break; } - case(osg::Primitive::DrawElementsUShortPrimitiveType): + case(osg::PrimitiveSet::DrawElementsUShortPrimitiveType): { osg::DrawElementsUShort* drawElements = static_cast(primitive); for(osg::DrawElementsUShort::iterator indexItr=drawElements->begin(); @@ -181,7 +181,7 @@ void Tesselator::retesselatePolygons(osg::Geometry& geom) } break; } - case(osg::Primitive::DrawElementsUIntPrimitiveType): + case(osg::PrimitiveSet::DrawElementsUIntPrimitiveType): { osg::DrawElementsUInt* drawElements = static_cast(primitive); for(osg::DrawElementsUInt::iterator indexItr=drawElements->begin(); diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp index d0e0f0539..82c04e4e4 100644 --- a/src/osgUtil/TriStripVisitor.cpp +++ b/src/osgUtil/TriStripVisitor.cpp @@ -48,12 +48,12 @@ void TriStripVisitor::stripify(Geometry& geom) { switch((*itr)->getMode()) { - case(Primitive::TRIANGLES): - case(Primitive::TRIANGLE_STRIP): - case(Primitive::TRIANGLE_FAN): - case(Primitive::QUADS): - case(Primitive::QUAD_STRIP): - case(Primitive::POLYGON): + case(PrimitiveSet::TRIANGLES): + case(PrimitiveSet::TRIANGLE_STRIP): + case(PrimitiveSet::TRIANGLE_FAN): + case(PrimitiveSet::QUADS): + case(PrimitiveSet::QUAD_STRIP): + case(PrimitiveSet::POLYGON): ++numSurfacePrimitives; break; default: @@ -76,12 +76,12 @@ void TriStripVisitor::stripify(Geometry& geom) { switch((*itr)->getMode()) { - case(Primitive::TRIANGLES): - case(Primitive::TRIANGLE_STRIP): - case(Primitive::TRIANGLE_FAN): - case(Primitive::QUADS): - case(Primitive::QUAD_STRIP): - case(Primitive::POLYGON): + case(PrimitiveSet::TRIANGLES): + case(PrimitiveSet::TRIANGLE_STRIP): + case(PrimitiveSet::TRIANGLE_FAN): + case(PrimitiveSet::QUADS): + case(PrimitiveSet::QUAD_STRIP): + case(PrimitiveSet::POLYGON): (*itr)->accept(taf); break; default: @@ -124,7 +124,7 @@ void TriStripVisitor::stripify(Geometry& geom) NvStripInfo *strip = strips[i]; int nStripFaceCount = strip->m_faces.size(); - osg::UShortDrawElements* elements = osgNew osg::UShortDrawElements(osg::Primitive::TRIANGLE_STRIP); + osg::DrawElementsUShort* elements = osgNew osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP); elements->reserve(nStripFaceCount+2); new_primitives.push_back(elements); @@ -187,7 +187,7 @@ void TriStripVisitor::stripify(Geometry& geom) if (leftoverFaces.size()) { - osg::UShortDrawElements* triangles = osgNew osg::UShortDrawElements(osg::Primitive::TRIANGLES); + osg::DrawElementsUShort* triangles = osgNew osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES); triangles->reserve(leftoverFaces.size()*3); new_primitives.push_back(triangles);