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.
This commit is contained in:
Robert Osfield 2016-07-11 09:52:07 +01:00
parent 51f85f4c94
commit fd0af1d9df
2 changed files with 62 additions and 2 deletions

View File

@ -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

View File

@ -56,7 +56,7 @@ void Optimizer::reset()
{
}
static osg::ApplicationUsageProxy Optimizer_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_OPTIMIZER \"<type> [<type>]\"","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 \"<type> [<type>]\"","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"<<std::endl;
BufferObjectVisitor bov(true, true, true, true, true, false);
node->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<<")"<<std::endl;
geometry.setUseVertexBufferObjects(_valueVertexBufferObject);
}
#if 0
if (_changeVertexArrayObject)
{
OSG_NOTICE<<"geometry.setUseVertexArrayObjects("<<_valueVertexArrayObject<<")"<<std::endl;
geometry.setUseVertexArrayObjects(_valueVertexArrayObject);
}
#endif
if (_changeDisplayList)
{
OSG_NOTICE<<"geometry.setUseDisplayList("<<_valueDisplayList<<")"<<std::endl;
geometry.setUseDisplayList(_valueDisplayList);
}
}