Unofficial OpenGL Software Development Kit
0.5.0
|
#include <StreamBuffer.h>
Inherits noncopyable.
A RAII-style class for mapping a StreamBuffer.
This object is the proper way to update the buffer's storage. It maps the buffer, containing a pointer to the buffer's contents that can only be written to. The user must ensure not to write outside of the byte range that was mapped.
Public Member Functions | |
Map (StreamBuffer &storage, size_t numBytes, bool invalidateIfNotAvailable=true) | |
Maps the number of bytes. More... | |
~Map () | |
Unmaps the buffer, if it has not already been unmapped. More... | |
bool | Release () |
Manually unmaps the buffer. More... | |
void * | GetPtr () |
Retrieve the mapped pointer. Will return NULL if Release() was called. | |
glmesh::StreamBuffer::Map::Map | ( | StreamBuffer & | storage, |
size_t | numBytes, | ||
bool | invalidateIfNotAvailable = true |
||
) |
Maps the number of bytes.
This function will cause the buffer to be mapped.
storage | The StreamBuffer to map. |
numBytes | The number of bytes to map. Must be less than the buffer's storage. |
invalidateIfNotAvailable | If numBytes is greater than storage.GetSpaceRemaining(), if this parameter is true, then the buffer will be invalidated before mapping. If it is false, then an exception is thrown. |
When this function completes, the binding state of GL_ARRAY_BUFFER
will be 0.
true
, the buffer can be invalidated. This means that the current position can change due to creating a Map. If you pass true
then you should get the offset after mapping but before unmapping. If you pass false
, the position will not be changed.NotEnoughStorageForMapException | Thrown if numBytes is larger than the storage size of the buffer. |
NotEnoughRemainingStorageForMapException | Thrown if numBytes is larger than the remaining space and invalidateIfNotAvailable is false. |
StoreAlreadyMappedException | Thrown if storage is already currently mapped. |
In the event of any exceptions, the StreamBuffer is not altered.
glmesh::StreamBuffer::Map::~Map | ( | ) |
bool glmesh::StreamBuffer::Map::Release | ( | ) |
Manually unmaps the buffer.
In OpenGL, unmapping a buffer can cause the buffer's contents to be lost. Destructors in C++ should never throw exceptions, so to be able to check for this condition, we allow for the buffer to be unmapped manually.
The current position within the buffer will be advanced by the number of bytes mapped.
When this function completes, if the Map was not previously Release()'d, the binding state of GL_ARRAY_BUFFER
will be 0.