public class SoBufferedShape extends SoShape
SoBufferObject
objects.
SoBufferedShape
is useful to manage the rendering of large geometry, provide application control over where the data is stored (CPU or GPU) and to integrate rendering with the Open Inventor computing framework (through the SoBufferObject
classes).
SoBufferedShape
provides fields for:
In this sense it is similar to the SoVertexProperty
node, but SoVertexProperty
is just a property node. SoBufferedShape
also does the rendering of the shape. Properties that are not specified are taken from the traversal state (e.g. colors) or computed (e.g. normals).
SoBufferedShape
can render many types of geometric primitives including points, lines, quads and triangles. (A single type must be specified per instance of SoBufferedShape
.) You specify the type of primitive in the SoSFEnum
field shapeType
.
SoBufferedShape
can render multiple primitives of the same type. You can specify the number of vertices (or indices if provided) to use for each primitive in the SoMFInt32
field numVertices
(similar to SoFaceSet
).
You can also use the primitive restart feature to define multiple indexed strip shapes, for example TRIANGLE_STRIP or LINE_STRIP. The end of each primitive is marked by a special index value in the index buffer and this value can be specified in the primitiveRestartValue
field. The behavior is similar to the "-1" value that can be used in Open Inventor indexed shape nodes like SoIndexedFaceSet
, but is implemented on the GPU.
NOTE:
primitiveRestartEnabled
field.
SoShape.isPrimitiveRestartAvailable()
.
The geometry and its attributes must be stored in buffer objects (see SoBufferObject
). The buffer objects can be SoGLBufferObjects stored directly on the graphics board or SoCpuBufferObjects stored in system memory. This allows the application to control what data is stored where.
If lighting is enabled (there is no SoLightModel
node or the model field of the SoLightModel
is set to PHONG) and the normalBuffer
field is not set, then Open Inventor will automatically compute normal vectors, but only in some cases (see Limitations section). Normal generation is affected by the creaseAngle field of the SoShapeHints
node, but only if the vertices are NOT indexed (indexBuffer field is not set). If the vertices are indexed the creaseAngle is forced to PI, creating a smooth surface rendering. If the application needs to render sharp edges on a shape, either compute normal vectors and set the normalBuffer field or do not use the indexBuffer field. It is possible to disable normal generation (if for example the normals are generated by a geometry shader) by setting the useNormalsGenerator
field to false. If no normal vectors are specified or generated, and lighting is enabled, the primitive may not be rendered correctly.
SoBufferedShape
provides fields to describe the content of each buffer, e.g. the data type and number of components in each buffer, as well as how to access the buffers, e.g. the offset into the buffer and "stride" separating data values in the buffer. The default values for offset and stride assume that the vertices, normals, etc are each in a separate buffer. However setting appropriate offset and stride allows, for example, vertices and normals to be interleaved in a single buffer. In this case the same buffer would be set into both the vertexBuffer and normalBuffer fields.
To disable computing the bounding box, which can take a long time with very large geometry, use the SoBBox
node to specify a pre-computed bounding box.
Limitations
SoMaterial
node works as usual. However if there is a color buffer with RGBA values, note that Open Inventor does not currently check the color buffer for transparency (alpha values < 1). So in this case the SoBufferedShape
will not be considered transparent geometry (even if there are alpha values < 1) and may not be rendered correctly. You can force Open Inventor to handle the shape as transparent geometry by putting an SoMaterial
node with non-zero transparency before it in the scene graph.
vertexComponentsCount
field is set to 2 or 3,
primitiveRestartEnabled
field is set to false (default), and
SoShapeHints
) is not used by the normal generator if the vertices are indexed. If the application needs to render sharp edges on a shape, either compute normal vectors and set the normalBuffer field or do not use the indexBuffer field.
SoGetPrimitiveCountAction
: SoGetPrimitiveCountAction
will not be accurate.
SoFaceSet
, SoBufferedShape
does NOT automatically tesselate concave or complex polygons. Such primitives may not be rendered correctly.
SoWriteAction
: SoBufferedShape
can be saved to and restored from a .iv file just like any other Open Inventor node. However, during the read operation any OpenGL buffer objects (SoGLBufferObject
) in the file will be created as CPU buffers (SoCpuBufferObject
) if there is no OpenGL context bound during the read operation.
SoBufferedShape
effectively only supports per-vertex and per-vertex-indexed binding of materials, normals and texture coordinates using the values found in its own buffers.
SoBufferedShape
is currently ignored by the "simplify" actions (SoShapeSimplifyAction
, SoGlobalSimplifyAction
, SoReorganizeAction
).
Example using CPU buffer:
// Result should be similar to SoLineSet example in PG-GettingStarted.pdf. // This example does not show any of the advantages of using SoBufferedShape, // just the simplest possible setup and usage. // Coordinate data float[] vertices = { 1.0f, 0.5f,0.0f, 0.0f, 1.0f,0.0f, -1.0f,0.5f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f, -1.0f,-1.5f,0.0f, 1.0f,-1.5f,0.0f }; int[] numVerts = { 3, 4, 2 }; // Create a CPU buffer object and set its size (allocate memory) SoCpuBufferObject cpuBuffer = new SoCpuBufferObject(); cpuBuffer.setSize( vertices.length * Float.SIZE/8 ); // Copy vertex data into the buffer object FloatBuffer vertData = cpuBuffer.map( SoBufferObject.AccessModes.SET ).asFloatBuffer(); vertData.put(vertices); cpuBuffer.unmap(); // Create a buffered shape to render the geometry SoBufferedShape shape = new SoBufferedShape(); shape.shapeType.setValue( "LINE_STRIP" ); shape.numVertices.setValues( 0, numVerts ); shape.vertexBuffer.setValue( cpuBuffer );
Example using GPU buffer:
// Result should be similar to SoLineSet example in PG-GettingStarted.pdf. // This example does not show any of the advantages of using SoBufferedShape, // just the simplest possible setup and usage. // Coordinate data float[] vertices = { 1.0f, 0.5f,0.0f, 0.0f, 1.0f,0.0f, -1.0f,0.5f,0.0f, -1.0f,-1.0f,0.0f, 1.0f,-1.0f,0.0f, 1.0f,0.0f,0.0f, -1.0f,0.0f,0.0f, -1.0f,-1.5f,0.0f, 1.0f,-1.5f,0.0f }; int[] numVerts = { 3, 4, 2 }; // Create a GPU (OpenGL) buffer and set its size (allocate memory) SoGLContext glContext = new SoGLContext( true ); glContext.bind(); SoGLBufferObject gpuBuffer = new SoGLBufferObject( SoGLBufferObject.Usages.STATIC_DRAW ); gpuBuffer.setTarget( SoGLBufferObject.BufferObjectTargets.ARRAY_BUFFER ); gpuBuffer.setSize( vertices.length * Float.SIZE/8 ); glContext.unbind(); // Copy vertex data into the GPU buffer object FloatBuffer vertData = gpuBuffer.map( SoBufferObject.AccessModes.SET ).asFloatBuffer(); vertData.put(vertices); gpuBuffer.unmap(); // Create a buffered shape to render the geometry SoBufferedShape shape = new SoBufferedShape(); shape.shapeType.setValue( "LINE_STRIP" ); shape.numVertices.setValues( 0, numVerts ); shape.vertexBuffer.setValue( gpuBuffer );
LIMITATIONS: SoBufferedShape
needs a graphic card supporting vertex buffer objects, if not available shape won't be rendered.
File format/default:
BufferedShape {
useNormalsGenerator | true |
shapeType | TRIANGLES |
numVertices | 0 |
vertexBuffer | NULL |
vertexComponentsCount | 3 |
vertexComponentsType | SbDataType.FLOAT |
vertexStride | 0 |
vertexOffset | 0 |
normalBuffer | NULL |
normalComponentsType | SbDataType.FLOAT |
normalStride | 3 * sizeof(float) |
normalOffset | 0 |
indexBuffer | NULL |
indexType | SbDataType.UNSIGNED_INT32 |
indexOffset | 0 |
colorBuffer | NULL |
colorComponentsType | SbDataType.FLOAT |
colorStride | 0 |
colorOffset | 0 |
colorComponentsCount | 3 |
texCoordsBuffer | NULL |
texCoordsComponentsType | SbDataType.FLOAT |
texCoordsStride | 0 |
texCoordsOffset | 0 |
texCoordsComponentsCount | 2 |
primitiveRestartEnabled | false |
primitiveRestartValue | -1 |
Action behavior:
SoGLRenderAction
, SoCallbackAction
, SoBoundingBoxAction
Do the actual rendering / bounding box computation.
See also:
SoCPUBufferObject, SoGLBufferObject
, SoBBox
Modifier and Type | Class and Description |
---|---|
static class |
SoBufferedShape.Types
Type of shape that will be rendered.
|
static class |
SoBufferedShape.Usages
This enum is used to set the
shapeUsage field. |
SoShape.ShapeTypes
SoNode.RenderModes
Inventor.ConstructorCommand
Modifier and Type | Field and Description |
---|---|
SoSFBufferObject |
colorBuffer
Buffer object that contains the (optional) color values.
|
SoSFInt32 |
colorComponentsCount
Number of components in each color value.
|
SoSFEnum<SbDataType.DataTypes> |
colorComponentsType
SbDataType.DataType type for the color values. |
SoSFInt32 |
colorOffset
Offset in bytes to the first color value in the buffer.
|
SoSFInt32 |
colorStride
Stride in bytes between the first component of two consecutive colors.
|
SoSFBufferObject |
indexBuffer
Buffer object that contains the (optional) indices.
|
SoSFInt32 |
indexOffset
Offset in bytes to the first index in the buffer.
|
SoSFEnum<SbDataType.DataTypes> |
indexType
SbDataType.DataType type for the indices. |
SoSFBufferObject |
normalBuffer
Buffer object that contains the (optional) normal vectors.
|
SoSFEnum<SbDataType.DataTypes> |
normalComponentsType
SbDataType.DataType type for the normal vectors. |
SoSFInt32 |
normalOffset
Offset in bytes to the first normal vector in the buffer.
|
SoSFShort |
normalStride
Stride in bytes between the first component of two consecutive normals.
|
SoMFInt32 |
numVertices
Number of vertices/indices to be used for each primitive.
|
SoSFBool |
primitiveRestartEnabled
Enable/disable the primitive restart feature.
|
SoSFInt32 |
primitiveRestartValue
Index value for the primitive restart feature.
|
SoSFEnum<SoBufferedShape.Types> |
shapeType
Shape type to render.
|
SoSFEnum<SoBufferedShape.Usages> |
shapeUsage
Defines the usage of the shape.
|
SoMFBufferObject |
texCoordsBuffer
Buffer objects that contains the (optional) texture coordinates.
|
SoMFInt32 |
texCoordsComponentsCount
Number of components in each texture coordinate.
|
SoMFEnum<SbDataType.DataTypes> |
texCoordsComponentsType
SbDataType.DataType type for the texture coordinates. |
SoMFInt32 |
texCoordsOffset
Offset in bytes to the first texture coordinate in the buffer.
|
SoMFInt32 |
texCoordsStride
Stride in bytes between the first component of two consecutive texture coordinates.
|
SoSFBool |
useNormalsGenerator
Indicates if the node should use the internal normal vector generator if no normals are defined.
|
SoSFBufferObject |
vertexBuffer
Buffer object that contains the vertex data.
|
SoSFShort |
vertexComponentsCount
Number of components in each vertex.
|
SoSFEnum<SbDataType.DataTypes> |
vertexComponentsType
SbDataType.DataType for vertices. |
SoSFInt32 |
vertexOffset
Offset in bytes to the first vertex within the buffer.
|
SoSFShort |
vertexStride
Stride in bytes between the first component of two consecutive vertices.
|
boundingBoxIgnoring
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoBufferedShape()
Default constructor.
|
getShapeType, isPrimitiveRestartAvailable, isPrimitiveRestartAvailable
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
getNativeResourceHandle
public final SoSFEnum<SoBufferedShape.Usages> shapeUsage
STATIC provides the best performance even if we update the buffers on a per frame basis, as long as we are replacing the contents of the buffer using the SET access mode.
This field does not have any effect if the specified buffer objects are SoGLBufferObjects, because the static/dynamic behaviour is set on each buffer object.
. The default value is STATIC.
public final SoSFBool primitiveRestartEnabled
Limitations: Enabling primitive restart disables the normal generator.
public final SoSFInt32 primitiveRestartValue
public final SoSFBool useNormalsGenerator
This mode is only supported for shapes with float coordinates and 3 components per vertex. It is not supported for the points and the lines.
Disabling the normal generator can be useful if the normals are computed in a shader or if the shaders don't need any normal at all.
Normal generation is affected by the creaseAngle field of SoShapeHints
.
public final SoSFEnum<SoBufferedShape.Types> shapeType
public final SoMFInt32 numVertices
public final SoSFBufferObject vertexBuffer
SoCpuBufferObject
or an SoGLBufferObject
with target = ARRAY_BUFFER.public final SoSFShort vertexComponentsCount
public final SoSFEnum<SbDataType.DataTypes> vertexComponentsType
SbDataType.DataType
for vertices.
. Default is SbDataType.FLOAT
.public final SoSFShort vertexStride
Note: When the values are packed (only vertices in the buffer) the value 0 can be used and OpenGL will compute the stride value.
public final SoSFInt32 vertexOffset
public final SoSFBufferObject normalBuffer
SoCpuBufferObject
or an SoGLBufferObject
with target = ARRAY_BUFFER.public final SoSFEnum<SbDataType.DataTypes> normalComponentsType
SbDataType.DataType
type for the normal vectors.
. Default is SbDataType.FLOAT
.public final SoSFShort normalStride
Note: When the values are packed (only normals in the buffer) the value 0 can be used and OpenGL will compute the stride value.
public final SoSFInt32 normalOffset
public final SoSFBufferObject indexBuffer
SoCpuBufferObject
or an SoGLBufferObject
with target = ELEMENT_ARRAY_BUFFER.public final SoSFEnum<SbDataType.DataTypes> indexType
SbDataType.DataType
type for the indices.
. Default is SbDataType.UNSIGNED_INT32
.public final SoSFInt32 indexOffset
public final SoSFBufferObject colorBuffer
SoCpuBufferObject
or an SoGLBufferObject
with target = ARRAY_BUFFER.public final SoSFEnum<SbDataType.DataTypes> colorComponentsType
SbDataType.DataType
type for the color values.
. Default is SbDataType.FLOAT
.public final SoSFInt32 colorStride
Note: When the values are packed (only color values in the buffer) the value 0 can be used and OpenGL will compute the stride value.
public final SoSFInt32 colorOffset
public final SoSFInt32 colorComponentsCount
public final SoMFBufferObject texCoordsBuffer
SoCpuBufferObject
or an SoGLBufferObject
with target = ARRAY_BUFFER.public final SoMFEnum<SbDataType.DataTypes> texCoordsComponentsType
SbDataType.DataType
type for the texture coordinates.
. Default is SbDataType.FLOAT
.public final SoMFInt32 texCoordsStride
Note: When the values are packed (only texture coordinates in the buffer) the value 0 can be used and OpenGL will compute the stride value.
public final SoMFInt32 texCoordsOffset
public final SoMFInt32 texCoordsComponentsCount
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com