This article intent is to give a practical code demonstrating the usage of Hardware Buffers and to be able to understand how the PagedGeometry Engine works aka forests ogreaddon.
This tutorial is not meant to replace the Ogre Manual but to give a practical code to toy with those classes.

As you will notice when you study the PagedGeometry engine the code below is a rip-off of the engine. I am greatly indebted to JohnJ without his code I wouldn't have grasped the concepts.

Forum icon question2.gif Please, use this forum thread to discuss problems, suggestions, etc.

What is Geometry Batching?

Batching is the process of rendering sending massive amounts of meshes by accessing directly the graphics memory. For simple usage using Static Geometry is ideal. However sometime you need to be able to use more fundamental methods (such as if you want to create a specific scene manager, have more control on the mesh detail based on -LOD, ...). PagedGeometry is a good example.

Vertex & Buffer structure

TODO A nice UML diagram :-D

Classes Structure Explanation
VertexData
api,
manual
VertexDeclaration* vertexDeclaration;
VertexBufferBinding* vertexBufferBinding;
size_t vertexStart; size_t vertexCount;
HardwareAnimationDataList hwAnimationDataList;
size_t hwAnimationItemUsed;
Collects vertex sources information.
vertexCount is the number of vertices. hwAnimationDataList is usef for morph/pose animation.
IndexData
api,
manual
size_t indexStart;
size_t indexCount;
indexStart: buffer position to start from during an Operation
indexCount: number of indexes to use from the buffer
HardwareVertexBuffer
api,
manual
size_t mNumVertices;
size_t mVertexSize;
mVertexSize: size of a single vertex in this buffer.
HardwareIndexBuffer
api,
manual
enum IndexType;
enum Usage;
enum LockOptions;
...
VertexBufferBinding
api,
manual
std::map<ushort,
HardwareVertexBufferSharedPtr>         VertexBufferBindingMap;
VertexBufferBindingMap mBindingMap;
ushort mHightIndex;
...
VertexDeclaration
api,
manual
typdef std::list<VertexElement>
VertexElementList;
VertexElementList mElementList;
VertexElement should be added in a precise order: see below.
VertexElement
api,
manual
ushort mSource;
size_t mOffset;
VertexElementType mType;
VertexElementSemantic mSemantics;
ushort mIndex;
todo



Some important points need to be taken in consideration when implementing VertexDeclaration:
You should be aware that the ordering and structure of the VertexDeclaration can be very important on DirectX with older cards,so if you want to maintain maximum compatibility with all render systems and all cards you should be careful to follow these rules:

  1. -VertexElements should be added in the following order, and the order of the elements within a shared buffer should be as follows: position, blending weights, normals, diffuse colours, specular colours, texture coordinates (in order, with no gaps)
  2. You must not have unused gaps in your buffers which are not referenced by any VertexElement
  3. You must not cause the buffer & offset settings of 2 VertexElements to overlap

Sample Code Usage

The code below will demonstrate how to make a MovableObject which uses batched geometry. The code can be compiled as a static lib and used very simply. It will display a simple cube (no texture, no color).
Adding texture and color could be done in a second part.

Ogre::SceneNode* sn = sceneManager->getRootSceneNode()
    ->createChildSceneNode(Ogre::Vector3(0,0,0));
 
 Ogre::BatchedGeometry* object = 
    new Ogre::BatchedGeometry(sceneManager, sn);
 
 object->addObject(Ogre::Vector3::ZERO);
 object->build();

To add your own geometry you need to modify the code between :

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Note: The code is a bare minimum rip-off from the PagedGeometry Engine source also know as the forests ogreaddons.

Code Structure

The code is only composed of two classes: BatchedGeometry and Batch.

BatchedGeometry derives from a MovableObject which means you can easily manipulate it in your scenes. Its purpose is to collect the various sub-part composing the geometry you want to batch.

An very important point to note is that batches should be grouped together to use the hardware at its fullest. This is the reason of the BatchedGeometry::getFormatString() method in the PagedGeometry Engine. I didn't implement this (yet) to keep the code... simple.

