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 
00025 
00026 
00027 
00028 
00029 
00030 #ifndef RVE_RENDER_SERVER_BATCH_RENDERABLE_H
00031 #define RVE_RENDER_SERVER_BATCH_RENDERABLE_H
00032 
00033 #include <OGRE/OgreSimpleRenderable.h>
00034 #include <OGRE/OgreMaterial.h>
00035 
00036 #include "../pickable.h"
00037 #include "../renderer.h"
00038 
00039 namespace rve_render_server
00040 {
00041 
00042 template<typename Child, typename Description>
00043 class BatchRenderable : public Ogre::SimpleRenderable, public Pickable
00044 {
00045 public:
00046   BatchRenderable(const Description& desc, bool alpha)
00047   : desc_(desc)
00048   , alpha_(alpha)
00049   , count_(0)
00050   {
00051     pick_id_ = getRenderer()->allocatePickID(this);
00052   }
00053 
00054   ~BatchRenderable()
00055   {
00056     getRenderer()->deallocatePickID(pick_id_);
00057   }
00058 
00059   bool isEmpty()
00060   {
00061     return count_ == 0;
00062   }
00063 
00064   bool isFull()
00065   {
00066     return count_ == static_cast<Child*>(this)->getElementsPerVBO();
00067   }
00068 
00069   bool isAlpha()
00070   {
00071     return alpha_;
00072   }
00073 
00074   
00075   virtual void _notifyCurrentCamera(Ogre::Camera* camera)
00076   {
00077     SimpleRenderable::_notifyCurrentCamera( camera );
00078   }
00079 
00080   virtual Ogre::Real getBoundingRadius(void) const
00081   {
00082     return Ogre::Math::Sqrt(std::max(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
00083   }
00084 
00085   virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const
00086   {
00087     Ogre::Vector3 vMin, vMax, vMid, vDist;
00088     vMin = mBox.getMinimum();
00089     vMax = mBox.getMaximum();
00090     vMid = ((vMax - vMin) * 0.5) + vMin;
00091     vDist = cam->getDerivedPosition() - vMid;
00092 
00093     return vDist.squaredLength();
00094   }
00095 
00096   virtual void getWorldTransforms(Ogre::Matrix4* xform) const
00097   {
00098      *xform = m_matWorldTransform * getParentNode()->_getFullTransform();
00099   }
00100 
00101   virtual const Ogre::LightList& getLights() const
00102   {
00103     return queryLights();
00104   }
00105 
00106 protected:
00107   Description desc_;
00108   bool alpha_;
00109   uint32_t count_;
00110   uint32_t pick_id_;
00111 };
00112 
00113 } 
00114 
00115 #endif // RVE_RENDER_SERVER_BATCH_RENDERABLE_H
00116