CPU buffer object class More...
#include <Inventor/devices/SoCpuBufferObject.h>
Public Member Functions | |
SoCpuBufferObject () | |
SoCpuBufferObject (void *buffer, size_t size) | |
void | setBuffer (void *buffer, size_t size) |
virtual SoBufferObject * | createInstance () const |
virtual void | clearInstance () |
This class provides management functions for CPU memory buffers.
By default memory allocations have the maximum possible alignment to allow use with (for example) SSE instructions.
Memory is managed using the new/delete operators. On Microsoft Windows platforms it is possible to use VirtualAlloc/VirtualFree instead by setting OIV_BUFFER_USE_VIRTUAL_ALLOC (see SoPreferences).
See SoBufferObject for general information about buffer objects.
See SoBufferedShape for an example of storing vertices in a CPU buffer.
NOTE:
SoBufferObject classes are reference counted objects (just like nodes, paths, etc). Therefore you cannot create an SoBufferObject on the stack. And to delete an SoBufferObject you must ref and unref the object. The SoRef smart pointer is a safe and convenient way to create buffer objects. See examples in SoBufferObject.
const float vertices[][3] = { 1,0.5,0, 0,1,0, -1,0.5,0, -1,-1,0, 1,-1,0, 1,0,0, -1,0,0, -1,-1.5,0, 1,-1.5,0 }; const int NUM_COORDS = sizeof(vertices) / sizeof(SbVec3f);
Wrap coordinate array in a CPU buffer object:
SoRef<SoCpuBufferObject> vertBuf = new SoCpuBufferObject( (void*)vertices, NUM_COORDS * sizeof(SbVec3f) );
Or allocate memory and copy data into buffer:
SoRef<SoCpuBufferObject> vertBuf = new SoCpuBufferObject(); vertBuf->setSize( NUM_COORDS * sizeof(SbVec3f) ); SbVec3f* vertPtr = (SbVec3f*)vertBuf->map( SoBufferObject::SET ); memcpy( vertPtr, vertices, NUM_COORDS * sizeof(SbVec3f) ); vertBuf->unmap();
unsigned char* data = (unsigned char*)cpuBuffer->map( SoBufferObject::READ_ONLY ); unsigned char value = data[0]; . . . cpuBuffer->unmap();
SoCpuBufferObject::SoCpuBufferObject | ( | ) |
Default constructor.
The contents of the buffer are initially empty.
SoCpuBufferObject::SoCpuBufferObject | ( | void * | buffer, | |
size_t | size | |||
) |
Constructor that takes an existing block of CPU memory.
This memory is owned, and should be freed by, the application.
buffer | Pointer to the buffer to manage. | |
size | Size of buffer in bytes. |
virtual void SoCpuBufferObject::clearInstance | ( | ) | [virtual] |
This function clears the content of the buffer, it frees the memory if the mode was COPY.
Implements SoBufferObject.
virtual SoBufferObject* SoCpuBufferObject::createInstance | ( | ) | const [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.
Implements SoBufferObject.
Reimplemented in SoCpuBufferBitSet.
void SoCpuBufferObject::setBuffer | ( | void * | buffer, | |
size_t | size | |||
) |
Request that the buffer object manage an existing block of memory.
The application still owns this memory and is responsible for releasing the memory (when no SoCpuBufferObjects have a reference on it).
We recommend to use the most aligned memory pointer possible to enable optimized algorithm usage.
NOTE: If another buffer object is currently mapped into another buffer, the other buffer is automatically unmapped and its contents are undefined.