Data buffer object abstraction. More...
Classes | |
struct | BufferHint |
Buffer allocation hints. More... | |
Public Types | |
enum | Source { Client, Server } |
Buffer object data source. More... | |
enum | UsageMode { Draw = 0, Read } |
Buffer object usage enumeration type definition. More... | |
enum | XferMode { Stream = 0, Static, Dynamic } |
Buffer object usage mode enumeration type definition. More... | |
Public Member Functions | |
BufferObject (int type, UsageMode usage, XferMode xfer) | |
Construct a BufferObject determining its type, data usage and transfer mode. | |
abstract void | AllocateOnClient (int items) |
Allocates BufferObject data on client. | |
void | Bind (RenderContext ctx) |
Bind this RenderBufferObject. | |
override void | Create (RenderContext ctx) |
Create this BufferObject. | |
override void | Delete (RenderContext ctx) |
Delete this BufferObject. | |
bool | IsMapped () |
Check whether this RenderBufferObject data is mapped. | |
void | Map (RenderContext ctx, int mask) |
Map this BufferObject. | |
T | MapGet< T > (RenderContext ctx, Int64 offset) |
void | MapSet< T > (RenderContext ctx, T value, Int64 offset) |
void | Unbind (RenderContext ctx) |
Unbind this RenderBufferObject. | |
void | Unmap (RenderContext ctx) |
Unmap this RenderBufferObject data. | |
Protected Member Functions | |
int | GetMappedBufferMask () |
Determine RenderBufferObject data mapping access mask. | |
void | ReleaseOnClient () |
Release BufferObject data on client. | |
Protected Attributes | |
BufferHint | mBufferHint |
BufferObject hints. | |
int | mDataItemSize = 0 |
BufferObject data item size. | |
int | mDataUsage |
RenderBufferObject data usage hint. | |
int | mType |
RenderBufferObject type. | |
Properties | |
Source | DataSource [get] |
BufferObject data source property. | |
BufferHint | Hints [get, set] |
BufferObject hints. | |
int | ItemsCount [get, set] |
Number of items included in this BufferObject. |
Data buffer object abstraction.
BufferObject collect data. This abstract class doesn't define the term of storage of the BufferObject, but it defines BufferObject interface. The BufferObject main characteristic is the location of the data buffer: client side or server side.
When data buffer is allocated on client memory, it can be accessed easily by application and it can be reallocated whenever required, but it cannot be used for rendering operations; infact the data buffer shall be allocated on server side before being used for rendering.
Once allocated on server side, the data buffer can be linked with shader inputs for rendering, but it cannot be accessed without synchornization with the graphic system, and each modification requires an update on the server side, which cost is linear with the data to be modified.
It shall be possible to manage BufferObject data with the following primitives:
The actual data buffer location can be queried with the DataSource property. To allocate a BufferObject on server, the data buffer shall be allocated in client memory first, then it can be allocated on server.
When allocating a data buffer on server, a set of hints shall be defined in order to optimize data buffer usage by the graphic system. These hints can be determined by the usage mode (see UsageMode and the transfer mode (see XferMode); these hints aid the graphics system to manage correctly the buffer data, assuming the data buffer usage and the data buffer update frequency.
Note that data buffer hints cannot be changed once the buffer object is allocated on server side, indeed to change buffer data hints it's necessary to deallocate and reallocate data buffer on server side; in this case you should consider to refactor the application logic, because the cost of the buffer allocation could be more significant respect the enhancements derived by buffer hints.
You can note that BufferObject class doesn't define the concrete data allocation, and methods and properties which iteracts with the data buffer are declared as abstract. Infact this class shall be derived in order to allocate data buffers, generally using generic classes to allow flexibility in the data definition.
The main class for accessing to the BufferObject interface is the RenderBufferObject class (a generic one). Other specific BufferObject implementation shall derive from RenderBufferObject (see RenderBufferObject<T>. for more details).
The BufferObject is quite flexible. There are many ways to allocate data for a collection of BufferObject instances. Here is an overview of standard allocation methods:
Buffer object data source.
Client |
Buffer object data is specified by client (application). When this data source is specified, the buffer object data is specified by client (application). Indeed the client is able to map buffer object data: in the case the usage is Draw, mapping is has read/write permissions, while in the case the usage is Read, mapping is read only.. |
Server |
Buffer object data is specified by server (OpenGL implementation). When this data source is specified, the buffer object data is specified by server (OpenGL implementation). Indeed the client is able to map buffer object data only in the case the usage is Read, which it has read only permissions. In the case usage is Draw, no mapping is allowed. |
Buffer object usage enumeration type definition.
Buffer object usage mode enumeration type definition.
Construct a BufferObject determining its type, data usage and transfer mode.
abstract void Derm.Render.BufferObject.AllocateOnClient | ( | int | items | ) | [pure virtual] |
Allocates BufferObject data on client.
items | Number of items to (re)allocate. A System.Int32 |
This routine shall allocate a certain number of BufferObject items on client memory; default values for allocated data is defined by specific BufferObject item implementor.
In the case BufferObject as already allocated the data buffer, it is reallocated keeping already defined data.
Implemented in Derm.Render.PackedArrayBufferObject, and Derm.Render.RenderBufferObject< T >.
void Derm.Render.BufferObject.Bind | ( | RenderContext | ctx | ) |
Bind this RenderBufferObject.
override void Derm.Render.BufferObject.Create | ( | RenderContext | ctx | ) | [virtual] |
override void Derm.Render.BufferObject.Delete | ( | RenderContext | ctx | ) | [virtual] |
int Derm.Render.BufferObject.GetMappedBufferMask | ( | ) | [protected] |
Determine RenderBufferObject data mapping access mask.
The RenderBufferObject makes available its data to application whenever it is mapped; The map implementation requires an access mask. This routine determines the most efficient access mask determined by the RenderBufferObject Usage and UsageMode.
In the case the RenderBufferObject data source is Client,
bool Derm.Render.BufferObject.IsMapped | ( | ) |
Check whether this RenderBufferObject data is mapped.
void Derm.Render.BufferObject.Map | ( | RenderContext | ctx, | |
int | mask | |||
) |
Map this BufferObject.
ctx | A RenderContext required for mapping this BufferObject. | |
mask | A System.Int32 specifying the map access. It can be Gl.READ_ONLY, Gl.WRITE_ONLY, or Gl.READ_WRITE. |
T Derm.Render.BufferObject.MapGet< T > | ( | RenderContext | ctx, | |
Int64 | offset | |||
) |
T | : | struct |
void Derm.Render.BufferObject.MapSet< T > | ( | RenderContext | ctx, | |
T | value, | |||
Int64 | offset | |||
) |
T | : | struct |
void Derm.Render.BufferObject.ReleaseOnClient | ( | ) | [protected] |
Release BufferObject data on client.
void Derm.Render.BufferObject.Unbind | ( | RenderContext | ctx | ) |
Unbind this RenderBufferObject.
void Derm.Render.BufferObject.Unmap | ( | RenderContext | ctx | ) |
Unmap this RenderBufferObject data.
BufferHint Derm.Render.BufferObject.mBufferHint [protected] |
BufferObject hints.
int Derm.Render.BufferObject.mDataItemSize = 0 [protected] |
BufferObject data item size.
int Derm.Render.BufferObject.mDataUsage [protected] |
RenderBufferObject data usage hint.
int Derm.Render.BufferObject.mType [protected] |
RenderBufferObject type.
The RenderBufferObject could assume the values Derm.Gl.ARRAY_BUFFER, Derm.Gl.ELEMENT_ARRAY_BUFFER, Derm.Gl.PIXEL_PACK_BUFFER, or Derm.Gl.PIXEL_UNPACK_BUFFER.
Source Derm.Render.BufferObject.DataSource [get] |
BufferObject data source property.
BufferHint Derm.Render.BufferObject.Hints [get, set] |
BufferObject hints.
BufferObject hints, specified at construction time. Hints cannot be changed after having allocated buffer on server.
int Derm.Render.BufferObject.ItemsCount [get, set] |
Number of items included in this BufferObject.