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

Revision 1809, 9.8 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 __CompositorInstance_H__
26#define __CompositorInstance_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreMaterial.h"
30#include "OgreTexture.h"
31#include "OgreRenderQueue.h"
32namespace 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                /** Get the instance name for a local texture.
150                @note It is only valid to call this when local textures have been loaded,
151                        which in practice means that the compositor instance is active. Calling
152                        it at other times will cause an exception. Note that since textures
153                        are cleaned up aggressively, this name is not guaranteed to stay the
154                        same if you disable and renable the compositor instance.
155                @param name The name of the texture in the original compositor definition
156                @returns The instance name for the texture, corresponds to a real texture
157                */
158                const String& getTextureInstanceName(const String& name);
159
160       
161        /** Recursively collect target states (except for final Pass).
162            @param compiledState    This vector will contain a list of TargetOperation objects
163        */
164        virtual void _compileTargetOperations(CompiledState &compiledState);
165       
166        /** Compile the final (output) operation. This is done seperately because this
167            is combined with the input in chained filters.
168        */
169        virtual void _compileOutputOperation(TargetOperation &finalState);
170       
171        /** Get Compositor of which this is an instance
172        */
173        Compositor *getCompositor();
174       
175        /** Get CompositionTechnique used by this instance
176        */
177        CompositionTechnique *getTechnique();
178
179                /** Get Chain that this instance is part of
180        */
181        CompositorChain *getChain();
182
183                /** Add a listener. Listeners provide an interface to "listen in" to to render system
184                        operations executed by this CompositorInstance so that materials can be
185                        programmatically set up.
186                        @see CompositorInstance::Listener
187                */
188                void addListener(Listener *l);
189
190                /** Remove a listener.
191                        @see CompositorInstance::Listener
192                */
193                void removeListener(Listener *l);
194
195                /** Notify listeners of a material compilation.
196                */
197                void _fireNotifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
198
199                /** Notify listeners of a material render.
200                */
201                void _fireNotifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
202        private:
203        /// Compositor of which this is an instance
204        Compositor *mCompositor;
205        /// Composition technique used by this instance
206        CompositionTechnique *mTechnique;
207        /// Composition chain of which this instance is part
208        CompositorChain *mChain;
209        /// Is this instance enabled?
210        bool mEnabled;
211        /// Map from name->local texture
212        typedef std::map<String,TexturePtr> LocalTextureMap;
213        LocalTextureMap mLocalTextures;
214
215                /// Vector of listeners
216                typedef std::vector<Listener*> Listeners;
217                Listeners mListeners;
218       
219        /// Previous instance (set by chain)
220        CompositorInstance *mPreviousInstance;
221               
222                /** Collect rendering passes. Here, passes are converted into render target operations
223                        and queued with queueRenderSystemOp.
224        */
225        virtual void collectPasses(TargetOperation &finalState, CompositionTargetPass *target);
226       
227        /** Create a local dummy material with one technique but no passes.
228            The material is detached from the Material Manager to make sure it is destroyed
229                        when going out of scope.
230        */
231        MaterialPtr createLocalMaterial();
232       
233        /** Create local rendertextures and other resources. Builds mLocalTextures.
234        */
235        void createResources();
236       
237        /** Destroy local rendertextures and other resources.
238        */
239        void freeResources();
240
241        /** Get RenderTarget for a named local texture.
242        */
243        RenderTarget *getTargetForTex(const String &name);
244       
245        /** Get source texture name for a named local texture.
246        */
247        const String &getSourceForTex(const String &name);
248
249                /** Queue a render system operation.
250                        @returns destination pass
251                 */
252                void queueRenderSystemOp(TargetOperation &finalState, RenderSystemOperation *op);
253       
254        friend class CompositorChain;
255    };
256}
257
258#endif
Note: See TracBrowser for help on using the repository browser.