## Optimizer options

- Details
- Category: User Guides
- Published on 17 September 2012
- Written by openscenegraph
- Hits: 3513

#### FLATTEN_STATIC_TRANSFORMS

Flatten Static Transform nodes by applying their transform to the geometry on the leaves of the scene graph, then removing the now redundant transforms. The geometry is now directly placed at the resulting positions.

The "data variance" above the geometry needs to be set to static with "setDataVariance(osg::Object::STATIC)"

Example from osg mailing list:

///before optimization FLATTEN_STATIC_TRANSFORMS ///left out several properties for clarity Group { DataVariance STATIC num_children 1 PositionAttitudeTransform { DataVariance STATIC referenceFrame RELATIVE position 0 0 0 attitude 0 0 0 1 scale 1 5 10 pivotPoint 0 0 0 num_children 1 Geode { DataVariance DYNAMIC num_drawables 1 Geometry { DataVariance DYNAMIC useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 1 { DrawArrays QUADS 0 4 } VertexArray UniqueID Vec3Array_2 VA 4 { 0 -0.5 -0.5 0 0.5 -0.5 0 0.5 0.5 0 -0.5 0.5 } } } } } ///after optimization FLATTEN_STATIC_TRANSFORMS ///left out several properties for clarity Group { DataVariance STATIC num_children 1 Group { DataVariance STATIC num_children 1 Geode { DataVariance DYNAMIC num_drawables 1 Geometry { DataVariance DYNAMIC useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 1 { DrawArrays QUADS 0 4 } VertexArray UniqueID Vec3Array_2 Vec3Array 4 { 0 -2.5 -5 0 2.5 -5 0 2.5 5 0 -2.5 5 } } } } }

#### REMOVE_REDUNDANT_NODES

Removes empty nodes and drawables, such as:

- geodes with 0 drawables
- drawables representing an empty geometry
- groups with 0 children

Removes redundant nodes, such as:

- groups with 1 child
- (world) identity (static) transforms

#### REMOVE_LOADED_PROXY_NODES

Replaces or removes all proxy nodes where the number of children equals the corresponding files in the proxy node. All files are loaded into the scene graph.

If there is information in a ProxyNode that needs to be stored (such as callbacks) the ProxyNode is replaced by a Group. Otherwise the children of the ProxyNode are put under the ProxyNodeâ€™s parents.

#### COMBINE_ADJACENT_LODS

If a group has more than two LODs (PagedLODS are neglected), their ranges and children are put together under a single LOD.

//before optimization COMBINE_ADJACENT_LODS Group { DataVariance DYNAMIC num_children 2 LOD { DataVariance DYNAMIC Radius -1 RangeMode DISTANCE_FROM_EYE_POINT RangeList 1 { 0 1000 } num_children 1 Geode { //left out geode 1 } } } LOD { DataVariance DYNAMIC Radius -1 RangeMode DISTANCE_FROM_EYE_POINT RangeList 1 { 1000 2000 } num_children 1 Geode { //left out geode 2 } } } //after optimization COMBINE_ADJACENT_LODS Group { DataVariance DYNAMIC num_children 1 LOD { DataVariance DYNAMIC name "newLOD" Center 0 0 0 Radius -1 RangeMode DISTANCE_FROM_EYE_POINT RangeList 2 { 0 1000 1000 2000 } num_children 2 Geode { //left out geode 1 } } Geode { //left out geode 2 } } }

#### SHARE_DUPLICATE_STATE

Optimize State in the scene graph by removing duplicate state, replacing it with shared instances, both for StateAttributes and whole StateSets.

The optimizer collects all static statesets from nodes and drawables. Checks all StateSets, StateAttributes and Uniforms for duplicates (checks objects with == operator) and replaces them with the pointer to a unique one.

#### MERGE_GEOMETRY

Collects all the geodes. It combines the drawables of these geodes (that do not share vertex arrays) until they reach a #vertices threshold (default set to 1000) CHECK_GEOMETRY

The optimizer class computeCorrectBindingsAndArraySizes for all drawables. This checks the normal, color, fog, texture and vertex binding for a drawable.

#### SPATIALIZE_GROUPS

Spatialize scene (groups) into a balanced quad/oct tree. It creates an octree if the z-distances are large enough. Improves culling

#### COPY_SHARED_NODES

Copy any shared subgraphs, enabling flattening of static transforms. Optimizer collects all nodes and replaced them with a deep copy of itself.

#### TRISTRIP_GEOMETRY

A tri stripping visitor for converting Geometry surface primitives into tri strips. A tri strip is made of a series of adjacent triangles developed iteratively from one triangle by adding a vertex and sharing two vertices with a triangle already in the strip. The current implemention is based upon Tanguy Fautre's triangulation code, which is implemented in osgUtil::TriStripVisitor. This converts mesh primitives in the Geometries into Tri Strips. It does not convert 2D primitives such as points, lines and linestrips.

#### TESSELATE_GEOMETRY

Tesselate all geodes, to remove POLYGONS.

#### OPTIMIZE_TEXTURE_SETTINGS

Sets the following value for all textures setUnRefImageDataAfterApply(true),

which comes down to the apply() function unreferencing the image data. If enabled, and the image data is only referened by this texture, apply() will delete the image data.

#### MERGE_GEODES

The optimizer merges all duplicate geodes (same address) under a group by adding the drawables of all geodes into the first and putting that one as single geode in the group.

#### FLATTEN_BILLBOARDS

Flatten MatrixTransform/!Billboard pairs. For every billboard, it moves up the scene graph. IF the parent of the billboard is a matrix transform, and IF the parent of that matrix transform is a group, and IF the matrix does not cause translation nor rotation, THEN the matrix transforms will be applied to the drawables of the billboard and the matrix transforms will be replaced by the new billboards.

#### CHECK_GEOMETRY

TODO

#### TEXTURE_ATLAS_BUILDER

Texture Atlas Builder creates a set of textures/images which each contain multiple images. Texture Atlases are used to make it possible to use much wider batching of data.

#### STATIC_OBJECT_DETECTION

Optimize the setting of StateSet and Geometry objects in scene so that they have a STATIC DataVariance when they don't have any callbacks associated with them.

#### FLATTEN_STATIC_TRANSFORMS_DUPLICATING_SHARED_SUBGRAPHS

FlattenStaticTransformsDuplicatingSharedSubgraphsVisitor is similar to FlattenStaticTransformsVisitor in that is designed to remove static transforms from the scene graph, pushing down the transforms to the geometry leaves of the scene graph, but with the difference that any subgraphs that are shared between different transforms of duplicated and flatten individually. This results in more static transforms being removed, but also means that more data is generated, and as a result may not always be the most appropriate flatten visitor to use.

#### INDEX_MESH

INDEX_MESH transforms polygonal geometry into an indexed triangle mesh with shared vertex attributes. Quads, triangle strips, triangle fans, and polygons are replaced by triangles. The result is in the DrawElements form that stores indices into arrays of vertex attributes. This optimization can reduce the storage space of a mesh and collapse several primitive sets into one.

#### VERTEX_POSTTRANSFORM

Optimize the order of triangles in a DrawElements mesh to reduce cache misses in the GPU post-transform cache. This can significantly improve rendering time; see this blog entry for details.

#### VERTEX_PRETRANSFORM

Change the order of vertex attributes to reflect their first use in the triangles of a mesh so that vertices that are used in early triangles come first in the vertex attribute arrays. This optimizes cache misses in the GPU pre-transform cache. This optimization should usually be run together with VERTEX_POSTTRANSFORM.