Batch derives from a Renderable. This is the class that access the hardware buffer during the rendering phase.

Code Source

OgreBatchedGeometry.h

#ifndef __OGE_BATCHEDGEOMETRY_H__
 #define __OGE_BATCHEDGEOMETRY_H__
 
 #include "OgreBatch.h"
 #include "OGRE/OgrePrerequisites.h"
 #include "OGRE/OgreMovableObject.h"
 
 namespace Ogre
 {
     /**
      */
     class BatchedGeometry: public MovableObject
     {
     private:
         Vector3 mCenter;
         Real mRadius;
         AxisAlignedBox mBounds;
         bool mBoundsUndefined;
     
         Real mMinDistanceSquared;
         // Why not using MovableObject::mBeyondFarDistance ?
         bool mWithinFarDistance; 
 
         /// Stores a list of Batchs, using a format string 
         /// (generated with getGeometryFormatString()) as the key value
         typedef std::map<String, Batch*> BatchMap; 
         BatchMap mBatchs;
 
         bool mIsBuilt;
 
         SceneManager* mSceneManager;
         SceneNode* mSceneNode;
         SceneNode* mParentSceneNode;
 
     public:
         typedef Ogre::MapIterator<BatchMap> BatchIterator;
 
     public:
         BatchedGeometry(SceneManager* mgr, SceneNode* parentSceneNode);
         virtual ~BatchedGeometry();
         
         // ---- Abstract method that need to be implemented ----
         const String& getMovableType() const {
             static String s = "BatchedGeometry"; return s; }
         const AxisAlignedBox& getBoundingBox() const { return mBounds; }
         Real getBoundingRadius() const { return mRadius; }
         const Vector3& getCenter() const { return mCenter; }
         const SceneNode* getSceneNode() const { return mSceneNode; }
 
         void _updateRenderQueue(RenderQueue* queue);
         void visitRenderables(Renderable::Visitor* visitor, bool debugRenderables) {}
 
         // ------------------------------------------------------
         void clear();
         void build();
 
         bool isVisible();
 
         /** Internal method to notify the object of the camera 
          *  to be used for the next rendering operation.
          */
         void _notifyCurrentCamera(Camera* cam);
 
         void addSelfToRenderQueue(RenderQueue* queue, uint8 group);
         inline Real const getMinDistanceSquared() const {
             return mMinDistanceSquared; }
 
         /// Convert from the given global position to the local 
         /// coordinate system of the parent scene node.
         Vector3 convertToLocal(const Vector3& globalVec) const;
 
         BatchIterator getBatchIterator() const;
 
         // The main method of the class!
         void addObject(const Vector3& position,
             const Quaternion& orientation = Quaternion::IDENTITY,
             const Vector3& scale = Vector3::UNIT_SCALE);
 
         ///Generate a format string that uniquely identifies 
         /// this material & vertex/index format
         // TODO String getFormatString(Ogre::SubEntity* ent);
     };
 }
 #endif

OgreBatchedGeometry.cpp


