Abstract base class for buffer object management More...
#include <Inventor/devices/SoBufferObject.h>
Public Types | |
enum | AccessMode { READ_ONLY, SET, READ_WRITE } |
Public Member Functions | |
void | lockBuffer () |
void | unlockBuffer () |
virtual bool | setSize (size_t size) |
virtual size_t | getSize () const |
virtual void * | map (AccessMode accessMode, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL) |
virtual void | unmap () |
virtual void | map (SoBufferObject *targetBufferObject, AccessMode accessMode, size_t startPosition=0, size_t mappingSize=SO_BUFFER_SIZE_ALL) |
virtual void | unmap (SoBufferObject *bufferObject) |
virtual void | memcpy (SoBufferObject *sourceBufferObject, size_t destOffset=0, size_t sourceOffset=0, size_t copySize=SO_BUFFER_SIZE_ALL) |
virtual void | memset (void *value, size_t valueSize=1, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL) |
virtual SoBufferObject * | createInstance () const =0 |
virtual void | clearInstance ()=0 |
SoDeviceContext * | getContext () const |
SoBufferObject * | getMappedBufferObject () |
AccessMode | getMappedBufferObjectAccessMode () |
size_t | getMappedBufferObjectPosition () const |
size_t | getMappedBufferObjectSize () const |
Static Public Member Functions | |
static SoCpuBufferObjectCache * | getBufferObjectCache () |
Friends | |
class | SoCpuBufferObject |
This class provides generic functions to manage buffer objects.
There are specific implementations of this class for buffer objects on each type of device:
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
{ SoCpuBufferObject cpuObj; // ILLEGAL . . . } // OR... { SoCpuBufferObject* cpuObj = new SoCpuBufferObject; cpuObj->map(SoBufferObject::READ_ONLY); . . . cpuObj->unmap(); delete cpuObj; // ILLEGAL }
{ SoRef<SoCpuBufferObject> cpuObj = new SoCpuBufferObject; cpuObj->map(SoBufferObject::READ_ONLY); . . . cpuObj->unmap(); } // OR... { SoCpuBufferObject* cpuObj = new SoCpuBufferObject; cpuObj->ref(); cpuObj->map(SoBufferObject::READ_ONLY); . . . cpuObj->unmap(); cpuObj->unref(); }
Allocating memory in a buffer object:
Loading data and retrieving data:
SoCpuBufferObject, SoGpuBufferObject, SoGLBufferObject, SoCpuDevice, SoGLDevice, SoBufferedShape
AnimatedShape, SoBufferedShape, MultiInstancingBufferedShape
This enum provides the possible access modes for a mapped buffer object.
virtual void SoBufferObject::clearInstance | ( | ) | [pure virtual] |
Free the memory allocated by the buffer object.
Implemented in SoCpuBufferObject, SoGLBufferObject, SoGpuBufferObject, and SoInteropBufferObject.
virtual SoBufferObject* SoBufferObject::createInstance | ( | ) | const [pure virtual] |
Create a new buffer with the same properties as the current one.
The new instance will have the same context or device properties, but no memory is allocated.
Implemented in SoCpuBufferObject, SoGLBufferObject, SoGpuBufferObject, SoInteropBufferObject, and SoCpuBufferBitSet.
static SoCpuBufferObjectCache* SoBufferObject::getBufferObjectCache | ( | ) | [static] |
Returns the cache manager object.
This object manages a cache of 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.
SoDeviceContext* SoBufferObject::getContext | ( | ) | const |
Returns the device context where this buffer is valid.
SoBufferObject* SoBufferObject::getMappedBufferObject | ( | ) |
Returns a pointer to the buffer object which is mapped by the actual object.
AccessMode SoBufferObject::getMappedBufferObjectAccessMode | ( | ) |
Returns the access mode used for the buffer mapping.
size_t SoBufferObject::getMappedBufferObjectPosition | ( | ) | const |
Returns the position in the source buffer mapped in this buffer.
size_t SoBufferObject::getMappedBufferObjectSize | ( | ) | const |
Returns the size of the mapped area in bytes.
virtual size_t SoBufferObject::getSize | ( | ) | const [virtual] |
Returns the size, in bytes, of the buffer object.
void SoBufferObject::lockBuffer | ( | ) |
Locks the buffer against concurrent calls from different threads.
This is a blocking call. In other words it will not return immediately if another thread currently has the buffer locked.
virtual void SoBufferObject::map | ( | SoBufferObject * | targetBufferObject, | |
AccessMode | accessMode, | |||
size_t | startPosition = 0 , |
|||
size_t | mappingSize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Maps the current buffer object into the specified buffer object.
This is useful in order to use a buffer in multiple contexts. The default is to map the entire contents of this buffer, but it is also possible to map a subset of this buffer's memory using the startPosition and mappingSize parameters.
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. |
virtual void* SoBufferObject::map | ( | AccessMode | accessMode, | |
size_t | offset = 0 , |
|||
size_t | count = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Map the buffer to a system memory address and allows the mapping of a sub part of the buffer object into CPU memory.
Notes:
Reimplemented in SoGLBufferObject, SoCpuBufferBitSet, SoCpuBufferCompressed, SoCpuBufferFromVolumeReader, and SoCpuBufferUniform.
virtual void SoBufferObject::memcpy | ( | SoBufferObject * | sourceBufferObject, | |
size_t | destOffset = 0 , |
|||
size_t | sourceOffset = 0 , |
|||
size_t | copySize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Copies data from the specified buffer object into this buffer object.
If the size or the offset are not valid an error is reported (SoDebugError). This buffer is not resized, if it is too small 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). |
virtual void SoBufferObject::memset | ( | void * | value, | |
size_t | valueSize = 1 , |
|||
size_t | offset = 0 , |
|||
size_t | count = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
This function sets the contents of (or a portion of) this buffer object to the specified value.
The valueSize parameter provides a way to do a memset with float, short, byte, etc values. The number of bytes set in this buffer object is exactly valueSize*count. The first byte changed in this buffer is given by the offset argument.
value | is a pointer to the value to set in the buffer. | |
valueSize | The size in bytes of the value. Default is 1 byte. | |
offset | The offset in bytes (where to start setting values). Default is 0. | |
count | The number of values to set. Default is number of bytes in buffer. |
EXAMPLE
unsigned char memset_value = 0; buffer->memset( &memset_value );
Reimplemented in SoCpuBufferBitSet, and SoCpuBufferUniform.
virtual bool SoBufferObject::setSize | ( | size_t | size | ) | [virtual] |
Sets the size in bytes of the buffer object.
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. |
Reimplemented in SoGLBufferObject, and SoGpuBufferObject.
void SoBufferObject::unlockBuffer | ( | ) |
Unlocks the buffer object.
If a thread calls lockBuffer() then it must call unlockBuffer() to allow other threads to lock the buffer.
virtual void SoBufferObject::unmap | ( | SoBufferObject * | bufferObject | ) | [virtual] |
Unmap this buffer from the specified buffer object.
In other words, remove the specified target buffer from the list of buffers which this buffer is mapped to. If the access mode supports writing, the specified buffer is sync'd with the current buffer. An error is reported (in debug builds) if the buffer is not mapped to the specified buffer
bufferObject | Buffer to be unmapped. |
virtual void SoBufferObject::unmap | ( | ) | [virtual] |
Unmaps the buffer from CPU address space.
Reimplemented in SoGLBufferObject, SoCpuBufferBitSet, SoCpuBufferCompressed, SoCpuBufferFromVolumeReader, and SoCpuBufferUniform.
friend class SoCpuBufferObject [friend] |