Coverage Report

Created: 2025-07-18 07:08

/src/ogre/OgreMain/include/OgreCompositorManager.h
Line
Count
Source (jump to first uncovered line)
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 __CompositorManager_H__
29
#define __CompositorManager_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreResourceManager.h"
33
#include "OgreRenderSystem.h"
34
#include "OgreCompositionTechnique.h"
35
#include "OgreHeaderPrefix.h"
36
37
namespace Ogre {
38
39
    class Rectangle2D;
40
41
    /** \addtogroup Core
42
    *  @{
43
    */
44
    /** \addtogroup Effects
45
    *  @{
46
    */
47
    /** Class for managing Compositor settings for Ogre. Compositors provide the means
48
        to flexibly "composite" the final rendering result from multiple scene renders
49
        and intermediate operations like rendering fullscreen quads. This makes
50
        it possible to apply postfilter effects, HDRI postprocessing, and shadow
51
        effects to a Viewport.
52
        @par
53
            When loaded from a script, a Compositor is in an 'unloaded' state and only stores the settings
54
            required. It does not at that stage load any textures. This is because the material settings may be
55
            loaded 'en masse' from bulk material script files, but only a subset will actually be required.
56
        @par
57
            Because this is a subclass of ResourceManager, any files loaded will be searched for in any path or
58
            archive added to the resource paths/archives. See ResourceManager for details.
59
    */
60
    class _OgreExport CompositorManager : public ResourceManager, public Singleton<CompositorManager>
61
    {
62
    public:
63
        CompositorManager();
64
        virtual ~CompositorManager();
65
66
        /**
67
         * Create a new compositor
68
         * @see ResourceManager::createResource
69
         */
70
        CompositorPtr create (const String& name, const String& group,
71
                            bool isManual = false, ManualResourceLoader* loader = 0,
72
                            const NameValuePairList* createParams = 0);
73
74
        /// Get a resource by name. For example, a compositor defined in some .compositor script.
75
        /// @see ResourceManager::getResourceByName
76
        CompositorPtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME) const;
77
78
        /** Get the compositor chain for a Viewport. If there is none yet, a new
79
            compositor chain is registered.
80
            XXX We need a _notifyViewportRemoved to find out when this viewport disappears,
81
            so we can destroy its chain as well.
82
        */
83
        CompositorChain *getCompositorChain(Viewport *vp);
84
85
        /** Returns whether exists compositor chain for a viewport.
86
        */
87
        bool hasCompositorChain(const Viewport *vp) const;
88
89
        /** Remove the compositor chain from a viewport if exists.
90
        */
91
        void removeCompositorChain(const Viewport *vp);
92
93
        /** Add a compositor to a viewport. By default, it is added to end of the chain,
94
            after the other compositors.
95
            @param vp           Viewport to modify
96
            @param compositor   The name of the compositor to apply
97
            @param addPosition  At which position to add, defaults to the end (-1).
98
            @return pointer to instance, or 0 if it failed.
99
        */
100
        CompositorInstance *addCompositor(Viewport *vp, const String &compositor, int addPosition=-1);
101
102
        /** Remove a compositor from a viewport
103
        */
104
        void removeCompositor(Viewport *vp, const String &compositor);
105
106
        /** Set the state of a compositor on a viewport to enabled or disabled.
107
            Disabling a compositor stops it from rendering but does not free any resources.
108
            This can be more efficient than using removeCompositor and addCompositor in cases
109
            the filter is switched on and off a lot.
110
        */
111
        void setCompositorEnabled(Viewport *vp, const String &compositor, bool value);
112
113
        /** Get a textured fullscreen 2D rectangle, for internal use.
114
        */
115
        Renderable *_getTexturedRectangle2D();
116
117
        /** Overridden from ResourceManager since we have to clean up chains too. */
118
        void removeAll(void) override;
119
120
        /** Internal method for forcing all active compositors to recreate their resources. */
121
        void _reconstructAllCompositorResources();
122
123
        typedef std::set<Texture*> UniqueTextureSet;
124
125
        /** Utility function to get an existing pooled texture matching a given
126
            definition, or creating one if one doesn't exist. It also takes into
127
            account whether a pooled texture has already been supplied to this
128
            same requester already, in which case it won't give the same texture
129
            twice (this is important for example if you request 2 ping-pong textures, 
130
            you don't want to get the same texture for both requests!
131
        */
132
        TexturePtr getPooledTexture(const CompositionTechnique::TextureDefinition& def, const String& localName,
133
                                    PixelFormat f, const String& aaHint, UniqueTextureSet& texturesAlreadyAssigned,
134
                                    CompositorInstance* inst);
135
136
        /// @deprecated do not use
137
        OGRE_DEPRECATED TexturePtr getPooledTexture(const String& name, const String& localName,
138
            uint32 w, uint32 h,
139
            PixelFormat f, uint aa, const String& aaHint, bool srgb, UniqueTextureSet& texturesAlreadyAssigned, 
140
            CompositorInstance* inst, CompositionTechnique::TextureScope scope, TextureType type = TEX_TYPE_2D);
141
142
        /** Free pooled textures from the shared pool (compositor instances still 
143
            using them will keep them in memory though). 
144
        */
145
        void freePooledTextures(bool onlyIfUnreferenced = true);
146
147
        /** Register a compositor logic for listening in to expecting composition
148
            techniques.
149
        */
150
        void registerCompositorLogic(const String& name, CompositorLogic* logic);
151
152
        /** Removes a listener for compositor logic registered with registerCompositorLogic
153
        */
154
        void unregisterCompositorLogic(const String& name);
155
        
156
        /** Get a compositor logic by its name
157
        */
158
        CompositorLogic* getCompositorLogic(const String& name);
159
160
    /** Check if a compositor logic exists
161
    */
162
    bool hasCompositorLogic(const String& name);
163
    
164
        /** Register a custom composition pass.
165
        */
166
        void registerCustomCompositionPass(const String& name, CustomCompositionPass* customPass);
167
168
        void unregisterCustomCompositionPass(const String& name);
169
170
        /** Get a custom composition pass by its name 
171
        */
172
        CustomCompositionPass* getCustomCompositionPass(const String& name);
173
174
    /** Check if a compositor pass exists
175
    */
176
        bool hasCustomCompositionPass(const String& name);
177
178
        /**
179
        Relocates a compositor chain from one viewport to another
180
        @param sourceVP The viewport to take the chain from
181
        @param destVP The viewport to connect the chain to
182
        */
183
        void _relocateChain(Viewport* sourceVP, Viewport* destVP);
184
185
        /// @copydoc Singleton::getSingleton()
186
        static CompositorManager& getSingleton(void);
187
188
        /// @copydoc Singleton::getSingleton()
189
        static CompositorManager* getSingletonPtr(void);
190
    
191
    private:
192
        Resource* createImpl(const String& name, ResourceHandle handle,
193
            const String& group, bool isManual, ManualResourceLoader* loader,
194
            const NameValuePairList* params) override;
195
196
        typedef std::map<const Viewport*, CompositorChain*> Chains;
197
        Chains mChains;
198
199
        /** Clear composition chains for all viewports
200
         */
201
        void freeChains();
202
203
        Rectangle2D *mRectangle;
204
205
        /// List of instances
206
        typedef std::vector<CompositorInstance *> Instances;
207
        Instances mInstances;
208
209
        /// Map of registered compositor logics
210
        typedef std::map<String, CompositorLogic*> CompositorLogicMap;
211
        CompositorLogicMap mCompositorLogics;
212
213
        /// Map of registered custom composition passes
214
        typedef std::map<String, CustomCompositionPass*> CustomCompositionPassMap;
215
        CustomCompositionPassMap mCustomCompositionPasses;
216
217
        typedef std::vector<TexturePtr> TextureList;
218
        typedef VectorIterator<TextureList> TextureIterator;
219
220
        struct TextureDef
221
        {
222
            size_t width, height;
223
            TextureType type;
224
            PixelFormat format;
225
            uint fsaa;
226
            String fsaaHint;
227
            bool sRGBwrite;
228
229
            TextureDef(size_t w, size_t h, TextureType t, PixelFormat f, uint aa, const String& aaHint,
230
                       bool srgb)
231
0
                : width(w), height(h), type(t), format(f), fsaa(aa), fsaaHint(aaHint), sRGBwrite(srgb)
232
0
            {
233
0
            }
234
235
            bool operator<(const TextureDef& y) const
236
0
            {
237
0
                return std::tie(width, height, type, format, fsaa, fsaaHint, sRGBwrite) <
238
0
                       std::tie(y.width, y.height, y.type, y.format, y.fsaa, y.fsaaHint, y.sRGBwrite);
239
0
            }
240
        };
241
        typedef std::map<TextureDef, TextureList> TexturesByDef;
242
        TexturesByDef mTexturesByDef;
243
244
        typedef std::pair<String, String> StringPair;
245
        typedef std::map<TextureDef, TexturePtr> TextureDefMap;
246
        typedef std::map<StringPair, TextureDefMap> ChainTexturesByDef;
247
        
248
        ChainTexturesByDef mChainTexturesByDef;
249
250
        bool isInputPreviousTarget(CompositorInstance* inst, const Ogre::String& localName);
251
        bool isInputPreviousTarget(CompositorInstance* inst, const TexturePtr& tex);
252
        bool isInputToOutputTarget(CompositorInstance* inst, const Ogre::String& localName);
253
        bool isInputToOutputTarget(CompositorInstance* inst, const TexturePtr& tex);
254
255
    };
256
    /** @} */
257
    /** @} */
258
259
}
260
261
#include "OgreHeaderSuffix.h"
262
263
#endif