From c27bf441e226a6f2b59322314f9d55515bd289aa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 6 Oct 2004 20:32:09 +0000 Subject: [PATCH] Improved the osg::Geometry::computeCorrectBindingsAndArraySizes() implemention so that it produce more optimal settings. Changed flt/GeoSetBuilder so that it doensn't merge geometry, as it was merging geometry even when inappropriate. --- src/osg/Geometry.cpp | 220 +++++++++++---------------- src/osgPlugins/flt/GeoSetBuilder.cpp | 16 +- 2 files changed, 103 insertions(+), 133 deletions(-) diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 085d6e000..394f593e0 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -2261,6 +2261,36 @@ bool _verifyBindings(const osg::Geometry& geom, const A& arrayData) 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; @@ -2276,136 +2306,70 @@ void _computeCorrectBindingsAndArraySizes(std::ostream& out, const osg::Geometry <<" reseting "<getNumElements(): - arrayData.array.valid()?arrayData.array->getNumElements():0; - - switch(arrayData.binding) + + if (numElements==numVertices) { - case(osg::Geometry::BIND_OFF): - if (numElements!=0) - { - arrayData.array = 0; - arrayData.indices = 0; - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<1) - { - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<geom.getPrimitiveSetList().size()) - { - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<numVertices) - { - out<<"Warning: in osg::Geometry::computeCorrectBindingsAndArraySizes() "<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 @@ -2454,7 +2418,7 @@ bool Geometry::verifyBindings() const void Geometry::computeCorrectBindingsAndArraySizes() { - if (verifyBindings()) return; + // if (verifyBindings()) return; computeCorrectBindingsAndArraySizes(_normalData,"_normalData"); computeCorrectBindingsAndArraySizes(_colorData,"_colorData"); diff --git a/src/osgPlugins/flt/GeoSetBuilder.cpp b/src/osgPlugins/flt/GeoSetBuilder.cpp index 1600e7ae3..74bd0b045 100644 --- a/src/osgPlugins/flt/GeoSetBuilder.cpp +++ b/src/osgPlugins/flt/GeoSetBuilder.cpp @@ -308,20 +308,24 @@ osg::Geode* GeoSetBuilder::createOsgGeoSets(osg::Geode* geode) itr!=_dynGeoSetList.end(); ++itr) { - DynGeoSet* dgset = itr->get(); - osg::Geometry* geom = dgset->getGeometry(); + DynGeoSet* dgset = itr->get(); + osg::Geometry* geom = dgset->getGeometry(); geode->addDrawable(geom); dgset->addToGeometry(geom); - osg::StateSet* stateset = dgset->getStateSet(); - assert( stateset == geom->getStateSet() ); + osg::StateSet* stateset = dgset->getStateSet(); + assert( stateset == geom->getStateSet() ); } osgUtil::Tesselator tesselator; for(unsigned int i=0;igetNumDrawables();++i) { osg::Geometry* geom = dynamic_cast(geode->getDrawable(i)); - if (geom) tesselator.retesselatePolygons(*geom); + if (geom) + { + geom->computeCorrectBindingsAndArraySizes(); + tesselator.retesselatePolygons(*geom); + } } return geode; @@ -343,6 +347,8 @@ bool GeoSetBuilder::addPrimitive(bool dontMerge) dgset->setBinding(); + dontMerge = true; + if( dontMerge == true) { _dynGeoSetList.push_back(dgset);