[148] | 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-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE SOFTWARE. |
---|
| 26 | ----------------------------------------------------------------------------- |
---|
| 27 | */ |
---|
| 28 | #ifndef __RenderQueue_H__ |
---|
| 29 | #define __RenderQueue_H__ |
---|
| 30 | |
---|
| 31 | #include "OgrePrerequisites.h" |
---|
| 32 | #include "OgreIteratorWrappers.h" |
---|
| 33 | #include "OgreHeaderPrefix.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre { |
---|
| 36 | |
---|
| 37 | class Camera; |
---|
| 38 | class MovableObject; |
---|
| 39 | struct VisibleObjectsBoundsInfo; |
---|
| 40 | |
---|
| 41 | /** \addtogroup Core |
---|
| 42 | * @{ |
---|
| 43 | */ |
---|
| 44 | /** \addtogroup RenderSystem |
---|
| 45 | * @{ |
---|
| 46 | */ |
---|
| 47 | /** Enumeration of queue groups, by which the application may group queued renderables |
---|
| 48 | so that they are rendered together with events in between |
---|
| 49 | @remarks |
---|
| 50 | When passed into methods these are actually passed as a uint8 to allow you |
---|
| 51 | to use values in between if you want to. |
---|
| 52 | */ |
---|
| 53 | enum RenderQueueGroupID |
---|
| 54 | { |
---|
| 55 | /// Use this queue for objects which must be rendered first e.g. backgrounds |
---|
| 56 | RENDER_QUEUE_BACKGROUND = 0, |
---|
| 57 | /// First queue (after backgrounds), used for skyboxes if rendered first |
---|
| 58 | RENDER_QUEUE_SKIES_EARLY = 5, |
---|
| 59 | RENDER_QUEUE_1 = 10, |
---|
| 60 | RENDER_QUEUE_2 = 20, |
---|
| 61 | RENDER_QUEUE_WORLD_GEOMETRY_1 = 25, |
---|
| 62 | RENDER_QUEUE_3 = 30, |
---|
| 63 | RENDER_QUEUE_4 = 40, |
---|
| 64 | /// The default render queue |
---|
| 65 | RENDER_QUEUE_MAIN = 50, |
---|
| 66 | RENDER_QUEUE_6 = 60, |
---|
| 67 | RENDER_QUEUE_7 = 70, |
---|
| 68 | RENDER_QUEUE_WORLD_GEOMETRY_2 = 75, |
---|
| 69 | RENDER_QUEUE_8 = 80, |
---|
| 70 | RENDER_QUEUE_9 = 90, |
---|
| 71 | /// Penultimate queue(before overlays), used for skyboxes if rendered last |
---|
| 72 | RENDER_QUEUE_SKIES_LATE = 95, |
---|
| 73 | /// Use this queue for objects which must be rendered last e.g. overlays |
---|
| 74 | RENDER_QUEUE_OVERLAY = 100, |
---|
| 75 | /// Final possible render queue, don't exceed this |
---|
| 76 | RENDER_QUEUE_MAX = 105 |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | #define OGRE_RENDERABLE_DEFAULT_PRIORITY 100 |
---|
| 80 | |
---|
| 81 | /** Class to manage the scene object rendering queue. |
---|
| 82 | @remarks |
---|
| 83 | Objects are grouped by material to minimise rendering state changes. The map from |
---|
| 84 | material to renderable object is wrapped in a class for ease of use. |
---|
| 85 | @par |
---|
| 86 | This class now includes the concept of 'queue groups' which allows the application |
---|
| 87 | adding the renderable to specifically schedule it so that it is included in |
---|
| 88 | a discrete group. Good for separating renderables into the main scene, |
---|
| 89 | backgrounds and overlays, and also could be used in the future for more |
---|
| 90 | complex multipass routines like stenciling. |
---|
| 91 | */ |
---|
| 92 | class _OgreExport RenderQueue : public RenderQueueAlloc |
---|
| 93 | { |
---|
| 94 | public: |
---|
| 95 | |
---|
| 96 | typedef map< uint8, RenderQueueGroup* >::type RenderQueueGroupMap; |
---|
| 97 | /// Iterator over queue groups |
---|
| 98 | typedef MapIterator<RenderQueueGroupMap> QueueGroupIterator; |
---|
| 99 | typedef ConstMapIterator<RenderQueueGroupMap> ConstQueueGroupIterator; |
---|
| 100 | |
---|
| 101 | /** Class to listen in on items being added to the render queue. |
---|
| 102 | @remarks |
---|
| 103 | Use RenderQueue::setRenderableListener to get callbacks when an item |
---|
| 104 | is added to the render queue. |
---|
| 105 | */ |
---|
| 106 | class _OgreExport RenderableListener |
---|
| 107 | { |
---|
| 108 | public: |
---|
| 109 | RenderableListener() {} |
---|
| 110 | virtual ~RenderableListener() {} |
---|
| 111 | |
---|
| 112 | /** Method called when a Renderable is added to the queue. |
---|
| 113 | @remarks |
---|
| 114 | You can use this event hook to alter the Technique used to |
---|
| 115 | render a Renderable as the item is added to the queue. This is |
---|
| 116 | a low-level way to override the material settings for a given |
---|
| 117 | Renderable on the fly. |
---|
| 118 | @param rend The Renderable being added to the queue |
---|
| 119 | @param groupID The render queue group this Renderable is being added to |
---|
| 120 | @param priority The priority the Renderable has been given |
---|
| 121 | @param ppTech A pointer to the pointer to the Technique that is |
---|
| 122 | intended to be used; you can alter this to an alternate Technique |
---|
| 123 | if you so wish (the Technique doesn't have to be from the same |
---|
| 124 | Material either). |
---|
| 125 | @param pQueue Pointer to the render queue that this object is being |
---|
| 126 | added to. You can for example call this back to duplicate the |
---|
| 127 | object with a different technique |
---|
| 128 | @return true to allow the Renderable to be added to the queue, |
---|
| 129 | false if you want to prevent it being added |
---|
| 130 | */ |
---|
| 131 | virtual bool renderableQueued(Renderable* rend, uint8 groupID, |
---|
| 132 | ushort priority, Technique** ppTech, RenderQueue* pQueue) = 0; |
---|
| 133 | }; |
---|
| 134 | protected: |
---|
| 135 | RenderQueueGroupMap mGroups; |
---|
| 136 | /// The current default queue group |
---|
| 137 | uint8 mDefaultQueueGroup; |
---|
| 138 | /// The default priority |
---|
| 139 | ushort mDefaultRenderablePriority; |
---|
| 140 | |
---|
| 141 | bool mSplitPassesByLightingType; |
---|
| 142 | bool mSplitNoShadowPasses; |
---|
| 143 | bool mShadowCastersCannotBeReceivers; |
---|
| 144 | |
---|
| 145 | RenderableListener* mRenderableListener; |
---|
| 146 | public: |
---|
| 147 | RenderQueue(); |
---|
| 148 | virtual ~RenderQueue(); |
---|
| 149 | |
---|
| 150 | /** Empty the queue - should only be called by SceneManagers. |
---|
| 151 | @param destroyPassMaps Set to true to destroy all pass maps so that |
---|
| 152 | the queue is completely clean (useful when switching scene managers) |
---|
| 153 | */ |
---|
| 154 | void clear(bool destroyPassMaps = false); |
---|
| 155 | |
---|
| 156 | /** Get a render queue group. |
---|
| 157 | @remarks |
---|
| 158 | OGRE registers new queue groups as they are requested, |
---|
| 159 | therefore this method will always return a valid group. |
---|
| 160 | */ |
---|
| 161 | RenderQueueGroup* getQueueGroup(uint8 qid); |
---|
| 162 | |
---|
| 163 | /** Add a renderable object to the queue. |
---|
| 164 | @remarks |
---|
| 165 | This methods adds a Renderable to the queue, which will be rendered later by |
---|
| 166 | the SceneManager. This is the advanced version of the call which allows the renderable |
---|
| 167 | to be added to any queue. |
---|
| 168 | @note |
---|
| 169 | Called by implementation of MovableObject::_updateRenderQueue. |
---|
| 170 | @param |
---|
| 171 | pRend Pointer to the Renderable to be added to the queue |
---|
| 172 | @param |
---|
| 173 | groupID The group the renderable is to be added to. This |
---|
| 174 | can be used to schedule renderable objects in separate groups such that the SceneManager |
---|
| 175 | respects the divisions between the groupings and does not reorder them outside these |
---|
| 176 | boundaries. This can be handy for overlays where no matter what you want the overlay to |
---|
| 177 | be rendered last. |
---|
| 178 | @param |
---|
| 179 | priority Controls the priority of the renderable within the queue group. If this number |
---|
| 180 | is raised, the renderable will be rendered later in the group compared to it's peers. |
---|
| 181 | Don't use this unless you really need to, manually ordering renderables prevents OGRE |
---|
| 182 | from sorting them for best efficiency. However this could be useful for ordering 2D |
---|
| 183 | elements manually for example. |
---|
| 184 | */ |
---|
| 185 | void addRenderable(Renderable* pRend, uint8 groupID, ushort priority); |
---|
| 186 | |
---|
| 187 | /** Add a renderable object to the queue. |
---|
| 188 | @remarks |
---|
| 189 | This methods adds a Renderable to the queue, which will be rendered later by |
---|
| 190 | the SceneManager. This is the simplified version of the call which does not |
---|
| 191 | require a priority to be specified. The queue priority is take from the |
---|
| 192 | current default (see setDefaultRenderablePriority). |
---|
| 193 | @note |
---|
| 194 | Called by implementation of MovableObject::_updateRenderQueue. |
---|
| 195 | @param pRend |
---|
| 196 | Pointer to the Renderable to be added to the queue |
---|
| 197 | @param groupId |
---|
| 198 | The group the renderable is to be added to. This |
---|
| 199 | can be used to schedule renderable objects in separate groups such that the SceneManager |
---|
| 200 | respects the divisions between the groupings and does not reorder them outside these |
---|
| 201 | boundaries. This can be handy for overlays where no matter what you want the overlay to |
---|
| 202 | be rendered last. |
---|
| 203 | */ |
---|
| 204 | void addRenderable(Renderable* pRend, uint8 groupId); |
---|
| 205 | |
---|
| 206 | /** Add a renderable object to the queue. |
---|
| 207 | @remarks |
---|
| 208 | This methods adds a Renderable to the queue, which will be rendered later by |
---|
| 209 | the SceneManager. This is the simplified version of the call which does not |
---|
| 210 | require a queue or priority to be specified. The queue group is taken from the |
---|
| 211 | current default (see setDefaultQueueGroup). The queue priority is take from the |
---|
| 212 | current default (see setDefaultRenderablePriority). |
---|
| 213 | @note |
---|
| 214 | Called by implementation of MovableObject::_updateRenderQueue. |
---|
| 215 | @param |
---|
| 216 | pRend Pointer to the Renderable to be added to the queue |
---|
| 217 | */ |
---|
| 218 | void addRenderable(Renderable* pRend); |
---|
| 219 | |
---|
| 220 | /** Gets the current default queue group, which will be used for all renderable which do not |
---|
| 221 | specify which group they wish to be on. |
---|
| 222 | */ |
---|
| 223 | uint8 getDefaultQueueGroup(void) const; |
---|
| 224 | |
---|
| 225 | /** Sets the current default renderable priority, |
---|
| 226 | which will be used for all renderables which do not |
---|
| 227 | specify which priority they wish to use. |
---|
| 228 | */ |
---|
| 229 | void setDefaultRenderablePriority(ushort priority); |
---|
| 230 | |
---|
| 231 | /** Gets the current default renderable priority, which will be used for all renderables which do not |
---|
| 232 | specify which priority they wish to use. |
---|
| 233 | */ |
---|
| 234 | ushort getDefaultRenderablePriority(void) const; |
---|
| 235 | |
---|
| 236 | /** Sets the current default queue group, which will be used for all renderable which do not |
---|
| 237 | specify which group they wish to be on. See the enum RenderQueueGroupID for what kind of |
---|
| 238 | values can be used here. |
---|
| 239 | */ |
---|
| 240 | void setDefaultQueueGroup(uint8 grp); |
---|
| 241 | |
---|
| 242 | /** Internal method, returns an iterator for the queue groups. */ |
---|
| 243 | QueueGroupIterator _getQueueGroupIterator(void); |
---|
| 244 | ConstQueueGroupIterator _getQueueGroupIterator(void) const; |
---|
| 245 | |
---|
| 246 | /** Sets whether or not the queue will split passes by their lighting type, |
---|
| 247 | ie ambient, per-light and decal. |
---|
| 248 | */ |
---|
| 249 | void setSplitPassesByLightingType(bool split); |
---|
| 250 | |
---|
| 251 | /** Gets whether or not the queue will split passes by their lighting type, |
---|
| 252 | ie ambient, per-light and decal. |
---|
| 253 | */ |
---|
| 254 | bool getSplitPassesByLightingType(void) const; |
---|
| 255 | |
---|
| 256 | /** Sets whether or not the queue will split passes which have shadow receive |
---|
| 257 | turned off (in their parent material), which is needed when certain shadow |
---|
| 258 | techniques are used. |
---|
| 259 | */ |
---|
| 260 | void setSplitNoShadowPasses(bool split); |
---|
| 261 | |
---|
| 262 | /** Gets whether or not the queue will split passes which have shadow receive |
---|
| 263 | turned off (in their parent material), which is needed when certain shadow |
---|
| 264 | techniques are used. |
---|
| 265 | */ |
---|
| 266 | bool getSplitNoShadowPasses(void) const; |
---|
| 267 | |
---|
| 268 | /** Sets whether or not objects which cast shadows should be treated as |
---|
| 269 | never receiving shadows. |
---|
| 270 | */ |
---|
| 271 | void setShadowCastersCannotBeReceivers(bool ind); |
---|
| 272 | |
---|
| 273 | /** Gets whether or not objects which cast shadows should be treated as |
---|
| 274 | never receiving shadows. |
---|
| 275 | */ |
---|
| 276 | bool getShadowCastersCannotBeReceivers(void) const; |
---|
| 277 | |
---|
| 278 | /** Set a renderable listener on the queue. |
---|
| 279 | @remarks |
---|
| 280 | There can only be a single renderable listener on the queue, since |
---|
| 281 | that listener has complete control over the techniques in use. |
---|
| 282 | */ |
---|
| 283 | void setRenderableListener(RenderableListener* listener) |
---|
| 284 | { mRenderableListener = listener; } |
---|
| 285 | |
---|
| 286 | RenderableListener* getRenderableListener(void) const |
---|
| 287 | { return mRenderableListener; } |
---|
| 288 | |
---|
| 289 | /** Merge render queue. |
---|
| 290 | */ |
---|
| 291 | void merge( const RenderQueue* rhs ); |
---|
| 292 | /** Utility method to perform the standard actions associated with |
---|
| 293 | getting a visible object to add itself to the queue. This is |
---|
| 294 | a replacement for SceneManager implementations of the associated |
---|
| 295 | tasks related to calling MovableObject::_updateRenderQueue. |
---|
| 296 | */ |
---|
| 297 | void processVisibleObject(MovableObject* mo, |
---|
| 298 | Camera* cam, |
---|
| 299 | bool onlyShadowCasters, |
---|
| 300 | VisibleObjectsBoundsInfo* visibleBounds); |
---|
| 301 | |
---|
| 302 | }; |
---|
| 303 | |
---|
| 304 | /** @} */ |
---|
| 305 | /** @} */ |
---|
| 306 | |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | #include "OgreHeaderSuffix.h" |
---|
| 310 | |
---|
| 311 | #endif |
---|