#include <DynamicRenderable.h>
Inheritance diagram for ASR::DynamicRenderable:
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. |
Definition at line 12 of file DynamicRenderable.h.
ASR::DynamicRenderable::DynamicRenderable | ( | ) |
ASR::DynamicRenderable::~DynamicRenderable | ( | ) | [virtual] |
virtual void ASR::DynamicRenderable::createVertexDeclaration | ( | ) | [protected, pure virtual] |
Creates the vertex declaration.
Implemented in ASR::DynamicLines.
virtual void ASR::DynamicRenderable::fillHardwareBuffers | ( | ) | [protected, pure virtual] |
Fills the hardware vertex and index buffers with data.
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.
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.
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 }
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().