#include "OgreBatchedGeometry.h"
 
 #include "OGRE/OgreCamera.h"
 #include "OGRE/OgreSceneNode.h"
 #include "OGRE/OgreSceneManager.h"
 
 namespace Ogre
 {
     //-----------------------------------------------------------------------------
     BatchedGeometry::BatchedGeometry(SceneManager* mgr, 
         SceneNode* parentSceneNode)
         : mBoundsUndefined(true),
           mMinDistanceSquared(0),
           mWithinFarDistance(false),
           mSceneManager(mgr),
           mSceneNode(0),
           mParentSceneNode(parentSceneNode)
     {
         clear();
         COUT("BatchedGeometry created")
     }
     //-----------------------------------------------------------------------------
     BatchedGeometry::~BatchedGeometry()
     {
         clear();
         COUT("BatchedGeometry destroyed")
     }
     //-----------------------------------------------------------------------------
     void BatchedGeometry::clear()
     {
         // Remove the batch from the scene
         if (mSceneNode)
         {
             mSceneNode->removeAllChildren();
             mSceneManager->destroySceneNode(mSceneNode->getName());
             mSceneNode = 0;
         }
 
         // Reset bounds information
         mBoundsUndefined = true;
         //mBounds = AxisAlignedBox::BOX_NULL; why not?
         mCenter = Vector3::ZERO;
         mRadius = 0;
 
         // Delete each batch
         for (BatchMap::iterator i = mBatchs.begin(); i != mBatchs.end(); ++i)
         {
             delete i->second;
         }
         mBatchs.clear();
 
         mIsBuilt = false;
     }
     //-----------------------------------------------------------------------------
     void BatchedGeometry::build()
     {
         if (mIsBuilt)
             OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Invalid call to build() - celestial object is already batched (call clear() first)", "BatchedGeometry::build()");
 
         if (mBatchs.size() != 0)
         {
             // Finish bounds information
             mCenter = mBounds.getCenter();
             //Center the bounding box
             mBounds.setMinimum(mBounds.getMinimum() - mCenter);
             mBounds.setMaximum(mBounds.getMaximum() - mCenter);
             //Calculate BB radius
             mRadius = mBounds.getMaximum().length(); 
 
             // Create scene node
             mSceneNode = mParentSceneNode->createChildSceneNode(mCenter);
 
             // Build each batch
             for (BatchMap::iterator i = mBatchs.begin(); i != mBatchs.end(); ++i)
             {
                 i->second->build();
             }
         }
 
         // Attach the batch to the scene node
         mSceneNode->attachObject(this);
 
         // Debug
         mSceneNode->showBoundingBox(true); // TODO param
 
         mIsBuilt = true;
     }
     //-----------------------------------------------------------------------------
     void BatchedGeometry::_updateRenderQueue(RenderQueue* queue)
     {
         if (isVisible())
         {
             // If appropriate ask each batch to add itself
             // to the render queue 
             for (BatchMap::iterator i = mBatchs.begin(); i != mBatchs.end(); ++i)
             {
                 i->second->addSelfToRenderQueue(queue, 
                     getRenderQueueGroup());
             }
         }
     }
     //-----------------------------------------------------------------------------
     bool BatchedGeometry::isVisible()
     {
         // mVisible is an MovableObject attribute
         return mVisible && mWithinFarDistance;
     }
     //-----------------------------------------------------------------------------
     void BatchedGeometry::_notifyCurrentCamera(Camera* cam)
     {
         if (getRenderingDistance() == 0)
         {
             mWithinFarDistance = true;
         }
         else
         {
             //Calculate camera distance
             Vector3 camVec = convertToLocal(
                 cam->getDerivedPosition()) - mCenter;
             Real centerDistanceSquared = camVec.squaredLength();
             mMinDistanceSquared = std::max(0.0f, 
                 centerDistanceSquared - (mRadius * mRadius));
 
             // Note: centerDistanceSquared measures the distance 
             // between the camera and the center of the Batch,
             // while minDistanceSquared measures the closest distance
             // between the camera and the closest edge of the
             // geometry's bounding sphere.
 
             //Determine whether the BatchedGeometry is within 
             / the far rendering distance
             mWithinFarDistance = 
                 mMinDistanceSquared <= Math::Sqr(getRenderingDistance());
         }
     }
     //-----------------------------------------------------------------------------
     Ogre::Vector3 BatchedGeometry::convertToLocal(const Vector3& globalVec) const
     {
         assert(mParentSceneNode);
         //Convert from the given global position to 
         // the local coordinate system of the parent scene node.
         return (mParentSceneNode->getOrientation().Inverse() * globalVec);
     }
     //-----------------------------------------------------------------------------
     BatchedGeometry::BatchIterator BatchedGeometry::getBatchIterator() const
     {
         return BatchIterator((BatchMap&)mBatchs);
     }
     //-----------------------------------------------------------------------------
     void BatchedGeometry::addObject(const Vector3& position, 
         const Quaternion& orientation, const Vector3& scale)
     {
         // Create geometry
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         String format = "aa"; // TODO = getFormatString(...)
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         Batch* batch;
 
         /* TODO
         BatchIterator iter = mBatchs.find(format);
         if (iter != mBatchs.end())
             batch = iter->second;
         else
         { */
             batch = new Batch(this);
             mBatchs.insert(std::pair<String, Batch*>(format, batch));
         // }
 
         // cf. PagedGeometry addSubEntity()
         batch->addSub( position, orientation, scale );
 
         // Update the bounding box
         Matrix4 mat(orientation);
         mat.setScale(scale);
         AxisAlignedBox entBounds;
 
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // entBounds = ent->getBoundingBox();
         entBounds.setMinimum(Vector3(-100,-100,-100));
         entBounds.setMaximum(Vector3( 100, 100, 100));
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         entBounds.transform(mat);
 
         if (mBoundsUndefined)
         {
             mBounds.setMinimum(entBounds.getMinimum() + position);
             mBounds.setMaximum(entBounds.getMaximum() + position);
             mBoundsUndefined = false;
         }
         else
         {
             Vector3 min = mBounds.getMinimum();
             Vector3 max = mBounds.getMaximum();
             min.makeFloor(entBounds.getMinimum() + position);
             max.makeCeil(entBounds.getMaximum() + position);
             mBounds.setMinimum(min);
             mBounds.setMaximum(max);
         }
     }
     //-----------------------------------------------------------------------------
 }

