public class SoGLBufferObject extends SoInteropBufferObject
NOTES:
SoGLContext
object and binding (then unbinding) it.
setTarget()
), allocating memory (setSize()) and copying data into the buffer (e.g. memcpy()). Mapping a buffer does not require explicitly binding a context.
setTarget()
method must be called before any operation, as long as OpenGL requires the target for that operation.
See SoBufferObject
for general information about buffer objects.
See SoBufferedShape
for an example of storing vertices in an OpenGL buffer.
Load data into a buffer object.
Create a GPU buffer object and load data from an array in memory:
Load data into an existing GPU buffer from a CPU buffer: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 (OpenGL) buffer and 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 ); // Set the buffer size (allocate memory) glContext.unbind(); // Copy data into the buffer object FloatBuffer vertData = gpuBuffer.map( SoBufferObject.AccessModes.SET ).asFloatBuffer(); vertData.put(vertices); gpuBuffer.unmap();
OrSoGLContext ctx = (SoGLContext)gpuBuffer.getContext(); ctx.bind(); gpuBuffer.setSize( cpuBuffer.getSize() ); // Set the buffer size (allocate memory) gpuBuffer.memcpy ( cpuBuffer ); // Copy data into the buffer ctx.unbind();
cpuBuffer.map( gpuBuffer, SoBufferObject.AccessModes.READ_ONLY ); cpuBuffer.unmap();
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:
Modifier and Type | Class and Description |
---|---|
static class |
SoGLBufferObject.BufferObjectTargets
This enum declares the possible targets of the buffer.
|
static class |
SoGLBufferObject.Usages
This enum declares the possible usages of the memory allocated for the buffer.
|
SoBufferObject.AccessModes
Inventor.ConstructorCommand
SO_BUFFER_SIZE_ALL
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoGLBufferObject(SoGLBufferObject.Usages usage)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
Bind the current buffer to the specified target so it's usable by OpenGL operations.
|
int |
getId()
Returns the OpenGL id of the buffer.
|
SoGLBufferObject.BufferObjectTargets |
getTarget()
Returns the current buffer target.
|
static boolean |
isAvailable()
Query if SoGLBufferObjects are available on this system.
|
boolean |
isValid()
Query if the buffer is valid in the current context.
|
void |
setTarget(SoGLBufferObject.BufferObjectTargets target)
Specify the buffer target, which defines possible usage of the buffer.
|
void |
unbind()
Unbind the buffer.
|
clearInstance, createInstance, dispose, getBufferObjectCache, getContext, getMappedBufferObject, getMappedBufferObjectAccessMode, getMappedBufferObjectPosition, getMappedBufferObjectSize, getSize, isDisposable, lockBuffer, map, map, map, map, map, map, memcpy, memcpy, memcpy, memcpy, setSize, unlockBuffer, unmap, unmap
getNativeResourceHandle
public SoGLBufferObject(SoGLBufferObject.Usages usage)
usage
- The intended usage of this buffer.public void unbind()
SoGLContext
) must be bound before calling this method.
public void bind()
SoGLContext
) must be bound before calling this method.
public void setTarget(SoGLBufferObject.BufferObjectTargets target)
target
- The new target of the buffer.public static boolean isAvailable()
public int getId()
public boolean isValid()
public SoGLBufferObject.BufferObjectTargets getTarget()
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com