Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/include/OgreCompositorChain.h @ 11

Last change on this file since 11 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 8.2 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#ifndef __CompositorChain_H__
30#define __CompositorChain_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreRenderTargetListener.h"
34#include "OgreRenderQueueListener.h"
35#include "OgreCompositorInstance.h"
36#include "OgreCompositor.h"
37namespace Ogre {
38   
39    /** Chain of compositor effects applying to one viewport.
40     */
41    class _OgreExport CompositorChain: public RenderTargetListener
42    {
43    public:
44        CompositorChain(Viewport *vp);
45        /** Another gcc warning here, which is no problem because RenderTargetListener is never used
46            to delete an object.
47            warning: `class Ogre::CompositorChain' has virtual functions but non-virtual destructor
48        */
49        virtual ~CompositorChain();
50       
51        /// Data types
52        typedef std::vector<CompositorInstance*> Instances;
53        typedef VectorIterator<Instances> InstanceIterator;
54       
55        /// Identifier for "last" compositor in chain
56        static const size_t LAST = (size_t)-1;
57        /// Identifier for best technique
58        static const size_t BEST = 0;
59       
60        /** Apply a compositor. Initially, the filter is enabled.
61        @param filter     Filter to apply
62        @param addPosition    Position in filter chain to insert this filter at; defaults to the end (last applied filter)
63        @param technique      Technique to use; CompositorChain::BEST (default) chooses to the best one
64                            available (first technique supported)
65        */
66        CompositorInstance* addCompositor(CompositorPtr filter, size_t addPosition=LAST, size_t technique=BEST);
67   
68        /** Remove a compositor.
69        @param position    Position in filter chain of filter to remove; defaults to the end (last applied filter)
70        */
71        void removeCompositor(size_t position=LAST);
72       
73        /** Get the number of compositors.
74        */
75        size_t getNumCompositors();
76       
77        /** Remove all compositors.
78        */
79        void removeAllCompositors();
80       
81        /** Get compositor instance by position.
82         */
83        CompositorInstance *getCompositor(size_t index);
84
85                /** Get the original scene compositor instance for this chain (internal use).
86                */
87                CompositorInstance* _getOriginalSceneCompositor(void) { return mOriginalScene; }
88   
89        /** Get an iterator over the compositor instances. The first compositor in this list is applied first, the last one is applied last.
90        */
91        InstanceIterator getCompositors();
92   
93        /** Enable or disable a compositor, by position. Disabling a compositor stops it from rendering
94            but does not free any resources. This can be more efficient than using removeCompositor and
95                        addCompositor in cases the filter is switched on and off a lot.
96        @param position    Position in filter chain of filter
97        */
98        void setCompositorEnabled(size_t position, bool state);
99   
100        /** @see RenderTargetListener::preRenderTargetUpdate */
101                virtual void preRenderTargetUpdate(const RenderTargetEvent& evt);
102                /** @see RenderTargetListener::preViewportUpdate */
103        virtual void preViewportUpdate(const RenderTargetViewportEvent& evt);
104        /** @see RenderTargetListener::postViewportUpdate */
105        virtual void postViewportUpdate(const RenderTargetViewportEvent& evt);
106                /** @see RenderTargetListener::viewportRemoved */
107                virtual void viewportRemoved(const RenderTargetViewportEvent& evt);
108       
109        /** Mark state as dirty, and to be recompiled next frame.
110         */
111        void _markDirty();
112       
113        /** Get viewport that is the target of this chain
114         */
115        Viewport *getViewport();
116
117                /** Remove a compositor by pointer. This is internally used by CompositionTechnique to
118                        "weak" remove any instanced of a deleted technique.
119        */
120        void _removeInstance(CompositorInstance *i);
121
122                /** Internal method for registering a queued operation for deletion later **/
123                void _queuedOperation(CompositorInstance::RenderSystemOperation* op);
124
125                /** Compile this Composition chain into a series of RenderTarget operations.
126                */
127                void _compile();
128    protected:   
129        /// Viewport affected by this CompositorChain
130        Viewport *mViewport;
131       
132        /** Plainly renders the scene; implicit first compositor in the chain.
133        */
134        CompositorInstance *mOriginalScene;
135       
136        /// Postfilter instances in this chain
137        Instances mInstances;
138       
139        /// State needs recompile
140        bool mDirty;
141                /// Any compositors enabled?
142                bool mAnyCompositorsEnabled;
143
144        /// Compiled state (updated with _compile)
145        CompositorInstance::CompiledState mCompiledState;
146        CompositorInstance::TargetOperation mOutputOperation;
147                /// Render System operations queued by last compile, these are created by this
148                /// instance thus managed and deleted by it. The list is cleared with
149                /// clearCompilationState()
150                typedef std::vector<CompositorInstance::RenderSystemOperation*> RenderSystemOperations;
151                RenderSystemOperations mRenderSystemOperations;
152
153       
154                /** Clear compiled state */
155                void clearCompiledState();
156       
157        /** Prepare a viewport, the camera and the scene for a rendering operation
158         */
159        void preTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
160       
161        /** Restore a viewport, the camera and the scene after a rendering operation
162         */
163        void postTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
164
165                /// destroy internal resources
166                void destroyResources(void);
167
168                /** Render queue listener used to set up rendering events. */
169                class _OgreExport RQListener: public RenderQueueListener
170                {
171                public:
172                        /** @copydoc RenderQueueListener::renderQueueStarted
173                        */
174                        virtual void renderQueueStarted(uint8 id, const String& invocation, bool& skipThisQueue);
175                        /** @copydoc RenderQueueListener::renderQueueEnded
176                        */
177                        virtual void renderQueueEnded(uint8 id, const String& invocation, bool& repeatThisQueue);
178
179                        /** Set current operation and target */
180                        void setOperation(CompositorInstance::TargetOperation *op,SceneManager *sm,RenderSystem *rs);
181
182                        /** Notify current destination viewport  */
183                        void notifyViewport(Viewport* vp) { mViewport = vp; }
184
185                        /** Flush remaining render system operations */
186                        void flushUpTo(uint8 id);
187                private:
188                        CompositorInstance::TargetOperation *mOperation;
189                        SceneManager *mSceneManager;
190                        RenderSystem *mRenderSystem;
191                        Viewport* mViewport;
192                        CompositorInstance::RenderSystemOpPairs::iterator currentOp, lastOp;
193                };
194                RQListener mOurListener;
195                /// Old viewport settings
196                unsigned int mOldClearEveryFrameBuffers;
197                /// Store old scene visibility mask
198                uint32 mOldVisibilityMask;
199                /// Store old find visible objects
200                bool mOldFindVisibleObjects;
201        /// Store old camera LOD bias     
202        float mOldLodBias;     
203                ///     Store old viewport material scheme
204                String mOldMaterialScheme;
205                /// Store old shadows enabled flag
206                bool mOldShadowsEnabled;
207
208    };
209}
210
211#endif
Note: See TracBrowser for help on using the repository browser.