GPU buffer object class More...
#include <Inventor/devices/SoGpuBufferObject.h>
Public Types | |
enum | BufferAccessFrequency { STATIC, DYNAMIC } |
enum | BufferAccessNature { SHARED, DEVICE } |
Public Member Functions | |
SoGpuBufferObject (BufferAccessFrequency accessFrequency=STATIC, BufferAccessNature accessNature=SHARED) | |
virtual bool | setSize (size_t size) |
virtual SoBufferObject * | createInstance () const |
virtual void | clearInstance () |
BufferAccessFrequency | getAccessFrequency () const |
BufferAccessNature | getAccessNature () const |
Friends | |
struct | inventor::renderer::Resource< SoBufferObject > |
This class provides management functions for GPU 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.
See SoBufferObject for general information about buffer objects.
NOTES:
See SoBufferObject for general information about buffer objects.
See SoBufferedShape for an example of storing vertices in a GPU 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 buffer and load data from CPU buffer // Ensure that a context is created and bound before this step ! // - If using the historical viewers call the SoWinGLWidget::bindNormalContext() method here // - If using viewer components, make sure the window containing the RenderArea is already exposed SoRef<SoGpuBufferObject> gpuBuffer = new SoGpuBufferObject( SoGpuBufferObject::STATIC, SoGpuBufferObject::SHARED ); gpuBuffer->setSize( cpuBuffer->getSize() ); // Set the buffer size (allocate memory) gpuBuffer->memcpy( cpuBuffer.ptr() ); // Copy data into the buffer
float* data = (float*)gpuBuffer->map( SoBufferObject::READ_ONLY ); float value = data[0]; value = data[1]; . . . gpuBuffer->unmap();
NOTE: Class available since Open Inventor 10.0.
BufferedShapePicking, GPUGeometry, InterleavedVertexAttribFeedback, SimpleVertexAttribFeedback, VertexAttribFeedback
Available values for hints on the nature of the application's access to the buffer.
They indicate whether the application will be directly reading or writing the buffer's data.
SoGpuBufferObject::SoGpuBufferObject | ( | BufferAccessFrequency | accessFrequency = STATIC , |
|
BufferAccessNature | accessNature = SHARED | |||
) |
Constructor.
accessFrequency | The intended access frequency of this buffer. Use enum BufferAccessFrequency | |
accessNature | The intended access nature of this buffer. Use enum BufferAccessNature |
virtual void SoGpuBufferObject::clearInstance | ( | ) | [virtual] |
This function clears the content of the buffer, it frees the memory if the mode was COPY.
Implements SoBufferObject.
virtual SoBufferObject* SoGpuBufferObject::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.
BufferAccessFrequency SoGpuBufferObject::getAccessFrequency | ( | ) | const |
Returns the current buffer access frequency hint for this buffer object.
BufferAccessNature SoGpuBufferObject::getAccessNature | ( | ) | const |
Returns the current buffer access nature hint for this buffer object.
virtual bool SoGpuBufferObject::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 from SoBufferObject.
friend struct inventor::renderer::Resource< SoBufferObject > [friend] |