[692] | 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-2005 The OGRE Team
|
---|
| 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 | */
|
---|
| 25 | #ifndef __CompositorInstance_H__
|
---|
| 26 | #define __CompositorInstance_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreMaterial.h"
|
---|
| 30 | #include "OgreTexture.h"
|
---|
| 31 | #include "OgreRenderQueue.h"
|
---|
| 32 | namespace Ogre {
|
---|
| 33 | const size_t RENDER_QUEUE_COUNT = RENDER_QUEUE_OVERLAY+1;
|
---|
| 34 |
|
---|
| 35 | /** An instance of a Compositor object for one Viewport. It is part of the CompositorChain
|
---|
| 36 | for a Viewport.
|
---|
| 37 | */
|
---|
| 38 | class _OgreExport CompositorInstance
|
---|
| 39 | {
|
---|
| 40 | public:
|
---|
| 41 | CompositorInstance(Compositor *filter, CompositionTechnique *technique, CompositorChain *chain);
|
---|
| 42 | virtual ~CompositorInstance();
|
---|
| 43 | /** Provides an interface to "listen in" to to render system operations executed by this
|
---|
| 44 | CompositorInstance.
|
---|
| 45 | */
|
---|
| 46 | class _OgreExport Listener
|
---|
| 47 | {
|
---|
| 48 | public:
|
---|
| 49 | virtual ~Listener();
|
---|
| 50 |
|
---|
| 51 | /** Notification of when a render target operation involving a material (like
|
---|
| 52 | rendering a quad) is compiled, so that miscelleneous parameters that are different
|
---|
| 53 | per Compositor instance can be set up.
|
---|
| 54 | @param pass_id Pass identifier within Compositor instance, this is speficied
|
---|
| 55 | by the user by CompositionPass::setIdentifier().
|
---|
| 56 | @param mat Material, this may be changed at will and will only affect
|
---|
| 57 | the current instance of the Compositor, not the global material
|
---|
| 58 | it was cloned from.
|
---|
| 59 | */
|
---|
| 60 | virtual void notifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
|
---|
| 61 |
|
---|
| 62 | /** Notification before a render target operation involving a material (like
|
---|
| 63 | rendering a quad), so that material parameters can be varied.
|
---|
| 64 | @param pass_id Pass identifier within Compositor instance, this is speficied
|
---|
| 65 | by the user by CompositionPass::setIdentifier().
|
---|
| 66 | @param mat Material, this may be changed at will and will only affect
|
---|
| 67 | the current instance of the Compositor, not the global material
|
---|
| 68 | it was cloned from.
|
---|
| 69 | */
|
---|
| 70 | virtual void notifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
|
---|
| 71 | };
|
---|
| 72 | /** Specific render system operation. A render target operation does special operations
|
---|
| 73 | between render queues like rendering a quad, clearing the frame buffer or
|
---|
| 74 | setting stencil state.
|
---|
| 75 | */
|
---|
| 76 | class RenderSystemOperation
|
---|
| 77 | {
|
---|
| 78 | public:
|
---|
| 79 | virtual ~RenderSystemOperation();
|
---|
| 80 | /// Set state to SceneManager and RenderSystem
|
---|
| 81 | virtual void execute(SceneManager *sm, RenderSystem *rs) = 0;
|
---|
| 82 | };
|
---|
| 83 | typedef std::map<int, MaterialPtr> QuadMaterialMap;
|
---|
| 84 | typedef std::pair<int, RenderSystemOperation*> RenderSystemOpPair;
|
---|
| 85 | typedef std::vector<RenderSystemOpPair> RenderSystemOpPairs;
|
---|
| 86 | /** Operation setup for a RenderTarget (collected).
|
---|
| 87 | */
|
---|
| 88 | class TargetOperation
|
---|
| 89 | {
|
---|
| 90 | public:
|
---|
| 91 | TargetOperation()
|
---|
| 92 | {
|
---|
| 93 | }
|
---|
| 94 | TargetOperation(RenderTarget *target):
|
---|
| 95 | target(target), currentQueueGroupID(0), visibilityMask(0xFFFFFFFF),
|
---|
| 96 | lodBias(1.0f),
|
---|
| 97 | onlyInitial(false), hasBeenRendered(false), findVisibleObjects(false)
|
---|
| 98 | {
|
---|
| 99 | }
|
---|
| 100 | /// Target
|
---|
| 101 | RenderTarget *target;
|
---|
| 102 |
|
---|
| 103 | /// Current group ID
|
---|
| 104 | int currentQueueGroupID;
|
---|
| 105 |
|
---|
| 106 | /// RenderSystem operations to queue into the scene manager, by
|
---|
| 107 | /// uint8
|
---|
| 108 | RenderSystemOpPairs renderSystemOperations;
|
---|
| 109 |
|
---|
| 110 | /// Scene visibility mask
|
---|
| 111 | /// If this is 0, the scene is not rendered at all
|
---|
| 112 | uint32 visibilityMask;
|
---|
| 113 |
|
---|
| 114 | /// LOD offset. This is multiplied with the camera LOD offset
|
---|
| 115 | /// 1.0 is default, lower means lower detail, higher means higher detail
|
---|
| 116 | float lodBias;
|
---|
| 117 |
|
---|
| 118 | /** A set of render queues to either include or exclude certain render queues.
|
---|
| 119 | */
|
---|
| 120 | typedef std::bitset<RENDER_QUEUE_COUNT> RenderQueueBitSet;
|
---|
| 121 |
|
---|
| 122 | /// Which renderqueues to render from scene
|
---|
| 123 | RenderQueueBitSet renderQueues;
|
---|
| 124 |
|
---|
| 125 | /** @see CompositionTargetPass::mOnlyInitial
|
---|
| 126 | */
|
---|
| 127 | bool onlyInitial;
|
---|
| 128 | /** "Has been rendered" flag; used in combination with
|
---|
| 129 | onlyInitial to determine whether to skip this target operation.
|
---|
| 130 | */
|
---|
| 131 | bool hasBeenRendered;
|
---|
| 132 | /** Whether this op needs to find visible scene objects or not
|
---|
| 133 | */
|
---|
| 134 | bool findVisibleObjects;
|
---|
| 135 | /** Which material scheme this op will use */
|
---|
| 136 | String materialScheme;
|
---|
| 137 | };
|
---|
| 138 | typedef std::vector<TargetOperation> CompiledState;
|
---|
| 139 |
|
---|
| 140 | /** Set enabled flag. The compositor instance will only render if it is
|
---|
| 141 | enabled, otherwise it is pass-through.
|
---|
| 142 | */
|
---|
| 143 | void setEnabled(bool value);
|
---|
| 144 |
|
---|
| 145 | /** Get enabled flag.
|
---|
| 146 | */
|
---|
| 147 | bool getEnabled();
|
---|
| 148 |
|
---|
| 149 | /** Prepare this instance for re-compilation. Clear all state that has been
|
---|
| 150 | set by the last compile.
|
---|
| 151 | */
|
---|
| 152 | virtual void _prepareForCompilation();
|
---|
| 153 |
|
---|
| 154 | /** Recursively collect target states (except for final Pass).
|
---|
| 155 | @param compiledState This vector will contain a list of TargetOperation objects
|
---|
| 156 | */
|
---|
| 157 | virtual void _compileTargetOperations(CompiledState &compiledState);
|
---|
| 158 |
|
---|
| 159 | /** Compile the final (output) operation. This is done seperately because this
|
---|
| 160 | is combined with the input in chained filters.
|
---|
| 161 | */
|
---|
| 162 | virtual void _compileOutputOperation(TargetOperation &finalState);
|
---|
| 163 |
|
---|
| 164 | /** Get Compositor of which this is an instance
|
---|
| 165 | */
|
---|
| 166 | Compositor *getCompositor();
|
---|
| 167 |
|
---|
| 168 | /** Get CompositionTechnique used by this instance
|
---|
| 169 | */
|
---|
| 170 | CompositionTechnique *getTechnique();
|
---|
| 171 |
|
---|
| 172 | /** Get Chain that this instance is part of
|
---|
| 173 | */
|
---|
| 174 | CompositorChain *getChain();
|
---|
| 175 |
|
---|
| 176 | /** Add a listener. Listeners provide an interface to "listen in" to to render system
|
---|
| 177 | operations executed by this CompositorInstance so that materials can be
|
---|
| 178 | programmatically set up.
|
---|
| 179 | @see CompositorInstance::Listener
|
---|
| 180 | */
|
---|
| 181 | void addListener(Listener *l);
|
---|
| 182 |
|
---|
| 183 | /** Remove a listener.
|
---|
| 184 | @see CompositorInstance::Listener
|
---|
| 185 | */
|
---|
| 186 | void removeListener(Listener *l);
|
---|
| 187 |
|
---|
| 188 | /** Notify listeners of a material compilation.
|
---|
| 189 | */
|
---|
| 190 | void _fireNotifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
|
---|
| 191 |
|
---|
| 192 | /** Notify listeners of a material render.
|
---|
| 193 | */
|
---|
| 194 | void _fireNotifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
|
---|
| 195 | private:
|
---|
| 196 | /// Compositor of which this is an instance
|
---|
| 197 | Compositor *mCompositor;
|
---|
| 198 | /// Composition technique used by this instance
|
---|
| 199 | CompositionTechnique *mTechnique;
|
---|
| 200 | /// Composition chain of which this instance is part
|
---|
| 201 | CompositorChain *mChain;
|
---|
| 202 | /// Is this instance enabled?
|
---|
| 203 | bool mEnabled;
|
---|
| 204 | /// Map from name->local texture
|
---|
| 205 | typedef std::map<String,TexturePtr> LocalTextureMap;
|
---|
| 206 | LocalTextureMap mLocalTextures;
|
---|
| 207 |
|
---|
| 208 | /// Render System operations queued by last compile, these are created by this
|
---|
| 209 | /// instance thus managed and deleted by it. The list is cleared with
|
---|
| 210 | /// clearCompilationState()
|
---|
| 211 | typedef std::vector<RenderSystemOperation*> RenderSystemOperations;
|
---|
| 212 | RenderSystemOperations mRenderSystemOperations;
|
---|
| 213 |
|
---|
| 214 | /// Vector of listeners
|
---|
| 215 | typedef std::vector<Listener*> Listeners;
|
---|
| 216 | Listeners mListeners;
|
---|
| 217 |
|
---|
| 218 | /// Previous instance (set by chain)
|
---|
| 219 | CompositorInstance *mPreviousInstance;
|
---|
| 220 |
|
---|
| 221 | /** Collect rendering passes. Here, passes are converted into render target operations
|
---|
| 222 | and queued with queueRenderSystemOp.
|
---|
| 223 | */
|
---|
| 224 | virtual void collectPasses(TargetOperation &finalState, CompositionTargetPass *target);
|
---|
| 225 |
|
---|
| 226 | /** Create a local dummy material with one technique but no passes.
|
---|
| 227 | The material is detached from the Material Manager to make sure it is destroyed
|
---|
| 228 | when going out of scope.
|
---|
| 229 | */
|
---|
| 230 | MaterialPtr createLocalMaterial();
|
---|
| 231 |
|
---|
| 232 | /** Create local rendertextures and other resources. Builds mLocalTextures.
|
---|
| 233 | */
|
---|
| 234 | void createResources();
|
---|
| 235 |
|
---|
| 236 | /** Destroy local rendertextures and other resources.
|
---|
| 237 | */
|
---|
| 238 | void freeResources();
|
---|
| 239 |
|
---|
| 240 | /** Destroy locally queued RenderTarget operations
|
---|
| 241 | */
|
---|
| 242 | void clearCompilationState();
|
---|
| 243 |
|
---|
| 244 | /** Get RenderTarget for a named local texture.
|
---|
| 245 | */
|
---|
| 246 | RenderTarget *getTargetForTex(const String &name);
|
---|
| 247 |
|
---|
| 248 | /** Get source texture name for a named local texture.
|
---|
| 249 | */
|
---|
| 250 | const String &getSourceForTex(const String &name);
|
---|
| 251 |
|
---|
| 252 | /** Queue a render system operation.
|
---|
| 253 | @returns destination pass
|
---|
| 254 | */
|
---|
| 255 | void queueRenderSystemOp(TargetOperation &finalState, RenderSystemOperation *op);
|
---|
| 256 |
|
---|
| 257 | friend class CompositorChain;
|
---|
| 258 | };
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | #endif
|
---|