ASR::DynamicRenderable Class Reference

Abstract base class providing mechanisms for dynamically growing hardware buffers. More...

#include <DynamicRenderable.h>

Inheritance diagram for ASR::DynamicRenderable:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 DynamicRenderable ()
 Constructor.
virtual ~DynamicRenderable ()
 Virtual destructor.
void initialize (Ogre::RenderOperation::OperationType operationType, bool useIndices)
 Initializes the dynamic renderable.
virtual Ogre::Real getBoundingRadius (void) const
 Implementation of Ogre::SimpleRenderable.
virtual Ogre::Real getSquaredViewDepth (const Ogre::Camera *cam) const
 Implementation of Ogre::SimpleRenderable.

Protected Member Functions

virtual void createVertexDeclaration ()=0
 Creates the vertex declaration.
void prepareHardwareBuffers (size_t vertexCount, size_t indexCount)
 Prepares the hardware buffers for the requested vertex and index counts.
virtual void fillHardwareBuffers ()=0
 Fills the hardware vertex and index buffers with data.

Protected Attributes

size_t mVertexBufferCapacity
 Maximum capacity of the currently allocated vertex buffer.
size_t mIndexBufferCapacity
 Maximum capacity of the currently allocated index buffer.

Detailed Description

Abstract base class providing mechanisms for dynamically growing hardware buffers.

Definition at line 12 of file DynamicRenderable.h.


Constructor & Destructor Documentation

ASR::DynamicRenderable::DynamicRenderable (  ) 

Constructor.

Definition at line 10 of file DynamicRenderable.cpp.

00011         {
00012         }

ASR::DynamicRenderable::~DynamicRenderable (  )  [virtual]

Virtual destructor.

Definition at line 14 of file DynamicRenderable.cpp.

00015         {
00016                 delete mRenderOp.vertexData;
00017                 delete mRenderOp.indexData;
00018         }


Member Function Documentation

virtual void ASR::DynamicRenderable::createVertexDeclaration (  )  [protected, pure virtual]

Creates the vertex declaration.

Remarks:
Override and set mRenderOp.vertexData->vertexDeclaration here. mRenderOp.vertexData will be created for you before this method is called.

Implemented in ASR::DynamicLines.

virtual void ASR::DynamicRenderable::fillHardwareBuffers (  )  [protected, pure virtual]

Fills the hardware vertex and index buffers with data.

Remarks:
This function must call prepareHardwareBuffers() before locking the buffers to ensure the they are large enough for the data to be written. Afterwards the vertex and index buffers (if using indices) can be locked, and data can be written to them.

Implemented in ASR::DynamicLines.

Real ASR::DynamicRenderable::getBoundingRadius ( void   )  const [virtual]

Implementation of Ogre::SimpleRenderable.

Definition at line 122 of file DynamicRenderable.cpp.

00123         {
00124                 return Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
00125         }

virtual Ogre::Real ASR::DynamicRenderable::getSquaredViewDepth ( const Ogre::Camera *  cam  )  const [virtual]

Implementation of Ogre::SimpleRenderable.

void ASR::DynamicRenderable::initialize ( Ogre::RenderOperation::OperationType  operationType,
bool  useIndices 
)

Initializes the dynamic renderable.

Remarks:
This function should only be called once. It initializes the render operation, and calls the abstract function createVertexDeclaration().
Parameters:
operationType The type of render operation to perform.
useIndices Specifies whether to use indices to determine the vertices to use as input.

Referenced by ASR::DynamicLines::DynamicLines().

void ASR::DynamicRenderable::prepareHardwareBuffers ( size_t  vertexCount,
size_t  indexCount 
) [protected]

Prepares the hardware buffers for the requested vertex and index counts.

Remarks:
This function must be called before locking the buffers in fillHardwareBuffers(). It guarantees that the hardware buffers are large enough to hold at least the requested number of vertices and indices (if using indices). The buffers are possibly reallocated to achieve this.
The vertex and index count in the render operation are set to the values of vertexCount and indexCount respectively.
Parameters:
vertexCount The number of vertices the buffer must hold.
indexCount The number of indices the buffer must hold. This parameter is ignored if not using indices.

Definition at line 38 of file DynamicRenderable.cpp.

