Unofficial OpenGL Software Development Kit  0.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
List of all members | Public Member Functions
glmesh::StreamBuffer::Map Class Reference

#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.
 

Constructor & Destructor Documentation

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.

Parameters
storageThe StreamBuffer to map.
numBytesThe number of bytes to map. Must be less than the buffer's storage.
invalidateIfNotAvailableIf 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.

Note
If invalidateIfNotAvailable is 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.
Exceptions
NotEnoughStorageForMapExceptionThrown if numBytes is larger than the storage size of the buffer.
NotEnoughRemainingStorageForMapExceptionThrown if numBytes is larger than the remaining space and invalidateIfNotAvailable is false.
StoreAlreadyMappedExceptionThrown if storage is already currently mapped.

In the event of any exceptions, the StreamBuffer is not altered.

glmesh::StreamBuffer::Map::~Map ( )

Unmaps the buffer, if it has not already been unmapped.

If the Map has not previously been Release()'d, then this function effectively calls Release(). If the buffer's storage was lost, you will be unable to tell.

Member Function Documentation

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.

Returns
true if the buffer's contents are fine. False if they are lost, or if Release() was called once before

The documentation for this class was generated from the following file: