public abstract class SoBufferObject extends Inventor implements SafeDisposable
There are specific implementations of this class for buffer objects on each type of device:
SoCpuBufferObject
: A buffer in CPU system memory.
SoGLBufferObject
: A buffer in GPU memory managed through the OpenGL API.
In many cases the abstract SoBufferObject
methods allow the application to handle buffer objects without knowing the specific type of the buffer. This is very convenient when computation is implemented on multiple devices. For example if computation is done using CUDA when available, but using the CPU when a CUDA device is not available.
Since version 8.0, some Open Inventor classes take or return data using an SoBufferObject
(or derived class). For example texture images (see SoSFImage
), geometry data (see SoBufferedShape
) and tiles of volume data (see SoLDMDataAccess
).
Creating a buffer object Before creating a non-CPU buffer object you must bind (then unbind) a valid context for the target device. For example, to create an OpenGL buffer object Use the
See also:
SoGLBufferObject
) you can bind the viewer's context using methods in the view class or you can use the class SoGLContext
. See the example on the SoGLBuffer page. For an existing buffer object you can use the buffer's bind()/unbind() methods or get a valid context to bind using thegetContext() method. Binding this context is necessary before changing buffer properties or calling setSize()
, memcpy()
, memset(), etc.
Allocating memory in a buffer object:
setSize()
method to allocate memory in a buffer object. (Note that you must bind a valid context before calling this method on non-CPU buffer objects.) Generally buffer objects have zero size when created. However some buffer object classes have a constructor that takes an existing block of memory as a parameter. In that case the initial size is non-zero. You must allocate memory before copying data into a buffer object using either the memcpy()
method or a direct reference . Memory is automatically allocated, if necessary, when a buffer object is mapped into another buffer object.
Loading data and retrieving data:
SoCpuBufferObject
, have a constructor that takes an existing block of memory as a parameter. In this case the buffer object is automatically set to the necessary size to contain the specified data. Creating an SoCpuBufferObect that "wraps" the existing data is usually the first step in loading data into a non-CPU buffer using memcpy()
or map()
.
memcpy()
methods copy data into a buffer object from another buffer object. For example to copy data into an OpenGL buffer from a CPU buffer. Before using these methods on a non-CPU buffer object, you must bind (then unbind) a valid context for the target device. The buffer object must be large enough (have enough memory allocated) to hold the data. See the allocating memory topic above.
map()
methods that have a buffer object parameter "map" one buffer object into another, usually to allow the data to be accessed on a different device. When the access mode is READ_ONLY or READ_WRITE, the contents of the source buffer are available through the target buffer object after the map()
call. If necessary, Open Inventor will automatically do an inter-device transfer of the data. When the access mode is SET or READ_WRITE, the contents of the modified target buffer object are available through the source buffer object after the unmap()
call. If necessary, Open Inventor will automatically do an inter-device data transfer.
map()
method that maps the buffer's data into CPU memory and returns a reference. If necessary, Open Inventor will automatically do an inter-device transfer of the data. While the buffer is mapped the application can directly modify its data using the returned reference. If the access mode is SET or READ_WRITE, the modified data will be available through the buffer object after the unmap()
call. If necessary, Open Inventor will automatically do an inter-device data transfer.
SoCpuBufferObject
, SoGLBufferObject
, SoCudaBufferObject, SoOpenCLBufferObject
SoCpuDevice
, SoCudaDevice, SoGLDevice
, SoOpenCLDevice
Modifier and Type | Class and Description |
---|---|
static class |
SoBufferObject.AccessModes
This enum provides the possible access modes for a mapped buffer object.
|
Inventor.ConstructorCommand
Modifier and Type | Field and Description |
---|---|
static int |
READ_ONLY
Deprecated.
Use
SoBufferObject.AccessModes.READ_ONLY instead. |
static int |
READ_WRITE
Deprecated.
Use
SoBufferObject.AccessModes.READ_WRITE instead. |
static int |
SET
Deprecated.
Use
SoBufferObject.AccessModes.SET instead. |
static long |
SO_BUFFER_SIZE_ALL
Used to indicate that we want to use the whole buffer.
|
VERBOSE_LEVEL, ZeroHandle
Modifier and Type | Method and Description |
---|---|
void |
clearInstance()
Free the memory allocated by the buffer object.
|
SoBufferObject |
createInstance()
Create a new buffer with the same properties as the current one.
|
boolean |
dispose()
Explicitly call this method to force object to dispose its unmanaged
resources.
|
static SoCpuBufferObjectCache |
getBufferObjectCache()
Returns the cache manager object.
|
SoDeviceContext |
getContext()
Returns the device context where this buffer is valid.
|
SoBufferObject |
getMappedBufferObject()
Returns a pointer to the buffer object which is mapped by the actual object.
|
SoBufferObject.AccessModes |
getMappingAccessMode()
Returns the access mode used for the buffer mapping.
|
long |
getMappingSize()
Returns the size of the mapped area in bytes.
|
long |
getMappingStartPosition()
Returns the position in the source buffer mapped in this buffer.
|
long |
getSize()
Returns the size, in bytes, of the buffer object.
|
boolean |
isDisposable()
Returns a boolean flag which indicates if it is safe to call
SafeDisposable.dispose() on the object. |
void |
lockBuffer()
Locks the buffer against concurrent calls from different threads.
|
void |
map(SoBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode)
Calls map(targetBufferObject, accessMode, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition)
Calls map(targetBufferObject, accessMode, startPosition, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition,
long mappingSize)
Maps the current buffer object into the specified buffer object.
|
void |
map(SoCpuBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode)
Calls map(targetBufferObject, accessMode, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoCpuBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition)
Calls map(targetBufferObject, accessMode, startPosition, (long)SO_BUFFER_SIZE_ALL).
|
void |
map(SoCpuBufferObject targetBufferObject,
SoBufferObject.AccessModes accessMode,
long startPosition,
long mappingSize)
Maps the current buffer object into the specified CPU buffer object.
|
void |
memcpy(SoBufferObject sourceBufferObject)
Calls memcpy(sourceBufferObject, (long)0, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoBufferObject sourceBufferObject,
long destOffset)
Calls memcpy(sourceBufferObject, destOffset, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoBufferObject sourceBufferObject,
long destOffset,
long sourceOffset)
Calls memcpy(sourceBufferObject, destOffset, sourceOffset, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoBufferObject sourceBufferObject,
long destOffset,
long sourceOffset,
long copySize)
Copies data from the specified buffer object into this buffer object.
|
void |
memcpy(SoCpuBufferObject sourceBufferObject)
Calls memcpy(sourceBufferObject, (long)0, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoCpuBufferObject sourceBufferObject,
long destOffset)
Calls memcpy(sourceBufferObject, destOffset, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoCpuBufferObject sourceBufferObject,
long destOffset,
long sourceOffset)
Calls memcpy(sourceBufferObject, destOffset, sourceOffset, (long)SO_BUFFER_SIZE_ALL).
|
void |
memcpy(SoCpuBufferObject sourceBufferObject,
long destOffset,
long sourceOffset,
long copySize)
Copies data from the specified CPU buffer object into this buffer object.
|
void |
setMappedBufferObject(SoBufferObject bufferObject)
This function is used when the instance of buffer object is used to map a buffer.
|
void |
setMappingAccessMode(SoBufferObject.AccessModes accessMode)
Sets the mapping mode used for the mapping of a buffer object.
|
void |
setMappingZoneInformation(long startPosition,
long size)
Stores information about the mapping in order to know the subset of the data mapped in the buffer.
|
boolean |
setSize(long size)
Sets the size in bytes of the buffer object.
|
void |
unlockBuffer()
Unlocks the buffer object.
|
void |
unmap(SoBufferObject bufferObject)
Remove the specified bufferObject from the list of buffers which map the current buffer.
|
void |
unmap(SoCpuBufferObject bufferObject)
Unmap the specified CPU buffer.
|
getAddress, getNativeResourceHandle, startInternalThreads, stopInternalThreads
public static final long SO_BUFFER_SIZE_ALL
@Deprecated public static final int READ_ONLY
SoBufferObject.AccessModes.READ_ONLY
instead.@Deprecated public static final int SET
SoBufferObject.AccessModes.SET
instead.@Deprecated public static final int READ_WRITE
SoBufferObject.AccessModes.READ_WRITE
instead.public void memcpy(SoCpuBufferObject sourceBufferObject, long destOffset, long sourceOffset)
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode)
public void map(SoCpuBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition)
public boolean isDisposable()
SafeDisposable
SafeDisposable.dispose()
on the object.isDisposable
in interface SafeDisposable
true
if the object can be disposed in a safe mannerpublic boolean dispose()
Inventor
dispose
in interface SafeDisposable
dispose
in class Inventor
true
if this object native resources were successfully
disposed; false
if it was already disposed or no
native resources has been registered for this object.public void memcpy(SoBufferObject sourceBufferObject, long destOffset)
public void memcpy(SoBufferObject sourceBufferObject, long destOffset, long sourceOffset)
public void memcpy(SoCpuBufferObject sourceBufferObject)
public void memcpy(SoBufferObject sourceBufferObject)
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition)
public void map(SoCpuBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode)
public void memcpy(SoCpuBufferObject sourceBufferObject, long destOffset)
public void setMappingZoneInformation(long startPosition, long size)
public SoBufferObject createInstance()
public long getMappingStartPosition()
public void memcpy(SoCpuBufferObject sourceBufferObject, long destOffset, long sourceOffset, long copySize)
See the general memcpy method for more information.
public SoDeviceContext getContext()
public void setMappedBufferObject(SoBufferObject bufferObject)
bufferObject
- The buffer object which is mapped.public SoBufferObject getMappedBufferObject()
public SoBufferObject.AccessModes getMappingAccessMode()
public void clearInstance()
public void setMappingAccessMode(SoBufferObject.AccessModes accessMode)
accessMode
- The accessMode used for the mapping.public void map(SoCpuBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition, long mappingSize)
See the general map method for more information.
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition, long mappingSize)
targetBufferObject
- The buffer object which will be the mapped version of this buffer.
accessMode
- The access mode used for the mapping.
startPosition
- Offset in source buffer to map from (default is start of buffer).
mappingSize
- Number of bytes from the startPosition to map (default is SO_BUFFER_SIZE_ALL meaning the whole buffer is mapped.public void unmap(SoBufferObject bufferObject)
bufferObject
- Buffer to be unmapped.public void unmap(SoCpuBufferObject bufferObject)
See the general unmap method for more information.
public static SoCpuBufferObjectCache getBufferObjectCache()
SoCpuBufferObject
objects. SoBufferObject
creates an instance of this class that is primarily used for the LDM tile cache (see SoLDMGlobalResourceParameters
for more information). The buffer object cache can be accessed using the SoBufferObject
static method getBufferObjectCache. Default size is 50 or the value of OIV_BUFFER_OBJECT_CACHE_SIZE.public long getSize()
public void memcpy(SoBufferObject sourceBufferObject, long destOffset, long sourceOffset, long copySize)
SoDebugError
). This buffer is not resized, if it is too small an error is reported.
Warning : Source and destination overlaping support is implementation dependent, if not supported an error is reported.
sourceBufferObject
- The buffer object to be copied.
destOffset
- The starting offset in the destination buffer object, useful for data subsets.
sourceOffset
- The starting offset in the source buffer object, useful for data subsets.
copySize
- The number of bytes to copy from the source buffer object (SO_BUFFER_SIZE_ALL means all).public long getMappingSize()
public void lockBuffer()
public boolean setSize(long size)
size
- The requested size in bytes.
public void unlockBuffer()
lockBuffer()
then it must call unlockBuffer()
to allow other threads to lock the buffer.Generated on January 23, 2025, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com