Class SoGpuBufferObject
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.devices.SoBufferObject
-
- com.openinventor.inventor.devices.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 withSoBufferedShape
orSoVertexShaderParameterBufferObject
.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 ofSoBufferedShape
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();
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoGpuBufferObject.BufferAccessFrequencies
Available values for hints on how frequently the application will be changing the buffer's data.static class
SoGpuBufferObject.BufferAccessNatures
Available values for hints on the nature of the application's access to the buffer.-
Nested classes/interfaces inherited from class com.openinventor.inventor.devices.SoBufferObject
SoBufferObject.AccessModes
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
-
Fields inherited from class com.openinventor.inventor.devices.SoBufferObject
SO_BUFFER_SIZE_ALL
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoGpuBufferObject()
Calls SoGpuBufferObject(SoGpuBufferObject.BufferAccessFrequencies.valueOf( SoGpuBufferObject.BufferAccessFrequencies.STATIC.getValue() ), SoGpuBufferObject.BufferAccessNatures.valueOf( SoGpuBufferObject.BufferAccessNatures.SHARED.getValue() )).SoGpuBufferObject(SoGpuBufferObject.BufferAccessFrequencies accessFrequency)
Calls SoGpuBufferObject(accessFrequency, SoGpuBufferObject.BufferAccessNatures.valueOf( SoGpuBufferObject.BufferAccessNatures.SHARED.getValue() )).SoGpuBufferObject(SoGpuBufferObject.BufferAccessFrequencies accessFrequency, SoGpuBufferObject.BufferAccessNatures accessNature)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SoGpuBufferObject.BufferAccessFrequencies
getAccessFrequency()
Returns the current buffer access frequency hint for this buffer object.SoGpuBufferObject.BufferAccessNatures
getAccessNature()
Returns the current buffer access nature hint for this buffer object.-
Methods inherited from class com.openinventor.inventor.devices.SoBufferObject
clearInstance, createInstance, dispose, getContext, getMappedBufferObject, getMappedBufferObjectAccessMode, getMappedBufferObjectPosition, getMappedBufferObjectSize, getSize, isDisposable, lockBuffer, map, map, map, map, map, map, memcpy, memcpy, memcpy, memcpy, setSize, unlockBuffer, unmap, unmap
-
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
-
-
-
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() )).
-
SoGpuBufferObject
public SoGpuBufferObject(SoGpuBufferObject.BufferAccessFrequencies accessFrequency, SoGpuBufferObject.BufferAccessNatures accessNature)
Constructor.- Parameters:
accessFrequency
- The intended access frequency of this buffer.accessNature
- The intended access nature of this buffer.
-
-
Method Detail
-
getAccessNature
public SoGpuBufferObject.BufferAccessNatures getAccessNature()
Returns the current buffer access nature hint for this buffer object.
-
getAccessFrequency
public SoGpuBufferObject.BufferAccessFrequencies getAccessFrequency()
Returns the current buffer access frequency hint for this buffer object.
-
-