References mIndexBufferCapacity, and mVertexBufferCapacity.

Referenced by ASR::DynamicLines::fillHardwareBuffers().

00040         {
00041                 // Prepare vertex buffer
00042                 size_t newVertCapacity = mVertexBufferCapacity;
00043                 if ((vertexCount > mVertexBufferCapacity) ||
00044                         (!mVertexBufferCapacity))
00045                 {
00046                         // vertexCount exceeds current capacity!
00047                         // It is necessary to reallocate the buffer.
00048 
00049                         // Check if this is the first call
00050                         if (!newVertCapacity)
00051                                 newVertCapacity = 1;
00052 
00053                         // Make capacity the next power of two
00054                         while (newVertCapacity < vertexCount)
00055                                 newVertCapacity <<= 1;
00056                 }
00057                 else if (vertexCount < mVertexBufferCapacity>>1) {
00058                         // Make capacity the previous power of two
00059                         while (vertexCount < newVertCapacity>>1)
00060                                 newVertCapacity >>= 1;
00061                 }
00062                 if (newVertCapacity != mVertexBufferCapacity) 
00063                 {
00064                         mVertexBufferCapacity = newVertCapacity;
00065                         // Create new vertex buffer
00066                         HardwareVertexBufferSharedPtr vbuf =
00067                                 HardwareBufferManager::getSingleton().createVertexBuffer(
00068                                 mRenderOp.vertexData->vertexDeclaration->getVertexSize(0),
00069                                 mVertexBufferCapacity,
00070                                 HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); // TODO: Custom HBU_?
00071 
00072                         // Bind buffer
00073                         mRenderOp.vertexData->vertexBufferBinding->setBinding(0, vbuf);
00074                 }
00075                 // Update vertex count in the render operation
00076                 mRenderOp.vertexData->vertexCount = vertexCount;
00077 
00078                 if (mRenderOp.useIndexes)
00079                 {
00080                         OgreAssert(indexCount <= std::numeric_limits<unsigned short>::max(), "indexCount exceeds 16 bit");
00081 
00082                         size_t newIndexCapacity = mIndexBufferCapacity;
00083                         // Prepare index buffer
00084                         if ((indexCount > newIndexCapacity) ||
00085                                 (!newIndexCapacity))
00086                         {
00087                                 // indexCount exceeds current capacity!
00088                                 // It is necessary to reallocate the buffer.
00089 
00090                                 // Check if this is the first call
00091                                 if (!newIndexCapacity)
00092                                         newIndexCapacity = 1;
00093 
00094                                 // Make capacity the next power of two
00095                                 while (newIndexCapacity < indexCount)
00096                                         newIndexCapacity <<= 1;
00097 
00098                         }
00099                         else if (indexCount < newIndexCapacity>>1) 
00100                         {
00101                                 // Make capacity the previous power of two
00102                                 while (indexCount < newIndexCapacity>>1)
00103                                         newIndexCapacity >>= 1;
00104                         }
00105 
00106                         if (newIndexCapacity != mIndexBufferCapacity)
00107                         {
00108                                 mIndexBufferCapacity = newIndexCapacity;
00109                                 // Create new index buffer
00110                                 mRenderOp.indexData->indexBuffer =
00111                                         HardwareBufferManager::getSingleton().createIndexBuffer(
00112                                         HardwareIndexBuffer::IT_16BIT,
00113                                         mIndexBufferCapacity,
00114                                         HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY); // TODO: Custom HBU_?
00115                         }
00116 
00117                         // Update index count in the render operation
00118                         mRenderOp.indexData->indexCount = indexCount;
00119                 }
00120         }


Member Data Documentation

size_t ASR::DynamicRenderable::mIndexBufferCapacity [protected]

Maximum capacity of the currently allocated index buffer.

Definition at line 40 of file DynamicRenderable.h.

Referenced by prepareHardwareBuffers().

size_t ASR::DynamicRenderable::mVertexBufferCapacity [protected]

Maximum capacity of the currently allocated vertex buffer.

Definition at line 38 of file DynamicRenderable.h.

Referenced by prepareHardwareBuffers().


The documentation for this class was generated from the following files:
Generated on Sun Jun 25 19:23:43 2006 for Valors End by  doxygen 1.4.7