# Ogre::HardwareBufferManager Class Reference

Abstract singleton class for managing hardware buffers, a concrete instance of this will be created by the RenderSystem. More...

`#include <OgreHardwareBufferManager.h>`

Inheritance diagram for Ogre::HardwareBufferManager:

[legend]
List of all members.

## Public Types

enum | BufferLicenseType { BLT_MANUAL_RELEASE, BLT_AUTOMATIC_RELEASE }

## Public Member Functions

| HardwareBufferManager ()
virtual | ~HardwareBufferManager ()
virtual HardwareVertexBufferSharedPtr | createVertexBuffer (size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage, bool useShadowBuffer=false)=0
| Create a hardware vertex buffer.
virtual HardwareIndexBufferSharedPtr | createIndexBuffer (HardwareIndexBuffer::IndexType itype, size_t numIndexes, HardwareBuffer::Usage usage, bool useShadowBuffer=false)=0
| Create a hardware index buffer.
virtual RenderToVertexBufferSharedPtr | createRenderToVertexBuffer ()=0
| Create a render to vertex buffer.
virtual VertexDeclaration * | createVertexDeclaration (void)
| Creates a new vertex declaration.
virtual void | destroyVertexDeclaration (VertexDeclaration *decl)
| Destroys a vertex declaration.
virtual VertexBufferBinding * | createVertexBufferBinding (void)
| Creates a new VertexBufferBinding.
virtual void | destroyVertexBufferBinding (VertexBufferBinding *binding)
| Destroys a VertexBufferBinding.
virtual void | registerVertexBufferSourceAndCopy (const HardwareVertexBufferSharedPtr &sourceBuffer, const HardwareVertexBufferSharedPtr &copy)
| Registers a vertex buffer as a copy of another.
virtual HardwareVertexBufferSharedPtr | allocateVertexBufferCopy (const HardwareVertexBufferSharedPtr &sourceBuffer, BufferLicenseType licenseType, HardwareBufferLicensee *licensee, bool copyData=false)
| Allocates a copy of a given vertex buffer.
virtual void | releaseVertexBufferCopy (const HardwareVertexBufferSharedPtr &bufferCopy)
| Manually release a vertex buffer copy for others to subsequently use.
virtual void | touchVertexBufferCopy (const HardwareVertexBufferSharedPtr &bufferCopy)
| Tell engine that the vertex buffer copy intent to reuse.
virtual void | _freeUnusedBufferCopies (void)
| Free all unused vertex buffer copies.
virtual void | _releaseBufferCopies (bool forceFreeUnused=false)
| Internal method for releasing all temporary buffers which have been allocated using BLT_AUTOMATIC_RELEASE; is called by OGRE.
virtual void | _forceReleaseBufferCopies (const HardwareVertexBufferSharedPtr &sourceBuffer)
| Internal method that forces the release of copies of a given buffer.
virtual void | _forceReleaseBufferCopies (HardwareVertexBuffer *sourceBuffer)
| Internal method that forces the release of copies of a given buffer.
void | _notifyVertexBufferDestroyed (HardwareVertexBuffer *buf)
| Notification that a hardware vertex buffer has been destroyed.
void | _notifyIndexBufferDestroyed (HardwareIndexBuffer *buf)
| Notification that a hardware index buffer has been destroyed.
| Singleton (void)

## Static Public Member Functions

static HardwareBufferManager & | getSingleton (void)
| Override standard Singleton retrieval.
static HardwareBufferManager * | getSingletonPtr (void)
| Override standard Singleton retrieval.

## Protected Types

typedef std::set< HardwareVertexBuffer * > | VertexBufferList
| WARNING: The following two members should place before all other members.
typedef std::set< HardwareIndexBuffer * > | IndexBufferList
typedef std::set< VertexDeclaration * > | VertexDeclarationList
typedef std::set< VertexBufferBinding * > | VertexBufferBindingList
typedef std::multimap< HardwareVertexBuffer *, HardwareVertexBufferSharedPtr > | FreeTemporaryVertexBufferMap
| Map from original buffer to temporary buffers.
typedef std::map< HardwareVertexBuffer *, VertexBufferLicense > | TemporaryVertexBufferLicenseMap
| Map from temporary buffer to details of a license.

## Protected Member Functions

virtual void | destroyAllDeclarations (void)
| Internal method for destroys all vertex declarations.
virtual void | destroyAllBindings (void)
| Internal method for destroys all vertex buffer bindings.
virtual VertexDeclaration * | createVertexDeclarationImpl (void)
| Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs.
virtual void | destroyVertexDeclarationImpl (VertexDeclaration *decl)
| Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs.
virtual VertexBufferBinding * | createVertexBufferBindingImpl (void)
| Internal method for creates a new VertexBufferBinding, may be overridden by certain rendering APIs.
virtual void | destroyVertexBufferBindingImpl (VertexBufferBinding *binding)
| Internal method for destroys a VertexBufferBinding, may be overridden by certain rendering APIs.
HardwareVertexBufferSharedPtr | makeBufferCopy (const HardwareVertexBufferSharedPtr &source, HardwareBuffer::Usage usage, bool useShadowBuffer)
| Creates a new buffer as a copy of the source, does not copy data.

## Protected Attributes

VertexBufferList | mVertexBuffers
IndexBufferList | mIndexBuffers
VertexDeclarationList | mVertexDeclarations
VertexBufferBindingList | mVertexBufferBindings
FreeTemporaryVertexBufferMap | mFreeTempVertexBufferMap
| Map of current available temp buffers.
TemporaryVertexBufferLicenseMap | mTempVertexBufferLicenses
| Map of currently licensed temporary buffers.
size_t | mUnderUsedFrameCount
| Number of frames elapsed since temporary buffers utilization was above half the available.

## Static Protected Attributes

static const size_t | UNDER_USED_FRAME_THRESHOLD
| Number of frames to wait before free unused temporary buffers.
static const size_t | EXPIRED_DELAY_FRAME_THRESHOLD
| Frame delay for BLT_AUTOMATIC_RELEASE temporary buffers.
static HardwareBufferManager * | ms_Singleton

## Friends

class | HardwareVertexBufferSharedPtr
class | HardwareIndexBufferSharedPtr

## Classes

class | VertexBufferLicense
| Struct holding details of a license to use a temporary shared buffer. More...

## Detailed Description

Abstract singleton class for managing hardware buffers, a concrete instance of this will be created by the RenderSystem.

Definition at line 95 of file OgreHardwareBufferManager.h.

## Member Typedef Documentation

typedef std::multimap<HardwareVertexBuffer*, HardwareVertexBufferSharedPtr> Ogre::HardwareBufferManager::FreeTemporaryVertexBufferMap`[protected]`

| Map from original buffer to temporary buffers. Definition at line 173 of file OgreHardwareBufferManager.h.

typedef std::set<HardwareIndexBuffer*> Ogre::HardwareBufferManager::IndexBufferList`[protected]`

| Definition at line 106 of file OgreHardwareBufferManager.h.

typedef std::map<HardwareVertexBuffer*, VertexBufferLicense> Ogre::HardwareBufferManager::TemporaryVertexBufferLicenseMap`[protected]`

| Map from temporary buffer to details of a license. Definition at line 177 of file OgreHardwareBufferManager.h.

typedef std::set<VertexBufferBinding*> Ogre::HardwareBufferManager::VertexBufferBindingList`[protected]`

| Definition at line 112 of file OgreHardwareBufferManager.h.

typedef std::set<HardwareVertexBuffer*> Ogre::HardwareBufferManager::VertexBufferList`[protected]`

| WARNING: The following two members should place before all other members. Members destruct order is very important here, because destructing other members will cause notify back to this class, and then will access to this two members. Definition at line 105 of file OgreHardwareBufferManager.h.

typedef std::set<VertexDeclaration*> Ogre::HardwareBufferManager::VertexDeclarationList`[protected]`

| Definition at line 111 of file OgreHardwareBufferManager.h.

## Member Enumeration Documentation

enum Ogre::HardwareBufferManager::BufferLicenseType

Enumeration values:

  BLT_MANUAL_RELEASE | Licensee will only release buffer when it says so.
  BLT_AUTOMATIC_RELEASE | Licensee can have license revoked.

Definition at line 139 of file OgreHardwareBufferManager.h.

## Constructor & Destructor Documentation

Ogre::HardwareBufferManager::HardwareBufferManager | ( |  | ) |

virtual Ogre::HardwareBufferManager::~HardwareBufferManager | ( |  | ) | `[virtual]`

## Member Function Documentation

virtual void Ogre::HardwareBufferManager::_forceReleaseBufferCopies | ( | HardwareVertexBuffer * | sourceBuffer | ) | `[virtual]`

Internal method that forces the release of copies of a given buffer.

Remarks:
  This usually means that the buffer which the copies are based on has been changed in some fundamental way, and the owner of the original wishes to make that known so that new copies will reflect the changes.

Parameters:

  | sourceBuffer | the source buffer as a pointer. Any buffer copies created from the source buffer are deleted.

virtual void Ogre::HardwareBufferManager::_forceReleaseBufferCopies | ( | const HardwareVertexBufferSharedPtr & | sourceBuffer | ) | `[virtual]`

Internal method that forces the release of copies of a given buffer.

Remarks:
  This usually means that the buffer which the copies are based on has been changed in some fundamental way, and the owner of the original wishes to make that known so that new copies will reflect the changes.

Parameters:

  | sourceBuffer | the source buffer as a shared pointer. Any buffer copies created from the source buffer are deleted.

virtual void Ogre::HardwareBufferManager::_freeUnusedBufferCopies | ( | void |  | ) | `[virtual]`

Free all unused vertex buffer copies.

Remarks:
  This method free all temporary vertex buffers that not in used. In normally, temporary vertex buffers are subsequently stored and can be made available for other purposes later without incurring the cost of construction / destruction. But in some cases you want to free them to save hardware memory (e.g. application was runs in a long time, you might free temporary buffers periodically to avoid memory overload).

void Ogre::HardwareBufferManager::_notifyIndexBufferDestroyed | ( | HardwareIndexBuffer * | buf | ) |

| Notification that a hardware index buffer has been destroyed.

void Ogre::HardwareBufferManager::_notifyVertexBufferDestroyed | ( | HardwareVertexBuffer * | buf | ) |

| Notification that a hardware vertex buffer has been destroyed.

virtual void Ogre::HardwareBufferManager::_releaseBufferCopies | ( | bool | forceFreeUnused = `false` | ) | `[virtual]`

Internal method for releasing all temporary buffers which have been allocated using BLT_AUTOMATIC_RELEASE; is called by OGRE.

Parameters:

  | forceFreeUnused | If true, free all unused temporary buffers. If false, auto detect and free all unused temporary buffers based on temporary buffers utilization.

virtual HardwareVertexBufferSharedPtr Ogre::HardwareBufferManager::allocateVertexBufferCopy | ( | const HardwareVertexBufferSharedPtr & | sourceBuffer,
|  | BufferLicenseType | licenseType,
|  | HardwareBufferLicensee * | licensee,
|  | bool | copyData = `false`
| ) | `[virtual]`

Allocates a copy of a given vertex buffer.

Remarks:
  This method allocates a temporary copy of an existing vertex buffer. This buffer is subsequently stored and can be made available for other purposes later without incurring the cost of construction / destruction.

Parameters:

  | sourceBuffer | The source buffer to use as a copy
  | licenseType | The type of license required on this buffer - automatic release causes this class to release licenses every frame so that they can be reallocated anew.
  | licensee | Pointer back to the class requesting the copy, which must implement HardwareBufferLicense in order to be notified when the license expires.
  | copyData | If true, the current data is copied as well as the structure of the buffer

virtual HardwareIndexBufferSharedPtr Ogre::HardwareBufferManager::createIndexBuffer | ( | HardwareIndexBuffer::IndexType | itype,
|  | size_t | numIndexes,
|  | HardwareBuffer::Usage | usage,
|  | bool | useShadowBuffer = `false`
| ) | `[pure virtual]`

Create a hardware index buffer.

Remarks:
  Note that because buffers can be shared, they are reference counted so you do not need to worry about destroying them this will be done automatically.

Parameters:

  | itype | The type in index, either 16- or 32-bit, depending on how many vertices you need to be able to address
  | numIndexes | The number of indexes in the buffer
  | usage | One or more members of the HardwareBuffer::Usage enumeration.

  useShadowBuffer

  If set to true, this buffer will be 'shadowed' by one stored in system memory rather than GPU or AGP memory. You should set this flag if you intend to read data back from the index buffer, because reading data from a buffer in the GPU or AGP memory is very expensive, and is in fact impossible if you specify HBU_WRITE_ONLY for the main buffer. If you use this option, all reads and writes will be done to the shadow buffer, and the shadow buffer will be synchronised with the real buffer at an appropriate time.

Implemented in Ogre::DefaultHardwareBufferManager.

virtual RenderToVertexBufferSharedPtr Ogre::HardwareBufferManager::createRenderToVertexBuffer | ( |  | ) | `[pure virtual]`

Create a render to vertex buffer.

