diff --git a/CMakeLists.txt b/CMakeLists.txt index ea91f4338..71184cc37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -433,6 +433,7 @@ MARK_AS_ADVANCED(OSG_DISABLE_MSVC_WARNINGS) OPTION(OSG_USE_REF_PTR_IMPLICIT_OUTPUT_CONVERSION "Set to ON to use the ref_ptr<> T* operator() output conversion. " ON) + OPTION(OSG_GL1_AVAILABLE "Set to OFF to disable use of OpenGL 1.x functions library." ON) OPTION(OSG_GL2_AVAILABLE "Set to OFF to disable use of OpenGL 2.x functions library." ON) OPTION(OSG_GL3_AVAILABLE "Set to OFF to disable use of OpenGL 3.x functions library." OFF) @@ -456,6 +457,8 @@ OPTION(OSG_GL_FIXED_FUNCTION_AVAILABLE "Set to OFF to disable use of OpenGL fixe OPTION(OSG_CPP_EXCEPTIONS_AVAILABLE "Set to OFF to disable compile of OSG components that use C++ exceptions." ON) +OPTION(OSG_USE_DEPRECATED_GEOMETRY_METHODS "Set to ON to enable use of deprecated osg::Geometry functions." ON) + ################################################################################ # Set Config file diff --git a/applications/osgfilecache/osgfilecache.cpp b/applications/osgfilecache/osgfilecache.cpp index 8b6d56c5b..d23b91436 100644 --- a/applications/osgfilecache/osgfilecache.cpp +++ b/applications/osgfilecache/osgfilecache.cpp @@ -130,40 +130,6 @@ struct Extents osg::Vec2d _max; }; -class CheckValidVisitor : public osg::NodeVisitor -{ -public: - - CheckValidVisitor(): - osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), - _numInvalidGeometries(0) {} - - void apply(osg::Geode& geode) - { - unsigned int local_numInvalidGeometries = 0; - for(unsigned int i=0; i(geode.getDrawable(i)); - if (geometry) - { - if (!geometry->verifyArrays(_errorReports)) ++local_numInvalidGeometries; - } - } - if (local_numInvalidGeometries) - { - _errorReports<<"Geode "<accept(cvv); - if (!cvv.valid()) - { - OSG_NOTICE<<"Warning, errors in geometry found in file "< ss = new osg::StateSet; diff --git a/examples/osggeometry/osggeometry.cpp b/examples/osggeometry/osggeometry.cpp index 40f418407..80bcc0ab0 100644 --- a/examples/osggeometry/osggeometry.cpp +++ b/examples/osggeometry/osggeometry.cpp @@ -17,7 +17,7 @@ */ #include -#include +#include #include #include #include @@ -93,7 +93,7 @@ osg::Node* createScene() // create POINTS { // create Geometry object to store all the vertices and points primitive. - osg::GeometryNew* pointsGeom = new osg::GeometryNew(); + osg::Geometry* pointsGeom = new osg::Geometry(); // create a Vec3Array and add to it all my coordinates. // Like all the *Array variants (see include/osg/Array) , Vec3Array is derived from both osg::Array @@ -122,14 +122,14 @@ osg::Node* createScene() // pass the color array to points geometry, note the binding to tell the geometry // that only use one color for the whole object. pointsGeom->setColorArray(colors); - pointsGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + pointsGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); pointsGeom->setNormalArray(normals); - pointsGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + pointsGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // create and add a DrawArray Primitive (see include/osg/Primitive). The first @@ -147,7 +147,7 @@ osg::Node* createScene() // create LINES { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* linesGeom = new osg::GeometryNew(); + osg::Geometry* linesGeom = new osg::Geometry(); // this time we'll preallocate the vertex array to the size we // need and then simple set them as array elements, 8 points @@ -170,14 +170,14 @@ osg::Node* createScene() osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); linesGeom->setColorArray(colors); - linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); linesGeom->setNormalArray(normals); - linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -192,7 +192,7 @@ osg::Node* createScene() // create LINE_STRIP { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* linesGeom = new osg::GeometryNew(); + osg::Geometry* linesGeom = new osg::Geometry(); // this time we'll preallocate the vertex array to the size // and then use an iterator to fill in the values, a bit perverse @@ -212,14 +212,14 @@ osg::Node* createScene() osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); linesGeom->setColorArray(colors); - linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); linesGeom->setNormalArray(normals); - linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -234,7 +234,7 @@ osg::Node* createScene() // create LINE_LOOP { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* linesGeom = new osg::GeometryNew(); + osg::Geometry* linesGeom = new osg::Geometry(); // this time we'll a C arrays to initialize the vertices. @@ -259,14 +259,14 @@ osg::Node* createScene() osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,0.0f,1.0f)); linesGeom->setColorArray(colors); - linesGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); linesGeom->setNormalArray(normals); - linesGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -307,7 +307,7 @@ osg::Node* createScene() // create POLYGON { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* polyGeom = new osg::GeometryNew(); + osg::Geometry* polyGeom = new osg::Geometry(); // this time we'll use C arrays to initialize the vertices. // note, anticlockwise ordering. @@ -333,12 +333,12 @@ osg::Node* createScene() // use the shared color array. polyGeom->setColorArray(shared_colors.get()); - polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // use the shared normal array. polyGeom->setNormalArray(shared_normals.get()); - polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -355,7 +355,7 @@ osg::Node* createScene() // create QUADS { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* polyGeom = new osg::GeometryNew(); + osg::Geometry* polyGeom = new osg::Geometry(); // note, anticlockwise ordering. osg::Vec3 myCoords[] = @@ -380,12 +380,12 @@ osg::Node* createScene() // use the shared color array. polyGeom->setColorArray(shared_colors.get()); - polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // use the shared normal array. polyGeom->setNormalArray(shared_normals.get()); - polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -402,7 +402,7 @@ osg::Node* createScene() // create QUAD_STRIP { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* polyGeom = new osg::GeometryNew(); + osg::Geometry* polyGeom = new osg::Geometry(); // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. osg::Vec3 myCoords[] = @@ -429,12 +429,12 @@ osg::Node* createScene() // use the shared color array. polyGeom->setColorArray(shared_colors.get()); - polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // use the shared normal array. polyGeom->setNormalArray(shared_normals.get()); - polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -451,7 +451,7 @@ osg::Node* createScene() // create TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN all in one Geometry/ { // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* polyGeom = new osg::GeometryNew(); + osg::Geometry* polyGeom = new osg::Geometry(); // note, first coord at top, second at bottom, reverse to that buggy OpenGL image.. osg::Vec3 myCoords[] = @@ -497,12 +497,12 @@ osg::Node* createScene() // use the shared color array. polyGeom->setColorArray(shared_colors.get()); - polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // use the shared normal array. polyGeom->setNormalArray(shared_normals.get()); - polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); // This time we simply use primitive, and hardwire the number of coords to use @@ -571,7 +571,7 @@ osg::Node* createBackground() // create Geometry object to store all the vertices and lines primitive. - osg::GeometryNew* polyGeom = new osg::GeometryNew(); + osg::Geometry* polyGeom = new osg::Geometry(); // note, anticlockwise ordering. osg::Vec3 myCoords[] = @@ -590,14 +590,14 @@ osg::Node* createBackground() osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); polyGeom->setColorArray(colors); - polyGeom->setColorBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL); // set the normal in the same way color. osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); polyGeom->setNormalArray(normals); - polyGeom->setNormalBinding(osg::GeometryNew::BIND_OVERALL); + polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec2 myTexCoords[] = { diff --git a/examples/osgimpostor/osgimpostor.cpp b/examples/osgimpostor/osgimpostor.cpp index ddc57eaff..35d2dce4e 100644 --- a/examples/osgimpostor/osgimpostor.cpp +++ b/examples/osgimpostor/osgimpostor.cpp @@ -43,7 +43,7 @@ typedef NodeContainer::iterator NodeIterator; NodeContainer nodes; // -osg::Group * Root = 0; +osg::ref_ptr Root = 0; const int HOUSES_SIZE = 25000; // total number of houses double XDim = 5000.0f; // area dimension +/- XDim @@ -81,11 +81,11 @@ void CreateHouses() }; // use the same color, normal and indices for all houses. - osg::Vec4Array* colors = new osg::Vec4Array(1); + osg::ref_ptr colors = new osg::Vec4Array(1); (*colors)[0] = osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f); // normals - osg::Vec3Array * normals = new osg::Vec3Array(16); + osg::ref_ptr normals = new osg::Vec3Array(16); (*normals)[0] = osg::Vec3( 0.0f, -0.0f, -1.0f); (*normals)[1] = osg::Vec3( 0.0f, -0.0f, -1.0f); (*normals)[2] = osg::Vec3( 0.0f, -1.0f, 0.0f); @@ -104,10 +104,10 @@ void CreateHouses() (*normals)[15] = osg::Vec3(-0.707107f, 0.0f, 0.707107f); // coordIndices - osg::UByteArray* coordIndices = new osg::UByteArray(48,indices); + osg::ref_ptr coordIndices = new osg::UByteArray(48,indices); - // share the primitive set. - osg::PrimitiveSet* primitives = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,48); + // share the primitive set. + osg::PrimitiveSet* primitives = new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES,0,48); for (int q = 0; q < HOUSES_SIZE; q++) { @@ -121,10 +121,10 @@ void CreateHouses() float scale = 10.0f; - osg::Vec3 offset(xPos,yPos,0.0f); + osg::Vec3 offset(xPos,yPos,0.0f); // coords - osg::Vec3Array* coords = new osg::Vec3Array(10); + osg::ref_ptr coords = new osg::Vec3Array(10); (*coords)[0] = osg::Vec3( 0.5f, -0.7f, 0.0f); (*coords)[1] = osg::Vec3( 0.5f, 0.7f, 0.0f); (*coords)[2] = osg::Vec3(-0.5f, 0.7f, 0.0f); @@ -143,23 +143,23 @@ void CreateHouses() // create geometry - osg::Geometry * geometry = new osg::Geometry(); + osg::ref_ptr geometry = new osg::Geometry(); geometry->addPrimitiveSet(primitives); - geometry->setVertexArray(coords); - geometry->setVertexIndices(coordIndices); + geometry->setVertexArray(coords.get()); + geometry->setVertexIndices(coordIndices.get()); - geometry->setColorArray(colors); + geometry->setColorArray(colors.get()); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); - geometry->setNormalArray(normals); + geometry->setNormalArray(normals.get()); geometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); - osg::Geode * geode = new osg::Geode(); - geode->addDrawable(geometry); + osg::ref_ptr geode = new osg::Geode(); + geode->addDrawable(geometry.get()); - nodes.push_back(geode); + nodes.push_back(geode.get()); } } diff --git a/examples/osgsharedarray/osgsharedarray.cpp b/examples/osgsharedarray/osgsharedarray.cpp index 219a3002f..fc5b4558b 100644 --- a/examples/osgsharedarray/osgsharedarray.cpp +++ b/examples/osgsharedarray/osgsharedarray.cpp @@ -106,6 +106,8 @@ public: return 0; } + virtual unsigned int getElementSize() const { return sizeof(osg::Vec3); } + /** Returns a pointer to the first element of the array. */ virtual const GLvoid* getDataPointer() const { return _ptr; @@ -123,6 +125,9 @@ public: return _numElements * sizeof(osg::Vec3); } + virtual void reserveArray(unsigned int num) { OSG_NOTICE<<"reserveArray() not supported"<setUseVertexBufferObjects(false); geom->setUseDisplayList(false); - geom->setFastPathHint(false); geode->addDrawable( geom.get() ); diff --git a/include/osg/Array b/include/osg/Array index dbb43676d..702028c4d 100644 --- a/include/osg/Array +++ b/include/osg/Array @@ -82,6 +82,9 @@ class OSG_EXPORT Array : public BufferData BIND_OFF=0, BIND_OVERALL=1, BIND_PER_PRIMITIVE_SET=2, +#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS) + BIND_PER_PRIMITIVE=3, +#endif BIND_PER_VERTEX=4, BIND_INSTANCE_DIVISOR_0=6, BIND_INSTANCE_DIVISOR_1=BIND_INSTANCE_DIVISOR_0+1, @@ -93,7 +96,7 @@ class OSG_EXPORT Array : public BufferData BIND_INSTANCE_DIVISOR_7=BIND_INSTANCE_DIVISOR_0+7 }; - Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0): + Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0, Binding=BIND_UNDEFINED): _arrayType(arrayType), _dataSize(dataSize), _dataType(dataType), @@ -101,7 +104,7 @@ class OSG_EXPORT Array : public BufferData _normalize(false), _preserveDataType(false) {} - Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): + Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): BufferData(array,copyop), _arrayType(array._arrayType), _dataSize(array._dataSize), @@ -131,9 +134,12 @@ class OSG_EXPORT Array : public BufferData virtual osg::Array* asArray() { return this; } virtual const osg::Array* asArray() const { return this; } + virtual unsigned int getElementSize() const = 0; virtual const GLvoid* getDataPointer() const = 0; virtual unsigned int getTotalDataSize() const = 0; virtual unsigned int getNumElements() const = 0; + virtual void reserveArray(unsigned int num) = 0; + virtual void resizeArray(unsigned int num) = 0; /** Specify how this array should be passed to OpenGL.*/ @@ -186,7 +192,7 @@ class TemplateArray : public Array, public MixinVector { public: - TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {} + TemplateArray(Binding binding=BIND_UNDEFINED) : Array(ARRAYTYPE,DataSize,DataType, binding) {} TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Array(ta,copyop), @@ -200,6 +206,14 @@ class TemplateArray : public Array, public MixinVector Array(ARRAYTYPE,DataSize,DataType), MixinVector(ptr,ptr+no) {} + TemplateArray(Binding binding, unsigned int no) : + Array(ARRAYTYPE,DataSize,DataType, binding), + MixinVector(no) {} + + TemplateArray(Binding binding, unsigned int no,const T* ptr) : + Array(ARRAYTYPE,DataSize,DataType, binding), + MixinVector(ptr,ptr+no) {} + template TemplateArray(InputIterator first,InputIterator last) : Array(ARRAYTYPE,DataSize,DataType), @@ -236,9 +250,12 @@ class TemplateArray : public Array, public MixinVector MixinVector( *this ).swap( *this ); } + virtual unsigned int getElementSize() const { return sizeof(ElementDataType); } virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } - virtual unsigned int getTotalDataSize() const { return static_cast(this->size()*sizeof(T)); } + virtual unsigned int getTotalDataSize() const { return static_cast(this->size()*sizeof(ElementDataType)); } virtual unsigned int getNumElements() const { return static_cast(this->size()); } + virtual void reserveArray(unsigned int num) { this->reserve(num); } + virtual void resizeArray(unsigned int num) { this->resize(num); } typedef T ElementDataType; // expose T @@ -322,9 +339,12 @@ class TemplateIndexArray : public IndexArray, public MixinVector MixinVector( *this ).swap( *this ); } + virtual unsigned int getElementSize() const { return sizeof(ElementDataType); } virtual const GLvoid* getDataPointer() const { if (!this->empty()) return &this->front(); else return 0; } virtual unsigned int getTotalDataSize() const { return static_cast(this->size()*sizeof(T)); } virtual unsigned int getNumElements() const { return static_cast(this->size()); } + virtual void reserveArray(unsigned int num) { this->reserve(num); } + virtual void resizeArray(unsigned int num) { this->resize(num); } virtual unsigned int index(unsigned int pos) const { return (*this)[pos]; } diff --git a/include/osg/ArrayDispatchers b/include/osg/ArrayDispatchers index 8120f5f07..604e9fe7b 100644 --- a/include/osg/ArrayDispatchers +++ b/include/osg/ArrayDispatchers @@ -17,7 +17,6 @@ #include #include #include -#include namespace osg { @@ -27,7 +26,7 @@ class AttributeDispatchMap; struct AttributeDispatch : public osg::Referenced { - virtual void assign(const GLvoid*, const IndexArray*) {} + virtual void assign(const GLvoid*) {} virtual void operator() (unsigned int) {}; }; @@ -51,30 +50,30 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced if (at) _activeDispatchList[binding].push_back(at); } - void activateVertexArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array, 0)); } - void activateColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array, 0)); } - void activateNormalArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array, 0)); } - void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array, 0)); } - void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array, 0)); } - void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array, 0)); } - void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()!=osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array, 0)); } + void activateVertexArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexDispatcher(array)); } + void activateColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), colorDispatcher(array)); } + void activateNormalArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), normalDispatcher(array)); } + void activateSecondaryColorArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), secondaryColorDispatcher(array)); } + void activateFogCoordArray(osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), fogCoordDispatcher(array)); } + void activateTexCoordArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), texCoordDispatcher(unit, array)); } + void activateVertexAttribArray(unsigned int unit, osg::Array* array) { if (array && array->getBinding()>osg::Array::BIND_OFF) activate(array->getBinding(), vertexAttribDispatcher(unit, array)); } - AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices); - AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices); - AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices); - AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices); - AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices); - AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices); - AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices); + AttributeDispatch* vertexDispatcher(Array* array); + AttributeDispatch* normalDispatcher(Array* array); + AttributeDispatch* colorDispatcher(Array* array); + AttributeDispatch* secondaryColorDispatcher(Array* array); + AttributeDispatch* fogCoordDispatcher(Array* array); + AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array); + AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array); - void activateVertexArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexDispatcher(array, indices)); } - void activateColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, colorDispatcher(array, indices)); } - void activateNormalArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, normalDispatcher(array, indices)); } - void activateSecondaryColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, secondaryColorDispatcher(array, indices)); } - void activateFogCoordArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, fogCoordDispatcher(array, indices)); } - void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, texCoordDispatcher(unit, array, indices)); } - void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexAttribDispatcher(unit, array, indices)); } + void activateVertexArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, vertexDispatcher(array)); } + void activateColorArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, colorDispatcher(array)); } + void activateNormalArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, normalDispatcher(array)); } + void activateSecondaryColorArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, secondaryColorDispatcher(array)); } + void activateFogCoordArray(unsigned int binding, osg::Array* array) { if (binding && array) activate(binding, fogCoordDispatcher(array)); } + void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array) { if (binding && array) activate(binding, texCoordDispatcher(unit, array)); } + void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array) { if (binding && array) activate(binding, vertexAttribDispatcher(unit, array)); } void dispatch(unsigned int binding, unsigned int index) { @@ -89,30 +88,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); } - void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; } - bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; } - - - void Begin(GLenum mode) - { -#ifdef OSG_GL1_AVAILABLE - if (_useGLBeginEndAdapter) _glBeginEndAdapter->Begin(mode); - else ::glBegin(mode); -#else - _glBeginEndAdapter->Begin(mode); -#endif - } - - void End() - { -#ifdef OSG_GL1_AVAILABLE - if (_useGLBeginEndAdapter) _glBeginEndAdapter->End(); - else ::glEnd(); -#else - _glBeginEndAdapter->End(); -#endif - } - protected: void init(); @@ -122,7 +97,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced bool _initialized; State* _state; - GLBeginEndAdapter* _glBeginEndAdapter; AttributeDispatchMap* _vertexDispatchers; AttributeDispatchMap* _normalDispatchers; @@ -140,7 +114,6 @@ class OSG_EXPORT ArrayDispatchers : public osg::Referenced ActiveDispatchList _activeDispatchList; bool _useVertexAttribAlias; - bool _useGLBeginEndAdapter; }; } diff --git a/include/osg/Geometry b/include/osg/Geometry index 43ce48de7..662b3f9ae 100644 --- a/include/osg/Geometry +++ b/include/osg/Geometry @@ -11,8 +11,8 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSG_GEOMETRY -#define OSG_GEOMETRY 1 +#ifndef OSG_GEOMETRYNEW +#define OSG_GEOMETRYNEW 1 #include #include @@ -23,7 +23,6 @@ namespace osg { - class OSG_EXPORT Geometry : public Drawable { public: @@ -44,164 +43,42 @@ class OSG_EXPORT Geometry : public Drawable bool empty() const; - enum AttributeBinding - { - BIND_OFF=0, - BIND_OVERALL, - BIND_PER_PRIMITIVE_SET, - BIND_PER_PRIMITIVE, - BIND_PER_VERTEX - }; - - struct OSG_EXPORT ArrayData - { - ArrayData(): - binding(BIND_OFF), - normalize(GL_FALSE) {} - - ArrayData(const ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY); - - ArrayData(Array* a, AttributeBinding b, GLboolean n = GL_FALSE): - array(a), - indices(0), - binding(b), - normalize(n) {} - - ArrayData(Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE): - array(a), - indices(i), - binding(b), - normalize(n) {} - - ArrayData& operator = (const ArrayData& rhs) - { - array = rhs.array; - indices = rhs.indices; - binding = rhs.binding; - normalize = rhs.normalize; - return *this; - } - - inline bool empty() const { return !array.valid(); } - - ref_ptr array; - ref_ptr indices; // deprecated. - AttributeBinding binding; - GLboolean normalize; - }; - - struct OSG_EXPORT Vec3ArrayData - { - Vec3ArrayData(): - binding(BIND_OFF), - normalize(GL_FALSE) {} - - Vec3ArrayData(const Vec3ArrayData& data,const CopyOp& copyop=CopyOp::SHALLOW_COPY); - - Vec3ArrayData(Vec3Array* a, AttributeBinding b, GLboolean n = GL_FALSE): - array(a), - indices(0), - binding(b), - normalize(n) {} - - Vec3ArrayData(Vec3Array* a, IndexArray* i, AttributeBinding b, GLboolean n = GL_FALSE): - array(a), - indices(i), - binding(b), - normalize(n) {} - - Vec3ArrayData& operator = (const Vec3ArrayData& rhs) - { - array = rhs.array; - indices = rhs.indices; - binding = rhs.binding; - normalize = rhs.normalize; - return *this; - } - - inline bool empty() const { return !array.valid(); } - - ref_ptr array; - ref_ptr indices; // deprecated. - AttributeBinding binding; - GLboolean normalize; - }; - - /** Static ArrayData which is returned from getTexCoordData(i) const and getVertexAttribData(i) const - * when i is out of range. - */ - static const ArrayData s_InvalidArrayData; - - typedef std::vector< ArrayData > ArrayDataList; - + typedef std::vector< osg::ref_ptr > ArrayList; void setVertexArray(Array* array); - Array* getVertexArray() { return _vertexData.array.get(); } - const Array* getVertexArray() const { return _vertexData.array.get(); } + Array* getVertexArray() { return _vertexArray.get(); } + const Array* getVertexArray() const { return _vertexArray.get(); } - void setVertexData(const ArrayData& arrayData); - ArrayData& getVertexData() { return _vertexData; } - const ArrayData& getVertexData() const { return _vertexData; } - - - void setNormalBinding(AttributeBinding ab); - AttributeBinding getNormalBinding() const { return _normalData.binding; } void setNormalArray(Array* array); - Array* getNormalArray() { return _normalData.array.get(); } - const Array* getNormalArray() const { return _normalData.array.get(); } + Array* getNormalArray() { return _normalArray.get(); } + const Array* getNormalArray() const { return _normalArray.get(); } - void setNormalData(const ArrayData& arrayData); - ArrayData& getNormalData() { return _normalData; } - const ArrayData& getNormalData() const { return _normalData; } - - void setColorBinding(AttributeBinding ab); - AttributeBinding getColorBinding() const { return _colorData.binding; } + void setColorArray(Array* array); - Array* getColorArray() { return _colorData.array.get(); } - const Array* getColorArray() const { return _colorData.array.get(); } - - void setColorData(const ArrayData& arrayData); - ArrayData& getColorData() { return _colorData; } - const ArrayData& getColorData() const { return _colorData; } + Array* getColorArray() { return _colorArray.get(); } + const Array* getColorArray() const { return _colorArray.get(); } - void setSecondaryColorBinding(AttributeBinding ab); - AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; } void setSecondaryColorArray(Array* array); - Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); } - const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); } + Array* getSecondaryColorArray() { return _secondaryColorArray.get(); } + const Array* getSecondaryColorArray() const { return _secondaryColorArray.get(); } - void setSecondaryColorData(const ArrayData& arrayData); - ArrayData& getSecondaryColorData() { return _secondaryColorData; } - const ArrayData& getSecondaryColorData() const { return _secondaryColorData; } - - - void setFogCoordBinding(AttributeBinding ab); - AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; } void setFogCoordArray(Array* array); - Array* getFogCoordArray() { return _fogCoordData.array.get(); } - const Array* getFogCoordArray() const { return _fogCoordData.array.get(); } - - void setFogCoordData(const ArrayData& arrayData); - ArrayData& getFogCoordData() { return _fogCoordData; } - const ArrayData& getFogCoordData() const { return _fogCoordData; } + Array* getFogCoordArray() { return _fogCoordArray.get(); } + const Array* getFogCoordArray() const { return _fogCoordArray.get(); } void setTexCoordArray(unsigned int unit,Array*); Array* getTexCoordArray(unsigned int unit); const Array* getTexCoordArray(unsigned int unit) const; - void setTexCoordData(unsigned int index,const ArrayData& arrayData); - ArrayData& getTexCoordData(unsigned int index); - const ArrayData& getTexCoordData(unsigned int index) const; - unsigned int getNumTexCoordArrays() const { return static_cast(_texCoordList.size()); } - ArrayDataList& getTexCoordArrayList() { return _texCoordList; } - const ArrayDataList& getTexCoordArrayList() const { return _texCoordList; } + ArrayList& getTexCoordArrayList() { return _texCoordList; } + const ArrayList& getTexCoordArrayList() const { return _texCoordList; } @@ -209,19 +86,10 @@ class OSG_EXPORT Geometry : public Drawable Array *getVertexAttribArray(unsigned int index); const Array *getVertexAttribArray(unsigned int index) const; - void setVertexAttribBinding(unsigned int index,AttributeBinding ab); - AttributeBinding getVertexAttribBinding(unsigned int index) const; - - void setVertexAttribNormalize(unsigned int index,GLboolean norm); - GLboolean getVertexAttribNormalize(unsigned int index) const; - - void setVertexAttribData(unsigned int index,const ArrayData& arrayData); - ArrayData& getVertexAttribData(unsigned int index); - const ArrayData& getVertexAttribData(unsigned int index) const; unsigned int getNumVertexAttribArrays() const { return static_cast(_vertexAttribList.size()); } - ArrayDataList& getVertexAttribArrayList() { return _vertexAttribList; } - const ArrayDataList& getVertexAttribArrayList() const { return _vertexAttribList; } + ArrayList& getVertexAttribArrayList() { return _vertexAttribList; } + const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; } @@ -255,43 +123,11 @@ class OSG_EXPORT Geometry : public Drawable unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const; + /** return true if any arrays are shared.*/ + bool containsSharedArrays() const; - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setVertexIndices(IndexArray* array); - IndexArray* getVertexIndices() { return _vertexData.indices.get(); } - const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); } - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setNormalIndices(IndexArray* array); - IndexArray* getNormalIndices() { return _normalData.indices.get(); } - const IndexArray* getNormalIndices() const { return _normalData.indices.get(); } - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setColorIndices(IndexArray* array); - IndexArray* getColorIndices() { return _colorData.indices.get(); } - const IndexArray* getColorIndices() const { return _colorData.indices.get(); } - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setSecondaryColorIndices(IndexArray* array); - IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); } - const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); } - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setFogCoordIndices(IndexArray* array); - IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); } - const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); } - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setTexCoordIndices(unsigned int unit,IndexArray*); - IndexArray* getTexCoordIndices(unsigned int unit); - const IndexArray* getTexCoordIndices(unsigned int unit) const; - - /** deprecated - forces OpenGL slow path, just kept for backwards compatibility.*/ - void setVertexAttribIndices(unsigned int index,IndexArray* array); - IndexArray* getVertexAttribIndices(unsigned int index); - const IndexArray* getVertexAttribIndices(unsigned int index) const; - - + /** duplicate any shared arrays.*/ + void duplicateSharedArrays(); /** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation @@ -310,69 +146,15 @@ class OSG_EXPORT Geometry : public Drawable * for all graphics contexts. */ virtual void releaseGLObjects(State* state=0) const; - typedef std::vector ArrayList; bool getArrayList(ArrayList& arrayList) const; typedef std::vector DrawElementsList; bool getDrawElementsList(DrawElementsList& drawElementsList) const; osg::VertexBufferObject* getOrCreateVertexBufferObject(); - osg::ElementBufferObject* getOrCreateElementBufferObject(); - /** Set whether fast paths should be used when supported. */ - void setFastPathHint(bool on) { _fastPathHint = on; } - - /** Get whether fast paths should be used when supported. */ - bool getFastPathHint() const { return _fastPathHint; } - - - /** Return true if OpenGL fast paths will be used with drawing this Geometry. - * Fast paths directly use vertex arrays, and glDrawArrays/glDrawElements so have low CPU overhead. - * With Slow paths the osg::Geometry::drawImplementation has to dynamically assemble OpenGL - * compatible vertex arrays from the osg::Geometry arrays data and then dispatch these to OpenGL, - * so have higher CPU overhead than the Fast paths. - * Use of per primitive bindings or per vertex indexed arrays will drop the rendering path off the fast path. - */ - inline bool areFastPathsUsed() const - { - if (_internalOptimizedGeometry.valid()) - return _internalOptimizedGeometry->areFastPathsUsed(); - else - return _fastPath && _fastPathHint; - } - - bool computeFastPathsUsed(); - - bool verifyBindings() const; - - void computeCorrectBindingsAndArraySizes(); - - /** check whether the arrays, indices, bindings and primitives all match correctly, return false is .*/ - bool verifyArrays(std::ostream& out) const; - - bool suitableForOptimization() const; - - void copyToAndOptimize(Geometry& target); - - - bool containsSharedArrays() const; - - void duplicateSharedArrays(); - - - void computeInternalOptimizedGeometry(); - - void removeInternalOptimizedGeometry() { _internalOptimizedGeometry = 0; } - - void setInternalOptimizedGeometry(osg::Geometry* geometry) { _internalOptimizedGeometry = geometry; } - - osg::Geometry* getInternalOptimizedGeometry() { return _internalOptimizedGeometry.get(); } - - const osg::Geometry* getInternalOptimizedGeometry() const { return _internalOptimizedGeometry.get(); } - - /** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable. * This size is used a hint for reuse of deleted display lists/vertex buffer objects. */ virtual unsigned int getGLObjectSizeHint() const; @@ -419,29 +201,97 @@ class OSG_EXPORT Geometry : public Drawable virtual ~Geometry(); - bool verifyBindings(const ArrayData& arrayData) const; - bool verifyBindings(const Vec3ArrayData& arrayData) const; - - void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName); - void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName); void addVertexBufferObjectIfRequired(osg::Array* array); void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet); PrimitiveSetList _primitives; - ArrayData _vertexData; - ArrayData _normalData; - ArrayData _colorData; - ArrayData _secondaryColorData; - ArrayData _fogCoordData; - ArrayDataList _texCoordList; - ArrayDataList _vertexAttribList; + osg::ref_ptr _vertexArray; + osg::ref_ptr _normalArray; + osg::ref_ptr _colorArray; + osg::ref_ptr _secondaryColorArray; + osg::ref_ptr _fogCoordArray; + ArrayList _texCoordList; + ArrayList _vertexAttribList; + + bool _containsDeprecatedData; + + public: + + + /** Return true if the deprecated use array indicies or BIND_PER_PRIMITIVE binding has been assigned to arrays.*/ + bool containsDeprecatedData() const { return _containsDeprecatedData; } - mutable bool _fastPath; - bool _fastPathHint; + /** fallback for deprecated functionality. Return true if the Geometry contains any array indices or BIND_PER_PRIMITIVE arrays. */ + bool checkForDeprecatedData(); - ref_ptr _internalOptimizedGeometry; + /** fallback for deprecated functionality. Removes any array indices and BIND_PER_PRIMITIVE arrays.*/ + void fixDeprecatedData(); + + /** Same values as Array::Binding.*/ + enum AttributeBinding + { + BIND_OFF=0, + BIND_OVERALL=1, + BIND_PER_PRIMITIVE_SET=2, + BIND_PER_PRIMITIVE=3, /// no longer supported + BIND_PER_VERTEX=4 + }; + + /** deprecated, use array->setBinding(..). */ + void setNormalBinding(AttributeBinding ab); + AttributeBinding getNormalBinding() const; + + /** deprecated, use array->setBinding(..). */ + void setColorBinding(AttributeBinding ab); + AttributeBinding getColorBinding() const; + + /** deprecated, use array->setBinding(..). */ + void setSecondaryColorBinding(AttributeBinding ab); + AttributeBinding getSecondaryColorBinding() const; + + /** deprecated, use array->setBinding(..). */ + void setFogCoordBinding(AttributeBinding ab); + AttributeBinding getFogCoordBinding() const; + + /** deprecated, use array->setBinding(..). */ + void setVertexAttribBinding(unsigned int index,AttributeBinding ab); + AttributeBinding getVertexAttribBinding(unsigned int index) const; + + /** deprecated, use array->setNormalize(..). */ + void setVertexAttribNormalize(unsigned int index,GLboolean norm); + GLboolean getVertexAttribNormalize(unsigned int index) const; + +#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS) + /** no longer supported.*/ + inline void setVertexIndices(IndexArray* array); + inline const IndexArray* getVertexIndices() const; + + /** no longer supported.*/ + inline void setNormalIndices(IndexArray* array); + inline const IndexArray* getNormalIndices() const; + + /** no longer supported.*/ + inline void setColorIndices(IndexArray* array); + inline const IndexArray* getColorIndices() const; + + /** no longer supported.*/ + inline void setSecondaryColorIndices(IndexArray* array); + inline const IndexArray* getSecondaryColorIndices() const; + + /** no longer supported.*/ + inline void setFogCoordIndices(IndexArray* array); + inline const IndexArray* getFogCoordIndices() const; + + /** no longer supported.*/ + inline void setTexCoordIndices(unsigned int unit,IndexArray*); + inline const IndexArray* getTexCoordIndices(unsigned int unit) const; + + /** no longer supported.*/ + inline void setVertexAttribIndices(unsigned int index,IndexArray* array); + inline const IndexArray* getVertexAttribIndices(unsigned int index) const; +#endif }; /** Convenience function to be used for creating quad geometry with texture coords. @@ -458,6 +308,89 @@ inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& width } +#if defined(OSG_USE_DEPRECATED_GEOMETRY_METHODS) + +#include + +inline void Geometry::setVertexIndices(IndexArray* array) +{ + if (_vertexArray.valid()) { _vertexArray->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setVertexIndicies(..) function failed as there is no vertex array to associate inidices with."<(_vertexArray->getUserData()); + else return 0; +} + +inline void Geometry::setNormalIndices(IndexArray* array) +{ + if (_normalArray.valid()) { _normalArray->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setNormalIndicies(..) function failed as there is no normal array to associate inidices with."<(_normalArray->getUserData()); + else return 0; +} + +inline void Geometry::setColorIndices(IndexArray* array) +{ + if (_colorArray.valid()) { _colorArray->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setColorIndicies(..) function failed as there is no color array to associate inidices with."<(_colorArray->getUserData()); + else return 0; +} + +inline void Geometry::setSecondaryColorIndices(IndexArray* array) +{ + if (_secondaryColorArray.valid()) { _secondaryColorArray->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setSecondaryColorArray(..) function failed as there is no secondary color array to associate inidices with."<(_secondaryColorArray->getUserData()); + else return 0; +} + +inline void Geometry::setFogCoordIndices(IndexArray* array) +{ + if (_fogCoordArray.valid()) { _fogCoordArray->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setFogCoordIndicies(..) function failed as there is no fog coord array to associate inidices with."<(_fogCoordArray->getUserData()); + else return 0; +} + +inline void Geometry::setTexCoordIndices(unsigned int unit,IndexArray* array) +{ + if (unit<_texCoordList.size() && _texCoordList[unit].valid()) { _texCoordList[unit]->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setTexCoordIndices(..) function failed as there is no texcoord array to associate inidices with."<(_texCoordList[unit]->getUserData()); + else return 0; +} + +inline void Geometry::setVertexAttribIndices(unsigned int index,IndexArray* array) +{ + if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) { _vertexAttribList[index]->setUserData(array); if (array) _containsDeprecatedData = true; } + else { OSG_WARN<<"Geometry::setVertexAttribIndices(..) function failed as there is no vertex attrib array to associate inidices with."<(_vertexAttribList[index]->getUserData()); + else return 0; +} +#endif + } #endif diff --git a/src/osg/ArrayDispatchers.cpp b/src/osg/ArrayDispatchers.cpp index ef6ddac81..11e6020f4 100644 --- a/src/osg/ArrayDispatchers.cpp +++ b/src/osg/ArrayDispatchers.cpp @@ -44,7 +44,7 @@ class TemplateAttributeDispatch : public AttributeDispatch TemplateAttributeDispatch(F functionPtr, unsigned int stride): _functionPtr(functionPtr), _stride(stride), _array(0) {} - virtual void assign(const GLvoid* array, const IndexArray*) + virtual void assign(const GLvoid* array) { _array = reinterpret_cast(array); } @@ -59,89 +59,6 @@ class TemplateAttributeDispatch : public AttributeDispatch const T* _array; }; -template -class TemplateAttributeWithIndicesDispatch : public AttributeDispatch -{ - public: - - typedef void (GL_APIENTRY * F) (const T*); - - TemplateAttributeWithIndicesDispatch(F functionPtr, unsigned int stride): - _functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {} - - virtual void assign(const GLvoid* array, const IndexArray* indices) - { - _array = reinterpret_cast(array); - _indices = indices; - } - - virtual void operator () (unsigned int pos) - { - _functionPtr(&(_array[_indices->index(pos) * _stride])); - } - - F _functionPtr; - unsigned int _stride; - const T* _array; - const IndexArray* _indices; -}; - -template -class TemplateBeginEndAttributeDispatch : public AttributeDispatch -{ - public: - - typedef void (GLBeginEndAdapter::*F) (const T*); - - TemplateBeginEndAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride): - _glBeginEndAdapter(glBeginEndAdapter), - _functionPtr(functionPtr), _stride(stride), _array(0) {} - - virtual void assign(const GLvoid* array, const IndexArray*) - { - _array = reinterpret_cast(array); - } - - virtual void operator () (unsigned int pos) - { - (_glBeginEndAdapter->*_functionPtr)(&(_array[pos*_stride])); - } - - GLBeginEndAdapter* _glBeginEndAdapter; - F _functionPtr; - unsigned int _stride; - const T* _array; -}; - -template -class TemplateBeginEndAttributeWithIndicesDispatch : public AttributeDispatch -{ - public: - - typedef void (GLBeginEndAdapter::*F) (const T*); - - TemplateBeginEndAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, F functionPtr, unsigned int stride): - _glBeginEndAdapter(glBeginEndAdapter), - _functionPtr(functionPtr), _stride(stride), _array(0), _indices(0) {} - - virtual void assign(const GLvoid* array, const IndexArray* indices) - { - _array = reinterpret_cast(array); - _indices = indices; - } - - virtual void operator () (unsigned int pos) - { - (_glBeginEndAdapter->*_functionPtr)(&(_array[_indices->index(pos) * _stride])); - } - - GLBeginEndAdapter* _glBeginEndAdapter; - F _functionPtr; - unsigned int _stride; - const T* _array; - const IndexArray* _indices; -}; - template class TemplateTargetAttributeDispatch : public AttributeDispatch @@ -169,108 +86,18 @@ class TemplateTargetAttributeDispatch : public AttributeDispatch const T* _array; }; -template -class TemplateTargetAttributeWithIndicesDispatch : public AttributeDispatch -{ - public: - - typedef void (GL_APIENTRY * F) (I, const T*); - - TemplateTargetAttributeWithIndicesDispatch(I target, F functionPtr, unsigned int stride): - _functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {} - - virtual void assign(const GLvoid* array, const IndexArray* indices) - { - _array = reinterpret_cast(array); - _indices = indices; - } - - virtual void operator () (unsigned int pos) - { - _functionPtr(_target, &(_array[_indices->index(pos) * _stride])); - } - - F _functionPtr; - I _target; - unsigned int _stride; - const T* _array; - const IndexArray* _indices; -}; - - -template -class TemplateBeginEndTargetAttributeDispatch : public AttributeDispatch -{ - public: - - typedef void (GLBeginEndAdapter::*F) (I, const T*); - - TemplateBeginEndTargetAttributeDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride): - _glBeginEndAdapter(glBeginEndAdapter), - _functionPtr(functionPtr), _target(target), _stride(stride), _array(0) {} - - virtual void assign(const GLvoid* array, const IndexArray*) - { - _array = reinterpret_cast(array); - } - - virtual void operator () (unsigned int pos) - { - (_glBeginEndAdapter->*_functionPtr)(_target, &(_array[pos * _stride])); - } - - GLBeginEndAdapter* _glBeginEndAdapter; - F _functionPtr; - I _target; - unsigned int _stride; - const T* _array; -}; - -template -class TemplateBeginEndTargetAttributeWithIndicesDispatch : public AttributeDispatch -{ - public: - - typedef void (GLBeginEndAdapter::*F) (I, const T*); - - TemplateBeginEndTargetAttributeWithIndicesDispatch(GLBeginEndAdapter* glBeginEndAdapter, I target, F functionPtr, unsigned int stride): - _glBeginEndAdapter(glBeginEndAdapter), - _functionPtr(functionPtr), _target(target), _stride(stride), _array(0), _indices(0) {} - - virtual void assign(const GLvoid* array, const IndexArray* indices) - { - _array = reinterpret_cast(array); - _indices = indices; - } - - virtual void operator () (unsigned int pos) - { - (_glBeginEndAdapter->*_functionPtr)(_target, &(_array[_indices->index(pos) * _stride])); - } - - GLBeginEndAdapter* _glBeginEndAdapter; - F _functionPtr; - I _target; - unsigned int _stride; - const T* _array; - const IndexArray* _indices; -}; class AttributeDispatchMap { public: - AttributeDispatchMap(GLBeginEndAdapter* glBeginEndAdapter): - _glBeginEndAdapter(glBeginEndAdapter) {} + AttributeDispatchMap() {} template void assign(Array::Type type, void (GL_APIENTRY *functionPtr) (const T*), unsigned int stride) { if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1); _attributeDispatchList[type] = functionPtr ? new TemplateAttributeDispatch(functionPtr, stride) : 0; - - if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1); - _attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateAttributeWithIndicesDispatch(functionPtr, stride) : 0; } template @@ -278,35 +105,11 @@ public: { if ((unsigned int)type >= _attributeDispatchList.size()) _attributeDispatchList.resize(type+1); _attributeDispatchList[type] = functionPtr ? new TemplateTargetAttributeDispatch(target, functionPtr, stride) : 0; - - if ((unsigned int)type >= _attributeDispatchWithIndicesList.size()) _attributeDispatchWithIndicesList.resize(type+1); - _attributeDispatchWithIndicesList[type] = functionPtr ? new TemplateTargetAttributeWithIndicesDispatch(target, functionPtr, stride) : 0; } - template - void assignGLBeginEnd(Array::Type type, void (GLBeginEndAdapter::*functionPtr) (const T*), unsigned int stride) + AttributeDispatch* dispatcher(const Array* array) { - if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1); - _glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndAttributeDispatch(_glBeginEndAdapter, functionPtr, stride) : 0; - - if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1); - _glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndAttributeWithIndicesDispatch(_glBeginEndAdapter, functionPtr, stride) : 0; - } - - template - void targetGLBeginEndAssign(I target, Array::Type type, void (GLBeginEndAdapter::*functionPtr) (I, const T*), unsigned int stride) - { - if ((unsigned int)type >= _glBeginEndAttributeDispatchList.size()) _glBeginEndAttributeDispatchList.resize(type+1); - _glBeginEndAttributeDispatchList[type] = functionPtr ? new TemplateBeginEndTargetAttributeDispatch(_glBeginEndAdapter, target, functionPtr, stride) : 0; - - if ((unsigned int)type >= _glBeginEndAttributeDispatchWithIndicesList.size()) _glBeginEndAttributeDispatchWithIndicesList.resize(type+1); - _glBeginEndAttributeDispatchWithIndicesList[type] = functionPtr ? new TemplateBeginEndTargetAttributeWithIndicesDispatch(_glBeginEndAdapter, target, functionPtr, stride) : 0; - } - - - AttributeDispatch* dispatcher(bool useGLBeginEndAdapter, const Array* array, const IndexArray* indices) - { - // OSG_NOTICE<<"dispatcher("<getType()="<getBinding() == static_cast(ab)) return; \ + array->setBinding(static_cast(ab));\ + if (ab==BIND_PER_PRIMITIVE) _containsDeprecatedData = true; + + +#define GET_BINDING(array) (array!=0 ? static_cast(array->getBinding()) : BIND_OFF) + + + + +void Geometry::setTexCoordArray(unsigned int index,Array* array) { - _fogCoordData.indices = array; - computeFastPathsUsed(); - dirtyDisplayList(); -} + if (_texCoordList.size()<=index) + _texCoordList.resize(index+1); -void Geometry::setFogCoordData(const ArrayData& arrayData) -{ - _fogCoordData = arrayData; - computeFastPathsUsed(); - dirtyDisplayList(); + _texCoordList[index] = array; - if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get()); -} + // do we set to array BIND_PER_VERTEX? -void Geometry::setNormalBinding(AttributeBinding ab) -{ - if (_normalData.binding == ab) return; - - _normalData.binding = ab; - computeFastPathsUsed(); - dirtyDisplayList(); -} - -void Geometry::setColorBinding(AttributeBinding ab) -{ - if (_colorData.binding == ab) return; - - _colorData.binding = ab; - computeFastPathsUsed(); - dirtyDisplayList(); -} - -void Geometry::setSecondaryColorBinding(AttributeBinding ab) -{ - if (_secondaryColorData.binding == ab) return; - - _secondaryColorData.binding = ab; - computeFastPathsUsed(); - dirtyDisplayList(); -} - -void Geometry::setFogCoordBinding(AttributeBinding ab) -{ - if (_fogCoordData.binding == ab) return; - - _fogCoordData.binding = ab; - computeFastPathsUsed(); - dirtyDisplayList(); -} - -void Geometry::setTexCoordData(unsigned int unit,const ArrayData& arrayData) -{ - if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1); - - _texCoordList[unit] = arrayData; - - if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get()); -} - -Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit) -{ - if (_texCoordList.size()<=unit) - _texCoordList.resize(unit+1); - - return _texCoordList[unit]; -} - -const Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit) const -{ - if (_texCoordList.size()<=unit) - return s_InvalidArrayData; - - return _texCoordList[unit]; -} - -void Geometry::setTexCoordArray(unsigned int unit,Array* array) -{ - getTexCoordData(unit).binding = BIND_PER_VERTEX; - getTexCoordData(unit).array = array; - - computeFastPathsUsed(); dirtyDisplayList(); if (_useVertexBufferObjects && array) @@ -325,73 +180,26 @@ void Geometry::setTexCoordArray(unsigned int unit,Array* array) } } -Array* Geometry::getTexCoordArray(unsigned int unit) +Array* Geometry::getTexCoordArray(unsigned int index) { - if (unit<_texCoordList.size()) return _texCoordList[unit].array.get(); + if (index<_texCoordList.size()) return _texCoordList[index].get(); else return 0; } -const Array* Geometry::getTexCoordArray(unsigned int unit) const +const Array* Geometry::getTexCoordArray(unsigned int index) const { - if (unit<_texCoordList.size()) return _texCoordList[unit].array.get(); + if (index<_texCoordList.size()) return _texCoordList[index].get(); else return 0; } -void Geometry::setTexCoordIndices(unsigned int unit,IndexArray* array) -{ - getTexCoordData(unit).indices = array; - - computeFastPathsUsed(); - dirtyDisplayList(); -} - -IndexArray* Geometry::getTexCoordIndices(unsigned int unit) -{ - if (unit<_texCoordList.size()) return _texCoordList[unit].indices.get(); - else return 0; -} - -const IndexArray* Geometry::getTexCoordIndices(unsigned int unit) const -{ - if (unit<_texCoordList.size()) return _texCoordList[unit].indices.get(); - else return 0; -} - - -void Geometry::setVertexAttribData(unsigned int index, const Geometry::ArrayData& attrData) -{ - if (_vertexAttribList.size()<=index) - _vertexAttribList.resize(index+1); - - _vertexAttribList[index] = attrData; - - computeFastPathsUsed(); - dirtyDisplayList(); - - if (_useVertexBufferObjects && attrData.array.valid()) addVertexBufferObjectIfRequired(attrData.array.get()); -} - -Geometry::ArrayData& Geometry::getVertexAttribData(unsigned int index) -{ - if (_vertexAttribList.size()<=index) - _vertexAttribList.resize(index+1); - - return _vertexAttribList[index]; -} - -const Geometry::ArrayData& Geometry::getVertexAttribData(unsigned int index) const -{ - if (_vertexAttribList.size()<=_vertexAttribList.size()) - return s_InvalidArrayData; - - return _vertexAttribList[index]; -} void Geometry::setVertexAttribArray(unsigned int index, Array* array) { - getVertexAttribData(index).array = array; + if (_vertexAttribList.size()<=index) + _vertexAttribList.resize(index+1); + + _vertexAttribList[index] = array; - computeFastPathsUsed(); dirtyDisplayList(); if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array); @@ -399,63 +207,16 @@ void Geometry::setVertexAttribArray(unsigned int index, Array* array) Array *Geometry::getVertexAttribArray(unsigned int index) { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].array.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].get(); else return 0; } const Array *Geometry::getVertexAttribArray(unsigned int index) const { - if (index<_vertexAttribList.size()) return _vertexAttribList[index].array.get(); + if (index<_vertexAttribList.size()) return _vertexAttribList[index].get(); else return 0; } -void Geometry::setVertexAttribIndices(unsigned int index,IndexArray* array) -{ - getVertexAttribData(index).indices = array; - - computeFastPathsUsed(); - dirtyDisplayList(); -} - -IndexArray* Geometry::getVertexAttribIndices(unsigned int index) -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].indices.get(); - else return 0; -} - -const IndexArray* Geometry::getVertexAttribIndices(unsigned int index) const -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].indices.get(); - else return 0; -} - -void Geometry::setVertexAttribBinding(unsigned int index,AttributeBinding ab) -{ - if (getVertexAttribData(index).binding == ab) - return; - getVertexAttribData(index).binding = ab; - computeFastPathsUsed(); - dirtyDisplayList(); -} - -Geometry::AttributeBinding Geometry::getVertexAttribBinding(unsigned int index) const -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].binding; - else return BIND_OFF; -} - -void Geometry::setVertexAttribNormalize(unsigned int index,GLboolean norm) -{ - getVertexAttribData(index).normalize = norm; - - dirtyDisplayList(); -} - -GLboolean Geometry::getVertexAttribNormalize(unsigned int index) const -{ - if (index<_vertexAttribList.size()) return _vertexAttribList[index].normalize; - else return GL_FALSE; -} bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset) { @@ -561,89 +322,24 @@ unsigned int Geometry::getPrimitiveSetIndex(const PrimitiveSet* primitiveset) co return _primitives.size(); // node not found. } -bool Geometry::computeFastPathsUsed() -{ - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // check to see if fast path can be used. - // - _fastPath = true; - if (_vertexData.indices.valid()) _fastPath = false; - else if (_normalData.binding==BIND_PER_PRIMITIVE || (_normalData.binding==BIND_PER_VERTEX && _normalData.indices.valid())) _fastPath = false; - else if (_colorData.binding==BIND_PER_PRIMITIVE || (_colorData.binding==BIND_PER_VERTEX && _colorData.indices.valid())) _fastPath = false; - else if (_secondaryColorData.binding==BIND_PER_PRIMITIVE || (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.indices.valid())) _fastPath = false; - else if (_fogCoordData.binding==BIND_PER_PRIMITIVE || (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.indices.valid())) _fastPath = false; - else - { - for( unsigned int va = 0; va < _vertexAttribList.size(); ++va ) - { - if (_vertexAttribList[va].binding==BIND_PER_PRIMITIVE) - { - _fastPath = false; - break; - } - else - { - const Array * array = _vertexAttribList[va].array.get(); - const IndexArray * idxArray = _vertexAttribList[va].indices.get(); - - if( _vertexAttribList[va].binding==BIND_PER_VERTEX && - array && array->getNumElements()>0 && - idxArray && idxArray->getNumElements()>0 ) - { - _fastPath = false; - break; - } - } - } - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // Set up tex coords if required. - // - for(unsigned int unit=0;unit<_texCoordList.size();++unit) - { - const ArrayData& texcoordData = _texCoordList[unit]; - if (texcoordData.array.valid() && texcoordData.array->getNumElements()>0) - { - if (texcoordData.indices.valid()) - { - if (texcoordData.indices->getNumElements()>0) - { - _fastPath = false; - break; - } - } - } - } - - _supportsVertexBufferObjects = _fastPath; - - //_supportsVertexBufferObjects = false; - //_useVertexBufferObjects = false; - - return _fastPath; -} - unsigned int Geometry::getGLObjectSizeHint() const { unsigned int totalSize = 0; - if (_vertexData.array.valid()) totalSize += _vertexData.array->getTotalDataSize(); + if (_vertexArray.valid()) totalSize += _vertexArray->getTotalDataSize(); - if (_normalData.array.valid()) totalSize += _normalData.array->getTotalDataSize(); + if (_normalArray.valid()) totalSize += _normalArray->getTotalDataSize(); - if (_colorData.array.valid()) totalSize += _colorData.array->getTotalDataSize(); + if (_colorArray.valid()) totalSize += _colorArray->getTotalDataSize(); - if (_secondaryColorData.array.valid()) totalSize += _secondaryColorData.array->getTotalDataSize(); + if (_secondaryColorArray.valid()) totalSize += _secondaryColorArray->getTotalDataSize(); - if (_fogCoordData.array.valid()) totalSize += _fogCoordData.array->getTotalDataSize(); + if (_fogCoordArray.valid()) totalSize += _fogCoordArray->getTotalDataSize(); unsigned int unit; for(unit=0;unit<_texCoordList.size();++unit) { - const Array* array = _texCoordList[unit].array.get(); + const Array* array = _texCoordList[unit].get(); if (array) totalSize += array->getTotalDataSize(); } @@ -654,7 +350,7 @@ unsigned int Geometry::getGLObjectSizeHint() const unsigned int index; for( index = 0; index < _vertexAttribList.size(); ++index ) { - const Array* array = _vertexAttribList[index].array.get(); + const Array* array = _vertexAttribList[index].get(); if (array) totalSize += array->getTotalDataSize(); } } @@ -677,21 +373,21 @@ bool Geometry::getArrayList(ArrayList& arrayList) const { unsigned int startSize = arrayList.size(); - if (_vertexData.array.valid()) arrayList.push_back(_vertexData.array.get()); - if (_normalData.array.valid()) arrayList.push_back(_normalData.array.get()); - if (_colorData.array.valid()) arrayList.push_back(_colorData.array.get()); - if (_secondaryColorData.array.valid()) arrayList.push_back(_secondaryColorData.array.get()); - if (_fogCoordData.array.valid()) arrayList.push_back(_fogCoordData.array.get()); + if (_vertexArray.valid()) arrayList.push_back(_vertexArray.get()); + if (_normalArray.valid()) arrayList.push_back(_normalArray.get()); + if (_colorArray.valid()) arrayList.push_back(_colorArray.get()); + if (_secondaryColorArray.valid()) arrayList.push_back(_secondaryColorArray.get()); + if (_fogCoordArray.valid()) arrayList.push_back(_fogCoordArray.get()); for(unsigned int unit=0;unit<_texCoordList.size();++unit) { - Array* array = _texCoordList[unit].array.get(); + Array* array = _texCoordList[unit].get(); if (array) arrayList.push_back(array); } for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) { - Array* array = _vertexAttribList[index].array.get(); + Array* array = _vertexAttribList[index].get(); if (array) arrayList.push_back(array); } @@ -746,7 +442,7 @@ osg::VertexBufferObject* Geometry::getOrCreateVertexBufferObject() vitr != arrayList.end(); ++vitr) { - osg::Array* array = *vitr; + osg::Array* array = vitr->get(); if (array->getVertexBufferObject()) return array->getVertexBufferObject(); } @@ -803,7 +499,7 @@ void Geometry::setUseVertexBufferObjects(bool flag) vitr != arrayList.end() && !vbo; ++vitr) { - osg::Array* array = *vitr; + osg::Array* array = vitr->get(); if (array->getVertexBufferObject()) vbo = array->getVertexBufferObject(); } @@ -813,7 +509,7 @@ void Geometry::setUseVertexBufferObjects(bool flag) vitr != arrayList.end(); ++vitr) { - osg::Array* array = *vitr; + osg::Array* array = vitr->get(); if (!array->getVertexBufferObject()) array->setVertexBufferObject(vbo.get()); } } @@ -850,7 +546,7 @@ void Geometry::setUseVertexBufferObjects(bool flag) vitr != arrayList.end(); ++vitr) { - osg::Array* array = *vitr; + osg::Array* array = vitr->get(); if (array->getVertexBufferObject()) array->setVertexBufferObject(0); } @@ -928,11 +624,9 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const { bool useVertexArrays = _supportsVertexBufferObjects && _useVertexBufferObjects && - renderInfo.getState()->isVertexBufferObjectSupported() && - areFastPathsUsed(); + renderInfo.getState()->isVertexBufferObjectSupported(); if (useVertexArrays) { - // OSG_NOTICE<<"Geometry::compileGLObjects() use VBO's "<getBufferObject()) bufferObjects.insert(_vertexData.array->getBufferObject()); - if (_normalData.array.valid() && _normalData.array->getBufferObject()) bufferObjects.insert(_normalData.array->getBufferObject()); - if (_colorData.array.valid() && _colorData.array->getBufferObject()) bufferObjects.insert(_colorData.array->getBufferObject()); - if (_secondaryColorData.array.valid() && _secondaryColorData.array->getBufferObject()) bufferObjects.insert(_secondaryColorData.array->getBufferObject()); - if (_fogCoordData.array.valid() && _fogCoordData.array->getBufferObject()) bufferObjects.insert(_fogCoordData.array->getBufferObject()); + if (_vertexArray.valid() && _vertexArray->getBufferObject()) bufferObjects.insert(_vertexArray->getBufferObject()); + if (_normalArray.valid() && _normalArray->getBufferObject()) bufferObjects.insert(_normalArray->getBufferObject()); + if (_colorArray.valid() && _colorArray->getBufferObject()) bufferObjects.insert(_colorArray->getBufferObject()); + if (_secondaryColorArray.valid() && _secondaryColorArray->getBufferObject()) bufferObjects.insert(_secondaryColorArray->getBufferObject()); + if (_fogCoordArray.valid() && _fogCoordArray->getBufferObject()) bufferObjects.insert(_fogCoordArray->getBufferObject()); - for(ArrayDataList::const_iterator itr = _texCoordList.begin(); + for(ArrayList::const_iterator itr = _texCoordList.begin(); itr != _texCoordList.end(); ++itr) { - if (itr->array.valid() && itr->array->getBufferObject()) bufferObjects.insert(itr->array->getBufferObject()); + if (itr->valid() && (*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject()); } - for(ArrayDataList::const_iterator itr = _vertexAttribList.begin(); + for(ArrayList::const_iterator itr = _vertexAttribList.begin(); itr != _vertexAttribList.end(); ++itr) { - if (itr->array.valid() && itr->array->getBufferObject()) bufferObjects.insert(itr->array->getBufferObject()); + if (itr->valid() && (*itr)->getBufferObject()) bufferObjects.insert((*itr)->getBufferObject()); } for(PrimitiveSetList::const_iterator itr = _primitives.begin(); @@ -999,47 +693,35 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const void Geometry::drawImplementation(RenderInfo& renderInfo) const { -#if 0 - if (!validGeometry()) + if (_containsDeprecatedData) { - OSG_NOTICE<<"Error, osg::Geometry has invalid array/primitive set usage"<fixDeprecatedData();"<drawImplementation(renderInfo); - return; - } - + State& state = *renderInfo.getState(); bool checkForGLErrors = state.getCheckForGLErrors()==osg::State::ONCE_PER_ATTRIBUTE; if (checkForGLErrors) state.checkGLErrors("start of Geometry::drawImplementation()"); - bool useFastPath = areFastPathsUsed(); - // useFastPath = false; - bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported(); bool handleVertexAttributes = !_vertexAttribList.empty(); ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers(); arrayDispatchers.reset(); - arrayDispatchers.setUseVertexAttribAlias(useFastPath && state.getUseVertexAttributeAliasing()); - arrayDispatchers.setUseGLBeginEndAdapter(!useFastPath); + arrayDispatchers.setUseVertexAttribAlias(state.getUseVertexAttributeAliasing()); - arrayDispatchers.activateNormalArray(_normalData.binding, _normalData.array.get(), _normalData.indices.get()); - arrayDispatchers.activateColorArray(_colorData.binding, _colorData.array.get(), _colorData.indices.get()); - arrayDispatchers.activateSecondaryColorArray(_secondaryColorData.binding, _secondaryColorData.array.get(), _secondaryColorData.indices.get()); - arrayDispatchers.activateFogCoordArray(_fogCoordData.binding, _fogCoordData.array.get(), _fogCoordData.indices.get()); + arrayDispatchers.activateNormalArray(_normalArray.get()); + arrayDispatchers.activateColorArray(_colorArray.get()); + arrayDispatchers.activateSecondaryColorArray(_secondaryColorArray.get()); + arrayDispatchers.activateFogCoordArray(_fogCoordArray.get()); if (handleVertexAttributes) { for(unsigned int unit=0;unit<_vertexAttribList.size();++unit) { - arrayDispatchers.activateVertexAttribArray(_vertexAttribList[unit].binding, unit, _vertexAttribList[unit].array.get(), _vertexAttribList[unit].indices.get()); + arrayDispatchers.activateVertexAttribArray(unit, _vertexAttribList[unit].get()); } } @@ -1048,230 +730,61 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const state.lazyDisablingOfVertexAttributes(); - if (useFastPath) + // set up arrays + if( _vertexArray.valid() ) + state.setVertexPointer(_vertexArray.get()); + + if (_normalArray.valid() && _normalArray->getBinding()==osg::Array::BIND_PER_VERTEX) + state.setNormalPointer(_normalArray.get()); + + if (_colorArray.valid() && _colorArray->getBinding()==osg::Array::BIND_PER_VERTEX) + state.setColorPointer(_colorArray.get()); + + if (_secondaryColorArray.valid() && _secondaryColorArray->getBinding()==osg::Array::BIND_PER_VERTEX) + state.setSecondaryColorPointer(_secondaryColorArray.get()); + + if (_fogCoordArray.valid() && _fogCoordArray->getBinding()==osg::Array::BIND_PER_VERTEX) + state.setFogCoordPointer(_fogCoordArray.get()); + + for(unsigned int unit=0;unit<_texCoordList.size();++unit) { - // set up arrays - if( _vertexData.array.valid() ) - state.setVertexPointer(_vertexData.array.get()); - - if (_normalData.binding==BIND_PER_VERTEX && _normalData.array.valid()) - state.setNormalPointer(_normalData.array.get()); - - if (_colorData.binding==BIND_PER_VERTEX && _colorData.array.valid()) - state.setColorPointer(_colorData.array.get()); - - if (_secondaryColorData.binding==BIND_PER_VERTEX && _secondaryColorData.array.valid()) - state.setSecondaryColorPointer(_secondaryColorData.array.get()); - - if (_fogCoordData.binding==BIND_PER_VERTEX && _fogCoordData.array.valid()) - state.setFogCoordPointer(_fogCoordData.array.get()); - - for(unsigned int unit=0;unit<_texCoordList.size();++unit) + const Array* array = _texCoordList[unit].get(); + if (array) { - const Array* array = _texCoordList[unit].array.get(); - if (array) state.setTexCoordPointer(unit,array); - } - - if( handleVertexAttributes ) - { - for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) - { - const Array* array = _vertexAttribList[index].array.get(); - const AttributeBinding ab = _vertexAttribList[index].binding; - if( ab == BIND_PER_VERTEX && array ) - { - state.setVertexAttribPointer( index, array, _vertexAttribList[index].normalize ); - } - } + state.setTexCoordPointer(unit,array); } } - else - { - for(unsigned int unit=0;unit<_texCoordList.size();++unit) - { - arrayDispatchers.activateTexCoordArray(BIND_PER_VERTEX, unit, _texCoordList[unit].array.get(), _texCoordList[unit].indices.get()); - } - arrayDispatchers.activateVertexArray(BIND_PER_VERTEX, _vertexData.array.get(), _vertexData.indices.get()); + if( handleVertexAttributes ) + { + for(unsigned int index = 0; index < _vertexAttribList.size(); ++index ) + { + const Array* array = _vertexAttribList[index].get(); + if(array && array->getBinding()==osg::Array::BIND_PER_VERTEX) + { + state.setVertexAttribPointer( index, array, _vertexAttribList[index]->getNormalize() ); + } + } } state.applyDisablingOfVertexAttributes(); bool bindPerPrimitiveSetActive = arrayDispatchers.active(BIND_PER_PRIMITIVE_SET); - bool bindPerPrimitiveActive = arrayDispatchers.active(BIND_PER_PRIMITIVE); - - unsigned int primitiveNum = 0; if (checkForGLErrors) state.checkGLErrors("Geometry::drawImplementation() after vertex arrays setup."); - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // draw the primitives themselves. // for(unsigned int primitiveSetNum=0; primitiveSetNum!=_primitives.size(); ++primitiveSetNum) { - // dispatch any attributes that are bound per primitive if (bindPerPrimitiveSetActive) arrayDispatchers.dispatch(BIND_PER_PRIMITIVE_SET, primitiveSetNum); const PrimitiveSet* primitiveset = _primitives[primitiveSetNum].get(); - if (useFastPath) - { - primitiveset->draw(state, usingVertexBufferObjects); - } - else - { - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - switch(mode) - { - case(GL_POINTS): primLength=1; break; - case(GL_LINES): primLength=2; break; - case(GL_TRIANGLES): primLength=3; break; - case(GL_QUADS): primLength=4; break; - default: primLength=0; break; // compute later when =0. - } - - // draw primitives by the more flexible "slow" path, - // sending OpenGL glBegin/glVertex.../glEnd(). - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawArrays* drawArray = static_cast(primitiveset); - arrayDispatchers.Begin(mode); - - unsigned int primCount=0; - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); - vindex(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - unsigned int localPrimLength; - if (primLength==0) localPrimLength=*primItr; - else localPrimLength=primLength; - - arrayDispatchers.Begin(mode); - - for(GLsizei primCount=0; - primCount<*primItr; - ++vindex,++primCount) - { - if (bindPerPrimitiveActive && (primCount%localPrimLength)==0) - { - arrayDispatchers.dispatch(BIND_PER_PRIMITIVE, primitiveNum++); - } - arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); - } - - arrayDispatchers.End(); - - } - break; - } - case(PrimitiveSet::DrawElementsUBytePrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUByte* drawElements = static_cast(primitiveset); - arrayDispatchers.Begin(mode); - - unsigned int primCount=0; - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - - if (bindPerPrimitiveActive && (primCount%primLength)==0) - { - arrayDispatchers.dispatch(BIND_PER_PRIMITIVE, primitiveNum++); - } - - unsigned int vindex=*primItr; - arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); - } - - arrayDispatchers.End(); - break; - } - case(PrimitiveSet::DrawElementsUShortPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUShort* drawElements = static_cast(primitiveset); - arrayDispatchers.Begin(mode); - - unsigned int primCount=0; - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - if (bindPerPrimitiveActive && (primCount%primLength)==0) - { - arrayDispatchers.dispatch(BIND_PER_PRIMITIVE, primitiveNum++); - } - - unsigned int vindex=*primItr; - arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); - } - - arrayDispatchers.End(); - break; - } - case(PrimitiveSet::DrawElementsUIntPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUInt* drawElements = static_cast(primitiveset); - arrayDispatchers.Begin(mode); - - unsigned int primCount=0; - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - if (bindPerPrimitiveActive && (primCount%primLength)==0) - { - arrayDispatchers.dispatch(BIND_PER_PRIMITIVE, primitiveNum++); - } - - unsigned int vindex=*primItr; - arrayDispatchers.dispatch(BIND_PER_VERTEX, vindex); - } - - arrayDispatchers.End(); - break; - } - default: - { - break; - } - } - } + primitiveset->draw(state, usingVertexBufferObjects); } // unbind the VBO's if any are used. @@ -1328,29 +841,29 @@ void Geometry::accept(AttributeFunctor& af) { AttributeFunctorArrayVisitor afav(af); - if (_vertexData.array.valid()) + if (_vertexArray.valid()) { - afav.applyArray(VERTICES,_vertexData.array.get()); + afav.applyArray(VERTICES,_vertexArray.get()); } else if (_vertexAttribList.size()>0) { OSG_INFO<<"Geometry::accept(AttributeFunctor& af): Using vertex attribute instead"<0) { OSG_INFO<<"Geometry::accept(ConstAttributeFunctor& af): Using vertex attribute instead"<0) { OSG_INFO<<"Using vertex attribute instead"<getNumElements()==0) return; - if (!indices) + if (_containsDeprecatedData && dynamic_cast(vertices->getUserData())!=0) { - switch(vertices->getType()) - { - case(Array::Vec2ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4ArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec2dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec3dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - case(Array::Vec4dArrayType): - functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); - break; - default: - OSG_WARN<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<getType()<accept(functor); - } + OSG_WARN<<"Geometry::accept(PrimitiveFunctor& functor) unable to work due to deprecated data, call geometry->fixDeprecatedData();"<getType()) { - const Vec2* vec2Array = 0; - const Vec3* vec3Array = 0; - const Vec4* vec4Array = 0; - const Vec2d* vec2dArray = 0; - const Vec3d* vec3dArray = 0; - const Vec4d* vec4dArray = 0; - Array::Type type = vertices->getType(); - switch(type) - { - case(Array::Vec2ArrayType): - vec2Array = static_cast(vertices->getDataPointer()); - break; - case(Array::Vec3ArrayType): - vec3Array = static_cast(vertices->getDataPointer()); - break; - case(Array::Vec4ArrayType): - vec4Array = static_cast(vertices->getDataPointer()); - break; - case(Array::Vec2dArrayType): - vec2dArray = static_cast(vertices->getDataPointer()); - break; - case(Array::Vec3dArrayType): - vec3dArray = static_cast(vertices->getDataPointer()); - break; - case(Array::Vec4dArrayType): - vec4dArray = static_cast(vertices->getDataPointer()); - break; - default: - OSG_WARN<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<getType()<get(); - GLenum mode=primitiveset->getMode(); - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - const DrawArrays* drawArray = static_cast(primitiveset); - functor.begin(mode); - - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); - vindexindex(vindex)]); - break; - case(Array::Vec3ArrayType): - functor.vertex(vec3Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4ArrayType): - functor.vertex(vec4Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec2dArrayType): - functor.vertex(vec2dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3dArrayType): - functor.vertex(vec3dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4dArrayType): - functor.vertex(vec4dArray[_vertexData.indices->index(vindex)]); - break; - default: - break; - } - - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - - const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - - functor.begin(mode); - - for(GLsizei primCount=0;primCount<*primItr;++primCount) - { - switch(type) - { - case(Array::Vec2ArrayType): - functor.vertex(vec2Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3ArrayType): - functor.vertex(vec3Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4ArrayType): - functor.vertex(vec4Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec2dArrayType): - functor.vertex(vec2dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3dArrayType): - functor.vertex(vec3dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4dArrayType): - functor.vertex(vec4dArray[_vertexData.indices->index(vindex)]); - break; - default: - break; - } - ++vindex; - } - - functor.end(); - - } - break; - } - case(PrimitiveSet::DrawElementsUBytePrimitiveType): - { - const DrawElementsUByte* drawElements = static_cast(primitiveset); - functor.begin(mode); - - unsigned int primCount=0; - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - unsigned int vindex=*primItr; - switch(type) - { - case(Array::Vec2ArrayType): - functor.vertex(vec2Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3ArrayType): - functor.vertex(vec3Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4ArrayType): - functor.vertex(vec4Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec2dArrayType): - functor.vertex(vec2dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3dArrayType): - functor.vertex(vec3dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4dArrayType): - functor.vertex(vec4dArray[_vertexData.indices->index(vindex)]); - break; - default: - break; - } - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawElementsUShortPrimitiveType): - { - const DrawElementsUShort* drawElements = static_cast(primitiveset); - functor.begin(mode); - - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - unsigned int vindex=*primItr; - switch(type) - { - case(Array::Vec2ArrayType): - functor.vertex(vec2Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3ArrayType): - functor.vertex(vec3Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4ArrayType): - functor.vertex(vec4Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec2dArrayType): - functor.vertex(vec2dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3dArrayType): - functor.vertex(vec3dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4dArrayType): - functor.vertex(vec4dArray[_vertexData.indices->index(vindex)]); - break; - default: - break; - } - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawElementsUIntPrimitiveType): - { - const DrawElementsUInt* drawElements = static_cast(primitiveset); - functor.begin(mode); - - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - unsigned int vindex=*primItr; - switch(type) - { - case(Array::Vec2ArrayType): - functor.vertex(vec2Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3ArrayType): - functor.vertex(vec3Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4ArrayType): - functor.vertex(vec4Array[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec2dArrayType): - functor.vertex(vec2dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec3dArrayType): - functor.vertex(vec3dArray[_vertexData.indices->index(vindex)]); - break; - case(Array::Vec4dArrayType): - functor.vertex(vec4dArray[_vertexData.indices->index(vindex)]); - break; - default: - break; - } - } - - functor.end(); - break; - } - default: - { - break; - } - } - } + case(Array::Vec2ArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + case(Array::Vec3ArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + case(Array::Vec4ArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + case(Array::Vec2dArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + case(Array::Vec3dArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + case(Array::Vec4dArrayType): + functor.setVertexArray(vertices->getNumElements(),static_cast(vertices->getDataPointer())); + break; + default: + OSG_WARN<<"Warning: Geometry::accept(PrimitiveFunctor&) cannot handle Vertex Array type"<getType()<accept(functor); } - return; } void Geometry::accept(PrimitiveIndexFunctor& functor) const { - const osg::Array* vertices = _vertexData.array.get(); - const osg::IndexArray* indices = _vertexData.indices.get(); + const osg::Array* vertices = _vertexArray.get(); if (!vertices && _vertexAttribList.size()>0) { OSG_INFO<<"Geometry::accept(PrimitiveIndexFunctor& functor): Using vertex attribute instead"<getNumElements()==0) return; + if (_containsDeprecatedData && dynamic_cast(vertices->getUserData())!=0) + { + OSG_WARN<<"Geometry::accept(PrimitiveIndexFunctor& functor) unable to work due to deprecated data, call geometry->fixDeprecatedData();"<getType()) { case(Array::Vec2ArrayType): @@ -1766,954 +1035,12 @@ void Geometry::accept(PrimitiveIndexFunctor& functor) const return; } - if (!indices) - { - for(PrimitiveSetList::const_iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - (*itr)->accept(functor); - } - } - else - { - for(PrimitiveSetList::const_iterator itr=_primitives.begin(); - itr!=_primitives.end(); - ++itr) - { - const PrimitiveSet* primitiveset = itr->get(); - GLenum mode=primitiveset->getMode(); - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - const DrawArrays* drawArray = static_cast(primitiveset); - functor.begin(mode); - - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); - vindexindex(vindex)); - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - - const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - - functor.begin(mode); - - for(GLsizei primCount=0;primCount<*primItr;++primCount) - { - functor.vertex(indices->index(vindex)); - ++vindex; - } - - functor.end(); - - } - break; - } - case(PrimitiveSet::DrawElementsUBytePrimitiveType): - { - const DrawElementsUByte* drawElements = static_cast(primitiveset); - functor.begin(mode); - - unsigned int primCount=0; - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - unsigned int vindex=*primItr; - functor.vertex(indices->index(vindex)); - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawElementsUShortPrimitiveType): - { - const DrawElementsUShort* drawElements = static_cast(primitiveset); - functor.begin(mode); - - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - unsigned int vindex=*primItr; - functor.vertex(indices->index(vindex)); - } - - functor.end(); - break; - } - case(PrimitiveSet::DrawElementsUIntPrimitiveType): - { - const DrawElementsUInt* drawElements = static_cast(primitiveset); - functor.begin(mode); - - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primItr) - { - unsigned int vindex=*primItr; - functor.vertex(indices->index(vindex)); - } - - functor.end(); - break; - } - default: - { - break; - } - } - } - } - return; -} - -unsigned int _computeNumberOfPrimitives(const osg::Geometry& geom) -{ - - unsigned int totalNumberOfPrimitives = 0; - - for(Geometry::PrimitiveSetList::const_iterator itr=geom.getPrimitiveSetList().begin(); - itr!=geom.getPrimitiveSetList().end(); + for(PrimitiveSetList::const_iterator itr=_primitives.begin(); + itr!=_primitives.end(); ++itr) { - const PrimitiveSet* primitiveset = itr->get(); - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - switch(mode) - { - case(GL_POINTS): primLength=1; OSG_INFO<<"prim=GL_POINTS"<getType()) - { - case(PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - - const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - if (primLength==0) totalNumberOfPrimitives += 1; - else totalNumberOfPrimitives += *primItr/primLength; - } - break; - } - default: - { - if (primLength==0) { totalNumberOfPrimitives += 1; OSG_INFO<<" totalNumberOfPrimitives="<getNumIndices()/primLength; OSG_INFO<<" primitiveset->getNumIndices()="<getNumIndices()<<" totalNumberOfPrimitives="<accept(functor); } - - return totalNumberOfPrimitives; -} - -template -bool _verifyBindings(const osg::Geometry& geom, const A& arrayData) -{ - unsigned int numElements = arrayData.indices.valid()?arrayData.indices->getNumElements(): - arrayData.array.valid()?arrayData.array->getNumElements():0; - - switch(arrayData.binding) - { - case(osg::Geometry::BIND_OFF): - if (numElements>0) return false; - break; - case(osg::Geometry::BIND_OVERALL): - if (numElements!=1) return false; - break; - case(osg::Geometry::BIND_PER_PRIMITIVE_SET): - if (numElements!=geom.getPrimitiveSetList().size()) return false; - break; - case(osg::Geometry::BIND_PER_PRIMITIVE): - if (numElements!=_computeNumberOfPrimitives(geom)) return false; - break; - case(osg::Geometry::BIND_PER_VERTEX): - { - unsigned int numVertices = geom.getVertexIndices()?geom.getVertexIndices()->getNumElements(): - geom.getVertexArray()?geom.getVertexArray()->getNumElements():0; - if (numElements!=numVertices) return false; - break; - } - } - return true; -} - -template -void _computeCorrectBindingsAndArraySizes(std::ostream& out, const osg::Geometry& geom, A& arrayData, const char* arrayName) -{ - unsigned int numElements = arrayData.indices.valid()?arrayData.indices->getNumElements(): - arrayData.array.valid()?arrayData.array->getNumElements():0; - - // check to see if binding matches 0 elements required. - if (numElements==0) - { - // correct binding if not correct. - if (arrayData.binding!=osg::Geometry::BIND_OFF) - { - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<getNumElements(): - geom.getVertexArray()?geom.getVertexArray()->getNumElements():0; - - if ( numVertices==0 ) - { - if (arrayData.binding!=osg::Geometry::BIND_OFF) - { - arrayData.array = 0; - arrayData.indices = 0; - arrayData.binding = osg::Geometry::BIND_OFF; - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() vertex array is empty but "<numVertices) - { - arrayData.binding = osg::Geometry::BIND_PER_VERTEX; - return; - } - if (numElements>numPrimitives) - { - arrayData.binding = osg::Geometry::BIND_PER_PRIMITIVE; - return; - } - if (numElements>numPrimitiveSets) - { - arrayData.binding = osg::Geometry::BIND_PER_PRIMITIVE_SET; - return; - } - if (numElements>=1) - { - arrayData.binding = osg::Geometry::BIND_OVERALL; - return; - } - arrayData.binding = osg::Geometry::BIND_OFF; - -} - -bool Geometry::verifyBindings(const ArrayData& arrayData) const -{ - return _verifyBindings(*this,arrayData); -} - -bool Geometry::verifyBindings(const Vec3ArrayData& arrayData) const -{ - return _verifyBindings(*this,arrayData); -} - -void Geometry::computeCorrectBindingsAndArraySizes(ArrayData& arrayData, const char* arrayName) -{ - _computeCorrectBindingsAndArraySizes(osg::notify(osg::INFO),*this,arrayData,arrayName); -} - -void Geometry::computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData, const char* arrayName) -{ - _computeCorrectBindingsAndArraySizes(osg::notify(osg::INFO),*this,arrayData,arrayName); -} - -bool Geometry::verifyBindings() const -{ - if (!verifyBindings(_normalData)) return false; - if (!verifyBindings(_colorData)) return false; - if (!verifyBindings(_secondaryColorData)) return false; - if (!verifyBindings(_fogCoordData)) return false; - - for(ArrayDataList::const_iterator titr=_texCoordList.begin(); - titr!=_texCoordList.end(); - ++titr) - { - if (!verifyBindings(*titr)) return false; - } - - for(ArrayDataList::const_iterator vitr=_vertexAttribList.begin(); - vitr!=_vertexAttribList.end(); - ++vitr) - { - if (!verifyBindings(*vitr)) return false; - } - - return true; -} - -void Geometry::computeCorrectBindingsAndArraySizes() -{ - // if (verifyBindings()) return; - - computeCorrectBindingsAndArraySizes(_normalData,"_normalData"); - computeCorrectBindingsAndArraySizes(_colorData,"_colorData"); - computeCorrectBindingsAndArraySizes(_secondaryColorData,"_secondaryColorData"); - computeCorrectBindingsAndArraySizes(_fogCoordData,"_fogCoordData"); - - for(ArrayDataList::iterator titr=_texCoordList.begin(); - titr!=_texCoordList.end(); - ++titr) - { - computeCorrectBindingsAndArraySizes(*titr,"_texCoordList[]"); - } - - for(ArrayDataList::iterator vitr=_vertexAttribList.begin(); - vitr!=_vertexAttribList.end(); - ++vitr) - { - computeCorrectBindingsAndArraySizes(*vitr,"_vertAttribList[]"); - } -} - -class ExpandIndexedArray : public osg::ConstArrayVisitor -{ - public: - ExpandIndexedArray(const osg::IndexArray& indices,Array* targetArray): - _indices(indices), - _targetArray(targetArray) {} - - virtual ~ExpandIndexedArray() {} - - // Create when both of the arrays are predefined templated classes. We - // can do some optimizations in this case that aren't possible in the general - // case. - template - T* create_inline(const T& array,const I& indices) - { - T* newArray = 0; - - // if source array type and target array type are equal but arrays arn't equal - if (_targetArray && _targetArray->getType()==array.getType() && _targetArray!=(osg::Array*)(&array)) - { - // reuse exisiting target array - newArray = static_cast(_targetArray); - if (newArray->size()!=indices.size()) - { - // make sure its the right size - newArray->resize(indices.size()); - } - } - else - { - // else create a new array. - newArray = new T(indices.size()); - } - - for(unsigned int i=0;i - osg::Array* create_noinline(const osg::Array& array, const osg::IndexArray& indices) - { - T* newArray = 0; - typedef typename T::ElementDataType EDT; - - unsigned int num_indices = indices.getNumElements(); - newArray = new T(num_indices); - - const EDT* src = static_cast(array.getDataPointer()); - - for(unsigned int i=0;i(array,indices); - case(osg::Array::ShortArrayType): return create_noinline(array,indices); - case(osg::Array::IntArrayType): return create_noinline(array,indices); - case(osg::Array::UByteArrayType): return create_noinline(array,indices); - case(osg::Array::UShortArrayType): return create_noinline(array,indices); - case(osg::Array::UIntArrayType): return create_noinline(array,indices); - case(osg::Array::Vec4ubArrayType): return create_noinline(array,indices); - case(osg::Array::FloatArrayType): return create_noinline(array,indices); - case(osg::Array::Vec2ArrayType): return create_noinline(array,indices); - case(osg::Array::Vec3ArrayType): return create_noinline(array,indices); - case(osg::Array::Vec4ArrayType): return create_noinline(array,indices); - case(osg::Array::Vec2dArrayType): return create_noinline(array,indices); - case(osg::Array::Vec3dArrayType): return create_noinline(array,indices); - case(osg::Array::Vec4dArrayType): return create_noinline(array,indices); - default: - return NULL; - } - } - - template - osg::Array* create(const TA& array, const osg::IndexArray& indices) - { - // We know that indices.getType returned the same thing as TI, but - // we need to determine whether it is really an instance of TI, or - // perhaps another subclass of osg::Array that contains the same - // type of data. - const TI* ba(dynamic_cast(&indices)); - if (ba != NULL) { - return create_inline(array,*ba); - } - else { - return create_noinline(array, _indices); - } - } - - template - osg::Array* create(const T& array) - { - switch(_indices.getType()) - { - case(osg::Array::ByteArrayType): return create(array, _indices); - case(osg::Array::ShortArrayType): return create(array, _indices); - case(osg::Array::IntArrayType): return create(array, _indices); - case(osg::Array::UByteArrayType): return create(array, _indices); - case(osg::Array::UShortArrayType): return create(array, _indices); - case(osg::Array::UIntArrayType): return create(array, _indices); - default: return create_noinline(array, _indices); - } - - } - - // applys for the predefined classes go through 1-arg create to do indexing - virtual void apply(const osg::ByteArray& array) { _targetArray = create(array); } - virtual void apply(const osg::ShortArray& array) { _targetArray = create(array); } - virtual void apply(const osg::IntArray& array) { _targetArray = create(array); } - virtual void apply(const osg::UByteArray& array) { _targetArray = create(array); } - virtual void apply(const osg::UShortArray& array) { _targetArray = create(array); } - virtual void apply(const osg::UIntArray& array) { _targetArray = create(array); } - virtual void apply(const osg::Vec4ubArray& array) { _targetArray = create(array); } - virtual void apply(const osg::FloatArray& array) { _targetArray = create(array); } - virtual void apply(const osg::Vec2Array& array) { _targetArray = create(array); } - virtual void apply(const osg::Vec3Array& array) { _targetArray = create(array); } - virtual void apply(const osg::Vec4Array& array) { _targetArray = create(array); } - - // other subclasses of osg::Array end up here - virtual void apply(const osg::Array& array) { _targetArray = create_noinline(array, _indices); } - - const osg::IndexArray& _indices; - osg::Array* _targetArray; - - protected: - - ExpandIndexedArray& operator = (const ExpandIndexedArray&) { return *this; } - -}; - -bool Geometry::suitableForOptimization() const -{ - bool hasIndices = false; - - if (getVertexIndices()) hasIndices = true; - - if (getNormalIndices()) hasIndices = true; - - if (getColorIndices()) hasIndices = true; - - if (getSecondaryColorIndices()) hasIndices = true; - - if (getFogCoordIndices()) hasIndices = true; - - for(unsigned int ti=0;tiaccept(eia); - - target.setVertexArray(eia._targetArray); - target.setVertexIndices(0); - } - else if (getVertexArray()) - { - if (!copyToSelf) target.setVertexArray(getVertexArray()); - } - - target.setNormalBinding(getNormalBinding()); - if (getNormalIndices() && getNormalArray()) - { - ExpandIndexedArray eia(*(getNormalIndices()),target.getNormalArray()); - getNormalArray()->accept(eia); - - target.setNormalArray(dynamic_cast(eia._targetArray)); - target.setNormalIndices(0); - } - else if (getNormalArray()) - { - if (!copyToSelf) target.setNormalArray(getNormalArray()); - } - - target.setColorBinding(getColorBinding()); - if (getColorIndices() && getColorArray()) - { - ExpandIndexedArray eia(*(getColorIndices()),target.getColorArray()); - getColorArray()->accept(eia); - - target.setColorArray(eia._targetArray); - target.setColorIndices(0); - } - else if (getColorArray()) - { - if (!copyToSelf) target.setColorArray(getColorArray()); - } - - target.setSecondaryColorBinding(getSecondaryColorBinding()); - if (getSecondaryColorIndices() && getSecondaryColorArray()) - { - ExpandIndexedArray eia(*(getSecondaryColorIndices()),target.getSecondaryColorArray()); - getSecondaryColorArray()->accept(eia); - - target.setSecondaryColorArray(eia._targetArray); - target.setSecondaryColorIndices(0); - } - else if (getSecondaryColorArray()) - { - if (!copyToSelf) target.setSecondaryColorArray(getSecondaryColorArray()); - } - - target.setFogCoordBinding(getFogCoordBinding()); - if (getFogCoordIndices() && getFogCoordArray()) - { - ExpandIndexedArray eia(*(getFogCoordIndices()),target.getFogCoordArray()); - getFogCoordArray()->accept(eia); - - target.setFogCoordArray(eia._targetArray); - target.setFogCoordIndices(0); - } - else if (getFogCoordArray()) - { - if (!copyToSelf) target.setFogCoordArray(getFogCoordArray()); - } - - for(unsigned int ti=0;tiaccept(eia); - - target.setTexCoordArray(ti,eia._targetArray); - target.setTexCoordIndices(ti,0); - } - else if (getTexCoordArray(ti)) - { - if (!copyToSelf) target.setTexCoordArray(ti,getTexCoordArray(ti)); - } - } - - for(unsigned int vi=0;vi<_vertexAttribList.size();++vi) - { - ArrayData& arrayData = _vertexAttribList[vi]; - if (arrayData.indices.valid()) - { - ExpandIndexedArray eia(*arrayData.indices,target.getVertexAttribArray(vi)); - arrayData.array->accept(eia); - target.setVertexAttribData(vi,ArrayData(eia._targetArray, 0, arrayData.binding, arrayData.normalize)); - } - else if (arrayData.array.valid()) - { - if (!copyToSelf) target.setVertexAttribData(vi,arrayData); - } - } -} - -bool Geometry::containsSharedArrays() const -{ - unsigned int numSharedArrays = 0; - - if (getVertexArray() && getVertexArray()->referenceCount()>1) ++numSharedArrays; - if (getNormalArray() && getNormalArray()->referenceCount()>1) ++numSharedArrays; - if (getColorArray() && getColorArray()->referenceCount()>1) ++numSharedArrays; - if (getSecondaryColorArray() && getSecondaryColorArray()->referenceCount()>1) ++numSharedArrays; - if (getFogCoordArray() && getFogCoordArray()->referenceCount()>1) ++numSharedArrays; - - for(unsigned int ti=0;tireferenceCount()>1) ++numSharedArrays; - } - - for(unsigned int vi=0;vi<_vertexAttribList.size();++vi) - { - const ArrayData& arrayData = _vertexAttribList[vi]; - if (arrayData.array.valid() && arrayData.array->referenceCount()>1) ++numSharedArrays; - } - return numSharedArrays!=0; -} - -void Geometry::duplicateSharedArrays() -{ - #define DUPLICATE_IF_REQUIRED(A) \ - if (get##A() && get##A()->referenceCount()>1) \ - { \ - set##A(osg::clone(get##A(), osg::CopyOp::DEEP_COPY_ARRAYS)); \ - } - - DUPLICATE_IF_REQUIRED(VertexArray) - DUPLICATE_IF_REQUIRED(NormalArray) - DUPLICATE_IF_REQUIRED(ColorArray) - DUPLICATE_IF_REQUIRED(SecondaryColorArray) - DUPLICATE_IF_REQUIRED(FogCoordArray) - - for(unsigned int ti=0;tireferenceCount()>1) - { - setTexCoordArray(ti, osg::clone(getTexCoordArray(ti),osg::CopyOp::DEEP_COPY_ARRAYS)); - } - } - - for(unsigned int vi=0;vi<_vertexAttribList.size();++vi) - { - ArrayData& arrayData = _vertexAttribList[vi]; - if (arrayData.array.valid() && arrayData.array->referenceCount()>1) - { - arrayData.array = osg::clone(arrayData.array.get(), osg::CopyOp::DEEP_COPY_ARRAYS); - } - } -} - -void Geometry::computeInternalOptimizedGeometry() -{ - if (suitableForOptimization()) - { - if (!_internalOptimizedGeometry) _internalOptimizedGeometry = new Geometry; - - copyToAndOptimize(*_internalOptimizedGeometry); - } -} - -class CheckArrayValidity -{ -public: - CheckArrayValidity(const osg::Geometry* geometry) - { - numPrimitiveSets = geometry->getNumPrimitiveSets(); - primitiveNum = 0; - maxVertexNumber = 0; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - // draw the primitives themselves. - // - for(unsigned int primitiveSetNum=0; primitiveSetNum != numPrimitiveSets; ++primitiveSetNum) - { - const PrimitiveSet* primitiveset = geometry->getPrimitiveSet(primitiveSetNum); - - GLenum mode=primitiveset->getMode(); - - unsigned int primLength; - switch(mode) - { - case(GL_POINTS): primLength=1; break; - case(GL_LINES): primLength=2; break; - case(GL_TRIANGLES): primLength=3; break; - case(GL_QUADS): primLength=4; break; - default: primLength=0; break; // compute later when =0. - } - - // draw primitives by the more flexible "slow" path, - // sending OpenGL glBegin/glVertex.../glEnd(). - switch(primitiveset->getType()) - { - case(PrimitiveSet::DrawArraysPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawArrays* drawArray = static_cast(primitiveset); - - unsigned int primCount=0; - unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); - for(unsigned int vindex=drawArray->getFirst(); - vindex maxVertexNumber) maxVertexNumber = (indexEnd-1); - break; - } - case(PrimitiveSet::DrawArrayLengthsPrimitiveType): - { - const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); - unsigned int vindex=drawArrayLengths->getFirst(); - for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); - primItr!=drawArrayLengths->end(); - ++primItr) - { - unsigned int localPrimLength; - if (primLength==0) localPrimLength=*primItr; - else localPrimLength=primLength; - - for(GLsizei primCount=0; - primCount<*primItr; - ++vindex,++primCount) - { - if ((primCount%localPrimLength)==0) - { - primitiveNum++; - } - } - - } - if ((vindex-1) > maxVertexNumber) maxVertexNumber = (vindex-1); - break; - } - case(PrimitiveSet::DrawElementsUBytePrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUByte* drawElements = static_cast(primitiveset); - - unsigned int primCount=0; - for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - if ((primCount%primLength)==0) - { - primitiveNum++; - } - unsigned int vindex = *primItr; - if (vindex > maxVertexNumber) maxVertexNumber = vindex; - } - - break; - } - case(PrimitiveSet::DrawElementsUShortPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUShort* drawElements = static_cast(primitiveset); - unsigned int primCount=0; - for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - if ((primCount%primLength)==0) - { - primitiveNum++; - } - unsigned int vindex = *primItr; - if (vindex > maxVertexNumber) maxVertexNumber = vindex; - } - - break; - } - case(PrimitiveSet::DrawElementsUIntPrimitiveType): - { - if (primLength==0) primLength=primitiveset->getNumIndices(); - - const DrawElementsUInt* drawElements = static_cast(primitiveset); - unsigned int primCount=0; - for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); - primItr!=drawElements->end(); - ++primCount,++primItr) - { - if ((primCount%primLength)==0) - { - primitiveNum++; - } - unsigned int vindex = *primItr; - if (vindex > maxVertexNumber) maxVertexNumber = vindex; - } - break; - } - default: - { - break; - } - } - } - } - - bool validArray(std::ostream& out, const osg::Geometry::ArrayData& arrayData, const char* arrayName) - { - unsigned int numRequired = 0; - switch(arrayData.binding) - { - case(osg::Geometry::BIND_OFF): numRequired = 0; break; - case(osg::Geometry::BIND_OVERALL): numRequired = 1; break; - case(osg::Geometry::BIND_PER_PRIMITIVE): numRequired = primitiveNum; break; - case(osg::Geometry::BIND_PER_PRIMITIVE_SET): numRequired = numPrimitiveSets; break; - case(osg::Geometry::BIND_PER_VERTEX): numRequired = maxVertexNumber+1; break; - } - - if (arrayData.indices.valid()) - { - unsigned int numIndices= arrayData.indices.valid() ? arrayData.indices->getNumElements() : 0; - if (numIndicesgetNumElements() : 0; - if (numElementsgetBinding()==static_cast(ab)) return; + + _vertexAttribList[index]->setBinding(static_cast(ab)); + + dirtyDisplayList(); + } + else + { + OSG_NOTICE<<"Warning, can't assign attribute binding as no has been array assigned to set binding for."<(_vertexAttribList[index]->getBinding()); + else return BIND_OFF; +} + +void Geometry::setVertexAttribNormalize(unsigned int index,GLboolean norm) +{ + if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) + { + _vertexAttribList[index]->setNormalize(norm); + + dirtyDisplayList(); + } +} + +GLboolean Geometry::getVertexAttribNormalize(unsigned int index) const +{ + if (index<_vertexAttribList.size() && _vertexAttribList[index].valid()) return _vertexAttribList[index]->getNormalize(); + else return GL_FALSE; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Helper methods +// +bool Geometry::containsSharedArrays() const +{ + unsigned int numSharedArrays = 0; + + if (getVertexArray() && getVertexArray()->referenceCount()>1) ++numSharedArrays; + if (getNormalArray() && getNormalArray()->referenceCount()>1) ++numSharedArrays; + if (getColorArray() && getColorArray()->referenceCount()>1) ++numSharedArrays; + if (getSecondaryColorArray() && getSecondaryColorArray()->referenceCount()>1) ++numSharedArrays; + if (getFogCoordArray() && getFogCoordArray()->referenceCount()>1) ++numSharedArrays; + + for(unsigned int ti=0;tireferenceCount()>1) ++numSharedArrays; + } + + for(unsigned int vi=0;vi<_vertexAttribList.size();++vi) + { + if (getVertexAttribArray(vi) && getVertexAttribArray(vi)->referenceCount()>1) ++numSharedArrays; + } + return numSharedArrays!=0; +} + +void Geometry::duplicateSharedArrays() +{ + #define DUPLICATE_IF_REQUIRED(A) \ + if (get##A() && get##A()->referenceCount()>1) \ + { \ + set##A(osg::clone(get##A(), osg::CopyOp::DEEP_COPY_ARRAYS)); \ + } + + DUPLICATE_IF_REQUIRED(VertexArray) + DUPLICATE_IF_REQUIRED(NormalArray) + DUPLICATE_IF_REQUIRED(ColorArray) + DUPLICATE_IF_REQUIRED(SecondaryColorArray) + DUPLICATE_IF_REQUIRED(FogCoordArray) + + for(unsigned int ti=0;tireferenceCount()>1) + { + setTexCoordArray(ti, osg::clone(getTexCoordArray(ti),osg::CopyOp::DEEP_COPY_ARRAYS)); + } + } + + for(unsigned int vi=0;vi<_vertexAttribList.size();++vi) + { + if (getVertexAttribArray(vi) && getVertexAttribArray(vi)->referenceCount()>1) + { + setVertexAttribArray(vi, osg::clone(getVertexAttribArray(vi),osg::CopyOp::DEEP_COPY_ARRAYS)); + } + } +} + +bool Geometry::checkForDeprecatedData() +{ + _containsDeprecatedData = false; + + if (getVertexIndices()) _containsDeprecatedData = true; + + if (getNormalIndices() || getNormalBinding()==osg::Geometry::BIND_PER_PRIMITIVE) _containsDeprecatedData = true; + + if (getColorIndices() || getColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE) _containsDeprecatedData = true; + + if (getSecondaryColorIndices() || getSecondaryColorBinding()==osg::Geometry::BIND_PER_PRIMITIVE) _containsDeprecatedData = true; + + if (getFogCoordIndices() || getFogCoordBinding()==osg::Geometry::BIND_PER_PRIMITIVE) _containsDeprecatedData = true; + + for(unsigned int ti=0;ti targetArray = osg::cloneType(sourceArray); + targetArray->setBinding(sourceArray->getBinding()); + targetArray->setNormalize(sourceArray->getNormalize()); + targetArray->setPreserveDataType(sourceArray->getPreserveDataType()); + targetArray->resizeArray(indices->getNumElements()); + + unsigned int elementSize = sourceArray->getElementSize(); + const char* sourcePtr = static_cast(sourceArray->getDataPointer()); + char* targetPtr = const_cast(static_cast(targetArray->getDataPointer())); + for(unsigned int i=0; igetNumElements(); ++i) + { + unsigned int vi = indices->index(i); + const char* sourceElementPtr = sourcePtr + elementSize*vi; + char* targetElementPtr = targetPtr + elementSize*i; + for(unsigned int j=0; j, osg::ref_ptr > ArrayPair; +typedef std::vector< ArrayPair > ArrayPairs; +static void duplicateArray(ArrayPairs& pairs, osg::ref_ptr& sourceArray, unsigned int numVertices) +{ + osg::Array* targetArray = osg::cloneType(sourceArray.get()); + targetArray->setBinding(osg::Array::BIND_PER_VERTEX); + targetArray->setNormalize(sourceArray->getNormalize()); + targetArray->setPreserveDataType(sourceArray->getPreserveDataType()); + targetArray->resizeArray(numVertices); + pairs.push_back(ArrayPair(sourceArray, targetArray)); + sourceArray = targetArray; +} + +struct PtrData +{ + char* source; + char* target; + unsigned int elementSize; + + PtrData():source(0),target(0),elementSize(0) {} + + PtrData(osg::Array* s, osg::Array* t): + source(const_cast(static_cast(s->getDataPointer()))), + target(const_cast(static_cast(t->getDataPointer()))), + elementSize(s->getElementSize()) {} + + PtrData(const PtrData& rhs): + source(rhs.source), + target(rhs.target), + elementSize(rhs.elementSize) {} + + PtrData& operator = (const PtrData& rhs) + { + source = rhs.source; + target = rhs.target; + elementSize = rhs.elementSize; + return *this; + } +}; + +void Geometry::fixDeprecatedData() +{ + if (!_containsDeprecatedData) return; + + bool containsBindPerPrimitive = false; + + OSG_NOTICE<<"Geometry::fixDeprecatedData()"<get(); + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + const DrawArrays* drawArray = static_cast(primitiveset); + numVertices = drawArray->getCount(); + break; + } + case(PrimitiveSet::DrawArrayLengthsPrimitiveType): + { + const DrawArrayLengths* drawArrayLengths = static_cast(primitiveset); + for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); + primItr!=drawArrayLengths->end(); + ++primItr) + { + unsigned int localNumVertices = *primItr; + numVertices += localNumVertices; + primItr += localNumVertices; + } + break; + } + case(PrimitiveSet::DrawElementsUBytePrimitiveType): + { + const DrawElementsUByte* drawElements = static_cast(primitiveset); + numVertices += drawElements->getNumIndices(); + break; + } + case(PrimitiveSet::DrawElementsUShortPrimitiveType): + { + const DrawElementsUShort* drawElements = static_cast(primitiveset); + numVertices += drawElements->getNumIndices(); + break; + } + case(PrimitiveSet::DrawElementsUIntPrimitiveType): + { + const DrawElementsUInt* drawElements = static_cast(primitiveset); + numVertices += drawElements->getNumIndices(); + break; + } + default: + { + break; + } + } + } + + // allocate the arrays. + ArrayPairs perVertexArrays; + ArrayPairs perPrimitiveArrays; + if (_vertexArray.valid()) duplicateArray(perVertexArrays, _vertexArray, numVertices); + + if (_normalArray.valid()) + { + if (_normalArray->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, _normalArray, numVertices); + else if (_normalArray->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, _normalArray, numVertices); + } + + if (_colorArray.valid()) + { + if (_colorArray->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, _colorArray, numVertices); + else if (_colorArray->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, _colorArray, numVertices); + } + + if (_secondaryColorArray.valid()) + { + if (_secondaryColorArray->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, _secondaryColorArray, numVertices); + else if (_secondaryColorArray->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, _secondaryColorArray, numVertices); + } + + if (_fogCoordArray.valid()) + { + if (_fogCoordArray->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, _fogCoordArray, numVertices); + else if (_fogCoordArray->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, _fogCoordArray, numVertices); + } + + for(ArrayList::iterator itr = _texCoordList.begin(); + itr != _texCoordList.end(); + ++itr) + { + if (itr->valid()) + { + if ((*itr)->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, *itr, numVertices); + else if ((*itr)->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, *itr, numVertices); + } + } + + for(ArrayList::iterator itr = _vertexAttribList.begin(); + itr != _vertexAttribList.end(); + ++itr) + { + if (itr->valid()) + { + if ((*itr)->getBinding()==osg::Array::BIND_PER_VERTEX) duplicateArray(perVertexArrays, *itr, numVertices); + else if ((*itr)->getBinding()==osg::Array::BIND_PER_PRIMITIVE) duplicateArray(perPrimitiveArrays, *itr, numVertices); + } + } + + typedef std::vector PtrList; + PtrList perVertexPtrs; + PtrList perPrimitivePtrs; + + for(ArrayPairs::iterator itr = perVertexArrays.begin(); + itr != perVertexArrays.end(); + ++itr) + { + perVertexPtrs.push_back(PtrData(itr->first.get(), itr->second.get())); + } + + for(ArrayPairs::iterator itr = perPrimitiveArrays.begin(); + itr != perPrimitiveArrays.end(); + ++itr) + { + perPrimitivePtrs.push_back(PtrData(itr->first.get(), itr->second.get())); + } + + + // start the primitiveNum at -1 as we increment it the first time through when + // we start processing the primitive sets. + int primitiveNum = -1; + for(PrimitiveSetList::iterator itr = _primitives.begin(); + itr != _primitives.end(); + ++itr) + { + osg::PrimitiveSet* primitiveset = itr->get(); + GLenum mode=primitiveset->getMode(); + + unsigned int primLength; + switch(mode) + { + case(GL_POINTS): primLength=1; break; + case(GL_LINES): primLength=2; break; + case(GL_TRIANGLES): primLength=3; break; + case(GL_QUADS): primLength=4; break; + default: primLength=0; break; // compute later when =0. + } + + // copy the vertex data across to the new arays + int source_pindex = -1; + int target_vindex = 0; + switch(primitiveset->getType()) + { + case(PrimitiveSet::DrawArraysPrimitiveType): + { + if (primLength==0) primLength=primitiveset->getNumIndices(); + + const DrawArrays* drawArray = static_cast(primitiveset); + + if (primLength==0) primLength = drawArray->getCount(); + + unsigned int primCount=0; + unsigned int indexEnd = drawArray->getFirst()+drawArray->getCount(); + for(unsigned int vindex=drawArray->getFirst(); + vindex(primitiveset); + unsigned int vindex=drawArrayLengths->getFirst(); + for(DrawArrayLengths::const_iterator primItr=drawArrayLengths->begin(); + primItr!=drawArrayLengths->end(); + ++primItr) + { + unsigned int localPrimLength; + if (primLength==0) localPrimLength=*primItr; + else localPrimLength=primLength; + + for(GLsizei primCount=0; + primCount<*primItr; + ++vindex, ++target_vindex, ++primCount) + { + if ((primCount%localPrimLength)==0) ++source_pindex; + + // copy bind per primitive from primitiveNum + for(PtrList::iterator itr = perVertexPtrs.begin(); + itr != perVertexPtrs.end(); + ++itr) + { + PtrData& ptrs = *itr; + char* source = ptrs.source + vindex*ptrs.elementSize; + char* target = ptrs.target + target_vindex*ptrs.elementSize; + for(unsigned int c=0; cgetNumIndices(); + + const DrawElementsUByte* drawElements = static_cast(primitiveset); + unsigned int primCount=0; + for(DrawElementsUByte::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount, ++target_vindex, ++primItr) + { + if ((primCount%primLength)==0) ++source_pindex; + unsigned int vindex=*primItr; + + // copy bind per primitive from primitiveNum + for(PtrList::iterator itr = perVertexPtrs.begin(); + itr != perVertexPtrs.end(); + ++itr) + { + PtrData& ptrs = *itr; + char* source = ptrs.source + vindex*ptrs.elementSize; + char* target = ptrs.target + target_vindex*ptrs.elementSize; + for(unsigned int c=0; cgetNumIndices(); + + const DrawElementsUShort* drawElements = static_cast(primitiveset); + unsigned int primCount=0; + for(DrawElementsUShort::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount, ++target_vindex, ++primItr) + { + if ((primCount%primLength)==0) ++primitiveNum; + unsigned int vindex=*primItr; + + // copy bind per primitive from primitiveNum + for(PtrList::iterator itr = perVertexPtrs.begin(); + itr != perVertexPtrs.end(); + ++itr) + { + PtrData& ptrs = *itr; + char* source = ptrs.source + vindex*ptrs.elementSize; + char* target = ptrs.target + target_vindex*ptrs.elementSize; + for(unsigned int c=0; cgetNumIndices(); + + const DrawElementsUInt* drawElements = static_cast(primitiveset); + unsigned int primCount=0; + for(DrawElementsUInt::const_iterator primItr=drawElements->begin(); + primItr!=drawElements->end(); + ++primCount, ++target_vindex, ++primItr) + { + if ((primCount%primLength)==0) ++primitiveNum; + unsigned int vindex=*primItr; + + // copy bind per primitive from primitiveNum + for(PtrList::iterator itr = perVertexPtrs.begin(); + itr != perVertexPtrs.end(); + ++itr) + { + PtrData& ptrs = *itr; + char* source = ptrs.source + vindex*ptrs.elementSize; + char* target = ptrs.target + target_vindex*ptrs.elementSize; + for(unsigned int c=0; cgetUseVertexBufferObjects() && geometry->areFastPathsUsed(); + bool usesVBO = geometry->getUseVertexBufferObjects(); bool usesDL = !usesVBO && geometry->getUseDisplayList() && geometry->getSupportsDisplayList(); if (usesVBO || usesDL) diff --git a/src/osgAnimation/MorphGeometry.cpp b/src/osgAnimation/MorphGeometry.cpp index 10175aad1..f3c819198 100644 --- a/src/osgAnimation/MorphGeometry.cpp +++ b/src/osgAnimation/MorphGeometry.cpp @@ -40,8 +40,6 @@ MorphGeometry::MorphGeometry(const osg::Geometry& b) : setUpdateCallback(new UpdateVertex); setDataVariance(osg::Object::DYNAMIC); setUseVertexBufferObjects(true); - if (b.getInternalOptimizedGeometry()) - computeInternalOptimizedGeometry(); } MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) : @@ -55,8 +53,6 @@ MorphGeometry::MorphGeometry(const MorphGeometry& b, const osg::CopyOp& copyop) { setUseDisplayList(false); setUseVertexBufferObjects(true); - if (b.getInternalOptimizedGeometry()) - computeInternalOptimizedGeometry(); } void MorphGeometry::transformSoftwareMethod() @@ -65,8 +61,6 @@ void MorphGeometry::transformSoftwareMethod() { // See if we have an internal optimized geometry osg::Geometry* morphGeometry = this; - if (_internalOptimizedGeometry.valid()) - morphGeometry = _internalOptimizedGeometry.get(); osg::Vec3Array* pos = dynamic_cast(morphGeometry->getVertexArray()); if (pos && _positionSource.size() != pos->size()) @@ -134,9 +128,7 @@ void MorphGeometry::transformSoftwareMethod() if (_morphTargets[i].getWeight() > 0) { // See if any the targets use the internal optimized geometry - osg::Geometry* targetGeometry = _morphTargets[i].getGeometry()->getInternalOptimizedGeometry(); - if (!targetGeometry) - targetGeometry = _morphTargets[i].getGeometry(); + osg::Geometry* targetGeometry = _morphTargets[i].getGeometry(); osg::Vec3Array* targetPos = dynamic_cast(targetGeometry->getVertexArray()); osg::Vec3Array* targetNormals = dynamic_cast(targetGeometry->getNormalArray()); diff --git a/src/osgAnimation/RigGeometry.cpp b/src/osgAnimation/RigGeometry.cpp index cb683dcd2..34872c673 100644 --- a/src/osgAnimation/RigGeometry.cpp +++ b/src/osgAnimation/RigGeometry.cpp @@ -153,28 +153,28 @@ void RigGeometry::copyFrom(osg::Geometry& from) if (!copyToSelf) target.setVertexArray(from.getVertexArray()); } - target.setNormalBinding(from.getNormalBinding()); if (from.getNormalArray()) { if (!copyToSelf) target.setNormalArray(from.getNormalArray()); + target.setNormalBinding(from.getNormalBinding()); } - target.setColorBinding(from.getColorBinding()); if (from.getColorArray()) { if (!copyToSelf) target.setColorArray(from.getColorArray()); + target.setColorBinding(from.getColorBinding()); } - target.setSecondaryColorBinding(from.getSecondaryColorBinding()); if (from.getSecondaryColorArray()) { if (!copyToSelf) target.setSecondaryColorArray(from.getSecondaryColorArray()); + target.setSecondaryColorBinding(from.getSecondaryColorBinding()); } - target.setFogCoordBinding(from.getFogCoordBinding()); if (from.getFogCoordArray()) { if (!copyToSelf) target.setFogCoordArray(from.getFogCoordArray()); + target.setFogCoordBinding(from.getFogCoordBinding()); } for(unsigned int ti=0;tiaddBindAttribLocation(ss.str(), attribIndex + i); - geom.setVertexAttribData(attribIndex + i, osg::Geometry::ArrayData(getVertexAttrib(i),osg::Geometry::BIND_PER_VERTEX)); + geom.setVertexAttribArray(attribIndex + i, getVertexAttrib(i)); OSG_INFO << "set vertex attrib " << ss.str() << std::endl; } program->addShader(_shader.get()); diff --git a/src/osgFX/BumpMapping.cpp b/src/osgFX/BumpMapping.cpp index 8e1c356ef..b3ac89fb9 100644 --- a/src/osgFX/BumpMapping.cpp +++ b/src/osgFX/BumpMapping.cpp @@ -597,11 +597,11 @@ void BumpMapping::prepareGeometry(osg::Geometry* geo) osg::ref_ptr tsg = new osgUtil::TangentSpaceGenerator; tsg->generate(geo, _normal_unit); if (!geo->getVertexAttribArray(6)) - geo->setVertexAttribData(6, osg::Geometry::ArrayData(tsg->getTangentArray(), osg::Geometry::BIND_PER_VERTEX,GL_FALSE)); + geo->setVertexAttribArray(6, tsg->getTangentArray()); if (!geo->getVertexAttribArray(7)) - geo->setVertexAttribData(7, osg::Geometry::ArrayData(tsg->getBinormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE)); + geo->setVertexAttribArray(7, tsg->getBinormalArray()); if (!geo->getVertexAttribArray(15)) - geo->setVertexAttribData(15, osg::Geometry::ArrayData(tsg->getNormalArray(), osg::Geometry::BIND_PER_VERTEX, GL_FALSE)); + geo->setVertexAttribArray(15, tsg->getNormalArray()); } void BumpMapping::prepareNode(osg::Node* node) diff --git a/src/osgPlugins/ac/Geode.cpp b/src/osgPlugins/ac/Geode.cpp index 04c67276e..7421d32ea 100644 --- a/src/osgPlugins/ac/Geode.cpp +++ b/src/osgPlugins/ac/Geode.cpp @@ -758,8 +758,8 @@ void Geode::ProcessGeometry(ostream& fout, const unsigned int ioffset) if (NULL != pVertexArray) { const unsigned int iNumVertices = pVertexArray->getNumElements(); // size(); - const osg::IndexArray *pVertexIndices = pGeometry->getVertexIndices(); - const osg::IndexArray * pTexIndices = pGeometry->getTexCoordIndices(0); + const osg::IndexArray *pVertexIndices = 0; + const osg::IndexArray * pTexIndices = 0; const osg::Vec2 *pTexCoords = NULL; fout << "OBJECT poly" << std::endl; fout << "name \"" << getName() << "\"" << std::endl; diff --git a/src/osgPlugins/ive/Geometry.cpp b/src/osgPlugins/ive/Geometry.cpp index 39aac9a9d..409d896e1 100644 --- a/src/osgPlugins/ive/Geometry.cpp +++ b/src/osgPlugins/ive/Geometry.cpp @@ -129,40 +129,52 @@ void Geometry::write(DataOutputStream* out){ out->writeArray(getFogCoordIndices()); } // Write texture coord arrays - Geometry::ArrayDataList& tcal = getTexCoordArrayList(); + Geometry::ArrayList& tcal = getTexCoordArrayList(); out->writeInt(tcal.size()); unsigned int j; for(j=0;jwriteBool(tcal[j].array.valid()); - if (tcal[j].array.valid()){ - out->writeArray(tcal[j].array.get()); + out->writeBool(tcal[j].valid()); + if (tcal[j].valid()){ + out->writeArray(tcal[j].get()); } + // Write indices if valid - out->writeBool(tcal[j].indices.valid()); - if (tcal[j].indices.valid()){ - out->writeArray(tcal[j].indices.get()); + const osg::IndexArray* indices = getTexCoordIndices(j); + out->writeBool(indices!=0); + if (indices!=0){ + out->writeArray(indices); } } // Write vertex attributes - Geometry::ArrayDataList& vaal = getVertexAttribArrayList(); + Geometry::ArrayList& vaal = getVertexAttribArrayList(); out->writeInt(vaal.size()); for(j=0;jwriteBinding(arrayData.binding); - out->writeBool(arrayData.normalize==GL_TRUE); - out->writeBool(arrayData.array.valid()); - if (arrayData.array.valid()){ - out->writeArray(arrayData.array.get()); + const osg::Array* array = vaal[j].get(); + if (array) + { + out->writeBinding(static_cast(array->getBinding())); + out->writeBool(array->getNormalize()); + out->writeBool(true); + out->writeArray(array); + + // Write indices if valid + const osg::IndexArray* indices = getVertexAttribIndices(j); + out->writeBool(indices!=0); + if (indices!=0){ + out->writeArray(indices); + } } - // Write indices if valid - out->writeBool(arrayData.indices.valid()); - if (arrayData.indices.valid()){ - out->writeArray(arrayData.indices.get()); + else + { + out->writeBinding(BIND_OFF); + out->writeBool(false); + out->writeBool(false); + out->writeBool(false); } } } diff --git a/src/osgPlugins/pov/POVWriterNodeVisitor.cpp b/src/osgPlugins/pov/POVWriterNodeVisitor.cpp index 86ea79211..7a5662f92 100644 --- a/src/osgPlugins/pov/POVWriterNodeVisitor.cpp +++ b/src/osgPlugins/pov/POVWriterNodeVisitor.cpp @@ -527,19 +527,6 @@ void POVWriterNodeVisitor::processGeometry( const Geometry *g, if( g->getVertexArray() == NULL || g->getVertexArray()->getNumElements() == 0 ) return; - if(( g->getVertexIndices() != NULL && - g->getVertexIndices()->getNumElements() != 0 ) || - ( g->getNormalIndices() != NULL && - g->getNormalIndices()->getNumElements() != 0 ) || - ( g->getTexCoordIndices(0) != NULL && - g->getTexCoordIndices(0)->getNumElements() != 0 )) - { - notify( WARN ) << "POV Writer WARNING: " - "Geometry with indices is not " << endl << - "supported yet by POV plugin. Skipping geometry." << endl; - return; - } - // mesh2 _fout << "mesh2" << endl; _fout << "{" << endl; diff --git a/src/osgUtil/EdgeCollector.cpp b/src/osgUtil/EdgeCollector.cpp index 94a5265e5..f3eec17eb 100644 --- a/src/osgUtil/EdgeCollector.cpp +++ b/src/osgUtil/EdgeCollector.cpp @@ -448,14 +448,6 @@ void EdgeCollector::setGeometry(osg::Geometry* geometry) { _geometry = geometry; - // check to see if vertex attributes indices exists, if so expand them to remove them - if (_geometry->suitableForOptimization()) - { - // removing coord indices - OSG_INFO<<"EdgeCollector::setGeometry(..): Removing attribute indices"<copyToAndOptimize(*_geometry); - } - unsigned int numVertices = geometry->getVertexArray()->getNumElements(); _originalPointList.resize(numVertices); diff --git a/src/osgUtil/MeshOptimizers.cpp b/src/osgUtil/MeshOptimizers.cpp index a3c461f15..4d978515f 100644 --- a/src/osgUtil/MeshOptimizers.cpp +++ b/src/osgUtil/MeshOptimizers.cpp @@ -279,17 +279,7 @@ void IndexMeshVisitor::makeMesh(Geometry& geom) // nothing to index if (!numSurfacePrimitives || !numNonIndexedPrimitives) return; - // check to see if vertex attributes indices exists, if so expand them to remove them - if (geom.suitableForOptimization()) - { - // removing coord indices - OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"< IndexList; unsigned int numVertices = geom.getVertexArray()->getNumElements(); IndexList indices(numVertices); diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 53a072f26..4a92dc988 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -50,6 +50,7 @@ using namespace osgUtil; +// #define GEOMETRYDEPRECATED void Optimizer::reset() { @@ -1684,33 +1685,18 @@ struct LessGeometry if (lhs->getStateSet()getStateSet()) return true; if (rhs->getStateSet()getStateSet()) return false; - if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; } - else if (lhs->getVertexIndices()) return false; - if (lhs->getNormalBinding()getNormalBinding()) return true; if (rhs->getNormalBinding()getNormalBinding()) return false; - if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; } - else if (lhs->getNormalIndices()) return false; - if (lhs->getColorBinding()getColorBinding()) return true; if (rhs->getColorBinding()getColorBinding()) return false; - if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; } - else if (lhs->getColorIndices()) return false; - if (lhs->getSecondaryColorBinding()getSecondaryColorBinding()) return true; if (rhs->getSecondaryColorBinding()getSecondaryColorBinding()) return false; - if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; } - else if (lhs->getSecondaryColorIndices()) return false; - if (lhs->getFogCoordBinding()getFogCoordBinding()) return true; if (rhs->getFogCoordBinding()getFogCoordBinding()) return false; - if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; } - else if (lhs->getFogCoordIndices()) return false; - if (lhs->getNumTexCoordArrays()getNumTexCoordArrays()) return true; if (rhs->getNumTexCoordArrays()getNumTexCoordArrays()) return false; @@ -1724,9 +1710,6 @@ struct LessGeometry if (!lhs->getTexCoordArray(i)) return true; } else if (lhs->getTexCoordArray(i)) return false; - - if (rhs->getTexCoordIndices(i)) { if (!lhs->getTexCoordIndices(i)) return true; } - else if (lhs->getTexCoordIndices(i)) return false; } for(i=0;igetNumVertexAttribArrays();++i) @@ -1736,9 +1719,6 @@ struct LessGeometry if (!lhs->getVertexAttribArray(i)) return true; } else if (lhs->getVertexAttribArray(i)) return false; - - if (rhs->getVertexAttribIndices(i)) { if (!lhs->getVertexAttribIndices(i)) return true; } - else if (lhs->getVertexAttribIndices(i)) return false; } @@ -1828,7 +1808,10 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode) osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom && isOperationPermissibleForObject(geom)) { - geom->computeCorrectBindingsAndArraySizes(); +#ifdef GEOMETRYDEPRECATED + geom1829 + ->computeCorrectBindingsAndArraySizes(); +#endif } } } @@ -1836,6 +1819,7 @@ void Optimizer::CheckGeometryVisitor::checkGeode(osg::Geode& geode) void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode) { + // GeometryDeprecated CAN REMOVED if (isOperationPermissibleForObject(&geode)) { for(unsigned int i=0;iasGeometry(); if (geom && isOperationPermissibleForObject(geom)) { - if (!geom->areFastPathsUsed() && !geom->getInternalOptimizedGeometry()) + if (geom->checkForDeprecatedData()) { - geom->computeInternalOptimizedGeometry(); + geom->fixDeprecatedData(); } } } @@ -2457,7 +2441,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom MergeArrayVisitor merger; unsigned int base = 0; - unsigned int vbase = lhs.getVertexArray() ? lhs.getVertexArray()->getNumElements() : 0; if (lhs.getVertexArray() && rhs.getVertexArray()) { @@ -2473,23 +2456,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setVertexArray(rhs.getVertexArray()); } - if (lhs.getVertexIndices() && rhs.getVertexIndices()) - { - base = lhs.getVertexIndices()->getNumElements(); - if (!merger.merge(lhs.getVertexIndices(),rhs.getVertexIndices(),vbase)) - { - OSG_DEBUG << "MergeGeometry: vertex indices not merged. Some data may be lost." <getNumElements() : 0; if (lhs.getNormalArray() && rhs.getNormalArray() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL) { if (!merger.merge(lhs.getNormalArray(),rhs.getNormalArray())) @@ -2502,21 +2469,7 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setNormalArray(rhs.getNormalArray()); } - if (lhs.getNormalIndices() && rhs.getNormalIndices() && lhs.getNormalBinding()!=osg::Geometry::BIND_OVERALL) - { - if (!merger.merge(lhs.getNormalIndices(),rhs.getNormalIndices(),nbase)) - { - OSG_DEBUG << "MergeGeometry: Vertex Array not merged. Some data may be lost." <getNumElements() : 0; if (lhs.getColorArray() && rhs.getColorArray() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL) { if (!merger.merge(lhs.getColorArray(),rhs.getColorArray())) @@ -2529,20 +2482,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setColorArray(rhs.getColorArray()); } - if (lhs.getColorIndices() && rhs.getColorIndices() && lhs.getColorBinding()!=osg::Geometry::BIND_OVERALL) - { - if (!merger.merge(lhs.getColorIndices(),rhs.getColorIndices(),cbase)) - { - OSG_DEBUG << "MergeGeometry: color indices not merged. Some data may be lost." <getNumElements() : 0; if (lhs.getSecondaryColorArray() && rhs.getSecondaryColorArray() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL) { if (!merger.merge(lhs.getSecondaryColorArray(),rhs.getSecondaryColorArray())) @@ -2555,20 +2494,6 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setSecondaryColorArray(rhs.getSecondaryColorArray()); } - if (lhs.getSecondaryColorIndices() && rhs.getSecondaryColorIndices() && lhs.getSecondaryColorBinding()!=osg::Geometry::BIND_OVERALL) - { - if (!merger.merge(lhs.getSecondaryColorIndices(),rhs.getSecondaryColorIndices(),scbase)) - { - OSG_DEBUG << "MergeGeometry: secondary color indices not merged. Some data may be lost." <getNumElements() : 0; if (lhs.getFogCoordArray() && rhs.getFogCoordArray() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL) { if (!merger.merge(lhs.getFogCoordArray(),rhs.getFogCoordArray())) @@ -2581,53 +2506,22 @@ bool Optimizer::MergeGeometryVisitor::mergeGeometry(osg::Geometry& lhs,osg::Geom lhs.setFogCoordArray(rhs.getFogCoordArray()); } - if (lhs.getFogCoordIndices() && rhs.getFogCoordIndices() && lhs.getFogCoordBinding()!=osg::Geometry::BIND_OVERALL) - { - if (!merger.merge(lhs.getFogCoordIndices(),rhs.getFogCoordIndices(),fcbase)) - { - OSG_DEBUG << "MergeGeometry: fog coord indices not merged. Some data may be lost." <getNumElements() : 0; if (!merger.merge(lhs.getTexCoordArray(unit),rhs.getTexCoordArray(unit))) { OSG_DEBUG << "MergeGeometry: tex coord array not merged. Some data may be lost." <getNumElements() : 0; if (!merger.merge(lhs.getVertexAttribArray(unit),rhs.getVertexAttribArray(unit))) { OSG_DEBUG << "MergeGeometry: vertex attrib array not merged. Some data may be lost." <asGeometry(); if (geom) { - if (geom->areFastPathsUsed()) - stats.addFastDrawable(); + stats.addFastDrawable(); } if (rl->_modelview.get()) @@ -576,8 +575,7 @@ bool RenderBin::getStats(Statistics& stats) const const Geometry* geom = dw->asGeometry(); if (geom) { - if (geom->areFastPathsUsed()) - stats.addFastDrawable(); + stats.addFastDrawable(); } if (rl->_modelview.get()) stats.addMatrix(); // number of matrices diff --git a/src/osgUtil/Simplifier.cpp b/src/osgUtil/Simplifier.cpp index f80506ce5..6bf041d99 100644 --- a/src/osgUtil/Simplifier.cpp +++ b/src/osgUtil/Simplifier.cpp @@ -1419,14 +1419,6 @@ void EdgeCollapse::setGeometry(osg::Geometry* geometry, const Simplifier::IndexL { _geometry = geometry; - // check to see if vertex attributes indices exists, if so expand them to remove them - if (_geometry->suitableForOptimization()) - { - // removing coord indices - OSG_INFO<<"EdgeCollapse::setGeometry(..): Removing attribute indices"<copyToAndOptimize(*_geometry); - } - // check to see if vertex attributes indices exists, if so expand them to remove them if (_geometry->containsSharedArrays()) { diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index 3e1492d15..5dbb7f8c9 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -143,10 +143,8 @@ static void smooth_old(osg::Geometry& geom) nitr->normalize(); } geom.setNormalArray( normals ); - geom.setNormalIndices( geom.getVertexIndices() ); geom.setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - geom.dirtyDisplayList(); } diff --git a/src/osgUtil/Statistics.cpp b/src/osgUtil/Statistics.cpp index 4c2a14e3d..5fa832b88 100644 --- a/src/osgUtil/Statistics.cpp +++ b/src/osgUtil/Statistics.cpp @@ -278,11 +278,8 @@ void StatsVisitor::apply(osg::Drawable& drawable) ++_numInstancedGeometry; _geometrySet.insert(geometry); - if (geometry->areFastPathsUsed()) - { - ++_numInstancedFastGeometry; - _fastGeometrySet.insert(geometry); - } + ++_numInstancedFastGeometry; + _fastGeometrySet.insert(geometry); } } diff --git a/src/osgUtil/TangentSpaceGenerator.cpp b/src/osgUtil/TangentSpaceGenerator.cpp index 57edb4e63..e9f57b2fe 100644 --- a/src/osgUtil/TangentSpaceGenerator.cpp +++ b/src/osgUtil/TangentSpaceGenerator.cpp @@ -11,6 +11,9 @@ TangentSpaceGenerator::TangentSpaceGenerator() B_(new osg::Vec4Array), N_(new osg::Vec4Array) { + T_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false); + B_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false); + N_->setBinding(osg::Geometry::BIND_PER_VERTEX); T_->setNormalize(false); } TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator ©, const osg::CopyOp ©op) @@ -23,14 +26,6 @@ TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator ©, void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit) { - // check to see if vertex attributes indices exists, if so expand them to remove them - if (geo->suitableForOptimization()) - { - // removing coord indices so we don't have to deal with them in the binormal code. - OSG_INFO<<"TangentSpaceGenerator::generate(Geometry*,int): Removing attribute indices"<copyToAndOptimize(*geo); - } - const osg::Array *vx = geo->getVertexArray(); const osg::Array *nx = geo->getNormalArray(); const osg::Array *tx = geo->getTexCoordArray(normal_map_tex_unit); @@ -39,21 +34,9 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit unsigned int vertex_count = vx->getNumElements(); - if (geo->getVertexIndices() == NULL) { - T_->assign(vertex_count, osg::Vec4()); - B_->assign(vertex_count, osg::Vec4()); - N_->assign(vertex_count, osg::Vec4()); - } else { - unsigned int index_count = geo->getVertexIndices()->getNumElements(); - T_->assign(index_count, osg::Vec4()); - B_->assign(index_count, osg::Vec4()); - N_->assign(index_count, osg::Vec4()); - indices_ = new osg::UIntArray(); - unsigned int i; - for (i=0;ipush_back(i); - } - } + T_->assign(vertex_count, osg::Vec4()); + B_->assign(vertex_count, osg::Vec4()); + N_->assign(vertex_count, osg::Vec4()); unsigned int i; // VC6 doesn't like for-scoped variables @@ -163,9 +146,6 @@ void TangentSpaceGenerator::generate(osg::Geometry *geo, int normal_map_tex_unit // normalize basis vectors and force the normal vector to match // the triangle normal's direction unsigned int attrib_count = vx->getNumElements(); - if (geo->getVertexIndices() != NULL) { - attrib_count = geo->getVertexIndices()->getNumElements(); - } for (i=0; iempty() || geom.getPrimitiveSetList().empty()) return; - - // we currently don't handle geometry which use indices... - if (geom.getVertexIndices() || - geom.getNormalIndices() || - geom.getColorIndices() || - geom.getSecondaryColorIndices() || - geom.getFogCoordIndices()) return; - - // not even text coord indices don't handle geometry which use indices... - for(unsigned int unit=0;unitarray.valid()) + if (tcalItr->valid()) { - arrays.push_back(tcalItr->array.get()); + arrays.push_back(tcalItr->get()); } } diff --git a/src/osgUtil/TriStripVisitor.cpp b/src/osgUtil/TriStripVisitor.cpp index 9e502a002..555ebb5e1 100644 --- a/src/osgUtil/TriStripVisitor.cpp +++ b/src/osgUtil/TriStripVisitor.cpp @@ -230,14 +230,6 @@ void TriStripVisitor::stripify(Geometry& geom) // no point tri stripping if we don't have enough vertices. if (!geom.getVertexArray() || geom.getVertexArray()->getNumElements()<3) return; - // check to see if vertex attributes indices exists, if so expand them to remove them - if (geom.suitableForOptimization()) - { - // removing coord indices - OSG_INFO<<"TriStripVisitor::stripify(Geometry&): Removing attribute indices"<(array->getUserData()) : 0; + if (indices) { fw.indent()<<"TexCoordIndices "<(array->getBinding()))<getNormalize()) fw.indent()<<"VertexAttribNormalize "<(array->getUserData()) : 0; + if (indices) { fw.indent()<<"VertexAttribIndices "< +#include #include #include #include @@ -14,7 +15,10 @@ static bool readDrawables( osgDB::InputStream& is, osg::Geode& node ) for ( unsigned int i=0; i( is.readObject() ); - if ( drawable ) node.addDrawable( drawable ); + if ( drawable ) + { + node.addDrawable( drawable ); + } } is >> is.END_BRACKET; return true; diff --git a/src/osgWrappers/serializers/osg/Geometry.cpp b/src/osgWrappers/serializers/osg/Geometry.cpp index d19534caf..87f931060 100644 --- a/src/osgWrappers/serializers/osg/Geometry.cpp +++ b/src/osgWrappers/serializers/osg/Geometry.cpp @@ -14,88 +14,98 @@ END_USER_TABLE() USER_READ_FUNC( AttributeBinding, readAttributeBinding ) USER_WRITE_FUNC( AttributeBinding, writeAttributeBinding ) -static void readArrayData( osgDB::InputStream& is, osg::Geometry::ArrayData& data ) +static osg::Array* readArray( osgDB::InputStream& is) { + osg::ref_ptr array; bool hasArray = false; is >> is.PROPERTY("Array") >> hasArray; - if ( hasArray ) data.array = is.readArray(); + if ( hasArray ) array = is.readArray(); bool hasIndices = false; is >> is.PROPERTY("Indices") >> hasIndices; - if ( hasIndices ) data.indices = dynamic_cast( is.readArray() ); + if ( hasIndices ) + { + osg::ref_ptr indices_array = is.readArray(); + osg::ref_ptr indices = dynamic_cast( indices_array.get() ); + if (array.valid() && indices.valid()) array->setUserData(indices.get()); + } is >> is.PROPERTY("Binding"); - data.binding = (osg::Geometry::AttributeBinding)readAttributeBinding(is); + int binding = readAttributeBinding(is); + if (array.valid()) array->setBinding(static_cast(binding)); int normalizeValue = 0; is >> is.PROPERTY("Normalize") >> normalizeValue; - data.normalize = normalizeValue; + if (array.valid()) array->setNormalize(normalizeValue!=0); + + return array.release(); } -static void writeArrayData( osgDB::OutputStream& os, const osg::Geometry::ArrayData& data ) +static void writeArray( osgDB::OutputStream& os, const osg::Array* array) { - os << os.PROPERTY("Array") << data.array.valid(); - if ( data.array.valid() ) os << data.array.get(); + os << os.PROPERTY("Array") << (array!=0); + if ( array!=0 ) os << array; else os << std::endl; - os << os.PROPERTY("Indices") << data.indices.valid(); - if ( data.indices.valid() ) os << data.indices.get(); + const osg::IndexArray* indices = (array!=0) ? dynamic_cast(array->getUserData()) : 0; + os << os.PROPERTY("Indices") << (indices!=0); + if ( indices!=0 ) os << indices; else os << std::endl; - os << os.PROPERTY("Binding"); writeAttributeBinding(os, data.binding); os << std::endl; - os << os.PROPERTY("Normalize") << (int)data.normalize << std::endl; + os << os.PROPERTY("Binding"); writeAttributeBinding(os, (array!=0) ? static_cast(array->getBinding()) : osg::Geometry::BIND_OFF); os << std::endl; + os << os.PROPERTY("Normalize") << ((array!=0 && array->getNormalize()) ? 1:0) << std::endl; } -#define ADD_ARRAYDATA_FUNCTIONS( PROP ) \ - static bool check##PROP( const osg::Geometry& geom ) \ - { return geom.get##PROP().array.valid(); } \ - static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \ - osg::Geometry::ArrayData data; \ - is >> is.BEGIN_BRACKET; readArrayData(is, data); \ +#define ADD_ARRAYDATA_FUNCTIONS( ORIGINAL_PROP, PROP ) \ + static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \ + { return geom.get##PROP()!=0; } \ + static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \ + is >> is.BEGIN_BRACKET; \ + osg::Array* array = readArray(is); \ + geom.set##PROP(array); \ is >> is.END_BRACKET; \ - geom.set##PROP(data); \ return true; \ } \ - static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \ + static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \ os << os.BEGIN_BRACKET << std::endl; \ - writeArrayData(os, geom.get##PROP()); \ + writeArray(os, geom.get##PROP()); \ os << os.END_BRACKET << std::endl; \ return true; \ } -ADD_ARRAYDATA_FUNCTIONS( VertexData ) -ADD_ARRAYDATA_FUNCTIONS( NormalData ) -ADD_ARRAYDATA_FUNCTIONS( ColorData ) -ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData ) -ADD_ARRAYDATA_FUNCTIONS( FogCoordData ) +ADD_ARRAYDATA_FUNCTIONS( VertexData, VertexArray ) +ADD_ARRAYDATA_FUNCTIONS( NormalData, NormalArray ) +ADD_ARRAYDATA_FUNCTIONS( ColorData, ColorArray ) +ADD_ARRAYDATA_FUNCTIONS( SecondaryColorData, SecondaryColorArray ) +ADD_ARRAYDATA_FUNCTIONS( FogCoordData, FogCoordArray ) -#define ADD_ARRAYLIST_FUNCTIONS( PROP, LISTNAME ) \ - static bool check##PROP( const osg::Geometry& geom ) \ +#define ADD_ARRAYLIST_FUNCTIONS( ORIGINAL_PROP, PROP, LISTNAME ) \ + static bool check##ORIGINAL_PROP( const osg::Geometry& geom ) \ { return geom.get##LISTNAME().size()>0; } \ - static bool read##PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \ + static bool read##ORIGINAL_PROP( osgDB::InputStream& is, osg::Geometry& geom ) { \ unsigned int size = is.readSize(); is >> is.BEGIN_BRACKET; \ for ( unsigned int i=0; i> is.PROPERTY("Data") >> is.BEGIN_BRACKET; \ - readArrayData(is, data); \ - is >> is.END_BRACKET; geom.set##PROP(i, data); } \ + osg::Array* array = readArray(is); \ + geom.set##PROP(i, array); \ + is >> is.END_BRACKET; } \ is >> is.END_BRACKET; \ return true; \ } \ - static bool write##PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \ - const osg::Geometry::ArrayDataList& LISTNAME = geom.get##LISTNAME(); \ + static bool write##ORIGINAL_PROP( osgDB::OutputStream& os, const osg::Geometry& geom ) { \ + const osg::Geometry::ArrayList& LISTNAME = geom.get##LISTNAME(); \ os.writeSize(LISTNAME.size()); os << os.BEGIN_BRACKET << std::endl; \ - for ( osg::Geometry::ArrayDataList::const_iterator itr=LISTNAME.begin(); \ + for ( osg::Geometry::ArrayList::const_iterator itr=LISTNAME.begin(); \ itr!=LISTNAME.end(); ++itr ) { \ os << os.PROPERTY("Data") << os.BEGIN_BRACKET << std::endl; \ - writeArrayData(os, *itr); os << os.END_BRACKET << std::endl; \ + writeArray(os, *itr); os << os.END_BRACKET << std::endl; \ } \ os << os.END_BRACKET << std::endl; \ return true; \ } -ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArrayList ) -ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArrayList ) +ADD_ARRAYLIST_FUNCTIONS( TexCoordData, TexCoordArray, TexCoordArrayList ) +ADD_ARRAYLIST_FUNCTIONS( VertexAttribData, VertexAttribArray, VertexAttribArrayList ) struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCallback { @@ -110,6 +120,26 @@ struct GeometryFinishedObjectReadCallback : public osgDB::FinishedObjectReadCall } }; +// implement backwards compatibility with reading/writing the FastPathHint +static bool checkFastPathHint( const osg::Geometry& geom ) { return false; } +static bool readFastPathHint( osgDB::InputStream& is, osg::Geometry& geom ) +{ + bool value = false; + if ( is.isBinary() ) + { + is >> value; + } + else if ( is.matchString("FastPathHint") ) + { + is >> value; + } + return true; +} +static bool writeFastPathHint( osgDB::OutputStream& os, const osg::Geometry& geom ) +{ + return true; +} + REGISTER_OBJECT_WRAPPER( Geometry, new osg::Geometry, osg::Geometry, @@ -123,8 +153,8 @@ REGISTER_OBJECT_WRAPPER( Geometry, ADD_USER_SERIALIZER( FogCoordData ); // _fogCoordData ADD_USER_SERIALIZER( TexCoordData ); // _texCoordList ADD_USER_SERIALIZER( VertexAttribData ); // _vertexAttribList - ADD_BOOL_SERIALIZER( FastPathHint, true ); // _fastPathHint - //ADD_OBJECT_SERIALIZER( InternalOptimizedGeometry, osg::Geometry, NULL ); // _internalOptimizedGeometry + + ADD_USER_SERIALIZER( FastPathHint ); // _fastPathHint wrapper->addFinishedObjectReadCallback( new GeometryFinishedObjectReadCallback() ); }