1 | /* |
---|
2 | ----------------------------------------------------------------------------- |
---|
3 | This source file is part of OGRE |
---|
4 | (Object-oriented Graphics Rendering Engine) |
---|
5 | For the latest info, see http://www.ogre3d.org/ |
---|
6 | |
---|
7 | Copyright (c) 2000-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software; you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation; either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreStableHeaders.h" |
---|
30 | |
---|
31 | #include "OgreRenderQueue.h" |
---|
32 | |
---|
33 | #include "OgreRenderable.h" |
---|
34 | #include "OgreMaterial.h" |
---|
35 | #include "OgreRenderQueueSortingGrouping.h" |
---|
36 | #include "OgrePass.h" |
---|
37 | #include "OgreMaterialManager.h" |
---|
38 | |
---|
39 | |
---|
40 | namespace Ogre { |
---|
41 | |
---|
42 | //--------------------------------------------------------------------- |
---|
43 | RenderQueue::RenderQueue() |
---|
44 | : mSplitPassesByLightingType(false) |
---|
45 | , mSplitNoShadowPasses(false) |
---|
46 | , mShadowCastersCannotBeReceivers(false) |
---|
47 | , mRenderableListener(0) |
---|
48 | { |
---|
49 | // Create the 'main' queue up-front since we'll always need that |
---|
50 | mGroups.insert( |
---|
51 | RenderQueueGroupMap::value_type( |
---|
52 | RENDER_QUEUE_MAIN, |
---|
53 | new RenderQueueGroup(this, |
---|
54 | mSplitPassesByLightingType, |
---|
55 | mSplitNoShadowPasses, |
---|
56 | mShadowCastersCannotBeReceivers) |
---|
57 | ) |
---|
58 | ); |
---|
59 | |
---|
60 | // set default queue |
---|
61 | mDefaultQueueGroup = RENDER_QUEUE_MAIN; |
---|
62 | mDefaultRenderablePriority = OGRE_RENDERABLE_DEFAULT_PRIORITY; |
---|
63 | |
---|
64 | } |
---|
65 | //--------------------------------------------------------------------- |
---|
66 | RenderQueue::~RenderQueue() |
---|
67 | { |
---|
68 | |
---|
69 | // trigger the pending pass updates, otherwise we could leak |
---|
70 | Pass::processPendingPassUpdates(); |
---|
71 | |
---|
72 | // Destroy the queues for good |
---|
73 | RenderQueueGroupMap::iterator i, iend; |
---|
74 | i = mGroups.begin(); |
---|
75 | iend = mGroups.end(); |
---|
76 | for (; i != iend; ++i) |
---|
77 | { |
---|
78 | delete i->second; |
---|
79 | } |
---|
80 | mGroups.clear(); |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | } |
---|
86 | //----------------------------------------------------------------------- |
---|
87 | void RenderQueue::addRenderable(Renderable* pRend, uint8 groupID, ushort priority) |
---|
88 | { |
---|
89 | // Find group |
---|
90 | RenderQueueGroup* pGroup = getQueueGroup(groupID); |
---|
91 | |
---|
92 | |
---|
93 | Technique* pTech; |
---|
94 | |
---|
95 | // tell material it's been used |
---|
96 | if (!pRend->getMaterial().isNull()) |
---|
97 | pRend->getMaterial()->touch(); |
---|
98 | |
---|
99 | // Check material & technique supplied (the former since the default implementation |
---|
100 | // of getTechnique is based on it for backwards compatibility |
---|
101 | if(pRend->getMaterial().isNull() || !(pTech = pRend->getTechnique())) |
---|
102 | { |
---|
103 | // Use default base white |
---|
104 | MaterialPtr baseWhite = MaterialManager::getSingleton().getByName("BaseWhite"); |
---|
105 | pTech = baseWhite->getTechnique(0); |
---|
106 | } |
---|
107 | |
---|
108 | if (mRenderableListener) |
---|
109 | { |
---|
110 | // Allow listener to override technique and to abort |
---|
111 | if (!mRenderableListener->renderableQueued(pRend, groupID, priority, &pTech)) |
---|
112 | return; // rejected |
---|
113 | |
---|
114 | // tell material it's been used (incase changed) |
---|
115 | pTech->getParent()->touch(); |
---|
116 | } |
---|
117 | |
---|
118 | pGroup->addRenderable(pRend, pTech, priority); |
---|
119 | |
---|
120 | } |
---|
121 | //----------------------------------------------------------------------- |
---|
122 | void RenderQueue::clear(bool destroyPassMaps) |
---|
123 | { |
---|
124 | // Clear the queues |
---|
125 | RenderQueueGroupMap::iterator i, iend; |
---|
126 | i = mGroups.begin(); |
---|
127 | iend = mGroups.end(); |
---|
128 | for (; i != iend; ++i) |
---|
129 | { |
---|
130 | i->second->clear(destroyPassMaps); |
---|
131 | } |
---|
132 | |
---|
133 | // Now trigger the pending pass updates |
---|
134 | Pass::processPendingPassUpdates(); |
---|
135 | |
---|
136 | // NB this leaves the items present (but empty) |
---|
137 | // We're assuming that frame-by-frame, the same groups are likely to |
---|
138 | // be used, so no point destroying the vectors and incurring the overhead |
---|
139 | // that would cause, let them be destroyed in the destructor. |
---|
140 | } |
---|
141 | //----------------------------------------------------------------------- |
---|
142 | RenderQueue::QueueGroupIterator RenderQueue::_getQueueGroupIterator(void) |
---|
143 | { |
---|
144 | return QueueGroupIterator(mGroups.begin(), mGroups.end()); |
---|
145 | } |
---|
146 | //----------------------------------------------------------------------- |
---|
147 | void RenderQueue::addRenderable(Renderable* pRend, uint8 groupID) |
---|
148 | { |
---|
149 | addRenderable(pRend, groupID, mDefaultRenderablePriority); |
---|
150 | } |
---|
151 | //----------------------------------------------------------------------- |
---|
152 | void RenderQueue::addRenderable(Renderable* pRend) |
---|
153 | { |
---|
154 | addRenderable(pRend, mDefaultQueueGroup, mDefaultRenderablePriority); |
---|
155 | } |
---|
156 | //----------------------------------------------------------------------- |
---|
157 | uint8 RenderQueue::getDefaultQueueGroup(void) const |
---|
158 | { |
---|
159 | return mDefaultQueueGroup; |
---|
160 | } |
---|
161 | //----------------------------------------------------------------------- |
---|
162 | void RenderQueue::setDefaultQueueGroup(uint8 grp) |
---|
163 | { |
---|
164 | mDefaultQueueGroup = grp; |
---|
165 | } |
---|
166 | //----------------------------------------------------------------------- |
---|
167 | ushort RenderQueue::getDefaultRenderablePriority(void) const |
---|
168 | { |
---|
169 | return mDefaultRenderablePriority; |
---|
170 | } |
---|
171 | //----------------------------------------------------------------------- |
---|
172 | void RenderQueue::setDefaultRenderablePriority(ushort priority) |
---|
173 | { |
---|
174 | mDefaultRenderablePriority = priority; |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | //----------------------------------------------------------------------- |
---|
179 | RenderQueueGroup* RenderQueue::getQueueGroup(uint8 groupID) |
---|
180 | { |
---|
181 | // Find group |
---|
182 | RenderQueueGroupMap::iterator groupIt; |
---|
183 | RenderQueueGroup* pGroup; |
---|
184 | |
---|
185 | groupIt = mGroups.find(groupID); |
---|
186 | if (groupIt == mGroups.end()) |
---|
187 | { |
---|
188 | // Insert new |
---|
189 | pGroup = new RenderQueueGroup(this, |
---|
190 | mSplitPassesByLightingType, |
---|
191 | mSplitNoShadowPasses, |
---|
192 | mShadowCastersCannotBeReceivers); |
---|
193 | mGroups.insert(RenderQueueGroupMap::value_type(groupID, pGroup)); |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | pGroup = groupIt->second; |
---|
198 | } |
---|
199 | |
---|
200 | return pGroup; |
---|
201 | |
---|
202 | } |
---|
203 | //----------------------------------------------------------------------- |
---|
204 | void RenderQueue::setSplitPassesByLightingType(bool split) |
---|
205 | { |
---|
206 | mSplitPassesByLightingType = split; |
---|
207 | |
---|
208 | RenderQueueGroupMap::iterator i, iend; |
---|
209 | i = mGroups.begin(); |
---|
210 | iend = mGroups.end(); |
---|
211 | for (; i != iend; ++i) |
---|
212 | { |
---|
213 | i->second->setSplitPassesByLightingType(split); |
---|
214 | } |
---|
215 | } |
---|
216 | //----------------------------------------------------------------------- |
---|
217 | void RenderQueue::setSplitNoShadowPasses(bool split) |
---|
218 | { |
---|
219 | mSplitNoShadowPasses = split; |
---|
220 | |
---|
221 | RenderQueueGroupMap::iterator i, iend; |
---|
222 | i = mGroups.begin(); |
---|
223 | iend = mGroups.end(); |
---|
224 | for (; i != iend; ++i) |
---|
225 | { |
---|
226 | i->second->setSplitNoShadowPasses(split); |
---|
227 | } |
---|
228 | } |
---|
229 | //----------------------------------------------------------------------- |
---|
230 | void RenderQueue::setShadowCastersCannotBeReceivers(bool ind) |
---|
231 | { |
---|
232 | mShadowCastersCannotBeReceivers = ind; |
---|
233 | |
---|
234 | RenderQueueGroupMap::iterator i, iend; |
---|
235 | i = mGroups.begin(); |
---|
236 | iend = mGroups.end(); |
---|
237 | for (; i != iend; ++i) |
---|
238 | { |
---|
239 | i->second->setShadowCastersCannotBeReceivers(ind); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | } |
---|
244 | |
---|