OpenGL buffer object class. More...
#include <Inventor/devices/SoGLBufferObject.h>
Classes | |
struct | Configuration |
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 | unmap (SoBufferObject *bufferObject) |
void | bind () |
void | unbind () |
virtual void * | map (AccessMode accessMode, size_t offset=0, size_t count=SO_BUFFER_SIZE_ALL) |
virtual void | unmap () |
bool | isValid () |
GLuint | getId () const |
virtual SoBufferObject * | createInstance () const |
virtual void | clearInstance () |
void | memcpy (SoBufferObject *source, size_t destOffset=0, size_t sourceOffset=0, size_t copySize=SO_BUFFER_SIZE_ALL) |
Static Public Member Functions | |
static bool | isAvailable () |
This class provides management functions for OpenGL memory buffers.
NOTE: Since Open Inventor 10.4, applications should use SoGPUBufferObject, instead of SoGLBufferObject, in most cases. For example to store vertex data in GPU memory for use with SoBufferedShape or SoVertexShaderParameterBufferObject.
This class can be used as a wrapper for GL memory buffer management when the application manages OpenGL code directly.
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 SoRef<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();
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();
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 SoInteropBufferObject.
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 SoInteropBufferObject.
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:
virtual void* SoGLBufferObject::map | ( | AccessMode | accessMode, | |
size_t | offset = 0 , |
|||
size_t | count = SO_BUFFER_SIZE_ALL | |||
) | [virtual] |
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:
Reimplemented from 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 | ( | SoBufferObject * | source, | |
size_t | destOffset = 0 , |
|||
size_t | sourceOffset = 0 , |
|||
size_t | copySize = SO_BUFFER_SIZE_ALL | |||
) |
Copy data from a buffer into this GL buffer.
Notes:
This function is a specialized function for speed-up.
source | 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 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:
virtual void SoGLBufferObject::unmap | ( | ) | [virtual] |
Unmaps the buffer using the regular unmap function.
Reimplemented from SoBufferObject.
virtual void SoGLBufferObject::unmap | ( | SoBufferObject * | bufferObject | ) | [virtual] |
Unmap the specified buffer object.