OgreBatch.h


#ifndef __OGRE_BATCH_H__
 #define __OGRE_BATCH_H__
 
 #include "OGRE/OgrePrerequisites.h"
 #include "OGRE/OgreMovableObject.h"
 #include "OGRE/OgreMaterialManager.h"
 
 #define COUT(x) std::cout << x << std::endl; 
 
 namespace Ogre
 {
     // Forward definition
     class BatchedGeometry;
 
     /*
      *
      */
     class Batch : public Renderable
     {
     private:
         bool mIsBuilt;
 
         VertexData* mVertexData;
         IndexData* mIndexData;
 
         BatchedGeometry* mParent;
         MaterialPtr mMaterial;
 
         // NOTE : This should be recalculated every frame
         Technique* mBestTechnique; 
 
         // Should those be part of a struct?
         Vector3 mPosition;
         Quaternion mOrientation;
         Vector3 mScale;
         ColourValue mColour;
 
     public:
         Batch(BatchedGeometry* parent); //, SubEntity* ent);
         ~Batch();
 
         void build();
         void clear();
 
         void setMaterial(MaterialPtr& mat) { mMaterial = mat; }
         void setMaterialName(const String& mat) { 
             mMaterial = MaterialManager::getSingleton().getByName(mat); }
         inline String getMaterialName() const {
             return mMaterial->getName(); }
         const MaterialPtr& getMaterial() const { return mMaterial; }
 
         Technique* getTechnique() const { return mBestTechnique; }
 
         void getWorldTransforms(Matrix4* xform) const;
         const Quaternion& getWorldOrientation() const;
         const Vector3& getWorldPosition() const;
 
         bool castsShadows() const;
         const LightList& getLights() const;
 
         void addSelfToRenderQueue(RenderQueue* queue, uint8 group);
         void getRenderOperation(RenderOperation& operation);
         Real getSquaredViewDepth(const Camera* cam) const;
 
         /**
         * This function is used to make a unique clone of materials,
         * since the materials will be modified by the batch system
         * (and it wouldn't be good to modify the original materials
         * that the user may be using somewhere else).
         */
         Material* getMaterialClone(Material* material);
 
         // cf. PagedGeometry method:
         // void BatchedGeometry::SubBatch::addSubEntity(
         //     SubEntity *ent,  ....);
         void addSub(const Vector3& position, 
             const Quaternion& orientation, const Vector3& scale, 
             const ColourValue& color = ColourValue::White);
     };
 }
 #endif

OgreBatch.cpp


#include "OgreBatch.h"
 #include "OgreBatchedGeometry.h"
 
 #include "OGRE/OgreCamera.h"
 #include "OGRE/OgreSceneNode.h"
 #include "OGRE/OgreHardwareBufferManager.h"
 #include "OGRE/OgreTechnique.h"
 #include "OGRE/OgreRoot.h"
 #include "OGRE/OgreRenderSystem.h"
 #include "OGRE/OgreColourValue.h"
 
 namespace Ogre
 {
     //-----------------------------------------------------------------------------
     Batch::Batch(BatchedGeometry* parent) :
         mParent(parent)
     {
         mIsBuilt = false;
 
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // See PagedGeometry BatchedGeometry::SubBatch::SubBatch()
         //    Material *origMat = 
         //      ((MaterialPtr)MaterialManager::getSingleton().getByName(
         //         ent->getMaterialName())).getPointer();
         //    mMaterial = 
         //       MaterialManager::getSingleton().getByName(
         //          getMaterialClone(origMat)->getName());
         //    mMaterial = MaterialManager::getSingleton().create(
         //       "Test/ColourTest", 
         //       ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
         mMaterial->getTechnique(0)->getPass(0)
             ->setVertexColourTracking(TVC_AMBIENT);
 
         mMaterial->getTechnique(0)->getPass(0)->setSpecular(0,0,0,1);
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // See PagedGeometry to see how to clone PARTS of the entity data
         mVertexData = new VertexData();
         mIndexData = new IndexData();
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         // Reset vertex/index count
         mVertexData->vertexStart = 0;
         mVertexData->vertexCount = 0;
         mIndexData->indexStart = 0;
         mIndexData->indexCount = 0;
     }
     //-----------------------------------------------------------------------------
     Batch::~Batch()
     {
         clear();
         delete mVertexData;
         delete mIndexData;
     }
     //-----------------------------------------------------------------------------
     void Batch::addSelfToRenderQueue(RenderQueue* queue, uint8 group)
     {
         if (mIsBuilt)
         {
             // Update material technique based on camera distance
             assert(!mMaterial.isNull());
             mBestTechnique = mMaterial->getBestTechnique(
                 mMaterial->getLodIndexSquaredDepth(
                     mParent->getMinDistanceSquared()));
             queue->addRenderable(this, group);
         }
     }
     //-----------------------------------------------------------------------------
     bool Batch::castsShadows() const
     {
         return mParent->getCastShadows();
     }
     //-----------------------------------------------------------------------------
     void Batch::clear()
     {
         // If built, delete it
         if (mIsBuilt)
         {
                    //Delete buffers
                    mIndexData->indexBuffer.setNull();
                    mVertexData->vertexBufferBinding->unsetAllBindings();
 
                    // NOTE: If you are adding the elements each time
                    //       you must remove the previous one before
                    // mVertexData->vertexDeclaration->removeAllElements();
 
                    //Reset vertex/index count
                    mVertexData->vertexStart = 0;
                    mVertexData->vertexCount = 0;
                    mIndexData->indexStart = 0;
                    mIndexData->indexCount = 0;
         }
         mIsBuilt = false;
     }
     //-----------------------------------------------------------------------------
     Material* Batch::getMaterialClone(Material* material)
     {
         String name = material->getName() + "_Batch";
         MaterialPtr clone = 
             MaterialManager::getSingleton().getByName( name );
 
         if (clone.isNull())
             clone = material->clone(name);
         return clone.getPointer();
     }
     //-----------------------------------------------------------------------------
     void Batch::getRenderOperation(RenderOperation& operation)
     {
         operation.operationType = RenderOperation::OT_TRIANGLE_LIST;
         operation.srcRenderable = this;
         operation.useIndexes = true;
         operation.vertexData = mVertexData;
         operation.indexData = mIndexData;
 
         /* debug
         COUT(" 1 " << mVertexData->vertexCount)
         COUT(" 1 " << mVertexData->vertexCount)
         COUT(" 2 " << mVertexData->vertexDeclaration->getElementCount())
         COUT(" 3 " << mVertexData->vertexDeclaration->getVertexSize(0))
         COUT(" 4 " << mVertexData->vertexDeclaration->getElement(1)->getIndex())
         COUT(" 5 " << mVertexData->vertexDeclaration->getElement(1)->getSource())
         COUT(" 5 " << mIndexData->indexCount)
         COUT(" 6 " << mIndexData->indexBuffer->getIndexSize())
         COUT(" 7 " << mIndexData->indexBuffer->getNumIndexes())
         */
     }
     //-----------------------------------------------------------------------------
     Real Batch::getSquaredViewDepth(const Camera *camera) const
     {
         Vector3 pos = mParent->convertToLocal(
             camera->getDerivedPosition()) - mParent->getCenter();
 
         return pos.squaredLength();
     }
     //-----------------------------------------------------------------------------
     const LightList& Batch::getLights() const
     {
         return mParent->queryLights();
     }
     //-----------------------------------------------------------------------------
     void Batch::getWorldTransforms(Matrix4* xform) const
     {
         *xform = mParent->_getParentNodeFullTransform();
     }
     //-----------------------------------------------------------------------------
     const Quaternion& Batch::getWorldOrientation() const
     {
         return mParent->getSceneNode()->_getDerivedOrientation();
     }
     //-----------------------------------------------------------------------------
     const Vector3& Batch::getWorldPosition() const
     {
         return mParent->getSceneNode()->_getDerivedPosition();
     }
     //-----------------------------------------------------------------------------
     void Batch::addSub(const Vector3& position, const Quaternion& orientation, 
         const Vector3& scale, const ColourValue& color)
     {
         assert(!mIsBuilt);
         
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         // Use a geometry data struct to pass the data
         mVertexData->vertexCount = 8;
         mIndexData->indexCount = 36;
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         mPosition = position;
         mOrientation = orientation;
         mScale = scale;
         mColour = color;
 
         VertexElementType format = Root::getSingleton().getRenderSystem()
            ->getColourVertexElementType();
 
         switch (format)
         {
             case VET_COLOUR_ARGB:
                 std::swap(mColour.r, mColour.b);
                 break;
             case VET_COLOUR_ABGR:
                 break;
             default:
                 OGRE_EXCEPT(0, "Unknown RenderSystem color format", "Batch::addSub()");
                 break;
         }
     }
     //-----------------------------------------------------------------------------
     void Batch::build()
     {
         assert(!mIsBuilt);
 
         Vector3 batchCenter = mParent->getCenter();
 
         // See PagedGeometry::BatchedGeometry for how to set IT_32BIT
         // If I understand it correctly this is dependent 
         // on the number of vertices you want to batch
         HardwareIndexBuffer::IndexType destIndexType;
         destIndexType = HardwareIndexBuffer::IT_16BIT;
 
         // The vertex data at last
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
         VertexBufferBinding *vertBinding =
             mVertexData->vertexBufferBinding;
         VertexDeclaration *vertDecl = mVertexData->vertexDeclaration;
 
         //Allocate & lock the vertex buffers
         HardwareVertexBufferSharedPtr buffer = 
             HardwareBufferManager::getSingleton()
             .createVertexBuffer(24, 8, 
                    HardwareBuffer::HBU_STATIC_WRITE_ONLY);
 
         vertBinding->setBinding(0, buffer);
 
         float* destPtr = static_cast<float*>
            (buffer->lock(HardwareBuffer::HBL_DISCARD));
 
         // See Ogre Samples/CubeMapping/include/CubeMapping.h !
         VertexDeclaration* dec = mVertexData->vertexDeclaration;
         size_t offset = 0;
         dec->addElement(0, offset, VET_FLOAT3, VES_POSITION);
         offset += VertexElement::getTypeSize(VET_FLOAT3);
         dec->addElement(0, offset, VET_FLOAT3, VES_NORMAL);
 
         const float sqrt13 = 0.577350269f;
 
         *destPtr++ = -100; *destPtr++ = 100; *destPtr++ = -100; 
         *destPtr++ = -sqrt13; *destPtr++ = sqrt13; *destPtr++ = -sqrt13;
         *destPtr++ = 100; *destPtr++ = 100; *destPtr++ = -100; 
         *destPtr++ = sqrt13; *destPtr++ = sqrt13; *destPtr++ = -sqrt13;
         *destPtr++ = 100; *destPtr++ = -100; *destPtr++ = -100; 
         *destPtr++ = sqrt13; *destPtr++ = -sqrt13; *destPtr++ = -sqrt13;
         *destPtr++ = -100; *destPtr++ = -100; *destPtr++ = -100; 
         *destPtr++ = -sqrt13; *destPtr++ = -sqrt13; *destPtr++ = -sqrt13;
         *destPtr++ = -100; *destPtr++ = 100; *destPtr++ = 100; 
         *destPtr++ = -sqrt13; *destPtr++ = sqrt13; *destPtr++ = sqrt13;
         *destPtr++ = 100; *destPtr++ = 100; *destPtr++ = 100; 
         *destPtr++ = sqrt13; *destPtr++ = sqrt13; *destPtr++ = sqrt13;
         *destPtr++ = 100; *destPtr++ = -100; *destPtr++ = 100; 
         *destPtr++ = sqrt13; *destPtr++ = -sqrt13; *destPtr++ = sqrt13;
         *destPtr++ = -100; *destPtr++ = -100; *destPtr++ = 100; 
         *destPtr++ = -sqrt13; *destPtr++ = -sqrt13; *destPtr++ = sqrt13;
 
 
         //Allocate the index buffer
         mIndexData->indexBuffer = HardwareBufferManager::getSingleton()
             .createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 36,
                HardwareBuffer::HBU_STATIC_WRITE_ONLY);
 
         // As an alternative you can lock the buffer your self
         // and copy the data "manually"
         //uint16* indexBuffer16 = static_cast<uint16*>
         //   (mIndexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD));
 
         uint16 faces[36] = {
                 0,2,3,   0,1,2,   1,6,2,   1,5,6,
                 4,6,5,   4,7,6,   0,7,4,   0,3,7,
                 0,5,1,   0,4,5,   2,7,3,   2,6,7
         };
 
         //for (int i=0; i<36; ++i)
         //{
         //    *indexBuffer16++ = static_cast<uint16>(faces[i]);
         //}
         
         COUT(mIndexData->indexBuffer->getSizeInBytes());
         COUT(sizeof(faces));
         mIndexData->indexBuffer->writeData(
            0, mIndexData->indexBuffer->getSizeInBytes(), faces, true);
         // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
         //mIndexData->indexBuffer->unlock();
         buffer->unlock();
 
         mMaterial->load(); // TODO Not sure about this
         mIsBuilt = true;
     }
 //-----------------------------------------------------------------------------
 }

