lugre_fastbatch.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LUGRE_FASTBATCH_H
00025 #define LUGRE_FASTBATCH_H
00026
00027 #include "lugre_smartptr.h"
00028 #include <OgreVector3.h>
00029 #include <OgreQuaternion.h>
00030 #include <OgreColourValue.h>
00031 #include <OgrePrerequisites.h>
00032 #include <OgreRenderable.h>
00033 #include <OgreMovableObject.h>
00034 #include <OgreAxisAlignedBox.h>
00035 #include <OgreMaterial.h>
00036
00037
00038
00039 #include <map>
00040 #include <OgreCommon.h>
00041 #include <OgreRenderOperation.h>
00042 #include <OgreMatrix4.h>
00043 #include <OgrePlane.h>
00044 #include <OgreGpuProgram.h>
00045 #include <OgreVector4.h>
00046 #include <OgreException.h>
00047
00048 class lua_State;
00049 using namespace Ogre;
00050
00051 namespace Lugre {
00052
00053 class cBufferedMesh;
00054 class cBufferedSubMesh;
00055
00067 class cFastBatch : public Ogre::MovableObject , public cSmartPointable { public:
00068
00069 cFastBatch ();
00070 virtual ~cFastBatch ();
00071
00074 void AddMesh (cBufferedMesh& pBufferedMesh,
00075 const Ogre::Vector3& vPos,
00076 const Ogre::Quaternion& qRot =Ogre::Quaternion::IDENTITY,
00077 const Ogre::Vector3& vScale =Ogre::Vector3::UNIT_SCALE,
00078 const Ogre::ColourValue& vCol =Ogre::ColourValue::White,
00079 const bool bColourOverride=false,
00080 const float fOrderValue=0);
00081
00083 void Build ();
00084
00086 void SetDisplayRange (const float fMin,const float fMax);
00087
00088
00089 inline const Ogre::Vector3& GetBoundsCenter () const { return mvBoundsCenter; }
00090
00091
00092
00093 virtual void _updateRenderQueue (Ogre::RenderQueue *queue);
00094 virtual const Ogre::AxisAlignedBox& getBoundingBox (void) const { return mBounds; }
00095 #if OGRE_VERSION >= 0x10600
00096 virtual void visitRenderables (Ogre::Renderable::Visitor *p ,bool b) {}
00097 #endif
00098 Ogre::Real getBoundingRadius (void) const { return mfBoundRad; }
00099 virtual const Ogre::String& getMovableType (void) const;
00100
00101
00102 private :
00103 class cSubBatch;
00104 typedef std::map<std::string,cSubBatch*>::iterator tSubBatchMapIterator;
00105 typedef std::map<std::string,cSubBatch*> tSubBatchMap;
00106 tSubBatchMap mSubBatches;
00107 Ogre::AxisAlignedBox mBounds;
00108 Ogre::Vector3 mvBoundsCenter;
00109 Ogre::Real mfBoundRad;
00110
00112 class cInstance { public:
00113 cBufferedSubMesh* mpBufferedSubMesh;
00114 Ogre::Vector3 mvPos;
00115 Ogre::Quaternion mqRot;
00116 Ogre::Vector3 mvScale;
00117 Ogre::ColourValue mvCol;
00118 bool mbColourOverride;
00119
00120 cInstance ( cBufferedSubMesh* pBufferedSubMesh,
00121 const Ogre::Vector3& vPos,
00122 const Ogre::Quaternion& qRot,
00123 const Ogre::Vector3& vScale,
00124 const Ogre::ColourValue& vCol,
00125 const bool bColourOverride) :
00126 mpBufferedSubMesh(pBufferedSubMesh),
00127 mvPos(vPos), mqRot(qRot), mvScale(vScale), mvCol(vCol),
00128 mbColourOverride(bColourOverride) {}
00129 };
00130
00132 class cSubBatch : public Ogre::Renderable { public:
00133 enum { kCommonSourceIndex = 0 };
00134 int miVertexSize;
00135 int miTotalIndexCount;
00136 std::multimap<float,cInstance> mInstances;
00137 std::map<float,int> mOrderValueOffsets;
00138 Ogre::VertexData* mpVertexData;
00139 Ogre::IndexData* mpIndexData;
00140 static Ogre::RenderSystem* mpRenderSys;
00141 bool mbAddColourAtEnd;
00142 Ogre::VertexElementType miPreferredColourFormat;
00143 Ogre::MaterialPtr mpMat;
00144 cFastBatch* mpParent;
00145
00146 cSubBatch (cFastBatch* pParent,cBufferedSubMesh& pBufferedSubMesh, const bool bColourOverride);
00147 ~cSubBatch ();
00148
00149 void AddInstance (cInstance pInstance,const float fOrderValue);
00150
00151 void SetDisplayRange (const float fMin,const float fMax);
00152
00153 void Build ();
00154
00155
00156
00157 inline void setMaterial (Ogre::MaterialPtr &mat) { mpMat = mat; }
00158 const Ogre::MaterialPtr& getMaterial (void) const { return mpMat; }
00159 void setMaterialName (const Ogre::String &mat);
00160 Ogre::String getMaterialName () const;
00161
00162 void getRenderOperation (Ogre::RenderOperation& op);
00163 virtual Ogre::Real getSquaredViewDepth (const Ogre::Camera* cam) const;
00164 const Ogre::LightList& getLights (void) const { return mpParent->queryLights(); }
00165
00166 void getWorldTransforms (Ogre::Matrix4* xform) const;
00167 const Ogre::Quaternion& getWorldOrientation (void) const;
00168 const Ogre::Vector3& getWorldPosition (void) const;
00169
00170
00171
00172 };
00173 };
00174
00175 };
00176
00177 #endif