Remarks:
  The parameters (such as vertex size etc) are determined later and are allocated when needed.

Implemented in Ogre::DefaultHardwareBufferManager.

virtual HardwareVertexBufferSharedPtr Ogre::HardwareBufferManager::createVertexBuffer | ( | size_t | vertexSize,
|  | size_t | numVerts,
|  | HardwareBuffer::Usage | usage,
|  | bool | useShadowBuffer = `false`
| ) | `[pure virtual]`

Create a hardware vertex buffer.

Remarks:
  This method creates a new vertex buffer; this will act as a source of geometry data for rendering objects. Note that because the meaning of the contents of the vertex buffer depends on the usage, this method does not specify a vertex format; the user of this buffer can actually insert whatever data they wish, in any format. However, in order to use this with a RenderOperation, the data in this vertex buffer will have to be associated with a semantic element of the rendering pipeline, e.g. a position, or texture coordinates. This is done using the VertexDeclaration class, which itself contains VertexElement structures referring to the source data.

  Note that because vertex buffers can be shared, they are reference counted so you do not need to worry about destroying themm this will be done automatically.

Parameters:

  | vertexSize | The size in bytes of each vertex in this buffer; you must calculate this based on the kind of data you expect to populate this buffer with.
  | numVerts | The number of vertices in this buffer.
  | usage | One or more members of the HardwareBuffer::Usage enumeration; you are strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to update regularly, consider HBU_DYNAMIC_WRITE_ONLY and useShadowBuffer=true.

  useShadowBuffer

  If set to true, this buffer will be 'shadowed' by one stored in system memory rather than GPU or AGP memory. You should set this flag if you intend to read data back from the vertex buffer, because reading data from a buffer in the GPU or AGP memory is very expensive, and is in fact impossible if you specify HBU_WRITE_ONLY for the main buffer. If you use this option, all reads and writes will be done to the shadow buffer, and the shadow buffer will be synchronised with the real buffer at an appropriate time.

Implemented in Ogre::DefaultHardwareBufferManager.

virtual VertexBufferBinding* Ogre::HardwareBufferManager::createVertexBufferBinding | ( | void |  | ) | `[virtual]`

| Creates a new VertexBufferBinding.

virtual VertexBufferBinding* Ogre::HardwareBufferManager::createVertexBufferBindingImpl | ( | void |  | ) | `[protected, virtual]`

| Internal method for creates a new VertexBufferBinding, may be overridden by certain rendering APIs.

virtual VertexDeclaration* Ogre::HardwareBufferManager::createVertexDeclaration | ( | void |  | ) | `[virtual]`

| Creates a new vertex declaration.

virtual VertexDeclaration* Ogre::HardwareBufferManager::createVertexDeclarationImpl | ( | void |  | ) | `[protected, virtual]`

| Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs.

virtual void Ogre::HardwareBufferManager::destroyAllBindings | ( | void |  | ) | `[protected, virtual]`

| Internal method for destroys all vertex buffer bindings.

virtual void Ogre::HardwareBufferManager::destroyAllDeclarations | ( | void |  | ) | `[protected, virtual]`

| Internal method for destroys all vertex declarations.

virtual void Ogre::HardwareBufferManager::destroyVertexBufferBinding | ( | VertexBufferBinding * | binding | ) | `[virtual]`

| Destroys a VertexBufferBinding.

virtual void Ogre::HardwareBufferManager::destroyVertexBufferBindingImpl | ( | VertexBufferBinding * | binding | ) | `[protected, virtual]`

| Internal method for destroys a VertexBufferBinding, may be overridden by certain rendering APIs.

virtual void Ogre::HardwareBufferManager::destroyVertexDeclaration | ( | VertexDeclaration * | decl | ) | `[virtual]`

| Destroys a vertex declaration.

virtual void Ogre::HardwareBufferManager::destroyVertexDeclarationImpl | ( | VertexDeclaration * | decl | ) | `[protected, virtual]`

| Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs.

static HardwareBufferManager& Ogre::HardwareBufferManager::getSingleton | ( | void |  | ) | `[static]`

Override standard Singleton retrieval.

Remarks:
  Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.

  This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< HardwareBufferManager >.

static HardwareBufferManager* Ogre::HardwareBufferManager::getSingletonPtr | ( | void |  | ) | `[static]`

Override standard Singleton retrieval.

Remarks:
  Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.

  This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from Ogre::Singleton< HardwareBufferManager >.

