Clean up up osg::Geometry, removing long deprecated support for array indices and BIND_PER_PRIMITIVE binding that forced OpenGL slow paths. osg::Geometry is now smaller and only supports OpenGL fasts paths.

New methods osg::Geometry::containsDeprecatedData() and osg::Geometry::fixDeprecatedData() provide a means for converting geometries that still use the array indices and BIND_PER_PRIMITIVE across to complient
versions.

Cleaned up the rest of the OSG where use of array indices and BIND_PER_PRIMITIVE were accessed or used.
This commit is contained in:
Robert Osfield
2013-06-18 11:18:28 +00:00
parent 05b72e9b4c
commit 7d40c7258f
35 changed files with 1379 additions and 2880 deletions

View File

@@ -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"<<std::endl;
_geometry->copyToAndOptimize(*_geometry);
}
unsigned int numVertices = geometry->getVertexArray()->getNumElements();
_originalPointList.resize(numVertices);

View File

@@ -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"<<std::endl;
geom.copyToAndOptimize(geom);
}
// compute duplicate vertices
typedef std::vector<unsigned int> IndexList;
unsigned int numVertices = geom.getVertexArray()->getNumElements();
IndexList indices(numVertices);

View File

@@ -50,6 +50,7 @@
using namespace osgUtil;
// #define GEOMETRYDEPRECATED
void Optimizer::reset()
{
@@ -1684,33 +1685,18 @@ struct LessGeometry
if (lhs->getStateSet()<rhs->getStateSet()) return true;
if (rhs->getStateSet()<lhs->getStateSet()) return false;
if (rhs->getVertexIndices()) { if (!lhs->getVertexIndices()) return true; }
else if (lhs->getVertexIndices()) return false;
if (lhs->getNormalBinding()<rhs->getNormalBinding()) return true;
if (rhs->getNormalBinding()<lhs->getNormalBinding()) return false;
if (rhs->getNormalIndices()) { if (!lhs->getNormalIndices()) return true; }
else if (lhs->getNormalIndices()) return false;
if (lhs->getColorBinding()<rhs->getColorBinding()) return true;
if (rhs->getColorBinding()<lhs->getColorBinding()) return false;
if (rhs->getColorIndices()) { if (!lhs->getColorIndices()) return true; }
else if (lhs->getColorIndices()) return false;
if (lhs->getSecondaryColorBinding()<rhs->getSecondaryColorBinding()) return true;
if (rhs->getSecondaryColorBinding()<lhs->getSecondaryColorBinding()) return false;
if (rhs->getSecondaryColorIndices()) { if (!lhs->getSecondaryColorIndices()) return true; }
else if (lhs->getSecondaryColorIndices()) return false;
if (lhs->getFogCoordBinding()<rhs->getFogCoordBinding()) return true;
if (rhs->getFogCoordBinding()<lhs->getFogCoordBinding()) return false;
if (rhs->getFogCoordIndices()) { if (!lhs->getFogCoordIndices()) return true; }
else if (lhs->getFogCoordIndices()) return false;
if (lhs->getNumTexCoordArrays()<rhs->getNumTexCoordArrays()) return true;
if (rhs->getNumTexCoordArrays()<lhs->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;i<lhs->getNumVertexAttribArrays();++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;i<geode.getNumDrawables();++i)
@@ -1843,9 +1827,9 @@ void Optimizer::MakeFastGeometryVisitor::checkGeode(osg::Geode& geode)
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
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." <<std::endl;
}
}
else if (rhs.getVertexIndices())
{
base = 0;
lhs.setVertexIndices(rhs.getVertexIndices());
}
unsigned int nbase = lhs.getNormalArray() ? lhs.getNormalArray()->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." <<std::endl;
}
}
else if (rhs.getNormalIndices())
{
// this assignment makes the assumption that lhs.NormalArray is empty as well and NormalIndices
lhs.setNormalIndices(rhs.getNormalIndices());
}
unsigned int cbase = lhs.getColorArray() ? lhs.getColorArray()->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." <<std::endl;
}
}
else if (rhs.getColorIndices())
{
// this assignment makes the assumption that lhs.ColorArray is empty as well and ColorIndices
lhs.setColorIndices(rhs.getColorIndices());
}
unsigned int scbase = lhs.getSecondaryColorArray() ? lhs.getSecondaryColorArray()->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." <<std::endl;
}
}
else if (rhs.getSecondaryColorIndices())
{
// this assignment makes the assumption that lhs.SecondaryColorArray is empty as well and SecondaryColorIndices
lhs.setSecondaryColorIndices(rhs.getSecondaryColorIndices());
}
unsigned int fcbase = lhs.getFogCoordArray() ? lhs.getFogCoordArray()->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." <<std::endl;
}
}
else if (rhs.getFogCoordIndices())
{
// this assignment makes the assumption that lhs.FogCoordArray is empty as well and FogCoordIndices
lhs.setFogCoordIndices(rhs.getFogCoordIndices());
}
unsigned int unit;
for(unit=0;unit<lhs.getNumTexCoordArrays();++unit)
{
unsigned int tcbase = lhs.getTexCoordArray(unit) ? lhs.getTexCoordArray(unit)->getNumElements() : 0;
if (!merger.merge(lhs.getTexCoordArray(unit),rhs.getTexCoordArray(unit)))
{
OSG_DEBUG << "MergeGeometry: tex coord array not merged. Some data may be lost." <<std::endl;
}
if (lhs.getTexCoordIndices(unit) && rhs.getTexCoordIndices(unit))
{
if (!merger.merge(lhs.getTexCoordIndices(unit),rhs.getTexCoordIndices(unit),tcbase))
{
OSG_DEBUG << "MergeGeometry: tex coord indices not merged. Some data may be lost." <<std::endl;
}
}
}
for(unit=0;unit<lhs.getNumVertexAttribArrays();++unit)
{
unsigned int vabase = lhs.getVertexAttribArray(unit) ? lhs.getVertexAttribArray(unit)->getNumElements() : 0;
if (!merger.merge(lhs.getVertexAttribArray(unit),rhs.getVertexAttribArray(unit)))
{
OSG_DEBUG << "MergeGeometry: vertex attrib array not merged. Some data may be lost." <<std::endl;
}
if (lhs.getVertexAttribIndices(unit) && rhs.getVertexAttribIndices(unit))
{
if (!merger.merge(lhs.getVertexAttribIndices(unit),rhs.getVertexAttribIndices(unit),vabase))
{
OSG_DEBUG << "MergeGeometry: vertex attrib indices not merged. Some data may be lost." <<std::endl;
}
}
}

