[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 __CompositorChain_H__
|
---|
| 26 | #define __CompositorChain_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreRenderTargetListener.h"
|
---|
| 30 | #include "OgreRenderQueueListener.h"
|
---|
| 31 | #include "OgreCompositorInstance.h"
|
---|
| 32 | #include "OgreCompositor.h"
|
---|
| 33 | namespace Ogre {
|
---|
| 34 |
|
---|
| 35 | /** Chain of compositor effects applying to one viewport.
|
---|
| 36 | */
|
---|
| 37 | class _OgreExport CompositorChain: public RenderTargetListener
|
---|
| 38 | {
|
---|
| 39 | public:
|
---|
| 40 | CompositorChain(Viewport *vp);
|
---|
| 41 | /** Another gcc warning here, which is no problem because RenderTargetListener is never used
|
---|
| 42 | to delete an object.
|
---|
| 43 | warning: `class Ogre::CompositorChain' has virtual functions but non-virtual destructor
|
---|
| 44 | */
|
---|
| 45 | virtual ~CompositorChain();
|
---|
| 46 |
|
---|
| 47 | /// Data types
|
---|
| 48 | typedef std::vector<CompositorInstance*> Instances;
|
---|
| 49 | typedef VectorIterator<Instances> InstanceIterator;
|
---|
| 50 |
|
---|
| 51 | /// Identifier for "last" compositor in chain
|
---|
| 52 | static const size_t LAST = (size_t)-1;
|
---|
| 53 | /// Identifier for best technique
|
---|
| 54 | static const size_t BEST = 0;
|
---|
| 55 |
|
---|
| 56 | /** Apply a compositor. Initially, the filter is enabled.
|
---|
| 57 | @param filter Filter to apply
|
---|
| 58 | @param addPosition Position in filter chain to insert this filter at; defaults to the end (last applied filter)
|
---|
| 59 | @param technique Technique to use; CompositorChain::BEST (default) chooses to the best one
|
---|
| 60 | available (first technique supported)
|
---|
| 61 | */
|
---|
| 62 | CompositorInstance* addCompositor(CompositorPtr filter, size_t addPosition=LAST, size_t technique=BEST);
|
---|
| 63 |
|
---|
| 64 | /** Remove a compositor.
|
---|
| 65 | @param position Position in filter chain of filter to remove; defaults to the end (last applied filter)
|
---|
| 66 | */
|
---|
| 67 | void removeCompositor(size_t position=LAST);
|
---|
| 68 |
|
---|
| 69 | /** Get the number of compositors.
|
---|
| 70 | */
|
---|
| 71 | size_t getNumCompositors();
|
---|
| 72 |
|
---|
| 73 | /** Remove all compositors.
|
---|
| 74 | */
|
---|
| 75 | void removeAllCompositors();
|
---|
| 76 |
|
---|
| 77 | /** Get compositor instance by position.
|
---|
| 78 | */
|
---|
| 79 | CompositorInstance *getCompositor(size_t index);
|
---|
| 80 |
|
---|
| 81 | /** Get the original scene compositor instance for this chain (internal use).
|
---|
| 82 | */
|
---|
| 83 | CompositorInstance* _getOriginalSceneCompositor(void) { return mOriginalScene; }
|
---|
| 84 |
|
---|
| 85 | /** Get an iterator over the compositor instances. The first compositor in this list is applied first, the last one is applied last.
|
---|
| 86 | */
|
---|
| 87 | InstanceIterator getCompositors();
|
---|
| 88 |
|
---|
| 89 | /** Enable or disable a compositor, by position. Disabling a compositor stops it from rendering
|
---|
| 90 | but does not free any resources. This can be more efficient than using removeCompositor and
|
---|
| 91 | addCompositor in cases the filter is switched on and off a lot.
|
---|
| 92 | @param position Position in filter chain of filter
|
---|
| 93 | */
|
---|
| 94 | void setCompositorEnabled(size_t position, bool state);
|
---|
| 95 |
|
---|
| 96 | /** @see RenderTargetListener::preRenderTargetUpdate */
|
---|
| 97 | virtual void preRenderTargetUpdate(const RenderTargetEvent& evt);
|
---|
| 98 | /** @see RenderTargetListener::preViewportUpdate */
|
---|
| 99 | virtual void preViewportUpdate(const RenderTargetViewportEvent& evt);
|
---|
| 100 | /** @see RenderTargetListener::postViewportUpdate */
|
---|
| 101 | virtual void postViewportUpdate(const RenderTargetViewportEvent& evt);
|
---|
| 102 | /** @see RenderTargetListener::viewportRemoved */
|
---|
| 103 | virtual void viewportRemoved(const RenderTargetViewportEvent& evt);
|
---|
| 104 |
|
---|
| 105 | /** Mark state as dirty, and to be recompiled next frame.
|
---|
| 106 | */
|
---|
| 107 | void _markDirty();
|
---|
| 108 |
|
---|
| 109 | /** Get viewport that is the target of this chain
|
---|
| 110 | */
|
---|
| 111 | Viewport *getViewport();
|
---|
| 112 |
|
---|
| 113 | /** Remove a compositor by pointer. This is internally used by CompositionTechnique to
|
---|
| 114 | "weak" remove any instanced of a deleted technique.
|
---|
| 115 | */
|
---|
| 116 | void _removeInstance(CompositorInstance *i);
|
---|
| 117 | protected:
|
---|
| 118 | /// Viewport affected by this CompositorChain
|
---|
| 119 | Viewport *mViewport;
|
---|
| 120 |
|
---|
| 121 | /** Plainly renders the scene; implicit first compositor in the chain.
|
---|
| 122 | */
|
---|
| 123 | CompositorInstance *mOriginalScene;
|
---|
| 124 |
|
---|
| 125 | /// Postfilter instances in this chain
|
---|
| 126 | Instances mInstances;
|
---|
| 127 |
|
---|
| 128 | /// State needs recompile
|
---|
| 129 | bool mDirty;
|
---|
| 130 | /// Any compositors enabled?
|
---|
| 131 | bool mAnyCompositorsEnabled;
|
---|
| 132 |
|
---|
| 133 | /// Compiled state (updated with _compile)
|
---|
| 134 | CompositorInstance::CompiledState mCompiledState;
|
---|
| 135 | CompositorInstance::TargetOperation mOutputOperation;
|
---|
| 136 |
|
---|
| 137 | /** Compile this Composition chain into a series of RenderTarget operations.
|
---|
| 138 | */
|
---|
| 139 | void _compile();
|
---|
| 140 |
|
---|
| 141 | /** Prepare a viewport, the camera and the scene for a rendering operation
|
---|
| 142 | */
|
---|
| 143 | void preTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
|
---|
| 144 |
|
---|
| 145 | /** Restore a viewport, the camera and the scene after a rendering operation
|
---|
| 146 | */
|
---|
| 147 | void postTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
|
---|
| 148 |
|
---|
| 149 | /// destroy internal resources
|
---|
| 150 | void destroyResources(void);
|
---|
| 151 |
|
---|
| 152 | /** Render queue listener used to set up rendering events. */
|
---|
| 153 | class RQListener: public RenderQueueListener
|
---|
| 154 | {
|
---|
| 155 | public:
|
---|
| 156 | /** @copydoc RenderQueueListener::renderQueueStarted
|
---|
| 157 | */
|
---|
| 158 | virtual void renderQueueStarted(uint8 id, const String& invocation, bool& skipThisQueue);
|
---|
| 159 | /** @copydoc RenderQueueListener::renderQueueEnded
|
---|
| 160 | */
|
---|
| 161 | virtual void renderQueueEnded(uint8 id, const String& invocation, bool& repeatThisQueue);
|
---|
| 162 |
|
---|
| 163 | /** Set current operation and target */
|
---|
| 164 | void setOperation(CompositorInstance::TargetOperation *op,SceneManager *sm,RenderSystem *rs);
|
---|
| 165 |
|
---|
| 166 | /** Flush remaining render system operations */
|
---|
| 167 | void flushUpTo(uint8 id);
|
---|
| 168 | private:
|
---|
| 169 | CompositorInstance::TargetOperation *mOperation;
|
---|
| 170 | SceneManager *mSceneManager;
|
---|
| 171 | RenderSystem *mRenderSystem;
|
---|
| 172 | CompositorInstance::RenderSystemOpPairs::iterator currentOp, lastOp;
|
---|
| 173 | };
|
---|
| 174 | RQListener mOurListener;
|
---|
| 175 | /// Old viewport settings
|
---|
| 176 | unsigned int mOldClearEveryFrameBuffers;
|
---|
| 177 | /// Store old scene visibility mask
|
---|
| 178 | uint32 mOldVisibilityMask;
|
---|
| 179 | /// Store old find visible objects
|
---|
| 180 | bool mOldFindVisibleObjects;
|
---|
| 181 | /// Store old camera LOD bias
|
---|
| 182 | float mOldLodBias;
|
---|
| 183 | /// Store old viewport material scheme
|
---|
| 184 | String mOldMaterialScheme;
|
---|
| 185 | };
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | #endif
|
---|