source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreCompositorChain.h @ 1809

Revision 1809, 8.2 KB checked in by gumbau, 18 years ago (diff)
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-2005 The OGRE Team
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-----------------------------------------------------------------------------
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"
33namespace 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
118                /** Internal method for registering a queued operation for deletion later **/
119                void _queuedOperation(CompositorInstance::RenderSystemOperation* op);
120
121    protected:   
122        /// Viewport affected by this CompositorChain
123        Viewport *mViewport;
124       
125        /** Plainly renders the scene; implicit first compositor in the chain.
126        */
127        CompositorInstance *mOriginalScene;
128       
129        /// Postfilter instances in this chain
130        Instances mInstances;
131       
132        /// State needs recompile
133        bool mDirty;
134                /// Any compositors enabled?
135                bool mAnyCompositorsEnabled;
136
137        /// Compiled state (updated with _compile)
138        CompositorInstance::CompiledState mCompiledState;
139        CompositorInstance::TargetOperation mOutputOperation;
140                /// Render System operations queued by last compile, these are created by this
141                /// instance thus managed and deleted by it. The list is cleared with
142                /// clearCompilationState()
143                typedef std::vector<CompositorInstance::RenderSystemOperation*> RenderSystemOperations;
144                RenderSystemOperations mRenderSystemOperations;
145
146       
147                /** Clear compiled state */
148                void clearCompiledState();
149
150                /** Compile this Composition chain into a series of RenderTarget operations.
151        */
152        void _compile();
153       
154        /** Prepare a viewport, the camera and the scene for a rendering operation
155         */
156        void preTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
157       
158        /** Restore a viewport, the camera and the scene after a rendering operation
159         */
160        void postTargetOperation(CompositorInstance::TargetOperation &op, Viewport *vp, Camera *cam);
161
162                /// destroy internal resources
163                void destroyResources(void);
164
165                /** Render queue listener used to set up rendering events. */
166                class RQListener: public RenderQueueListener
167                {
168                public:
169                        /** @copydoc RenderQueueListener::renderQueueStarted
170                        */
171                        virtual void renderQueueStarted(uint8 id, const String& invocation, bool& skipThisQueue);
172                        /** @copydoc RenderQueueListener::renderQueueEnded
173                        */
174                        virtual void renderQueueEnded(uint8 id, const String& invocation, bool& repeatThisQueue);
175
176                        /** Set current operation and target */
177                        void setOperation(CompositorInstance::TargetOperation *op,SceneManager *sm,RenderSystem *rs);
178
179                        /** Notify current destination viewport  */
180                        void notifyViewport(Viewport* vp) { mViewport = vp; }
181
182                        /** Flush remaining render system operations */
183                        void flushUpTo(uint8 id);
184                private:
185                        CompositorInstance::TargetOperation *mOperation;
186                        SceneManager *mSceneManager;
187                        RenderSystem *mRenderSystem;
188                        Viewport* mViewport;
189                        CompositorInstance::RenderSystemOpPairs::iterator currentOp, lastOp;
190                };
191                RQListener mOurListener;
192                /// Old viewport settings
193                unsigned int mOldClearEveryFrameBuffers;
194                /// Store old scene visibility mask
195                uint32 mOldVisibilityMask;
196                /// Store old find visible objects
197                bool mOldFindVisibleObjects;
198        /// Store old camera LOD bias     
199        float mOldLodBias;     
200                ///     Store old viewport material scheme
201                String mOldMaterialScheme;
202    };
203}
204
205#endif
Note: See TracBrowser for help on using the repository browser.