Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreRenderQueue.cpp

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 © 2000-2002 The OGRE Team
00008 Also see acknowledgements in Readme.html
00009 
00010 This program is free software; you can redistribute it and/or modify it under
00011 the terms of the GNU Lesser General Public License as published by the Free Software
00012 Foundation; either version 2 of the License, or (at your option) any later
00013 version.
00014 
00015 This program is distributed in the hope that it will be useful, but WITHOUT
00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
00018 
00019 You should have received a copy of the GNU Lesser General Public License along with
00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00022 http://www.gnu.org/copyleft/lesser.txt.
00023 -----------------------------------------------------------------------------
00024 */
00025 #include "OgreStableHeaders.h"
00026 
00027 #include "OgreRenderQueue.h"
00028 
00029 #include "OgreRenderable.h"
00030 #include "OgreMaterial.h"
00031 #include "OgreRenderQueueSortingGrouping.h"
00032 #include "OgrePass.h"
00033 
00034 namespace Ogre {
00035 
00036     //---------------------------------------------------------------------
00037     RenderQueue::RenderQueue() : mSplitPassesByLightingType(false), mSplitNoShadowPasses(false)
00038     {
00039         // Create the 'main' queue up-front since we'll always need that
00040         mGroups.insert(
00041             RenderQueueGroupMap::value_type(
00042                 RENDER_QUEUE_MAIN, 
00043                 new RenderQueueGroup(this, mSplitPassesByLightingType, mSplitNoShadowPasses)
00044                 )
00045             );
00046 
00047         // set default queue
00048         mDefaultQueueGroup = RENDER_QUEUE_MAIN;
00049 
00050     }
00051     //---------------------------------------------------------------------
00052     RenderQueue::~RenderQueue()
00053     {
00054         
00055         // trigger the pending pass updates, otherwise we could leak
00056         Pass::processPendingPassUpdates();
00057         
00058         // Destroy the queues for good
00059         RenderQueueGroupMap::iterator i, iend;
00060         i = mGroups.begin();
00061         iend = mGroups.end();
00062         for (; i != iend; ++i)
00063         {
00064             delete i->second;
00065         }
00066         mGroups.clear();
00067 
00068 
00069 
00070 
00071     }
00072     //-----------------------------------------------------------------------
00073     void RenderQueue::addRenderable(Renderable* pRend, RenderQueueGroupID groupID, ushort priority)
00074     {
00075         // Find group
00076         RenderQueueGroup* pGroup = getQueueGroup(groupID);
00077 
00078         // tell material it's been used
00079         pRend->getMaterial()->touch();
00080         pGroup->addRenderable(pRend, priority);
00081 
00082     }
00083     //-----------------------------------------------------------------------
00084     void RenderQueue::clear(void)
00085     {
00086         // Clear the queues
00087         RenderQueueGroupMap::iterator i, iend;
00088         i = mGroups.begin();
00089         iend = mGroups.end();
00090         for (; i != iend; ++i)
00091         {
00092             i->second->clear();
00093         }
00094 
00095         // Now trigger the pending pass updates
00096         Pass::processPendingPassUpdates();
00097 
00098         // NB this leaves the items present (but empty)
00099         // We're assuming that frame-by-frame, the same groups are likely to 
00100         //  be used, so no point destroying the vectors and incurring the overhead
00101         //  that would cause, let them be destroyed in the destructor.
00102     }
00103     //-----------------------------------------------------------------------
00104     RenderQueue::QueueGroupIterator RenderQueue::_getQueueGroupIterator(void)
00105     {
00106         return QueueGroupIterator(mGroups.begin(), mGroups.end());
00107     }
00108     //-----------------------------------------------------------------------
00109     void RenderQueue::addRenderable(Renderable* pRend, ushort priority)
00110     {
00111         addRenderable(pRend, mDefaultQueueGroup, priority);
00112     }
00113     //-----------------------------------------------------------------------
00114     RenderQueueGroupID RenderQueue::getDefaultQueueGroup(void) const
00115     {
00116         return mDefaultQueueGroup;
00117     }
00118     //-----------------------------------------------------------------------
00119     void RenderQueue::setDefaultQueueGroup(RenderQueueGroupID grp)
00120     {
00121         mDefaultQueueGroup = grp;
00122     }
00123     //-----------------------------------------------------------------------
00124     RenderQueueGroup* RenderQueue::getQueueGroup(RenderQueueGroupID groupID)
00125     {
00126         // Find group
00127         RenderQueueGroupMap::iterator groupIt;
00128         RenderQueueGroup* pGroup;
00129 
00130         groupIt = mGroups.find(groupID);
00131         if (groupIt == mGroups.end())
00132         {
00133             // Insert new
00134             pGroup = new RenderQueueGroup(this, mSplitPassesByLightingType, mSplitNoShadowPasses);
00135             mGroups.insert(RenderQueueGroupMap::value_type(groupID, pGroup));
00136         }
00137         else
00138         {
00139             pGroup = groupIt->second;
00140         }
00141 
00142         return pGroup;
00143 
00144     }
00145     //-----------------------------------------------------------------------
00146     void RenderQueue::setSplitPassesByLightingType(bool split)
00147     {
00148         mSplitPassesByLightingType = split;
00149 
00150         RenderQueueGroupMap::iterator i, iend;
00151         i = mGroups.begin();
00152         iend = mGroups.end();
00153         for (; i != iend; ++i)
00154         {
00155             i->second->setSplitPassesByLightingType(split);
00156         }
00157     }
00158     //-----------------------------------------------------------------------
00159     void RenderQueue::setSplitNoShadowPasses(bool split)
00160     {
00161         mSplitNoShadowPasses = split;
00162 
00163         RenderQueueGroupMap::iterator i, iend;
00164         i = mGroups.begin();
00165         iend = mGroups.end();
00166         for (; i != iend; ++i)
00167         {
00168             i->second->setSplitNoShadowPasses(split);
00169         }
00170     }
00171 
00172 }
00173 

Copyright © 2002-2003 by The OGRE Team
Last modified Fri May 14 23:22:39 2004