30.5. Optimizing for Large Amounts of Data

FEI has added new methods to the multiple field classes, for example SoMFVec3f( C++ | Java | .NET ), to allow application data to be assigned to the field without making a copy of the data. This enhancement is of particular benefit to programs that handle large amounts of data.

There are two ways to pass arguments:

The example below shows a typical use of the pass-by-reference feature. It is extracted from a sample program ($OIVHOME/src/Inventor/examples/Features/NonDuplicateMField). This example displays the pointer values of the original data (vertices) and of the internal multiple-field data to show that they are the same.


Multiple field classes that support the pass-by-reference enhancement are: SoMFBool( C++ | Java | .NET ) ,SoMFColor( C++ | Java | .NET ) ,SoMFFloat( C++ | Java | .NET ) ,SoMFInt32( C++ | Java | .NET ) ,SoMFUInt32( C++ | Java | .NET ) ,SoMFShort( C++ | Java | .NET ) ,SoMFUShort( C++ | Java | .NET ) ,SoMFVec2f( C++ | Java | .NET ) ,SoMFVec3f( C++ | Java | .NET ) ,and SoMFVec4f( C++ | Java | .NET ).

This section shows how to add pass-by-reference methods to a new multiple field class. You will only need to know this if you are writing a custom class.

First, add the following macro to the multiple field class definition to declare the pass-by-reference methods and variables:

SO_MFIELD_SETVALUESPOINTER_HEADER(<storage type>);

where <storage type> is the primitive type.

The following example shows the beginning of the SoMFVec4f( C++ | Java | .NET ) class declaration. The primitive type is float.


Second, add the following macro to the multiple field class source to define the methods that are declared in SO_MFIELD_SETVALUESPOINTER_HEADER:

SO_MFIELD_SETVALUESPOINTER_SOURCE (<field name>, <basic type>, <storage type>);

where <field name> is the field class name, <basic type> is field value type, and <storage type> is the primitive type. The following example shows the line added to SoMFVec4f( C++ | Java | .NET ) to enable the pass-by-reference enhancement.


If the geometry or the appearance of some shapes in your scene graph is frequently modified, for example, to do animation, these shapes will be not cached. This means that at each modification, all vertices, normals, colors, and texture coordinates to render these shapes will be sent from main memory to the graphics board. With large models, this data transfer can be be a performance bottleneck.

Vertex Buffer Objects (VBOs), which are a standard feature of OpenGL 1.5 and an extension feature (ARB_vertex_buffer_object) in previous OpenGL versions, provide a mechanism to store certain kinds of data in high performance memory on the graphics board. Open Inventor provides access to this OpenGL feature through the field SoShapeHints::useVBO . Setting this field to TRUE allows subsequent indexed shapes (SoIndexedFaceSet( C++ | Java | .NET )and SoIndexedTriangleStripSet( C++ | Java | .NET ) )) to use VBO to speed up rendering.

When VBO usage is allowed, a VBO is created for each data array (indices, vertices, normals, colors, texture coords...). When a change to one of the data arrays is detected after the first rendering (for instance, the color values changed), the corresponding VBO is updated on the hardware, but the other buffers (for instance, vertices, texture coords...) are not changed.

[Warning]

If this OpenGL feature is not available, setting the useVBO field to TRUE has no effect.

An example of use is available in $OIVHOME/src/Inventor/examples/Features/VBO. This example allows you to turn VBO usage on and off so that you can see its effect on performance.