Class SoGpuBufferObject

  • All Implemented Interfaces:
    SafeDisposable

    public class SoGpuBufferObject
    extends SoBufferObject
    GPU buffer object class. This class provides management functions for GPU memory buffers.

    Note: Since Open Inventor 10.4, applications should use SoGPUBufferObject, instead of SoGLBufferObject, in most cases. For example to store vertex data in GPU memory for use with SoBufferedShape or SoVertexShaderParameterBufferObject.

    See SoBufferObject for general information about buffer objects.

    NOTES:

    • Creating a GPU buffer requires a current GPU context (like OpenGL).
    • Modifying the properties of an GPU buffer require a current GPU context.
      This includes mapping and unmapping the buffer (map()/unmap()), allocating memory (setSize()) and copying data into the buffer (e.g. memcpy()).
    • The same instance of SoGpuBufferObject can not be used inside two GPU contexts that are not shared. For example, if an instance of SoBufferedShape contains SoGpuBufferObjects in its fields, this instance can be used in multiple viewers only if their contexts are shared.

    See SoBufferObject for general information about buffer objects.

    See SoBufferedShape for an example of storing vertices in a GPU buffer.

    EXAMPLE

    Load data into a buffer object.

    Create a GPU buffer object and load data from an array in memory:

     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
     };
     
     // Create a GPU buffer and allocate memory
     // Ensure that a context is created and bound before this step !
     // Make sure the window containing the RenderArea is already exposed
     SoGpuBufferObject gpuBuffer = new SoGpuBufferObject( SoGpuBufferObject.BufferAccessFrequencies.STATIC, SoGpuBufferObject.BufferAccessNatures.SHARED );
     gpuBuffer.setSize( vertices.length * Float.SIZE/8 ); // Set the buffer size (allocate memory)
     
     // Copy data into the buffer object
     FloatBuffer vertData = gpuBuffer.map( SoBufferObject.AccessModes.SET ).asFloatBuffer();
         vertData.put(vertices);
     gpuBuffer.unmap();

    EXAMPLE

    Access data stored in a GPU buffer object.

     FloatBuffer data = gpuBuffer.map( SoBufferObject.AccessModes.READ_ONLY ).asFloatBuffer();
     float value = data.get(0);
     value = data.get(1);
         . . .
     gpuBuffer.unmap();

    See Also:
    SoCpuBufferObject NOTE: Class available since Open Inventor 10.0.
    • Constructor Detail

      • SoGpuBufferObject

        public SoGpuBufferObject​(SoGpuBufferObject.BufferAccessFrequencies accessFrequency)
        Calls SoGpuBufferObject(accessFrequency, SoGpuBufferObject.BufferAccessNatures.valueOf( SoGpuBufferObject.BufferAccessNatures.SHARED.getValue() )).
      • SoGpuBufferObject

        public SoGpuBufferObject()
        Calls SoGpuBufferObject(SoGpuBufferObject.BufferAccessFrequencies.valueOf( SoGpuBufferObject.BufferAccessFrequencies.STATIC.getValue() ), SoGpuBufferObject.BufferAccessNatures.valueOf( SoGpuBufferObject.BufferAccessNatures.SHARED.getValue() )).