OpenGL buffer object class. More...
#include <Inventor/devices/SoGLBufferObject.h>
Public Types | |
enum | BufferObjectTarget { PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, ARRAY_BUFFER, ELEMENT_ARRAY_BUFFER, SHADER_STORAGE_BUFFER } |
enum | Usage { STREAM_DRAW, STREAM_READ, STREAM_COPY, STATIC_DRAW, STATIC_READ, STATIC_COPY, DYNAMIC_DRAW, DYNAMIC_READ, DYNAMIC_COPY } |
Public Member Functions | |
SoGLBufferObject (Usage usage) | |
void | setTarget (BufferObjectTarget target) |
BufferObjectTarget | getTarget () const |
virtual bool | setSize (size_t size) |
virtual void | map (SoBufferObject *targetBufferObject, AccessMode accessMode, size_t startPosition=0, size_t mappingSize=SO_BUFFER_SIZE_ALL) |
virtual void | map (SoGLBufferObject *targetBufferObject, AccessMode accessMode, size_t startPosition=0, size_t mappingSize=SO_BUFFER_SIZE_ALL) |
virtual void | map (SoCpuBufferObject *targetBufferObject, AccessMode accessMode, size_t startPosition=0, size_t mappingSize=SO_BUFFER_SIZE_ALL) |
virtual void | unmap (SoBufferObject *bufferObject) |
virtual void | unmap (SoCpuBufferObject *bufferObject) |
virtual void | unmap (SoGLBufferObject *bufferObject) |
void | memcpy (SoBufferObject *sourceBufferObject, size_t destOffset=0, size_t sourceOffset=0, size_t copySize=SO_BUFFER_SIZE_ALL) |
void | memcpy (SoGLBufferObject *sourceBufferObject, size_t destOffset=0, size_t sourceOffset=0, size_t copySize=SO_BUFFER_SIZE_ALL) |
void | memcpy (SoCpuBufferObject *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) |
void | bind () |
void | unbind () |
void * | map (AccessMode accessMode) |
void * | map (AccessMode accessMode, size_t offset, size_t count) |
void | unmap () |
bool | isValid () |
GLuint | getId () const |
virtual SoBufferObject * | createInstance () const |
virtual void | clearInstance () |
Static Public Member Functions | |
static bool | isAvailable () |
Friends | |
class | SoCpuBufferObject |
This class provides management functions for OpenGL memory buffers.
NOTES:
See SoBufferObject for general information about buffer objects.
See SoBufferedShape for an example of storing vertices in an OpenGL buffer.
Create a GPU buffer object and load data from an array in memory:
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> cpuBuffer = new SoCpuBufferObject( (void*)coords, NUM_COORDS * sizeof(SbVec3f) ); // Create a GPU (OpenGL) buffer and load data from CPU buffer SoGLContext* glContext = new SoGLContext(true); glContext->bind(); SoRef<SoGLBufferObject> gpuBuffer = new SoGLBufferObject( SoGLBufferObject::STATIC_DRAW ); gpuBuffer->setTarget( SoGLBufferObject::ARRAY_BUFFER ); gpuBuffer->setSize ( cpuBuffer->getSize() ); // Set the buffer size (allocate memory) gpuBuffer->memcpy ( cpuBuffer.ptr() ); // Copy data into the buffer glContext->unbind(); glContext->unref(); // See ref counting rules for SoGLContext cpuBuffer->unref(); // Clean up this buffer
Load data into an existing GPU buffer from a CPU buffer:
SoGLContext* ctx = (SoGLContext*)gpuBuffer->getContext(); ctx->bind(); gpuBuffer->setSize( cpuBuffer->getSize() ); // Set the buffer size (allocate memory) gpuBuffer->memcpy ( cpuBuffer.ptr() ); // Copy data into the buffer ctx->unbind();
Or
cpuBuffer->map( gpuBuffer.ptr(), SoBufferObject::READ_ONLY ); cpuBuffer->unmap();
float* data = (float*)gpuBuffer->map( SoBufferObject::READ_ONLY ); float value = data[0]; value = data[1]; . . . gpuBuffer->unmap();
BufferedShapePicking, GPUGeometry, InterleavedVertexAttribFeedback, SimpleVertexAttribFeedback, VertexAttribFeedback, SimpleCUDAKernel, SimpleOpenCLKernel, ComputeSlice, CudaMarchingCubes
This enum declares the possible targets of the buffer.
This enum declares the possible usages of the memory allocated for the buffer.
This is a hint to the OpenGL driver implementation as to how a buffer object's data store will be accessed. This enables the OpenGL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store. usage can be broken down into two parts: first, the frequency of access (modification and usage - STATIC, STREAM, DYNAMIC), and second, the nature of that access - DRAW, COPY, READ.
SoGLBufferObject::SoGLBufferObject | ( | Usage | usage | ) |
Constructor.
usage | The intended usage of this buffer. Use enum Usage |
void SoGLBufferObject::bind | ( | ) |
Bind the current buffer to the specified target so it's usable by OpenGL operations.
Notes:
virtual void SoGLBufferObject::clearInstance | ( | ) | [virtual] |
Free the memory allocated in the buffer object.
Notes:
Implements SoBufferObject.
virtual SoBufferObject* SoGLBufferObject::createInstance | ( | ) | const [virtual] |
Create a new buffer with the same properties as the current one.
The new instance will have the same context and device properties, but no memory is allocated so the new buffer is initially invalid.
Implements SoBufferObject.
GLuint SoGLBufferObject::getId | ( | ) | const |
Returns the OpenGL id of the buffer.
BufferObjectTarget SoGLBufferObject::getTarget | ( | ) | const |
Returns the current buffer target.
static bool SoGLBufferObject::isAvailable | ( | ) | [static] |
Query if SoGLBufferObjects are available on this system.
bool SoGLBufferObject::isValid | ( | ) |
Query if the buffer is valid in the current context.
Notes:
void* SoGLBufferObject::map | ( | AccessMode | accessMode, | |
size_t | offset, | |||
size_t | count | |||
) |
This function extends the 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:
void* SoGLBufferObject::map | ( | AccessMode | accessMode | ) |
This function maps the OpenGL buffer memory into CPU memory.
So the returned pointer is usable as a regular pointer. See the example code in the class description.
Notes:
virtual void SoGLBufferObject::map | ( | SoCpuBufferObject * | targetBufferObject, | |
AccessMode | accessMode, | |||
size_t | startPosition = 0 , |
|||
size_t | mappingSize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Map the current buffer object into the specified CPU buffer object.
It is defined just to speed up the call when the type of the object is known.
See the general map function for more information.
Implements SoBufferObject.
virtual void SoGLBufferObject::map | ( | SoGLBufferObject * | targetBufferObject, | |
AccessMode | accessMode, | |||
size_t | startPosition = 0 , |
|||
size_t | mappingSize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Map the current buffer object into the specified GL buffer object.
It is defined just to speed up the call when the type of the object is known.
See the general map function for more information.
Implements SoBufferObject.
virtual void SoGLBufferObject::map | ( | SoBufferObject * | targetBufferObject, | |
AccessMode | accessMode, | |||
size_t | startPosition = 0 , |
|||
size_t | mappingSize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Map the current buffer object into the specified buffer object.
targetBufferObject | The buffer object which will be the mapped version of this buffer. | |
accessMode | The access mode used for the mapping. Use enum AccessMode | |
startPosition | offset in source buffer to map from (default is start of buffer). | |
mappingSize | size from the startPosition, if SO_BUFFER_SIZE_ALL then the whole buffer is mapped. |
void SoGLBufferObject::memcpy | ( | SoCpuBufferObject * | sourceBufferObject, | |
size_t | destOffset = 0 , |
|||
size_t | sourceOffset = 0 , |
|||
size_t | copySize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Copy data from a CPU buffer into this buffer.
Notes:
This function is a specialized function for speed-up.
See the general memcpy function for more information
Implements SoBufferObject.
void SoGLBufferObject::memcpy | ( | SoGLBufferObject * | sourceBufferObject, | |
size_t | destOffset = 0 , |
|||
size_t | sourceOffset = 0 , |
|||
size_t | copySize = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Copy data from a GL buffer into this buffer.
Notes:
This function is a specialized function for speed-up.
See the general memcpy function for more information
Implements SoBufferObject.
void SoGLBufferObject::memcpy | ( | SoBufferObject * | sourceBufferObject, | |
size_t | destOffset = 0 , |
|||
size_t | sourceOffset = 0 , |
|||
size_t | copySize = SO_BUFFER_SIZE_ALL | |||
) |
Copy data from any SoBufferObject into this buffer.
Notes:
sourceBufferObject | The source buffer object which contains the data to copy. | |
destOffset | The starting offset in the source buffer. | |
sourceOffset | The starting offset in the source buffer. | |
copySize | The size in bytes of the chunk of data to copy. |
virtual void SoGLBufferObject::memset | ( | void * | value, | |
size_t | valueSize = 1 , |
|||
size_t | offset = 0 , |
|||
size_t | count = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
Set 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 that will be set 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. |
Notes:
EXAMPLE
unsigned char memset_value = 0; buffer->memset( &memset_value );
Implements SoBufferObject.
virtual bool SoGLBufferObject::setSize | ( | size_t | size | ) | [virtual] |
Set the size of the buffer in bytes.
size | New size in bytes of the buffer. |
Notes:
Reimplemented from SoBufferObject.
void SoGLBufferObject::setTarget | ( | BufferObjectTarget | target | ) |
Specify the buffer target, which defines possible usage of the buffer.
WARNING: The function setTarget must be called before any operation for which OpenGL requires the target to be specified.
target | The new target of the buffer. Use enum BufferObjectTarget |
void SoGLBufferObject::unbind | ( | ) |
Unbind the buffer.
Notes:
void SoGLBufferObject::unmap | ( | ) |
Unmaps the buffer using the regular unmap function.
virtual void SoGLBufferObject::unmap | ( | SoGLBufferObject * | bufferObject | ) | [virtual] |
Unmap the specified GL buffer object.
It is defined just to speed up the call when the type of the object is known.
Implements SoBufferObject.
virtual void SoGLBufferObject::unmap | ( | SoCpuBufferObject * | bufferObject | ) | [virtual] |
Unmap the specified CPU buffer object.
It is defined just to speed up the call when the type of the object is known.
Implements SoBufferObject.
virtual void SoGLBufferObject::unmap | ( | SoBufferObject * | bufferObject | ) | [virtual] |
Unmap the specified buffer object.
friend class SoCpuBufferObject [friend] |