OgreRenderQueue.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __RenderQueue_H__
00029 #define __RenderQueue_H__
00030 
00031 #include "OgreHeaderPrefix.h"
00032 #include "OgrePrerequisites.h"
00033 #include "OgreIteratorWrappers.h"
00034 
00035 namespace Ogre {
00036 
00037     class Camera;
00038     class MovableObject;
00039     struct VisibleObjectsBoundsInfo;
00040 
00053     enum RenderQueueGroupID
00054     {
00056         RENDER_QUEUE_BACKGROUND = 0,
00058         RENDER_QUEUE_SKIES_EARLY = 5,
00059         RENDER_QUEUE_1 = 10,
00060         RENDER_QUEUE_2 = 20,
00061         RENDER_QUEUE_WORLD_GEOMETRY_1 = 25,
00062         RENDER_QUEUE_3 = 30,
00063         RENDER_QUEUE_4 = 40,
00065         RENDER_QUEUE_MAIN = 50,
00066         RENDER_QUEUE_6 = 60,
00067         RENDER_QUEUE_7 = 70,
00068         RENDER_QUEUE_WORLD_GEOMETRY_2 = 75,
00069         RENDER_QUEUE_8 = 80,
00070         RENDER_QUEUE_9 = 90,
00072         RENDER_QUEUE_SKIES_LATE = 95,
00074         RENDER_QUEUE_OVERLAY = 100, 
00076         RENDER_QUEUE_MAX = 105
00077     };
00078 
00079     #define OGRE_RENDERABLE_DEFAULT_PRIORITY  100
00080 
00092     class _OgreExport RenderQueue : public RenderQueueAlloc
00093     {
00094     public:
00095 
00096         class RenderQueueGroupMap
00097         {
00098         public:
00099             class value_type
00100             {
00101             public:
00102                 value_type(uint8 _f, RenderQueueGroup* _g) : first(_f), second(_g)
00103                 {
00104 
00105                 }
00106                 value_type() : first(0), second(0)
00107                 {
00108 
00109                 }
00110                 uint8 first;
00111                 RenderQueueGroup* second;
00112             };
00113 
00114             typedef uint8 key_type;
00115             typedef RenderQueueGroup* mapped_type;
00116             typedef value_type& reference;
00117             typedef value_type* pointer;
00118             typedef const value_type& const_reference;
00119             typedef const value_type* const_pointer;
00120             typedef vector<value_type >::type GroupVector;
00121 
00122             class iterator
00123             {
00124                 friend class RenderQueueGroupMap;
00125             public:
00126 
00127                 iterator() : mRenderQueueGroupMap(0), mIndex(RENDER_QUEUE_MAX)
00128                 {
00129                 }
00130 
00131                 iterator(const RenderQueueGroupMap* _mRenderQueueGroupMap, uint8 _index) : mRenderQueueGroupMap(_mRenderQueueGroupMap), mIndex(_index)
00132                 {
00133                 }
00134 
00135                 const_reference operator*() const
00136                 {   
00137                     assert(this->mRenderQueueGroupMap);
00138 
00139                     return mRenderQueueGroupMap->mGroupVector[mIndex];
00140                 }
00141 
00142                 const_pointer operator->() const
00143                 {
00144                     assert(this->mRenderQueueGroupMap);
00145 
00146                     return &(mRenderQueueGroupMap->mGroupVector[mIndex]);
00147                 }
00148 
00149                 iterator& operator++()
00150                 {
00151                     assert(this->mRenderQueueGroupMap);
00152 
00153                     while(mIndex < mRenderQueueGroupMap->mMaxID)
00154                     {
00155                         ++mIndex;
00156                         if(mRenderQueueGroupMap->mGroupVector[mIndex].second != 0)
00157                         {
00158                             break;
00159                         }
00160                     }
00161                     return (*this);
00162                 }
00163 
00164                 const iterator& operator++()const
00165                 {
00166                     assert(this->mRenderQueueGroupMap);
00167 
00168                     while(mIndex < mRenderQueueGroupMap->mMaxID)
00169                     {
00170                         ++mIndex;
00171                         if(mRenderQueueGroupMap->mGroupVector[mIndex].second != 0)
00172                         {
00173                             break;
00174                         }
00175                     }
00176                     return (*this);
00177                 }
00178 
00179                 iterator operator++(int)
00180                 {
00181                     assert(this->mRenderQueueGroupMap);
00182 
00183                     iterator temp = *this;
00184                     while(mIndex < mRenderQueueGroupMap->mMaxID)
00185                     {
00186                         ++mIndex;
00187                         if(mRenderQueueGroupMap->mGroupVector[mIndex].second != 0)
00188                         {
00189                             break;
00190                         }
00191                     }
00192                     return (temp);
00193                 }
00194 
00195                 const iterator operator++(int)const
00196                 {
00197                     assert(this->mRenderQueueGroupMap);
00198 
00199                     const_iterator temp = *this;
00200                     while(mIndex < mRenderQueueGroupMap->mMaxID)
00201                     {
00202                         ++mIndex;
00203                         if(mRenderQueueGroupMap->mGroupVector[mIndex].second != 0)
00204                         {
00205                             break;
00206                         }
00207                     }
00208                     return (temp);
00209                 }
00210 
00211                 bool operator !=(const iterator& o)const
00212                 {
00213                     assert(mRenderQueueGroupMap);
00214                     assert(o.mRenderQueueGroupMap);
00215                     assert(o.mRenderQueueGroupMap == this->mRenderQueueGroupMap);
00216                     if( o.mIndex != this->mIndex)
00217                         return true;
00218                     return false;
00219                 }
00220 
00221                 bool operator ==(const iterator& o)const
00222                 {
00223                     assert(this->mRenderQueueGroupMap);
00224                     assert(o.mRenderQueueGroupMap);
00225                     assert(o.mRenderQueueGroupMap == this->mRenderQueueGroupMap);
00226                     if(o.mIndex == this->mIndex)
00227                     {
00228                         return true;
00229                     }
00230                     return false;
00231                 }
00232             protected:
00233                 const RenderQueueGroupMap* mRenderQueueGroupMap;
00234                 mutable uint8 mIndex;
00235             };
00236 
00237             typedef const iterator const_iterator;
00238             
00239             RenderQueueGroupMap() : mMinID(RENDER_QUEUE_MAX), mMaxID(RENDER_QUEUE_MAX)
00240             {
00241                 mGroupVector.resize(RENDER_QUEUE_MAX + 2);
00242             }
00243 
00244             void insert(value_type v)
00245             {
00246                 mGroupVector[v.first] = v;
00247                 if(v.first < mMinID)
00248                 {
00249                     mMinID = v.first;
00250                 }
00251 
00252                 if(v.first >= mMaxID || mMaxID == RENDER_QUEUE_MAX)
00253                 {
00254                     mMaxID = v.first + 1;
00255                 }
00256             }
00257 
00258             iterator find(uint8 key)
00259             {
00260                 if(mGroupVector[key].second == 0)
00261                 {
00262                     return iterator(this, mMaxID);
00263                 }
00264                 else
00265                 {
00266                     return iterator(this, key);
00267                 }
00268             }
00269 
00270             iterator begin()
00271             {
00272                 return iterator(this, mMinID);
00273             }
00274 
00275             iterator end()
00276             {
00277                 return iterator(this, mMaxID);
00278             }
00279 
00280             const_iterator begin() const
00281             {
00282                 return iterator(this, mMinID);
00283             }
00284 
00285             const_iterator end() const
00286             {
00287                 return iterator(this, mMaxID);
00288             }
00289             
00290             void clear()
00291             {
00292                 mGroupVector.reserve(RENDER_QUEUE_MAX + 2);
00293                 mGroupVector.clear();
00294                 mGroupVector.resize(RENDER_QUEUE_MAX + 2);
00295                 mMinID = RENDER_QUEUE_MAX;
00296                 mMaxID = RENDER_QUEUE_MAX;
00297             }
00298         protected:
00299             uint8 mMinID;
00300             uint8 mMaxID;
00301             GroupVector mGroupVector;
00302         };
00303 
00304         typedef MapIterator<RenderQueueGroupMap> QueueGroupIterator;
00305         typedef ConstMapIterator<RenderQueueGroupMap> ConstQueueGroupIterator;
00306 
00312         class _OgreExport RenderableListener
00313         {
00314         public:
00315             RenderableListener() {}
00316             virtual ~RenderableListener() {}
00317 
00337             virtual bool renderableQueued(Renderable* rend, uint8 groupID, 
00338                 ushort priority, Technique** ppTech, RenderQueue* pQueue) = 0;
00339         };
00340     protected:
00341         RenderQueueGroupMap mGroups;
00343         uint8 mDefaultQueueGroup;
00345         ushort mDefaultRenderablePriority;
00346 
00347         bool mSplitPassesByLightingType;
00348         bool mSplitNoShadowPasses;
00349         bool mShadowCastersCannotBeReceivers;
00350 
00351         RenderableListener* mRenderableListener;
00352     public:
00353         RenderQueue();
00354         virtual ~RenderQueue();
00355 
00360         void clear(bool destroyPassMaps = false);
00361 
00367         RenderQueueGroup* getQueueGroup(uint8 qid);
00368 
00391         void addRenderable(Renderable* pRend, uint8 groupID, ushort priority);
00392 
00410         void addRenderable(Renderable* pRend, uint8 groupId);
00411 
00424         void addRenderable(Renderable* pRend);
00425         
00429         uint8 getDefaultQueueGroup(void) const;
00430 
00435         void setDefaultRenderablePriority(ushort priority);
00436 
00440         ushort getDefaultRenderablePriority(void) const;
00441 
00446         void setDefaultQueueGroup(uint8 grp);
00447         
00449         QueueGroupIterator _getQueueGroupIterator(void);
00450         ConstQueueGroupIterator _getQueueGroupIterator(void) const;
00451 
00455         void setSplitPassesByLightingType(bool split);
00456 
00460         bool getSplitPassesByLightingType(void) const;
00461 
00466         void setSplitNoShadowPasses(bool split);
00467 
00472         bool getSplitNoShadowPasses(void) const;
00473 
00477         void setShadowCastersCannotBeReceivers(bool ind);
00478 
00482         bool getShadowCastersCannotBeReceivers(void) const;
00483 
00489         void setRenderableListener(RenderableListener* listener)
00490         { mRenderableListener = listener; }
00491 
00492         RenderableListener* getRenderableListener(void) const
00493         { return mRenderableListener; }
00494 
00497         void merge( const RenderQueue* rhs );
00503         void processVisibleObject(MovableObject* mo, 
00504             Camera* cam, 
00505             bool onlyShadowCasters, 
00506             VisibleObjectsBoundsInfo* visibleBounds);
00507 
00508     };
00509 
00513 }
00514 
00515 #include "OgreHeaderSuffix.h"
00516 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:25 2012