]> git.lizzy.rs Git - irrlicht.git/blob - include/IrrlichtDevice.h
Add a unified cross platform OpenGL core profile binding (#52)
[irrlicht.git] / include / IrrlichtDevice.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __I_IRRLICHT_DEVICE_H_INCLUDED__\r
6 #define __I_IRRLICHT_DEVICE_H_INCLUDED__\r
7 \r
8 #include "IReferenceCounted.h"\r
9 #include "dimension2d.h"\r
10 #include "IVideoDriver.h"\r
11 #include "EDriverTypes.h"\r
12 #include "EDeviceTypes.h"\r
13 #include "IEventReceiver.h"\r
14 #include "ICursorControl.h"\r
15 #include "IVideoModeList.h"\r
16 #include "ITimer.h"\r
17 #include "IOSOperator.h"\r
18 \r
19 namespace irr\r
20 {\r
21         class ILogger;\r
22         class IEventReceiver;\r
23         class IRandomizer;\r
24 \r
25         namespace io {\r
26                 class IFileSystem;\r
27         } // end namespace io\r
28 \r
29         namespace gui {\r
30                 class IGUIEnvironment;\r
31         } // end namespace gui\r
32 \r
33         namespace scene {\r
34                 class ISceneManager;\r
35         } // end namespace scene\r
36 \r
37         namespace video {\r
38                 class IContextManager;\r
39         } // end namespace video\r
40 \r
41         //! The Irrlicht device. You can create it with createDevice() or createDeviceEx().\r
42         /** This is the most important class of the Irrlicht Engine. You can\r
43         access everything in the engine if you have a pointer to an instance of\r
44         this class.  There should be only one instance of this class at any\r
45         time.\r
46         */\r
47         class IrrlichtDevice : public virtual IReferenceCounted\r
48         {\r
49         public:\r
50 \r
51                 //! Runs the device.\r
52                 /** Also increments the virtual timer by calling\r
53                 ITimer::tick();. You can prevent this\r
54                 by calling ITimer::stop(); before and ITimer::start() after\r
55                 calling IrrlichtDevice::run(). Returns false if device wants\r
56                 to be deleted. Use it in this way:\r
57                 \code\r
58                 while(device->run())\r
59                 {\r
60                         // draw everything here\r
61                 }\r
62                 \endcode\r
63                 If you want the device to do nothing if the window is inactive\r
64                 (recommended), use the slightly enhanced code shown at isWindowActive().\r
65 \r
66                 Note if you are running Irrlicht inside an external, custom\r
67                 created window: Calling Device->run() will cause Irrlicht to\r
68                 dispatch windows messages internally.\r
69                 If you are running Irrlicht in your own custom window, you can\r
70                 also simply use your own message loop using GetMessage,\r
71                 DispatchMessage and whatever and simply don't use this method.\r
72                 But note that Irrlicht will not be able to fetch user input\r
73                 then. See irr::SIrrlichtCreationParameters::WindowId for more\r
74                 information and example code.\r
75                 */\r
76                 virtual bool run() = 0;\r
77 \r
78                 //! Cause the device to temporarily pause execution and let other processes run.\r
79                 /** This should bring down processor usage without major\r
80                 performance loss for Irrlicht */\r
81                 virtual void yield() = 0;\r
82 \r
83                 //! Pause execution and let other processes to run for a specified amount of time.\r
84                 /** It may not wait the full given time, as sleep may be interrupted\r
85                 \param timeMs: Time to sleep for in milliseconds.\r
86                 \param pauseTimer: If true, pauses the device timer while sleeping\r
87                 */\r
88                 virtual void sleep(u32 timeMs, bool pauseTimer=false) = 0;\r
89 \r
90                 //! Provides access to the video driver for drawing 3d and 2d geometry.\r
91                 /** \return Pointer the video driver. */\r
92                 virtual video::IVideoDriver* getVideoDriver() = 0;\r
93 \r
94                 //! Provides access to the virtual file system.\r
95                 /** \return Pointer to the file system. */\r
96                 virtual io::IFileSystem* getFileSystem() = 0;\r
97 \r
98                 //! Provides access to the 2d user interface environment.\r
99                 /** \return Pointer to the gui environment. */\r
100                 virtual gui::IGUIEnvironment* getGUIEnvironment() = 0;\r
101 \r
102                 //! Provides access to the scene manager.\r
103                 /** \return Pointer to the scene manager. */\r
104                 virtual scene::ISceneManager* getSceneManager() = 0;\r
105 \r
106                 //! Provides access to the cursor control.\r
107                 /** \return Pointer to the mouse cursor control interface. */\r
108                 virtual gui::ICursorControl* getCursorControl() = 0;\r
109 \r
110                 //! Provides access to the message logger.\r
111                 /** \return Pointer to the logger. */\r
112                 virtual ILogger* getLogger() = 0;\r
113 \r
114                 //! Gets a list with all video modes available.\r
115                 /** You only need a null driver (ED_NULL) to access\r
116                 those video modes. So you can get the available modes\r
117                 before starting any other video driver.\r
118                 \return Pointer to a list with all video modes supported\r
119                 by the gfx adapter. */\r
120                 virtual video::IVideoModeList* getVideoModeList() = 0;\r
121 \r
122                 //! Get context manager\r
123                 virtual video::IContextManager* getContextManager() = 0;\r
124 \r
125                 //! Provides access to the operation system operator object.\r
126                 /** The OS operator provides methods for\r
127                 getting system specific information and doing system\r
128                 specific operations, such as exchanging data with the clipboard\r
129                 or reading the operation system version.\r
130                 \return Pointer to the OS operator. */\r
131                 virtual IOSOperator* getOSOperator() = 0;\r
132 \r
133                 //! Provides access to the engine's timer.\r
134                 /** The system time can be retrieved by it as\r
135                 well as the virtual time, which also can be manipulated.\r
136                 \return Pointer to the ITimer object. */\r
137                 virtual ITimer* getTimer() = 0;\r
138 \r
139                 //! Provides access to the engine's currently set randomizer.\r
140                 /** \return Pointer to the IRandomizer object. */\r
141                 virtual IRandomizer* getRandomizer() const =0;\r
142 \r
143                 //! Sets a new randomizer.\r
144                 /** \param r Pointer to the new IRandomizer object. This object is\r
145                 grab()'ed by the engine and will be released upon the next setRandomizer\r
146                 call or upon device destruction. */\r
147                 virtual void setRandomizer(IRandomizer* r) =0;\r
148 \r
149                 //! Creates a new default randomizer.\r
150                 /** The default randomizer provides the random sequence known from previous\r
151                 Irrlicht versions and is the initial randomizer set on device creation.\r
152                 \return Pointer to the default IRandomizer object. */\r
153                 virtual IRandomizer* createDefaultRandomizer() const =0;\r
154 \r
155                 //! Sets the caption of the window.\r
156                 /** \param text: New text of the window caption. */\r
157                 virtual void setWindowCaption(const wchar_t* text) = 0;\r
158 \r
159                 //! Returns if the window is active.\r
160                 /** If the window is inactive,\r
161                 nothing needs to be drawn. So if you don't want to draw anything\r
162                 when the window is inactive, create your drawing loop this way:\r
163                 \code\r
164                 while(device->run())\r
165                 {\r
166                         if (device->isWindowActive())\r
167                         {\r
168                                 // draw everything here\r
169                         }\r
170                         else\r
171                                 device->yield();\r
172                 }\r
173                 \endcode\r
174                 \return True if window is active. */\r
175                 virtual bool isWindowActive() const = 0;\r
176 \r
177                 //! Checks if the Irrlicht window has the input focus\r
178                 /** \return True if window has focus. */\r
179                 virtual bool isWindowFocused() const = 0;\r
180 \r
181                 //! Checks if the Irrlicht window is minimized\r
182                 /** \return True if window is minimized. */\r
183                 virtual bool isWindowMinimized() const = 0;\r
184 \r
185                 //! Checks if the Irrlicht window is running in fullscreen mode\r
186                 /** \return True if window is fullscreen. */\r
187                 virtual bool isFullscreen() const = 0;\r
188 \r
189                 //! Get the current color format of the window\r
190                 /** \return Color format of the window. */\r
191                 virtual video::ECOLOR_FORMAT getColorFormat() const = 0;\r
192 \r
193                 //! Notifies the device that it should close itself.\r
194                 /** IrrlichtDevice::run() will always return false after closeDevice() was called. */\r
195                 virtual void closeDevice() = 0;\r
196 \r
197                 //! Get the version of the engine.\r
198                 /** The returned string\r
199                 will look like this: "1.2.3" or this: "1.2".\r
200                 \return String which contains the version. */\r
201                 virtual const c8* getVersion() const = 0;\r
202 \r
203                 //! Sets a new user event receiver which will receive events from the engine.\r
204                 /** Return true in IEventReceiver::OnEvent to prevent the event from continuing along\r
205                 the chain of event receivers. The path that an event takes through the system depends\r
206                 on its type. See irr::EEVENT_TYPE for details.\r
207                 \param receiver New receiver to be used. */\r
208                 virtual void setEventReceiver(IEventReceiver* receiver) = 0;\r
209 \r
210                 //! Provides access to the current event receiver.\r
211                 /** \return Pointer to the current event receiver. Returns 0 if there is none. */\r
212                 virtual IEventReceiver* getEventReceiver() = 0;\r
213 \r
214                 //! Sends a user created event to the engine.\r
215                 /** Is is usually not necessary to use this. However, if you\r
216                 are using an own input library for example for doing joystick\r
217                 input, you can use this to post key or mouse input events to\r
218                 the engine. Internally, this method only delegates the events\r
219                 further to the scene manager and the GUI environment. */\r
220                 virtual bool postEventFromUser(const SEvent& event) = 0;\r
221 \r
222                 //! Sets the input receiving scene manager.\r
223                 /** If set to null, the main scene manager (returned by\r
224                 GetSceneManager()) will receive the input\r
225                 \param sceneManager New scene manager to be used. */\r
226                 virtual void setInputReceivingSceneManager(scene::ISceneManager* sceneManager) = 0;\r
227 \r
228                 //! Sets if the window should be resizable in windowed mode.\r
229                 /** The default is false. This method only works in windowed\r
230                 mode.\r
231                 \param resize Flag whether the window should be resizable. */\r
232                 virtual void setResizable(bool resize=false) = 0;\r
233 \r
234                 //! Resize the render window.\r
235                 /**     This will only work in windowed mode and is not yet supported on all systems.\r
236                 It does set the drawing/clientDC size of the window, the window decorations are added to that.\r
237                 You get the current window size with IVideoDriver::getScreenSize() (might be unified in future)\r
238                 */\r
239                 virtual void setWindowSize(const irr::core::dimension2d<u32>& size) = 0;\r
240 \r
241                 //! Minimizes the window if possible.\r
242                 virtual void minimizeWindow() =0;\r
243 \r
244                 //! Maximizes the window if possible.\r
245                 virtual void maximizeWindow() =0;\r
246 \r
247                 //! Restore the window to normal size if possible.\r
248                 virtual void restoreWindow() =0;\r
249 \r
250                 //! Get the position of the frame on-screen\r
251                 virtual core::position2di getWindowPosition() = 0;\r
252 \r
253                 //! Activate any joysticks, and generate events for them.\r
254                 /** Irrlicht contains support for joysticks, but does not generate joystick events by default,\r
255                 as this would consume joystick info that 3rd party libraries might rely on. Call this method to\r
256                 activate joystick support in Irrlicht and to receive irr::SJoystickEvent events.\r
257                 \param joystickInfo On return, this will contain an array of each joystick that was found and activated.\r
258                 \return true if joysticks are supported on this device and _IRR_COMPILE_WITH_JOYSTICK_EVENTS_\r
259                                 is defined, false if joysticks are not supported or support is compiled out.\r
260                 */\r
261                 virtual bool activateJoysticks(core::array<SJoystickInfo>& joystickInfo) =0;\r
262 \r
263         //! Activate accelerometer.\r
264         virtual bool activateAccelerometer(float updateInterval = 0.016666f) = 0;\r
265 \r
266         //! Deactivate accelerometer.\r
267         virtual bool deactivateAccelerometer() = 0;\r
268 \r
269         //! Is accelerometer active.\r
270         virtual bool isAccelerometerActive() = 0;\r
271 \r
272         //! Is accelerometer available.\r
273         virtual bool isAccelerometerAvailable() = 0;\r
274 \r
275         //! Activate gyroscope.\r
276         virtual bool activateGyroscope(float updateInterval = 0.016666f) = 0;\r
277 \r
278         //! Deactivate gyroscope.\r
279         virtual bool deactivateGyroscope() = 0;\r
280 \r
281         //! Is gyroscope active.\r
282         virtual bool isGyroscopeActive() = 0;\r
283 \r
284         //! Is gyroscope available.\r
285         virtual bool isGyroscopeAvailable() = 0;\r
286 \r
287         //! Activate device motion.\r
288         virtual bool activateDeviceMotion(float updateInterval = 0.016666f) = 0;\r
289 \r
290         //! Deactivate device motion.\r
291         virtual bool deactivateDeviceMotion() = 0;\r
292 \r
293         //! Is device motion active.\r
294         virtual bool isDeviceMotionActive() = 0;\r
295 \r
296         //! Is device motion available.\r
297         virtual bool isDeviceMotionAvailable() = 0;\r
298 \r
299                 //! Set the current Gamma Value for the Display\r
300                 virtual bool setGammaRamp(f32 red, f32 green, f32 blue,\r
301                                         f32 relativebrightness, f32 relativecontrast) =0;\r
302 \r
303                 //! Get the current Gamma Value for the Display\r
304                 virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue,\r
305                                         f32 &brightness, f32 &contrast) =0;\r
306 \r
307                 //! Set the maximal elapsed time between 2 clicks to generate doubleclicks for the mouse. It also affects tripleclick behavior.\r
308                 /** When set to 0 no double- and tripleclicks will be generated.\r
309                 \param timeMs maximal time in milliseconds for two consecutive clicks to be recognized as double click\r
310                 */\r
311                 virtual void setDoubleClickTime(u32 timeMs) =0;\r
312 \r
313                 //! Get the maximal elapsed time between 2 clicks to generate double- and tripleclicks for the mouse.\r
314                 /** When return value is 0 no double- and tripleclicks will be generated.\r
315                 \return maximal time in milliseconds for two consecutive clicks to be recognized as double click\r
316                 */\r
317                 virtual u32 getDoubleClickTime() const =0;\r
318 \r
319                 //! Remove messages pending in the system message loop\r
320                 /** This function is usually used after messages have been buffered for a longer time, for example\r
321                 when loading a large scene. Clearing the message loop prevents that mouse- or buttonclicks which users\r
322                 have pressed in the meantime will now trigger unexpected actions in the gui. <br>\r
323                 So far the following messages are cleared:<br>\r
324                 Win32: All keyboard and mouse messages<br>\r
325                 Linux: All keyboard and mouse messages<br>\r
326                 All other devices are not yet supported here.<br>\r
327                 The function is still somewhat experimental, as the kind of messages we clear is based on just a few use-cases.\r
328                 If you think further messages should be cleared, or some messages should not be cleared here, then please tell us. */\r
329                 virtual void clearSystemMessages() = 0;\r
330 \r
331                 //! Get the type of the device.\r
332                 /** This allows the user to check which windowing system is currently being\r
333                 used. */\r
334                 virtual E_DEVICE_TYPE getType() const = 0;\r
335 \r
336                 //! Check if a driver type is supported by the engine.\r
337                 /** Even if true is returned the driver may not be available\r
338                 for a configuration requested when creating the device. */\r
339                 static bool isDriverSupported(video::E_DRIVER_TYPE driver)\r
340                 {\r
341                         switch (driver)\r
342                         {\r
343                                 case video::EDT_NULL:\r
344                                         return true;\r
345                                 case video::EDT_SOFTWARE:\r
346 #ifdef _IRR_COMPILE_WITH_SOFTWARE_\r
347                                         return true;\r
348 #else\r
349                                         return false;\r
350 #endif\r
351                                 case video::EDT_BURNINGSVIDEO:\r
352 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
353                                         return true;\r
354 #else\r
355                                         return false;\r
356 #endif\r
357                                 case video::EDT_DIRECT3D9:\r
358 #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_\r
359                                         return true;\r
360 #else\r
361                                         return false;\r
362 #endif\r
363                                 case video::EDT_OPENGL:\r
364 #ifdef _IRR_COMPILE_WITH_OPENGL_\r
365                                         return true;\r
366 #else\r
367                                         return false;\r
368 #endif\r
369                                 case video::EDT_OGLES1:\r
370 #ifdef _IRR_COMPILE_WITH_OGLES1_\r
371                                         return true;\r
372 #else\r
373                                         return false;\r
374 #endif\r
375                                 case video::EDT_OGLES2:\r
376 #ifdef _IRR_COMPILE_WITH_OGLES2_\r
377                                         return true;\r
378 #else\r
379                                         return false;\r
380 #endif\r
381                                 case video::EDT_WEBGL1:\r
382 #ifdef _IRR_COMPILE_WITH_WEBGL1_\r
383                                         return true;\r
384 #else\r
385                                         return false;\r
386 #endif\r
387                                 default:\r
388                                         return false;\r
389                         }\r
390                 }\r
391         };\r
392 \r
393 } // end namespace irr\r
394 \r
395 #endif\r
396 \r