That's all folks.

--Steven 04:32, 2 April 2009 (UTC)


Alias: Geometry_Batching

<HR>
Creative Commons Copyright -- Some rights reserved.


THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.

BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.

1. Definitions

  • "Collective Work" means a work, such as a periodical issue, anthology or encyclopedia, in which the Work in its entirety in unmodified form, along with a number of other contributions, constituting separate and independent works in themselves, are assembled into a collective whole. A work that constitutes a Collective Work will not be considered a Derivative Work (as defined below) for the purposes of this License.
  • "Derivative Work" means a work based upon the Work or upon the Work and other pre-existing works, such as a translation, musical arrangement, dramatization, fictionalization, motion picture version, sound recording, art reproduction, abridgment, condensation, or any other form in which the Work may be recast, transformed, or adapted, except that a work that constitutes a Collective Work will not be considered a Derivative Work for the purpose of this License. For the avoidance of doubt, where the Work is a musical composition or sound recording, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered a Derivative Work for the purpose of this License.
  • "Licensor" means the individual or entity that offers the Work under the terms of this License.
  • "Original Author" means the individual or entity who created the Work.
  • "Work" means the copyrightable work of authorship offered under the terms of this License.
  • "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
  • "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, ShareAlike.

2. Fair Use Rights

Nothing in this license is intended to reduce, limit, or restrict any rights arising from fair use, first sale or other limitations on the exclusive rights of the copyright owner under copyright law or other applicable laws.

