lugre_fastbatch.h

Go to the documentation of this file.
00001 /*
00002 http://www.opensource.org/licenses/mit-license.php  (MIT-License)
00003 
00004 Copyright (c) 2007 Lugre-Team
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022 THE SOFTWARE.
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 //~ #include <OgreSceneNode.h>
00037 //~ #include <OgreMaterialManager.h>
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; // see lugre_meshbuffer.h  
00054 class cBufferedSubMesh; // see lugre_meshbuffer.h   
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     // utils
00089     inline const Ogre::Vector3&     GetBoundsCenter     () const { return mvBoundsCenter; }
00090     
00091     // Ogre::MovableObject implementation
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     // implementation details
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         // Ogre::Renderable implementation 
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         //~ Ogre::Technique*            getTechnique            () const { return bestTechnqiue; }
00171         //~ bool                        castsShadows            (void) const { return mpParent->getCastShadows(); }
00172     };
00173 };
00174 
00175 };
00176 
00177 #endif

Generated on Wed Feb 8 06:00:12 2012 for cpp by  doxygen 1.5.6