Coverage Report

Created: 2026-02-26 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgreViewport.h
Line
Count
Source
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 __Viewport_H__
29
#define __Viewport_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreCommon.h"
33
#include "OgreFrustum.h"
34
#include "OgreHeaderPrefix.h"
35
36
namespace Ogre {
37
    /** \addtogroup Core
38
    *  @{
39
    */
40
    /** \addtogroup RenderSystem
41
    *  @{
42
    */
43
    /** An abstraction of a viewport, i.e., a rendering region on a render
44
        target.
45
46
        A viewport is the meeting of a camera and a rendering surface -
47
        the camera renders the scene from a viewpoint, and places its
48
        results into some subset of a rendering target, which may be the
49
        whole surface or just a part of the surface. Each viewport has a
50
        single camera as source and a single target as destination. A
51
        camera only has 1 viewport, but a render target may have several.
52
        A viewport also has a Z-order, i.e. if there is more than one
53
        viewport on a single render target and they overlap, one must
54
        obscure the other in some predetermined way.
55
    */
56
    class _OgreExport Viewport : public ViewportAlloc
57
    {
58
    public:
59
        /** Listener interface so you can be notified of Viewport changes. */
60
        class _OgreExport Listener
61
        {
62
        public:
63
0
            virtual ~Listener() {}
64
65
            /** Notification of when a new camera is set to target listening Viewport. */
66
0
            virtual void viewportCameraChanged(Viewport* viewport) {}
67
68
            /** Notification of when target listening Viewport's dimensions changed. */
69
0
            virtual void viewportDimensionsChanged(Viewport* viewport) {}
70
71
            /** Notification of when target listening Viewport's is destroyed. */
72
0
            virtual void viewportDestroyed(Viewport* viewport) {}
73
        };
74
75
        /** The usual constructor.
76
            @param camera
77
                Pointer to a camera to be the source for the image.
78
            @param target
79
                Pointer to the render target to be the destination
80
                for the rendering.
81
            @param left, top, width, height
82
                Dimensions of the viewport, expressed as a value between
83
                0 and 1. This allows the dimensions to apply irrespective of
84
                changes in the target's size: e.g. to fill the whole area,
85
                values of 0,0,1,1 are appropriate.
86
            @param ZOrder
87
                Relative Z-order on the target. Lower = further to
88
                the front.
89
        */
90
        Viewport(Camera* camera, RenderTarget* target, float left, float top, float width, float height, int ZOrder)
91
            : Viewport(camera, target, {left, top, left + width, top + height}, ZOrder)
92
0
        {
93
0
        }
94
95
        /// @overload
96
        Viewport(Camera* camera, RenderTarget* target, FloatRect relRect, int ZOrder);
97
98
        /** Default destructor.
99
        */
100
        virtual ~Viewport();
101
102
        /** Notifies the viewport of a possible change in dimensions.
103
104
            Used by the target to update the viewport's dimensions
105
            (usually the result of a change in target size).
106
            @note
107
                Internal use by Ogre only.
108
        */
109
        void _updateDimensions(void);
110
111
        /** Instructs the viewport to updates its contents.
112
        */
113
        void update(void);
114
        
115
        /// @deprecated use RenderSystem::clearFrameBuffer instead
116
        OGRE_DEPRECATED void clear(uint32 buffers = FBT_COLOUR | FBT_DEPTH, const ColourValue& colour = ColourValue::Black,
117
                   float depth = 1.0f, uint16 stencil = 0);
118
119
        /** Retrieves a pointer to the render target for this viewport.
120
        */
121
0
        RenderTarget* getTarget(void) const { return mTarget; }
122
123
        /** Retrieves a pointer to the camera for this viewport.
124
        */
125
0
        Camera* getCamera(void) const { return mCamera; }
126
127
        /** Sets the camera to use for rendering to this viewport. */
128
        void setCamera(Camera* cam);
129
130
        /** Gets the Z-Order of this viewport. */
131
0
        int getZOrder(void) const { return mZOrder; }
132
133
        /// @name Relative dimensions
134
        /// These methods return the relative dimensions of the viewport, which are
135
        /// expressed as a value between 0.0 and 1.0.
136
        /// @{
137
0
        float getLeft(void) const { return mRelRect.left; }
138
0
        float getTop(void) const { return mRelRect.top; }
139
0
        float getWidth(void) const { return mRelRect.width(); }
140
0
        float getHeight(void) const { return mRelRect.height(); }
141
0
        FloatRect getDimensions(void) const { return mRelRect; }
142
        /// @}
143
144
        /** Sets the dimensions (after creation).
145
            @param
146
                left Left point of viewport.
147
            @param
148
                top Top point of the viewport.
149
            @param
150
                width Width of the viewport.
151
            @param
152
                height Height of the viewport.
153
            @note Dimensions relative to the size of the target,
154
                represented as real values between 0 and 1. i.e. the full
155
                target area is 0, 0, 1, 1.
156
        */
157
        void setDimensions(float left, float top, float width, float height);
158
159
        /// @name Actual dimensions
160
        /// These methods return the actual dimensions of the viewport in pixels.
161
        /// @{
162
0
        int getActualLeft(void) const { return mActRect.left; }
163
0
        int getActualTop(void) const { return mActRect.top; }
164
0
        int getActualWidth(void) const { return mActRect.width(); }
165
0
        int getActualHeight(void) const { return mActRect.height(); }
166
0
        Rect getActualDimensions() const { return mActRect; }
167
        /// @}
168
169
        /** Sets the initial background colour of the viewport (before
170
            rendering).
171
        */
172
0
        void setBackgroundColour(const ColourValue& colour) { mBackColour = colour; }
173
174
        /** Gets the background colour.
175
        */
176
0
        const ColourValue& getBackgroundColour(void) const { return mBackColour; }
177
178
        /** Sets the initial depth buffer value of the viewport (before
179
            rendering). Default is 1
180
        */
181
0
        void setDepthClear( float depth ) { mDepthClearValue = depth; }
182
183
        /** Gets the default depth buffer value to which the viewport is cleared.
184
        */
185
0
        float getDepthClear(void) const { return mDepthClearValue; }
186
187
        /** Determines whether to clear the viewport before rendering.
188
189
            You can use this method to set which buffers are cleared
190
            (if any) before rendering every frame.
191
        @param clear Whether or not to clear any buffers
192
        @param buffers One or more values from FrameBufferType denoting
193
            which buffers to clear, if clear is set to true. Note you should
194
            not clear the stencil buffer here unless you know what you're doing.
195
         */
196
        void setClearEveryFrame(bool clear, unsigned int buffers = FBT_COLOUR | FBT_DEPTH);
197
198
        /** Determines if the viewport is cleared before every frame.
199
        */
200
0
        bool getClearEveryFrame(void) const { return mClearEveryFrame; }
201
202
        /** Gets which buffers are to be cleared each frame. */
203
0
        unsigned int getClearBuffers(void) const { return mClearBuffers; }
204
205
        /** Sets whether this viewport should be automatically updated 
206
            if Ogre's rendering loop or RenderTarget::update is being used.
207
208
            By default, if you use Ogre's own rendering loop (Root::startRendering)
209
            or call RenderTarget::update, all viewports are updated automatically.
210
            This method allows you to control that behaviour, if for example you 
211
            have a viewport which you only want to update periodically.
212
        @param autoupdate If true, the viewport is updated during the automatic
213
            render loop or when RenderTarget::update() is called. If false, the 
214
            viewport is only updated when its update() method is called explicitly.
215
        */
216
0
        void setAutoUpdated(bool autoupdate) { mIsAutoUpdated = autoupdate; }
217
        /** Gets whether this viewport is automatically updated if 
218
            Ogre's rendering loop or RenderTarget::update is being used.
219
        */
220
0
        bool isAutoUpdated() const { return mIsAutoUpdated; }
221
222
        /** Set the material scheme which the viewport should use.
223
224
            This allows you to tell the system to use a particular
225
            material scheme when rendering this viewport, which can 
226
            involve using different techniques to render your materials.
227
        @see Technique::setSchemeName
228
        */
229
        void setMaterialScheme(const String& schemeName)
230
0
        { mMaterialSchemeName = schemeName; }
231
        
232
        /** Get the material scheme which the viewport should use.
233
        */
234
        const String& getMaterialScheme(void) const
235
0
        { return mMaterialSchemeName; }
236
237
        /// @deprecated
238
        OGRE_DEPRECATED void getActualDimensions(int& left, int& top, int& width, int& height) const;
239
240
        bool _isUpdated(void) const;
241
        void _clearUpdatedFlag(void);
242
243
        /** Gets the number of rendered faces in the last update.
244
        */
245
        unsigned int _getNumRenderedFaces(void) const;
246
247
        /** Gets the number of rendered batches in the last update.
248
        */
249
        unsigned int _getNumRenderedBatches(void) const;
250
251
        /** Tells this viewport whether it should display Overlay objects.
252
253
            Overlay objects are layers which appear on top of the scene. They are created via
254
            @ref OverlayManager::create and every viewport displays these by default.
255
            However, you probably don't want this if you're using multiple viewports,
256
            because one of them is probably a picture-in-picture which is not supposed to
257
            have overlays of it's own. In this case you can turn off overlays on this viewport
258
            by calling this method.
259
        @param enabled If true, any overlays are displayed, if false they are not.
260
        */
261
0
        void setOverlaysEnabled(bool enabled) { mShowOverlays = enabled; }
262
263
        /** Returns whether or not Overlay objects (created with the OverlayManager) are displayed in this
264
            viewport. */
265
0
        bool getOverlaysEnabled(void) const { return mShowOverlays; }
266
267
        /** Tells this viewport whether it should display skies.
268
269
            Skies are layers which appear on background of the scene. They are created via
270
            SceneManager::setSkyBox, SceneManager::setSkyPlane and SceneManager::setSkyDome and
271
            every viewport displays these by default. However, you probably don't want this if
272
            you're using multiple viewports, because one of them is probably a picture-in-picture
273
            which is not supposed to have skies of it's own. In this case you can turn off skies
274
            on this viewport by calling this method.
275
        @param enabled If true, any skies are displayed, if false they are not.
276
        */
277
0
        void setSkiesEnabled(bool enabled) { mShowSkies = enabled; }
278
279
        /** Returns whether or not skies (created in the SceneManager) are displayed in this
280
            viewport. */
281
0
        bool getSkiesEnabled(void) const { return mShowSkies; }
282
283
        /** Tells this viewport whether it should display shadows.
284
285
            This setting enables you to disable shadow rendering for a given viewport. The global
286
            shadow technique set on SceneManager still controls the type and nature of shadows,
287
            but this flag can override the setting so that no shadows are rendered for a given
288
            viewport to save processing time where they are not required.
289
        @param enabled If true, any shadows are displayed, if false they are not.
290
        */
291
0
        void setShadowsEnabled(bool enabled) { mShowShadows = enabled; }
292
293
        /** Returns whether or not shadows (defined in the SceneManager) are displayed in this
294
            viewport. */
295
0
        bool getShadowsEnabled(void) const { return mShowShadows; }
296
297
298
        /** Sets a per-viewport visibility mask.
299
300
            The visibility mask is a way to exclude objects from rendering for
301
            a given viewport. For each object in the frustum, a check is made
302
            between this mask and the objects visibility flags, and if a binary 'and'
303
            returns zero, the object will not be rendered.
304
            @see MovableObject::setVisibilityFlags
305
        */
306
0
        void setVisibilityMask(uint32 mask) { mVisibilityMask = mask; }
307
308
        /** Gets a per-viewport visibility mask.
309
        @see Viewport::setVisibilityMask
310
        */
311
0
        uint getVisibilityMask(void) const { return mVisibilityMask; }
312
313
        /// Add a listener to this viewport
314
        void addListener(Listener* l);
315
        /// Remove a listener to this viewport
316
        void removeListener(Listener* l);
317
    
318
    /** Sets the draw buffer type for the next frame.
319
320
      Specifies the particular buffer that will be
321
      targeted by the render target. Should be used if
322
      the render target supports quad buffer stereo. If
323
      the render target does not support stereo (ie. left
324
      and right), then only back and front will be used.
325
    @param
326
      colourBuffer Specifies the particular buffer that will be
327
      targeted by the render target.
328
    */
329
0
    void setDrawBuffer(ColourBufferType colourBuffer) { mColourBuffer = colourBuffer; }
330
331
    /** Returns the current colour buffer type for this viewport.*/
332
0
    ColourBufferType getDrawBuffer() const { return mColourBuffer; }
333
334
    private:
335
        Camera* mCamera;
336
        RenderTarget* mTarget;
337
        /// Relative dimensions, irrespective of target dimensions (0..1)
338
        FloatRect mRelRect;
339
        /// Actual dimensions, based on target dimensions
340
        Rect mActRect;
341
        /// Z-order
342
        int mZOrder;
343
        /// Background options
344
        ColourValue mBackColour;
345
        float mDepthClearValue;
346
        bool mClearEveryFrame;
347
        unsigned int mClearBuffers;
348
        bool mUpdated;
349
        bool mShowOverlays;
350
        bool mShowSkies;
351
        bool mShowShadows;
352
        uint32 mVisibilityMask;
353
        /// Material scheme
354
        String mMaterialSchemeName;
355
356
        /// Automatic rendering on/off
357
        bool mIsAutoUpdated;
358
359
        typedef std::vector<Listener*> ListenerList;
360
        ListenerList mListeners;
361
    ColourBufferType mColourBuffer;
362
    };
363
    /** @} */
364
    /** @} */
365
366
}
367
368
#include "OgreHeaderSuffix.h"
369
370
#endif