Isolate irrlicht references and use a singleton (#6041)
[oweals/minetest.git] / src / client / renderingengine.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #pragma once
22
23 #include <vector>
24 #include <string>
25 #include "irrlichttypes_extrabloated.h"
26 #include "debug.h"
27
28 class ITextureSource;
29 class Camera;
30 class Client;
31 class LocalPlayer;
32 class Hud;
33 class Minimap;
34
35 class RenderingEngine
36 {
37 public:
38         RenderingEngine(IEventReceiver *eventReceiver);
39         ~RenderingEngine();
40
41         v2u32 getWindowSize() const;
42         void setResizable(bool resize);
43
44         video::IVideoDriver *getVideoDriver();
45
46         static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
47         static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
48         static float getDisplayDensity();
49         static v2u32 getDisplaySize();
50
51         static void setXorgClassHint(const video::SExposedVideoData &video_data,
52                         const std::string &name);
53         bool setWindowIcon();
54         bool setXorgWindowIconFromPath(const std::string &icon_file);
55         static bool print_video_modes();
56
57         static RenderingEngine *get_instance() { return s_singleton; }
58
59         static io::IFileSystem *get_filesystem()
60         {
61                 sanity_check(s_singleton && s_singleton->m_device);
62                 return s_singleton->m_device->getFileSystem();
63         }
64
65         static video::IVideoDriver *get_video_driver()
66         {
67                 sanity_check(s_singleton && s_singleton->m_device);
68                 return s_singleton->m_device->getVideoDriver();
69         }
70
71         static scene::IMeshCache *get_mesh_cache()
72         {
73                 sanity_check(s_singleton && s_singleton->m_device);
74                 return s_singleton->m_device->getSceneManager()->getMeshCache();
75         }
76
77         static scene::ISceneManager *get_scene_manager()
78         {
79                 sanity_check(s_singleton && s_singleton->m_device);
80                 return s_singleton->m_device->getSceneManager();
81         }
82
83         static irr::IrrlichtDevice *get_raw_device()
84         {
85                 sanity_check(s_singleton && s_singleton->m_device);
86                 return s_singleton->m_device;
87         }
88
89         static u32 get_timer_time()
90         {
91                 sanity_check(s_singleton && s_singleton->m_device &&
92                                 s_singleton->m_device->getTimer());
93                 return s_singleton->m_device->getTimer()->getTime();
94         }
95
96         static gui::IGUIEnvironment *get_gui_env()
97         {
98                 sanity_check(s_singleton && s_singleton->m_device);
99                 return s_singleton->m_device->getGUIEnvironment();
100         }
101
102         inline static void draw_load_screen(const std::wstring &text,
103                         gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
104                         float dtime = 0, int percent = 0, bool clouds = true)
105         {
106                 s_singleton->_draw_load_screen(
107                                 text, guienv, tsrc, dtime, percent, clouds);
108         }
109
110         inline static void draw_scene(Camera *camera, Client *client, LocalPlayer *player,
111                         Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
112                         const v2u32 &screensize, const video::SColor &skycolor,
113                         bool show_hud, bool show_minimap)
114         {
115                 s_singleton->_draw_scene(camera, client, player, hud, mapper, guienv,
116                                 screensize, skycolor, show_hud, show_minimap);
117         }
118
119         static bool run()
120         {
121                 sanity_check(s_singleton && s_singleton->m_device);
122                 return s_singleton->m_device->run();
123         }
124
125         static std::vector<core::vector3d<u32>> getSupportedVideoModes();
126         static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
127
128 private:
129         enum parallax_sign
130         {
131                 LEFT = -1,
132                 RIGHT = 1,
133                 EYECOUNT = 2
134         };
135
136         void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
137                         ITextureSource *tsrc, float dtime = 0, int percent = 0,
138                         bool clouds = true);
139
140         void _draw_scene(Camera *camera, Client *client, LocalPlayer *player, Hud *hud,
141                         Minimap *mapper, gui::IGUIEnvironment *guienv,
142                         const v2u32 &screensize, const video::SColor &skycolor,
143                         bool show_hud, bool show_minimap);
144
145         void draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
146                         bool draw_wield_tool, Client *client,
147                         gui::IGUIEnvironment *guienv);
148
149         void draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
150                         const v2u32 &screensize, bool draw_wield_tool, Client *client,
151                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
152
153         void draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
154                         const v2u32 &screensize, bool draw_wield_tool, Client *client,
155                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
156
157         void draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
158                         const v2u32 &screensize, bool draw_wield_tool, Client *client,
159                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
160
161         void draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
162                         const v2u32 &screensize, bool draw_wield_tool, Client *client,
163                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
164
165         void draw_plain(Camera *camera, bool show_hud, Hud *hud, const v2u32 &screensize,
166                         bool draw_wield_tool, Client *client,
167                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
168
169         void init_texture(const v2u32 &screensize, video::ITexture **texture,
170                         const char *name);
171
172         video::ITexture *draw_image(const v2u32 &screensize, parallax_sign psign,
173                         const irr::core::matrix4 &startMatrix,
174                         const irr::core::vector3df &focusPoint, bool show_hud,
175                         Camera *camera, Hud *hud, bool draw_wield_tool, Client *client,
176                         gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
177
178         video::ITexture *draw_hud(const v2u32 &screensize, bool show_hud, Hud *hud,
179                         Client *client, bool draw_crosshair,
180                         const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
181                         Camera *camera);
182
183         irr::IrrlichtDevice *m_device = nullptr;
184         static RenderingEngine *s_singleton;
185 };