Coverage Report

Created: 2025-07-11 06:36

/src/ogre/OgreMain/include/OgreCompositionPass.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 __CompositionPass_H__
29
#define __CompositionPass_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreHeaderPrefix.h"
33
#include "OgreRenderSystem.h"
34
35
namespace Ogre {
36
37
    /** \addtogroup Core
38
    *  @{
39
    */
40
    /** \addtogroup Effects
41
    *  @{
42
    */
43
    /** Object representing one pass or operation in a composition sequence. This provides a 
44
        method to conveniently interleave RenderSystem commands between Render Queues.
45
     */
46
    class _OgreExport CompositionPass : public CompositorInstAlloc
47
    {
48
    public:
49
        CompositionPass(CompositionTargetPass *parent);
50
        ~CompositionPass();
51
        
52
        /** Enumeration that enumerates the various composition pass types.
53
        */
54
        enum PassType
55
        {
56
            PT_CLEAR,           //!< Clear target to one colour
57
            PT_STENCIL,         //!< Set stencil operation
58
            PT_RENDERSCENE,     //!< Render the scene or part of it
59
            PT_RENDERQUAD,      //!< Render a full screen quad
60
            PT_RENDERCUSTOM,    //!< Render a custom sequence
61
            PT_COMPUTE          //!< dispatch a compute shader
62
        };
63
        
64
        /** Set the type of composition pass */
65
        void setType(PassType type);
66
        /** Get the type of composition pass */
67
        PassType getType() const;
68
        
69
        /** Set an identifier for this pass. This identifier can be used to
70
            "listen in" on this pass with an CompositorInstance::Listener. 
71
        */
72
        void setIdentifier(uint32 id);
73
        /** Get the identifier for this pass */
74
        uint32 getIdentifier() const;
75
76
        /** Set the material used by this pass
77
            @note applies when PassType is RENDERQUAD 
78
        */
79
        void setMaterial(const MaterialPtr& mat);
80
        /** Set the material used by this pass 
81
            @note applies when PassType is RENDERQUAD 
82
        */
83
        void setMaterialName(const String &name);
84
        /** Get the material used by this pass 
85
            @note applies when PassType is RENDERQUAD 
86
        */
87
        const MaterialPtr& getMaterial() const;
88
        /** Set the first render queue to be rendered in this pass (inclusive) 
89
            @note applies when PassType is RENDERSCENE
90
        */
91
        void setFirstRenderQueue(uint8 id);
92
        /** Get the first render queue to be rendered in this pass (inclusive) 
93
            @note applies when PassType is RENDERSCENE
94
        */
95
        uint8 getFirstRenderQueue() const;
96
        /** Set the last render queue to be rendered in this pass (inclusive) 
97
            @note applies when PassType is RENDERSCENE
98
        */
99
        void setLastRenderQueue(uint8 id);
100
        /** Get the last render queue to be rendered in this pass (inclusive) 
101
            @note applies when PassType is RENDERSCENE
102
        */
103
        uint8 getLastRenderQueue() const;
104
105
        /** Set the material scheme used by this pass.
106
107
            Only applicable to passes that render the scene.
108
            @see Technique::setScheme.
109
        */
110
        void setMaterialScheme(const String& schemeName);
111
        /** Get the material scheme used by this pass.
112
113
            Only applicable to passes that render the scene.
114
            @see Technique::setScheme.
115
        */
116
        const String& getMaterialScheme(void) const;
117
118
        /** Would be nice to have for RENDERSCENE:
119
            flags to:
120
                exclude transparents
121
                override material (at least -- color)
122
        */
123
124
        /** Set the viewport clear buffers  (defaults to FBT_COLOUR|FBT_DEPTH)
125
            @param val is a combination of FBT_COLOUR, FBT_DEPTH, FBT_STENCIL.
126
            @note applies when PassType is CLEAR
127
        */
128
        void setClearBuffers(uint32 val);
129
        /** Get the viewport clear buffers.
130
            @note applies when PassType is CLEAR
131
        */
132
        uint32 getClearBuffers() const;
133
        /** Set the viewport clear colour (defaults to 0,0,0,0) 
134
            @note applies when PassType is CLEAR
135
         */
136
        void setClearColour(const ColourValue &val);
137
        /** Get the viewport clear colour (defaults to 0,0,0,0) 
138
            @note applies when PassType is CLEAR
139
         */
140
        const ColourValue &getClearColour() const;
141
        /** Set the clear colour to be the background colour of the original viewport
142
        @note applies when PassType is CLEAR
143
        */
144
        void setAutomaticColour(bool val);
145
        /** Retrieves if the clear colour is automatically set to the background colour of the original viewport
146
        @note applies when PassType is CLEAR
147
        */
148
        bool getAutomaticColour() const;
149
        /** Set the viewport clear depth (defaults to 1.0) 
150
            @note applies when PassType is CLEAR
151
        */
152
        void setClearDepth(float depth);
153
        /** Get the viewport clear depth (defaults to 1.0) 
154
            @note applies when PassType is CLEAR
155
        */
156
        float getClearDepth() const;
157
        /** Set the viewport clear stencil value (defaults to 0) 
158
            @note applies when PassType is CLEAR
159
        */
160
        void setClearStencil(uint16 value);
161
        /** Get the viewport clear stencil value (defaults to 0) 
162
            @note applies when PassType is CLEAR
163
        */
164
        uint16 getClearStencil() const;
165
166
        /** Set stencil check on or off.
167
            @note applies when PassType is STENCIL
168
        */
169
        void setStencilCheck(bool value);
170
        /** Get stencil check enable.
171
            @note applies when PassType is STENCIL
172
        */
173
        bool getStencilCheck() const;
174
        /** Set stencil compare function.
175
            @note applies when PassType is STENCIL
176
        */
177
        void setStencilFunc(CompareFunction value); 
178
        /** Get stencil compare function.
179
            @note applies when PassType is STENCIL
180
        */
181
        CompareFunction getStencilFunc() const; 
182
        /** Set stencil reference value.
183
            @note applies when PassType is STENCIL
184
        */
185
        void setStencilRefValue(uint32 value);
186
        /** Get stencil reference value.
187
            @note applies when PassType is STENCIL
188
        */
189
        uint32 getStencilRefValue() const;
190
        /** Set stencil mask.
191
            @note applies when PassType is STENCIL
192
        */
193
        void setStencilMask(uint32 value);
194
        /** Get stencil mask.
195
            @note applies when PassType is STENCIL
196
        */
197
        uint32 getStencilMask() const;
198
        /** Set stencil fail operation.
199
            @note applies when PassType is STENCIL
200
        */
201
        void setStencilFailOp(StencilOperation value);
202
        /** Get stencil fail operation.
203
            @note applies when PassType is STENCIL
204
        */
205
        StencilOperation getStencilFailOp() const;
206
        /** Set stencil depth fail operation.
207
            @note applies when PassType is STENCIL
208
        */
209
        void setStencilDepthFailOp(StencilOperation value);
210
        /** Get stencil depth fail operation.
211
            @note applies when PassType is STENCIL
212
        */
213
        StencilOperation getStencilDepthFailOp() const;
214
        /** Set stencil pass operation.
215
            @note applies when PassType is STENCIL
216
        */
217
        void setStencilPassOp(StencilOperation value);
218
        /** Get stencil pass operation.
219
            @note applies when PassType is STENCIL
220
        */
221
        StencilOperation getStencilPassOp() const;
222
        /** Set two sided stencil operation.
223
            @note applies when PassType is STENCIL
224
        */
225
        void setStencilTwoSidedOperation(bool value);
226
        /** Get two sided stencil operation.
227
            @note applies when PassType is STENCIL
228
        */
229
        bool getStencilTwoSidedOperation() const;
230
231
0
        const StencilState& getStencilState() const { return mStencilState; }
232
233
        /// Inputs (for material used for rendering the quad)
234
        struct InputTex
235
        {
236
            /// Name (local) of the input texture (empty == no input)
237
            String name;
238
            /// MRT surface index if applicable
239
            size_t mrtIndex;
240
0
            InputTex() : mrtIndex(0) {}
241
            InputTex(const String& _name, size_t _mrtIndex = 0)
242
0
                : name(_name), mrtIndex(_mrtIndex) {}
243
        };
244
245
        /** Set an input local texture. An empty string clears the input.
246
            @param id    Input to set. Must be in 0..OGRE_MAX_TEXTURE_LAYERS-1
247
            @param input Which texture to bind to this input. An empty string clears the input.
248
            @param mrtIndex Which surface of an MRT to retrieve
249
            @note applies when PassType is RENDERQUAD 
250
        */
251
        void setInput(size_t id, const String &input=BLANKSTRING, size_t mrtIndex=0);
252
        
253
        /** Get the value of an input.
254
            @param id    Input to get. Must be in 0..OGRE_MAX_TEXTURE_LAYERS-1.
255
            @note applies when PassType is RENDERQUAD 
256
        */
257
        const InputTex &getInput(size_t id) const;
258
        
259
        /** Get the number of inputs used.
260
            @note applies when PassType is RENDERQUAD 
261
        */
262
        size_t getNumInputs() const;
263
        
264
        /** Clear all inputs.
265
            @note applies when PassType is RENDERQUAD 
266
        */
267
        void clearAllInputs();
268
        
269
        /** Get parent object 
270
            @note applies when PassType is RENDERQUAD 
271
        */
272
        CompositionTargetPass *getParent();
273
274
        /** Determine if this target pass is supported on the current rendering device. 
275
         */
276
        bool _isSupported(void);
277
278
        /** Set quad normalised positions [-1;1]x[-1;1]
279
            @note applies when PassType is RENDERQUAD
280
         */
281
0
        void setQuadCorners(const FloatRect& quad) { mQuad.rect = quad; mQuad.cornerModified = true; }
282
283
        /** Get quad normalised positions [-1;1]x[-1;1]
284
            @note applies when PassType is RENDERQUAD 
285
         */
286
0
        bool getQuadCorners(FloatRect& quad) const { quad = mQuad.rect; return mQuad.cornerModified; }
287
            
288
        /** Sets the use of camera frustum far corners provided in the quad's normals
289
            @note applies when PassType is RENDERQUAD 
290
        */
291
        void setQuadFarCorners(bool farCorners, bool farCornersViewSpace);
292
293
        /** Returns true if camera frustum far corners are provided in the quad.
294
            @note applies when PassType is RENDERQUAD 
295
        */
296
        bool getQuadFarCorners() const;
297
298
        /** Returns true if the far corners provided in the quad are in view space
299
            @note applies when PassType is RENDERQUAD 
300
        */
301
        bool getQuadFarCornersViewSpace() const;
302
303
        /** Set the type name of this custom composition pass.
304
            @note applies when PassType is RENDERCUSTOM
305
            @see CompositorManager::registerCustomCompositionPass
306
        */
307
        void setCustomType(const String& customType);
308
309
        /** Get the type name of this custom composition pass.
310
            @note applies when PassType is RENDERCUSTOM
311
            @see CompositorManager::registerCustomCompositionPass
312
        */
313
        const String& getCustomType() const;
314
315
0
        void setThreadGroups(const Vector3i& g) { mThreadGroups = g; }
316
0
        const Vector3i& getThreadGroups() const { return mThreadGroups; }
317
318
0
        void setCameraName(const String& name) { mRenderScene.cameraName = name; }
319
0
        const String& getCameraName() const { return mRenderScene.cameraName; }
320
321
0
        void setAlignCameraToFace(bool val) { mRenderScene.alignCameraToFace = val; }
322
0
        bool getAlignCameraToFace() const { return mRenderScene.alignCameraToFace; }
323
    private:
324
        /// Parent technique
325
        CompositionTargetPass *mParent;
326
        /// Type of composition pass
327
        PassType mType;
328
329
        // in case of PT_RENDERQUAD, PT_COMPUTE, PT_CUSTOM
330
        struct MaterialData
331
        {
332
            /// Identifier for this pass
333
            uint32 identifier;
334
            /// Material used for rendering
335
            MaterialPtr material;
336
            /** Inputs (for material used for rendering the quad).
337
                An empty string signifies that no input is used */
338
            InputTex inputs[OGRE_MAX_TEXTURE_LAYERS];
339
340
0
            MaterialData() : identifier(0) {}
341
        } mMaterial;
342
343
        // in case of PT_RENDERSCENE
344
        struct RenderSceneData
345
        {
346
            /// [first,last] render queue to render this pass (in case of PT_RENDERSCENE)
347
            uint8 firstRenderQueue;
348
            uint8 lastRenderQueue;
349
350
            /// Material scheme name
351
            String materialScheme;
352
353
            /// name of camera to use instead of default
354
            String cameraName;
355
            bool alignCameraToFace;
356
357
            RenderSceneData()
358
0
                : firstRenderQueue(RENDER_QUEUE_BACKGROUND), lastRenderQueue(RENDER_QUEUE_TRANSPARENTS),
359
0
                  alignCameraToFace(false)
360
0
            {
361
0
            }
362
        } mRenderScene;
363
364
        // in case of PT_CLEAR
365
        struct ClearData
366
        {
367
            /// Clear buffers
368
            uint32 buffers;
369
            /// Clear colour
370
            ColourValue colour;
371
            /// Clear colour with the colour of the original viewport. Overrides mClearColour
372
            bool automaticColour;
373
            /// Clear depth
374
            float depth;
375
            /// Clear stencil value
376
            uint16 stencil;
377
378
            ClearData()
379
0
                : buffers(FBT_COLOUR | FBT_DEPTH), colour(ColourValue::ZERO), automaticColour(false),
380
0
                  depth(1.0f), stencil(0)
381
0
            {
382
0
            }
383
        } mClear;
384
385
        /// in case of PT_COMPUTE
386
        Vector3i mThreadGroups;
387
388
        /// in case of PT_STENCIL
389
        StencilState mStencilState;
390
391
        // in case of PT_RENDERQUAD
392
        struct QuadData
393
        {
394
            /// True if quad should not cover whole screen
395
            bool cornerModified;
396
            /// quad positions in normalised coordinates [-1;1]x[-1;1]
397
            FloatRect rect;
398
            bool farCorners, farCornersViewSpace;
399
400
            QuadData()
401
0
                : cornerModified(false), rect(-1, 1, 1, -1), farCorners(false), farCornersViewSpace(false)
402
0
            {
403
0
            }
404
        } mQuad;
405
406
        /// in case of PT_RENDERCUSTOM
407
        String mCustomType;
408
    };
409
    /** @} */
410
    /** @} */
411
412
}
413
414
#include "OgreHeaderSuffix.h"
415
416
#endif