/src/ogre/OgreMain/include/OgreCompositorChain.h
Line | Count | Source |
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-2014 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 __CompositorChain_H__ |
29 | | #define __CompositorChain_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | #include "OgreRenderTargetListener.h" |
33 | | #include "OgreRenderQueueListener.h" |
34 | | #include "OgreCompositorInstance.h" |
35 | | #include "OgreViewport.h" |
36 | | #include "OgreHeaderPrefix.h" |
37 | | |
38 | | namespace Ogre { |
39 | | /** \addtogroup Core |
40 | | * @{ |
41 | | */ |
42 | | /** \addtogroup Effects |
43 | | * @{ |
44 | | */ |
45 | | /** Chain of compositor effects applying to one viewport. |
46 | | */ |
47 | | class _OgreExport CompositorChain : public RenderTargetListener, public Viewport::Listener, public CompositorInstAlloc |
48 | | { |
49 | | public: |
50 | | CompositorChain(Viewport *vp); |
51 | | /** Another gcc warning here, which is no problem because RenderTargetListener is never used |
52 | | to delete an object. |
53 | | */ |
54 | | virtual ~CompositorChain(); |
55 | | |
56 | | /// Data types |
57 | | typedef std::vector<CompositorInstance*> Instances; |
58 | | typedef VectorIterator<Instances> InstanceIterator; |
59 | | |
60 | | enum { |
61 | | /// Identifier for best technique. |
62 | | BEST = 0, |
63 | | /// Identifier for "last" compositor in chain. |
64 | | LAST = (size_t)-1, |
65 | | NPOS = LAST |
66 | | }; |
67 | | |
68 | | /** Apply a compositor. Initially, the filter is enabled. |
69 | | @param filter |
70 | | Filter to apply. |
71 | | @param addPosition |
72 | | Position in filter chain to insert this filter at; defaults to the end (last applied filter). |
73 | | @param scheme |
74 | | Scheme to use (blank means default). |
75 | | */ |
76 | | CompositorInstance* addCompositor(const CompositorPtr& filter, size_t addPosition=LAST, const String& scheme = BLANKSTRING); |
77 | | |
78 | | /** Remove a compositor. |
79 | | @param position |
80 | | Position in filter chain of filter to remove; defaults to the end (last applied filter) |
81 | | */ |
82 | | void removeCompositor(size_t position=LAST); |
83 | | |
84 | | /// @deprecated use getCompositorInstances |
85 | | OGRE_DEPRECATED size_t getNumCompositors(); |
86 | | |
87 | | /** Remove all compositors. |
88 | | */ |
89 | | void removeAllCompositors(); |
90 | | |
91 | | /** Get compositor instance by name. Returns null if not found. |
92 | | */ |
93 | | CompositorInstance* getCompositor(const String& name) const; |
94 | | |
95 | | /// @overload |
96 | 0 | CompositorInstance *getCompositor(size_t index) const { return mInstances.at(index); } |
97 | | |
98 | | /// Get compositor position by name. Returns #NPOS if not found. |
99 | | size_t getCompositorPosition(const String& name) const; |
100 | | |
101 | | /** Get the original scene compositor instance for this chain (internal use). |
102 | | */ |
103 | 0 | CompositorInstance* _getOriginalSceneCompositor(void) { return mOriginalScene; } |
104 | | |
105 | | /** The compositor instances. The first compositor in this list is applied first, the last one is applied last. |
106 | | */ |
107 | 0 | const Instances& getCompositorInstances() const { return mInstances; } |
108 | | |
109 | | /// @deprecated use getCompositorInstances |
110 | | OGRE_DEPRECATED InstanceIterator getCompositors(); |
111 | | |
112 | | /** Enable or disable a compositor, by position. Disabling a compositor stops it from rendering |
113 | | but does not free any resources. This can be more efficient than using removeCompositor and |
114 | | addCompositor in cases the filter is switched on and off a lot. |
115 | | @param position |
116 | | Position in filter chain of filter |
117 | | @param state enabled flag |
118 | | */ |
119 | | void setCompositorEnabled(size_t position, bool state); |
120 | | |
121 | | void preRenderTargetUpdate(const RenderTargetEvent& evt) override; |
122 | | void postRenderTargetUpdate(const RenderTargetEvent& evt) override; |
123 | | void preViewportUpdate(const RenderTargetViewportEvent& evt) override; |
124 | | void postViewportUpdate(const RenderTargetViewportEvent& evt) override; |
125 | | void viewportCameraChanged(Viewport* viewport) override; |
126 | | void viewportDimensionsChanged(Viewport* viewport) override; |
127 | | void viewportDestroyed(Viewport* viewport) override; |
128 | | |
129 | | /** Mark state as dirty, and to be recompiled next frame. |
130 | | */ |
131 | | void _markDirty(); |
132 | | |
133 | | /** Get viewport that is the target of this chain |
134 | | */ |
135 | | Viewport *getViewport(); |
136 | | /** Set viewport that is the target of this chain |
137 | | */ |
138 | | void _notifyViewport(Viewport* vp); |
139 | | |
140 | | /** Remove a compositor by pointer. This is internally used by CompositionTechnique to |
141 | | "weak" remove any instanced of a deleted technique. |
142 | | */ |
143 | | void _removeInstance(CompositorInstance *i); |
144 | | |
145 | | /** Internal method for registering a queued operation for deletion later **/ |
146 | | void _queuedOperation(CompositorInstance::RenderSystemOperation* op); |
147 | | |
148 | | /** Compile this Composition chain into a series of RenderTarget operations. |
149 | | */ |
150 | | void _compile(); |
151 | | |
152 | | /** Get the previous instance in this chain to the one specified. |
153 | | */ |
154 | | CompositorInstance* getPreviousInstance(CompositorInstance* curr, bool activeOnly = true); |
155 | | /** Get the next instance in this chain to the one specified. |
156 | | */ |
157 | | CompositorInstance* getNextInstance(CompositorInstance* curr, bool activeOnly = true); |
158 | | |
159 | | private: |
160 | | /// Viewport affected by this CompositorChain |
161 | | Viewport *mViewport; |
162 | | |
163 | | /** Plainly renders the scene; implicit first compositor in the chain. |
164 | | */ |
165 | | CompositorInstance *mOriginalScene; |
166 | | |
167 | | /// Postfilter instances in this chain |
168 | | Instances mInstances; |
169 | | |
170 | | /// State needs recompile |
171 | | bool mDirty; |
172 | | /// Any compositors enabled? |
173 | | bool mAnyCompositorsEnabled; |
174 | | |
175 | | String mOriginalSceneScheme; |
176 | | |
177 | | /// Compiled state (updated with _compile) |
178 | | CompositorInstance::CompiledState mCompiledState; |
179 | | CompositorInstance::TargetOperation mOutputOperation; |
180 | | /// Render System operations queued by last compile, these are created by this |
181 | | /// instance thus managed and deleted by it. The list is cleared with |
182 | | /// clearCompilationState() |
183 | | typedef std::vector<CompositorInstance::RenderSystemOperation*> RenderSystemOperations; |
184 | | RenderSystemOperations mRenderSystemOperations; |
185 | | |
186 | | /** Clear compiled state */ |
187 | | void clearCompiledState(); |
188 | | |
189 | | /** Prepare a viewport, the camera and the scene for a rendering operation |
190 | | */ |
191 | | void preTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam); |
192 | | |
193 | | /** Restore a viewport, the camera and the scene after a rendering operation |
194 | | */ |
195 | | void postTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam); |
196 | | |
197 | | void createOriginalScene(); |
198 | | void destroyOriginalScene(); |
199 | | |
200 | | /// destroy internal resources |
201 | | void destroyResources(void); |
202 | | |
203 | | /** Internal method to get a unique name of a compositor |
204 | | */ |
205 | | const String getCompositorName() const; |
206 | | |
207 | | /** Render queue listener used to set up rendering events. */ |
208 | | class _OgreExport RQListener: public RenderQueueListener |
209 | | { |
210 | | public: |
211 | 0 | RQListener() : mOperation(0), mSceneManager(0), mRenderSystem(0), mViewport(0) {} |
212 | | |
213 | | void renderQueueStarted(uint8 queueGroupId, const String& cameraName, bool& skipThisInvocation) override; |
214 | | |
215 | | /** Set current operation and target. */ |
216 | | void setOperation(CompositorInstance::TargetOperation *op,SceneManager *sm,RenderSystem *rs); |
217 | | |
218 | | /** Notify current destination viewport. */ |
219 | 0 | void notifyViewport(Viewport* vp) { mViewport = vp; } |
220 | | |
221 | | /** Flush remaining render system operations. */ |
222 | | void flushUpTo(uint8 id); |
223 | | private: |
224 | | CompositorInstance::TargetOperation *mOperation; |
225 | | SceneManager *mSceneManager; |
226 | | RenderSystem *mRenderSystem; |
227 | | Viewport* mViewport; |
228 | | CompositorInstance::RenderSystemOpPairs::iterator currentOp, lastOp; |
229 | | }; |
230 | | RQListener mOurListener; |
231 | | /// Old viewport settings |
232 | | unsigned int mOldClearEveryFrameBuffers; |
233 | | /// Store old scene visibility mask |
234 | | uint32 mOldVisibilityMask; |
235 | | /// Store old find visible objects |
236 | | bool mOldFindVisibleObjects; |
237 | | /// Store old camera LOD bias |
238 | | float mOldLodBias; |
239 | | /// Store old viewport material scheme |
240 | | String mOldMaterialScheme; |
241 | | /// Store old shadows enabled flag |
242 | | bool mOldShadowsEnabled; |
243 | | |
244 | | }; |
245 | | /** @} */ |
246 | | /** @} */ |
247 | | } // namespace Ogre |
248 | | |
249 | | #include "OgreHeaderSuffix.h" |
250 | | |
251 | | #endif // __CompositorChain_H__ |