source: OGRE/trunk/ogrenew/OgreMain/src/OgreRenderQueue.cpp @ 657

Revision 657, 6.5 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

RevLine 
[657]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26
27#include "OgreRenderQueue.h"
28
29#include "OgreRenderable.h"
30#include "OgreMaterial.h"
31#include "OgreRenderQueueSortingGrouping.h"
32#include "OgrePass.h"
33
34namespace Ogre {
35
36    //---------------------------------------------------------------------
37    RenderQueue::RenderQueue() : mSplitPassesByLightingType(false), mSplitNoShadowPasses(false)
38    {
39        // Create the 'main' queue up-front since we'll always need that
40        mGroups.insert(
41            RenderQueueGroupMap::value_type(
42                RENDER_QUEUE_MAIN,
43                new RenderQueueGroup(this, mSplitPassesByLightingType, mSplitNoShadowPasses)
44                )
45            );
46
47        // set default queue
48        mDefaultQueueGroup = RENDER_QUEUE_MAIN;
49                mDefaultRenderablePriority = OGRE_RENDERABLE_DEFAULT_PRIORITY;
50
51    }
52    //---------------------------------------------------------------------
53    RenderQueue::~RenderQueue()
54    {
55       
56        // trigger the pending pass updates, otherwise we could leak
57        Pass::processPendingPassUpdates();
58       
59        // Destroy the queues for good
60        RenderQueueGroupMap::iterator i, iend;
61        i = mGroups.begin();
62        iend = mGroups.end();
63        for (; i != iend; ++i)
64        {
65            delete i->second;
66        }
67        mGroups.clear();
68
69
70
71
72    }
73    //-----------------------------------------------------------------------
74    void RenderQueue::addRenderable(Renderable* pRend, RenderQueueGroupID groupID, ushort priority)
75    {
76        // Find group
77        RenderQueueGroup* pGroup = getQueueGroup(groupID);
78
79        // tell material it's been used
80        pRend->getMaterial()->touch();
81        pGroup->addRenderable(pRend, priority);
82
83    }
84    //-----------------------------------------------------------------------
85    void RenderQueue::clear(bool destroyPassMaps)
86    {
87        // Clear the queues
88        RenderQueueGroupMap::iterator i, iend;
89        i = mGroups.begin();
90        iend = mGroups.end();
91        for (; i != iend; ++i)
92        {
93            i->second->clear(destroyPassMaps);
94        }
95
96        // Now trigger the pending pass updates
97        Pass::processPendingPassUpdates();
98
99        // NB this leaves the items present (but empty)
100        // We're assuming that frame-by-frame, the same groups are likely to
101        //  be used, so no point destroying the vectors and incurring the overhead
102        //  that would cause, let them be destroyed in the destructor.
103    }
104    //-----------------------------------------------------------------------
105    RenderQueue::QueueGroupIterator RenderQueue::_getQueueGroupIterator(void)
106    {
107        return QueueGroupIterator(mGroups.begin(), mGroups.end());
108    }
109    //-----------------------------------------------------------------------
110    void RenderQueue::addRenderable(Renderable* pRend, RenderQueueGroupID groupID)
111    {
112        addRenderable(pRend, groupID, mDefaultRenderablePriority);
113    }
114        //-----------------------------------------------------------------------
115    void RenderQueue::addRenderable(Renderable* pRend)
116    {
117        addRenderable(pRend, mDefaultQueueGroup, mDefaultRenderablePriority);
118    }
119    //-----------------------------------------------------------------------
120    RenderQueueGroupID RenderQueue::getDefaultQueueGroup(void) const
121    {
122        return mDefaultQueueGroup;
123    }
124    //-----------------------------------------------------------------------
125    void RenderQueue::setDefaultQueueGroup(RenderQueueGroupID grp)
126    {
127        mDefaultQueueGroup = grp;
128    }
129    //-----------------------------------------------------------------------
130    ushort RenderQueue::getDefaultRenderablePriority(void) const
131    {
132        return mDefaultRenderablePriority;
133    }
134    //-----------------------------------------------------------------------
135    void RenderQueue::setDefaultRenderablePriority(ushort priority)
136    {
137        mDefaultRenderablePriority = priority;
138    }
139       
140       
141        //-----------------------------------------------------------------------
142        RenderQueueGroup* RenderQueue::getQueueGroup(RenderQueueGroupID groupID)
143        {
144                // Find group
145                RenderQueueGroupMap::iterator groupIt;
146                RenderQueueGroup* pGroup;
147
148                groupIt = mGroups.find(groupID);
149                if (groupIt == mGroups.end())
150                {
151                        // Insert new
152                        pGroup = new RenderQueueGroup(this, mSplitPassesByLightingType, mSplitNoShadowPasses);
153                        mGroups.insert(RenderQueueGroupMap::value_type(groupID, pGroup));
154                }
155                else
156                {
157                        pGroup = groupIt->second;
158                }
159
160                return pGroup;
161
162        }
163    //-----------------------------------------------------------------------
164    void RenderQueue::setSplitPassesByLightingType(bool split)
165    {
166        mSplitPassesByLightingType = split;
167
168        RenderQueueGroupMap::iterator i, iend;
169        i = mGroups.begin();
170        iend = mGroups.end();
171        for (; i != iend; ++i)
172        {
173            i->second->setSplitPassesByLightingType(split);
174        }
175    }
176    //-----------------------------------------------------------------------
177    void RenderQueue::setSplitNoShadowPasses(bool split)
178    {
179        mSplitNoShadowPasses = split;
180
181        RenderQueueGroupMap::iterator i, iend;
182        i = mGroups.begin();
183        iend = mGroups.end();
184        for (; i != iend; ++i)
185        {
186            i->second->setSplitNoShadowPasses(split);
187        }
188    }
189
190}
191
Note: See TracBrowser for help on using the repository browser.