public class SoGLBufferObject extends SoBufferObject
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.
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
READ_ONLY, READ_WRITE, SET, 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.
|
java.nio.ByteBuffer |
map(SoBufferObject.AccessModes accessMode)
This function maps the OpenGL buffer memory into CPU memory.
|
java.nio.ByteBuffer |
map(SoBufferObject.AccessModes accessMode,
long offset,
long count)
This function extends the
map(AccessMode) method by allowing the mapping of a sub part of the buffer object into CPU memory. |
void |
map(SoGLBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode)
Calls map(targetBufferObject, accessMode, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoGLBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition)
Calls map(targetBufferObject, accessMode, startPosition, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoGLBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition,
long mappingSize)
Map the current buffer object into the specified GL buffer object.
|
void |
memcpy(SoGLBufferObject sourceBufferObject)
Calls memcpy(sourceBufferObject, (long)0, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoGLBufferObject sourceBufferObject,
long destOffset)
Calls memcpy(sourceBufferObject, destOffset, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoGLBufferObject sourceBufferObject,
long destOffset,
long sourceOffset)
Calls memcpy(sourceBufferObject, destOffset, sourceOffset, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoGLBufferObject sourceBufferObject,
long destOffset,
long sourceOffset,
long copySize)
Copy data from a GL buffer into this buffer.
|
void |
setTarget(SoGLBufferObject.BufferObjectTargets target)
Specify the buffer target, which defines possible usage of the buffer.
|
void |
unbind()
Unbind the buffer.
|
void |
unmap()
Unmaps the buffer using the regular unmap function.
|
void |
unmap(SoGLBufferObject bufferObject)
Unmap the specified GL buffer object.
|
clearInstance, createInstance, dispose, getBufferObjectCache, getContext, getMappedBufferObject, getMappingAccessMode, getMappingSize, getMappingStartPosition, getSize, isDisposable, lockBuffer, map, map, map, map, map, map, memcpy, memcpy, memcpy, memcpy, memcpy, memcpy, memcpy, memcpy, setMappedBufferObject, setMappingAccessMode, setMappingZoneInformation, setSize, unlockBuffer, unmap, unmap
getAddress, getNativeResourceHandle, startInternalThreads, stopInternalThreads
@Deprecated public static final int PIXEL_PACK_BUFFER
SoGLBufferObject.BufferObjectTargets.PIXEL_PACK_BUFFER
instead.@Deprecated public static final int PIXEL_UNPACK_BUFFER
SoGLBufferObject.BufferObjectTargets.PIXEL_UNPACK_BUFFER
instead.@Deprecated public static final int ARRAY_BUFFER
SoGLBufferObject.BufferObjectTargets.ARRAY_BUFFER
instead.@Deprecated public static final int ELEMENT_ARRAY_BUFFER
SoGLBufferObject.BufferObjectTargets.ELEMENT_ARRAY_BUFFER
instead.@Deprecated public static final int SHADER_STORAGE_BUFFER
SoGLBufferObject.BufferObjectTargets.SHADER_STORAGE_BUFFER
instead.@Deprecated public static final int STREAM_DRAW
SoGLBufferObject.Usages.STREAM_DRAW
instead.@Deprecated public static final int STREAM_READ
SoGLBufferObject.Usages.STREAM_READ
instead.@Deprecated public static final int STREAM_COPY
SoGLBufferObject.Usages.STREAM_COPY
instead.@Deprecated public static final int STATIC_DRAW
SoGLBufferObject.Usages.STATIC_DRAW
instead.@Deprecated public static final int STATIC_READ
SoGLBufferObject.Usages.STATIC_READ
instead.@Deprecated public static final int STATIC_COPY
SoGLBufferObject.Usages.STATIC_COPY
instead.@Deprecated public static final int DYNAMIC_DRAW
SoGLBufferObject.Usages.DYNAMIC_DRAW
instead.@Deprecated public static final int DYNAMIC_READ
SoGLBufferObject.Usages.DYNAMIC_READ
instead.@Deprecated public static final int DYNAMIC_COPY
SoGLBufferObject.Usages.DYNAMIC_COPY
instead.public SoGLBufferObject(SoGLBufferObject.Usages usage)
usage
- The intended usage of this buffer.public void memcpy(SoGLBufferObject sourceBufferObject)
public void memcpy(SoGLBufferObject sourceBufferObject, long destOffset)
public void map(SoGLBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode)
public void map(SoGLBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition)
public void memcpy(SoGLBufferObject sourceBufferObject, long destOffset, long sourceOffset)
public SoGLBufferObject.BufferObjectTargets getTarget()
public java.nio.ByteBuffer map(SoBufferObject.AccessModes accessMode, long offset, long count)
map(AccessMode)
method by allowing the mapping of a sub part of the buffer object into CPU memory.
On some systems this method has better performance.
Notes:
unmap()
method must be called before using the buffer for any OpenGL operation, otherwise the operation will produce an error.
public void setTarget(SoGLBufferObject.BufferObjectTargets target)
target
- The new target of the buffer.public void map(SoGLBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition, long mappingSize)
See the general map function for more information.
public java.nio.ByteBuffer map(SoBufferObject.AccessModes accessMode)
Notes:
unmap()
method must be called before using the buffer for any OpenGL operation, including rendering (e.g. SoBufferedShape
), otherwise the operation will produce an OpenGL error.
public void unbind()
SoGLContext
) must be bound before calling this method.
public boolean isValid()
public void unmap()
public void bind()
SoGLContext
) must be bound before calling this method.
public int getId()
public void unmap(SoGLBufferObject bufferObject)
public static boolean isAvailable()
public void memcpy(SoGLBufferObject sourceBufferObject, long destOffset, long sourceOffset, long copySize)
SoGLContext
) must be bound to perform this operation.
This function is a specialized function for speed-up.
See the general memcpy function for more information
Generated on January 23, 2025, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com