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.
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 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.
Use the 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.
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.
See also:
SoCpuBufferObject
, SoGLBufferObject
, SoCpuDevice
, SoGLDevice
, SoBufferedShape
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 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 |
getMappedBufferObjectAccessMode()
Returns the access mode used for the buffer mapping.
|
long |
getMappedBufferObjectPosition()
Returns the position in the source buffer mapped in this buffer.
|
long |
getMappedBufferObjectSize()
Returns the size of the mapped area in bytes.
|
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.
|
java.nio.ByteBuffer |
map(SoBufferObject.AccessModes accessMode)
Calls map(accessMode, (long)0, (long)SO_BUFFER_SIZE_ALL).
|
java.nio.ByteBuffer |
map(SoBufferObject.AccessModes accessMode,
long offset)
Calls map(accessMode, offset, (long)SO_BUFFER_SIZE_ALL).
|
java.nio.ByteBuffer |
map(SoBufferObject.AccessModes accessMode,
long offset,
long count)
Map the buffer to a system memory address and allows the mapping of a sub part of the buffer object into CPU memory.
|
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 |
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.
|
boolean |
setSize(long size)
Sets the size in bytes of the buffer object.
|
void |
unlockBuffer()
Unlocks the buffer object.
|
void |
unmap()
Unmaps the buffer from CPU address space.
|
void |
unmap(SoBufferObject bufferObject)
Unmap this buffer from the specified buffer object.
|
getNativeResourceHandle
public static final long SO_BUFFER_SIZE_ALL
public java.nio.ByteBuffer map(SoBufferObject.AccessModes accessMode, long offset)
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode)
public 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 java.nio.ByteBuffer map(SoBufferObject.AccessModes accessMode)
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition)
public void memcpy(SoBufferObject sourceBufferObject, long destOffset, long sourceOffset)
public boolean isDisposable()
SafeDisposable
SafeDisposable.dispose()
on the object.isDisposable
in interface SafeDisposable
true
if the object can be disposed in a safe mannerpublic void memcpy(SoBufferObject sourceBufferObject)
public void memcpy(SoBufferObject sourceBufferObject, long destOffset)
public java.nio.ByteBuffer map(SoBufferObject.AccessModes accessMode, long offset, long count)
unmap()
method must be called before using the buffer.
public void unmap()
public void map(SoBufferObject targetBufferObject, SoBufferObject.AccessModes accessMode, long startPosition, long mappingSize)
A source buffer may be mapped into multiple target buffers. However a target buffer can only be mapped from one source buffer at a time. If a different source buffer is currently mapped into the target buffer, it is automatically unmapped and may be left in an undefined state.
Note: If the current buffer is empty or startPosition is beyond the end of the managed memory, the buffer is not mapped (and an error message is issued in debug builds).
targetBufferObject
- The buffer object which will be the mapped version of this buffer.
accessMode
- The access mode used for the mapping.
startPosition
- Offset (in bytes) in source buffer to map from (default is start of buffer).
mappingSize
- Size (in bytes) from the startPosition, if SO_BUFFER_SIZE_ALL then the whole buffer is mapped.public long getSize()
public void lockBuffer()
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 boolean setSize(long size)
If the requested size is the same as the current size, this method does nothing and returns true. If there is existing memory that is owned by the buffer object, that memory is released. If the requested size is zero, the buffer object is now empty.
size
- The requested size in bytes.
public void unlockBuffer()
lockBuffer()
then it must call unlockBuffer()
to allow other threads to lock the buffer.public void unmap(SoBufferObject bufferObject)
bufferObject
- Buffer to be unmapped.public SoBufferObject.AccessModes getMappedBufferObjectAccessMode()
public SoBufferObject getMappedBufferObject()
public long getMappedBufferObjectSize()
public long getMappedBufferObjectPosition()
public SoBufferObject createInstance()
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 SoDeviceContext getContext()
public void clearInstance()
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com