3. License Grant

Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:

  • to reproduce the Work, to incorporate the Work into one or more Collective Works, and to reproduce the Work as incorporated in the Collective Works;
  • to create and reproduce Derivative Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission the Work including as incorporated in Collective Works;
  • to distribute copies or phonorecords of, display publicly, perform publicly, and perform publicly by means of a digital audio transmission Derivative Works.
  • For the avoidance of doubt, where the work is a musical composition:
    • Performance Royalties Under Blanket Licenses. Licensor waives the exclusive right to collect, whether individually or via a performance rights society (e.g. ASCAP, BMI, SESAC), royalties for the public performance or public digital performance (e.g. webcast) of the Work.
    • Mechanical Rights and Statutory Royalties. Licensor waives the exclusive right to collect, whether individually or via a music rights society or designated agent (e.g. Harry Fox Agency), royalties for any phonorecord You create from the Work ("cover version") and distribute, subject to the compulsory license created by 17 USC Section 115 of the US Copyright Act (or the equivalent in other jurisdictions).
    • Webcasting Rights and Statutory Royalties. For the avoidance of doubt, where the Work is a sound recording, Licensor waives the exclusive right to collect, whether individually or via a performance-rights society (e.g. SoundExchange), royalties for the public digital performance (e.g. webcast) of the Work, subject to the compulsory license created by 17 USC Section 114 of the US Copyright Act (or the equivalent in other jurisdictions).


