/src/ogre/OgreMain/include/OgreRenderWindow.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*------------------------------------------------------------------------- |
2 | | This source file is a part of OGRE |
3 | | (Object-oriented Graphics Rendering Engine) |
4 | | |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
9 | | of this software and associated documentation files (the "Software"), to deal |
10 | | in the Software without restriction, including without limitation the rights |
11 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 | | copies of the Software, and to permit persons to whom the Software is |
13 | | furnished to do so, subject to the following conditions: |
14 | | |
15 | | The above copyright notice and this permission notice shall be included in |
16 | | all copies or substantial portions of the Software. |
17 | | |
18 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 | | THE SOFTWARE |
25 | | -------------------------------------------------------------------------*/ |
26 | | #ifndef __RenderWindow_H__ |
27 | | #define __RenderWindow_H__ |
28 | | |
29 | | #include "OgrePrerequisites.h" |
30 | | |
31 | | #include "OgreRenderTarget.h" |
32 | | |
33 | | namespace Ogre |
34 | | { |
35 | | /** \addtogroup Core |
36 | | * @{ |
37 | | */ |
38 | | /** \addtogroup RenderSystem |
39 | | * @{ |
40 | | */ |
41 | | /** Manages the target rendering window. |
42 | | |
43 | | This class handles a window into which the contents |
44 | | of a scene are rendered. There is a many-to-1 relationship |
45 | | between instances of this class an instance of RenderSystem |
46 | | which controls the rendering of the scene. There may be |
47 | | more than one window in the case of level editor tools etc. |
48 | | This class is abstract since there may be |
49 | | different implementations for different windowing systems. |
50 | | |
51 | | Instances are created and communicated with by the render system |
52 | | although client programs can get a reference to it from |
53 | | the render system if required for resizing or moving. |
54 | | Note that you can have multiple viewpoints |
55 | | in the window for effects like rear-view mirrors and |
56 | | picture-in-picture views (see Viewport and Camera). |
57 | | @author |
58 | | Steven Streeting |
59 | | */ |
60 | | class _OgreExport RenderWindow : public RenderTarget |
61 | | { |
62 | | |
63 | | public: |
64 | | /** Default constructor. |
65 | | */ |
66 | | RenderWindow(); |
67 | | |
68 | | /** Many windowing systems that support HiDPI displays use special points to specify |
69 | | size of the windows and controls, so that windows and controls with hardcoded |
70 | | sizes does not become too small on HiDPI displays. Such points have constant density |
71 | | ~ 100 points per inch (probably 96 on Windows and 72 on Mac), that is independent |
72 | | of pixel density of real display, and are used through the all windowing system. |
73 | | |
74 | | Sometimes, such view points are chosen bigger for output devices that are viewed |
75 | | from larger distances, like 30" TV comparing to 30" monitor, therefore maintaining |
76 | | constant points angular density rather than constant linear density. |
77 | | |
78 | | In any case, all such windowing system provides the way to convert such view points |
79 | | to pixels, be it DisplayProperties::LogicalDpi on WinRT or backingScaleFactor on MacOSX. |
80 | | We use pixels consistently through the Ogre, but window/view management functions |
81 | | takes view points for convenience, as does the rest of windowing system. Such parameters |
82 | | are named using xxxxPt pattern, and should not be mixed with pixels without being |
83 | | converted using getViewPointToPixelScale() function. |
84 | | |
85 | | Sometimes such scale factor can change on-the-fly, for example if window is dragged |
86 | | to monitor with different DPI. In such situation, window size in view points is usually |
87 | | preserved by windowing system, and Ogre should adjust pixel size of RenderWindow. |
88 | | */ |
89 | 0 | virtual float getViewPointToPixelScale() { return 1.0f; } |
90 | | |
91 | | /** Creates & displays the new window. |
92 | | @param name the internal window name. Not necessarily the title. |
93 | | @param |
94 | | widthPt The width of the window in view points. |
95 | | @param |
96 | | heightPt The height of the window in view points. |
97 | | @param |
98 | | fullScreen If true, the window fills the screen, |
99 | | with no title bar or border. |
100 | | @param |
101 | | miscParams A variable number of pointers to platform-specific arguments. The |
102 | | actual requirements must be defined by the implementing subclasses. |
103 | | */ |
104 | | virtual void create(const String& name, unsigned int widthPt, unsigned int heightPt, |
105 | | bool fullScreen, const NameValuePairList *miscParams) = 0; |
106 | | |
107 | | /** Alter fullscreen mode options. |
108 | | Nothing will happen unless the settings here are different from the |
109 | | current settings. |
110 | | @note Only implemented by few RenderSystems. Prefer native windowing API. |
111 | | @param fullScreen Whether to use fullscreen mode or not. |
112 | | @param widthPt The new width to use |
113 | | @param heightPt The new height to use |
114 | | */ |
115 | | virtual void setFullscreen(bool fullScreen, unsigned int widthPt, unsigned int heightPt) |
116 | 0 | { (void)fullScreen; (void)widthPt; (void)heightPt; } |
117 | | |
118 | | /** Destroys the window. |
119 | | */ |
120 | | virtual void destroy(void) = 0; |
121 | | |
122 | | /** Alter the size of the window. |
123 | | */ |
124 | | virtual void resize(unsigned int widthPt, unsigned int heightPt); |
125 | | |
126 | | /** Query the current size and position from an external window handle. |
127 | | @note most of the time you already know the size and should call @ref resize instead. |
128 | | */ |
129 | 0 | virtual void windowMovedOrResized() {} |
130 | | |
131 | | /** Reposition the window. |
132 | | |
133 | | @note Only implemented by few RenderSystems. Prefer native windowing API. |
134 | | */ |
135 | 0 | virtual void reposition(int leftPt, int topPt) {} |
136 | | |
137 | | /** Indicates whether the window is visible (not minimized or obscured) |
138 | | */ |
139 | 0 | virtual bool isVisible(void) const { return true; } |
140 | | |
141 | | /** Set the visibility state |
142 | | */ |
143 | | virtual void setVisible(bool visible) |
144 | 0 | { (void)visible; } |
145 | | |
146 | | /** Indicates whether the window was set to hidden (not displayed) |
147 | | */ |
148 | 0 | virtual bool isHidden(void) const { return false; } |
149 | | |
150 | | /** Hide (or show) the window. If called with hidden=true, this |
151 | | will make the window completely invisible to the user. |
152 | | |
153 | | Setting a window to hidden is useful to create a dummy primary |
154 | | RenderWindow hidden from the user so that you can create and |
155 | | recreate your actual RenderWindows without having to recreate |
156 | | all your resources. |
157 | | */ |
158 | | virtual void setHidden(bool hidden) |
159 | 0 | { (void)hidden; } |
160 | | |
161 | | /** Enable or disable vertical sync for the RenderWindow. |
162 | | */ |
163 | | virtual void setVSyncEnabled(bool vsync) |
164 | 0 | { (void)vsync; } |
165 | | |
166 | | /** Indicates whether vertical sync is activated for the window. |
167 | | */ |
168 | 0 | virtual bool isVSyncEnabled() const { return false; } |
169 | | |
170 | | /** Set the vertical sync interval. This indicates the number of vertical retraces to wait for |
171 | | before swapping buffers. A value of 1 is the default. |
172 | | */ |
173 | | virtual void setVSyncInterval(unsigned int interval) |
174 | 0 | { (void)interval; } |
175 | | |
176 | | /** Returns the vertical sync interval. |
177 | | */ |
178 | 0 | unsigned int getVSyncInterval() const { return mVSyncInterval; } |
179 | | |
180 | | |
181 | | /** Overridden from RenderTarget, flags invisible windows as inactive |
182 | | */ |
183 | 0 | bool isActive(void) const override { return mActive && isVisible(); } |
184 | | |
185 | | /** Indicates whether the window has been closed by the user. |
186 | | */ |
187 | 0 | virtual bool isClosed(void) const { return mClosed; } |
188 | | |
189 | | /** Indicates whether the window is the primary window. The |
190 | | primary window is special in that it is destroyed when |
191 | | ogre is shut down, and cannot be destroyed directly. |
192 | | This is the case because it holds the context for vertex, |
193 | | index buffers and textures. |
194 | | */ |
195 | | bool isPrimary(void) const override; |
196 | | |
197 | | /** Returns true if window is running in fullscreen mode. |
198 | | */ |
199 | | virtual bool isFullScreen(void) const; |
200 | | |
201 | | /** Overloaded version of getMetrics from RenderTarget, including extra details |
202 | | specific to windowing systems. Result is in pixels. |
203 | | */ |
204 | | void getMetrics(unsigned int& width, unsigned int& height, int& left, int& top) const; |
205 | | |
206 | | /// Override since windows don't usually have alpha |
207 | 0 | PixelFormat suggestPixelFormat() const override { return PF_BYTE_RGB; } |
208 | | |
209 | | /** Returns true if the window will automatically de-activate itself when it loses focus. |
210 | | */ |
211 | | bool isDeactivatedOnFocusChange() const; |
212 | | |
213 | | /** Indicates whether the window will automatically deactivate itself when it loses focus. |
214 | | * @param deactivate a value of 'true' will cause the window to deactivate itself when it loses focus. 'false' will allow it to continue to render even when window focus is lost. |
215 | | * @note 'true' is the default behavior. |
216 | | */ |
217 | | void setDeactivateOnFocusChange(bool deactivate); |
218 | | |
219 | | #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN |
220 | | virtual void _notifySurfaceDestroyed() = 0; |
221 | | virtual void _notifySurfaceCreated(void* nativeWindow, void* config = NULL) = 0; |
222 | | #endif |
223 | | |
224 | | protected: |
225 | | bool mIsFullScreen; |
226 | | bool mIsPrimary; |
227 | | bool mAutoDeactivatedOnFocusChange; |
228 | | bool mClosed; |
229 | | int mLeft; |
230 | | int mTop; |
231 | | unsigned int mVSyncInterval; |
232 | | |
233 | | /** Indicates that this is the primary window. Only to be called by |
234 | | Ogre::Root |
235 | | */ |
236 | 0 | void _setPrimary() { mIsPrimary = true; } |
237 | | |
238 | | friend class Root; |
239 | | }; |
240 | | /** @} */ |
241 | | /** @} */ |
242 | | |
243 | | } // Namespace |
244 | | #endif |