/src/ogre/OgreMain/include/OgreViewport.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 __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 | | /** Instructs the viewport to clear itself, without performing an update. |
116 | | |
117 | | You would not normally call this method when updating the viewport, |
118 | | since the viewport usually clears itself when updating anyway. However, if you wish you have the |
119 | | option of manually clearing the frame buffer (or elements of it) |
120 | | using this method. |
121 | | @see Viewport::setClearEveryFrame |
122 | | @param buffers Bitmask identifying which buffer elements to clear |
123 | | @param colour The colour value to clear to, if FBT_COLOUR is included |
124 | | @param depth The depth value to clear to, if FBT_DEPTH is included |
125 | | @param stencil The stencil value to clear to, if FBT_STENCIL is included |
126 | | */ |
127 | | void clear(uint32 buffers = FBT_COLOUR | FBT_DEPTH, const ColourValue& colour = ColourValue::Black, |
128 | | float depth = 1.0f, uint16 stencil = 0); |
129 | | |
130 | | /** Retrieves a pointer to the render target for this viewport. |
131 | | */ |
132 | 0 | RenderTarget* getTarget(void) const { return mTarget; } |
133 | | |
134 | | /** Retrieves a pointer to the camera for this viewport. |
135 | | */ |
136 | 0 | Camera* getCamera(void) const { return mCamera; } |
137 | | |
138 | | /** Sets the camera to use for rendering to this viewport. */ |
139 | | void setCamera(Camera* cam); |
140 | | |
141 | | /** Gets the Z-Order of this viewport. */ |
142 | 0 | int getZOrder(void) const { return mZOrder; } |
143 | | |
144 | | /// @name Relative dimensions |
145 | | /// These methods return the relative dimensions of the viewport, which are |
146 | | /// expressed as a value between 0.0 and 1.0. |
147 | | /// @{ |
148 | 0 | float getLeft(void) const { return mRelRect.left; } |
149 | 0 | float getTop(void) const { return mRelRect.top; } |
150 | 0 | float getWidth(void) const { return mRelRect.width(); } |
151 | 0 | float getHeight(void) const { return mRelRect.height(); } |
152 | 0 | FloatRect getDimensions(void) const { return mRelRect; } |
153 | | /// @} |
154 | | |
155 | | /** Sets the dimensions (after creation). |
156 | | @param |
157 | | left Left point of viewport. |
158 | | @param |
159 | | top Top point of the viewport. |
160 | | @param |
161 | | width Width of the viewport. |
162 | | @param |
163 | | height Height of the viewport. |
164 | | @note Dimensions relative to the size of the target, |
165 | | represented as real values between 0 and 1. i.e. the full |
166 | | target area is 0, 0, 1, 1. |
167 | | */ |
168 | | void setDimensions(float left, float top, float width, float height); |
169 | | |
170 | | /// @name Actual dimensions |
171 | | /// These methods return the actual dimensions of the viewport in pixels. |
172 | | /// @{ |
173 | 0 | int getActualLeft(void) const { return mActRect.left; } |
174 | 0 | int getActualTop(void) const { return mActRect.top; } |
175 | 0 | int getActualWidth(void) const { return mActRect.width(); } |
176 | 0 | int getActualHeight(void) const { return mActRect.height(); } |
177 | 0 | Rect getActualDimensions() const { return mActRect; } |
178 | | /// @} |
179 | | |
180 | | /** Sets the initial background colour of the viewport (before |
181 | | rendering). |
182 | | */ |
183 | 0 | void setBackgroundColour(const ColourValue& colour) { mBackColour = colour; } |
184 | | |
185 | | /** Gets the background colour. |
186 | | */ |
187 | 0 | const ColourValue& getBackgroundColour(void) const { return mBackColour; } |
188 | | |
189 | | /** Sets the initial depth buffer value of the viewport (before |
190 | | rendering). Default is 1 |
191 | | */ |
192 | 0 | void setDepthClear( float depth ) { mDepthClearValue = depth; } |
193 | | |
194 | | /** Gets the default depth buffer value to which the viewport is cleared. |
195 | | */ |
196 | 0 | float getDepthClear(void) const { return mDepthClearValue; } |
197 | | |
198 | | /** Determines whether to clear the viewport before rendering. |
199 | | |
200 | | You can use this method to set which buffers are cleared |
201 | | (if any) before rendering every frame. |
202 | | @param clear Whether or not to clear any buffers |
203 | | @param buffers One or more values from FrameBufferType denoting |
204 | | which buffers to clear, if clear is set to true. Note you should |
205 | | not clear the stencil buffer here unless you know what you're doing. |
206 | | */ |
207 | | void setClearEveryFrame(bool clear, unsigned int buffers = FBT_COLOUR | FBT_DEPTH); |
208 | | |
209 | | /** Determines if the viewport is cleared before every frame. |
210 | | */ |
211 | 0 | bool getClearEveryFrame(void) const { return mClearEveryFrame; } |
212 | | |
213 | | /** Gets which buffers are to be cleared each frame. */ |
214 | 0 | unsigned int getClearBuffers(void) const { return mClearBuffers; } |
215 | | |
216 | | /** Sets whether this viewport should be automatically updated |
217 | | if Ogre's rendering loop or RenderTarget::update is being used. |
218 | | |
219 | | By default, if you use Ogre's own rendering loop (Root::startRendering) |
220 | | or call RenderTarget::update, all viewports are updated automatically. |
221 | | This method allows you to control that behaviour, if for example you |
222 | | have a viewport which you only want to update periodically. |
223 | | @param autoupdate If true, the viewport is updated during the automatic |
224 | | render loop or when RenderTarget::update() is called. If false, the |
225 | | viewport is only updated when its update() method is called explicitly. |
226 | | */ |
227 | 0 | void setAutoUpdated(bool autoupdate) { mIsAutoUpdated = autoupdate; } |
228 | | /** Gets whether this viewport is automatically updated if |
229 | | Ogre's rendering loop or RenderTarget::update is being used. |
230 | | */ |
231 | 0 | bool isAutoUpdated() const { return mIsAutoUpdated; } |
232 | | |
233 | | /** Set the material scheme which the viewport should use. |
234 | | |
235 | | This allows you to tell the system to use a particular |
236 | | material scheme when rendering this viewport, which can |
237 | | involve using different techniques to render your materials. |
238 | | @see Technique::setSchemeName |
239 | | */ |
240 | | void setMaterialScheme(const String& schemeName) |
241 | 0 | { mMaterialSchemeName = schemeName; } |
242 | | |
243 | | /** Get the material scheme which the viewport should use. |
244 | | */ |
245 | | const String& getMaterialScheme(void) const |
246 | 0 | { return mMaterialSchemeName; } |
247 | | |
248 | | /// @deprecated |
249 | | OGRE_DEPRECATED void getActualDimensions(int& left, int& top, int& width, int& height) const; |
250 | | |
251 | | bool _isUpdated(void) const; |
252 | | void _clearUpdatedFlag(void); |
253 | | |
254 | | /** Gets the number of rendered faces in the last update. |
255 | | */ |
256 | | unsigned int _getNumRenderedFaces(void) const; |
257 | | |
258 | | /** Gets the number of rendered batches in the last update. |
259 | | */ |
260 | | unsigned int _getNumRenderedBatches(void) const; |
261 | | |
262 | | /** Tells this viewport whether it should display Overlay objects. |
263 | | |
264 | | Overlay objects are layers which appear on top of the scene. They are created via |
265 | | @ref OverlayManager::create and every viewport displays these by default. |
266 | | However, you probably don't want this if you're using multiple viewports, |
267 | | because one of them is probably a picture-in-picture which is not supposed to |
268 | | have overlays of it's own. In this case you can turn off overlays on this viewport |
269 | | by calling this method. |
270 | | @param enabled If true, any overlays are displayed, if false they are not. |
271 | | */ |
272 | 0 | void setOverlaysEnabled(bool enabled) { mShowOverlays = enabled; } |
273 | | |
274 | | /** Returns whether or not Overlay objects (created with the OverlayManager) are displayed in this |
275 | | viewport. */ |
276 | 0 | bool getOverlaysEnabled(void) const { return mShowOverlays; } |
277 | | |
278 | | /** Tells this viewport whether it should display skies. |
279 | | |
280 | | Skies are layers which appear on background of the scene. They are created via |
281 | | SceneManager::setSkyBox, SceneManager::setSkyPlane and SceneManager::setSkyDome and |
282 | | every viewport displays these by default. However, you probably don't want this if |
283 | | you're using multiple viewports, because one of them is probably a picture-in-picture |
284 | | which is not supposed to have skies of it's own. In this case you can turn off skies |
285 | | on this viewport by calling this method. |
286 | | @param enabled If true, any skies are displayed, if false they are not. |
287 | | */ |
288 | 0 | void setSkiesEnabled(bool enabled) { mShowSkies = enabled; } |
289 | | |
290 | | /** Returns whether or not skies (created in the SceneManager) are displayed in this |
291 | | viewport. */ |
292 | 0 | bool getSkiesEnabled(void) const { return mShowSkies; } |
293 | | |
294 | | /** Tells this viewport whether it should display shadows. |
295 | | |
296 | | This setting enables you to disable shadow rendering for a given viewport. The global |
297 | | shadow technique set on SceneManager still controls the type and nature of shadows, |
298 | | but this flag can override the setting so that no shadows are rendered for a given |
299 | | viewport to save processing time where they are not required. |
300 | | @param enabled If true, any shadows are displayed, if false they are not. |
301 | | */ |
302 | 0 | void setShadowsEnabled(bool enabled) { mShowShadows = enabled; } |
303 | | |
304 | | /** Returns whether or not shadows (defined in the SceneManager) are displayed in this |
305 | | viewport. */ |
306 | 0 | bool getShadowsEnabled(void) const { return mShowShadows; } |
307 | | |
308 | | |
309 | | /** Sets a per-viewport visibility mask. |
310 | | |
311 | | The visibility mask is a way to exclude objects from rendering for |
312 | | a given viewport. For each object in the frustum, a check is made |
313 | | between this mask and the objects visibility flags, and if a binary 'and' |
314 | | returns zero, the object will not be rendered. |
315 | | @see MovableObject::setVisibilityFlags |
316 | | */ |
317 | 0 | void setVisibilityMask(uint32 mask) { mVisibilityMask = mask; } |
318 | | |
319 | | /** Gets a per-viewport visibility mask. |
320 | | @see Viewport::setVisibilityMask |
321 | | */ |
322 | 0 | uint getVisibilityMask(void) const { return mVisibilityMask; } |
323 | | |
324 | | /// Add a listener to this viewport |
325 | | void addListener(Listener* l); |
326 | | /// Remove a listener to this viewport |
327 | | void removeListener(Listener* l); |
328 | | |
329 | | /** Sets the draw buffer type for the next frame. |
330 | | |
331 | | Specifies the particular buffer that will be |
332 | | targeted by the render target. Should be used if |
333 | | the render target supports quad buffer stereo. If |
334 | | the render target does not support stereo (ie. left |
335 | | and right), then only back and front will be used. |
336 | | @param |
337 | | colourBuffer Specifies the particular buffer that will be |
338 | | targeted by the render target. |
339 | | */ |
340 | 0 | void setDrawBuffer(ColourBufferType colourBuffer) { mColourBuffer = colourBuffer; } |
341 | | |
342 | | /** Returns the current colour buffer type for this viewport.*/ |
343 | 0 | ColourBufferType getDrawBuffer() const { return mColourBuffer; } |
344 | | |
345 | | private: |
346 | | Camera* mCamera; |
347 | | RenderTarget* mTarget; |
348 | | /// Relative dimensions, irrespective of target dimensions (0..1) |
349 | | FloatRect mRelRect; |
350 | | /// Actual dimensions, based on target dimensions |
351 | | Rect mActRect; |
352 | | /// Z-order |
353 | | int mZOrder; |
354 | | /// Background options |
355 | | ColourValue mBackColour; |
356 | | float mDepthClearValue; |
357 | | bool mClearEveryFrame; |
358 | | unsigned int mClearBuffers; |
359 | | bool mUpdated; |
360 | | bool mShowOverlays; |
361 | | bool mShowSkies; |
362 | | bool mShowShadows; |
363 | | uint32 mVisibilityMask; |
364 | | /// Material scheme |
365 | | String mMaterialSchemeName; |
366 | | |
367 | | /// Automatic rendering on/off |
368 | | bool mIsAutoUpdated; |
369 | | |
370 | | typedef std::vector<Listener*> ListenerList; |
371 | | ListenerList mListeners; |
372 | | ColourBufferType mColourBuffer; |
373 | | }; |
374 | | /** @} */ |
375 | | /** @} */ |
376 | | |
377 | | } |
378 | | |
379 | | #include "OgreHeaderSuffix.h" |
380 | | |
381 | | #endif |