From a082b57c3fc137cf31f22d50eb1fe4ca4e2e9932 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 20 Apr 2018 11:42:31 +0100 Subject: [PATCH] Removed usage of the osgUtil::TriStripVisitor is it generates osg::Geometry that perform very poorly when using VBO and VAO's vs GL DisplayLists. With DisplayLists being deprecated in GL and VBO and VAO becoming standard it's best to standardize on using the osgUtil::MeshOptimizers instead of TripStrupVisitor --- examples/osganalysis/osganalysis.cpp | 3 - src/osgPlugins/3ds/ReaderWriter3DS.cpp | 6 -- .../OpenCASCADE/ReaderWriterOpenCASCADE.cpp | 1 - .../OpenCASCADE/ReaderWriterOpenCASCADE.h | 2 - src/osgPlugins/bsp/VBSPGeometry.cpp | 6 +- src/osgPlugins/fbx/fbxRMesh.cpp | 1 - src/osgPlugins/gles/CMakeLists.txt | 2 - src/osgPlugins/gles/OpenGLESGeometryOptimizer | 20 ++-- .../gles/OpenGLESGeometryOptimizer.cpp | 4 +- src/osgPlugins/gles/ReaderWriterGLES.cpp | 26 ++--- src/osgPlugins/gles/TriangleStripVisitor | 35 ------- src/osgPlugins/gles/TriangleStripVisitor.cpp | 98 ------------------- src/osgPlugins/gles/glesUtil | 7 +- src/osgPlugins/obj/ReaderWriterOBJ.cpp | 10 +- src/osgPlugins/stl/ReaderWriterSTL.cpp | 5 +- src/osgUtil/Simplifier.cpp | 5 +- 16 files changed, 24 insertions(+), 207 deletions(-) delete mode 100644 src/osgPlugins/gles/TriangleStripVisitor delete mode 100644 src/osgPlugins/gles/TriangleStripVisitor.cpp diff --git a/examples/osganalysis/osganalysis.cpp b/examples/osganalysis/osganalysis.cpp index 063c410db..37fa01deb 100644 --- a/examples/osganalysis/osganalysis.cpp +++ b/examples/osganalysis/osganalysis.cpp @@ -393,8 +393,6 @@ public: while (arguments.read("--dl")) { modifyDrawableSettings = true; useDisplayLists = true; } while (arguments.read("-s", simplificatioRatio)) {} - while (arguments.read("--tristripper")) { useTriStripVisitor=true; } - while (arguments.read("--no-tristripper")) { useTriStripVisitor=false; } while (arguments.read("--smoother")) { useSmoothingVisitor=true; } while (arguments.read("--no-smoother")) { useSmoothingVisitor=false; } @@ -426,7 +424,6 @@ public: OSG_NOTICE<<"Running simplifier with simplification ratio="<accept(simplifier); } diff --git a/src/osgPlugins/3ds/ReaderWriter3DS.cpp b/src/osgPlugins/3ds/ReaderWriter3DS.cpp index aeae272ad..dfa601b61 100644 --- a/src/osgPlugins/3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/3ds/ReaderWriter3DS.cpp @@ -17,8 +17,6 @@ #include #include -#include - //MIKEC debug only for PrintVisitor #include @@ -1139,10 +1137,6 @@ osg::Drawable* ReaderWriter3DS::ReaderObject::createDrawable(Lib3dsMesh *m,FaceL } else { fillTriangles (*geom, remappedFaces, faceCount * 3); } -#if 0 - osgUtil::TriStripVisitor tsv; - tsv.stripify(*geom); -#endif return geom; } diff --git a/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.cpp b/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.cpp index 7a4612a1c..60de6cb23 100644 --- a/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.cpp +++ b/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.cpp @@ -74,7 +74,6 @@ #include #include -#include #include //#define _LOG_DEBUG_ diff --git a/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.h b/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.h index af08b7499..dd87c9101 100644 --- a/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.h +++ b/src/osgPlugins/OpenCASCADE/ReaderWriterOpenCASCADE.h @@ -47,8 +47,6 @@ #include #include -#include - /// \class ReaderWritterOpenCASCADE /// \brief contains implementation of reading IGES models /// depends on OpenCascade library diff --git a/src/osgPlugins/bsp/VBSPGeometry.cpp b/src/osgPlugins/bsp/VBSPGeometry.cpp index 52fa073e3..23ccf3305 100644 --- a/src/osgPlugins/bsp/VBSPGeometry.cpp +++ b/src/osgPlugins/bsp/VBSPGeometry.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include "VBSPGeometry.h" @@ -653,9 +653,7 @@ ref_ptr VBSPGeometry::createGeometry() // Now, stripify the geode to convert the POLYGON primitives to // triangle strips - osgUtil::TriStripVisitor tsv; - geode->accept(tsv); - tsv.stripify(); + osgUtil::optimizeMesh(geode); } // Now do the same for the displacement surfaces (if any) diff --git a/src/osgPlugins/fbx/fbxRMesh.cpp b/src/osgPlugins/fbx/fbxRMesh.cpp index b02ce30c7..8ba58687a 100644 --- a/src/osgPlugins/fbx/fbxRMesh.cpp +++ b/src/osgPlugins/fbx/fbxRMesh.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/src/osgPlugins/gles/CMakeLists.txt b/src/osgPlugins/gles/CMakeLists.txt index 559b460f0..fbbb36f94 100644 --- a/src/osgPlugins/gles/CMakeLists.txt +++ b/src/osgPlugins/gles/CMakeLists.txt @@ -12,7 +12,6 @@ SET(TARGET_SRC RigAttributesVisitor.cpp TriangleMeshSmoother.cpp TangentSpaceVisitor.cpp - TriangleStripVisitor.cpp IndexMeshVisitor.cpp UnIndexMeshVisitor.cpp) @@ -49,7 +48,6 @@ SET(TARGET_H TangentSpaceVisitor TriangleMeshGraph TriangleMeshSmoother - TriangleStripVisitor UnIndexMeshVisitor WireframeVisitor ) diff --git a/src/osgPlugins/gles/OpenGLESGeometryOptimizer b/src/osgPlugins/gles/OpenGLESGeometryOptimizer index c8bdf58fc..1e4f4b50e 100644 --- a/src/osgPlugins/gles/OpenGLESGeometryOptimizer +++ b/src/osgPlugins/gles/OpenGLESGeometryOptimizer @@ -34,7 +34,6 @@ #include "RemapGeometryVisitor" #include "SmoothNormalVisitor" #include "TangentSpaceVisitor" -#include "TriangleStripVisitor" #include "UnIndexMeshVisitor" #include "WireframeVisitor" @@ -51,14 +50,12 @@ public: OpenGLESGeometryOptimizer() : _mode("all"), _useDrawArray(false), - _disableTriStrip(false), + _disableMeshOptimization(false), _disableMergeTriStrip(false), _disablePreTransform(false), _disableAnimation(false), _disableAnimationCleaning(false), _enableAABBonBone(false), - _triStripCacheSize(16), - _triStripMinSize(2), _generateTangentSpace(false), _tangentUnit(0), _maxIndexValue(65535), @@ -74,14 +71,12 @@ public: void setMode(const std::string& mode) { _mode = mode; } void setUseDrawArray(bool s) { _useDrawArray = s; } - void setDisableTriStrip(bool s) { _disableTriStrip = s; } + void setDisableMeshOptimization(bool s) { _disableMeshOptimization = s; } void setDisableMergeTriStrip(bool s) { _disableMergeTriStrip = s; } void setDisablePreTransform(bool s) { _disablePreTransform = s; } void setDisableAnimation(bool s) { _disableAnimation = s; } void setDisableAnimationCleaning(bool s) { _disableAnimationCleaning = s; } void setEnableAABBonBone(bool s) { _enableAABBonBone = s; } - void setTripStripCacheSize(unsigned int size) { _triStripCacheSize = size; } - void setTripStripMinSize(unsigned int size) { _triStripMinSize = std::max(size, 2); } void setExportNonGeometryDrawables(bool value) { _exportNonGeometryDrawables = value; } void setTexCoordChannelForTangentSpace(int uv) { _tangentUnit = uv; @@ -93,7 +88,7 @@ public: _wireframe = s; if(_wireframe == std::string("outline")) { // no use to build strip if we only want wireframe - setDisableTriStrip(true); + setDisableMeshOptimization(true); } } void setMaxMorphTarget(unsigned int maxMorphTarget) { @@ -193,9 +188,8 @@ protected: node->accept(remapper); } - void makeTriStrip(osg::Node* node) { - TriangleStripVisitor strip(_triStripCacheSize, _triStripMinSize, !_disableMergeTriStrip); - node->accept(strip); + void makeOptimizeMesh(osg::Node* node) { + osgUtil::optimizeMesh(node); } void makeDrawArray(osg::Node* node) { @@ -226,14 +220,12 @@ protected: std::string _mode; bool _useDrawArray; - bool _disableTriStrip; + bool _disableMeshOptimization; bool _disableMergeTriStrip; bool _disablePreTransform; bool _disableAnimation; bool _disableAnimationCleaning; bool _enableAABBonBone; - unsigned int _triStripCacheSize; - unsigned int _triStripMinSize; bool _generateTangentSpace; int _tangentUnit; diff --git a/src/osgPlugins/gles/OpenGLESGeometryOptimizer.cpp b/src/osgPlugins/gles/OpenGLESGeometryOptimizer.cpp index 82b0a2ca1..d68c12222 100644 --- a/src/osgPlugins/gles/OpenGLESGeometryOptimizer.cpp +++ b/src/osgPlugins/gles/OpenGLESGeometryOptimizer.cpp @@ -46,8 +46,8 @@ osg::Node* OpenGLESGeometryOptimizer::optimize(osg::Node& node) { } // strip - if(!_disableTriStrip) { - makeTriStrip(model.get()); + if(!_disableMeshOptimization) { + makeOptimizeMesh(model.get()); } if(_useDrawArray) { diff --git a/src/osgPlugins/gles/ReaderWriterGLES.cpp b/src/osgPlugins/gles/ReaderWriterGLES.cpp index 799601409..363ca42a9 100644 --- a/src/osgPlugins/gles/ReaderWriterGLES.cpp +++ b/src/osgPlugins/gles/ReaderWriterGLES.cpp @@ -40,14 +40,12 @@ public: std::string enableWireframe; bool generateTangentSpace; int tangentSpaceTextureUnit; - bool disableTriStrip; + bool disableMeshOptimization; bool disableMergeTriStrip; bool disablePreTransform; bool disableAnimation; bool disableAnimationCleaning; bool enableAABBonBone; - unsigned int triStripCacheSize; - unsigned int triStripMinSize; bool useDrawArray; bool disableIndex; unsigned int maxIndexValue; @@ -59,14 +57,12 @@ public: enableWireframe = ""; generateTangentSpace = false; tangentSpaceTextureUnit = 0; - disableTriStrip = false; + disableMeshOptimization = false; disableMergeTriStrip = false; disablePreTransform = false; disableAnimation = false; disableAnimationCleaning = false; enableAABBonBone = false; - triStripCacheSize = 16; - triStripMinSize = 2; useDrawArray = false; disableIndex = false; maxIndexValue = 0; @@ -84,10 +80,8 @@ public: supportsOption("enableWireframe[=inline]","create a wireframe geometry for each triangles geometry. The wire geometry will be stored along the solid geometry if 'inline' is specified."); supportsOption("generateTangentSpace","Build tangent space to each geometry"); supportsOption("tangentSpaceTextureUnit=","Specify on which texture unit normal map is"); - supportsOption("triStripCacheSize=","set the cache size when doing tristrip"); - supportsOption("triStripMinSize=","set the minimum accepted length for a strip"); supportsOption("disableMergeTriStrip","disable the merge of all tristrip into one"); - supportsOption("disableTriStrip","disable generation of tristrip"); + supportsOption("disableMeshOptimization","disable mesh optimization"); supportsOption("disablePreTransform","disable pre-transform of geometries after split"); supportsOption("disableAnimation","disable animation support"); supportsOption("disableAnimationCleaning","disable animations/channels cleaning"); @@ -114,9 +108,7 @@ public: optimizer.setMode(options.glesMode); optimizer.setUseDrawArray(options.useDrawArray); - optimizer.setTripStripCacheSize(options.triStripCacheSize); - optimizer.setTripStripMinSize(options.triStripMinSize); - optimizer.setDisableTriStrip(options.disableTriStrip); + optimizer.setDisableMeshOptimization(options.disableMeshOptimization); optimizer.setDisableMergeTriStrip(options.disableMergeTriStrip); optimizer.setDisablePreTransform(options.disablePreTransform); optimizer.setDisableAnimation(options.disableAnimation); @@ -260,9 +252,9 @@ public: { localOptions.enableAABBonBone = true; } - if (pre_equals == "disableTriStrip") + if (pre_equals == "disableMeshOptimization") { - localOptions.disableTriStrip = true; + localOptions.disableMeshOptimization = true; } if (pre_equals == "generateTangentSpace") { @@ -280,12 +272,6 @@ public: if (pre_equals == "tangentSpaceTextureUnit") { localOptions.tangentSpaceTextureUnit = atoi(post_equals.c_str()); } - if (pre_equals == "triStripCacheSize") { - localOptions.triStripCacheSize = atoi(post_equals.c_str()); - } - if (pre_equals == "triStripMinSize") { - localOptions.triStripMinSize = atoi(post_equals.c_str()); - } if (pre_equals == "maxIndexValue") { localOptions.maxIndexValue = atoi(post_equals.c_str()); } diff --git a/src/osgPlugins/gles/TriangleStripVisitor b/src/osgPlugins/gles/TriangleStripVisitor deleted file mode 100644 index e7ac4c315..000000000 --- a/src/osgPlugins/gles/TriangleStripVisitor +++ /dev/null @@ -1,35 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) Cedric Pinson - * - * This application is open source and may be redistributed and/or modified - * freely and without restriction, both in commercial and non commercial - * applications, as long as this copyright notice is maintained. - * - * This application is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * -*/ - -#ifndef TRIANGLE_STRIP_VISITOR_H -#define TRIANGLE_STRIP_VISITOR_H - -#include "GeometryUniqueVisitor" - -class TriangleStripVisitor : public GeometryUniqueVisitor { -public: - TriangleStripVisitor(unsigned int cacheSize, unsigned int minSize, bool merge): - GeometryUniqueVisitor("TriangleStripVisitor"), - _cacheSize(cacheSize), _minSize(minSize), _merge(merge) - {} - - void process(osg::Geometry& geometry); - -protected: - void mergeTrianglesStrip(osg::Geometry& geometry); - - unsigned int _cacheSize; - unsigned int _minSize; - bool _merge; -}; - -#endif diff --git a/src/osgPlugins/gles/TriangleStripVisitor.cpp b/src/osgPlugins/gles/TriangleStripVisitor.cpp deleted file mode 100644 index eb9202b80..000000000 --- a/src/osgPlugins/gles/TriangleStripVisitor.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include "TriangleStripVisitor" - - -void TriangleStripVisitor::process(osg::Geometry& geometry) { - osgUtil::TriStripVisitor tristrip; - tristrip.setCacheSize(_cacheSize); - tristrip.setMinStripSize(_minSize); - tristrip.setIndexMesh(false); - tristrip.stripify(geometry); - - // merge stritrip to one using degenerated triangles as glue - if (_merge) { - mergeTrianglesStrip(geometry); - } -} - - -void TriangleStripVisitor::mergeTrianglesStrip(osg::Geometry& geometry) -{ - int nbtristrip = 0; - int nbtristripVertexes = 0; - - for (unsigned int i = 0; i < geometry.getNumPrimitiveSets(); i++) { - osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i); - osg::DrawElements* de = ps->getDrawElements(); - if (de && de->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP) { - nbtristrip++; - nbtristripVertexes += de->getNumIndices(); - } - } - - if (nbtristrip > 0) { - osg::notify(osg::NOTICE) << "found " << nbtristrip << " tristrip, " - << "total vertexes " << nbtristripVertexes - << " should result to " << nbtristripVertexes + nbtristrip*2 - << " after connection" << std::endl; - - osg::DrawElementsUShort* ndw = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP); - for (unsigned int i = 0 ; i < geometry.getNumPrimitiveSets() ; ++ i) { - osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i); - if (ps && ps->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP) { - osg::DrawElements* de = ps->getDrawElements(); - if (de) { - // if connection needed insert degenerate triangles - if (ndw->getNumIndices() != 0 && ndw->back() != de->getElement(0)) { - // duplicate last vertex - ndw->addElement(ndw->back()); - // insert first vertex of next strip - ndw->addElement(de->getElement(0)); - } - - if (ndw->getNumIndices() % 2 != 0 ) { - // add a dummy vertex to reverse the strip - ndw->addElement(de->getElement(0)); - } - - for (unsigned int j = 0; j < de->getNumIndices(); j++) { - ndw->addElement(de->getElement(j)); - } - } - else if (ps->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) { - // trip strip can generate drawarray of 5 elements we want to merge them too - osg::DrawArrays* da = dynamic_cast (ps); - if (da) - { - // if connection needed insert degenerate triangles - if (ndw->getNumIndices() != 0 && ndw->back() != da->getFirst()) { - // duplicate last vertex - ndw->addElement(ndw->back()); - // insert first vertex of next strip - ndw->addElement(da->getFirst()); - } - - if (ndw->getNumIndices() % 2 != 0 ) { - // add a dummy vertex to reverse the strip - ndw->addElement(da->getFirst()); - } - - for (unsigned int j = 0; j < da->getNumIndices(); j++) { - ndw->addElement(da->getFirst() + j); - } - } - } - } - } - - for (int i = geometry.getNumPrimitiveSets() - 1 ; i >= 0 ; -- i) { - osg::PrimitiveSet* ps = geometry.getPrimitiveSet(i); - // remove null primitive sets and all primitives that have been merged - // (i.e. all TRIANGLE_STRIP DrawElements and DrawArrays) - if (!ps || (ps && ps->getMode() == osg::PrimitiveSet::TRIANGLE_STRIP)) { - geometry.getPrimitiveSetList().erase(geometry.getPrimitiveSetList().begin() + i); - } - } - geometry.getPrimitiveSetList().insert(geometry.getPrimitiveSetList().begin(), ndw); - } -} diff --git a/src/osgPlugins/gles/glesUtil b/src/osgPlugins/gles/glesUtil index 168808532..88f381728 100644 --- a/src/osgPlugins/gles/glesUtil +++ b/src/osgPlugins/gles/glesUtil @@ -159,7 +159,7 @@ namespace glesUtil { }; - // Compact the vertex attribute arrays. Also stolen from TriStripVisitor + // Compact the vertex attribute arrays. class RemapArray : public osg::ArrayVisitor { public: @@ -229,7 +229,7 @@ namespace glesUtil { // Compare vertices in a mesh using all their attributes. The vertices - // are identified by their index. Extracted from TriStripVisitor.cpp + // are identified by their index. struct VertexAttribComparitor : public GeometryArrayGatherer { VertexAttribComparitor(osg::Geometry& geometry) : GeometryArrayGatherer(geometry) @@ -259,8 +259,7 @@ namespace glesUtil { // Move the values in an array to new positions, based on the // remapping table. remapping[i] contains element i's new position, if - // any. Unlike RemapArray in TriStripVisitor, this code doesn't - // assume that elements only move downward in the array. + // any. class Remapper : public osg::ArrayVisitor { public: diff --git a/src/osgPlugins/obj/ReaderWriterOBJ.cpp b/src/osgPlugins/obj/ReaderWriterOBJ.cpp index 823a4eaf7..f958c515c 100644 --- a/src/osgPlugins/obj/ReaderWriterOBJ.cpp +++ b/src/osgPlugins/obj/ReaderWriterOBJ.cpp @@ -42,7 +42,6 @@ #include #include -#include #include #include #include @@ -798,14 +797,7 @@ osg::Node* ReaderWriterOBJ::convertModelToSceneGraph(obj::Model& model, ObjOptio // tri strip polygons to improve graphics peformance if (!localOptions.noTriStripPolygons) { - osgUtil::IndexMeshVisitor imv; - imv.makeMesh(*geometry); - - osgUtil::VertexCacheVisitor vcv; - vcv.optimizeVertices(*geometry); - - osgUtil::VertexAccessOrderVisitor vaov; - vaov.optimizeOrder(*geometry); + osgUtil::optimizeMesh(geometry); } // if no normals present add them. diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index 9e23d1b00..456322ad3 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include #include @@ -182,8 +182,7 @@ private: geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, _numFacets * 3)); if(!_noTriStripPolygons) { - osgUtil::TriStripVisitor tristripper; - tristripper.stripify(*geom); + osgUtil::optimizeMesh(geom); } return geom; diff --git a/src/osgUtil/Simplifier.cpp b/src/osgUtil/Simplifier.cpp index 9d54a2d16..7ab24b693 100644 --- a/src/osgUtil/Simplifier.cpp +++ b/src/osgUtil/Simplifier.cpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include @@ -1802,8 +1802,7 @@ void Simplifier::simplify(osg::Geometry& geometry, const IndexList& protectedPoi if (_triStrip) { - osgUtil::TriStripVisitor stripper; - stripper.stripify(geometry); + osgUtil::optimizeMesh(&geometry); } }