View File

@@ -543,8 +543,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())
@@ -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

View File

@@ -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"<<std::endl;
_geometry->copyToAndOptimize(*_geometry);
}
// check to see if vertex attributes indices exists, if so expand them to remove them
if (_geometry->containsSharedArrays())
{

View File

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

View File

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

View File

@@ -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 &copy, const osg::CopyOp &copyop)
@@ -23,14 +26,6 @@ TangentSpaceGenerator::TangentSpaceGenerator(const TangentSpaceGenerator &copy,
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"<<std::endl;
geo->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;i<index_count;i++) {
indices_->push_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; i<attrib_count; ++i) {
osg::Vec4 &vT = (*T_)[i];
osg::Vec4 &vB = (*B_)[i];

View File

@@ -182,20 +182,6 @@ void Tessellator::retessellatePolygons(osg::Geometry &geom)
if (!vertices || vertices->empty() || 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;unit<geom.getNumTexCoordArrays();++unit)
{
if (geom.getTexCoordIndices(unit)) return;
}
if (_ttype==TESS_TYPE_POLYGONS || _ttype==TESS_TYPE_DRAWABLE) _numberVerts=0; // 09.04.04 GWM reset Tessellator
// the reset is needed by the flt loader which reuses a Tessellator for triangulating polygons.
// as such it might be reset by other loaders/developers in future.
@@ -470,14 +456,14 @@ void Tessellator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &ver
arrays.push_back(geom.getFogCoordArray());
}
osg::Geometry::ArrayDataList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayDataList::iterator tcalItr=tcal.begin();
osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin();
tcalItr!=tcal.end();
++tcalItr)
{
if (tcalItr->array.valid())
if (tcalItr->valid())
{
arrays.push_back(tcalItr->array.get());
arrays.push_back(tcalItr->get());
}
}

View File

@@ -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"<<std::endl;
geom.copyToAndOptimize(geom);
}
// check for the existence of surface primitives
unsigned int numSurfacePrimitives = 0;
unsigned int numNonSurfacePrimitives = 0;