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 
00033 namespace Ogre {
00034 
00035     //---------------------------------------------------------------------
00036     RenderQueue::RenderQueue()
00037     {
00038         // Create the 'main' queue up-front since we'll always need that
00039         mGroups.insert(RenderQueueGroupMap::value_type(RENDER_QUEUE_MAIN, new RenderQueueGroup()));
00040 
00041         // set default queue
00042         mDefaultQueueGroup = RENDER_QUEUE_MAIN;
00043 
00044     }
00045     //---------------------------------------------------------------------
00046     RenderQueue::~RenderQueue()
00047     {
00048         // Destroy the queues for good
00049         RenderQueueGroupMap::iterator i, iend;
00050         i = mGroups.begin();
00051         iend = mGroups.end();
00052         for (; i != iend; ++i)
00053         {
00054             delete i->second;
00055         }
00056         mGroups.clear();
00057 
00058 
00059     }
00060     //-----------------------------------------------------------------------
00061     void RenderQueue::addRenderable(Renderable* pRend, RenderQueueGroupID groupID, ushort priority)
00062     {
00063         // Find group
00064         RenderQueueGroupMap::iterator groupIt;
00065         RenderQueueGroup* pGroup;
00066 
00067         groupIt = mGroups.find(groupID);
00068         if (groupIt == mGroups.end())
00069         {
00070             // Insert new
00071             pGroup = new RenderQueueGroup();
00072             mGroups.insert(RenderQueueGroupMap::value_type(groupID, pGroup));
00073         }
00074         else
00075         {
00076             pGroup = groupIt->second;
00077         }
00078 
00079         // tell material it's been used
00080         pRend->getMaterial()->touch();
00081         pGroup->addRenderable(pRend, priority);
00082 
00083     }
00084     //-----------------------------------------------------------------------
00085     void RenderQueue::clear(void)
00086     {
00087         // Clear the queues
00088         RenderQueueGroupMap::iterator i, iend;
00089         i = mGroups.begin();
00090         iend = mGroups.end();
00091         for (; i != iend; ++i)
00092         {
00093             i->second->clear();
00094         }
00095 
00096         // NB this leaves the items present (but empty)
00097         // We're assuming that frame-by-frame, the same groups are likely to 
00098         //  be used, so no point destroying the vectors and incurring the overhead
00099         //  that would cause, let them be destroyed in the destructor.
00100     }
00101     //-----------------------------------------------------------------------
00102     RenderQueue::QueueGroupIterator RenderQueue::_getQueueGroupIterator(void)
00103     {
00104         return QueueGroupIterator(mGroups.begin(), mGroups.end());
00105     }
00106     //-----------------------------------------------------------------------
00107     void RenderQueue::addRenderable(Renderable* pRend, ushort priority)
00108     {
00109         addRenderable(pRend, mDefaultQueueGroup, priority);
00110     }
00111     //-----------------------------------------------------------------------
00112     RenderQueueGroupID RenderQueue::getDefaultQueueGroup(void) const
00113     {
00114         return mDefaultQueueGroup;
00115     }
00116     //-----------------------------------------------------------------------
00117     void RenderQueue::setDefaultQueueGroup(RenderQueueGroupID grp)
00118     {
00119         mDefaultQueueGroup = grp;
00120     }
00121 }
00122 

Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:24 2004