HardwareVertexBufferSharedPtr Ogre::HardwareBufferManager::makeBufferCopy | ( | const HardwareVertexBufferSharedPtr & | source,
|  | HardwareBuffer::Usage | usage,
|  | bool | useShadowBuffer
| ) | `[protected]`

| Creates a new buffer as a copy of the source, does not copy data.

virtual void Ogre::HardwareBufferManager::registerVertexBufferSourceAndCopy | ( | const HardwareVertexBufferSharedPtr & | sourceBuffer,
|  | const HardwareVertexBufferSharedPtr & | copy
| ) | `[virtual]`

Registers a vertex buffer as a copy of another.

Remarks:
  This is useful for registering an existing buffer as a temporary buffer which can be allocated just like a copy.

virtual void Ogre::HardwareBufferManager::releaseVertexBufferCopy | ( | const HardwareVertexBufferSharedPtr & | bufferCopy | ) | `[virtual]`

Manually release a vertex buffer copy for others to subsequently use.

Remarks:
  Only required if the original call to allocateVertexBufferCopy included a licenseType of BLT_MANUAL_RELEASE.

Parameters:

  | bufferCopy | The buffer copy. The caller is expected to delete or at least no longer use this reference, since another user may well begin to modify the contents of the buffer.

Ogre::Singleton< HardwareBufferManager >::Singleton | ( | void |  | ) | `[inherited]`

| Definition at line 64 of file OgreSingleton.h.

virtual void Ogre::HardwareBufferManager::touchVertexBufferCopy | ( | const HardwareVertexBufferSharedPtr & | bufferCopy | ) | `[virtual]`

Tell engine that the vertex buffer copy intent to reuse.

Remarks:
  Ogre internal keep an expired delay counter of BLT_AUTOMATIC_RELEASE buffers, when the counter count down to zero, it'll release for other purposes later. But you can use this function to reset the counter to the internal configured value, keep the buffer not get released for some frames.

Parameters:

  | bufferCopy | The buffer copy. The caller is expected to keep this buffer copy for use.

## Friends And Related Function Documentation

friend class HardwareIndexBufferSharedPtr`[friend]`

| Definition at line 98 of file OgreHardwareBufferManager.h.

friend class HardwareVertexBufferSharedPtr`[friend]`

| Definition at line 97 of file OgreHardwareBufferManager.h.

## Member Data Documentation

const size_t Ogre::HardwareBufferManager::EXPIRED_DELAY_FRAME_THRESHOLD`[static, protected]`

| Frame delay for BLT_AUTOMATIC_RELEASE temporary buffers. Definition at line 185 of file OgreHardwareBufferManager.h.

FreeTemporaryVertexBufferMap Ogre::HardwareBufferManager::mFreeTempVertexBufferMap`[protected]`

| Map of current available temp buffers. Definition at line 175 of file OgreHardwareBufferManager.h.

IndexBufferList Ogre::HardwareBufferManager::mIndexBuffers`[protected]`

| Definition at line 108 of file OgreHardwareBufferManager.h.

HardwareBufferManager * Ogre::Singleton< HardwareBufferManager >::ms_Singleton`[static, protected, inherited]`

| Definition at line 61 of file OgreSingleton.h.

TemporaryVertexBufferLicenseMap Ogre::HardwareBufferManager::mTempVertexBufferLicenses`[protected]`

| Map of currently licensed temporary buffers. Definition at line 179 of file OgreHardwareBufferManager.h.

size_t Ogre::HardwareBufferManager::mUnderUsedFrameCount`[protected]`

| Number of frames elapsed since temporary buffers utilization was above half the available. Definition at line 181 of file OgreHardwareBufferManager.h.

VertexBufferBindingList Ogre::HardwareBufferManager::mVertexBufferBindings`[protected]`

| Definition at line 114 of file OgreHardwareBufferManager.h.

VertexBufferList Ogre::HardwareBufferManager::mVertexBuffers`[protected]`

| Definition at line 107 of file OgreHardwareBufferManager.h.

VertexDeclarationList Ogre::HardwareBufferManager::mVertexDeclarations`[protected]`

| Definition at line 113 of file OgreHardwareBufferManager.h.

const size_t Ogre::HardwareBufferManager::UNDER_USED_FRAME_THRESHOLD`[static, protected]`

| Number of frames to wait before free unused temporary buffers. Definition at line 183 of file OgreHardwareBufferManager.h.

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

- OgreHardwareBufferManager.h

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sat Apr 11 13:48:15 2009