The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. All rights not expressly granted by Licensor are hereby reserved.

4. Restrictions

The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:

  • You may distribute, publicly display, publicly perform, or publicly digitally perform the Work only under the terms of this License, and You must include a copy of, or the Uniform Resource Identifier for, this License with every copy or phonorecord of the Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Work that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Work itself to be made subject to the terms of this License. If You create a Collective Work, upon notice from any Licensor You must, to the extent practicable, remove from the Collective Work any credit as required by clause 4(c), as requested. If You create a Derivative Work, upon notice from any Licensor You must, to the extent practicable, remove from the Derivative Work any credit as required by clause 4(c), as requested.
  • You may distribute, publicly display, publicly perform, or publicly digitally perform a Derivative Work only under the terms of this License, a later version of this License with the same License Elements as this License, or a Creative Commons iCommons license that contains the same License Elements as this License (e.g. Attribution-ShareAlike 2.5 Japan). You must include a copy of, or the Uniform Resource Identifier for, this License or other license specified in the previous sentence with every copy or phonorecord of each Derivative Work You distribute, publicly display, publicly perform, or publicly digitally perform. You may not offer or impose any terms on the Derivative Works that alter or restrict the terms of this License or the recipients' exercise of the rights granted hereunder, and You must keep intact all notices that refer to this License and to the disclaimer of warranties. You may not distribute, publicly display, publicly perform, or publicly digitally perform the Derivative Work with any technological measures that control access or use of the Work in a manner inconsistent with the terms of this License Agreement. The above applies to the Derivative Work as incorporated in a Collective Work, but this does not require the Collective Work apart from the Derivative Work itself to be made subject to the terms of this License.
  • If you distribute, publicly display, publicly perform, or publicly digitally perform the Work or any Derivative Works or Collective Works, You must keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or (ii) if the Original Author and/or Licensor designate another party or parties (e.g. a sponsor institute, publishing entity, journal) for attribution in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; the title of the Work if supplied; to the extent reasonably practicable, the Uniform Resource Identifier, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and in the case of a Derivative Work, a credit identifying the use of the Work in the Derivative Work (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). Such credit may be implemented in any reasonable manner; provided, however, that in the case of a Derivative Work or Collective Work, at a minimum such credit will appear where any other comparable authorship credit appears and in a manner at least as prominent as such other comparable authorship credit.

5. Representations, Warranties and Disclaimer

UNLESS OTHERWISE AGREED TO BY THE PARTIES IN WRITING, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE MATERIALS, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.

6. Limitation on Liability.

EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

7. Termination

  • This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Derivative Works or Collective Works from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
  • Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.

8. Miscellaneous

  • Each time You distribute or publicly digitally perform the Work or a Collective Work, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
  • Each time You distribute or publicly digitally perform a Derivative Work, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
  • If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  • No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
  • This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.