From fd0af1d9dff9b575d71ef09a309aaa2a64759c83 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 11 Jul 2016 09:52:07 +0100 Subject: [PATCH] Added Optimizer::BufferObjectVisitor and associated BUFFER_OBJECT_SETTINGS value to enable it via the OSG_OPTIMZIER env var. The BufferObjectVisitor enbales vertex buffer objects usage on Drawable in the scene graph. --- include/osgUtil/Optimizer | 26 +++++++++++++++++++++++++- src/osgUtil/Optimizer.cpp | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/include/osgUtil/Optimizer b/include/osgUtil/Optimizer index a6ce889ce..75328b933 100644 --- a/include/osgUtil/Optimizer +++ b/include/osgUtil/Optimizer @@ -88,6 +88,7 @@ class OSGUTIL_EXPORT Optimizer INDEX_MESH = (1 << 18), VERTEX_POSTTRANSFORM = (1 << 19), VERTEX_PRETRANSFORM = (1 << 20), + BUFFER_OBJECT_SETTINGS = (1 << 21), DEFAULT_OPTIMIZATIONS = FLATTEN_STATIC_TRANSFORMS | REMOVE_REDUNDANT_NODES | REMOVE_LOADED_PROXY_NODES | @@ -112,7 +113,8 @@ class OSGUTIL_EXPORT Optimizer TRISTRIP_GEOMETRY | OPTIMIZE_TEXTURE_SETTINGS | TEXTURE_ATLAS_BUILDER | - STATIC_OBJECT_DETECTION + STATIC_OBJECT_DETECTION | + BUFFER_OBJECT_SETTINGS }; /** Reset internal data to initial state - the getPermissibleOptionsMap is cleared.*/ @@ -858,6 +860,28 @@ class OSGUTIL_EXPORT Optimizer void applyDrawable(osg::Drawable& drawable); }; + + /** For all geometry apply settings.*/ + class OSGUTIL_EXPORT BufferObjectVisitor : public BaseOptimizerVisitor + { + public: + + BufferObjectVisitor(bool changeVBO, bool valueVBO, + bool changeVertexArrayObject, bool valueVertexArrayObject, + bool changeDisplayList, bool valueDisplayList, + Optimizer* optimizer=0): + BaseOptimizerVisitor(optimizer, BUFFER_OBJECT_SETTINGS), + _changeVertexBufferObject(changeVBO), _valueVertexBufferObject(valueVBO), + _changeVertexArrayObject(changeVertexArrayObject), _valueVertexArrayObject(valueVertexArrayObject), + _changeDisplayList(changeDisplayList), _valueDisplayList(valueDisplayList) {} + + virtual void apply(osg::Geometry& geometry); + + bool _changeVertexBufferObject, _valueVertexBufferObject; + bool _changeVertexArrayObject, _valueVertexArrayObject; + bool _changeDisplayList, _valueDisplayList; + + }; }; inline bool BaseOptimizerVisitor::isOperationPermissibleForObject(const osg::StateSet* object) const diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index 5904d780d..997ac55f2 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -56,7 +56,7 @@ void Optimizer::reset() { } -static osg::ApplicationUsageProxy Optimizer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_OPTIMIZER \" []\"","OFF | DEFAULT | FLATTEN_STATIC_TRANSFORMS | FLATTEN_STATIC_TRANSFORMS_DUPLICATING_SHARED_SUBGRAPHS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | SHARE_DUPLICATE_STATE | MERGE_GEOMETRY | MERGE_GEODES | SPATIALIZE_GROUPS | COPY_SHARED_NODES | TRISTRIP_GEOMETRY | OPTIMIZE_TEXTURE_SETTINGS | REMOVE_LOADED_PROXY_NODES | TESSELLATE_GEOMETRY | CHECK_GEOMETRY | FLATTEN_BILLBOARDS | TEXTURE_ATLAS_BUILDER | STATIC_OBJECT_DETECTION | INDEX_MESH | VERTEX_POSTTRANSFORM | VERTEX_PRETRANSFORM"); +static osg::ApplicationUsageProxy Optimizer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_OPTIMIZER \" []\"","OFF | DEFAULT | FLATTEN_STATIC_TRANSFORMS | FLATTEN_STATIC_TRANSFORMS_DUPLICATING_SHARED_SUBGRAPHS | REMOVE_REDUNDANT_NODES | COMBINE_ADJACENT_LODS | SHARE_DUPLICATE_STATE | MERGE_GEOMETRY | MERGE_GEODES | SPATIALIZE_GROUPS | COPY_SHARED_NODES | TRISTRIP_GEOMETRY | OPTIMIZE_TEXTURE_SETTINGS | REMOVE_LOADED_PROXY_NODES | TESSELLATE_GEOMETRY | CHECK_GEOMETRY | FLATTEN_BILLBOARDS | TEXTURE_ATLAS_BUILDER | STATIC_OBJECT_DETECTION | INDEX_MESH | VERTEX_POSTTRANSFORM | VERTEX_PRETRANSFORM | BUFFER_OBJECT_SETTINGS"); void Optimizer::optimize(osg::Node* node) { @@ -136,6 +136,8 @@ void Optimizer::optimize(osg::Node* node) if(str.find("~VERTEX_PRETRANSFORM")!=std::string::npos) options ^= VERTEX_PRETRANSFORM; else if(str.find("VERTEX_PRETRANSFORM")!=std::string::npos) options |= VERTEX_PRETRANSFORM; + if(str.find("~BUFFER_OBJECT_SETTINGS")!=std::string::npos) options ^= BUFFER_OBJECT_SETTINGS; + else if(str.find("BUFFER_OBJECT_SETTINGS")!=std::string::npos) options |= BUFFER_OBJECT_SETTINGS; } else { @@ -382,6 +384,13 @@ void Optimizer::optimize(osg::Node* node, unsigned int options) vaov.optimizeOrder(); } + if (options & BUFFER_OBJECT_SETTINGS) + { + OSG_INFO<<"Optimizer::optimize() doing BUFFER_OBJECT_SETTINGS"<accept(bov); + } + if (osg::getNotifyLevel()>=osg::INFO) { stats.reset(); @@ -4763,3 +4772,30 @@ void Optimizer::FlattenStaticTransformsDuplicatingSharedSubgraphsVisitor::transf +//////////////////////////////////////////////////////////////////////////////////////////// +// +// Set the attributes of BufferObjects up. +// + +void Optimizer::BufferObjectVisitor::apply(osg::Geometry& geometry) +{ + if (!isOperationPermissibleForObject(&geometry)) return; + + if (_changeVertexBufferObject) + { + OSG_NOTICE<<"geometry.setUseVertexBufferObjects("<<_valueVertexBufferObject<<")"<