Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreCompositorInstance.h @ 3

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

=update

File size: 9.8 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 __CompositorInstance_H__
30#define __CompositorInstance_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreMaterial.h"
34#include "OgreTexture.h"
35#include "OgreRenderQueue.h"
36namespace Ogre {
37    const size_t RENDER_QUEUE_COUNT = RENDER_QUEUE_OVERLAY+1;       
38           
39    /** An instance of a Compositor object for one Viewport. It is part of the CompositorChain
40                for a Viewport.
41     */
42    class _OgreExport CompositorInstance
43    {
44    public:
45        CompositorInstance(Compositor *filter, CompositionTechnique *technique, CompositorChain *chain);
46        virtual ~CompositorInstance();
47                /** Provides an interface to "listen in" to to render system operations executed by this
48                        CompositorInstance.
49                */
50                class _OgreExport Listener
51                {
52                public:
53                        virtual ~Listener();
54
55                        /** Notification of when a render target operation involving a material (like
56                                rendering a quad) is compiled, so that miscelleneous parameters that are different
57                                per Compositor instance can be set up.
58                                @param pass_id  Pass identifier within Compositor instance, this is speficied
59                                                                by the user by CompositionPass::setIdentifier().
60                                @param mat              Material, this may be changed at will and will only affect
61                                                                the current instance of the Compositor, not the global material
62                                                                it was cloned from.
63                         */
64                        virtual void notifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
65
66                        /** Notification before a render target operation involving a material (like
67                                rendering a quad), so that material parameters can be varied.
68                                @param pass_id  Pass identifier within Compositor instance, this is speficied
69                                                                by the user by CompositionPass::setIdentifier().
70                                @param mat              Material, this may be changed at will and will only affect
71                                                                the current instance of the Compositor, not the global material
72                                                                it was cloned from.
73                         */
74                        virtual void notifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
75                };
76        /** Specific render system operation. A render target operation does special operations
77                    between render queues like rendering a quad, clearing the frame buffer or
78                        setting stencil state.
79                */
80                class RenderSystemOperation
81                {
82                public:
83                        virtual ~RenderSystemOperation();
84                        /// Set state to SceneManager and RenderSystem
85                        virtual void execute(SceneManager *sm, RenderSystem *rs) = 0;
86                };
87                typedef std::map<int, MaterialPtr> QuadMaterialMap;
88                typedef std::pair<int, RenderSystemOperation*> RenderSystemOpPair;
89                typedef std::vector<RenderSystemOpPair> RenderSystemOpPairs;
90        /** Operation setup for a RenderTarget (collected).
91        */
92        class TargetOperation
93        {
94        public:
95            TargetOperation()
96            { 
97            }
98            TargetOperation(RenderTarget *target):
99                target(target), currentQueueGroupID(0), visibilityMask(0xFFFFFFFF),
100                lodBias(1.0f),
101                onlyInitial(false), hasBeenRendered(false), findVisibleObjects(false), 
102                                shadowsEnabled(true)
103            { 
104            }
105            /// Target
106            RenderTarget *target;
107
108                        /// Current group ID
109                        int currentQueueGroupID;
110
111                        /// RenderSystem operations to queue into the scene manager, by
112                        /// uint8
113                        RenderSystemOpPairs renderSystemOperations;
114
115                        /// Scene visibility mask
116            /// If this is 0, the scene is not rendered at all
117            uint32 visibilityMask;
118           
119            /// LOD offset. This is multiplied with the camera LOD offset
120            /// 1.0 is default, lower means lower detail, higher means higher detail
121            float lodBias;
122           
123            /** A set of render queues to either include or exclude certain render queues.
124                        */
125            typedef std::bitset<RENDER_QUEUE_COUNT> RenderQueueBitSet;
126
127                        /// Which renderqueues to render from scene
128                        RenderQueueBitSet renderQueues;
129           
130            /** @see CompositionTargetPass::mOnlyInitial
131            */
132            bool onlyInitial;
133            /** "Has been rendered" flag; used in combination with
134                onlyInitial to determine whether to skip this target operation.
135            */
136            bool hasBeenRendered;
137            /** Whether this op needs to find visible scene objects or not
138            */
139            bool findVisibleObjects;
140                        /** Which material scheme this op will use */
141                        String materialScheme;
142                        /** Whether shadows will be enabled */
143                        bool shadowsEnabled;
144        };
145        typedef std::vector<TargetOperation> CompiledState;
146       
147        /** Set enabled flag. The compositor instance will only render if it is
148            enabled, otherwise it is pass-through.
149        */
150        void setEnabled(bool value);
151       
152        /** Get enabled flag.
153        */
154        bool getEnabled();
155
156                /** Get the instance name for a local texture.
157                @note It is only valid to call this when local textures have been loaded,
158                        which in practice means that the compositor instance is active. Calling
159                        it at other times will cause an exception. Note that since textures
160                        are cleaned up aggressively, this name is not guaranteed to stay the
161                        same if you disable and renable the compositor instance.
162                @param name The name of the texture in the original compositor definition
163                @returns The instance name for the texture, corresponds to a real texture
164                */
165                const String& getTextureInstanceName(const String& name);
166
167       
168        /** Recursively collect target states (except for final Pass).
169            @param compiledState    This vector will contain a list of TargetOperation objects
170        */
171        virtual void _compileTargetOperations(CompiledState &compiledState);
172       
173        /** Compile the final (output) operation. This is done seperately because this
174            is combined with the input in chained filters.
175        */
176        virtual void _compileOutputOperation(TargetOperation &finalState);
177       
178        /** Get Compositor of which this is an instance
179        */
180        Compositor *getCompositor();
181       
182        /** Get CompositionTechnique used by this instance
183        */
184        CompositionTechnique *getTechnique();
185
186                /** Get Chain that this instance is part of
187        */
188        CompositorChain *getChain();
189
190                /** Add a listener. Listeners provide an interface to "listen in" to to render system
191                        operations executed by this CompositorInstance so that materials can be
192                        programmatically set up.
193                        @see CompositorInstance::Listener
194                */
195                void addListener(Listener *l);
196
197                /** Remove a listener.
198                        @see CompositorInstance::Listener
199                */
200                void removeListener(Listener *l);
201
202                /** Notify listeners of a material compilation.
203                */
204                void _fireNotifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
205
206                /** Notify listeners of a material render.
207                */
208                void _fireNotifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
209        private:
210        /// Compositor of which this is an instance
211        Compositor *mCompositor;
212        /// Composition technique used by this instance
213        CompositionTechnique *mTechnique;
214        /// Composition chain of which this instance is part
215        CompositorChain *mChain;
216        /// Is this instance enabled?
217        bool mEnabled;
218        /// Map from name->local texture
219        typedef std::map<String,TexturePtr> LocalTextureMap;
220        LocalTextureMap mLocalTextures;
221
222                /// Vector of listeners
223                typedef std::vector<Listener*> Listeners;
224                Listeners mListeners;
225       
226        /// Previous instance (set by chain)
227        CompositorInstance *mPreviousInstance;
228               
229                /** Collect rendering passes. Here, passes are converted into render target operations
230                        and queued with queueRenderSystemOp.
231        */
232        virtual void collectPasses(TargetOperation &finalState, CompositionTargetPass *target);
233       
234        /** Create a local dummy material with one technique but no passes.
235            The material is detached from the Material Manager to make sure it is destroyed
236                        when going out of scope.
237        */
238        MaterialPtr createLocalMaterial();
239       
240        /** Create local rendertextures and other resources. Builds mLocalTextures.
241        */
242        void createResources();
243       
244        /** Destroy local rendertextures and other resources.
245        */
246        void freeResources();
247
248        /** Get RenderTarget for a named local texture.
249        */
250        RenderTarget *getTargetForTex(const String &name);
251       
252        /** Get source texture name for a named local texture.
253        */
254        const String &getSourceForTex(const String &name);
255
256                /** Queue a render system operation.
257                        @returns destination pass
258                 */
259                void queueRenderSystemOp(TargetOperation &finalState, RenderSystemOperation *op);
260       
261        friend class CompositorChain;
262    };
263}
264
265#endif
Note: See TracBrowser for help on using the repository browser.