diff --git a/include/osg/GeoSet b/include/osg/GeoSet index 43b3a457b..d551d6e60 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -23,6 +23,8 @@ class SG_EXPORT GeoSet : public Drawable { public: + + enum PrimitiveType { NO_TYPE, POINTS, @@ -290,6 +292,28 @@ class SG_EXPORT GeoSet : public Drawable const bool check() const; + + /** function object which is used to handling the clean up of attribute arrays + * associated with GeoSet's. A default is provided which assumes that all + * momory attached to the GeoSet is owned by this GeoSet and can be deleted + * using delete []. If this is not the cause derive your own AttributeDeleteFunctor + * a specify your own memory deletion operation.*/ + struct AttributeDeleteFunctor : public osg::Referenced + { + // see GeoSet.cpp for implemention. + virtual void operator() (GeoSet* gset); + }; + + /** set an alternative AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/ + void setAttributeDeleteFunctor(AttributeDeleteFunctor* adf) { _adf = adf; } + + /** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/ + AttributeDeleteFunctor* getAttributeDeleteFunctor() { return _adf.get(); } + + /** get the current AttributeDeleteFunction to handle attribute arrays attached to this Geoset.*/ + const AttributeDeleteFunctor* getAttributeDeleteFunctor() const { return _adf.get(); } + + /** Statistics collection for each drawable- 26.09.01 */ bool getStats(Statistics &); @@ -302,6 +326,7 @@ class SG_EXPORT GeoSet : public Drawable virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf); + protected: GeoSet(const GeoSet&):Drawable() {} @@ -311,6 +336,8 @@ class SG_EXPORT GeoSet : public Drawable virtual const bool computeBound() const; + ref_ptr _adf; + int _numprims; PrimitiveType _primtype; int _needprimlen; @@ -343,6 +370,7 @@ class SG_EXPORT GeoSet : public Drawable InterleaveArrayType _iaformat; unsigned int _ogliaformat; + int _fast_path; void set_fast_path( void ); diff --git a/src/osg/GeoSet.cpp b/src/osg/GeoSet.cpp index 9286bb6c0..ef50ed83d 100644 --- a/src/osg/GeoSet.cpp +++ b/src/osg/GeoSet.cpp @@ -16,6 +16,11 @@ using namespace osg; GeoSet::GeoSet() { + // we will use the a default delete functor which + // assumes that users have allocated arrays with new only + // and that now sharing of attributes exists between GeoSet's. + _adf = new AttributeDeleteFunctor; + _coords = (Vec3 *)0; _normals = (Vec3 *)0; @@ -50,18 +55,31 @@ GeoSet::GeoSet() } +#define INDEX_ARRAY_DELETE(A) if (A._is_ushort) delete [] A._ptr._ushort; else delete [] A._ptr._uint; + +void GeoSet::AttributeDeleteFunctor::operator() (GeoSet* gset) +{ + // note, delete checks for NULL so want delete NULL pointers. + delete [] gset->getPrimLengths(); + delete [] gset->getCoords(); + INDEX_ARRAY_DELETE(gset->getCoordIndices()) + delete [] gset->getNormals(); + INDEX_ARRAY_DELETE(gset->getNormalIndices()); + delete [] gset->getColors(); + INDEX_ARRAY_DELETE(gset->getColorIndices()); + delete [] gset->getTextureCoords(); + INDEX_ARRAY_DELETE(gset->getTextureIndices()) + // can't delete a void* right now... interleaved arrays needs to be reimplemented with a proper pointer.. + // delete [] gset->getInterleavedArray(); + INDEX_ARRAY_DELETE(gset->getInterleavedIndices()); +} + +#undef INDEX_ARRAY_DELETE GeoSet::~GeoSet() { - // note all coordinates, colors, texture coordinates and normals - // are not currently deleted, ahh!!!! This issue needs to be - // addressed. However, since the data is simple passed in it - // is unclear whether the data is shared, allocated with malloc, - // or new [] so its difficult right now to now how to delete it - // appropriatly. Should data be copied rather than simply copying - // pointers?? Using vector<> could simplify this issue. But then - // would you want to share coords etc? - // Robert Osfield, Decemeber 2000. + // if attached call the adf do delete the memory. + if (_adf.valid()) (*_adf)(this); } diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index d8b52f734..5611949ee 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -94,7 +94,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterOBJ::readNode(const std::string& fil osg_mtl = new osg::StateSet*[obj->nummaterials]; for (i = 0; i < obj->nummaterials; i++) { GLMmaterial* omtl = &(obj->materials[i]); - osg::notify(DEBUG) << "mtl: " << omtl->name << endl; + osg::notify(osg::DEBUG_INFO) << "mtl: " << omtl->name << endl; osg::StateSet* stateset = new osg::StateSet; osg_mtl[i] = stateset;