aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-06-26 20:11:17 +0200
committerGitHub <noreply@github.com>2017-06-26 20:11:17 +0200
commitb3a36f7378ea0f299cfa36c81de42e00adb7292d (patch)
tree23d056b575ff0dba8cc759cc00f732099a1f3bce /src/client
parenta8650e785df3f12efa5f8cd3c6a695fb9e22a598 (diff)
downloadhax-minetest-server-b3a36f7378ea0f299cfa36c81de42e00adb7292d.tar.gz
hax-minetest-server-b3a36f7378ea0f299cfa36c81de42e00adb7292d.zip
Isolate irrlicht references and use a singleton (#6041)
* Add Device3D class which will contain IrrlichtDevice interface move getSupportedVideoDrivers to Device3D Add Device3D singleton & use it in various places Rename Device3D to Rendering engine & add helper functions to various device pointers More singleton work RenderingEngine owns draw_load_screen move draw functions to RenderingEngine Reduce IrrlichtDevice exposure and guienvironment RenderingEngine: Expose get_timer_time() to remove device from guiEngine Make irrlichtdevice & scene manager less exposed * Code style fixes * Move porting::getVideoDriverName, getVideoDriverFriendlyName, getDisplayDensity, getDisplaySize to RenderingEngine Fix XORG_USED macro -> RenderingEngine + create_engine_device from RenderingEngine constructor directly * enum paralax => enum parallax
Diffstat (limited to 'src/client')
-rw-r--r--src/client/CMakeLists.txt1
-rw-r--r--src/client/clientlauncher.cpp194
-rw-r--r--src/client/clientlauncher.h5
-rw-r--r--src/client/inputhandler.h17
-rw-r--r--src/client/renderingengine.cpp1072
-rw-r--r--src/client/renderingengine.h185
-rw-r--r--src/client/tile.cpp65
-rw-r--r--src/client/tile.h6
8 files changed, 1334 insertions, 211 deletions
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index 2d274ae68..4ba8fea5b 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -1,4 +1,5 @@
set(client_SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 9856c1920..4fc8fb3ee 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -18,7 +18,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "mainmenumanager.h"
-#include "debug.h"
#include "clouds.h"
#include "server.h"
#include "filesys.h"
@@ -27,14 +26,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "chat.h"
#include "gettext.h"
#include "profiler.h"
-#include "log.h"
#include "serverlist.h"
#include "guiEngine.h"
-#include "player.h"
#include "fontengine.h"
-#include "joystick_controller.h"
#include "clientlauncher.h"
#include "version.h"
+#include "renderingengine.h"
/* mainmenumanager.h
*/
@@ -58,9 +55,9 @@ ClientLauncher::~ClientLauncher()
delete input;
delete g_fontengine;
+ delete g_gamecallback;
- if (device)
- device->drop();
+ delete RenderingEngine::get_instance();
}
@@ -70,7 +67,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
// List video modes if requested
if (list_video_modes)
- return print_video_modes();
+ return RenderingEngine::print_video_modes();
if (!init_engine()) {
errorstream << "Could not initialize game engine." << std::endl;
@@ -84,15 +81,14 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
return true;
}
- video::IVideoDriver *video_driver = device->getVideoDriver();
+ video::IVideoDriver *video_driver = RenderingEngine::get_video_driver();
if (video_driver == NULL) {
errorstream << "Could not initialize video driver." << std::endl;
return false;
}
- porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
-
- porting::setWindowIcon(device);
+ RenderingEngine::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
+ RenderingEngine::get_instance()->setWindowIcon();
/*
This changes the minimum allowed number of vertices in a VBO.
@@ -101,17 +97,17 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
//driver->setMinHardwareBufferVertexCount(50);
// Create game callback for menus
- g_gamecallback = new MainGameCallback(device);
+ g_gamecallback = new MainGameCallback();
- device->setResizable(true);
+ RenderingEngine::get_instance()->setResizable(true);
init_input();
- smgr = device->getSceneManager();
- smgr->getParameters()->setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
+ RenderingEngine::get_scene_manager()->getParameters()->
+ setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);
- guienv = device->getGUIEnvironment();
- skin = guienv->getSkin();
+ guienv = RenderingEngine::get_gui_env();
+ skin = RenderingEngine::get_gui_env()->getSkin();
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30));
@@ -130,10 +126,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
// Create the menu clouds
if (!g_menucloudsmgr)
- g_menucloudsmgr = smgr->createNewSceneManager();
+ g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager();
if (!g_menuclouds)
- g_menuclouds = new Clouds(g_menucloudsmgr->getRootSceneNode(),
- g_menucloudsmgr, -1, rand(), 100);
+ g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand(), 100);
g_menuclouds->update(v2f(0, 0), video::SColor(255, 200, 200, 255));
scene::ICameraSceneNode* camera;
camera = g_menucloudsmgr->addCameraSceneNode(0,
@@ -159,25 +154,27 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
bool retval = true;
bool *kill = porting::signal_handler_killstatus();
- while (device->run() && !*kill && !g_gamecallback->shutdown_requested)
- {
+ while (RenderingEngine::run() && !*kill &&
+ !g_gamecallback->shutdown_requested) {
// Set the window caption
const wchar_t *text = wgettext("Main Menu");
- device->setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
+ RenderingEngine::get_raw_device()->
+ setWindowCaption((utf8_to_wide(PROJECT_NAME_C) +
L" " + utf8_to_wide(g_version_hash) +
L" [" + text + L"]").c_str());
delete[] text;
try { // This is used for catching disconnects
- guienv->clear();
+ RenderingEngine::get_gui_env()->clear();
/*
We need some kind of a root node to be able to add
custom gui elements directly on the screen.
Otherwise they won't be automatically drawn.
*/
- guiroot = guienv->addStaticText(L"", core::rect<s32>(0, 0, 10000, 10000));
+ guiroot = RenderingEngine::get_gui_env()->addStaticText(L"",
+ core::rect<s32>(0, 0, 10000, 10000));
bool game_has_run = launch_game(error_message, reconnect_requested,
game_params, cmd_args);
@@ -199,7 +196,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
}
// Break out of menu-game loop to shut down cleanly
- if (!device->run() || *kill) {
+ if (!RenderingEngine::get_raw_device()->run() || *kill) {
if (g_settings_path != "")
g_settings->updateConfigFile(g_settings_path.c_str());
break;
@@ -212,7 +209,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
continue;
}
- device->getVideoDriver()->setTextureCreationFlag(
+ RenderingEngine::get_video_driver()->setTextureCreationFlag(
video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map"));
#ifdef HAVE_TOUCHSCREENGUI
@@ -224,7 +221,6 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
kill,
random_input,
input,
- device,
worldspec.path,
current_playername,
current_password,
@@ -236,7 +232,7 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
gamespec,
simple_singleplayer_mode
);
- smgr->clear();
+ RenderingEngine::get_scene_manager()->clear();
#ifdef HAVE_TOUCHSCREENGUI
delete g_touchscreengui;
@@ -308,8 +304,8 @@ void ClientLauncher::init_args(GameParams &game_params, const Settings &cmd_args
bool ClientLauncher::init_engine()
{
receiver = new MyEventReceiver();
- create_engine_device();
- return device != NULL;
+ new RenderingEngine(receiver);
+ return RenderingEngine::get_raw_device() != nullptr;
}
void ClientLauncher::init_input()
@@ -317,7 +313,7 @@ void ClientLauncher::init_input()
if (random_input)
input = new RandomInputHandler();
else
- input = new RealInputHandler(device, receiver);
+ input = new RealInputHandler(receiver);
if (g_settings->getBool("enable_joysticks")) {
irr::core::array<irr::SJoystickInfo> infos;
@@ -326,7 +322,7 @@ void ClientLauncher::init_input()
// Make sure this is called maximum once per
// irrlicht device, otherwise it will give you
// multiple events for the same joystick.
- if (device->activateJoysticks(infos)) {
+ if (RenderingEngine::get_raw_device()->activateJoysticks(infos)) {
infostream << "Joystick support enabled" << std::endl;
joystick_infos.reserve(infos.size());
for (u32 i = 0; i < infos.size(); i++) {
@@ -487,14 +483,14 @@ bool ClientLauncher::launch_game(std::string &error_message,
void ClientLauncher::main_menu(MainMenuData *menudata)
{
bool *kill = porting::signal_handler_killstatus();
- video::IVideoDriver *driver = device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
infostream << "Waiting for other menus" << std::endl;
- while (device->run() && *kill == false) {
+ while (RenderingEngine::get_raw_device()->run() && *kill == false) {
if (!isMenuActive())
break;
driver->beginScene(true, true, video::SColor(255, 128, 128, 128));
- guienv->drawAll();
+ RenderingEngine::get_gui_env()->drawAll();
driver->endScene();
// On some computers framerate doesn't seem to be automatically limited
sleep_ms(25);
@@ -503,73 +499,14 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
// Cursor can be non-visible when coming from the game
#ifndef ANDROID
- device->getCursorControl()->setVisible(true);
+ RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true);
#endif
/* show main menu */
- GUIEngine mymenu(device, &input->joystick, guiroot,
- &g_menumgr, smgr, menudata, *kill);
+ GUIEngine mymenu(&input->joystick, guiroot, &g_menumgr, menudata, *kill);
- smgr->clear(); /* leave scene manager in a clean state */
-}
-
-bool ClientLauncher::create_engine_device()
-{
- // Resolution selection
- bool fullscreen = g_settings->getBool("fullscreen");
- u16 screen_w = g_settings->getU16("screen_w");
- u16 screen_h = g_settings->getU16("screen_h");
-
- // bpp, fsaa, vsync
- bool vsync = g_settings->getBool("vsync");
- u16 bits = g_settings->getU16("fullscreen_bpp");
- u16 fsaa = g_settings->getU16("fsaa");
-
- // stereo buffer required for pageflip stereo
- bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
-
- // Determine driver
- video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
- const std::string &driverstring = g_settings->get("video_driver");
- std::vector<video::E_DRIVER_TYPE> drivers
- = porting::getSupportedVideoDrivers();
- u32 i;
- for (i = 0; i != drivers.size(); i++) {
- if (!strcasecmp(driverstring.c_str(),
- porting::getVideoDriverName(drivers[i]))) {
- driverType = drivers[i];
- break;
- }
- }
- if (i == drivers.size()) {
- errorstream << "Invalid video_driver specified; "
- "defaulting to opengl" << std::endl;
- }
-
- SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
- params.DriverType = driverType;
- params.WindowSize = core::dimension2d<u32>(screen_w, screen_h);
- params.Bits = bits;
- params.AntiAlias = fsaa;
- params.Fullscreen = fullscreen;
- params.Stencilbuffer = false;
- params.Stereobuffer = stereo_buffer;
- params.Vsync = vsync;
- params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
- params.ZBufferBits = 24;
-#ifdef __ANDROID__
- params.PrivateData = porting::app_global;
- params.OGLES2ShaderPath = std::string(porting::path_user + DIR_DELIM +
- "media" + DIR_DELIM + "Shaders" + DIR_DELIM).c_str();
-#endif
-
- device = createDeviceEx(params);
-
- if (device)
- porting::initIrrlicht(device);
-
- return device != NULL;
+ /* leave scene manager in a clean state */
+ RenderingEngine::get_scene_manager()->clear();
}
void ClientLauncher::speed_tests()
@@ -584,8 +521,8 @@ void ClientLauncher::speed_tests()
tempv3f1 = v3f();
tempv3f2 = v3f();
- tempstring = std::string();
- tempstring2 = std::string();
+ tempstring.clear();
+ tempstring2.clear();
{
infostream << "The following test should take around 20ms." << std::endl;
@@ -670,58 +607,3 @@ void ClientLauncher::speed_tests()
infostream << "Done. " << dtime << "ms, " << per_ms << "/ms" << std::endl;
}
}
-
-bool ClientLauncher::print_video_modes()
-{
- IrrlichtDevice *nulldevice;
-
- bool vsync = g_settings->getBool("vsync");
- u16 fsaa = g_settings->getU16("fsaa");
- MyEventReceiver* receiver = new MyEventReceiver();
-
- SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
- params.DriverType = video::EDT_NULL;
- params.WindowSize = core::dimension2d<u32>(640, 480);
- params.Bits = 24;
- params.AntiAlias = fsaa;
- params.Fullscreen = false;
- params.Stencilbuffer = false;
- params.Vsync = vsync;
- params.EventReceiver = receiver;
- params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
-
- nulldevice = createDeviceEx(params);
-
- if (nulldevice == NULL) {
- delete receiver;
- return false;
- }
-
- std::cout << _("Available video modes (WxHxD):") << std::endl;
-
- video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
-
- if (videomode_list != NULL) {
- s32 videomode_count = videomode_list->getVideoModeCount();
- core::dimension2d<u32> videomode_res;
- s32 videomode_depth;
- for (s32 i = 0; i < videomode_count; ++i) {
- videomode_res = videomode_list->getVideoModeResolution(i);
- videomode_depth = videomode_list->getVideoModeDepth(i);
- std::cout << videomode_res.Width << "x" << videomode_res.Height
- << "x" << videomode_depth << std::endl;
- }
-
- std::cout << _("Active video mode (WxHxD):") << std::endl;
- videomode_res = videomode_list->getDesktopResolution();
- videomode_depth = videomode_list->getDesktopDepth();
- std::cout << videomode_res.Width << "x" << videomode_res.Height
- << "x" << videomode_depth << std::endl;
-
- }
-
- nulldevice->drop();
- delete receiver;
-
- return videomode_list != NULL;
-}
diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h
index 9e0560b14..8f8a01e2f 100644
--- a/src/client/clientlauncher.h
+++ b/src/client/clientlauncher.h
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/inputhandler.h"
#include "gameparams.h"
+class RenderingEngine;
class ClientLauncher
{
@@ -43,10 +44,8 @@ protected:
GameParams &game_params, const Settings &cmd_args);
void main_menu(MainMenuData *menudata);
- bool create_engine_device();
void speed_tests();
- bool print_video_modes();
bool list_video_modes = false;
bool skip_main_menu = false;
@@ -55,12 +54,10 @@ protected:
std::string address = "";
std::string playername = "";
std::string password = "";
- IrrlichtDevice *device = nullptr;
InputHandler *input = nullptr;
MyEventReceiver *receiver = nullptr;
gui::IGUISkin *skin = nullptr;
gui::IGUIFont *font = nullptr;
- scene::ISceneManager *smgr = nullptr;
SubgameSpec gamespec;
WorldSpec worldspec;
bool simple_singleplayer_mode;
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index 19733e3ec..822e27863 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "joystick_controller.h"
#include <list>
#include "keycode.h"
+#include "renderingengine.h"
#ifdef HAVE_TOUCHSCREENGUI
#include "touchscreengui.h"
@@ -219,8 +220,7 @@ public:
class RealInputHandler : public InputHandler
{
public:
- RealInputHandler(IrrlichtDevice *device, MyEventReceiver *receiver)
- : m_device(device), m_receiver(receiver)
+ RealInputHandler(MyEventReceiver *receiver) : m_receiver(receiver)
{
m_receiver->joystick = &joystick;
}
@@ -239,16 +239,20 @@ public:
virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); }
virtual v2s32 getMousePos()
{
- if (m_device->getCursorControl()) {
- return m_device->getCursorControl()->getPosition();
+ if (RenderingEngine::get_raw_device()->getCursorControl()) {
+ return RenderingEngine::get_raw_device()
+ ->getCursorControl()
+ ->getPosition();
} else {
return m_mousepos;
}
}
virtual void setMousePos(s32 x, s32 y)
{
- if (m_device->getCursorControl()) {
- m_device->getCursorControl()->setPosition(x, y);
+ if (RenderingEngine::get_raw_device()->getCursorControl()) {
+ RenderingEngine::get_raw_device()
+ ->getCursorControl()
+ ->setPosition(x, y);
} else {
m_mousepos = v2s32(x, y);
}
@@ -276,7 +280,6 @@ public:
}
private:
- IrrlichtDevice *m_device = nullptr;
MyEventReceiver *m_receiver = nullptr;
v2s32 m_mousepos;
};
diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp
new file mode 100644
index 000000000..ce8f643b9
--- /dev/null
+++ b/src/client/renderingengine.cpp
@@ -0,0 +1,1072 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include <IrrlichtDevice.h>
+#include <irrlicht.h>
+#include "fontengine.h"
+#include "clouds.h"
+#include "util/numeric.h"
+#include "guiscalingfilter.h"
+#include "hud.h"
+#include "camera.h"
+#include "minimap.h"
+#include "clientmap.h"
+#include "renderingengine.h"
+#include "inputhandler.h"
+#include "gettext.h"
+
+#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__) && !defined(SERVER)
+#define XORG_USED
+#endif
+#ifdef XORG_USED
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#endif
+
+RenderingEngine *RenderingEngine::s_singleton = nullptr;
+
+RenderingEngine::RenderingEngine(IEventReceiver *receiver)
+{
+ sanity_check(!s_singleton);
+
+ // Resolution selection
+ bool fullscreen = g_settings->getBool("fullscreen");
+ u16 screen_w = g_settings->getU16("screen_w");
+ u16 screen_h = g_settings->getU16("screen_h");
+
+ // bpp, fsaa, vsync
+ bool vsync = g_settings->getBool("vsync");
+ u16 bits = g_settings->getU16("fullscreen_bpp");
+ u16 fsaa = g_settings->getU16("fsaa");
+
+ // stereo buffer required for pageflip stereo
+ bool stereo_buffer = g_settings->get("3d_mode") == "pageflip";
+
+ // Determine driver
+ video::E_DRIVER_TYPE driverType = video::EDT_OPENGL;
+ const std::string &driverstring = g_settings->get("video_driver");
+ std::vector<video::E_DRIVER_TYPE> drivers =
+ RenderingEngine::getSupportedVideoDrivers();
+ u32 i;
+ for (i = 0; i != drivers.size(); i++) {
+ if (!strcasecmp(driverstring.c_str(),
+ RenderingEngine::getVideoDriverName(drivers[i]))) {
+ driverType = drivers[i];
+ break;
+ }
+ }
+ if (i == drivers.size()) {
+ errorstream << "Invalid video_driver specified; "
+ "defaulting to opengl"
+ << std::endl;
+ }
+
+ SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
+ params.DriverType = driverType;
+ params.WindowSize = core::dimension2d<u32>(screen_w, screen_h);
+ params.Bits = bits;
+ params.AntiAlias = fsaa;
+ params.Fullscreen = fullscreen;
+ params.Stencilbuffer = false;
+ params.Stereobuffer = stereo_buffer;
+ params.Vsync = vsync;
+ params.EventReceiver = receiver;
+ params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
+ params.ZBufferBits = 24;
+#ifdef __ANDROID__
+ params.PrivateData = porting::app_global;
+ params.OGLES2ShaderPath = std::string(
+ porting::path_user + DIR_DELIM + "media" + DIR_DELIM + "Shaders" +
+ DIR_DELIM).c_str();
+#endif
+
+ m_device = createDeviceEx(params);
+ s_singleton = this;
+}
+
+RenderingEngine::~RenderingEngine()
+{
+ m_device->drop();
+ s_singleton = nullptr;
+}
+
+v2u32 RenderingEngine::getWindowSize() const
+{
+ return m_device->getVideoDriver()->getScreenSize();
+}
+
+void RenderingEngine::setResizable(bool resize)
+{
+ m_device->setResizable(resize);
+}
+
+video::IVideoDriver *RenderingEngine::getVideoDriver()
+{
+ return m_device->getVideoDriver();
+}
+
+bool RenderingEngine::print_video_modes()
+{
+ IrrlichtDevice *nulldevice;
+
+ bool vsync = g_settings->getBool("vsync");
+ u16 fsaa = g_settings->getU16("fsaa");
+ MyEventReceiver *receiver = new MyEventReceiver();
+
+ SIrrlichtCreationParameters params = SIrrlichtCreationParameters();
+ params.DriverType = video::EDT_NULL;
+ params.WindowSize = core::dimension2d<u32>(640, 480);
+ params.Bits = 24;
+ params.AntiAlias = fsaa;
+ params.Fullscreen = false;
+ params.Stencilbuffer = false;
+ params.Vsync = vsync;
+ params.EventReceiver = receiver;
+ params.HighPrecisionFPU = g_settings->getBool("high_precision_fpu");
+
+ nulldevice = createDeviceEx(params);
+
+ if (!nulldevice) {
+ delete receiver;
+ return false;
+ }
+
+ std::cout << _("Available video modes (WxHxD):") << std::endl;
+
+ video::IVideoModeList *videomode_list = nulldevice->getVideoModeList();
+
+ if (videomode_list != NULL) {
+ s32 videomode_count = videomode_list->getVideoModeCount();
+ core::dimension2d<u32> videomode_res;
+ s32 videomode_depth;
+ for (s32 i = 0; i < videomode_count; ++i) {
+ videomode_res = videomode_list->getVideoModeResolution(i);
+ videomode_depth = videomode_list->getVideoModeDepth(i);
+ std::cout << videomode_res.Width << "x" << videomode_res.Height
+ << "x" << videomode_depth << std::endl;
+ }
+
+ std::cout << _("Active video mode (WxHxD):") << std::endl;
+ videomode_res = videomode_list->getDesktopResolution();
+ videomode_depth = videomode_list->getDesktopDepth();
+ std::cout << videomode_res.Width << "x" << videomode_res.Height << "x"
+ << videomode_depth << std::endl;
+ }
+
+ nulldevice->drop();
+ delete receiver;
+
+ return videomode_list != NULL;
+}
+
+void RenderingEngine::setXorgClassHint(
+ const video::SExposedVideoData &video_data, const std::string &name)
+{
+#ifdef XORG_USED
+ if (video_data.OpenGLLinux.X11Display == NULL)
+ return;
+
+ XClassHint *classhint = XAllocClassHint();
+ classhint->res_name = (char *)name.c_str();
+ classhint->res_class = (char *)name.c_str();
+
+ XSetClassHint((Display *)video_data.OpenGLLinux.X11Display,
+ video_data.OpenGLLinux.X11Window, classhint);
+ XFree(classhint);
+#endif
+}
+
+bool RenderingEngine::setWindowIcon()
+{
+#if defined(XORG_USED)
+#if RUN_IN_PLACE
+ return setXorgWindowIconFromPath(
+ porting::path_share + "/misc/" PROJECT_NAME "-xorg-icon-128.png");
+#else
+ // We have semi-support for reading in-place data if we are
+ // compiled with RUN_IN_PLACE. Don't break with this and
+ // also try the path_share location.
+ return setXorgWindowIconFromPath(
+ ICON_DIR "/hicolor/128x128/apps/" PROJECT_NAME ".png") ||
+ setXorgWindowIconFromPath(porting::path_share + "/misc/" PROJECT_NAME
+ "-xorg-icon-128.png");
+#endif
+#elif defined(_WIN32)
+ const video::SExposedVideoData exposedData =
+ m_device->getVideoDriver()->getExposedVideoData();
+ HWND hWnd; // Window handle
+
+ switch (m_device->getVideoDriver()->getDriverType()) {
+ case video::EDT_DIRECT3D8:
+ hWnd = reinterpret_cast<HWND>(exposedData.D3D8.HWnd);
+ break;
+ case video::EDT_DIRECT3D9:
+ hWnd = reinterpret_cast<HWND>(exposedData.D3D9.HWnd);
+ break;
+ case video::EDT_OPENGL:
+ hWnd = reinterpret_cast<HWND>(exposedData.OpenGLWin32.HWnd);
+ break;
+ default:
+ return false;
+ }
+
+ // Load the ICON from resource file
+ const HICON hicon = LoadIcon(GetModuleHandle(NULL),
+ MAKEINTRESOURCE(130) // The ID of the ICON defined in
+ // winresource.rc
+ );
+
+ if (hicon) {
+ SendMessage(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(hicon));
+ SendMessage(hWnd, WM_SETICON, ICON_SMALL,
+ reinterpret_cast<LPARAM>(hicon));
+ return true;
+ }
+ return false;
+#else
+ return false;
+#endif
+}
+
+bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file)
+{
+#ifdef XORG_USED
+
+ video::IVideoDriver *v_driver = m_device->getVideoDriver();
+
+ video::IImageLoader *image_loader = NULL;
+ u32 cnt = v_driver->getImageLoaderCount();
+ for (u32 i = 0; i < cnt; i++) {
+ if (v_driver->getImageLoader(i)->isALoadableFileExtension(
+ icon_file.c_str())) {
+ image_loader = v_driver->getImageLoader(i);
+ break;
+ }
+ }
+
+ if (!image_loader) {
+ warningstream << "Could not find image loader for file '" << icon_file
+ << "'" << std::endl;
+ return false;
+ }
+
+ io::IReadFile *icon_f =
+ m_device->getFileSystem()->createAndOpenFile(icon_file.c_str());
+
+ if (!icon_f) {
+ warningstream << "Could not load icon file '" << icon_file << "'"
+ << std::endl;
+ return false;
+ }
+
+ video::IImage *img = image_loader->loadImage(icon_f);
+
+ if (!img) {
+ warningstream << "Could not load icon file '" << icon_file << "'"
+ << std::endl;
+ icon_f->drop();
+ return false;
+ }
+
+ u32 height = img->getDimension().Height;
+ u32 width = img->getDimension().Width;
+
+ size_t icon_buffer_len = 2 + height * width;
+ long *icon_buffer = new long[icon_buffer_len];
+
+ icon_buffer[0] = width;
+ icon_buffer[1] = height;
+
+ for (u32 x = 0; x < width; x++) {
+ for (u32 y = 0; y < height; y++) {
+ video::SColor col = img->getPixel(x, y);
+ long pixel_val = 0;
+ pixel_val |= (u8)col.getAlpha() << 24;
+ pixel_val |= (u8)col.getRed() << 16;
+ pixel_val |= (u8)col.getGreen() << 8;
+ pixel_val |= (u8)col.getBlue();
+ icon_buffer[2 + x + y * width] = pixel_val;
+ }
+ }
+
+ img->drop();
+ icon_f->drop();
+
+ const video::SExposedVideoData &video_data = v_driver->getExposedVideoData();
+
+ Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display;
+
+ if (x11_dpl == NULL) {
+ warningstream << "Could not find x11 display for setting its icon."
+ << std::endl;
+ delete[] icon_buffer;
+ return false;
+ }
+
+ Window x11_win = (Window)video_data.OpenGLLinux.X11Window;
+
+ Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False);
+ Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False);
+ XChangeProperty(x11_dpl, x11_win, net_wm_icon, cardinal, 32, PropModeReplace,
+ (const unsigned char *)icon_buffer, icon_buffer_len);
+
+ delete[] icon_buffer;
+
+#endif
+ return true;
+}
+
+/*
+ Draws a screen with a single text on it.
+ Text will be removed when the screen is drawn the next time.
+ Additionally, a progressbar can be drawn when percent is set between 0 and 100.
+*/
+void RenderingEngine::_draw_load_screen(const std::wstring &text,
+ gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime,
+ int percent, bool clouds)
+{
+ v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
+
+ v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
+ v2s32 center(screensize.X / 2, screensize.Y / 2);
+ core::rect<s32> textrect(center - textsize / 2, center + textsize / 2);
+
+ gui::IGUIStaticText *guitext =
+ guienv->addStaticText(text.c_str(), textrect, false, false);
+ guitext->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+
+ bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds");
+ if (cloud_menu_background) {
+ g_menuclouds->step(dtime * 3);
+ g_menuclouds->render();
+ get_video_driver()->beginScene(
+ true, true, video::SColor(255, 140, 186, 250));
+ g_menucloudsmgr->drawAll();
+ } else
+ get_video_driver()->beginScene(true, true, video::SColor(255, 0, 0, 0));
+
+ // draw progress bar
+ if ((percent >= 0) && (percent <= 100)) {
+ video::ITexture *progress_img = tsrc->getTexture("progress_bar.png");
+ video::ITexture *progress_img_bg =
+ tsrc->getTexture("progress_bar_bg.png");
+
+ if (progress_img && progress_img_bg) {
+#ifndef __ANDROID__
+ const core::dimension2d<u32> &img_size =
+ progress_img_bg->getSize();
+ u32 imgW = rangelim(img_size.Width, 200, 600);
+ u32 imgH = rangelim(img_size.Height, 24, 72);
+#else
+ const core::dimension2d<u32> img_size(256, 48);
+ float imgRatio = (float)img_size.Height / img_size.Width;
+ u32 imgW = screensize.X / 2.2f;
+ u32 imgH = floor(imgW * imgRatio);
+#endif
+ v2s32 img_pos((screensize.X - imgW) / 2,
+ (screensize.Y - imgH) / 2);
+
+ draw2DImageFilterScaled(get_video_driver(), progress_img_bg,
+ core::rect<s32>(img_pos.X, img_pos.Y,
+ img_pos.X + imgW,
+ img_pos.Y + imgH),
+ core::rect<s32>(0, 0, img_size.Width,
+ img_size.Height),
+ 0, 0, true);
+
+ draw2DImageFilterScaled(get_video_driver(), progress_img,
+ core::rect<s32>(img_pos.X, img_pos.Y,
+ img_pos.X + (percent * imgW) / 100,
+ img_pos.Y + imgH),
+ core::rect<s32>(0, 0,
+ (percent * img_size.Width) / 100,
+ img_size.Height),
+ 0, 0, true);
+ }
+ }
+
+ guienv->drawAll();
+ get_video_driver()->endScene();
+ guitext->remove();
+}
+
+std::vector<core::vector3d<u32>> RenderingEngine::getSupportedVideoModes()
+{
+ IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
+ sanity_check(nulldevice);
+
+ std::vector<core::vector3d<u32>> mlist;
+ video::IVideoModeList *modelist = nulldevice->getVideoModeList();
+
+ s32 num_modes = modelist->getVideoModeCount();
+ for (s32 i = 0; i != num_modes; i++) {
+ core::dimension2d<u32> mode_res = modelist->getVideoModeResolution(i);
+ u32 mode_depth = (u32)modelist->getVideoModeDepth(i);
+ mlist.push_back(core::vector3d<u32>(
+ mode_res.Width, mode_res.Height, mode_depth));
+ }
+
+ nulldevice->drop();
+ return mlist;
+}
+
+std::vector<irr::video::E_DRIVER_TYPE> RenderingEngine::getSupportedVideoDrivers()
+{
+ std::vector<irr::video::E_DRIVER_TYPE> drivers;
+
+ for (int i = 0; i != irr::video::EDT_COUNT; i++) {
+ if (irr::IrrlichtDevice::isDriverSupported((irr::video::E_DRIVER_TYPE)i))
+ drivers.push_back((irr::video::E_DRIVER_TYPE)i);
+ }
+
+ return drivers;
+}
+
+void RenderingEngine::_draw_scene(Camera *camera, Client *client, LocalPlayer *player,
+ Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
+ const v2u32 &screensize, const video::SColor &skycolor, bool show_hud,
+ bool show_minimap)
+{
+ bool draw_wield_tool =
+ (show_hud && (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE) &&
+ camera->getCameraMode() < CAMERA_MODE_THIRD);
+
+ bool draw_crosshair = ((player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
+ (camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));
+
+#ifdef HAVE_TOUCHSCREENGUI
+ try {
+ draw_crosshair = !g_settings->getBool("touchtarget");
+ } catch (SettingNotFoundException) {
+ }
+#endif
+
+ const std::string &draw_mode = g_settings->get("3d_mode");
+
+ if (draw_mode == "anaglyph") {
+ draw_anaglyph_3d_mode(
+ camera, show_hud, hud, draw_wield_tool, client, guienv);
+ draw_crosshair = false;
+ } else if (draw_mode == "interlaced") {
+ draw_interlaced_3d_mode(camera, show_hud, hud, screensize,
+ draw_wield_tool, client, guienv, skycolor);
+ draw_crosshair = false;
+ } else if (draw_mode == "sidebyside") {
+ draw_sidebyside_3d_mode(camera, show_hud, hud, screensize,
+ draw_wield_tool, client, guienv, skycolor);
+ show_hud = false;
+ } else if (draw_mode == "topbottom") {
+ draw_top_bottom_3d_mode(camera, show_hud, hud, screensize,
+ draw_wield_tool, client, guienv, skycolor);
+ show_hud = false;
+ } else if (draw_mode == "pageflip") {
+ draw_pageflip_3d_mode(camera, show_hud, hud, screensize, draw_wield_tool,
+ client, guienv, skycolor);
+ draw_crosshair = false;
+ show_hud = false;
+ } else {
+ draw_plain(camera, show_hud, hud, screensize, draw_wield_tool, client,
+ guienv, skycolor);
+ }
+
+ /*
+ Post effects
+ */
+ client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
+
+ // TODO how to make those 3d too
+ if (show_hud) {
+ if (draw_crosshair)
+ hud->drawCrosshair();
+
+ hud->drawHotbar(client->getPlayerItem());
+ hud->drawLuaElements(camera->getOffset());
+ camera->drawNametags();
+
+ if (mapper && show_minimap)
+ mapper->drawMinimap();
+ }
+
+ guienv->drawAll();
+}
+
+void RenderingEngine::draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ bool draw_wield_tool, Client *client, gui::IGUIEnvironment *guienv)
+{
+
+ /* preserve old setup*/
+ irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+
+ irr::core::matrix4 startMatrix =
+ camera->getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint =
+ (camera->getCameraNode()->getTarget() -
+ camera->getCameraNode()->getAbsolutePosition())
+ .setLength(1) +
+ camera->getCameraNode()->getAbsolutePosition();
+
+ // Left eye...
+ irr::core::vector3df leftEye;
+ irr::core::matrix4 leftMove;
+ leftMove.setTranslation(irr::core::vector3df(
+ -g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+ leftEye = (startMatrix * leftMove).getTranslation();
+
+ // clear the depth buffer, and color
+ getVideoDriver()->beginScene(true, true, irr::video::SColor(0, 200, 200, 255));
+ getVideoDriver()->getOverrideMaterial().Material.ColorMask = irr::video::ECP_RED;
+ getVideoDriver()->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
+ getVideoDriver()->getOverrideMaterial().EnablePasses =
+ irr::scene::ESNRP_SKY_BOX + irr::scene::ESNRP_SOLID +
+ irr::scene::ESNRP_TRANSPARENT +
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
+ camera->getCameraNode()->setPosition(leftEye);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&leftMove);
+ }
+
+ guienv->drawAll();
+
+ // Right eye...
+ irr::core::vector3df rightEye;
+ irr::core::matrix4 rightMove;
+ rightMove.setTranslation(irr::core::vector3df(
+ g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+ rightEye = (startMatrix * rightMove).getTranslation();
+
+ // clear the depth buffer
+ getVideoDriver()->clearZBuffer();
+ getVideoDriver()->getOverrideMaterial().Material.ColorMask =
+ irr::video::ECP_GREEN + irr::video::ECP_BLUE;
+ getVideoDriver()->getOverrideMaterial().EnableFlags = irr::video::EMF_COLOR_MASK;
+ getVideoDriver()->getOverrideMaterial().EnablePasses =
+ irr::scene::ESNRP_SKY_BOX + irr::scene::ESNRP_SOLID +
+ irr::scene::ESNRP_TRANSPARENT +
+ irr::scene::ESNRP_TRANSPARENT_EFFECT + irr::scene::ESNRP_SHADOW;
+ camera->getCameraNode()->setPosition(rightEye);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&rightMove);
+ }
+
+ guienv->drawAll();
+
+ getVideoDriver()->getOverrideMaterial().Material.ColorMask = irr::video::ECP_ALL;
+ getVideoDriver()->getOverrideMaterial().EnableFlags = 0;
+ getVideoDriver()->getOverrideMaterial().EnablePasses = 0;
+ camera->getCameraNode()->setPosition(oldPosition);
+ camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::init_texture(
+ const v2u32 &screensize, video::ITexture **texture, const char *name)
+{
+ if (*texture) {
+ getVideoDriver()->removeTexture(*texture);
+ }
+ *texture = getVideoDriver()->addRenderTargetTexture(
+ core::dimension2d<u32>(screensize.X, screensize.Y), name,
+ irr::video::ECF_A8R8G8B8);
+}
+
+video::ITexture *RenderingEngine::draw_image(const v2u32 &screensize, parallax_sign psign,
+ const irr::core::matrix4 &startMatrix,
+ const irr::core::vector3df &focusPoint, bool show_hud, Camera *camera,
+ Hud *hud, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+ static video::ITexture *images[2] = {NULL, NULL};
+ static v2u32 last_screensize = v2u32(0, 0);
+
+ video::ITexture *image = NULL;
+
+ if (screensize != last_screensize) {
+ init_texture(screensize, &images[1], "mt_drawimage_img1");
+ init_texture(screensize, &images[0], "mt_drawimage_img2");
+ last_screensize = screensize;
+ }
+
+ if (psign == RIGHT)
+ image = images[1];
+ else
+ image = images[0];
+
+ getVideoDriver()->setRenderTarget(image, true, true,
+ irr::video::SColor(255, skycolor.getRed(), skycolor.getGreen(),
+ skycolor.getBlue()));
+
+ irr::core::vector3df eye_pos;
+ irr::core::matrix4 movement;
+ movement.setTranslation(irr::core::vector3df(
+ (int)psign * g_settings->getFloat("3d_paralax_strength"), 0.0f,
+ 0.0f));
+ eye_pos = (startMatrix * movement).getTranslation();
+
+ // clear the depth buffer
+ getVideoDriver()->clearZBuffer();
+ camera->getCameraNode()->setPosition(eye_pos);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&movement);
+ }
+
+ guienv->drawAll();
+
+ /* switch back to real renderer */
+ getVideoDriver()->setRenderTarget(0, true, true,
+ irr::video::SColor(0, skycolor.getRed(), skycolor.getGreen(),
+ skycolor.getBlue()));
+
+ return image;
+}
+
+video::ITexture *RenderingEngine::draw_hud(const v2u32 &screensize, bool show_hud,
+ Hud *hud, Client *client, bool draw_crosshair,
+ const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
+ Camera *camera)
+{
+ static video::ITexture *image = nullptr;
+ init_texture(screensize, &image, "mt_drawimage_hud");
+ getVideoDriver()->setRenderTarget(
+ image, true, true, irr::video::SColor(255, 0, 0, 0));
+
+ if (show_hud) {
+ if (draw_crosshair)
+ hud->drawCrosshair();
+ hud->drawHotbar(client->getPlayerItem());
+ hud->drawLuaElements(camera->getOffset());
+ camera->drawNametags();
+ guienv->drawAll();
+ }
+
+ getVideoDriver()->setRenderTarget(0, true, true,
+ irr::video::SColor(0, skycolor.getRed(), skycolor.getGreen(),
+ skycolor.getBlue()));
+
+ return image;
+}
+
+void RenderingEngine::draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+ /* save current info */
+ irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+ irr::core::matrix4 startMatrix =
+ camera->getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint =
+ (camera->getCameraNode()->getTarget() -
+ camera->getCameraNode()->getAbsolutePosition())
+ .setLength(1) +
+ camera->getCameraNode()->getAbsolutePosition();
+
+ /* create left view */
+ video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+ focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+ guienv, skycolor);
+
+ // Right eye...
+ irr::core::vector3df rightEye;
+ irr::core::matrix4 rightMove;
+ rightMove.setTranslation(irr::core::vector3df(
+ g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+ rightEye = (startMatrix * rightMove).getTranslation();
+
+ // clear the depth buffer
+ getVideoDriver()->clearZBuffer();
+ camera->getCameraNode()->setPosition(rightEye);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&rightMove);
+ }
+ guienv->drawAll();
+
+ for (unsigned int i = 0; i < screensize.Y; i += 2) {
+#if (IRRLICHT_VERSION_MAJOR >= 1) && (IRRLICHT_VERSION_MINOR >= 8)
+ getVideoDriver()->draw2DImage(left_image,
+ irr::core::position2d<s32>(0, i),
+#else
+ getVideoDriver()->draw2DImage(left_image,
+ irr::core::position2d<s32>(0, screensize.Y - i),
+#endif
+ irr::core::rect<s32>(0, i, screensize.X, i + 1), 0,
+ irr::video::SColor(255, 255, 255, 255), false);
+ }
+
+ /* cleanup */
+ camera->getCameraNode()->setPosition(oldPosition);
+ camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+ /* save current info */
+ irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+ irr::core::matrix4 startMatrix =
+ camera->getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint =
+ (camera->getCameraNode()->getTarget() -
+ camera->getCameraNode()->getAbsolutePosition())
+ .setLength(1) +
+ camera->getCameraNode()->getAbsolutePosition();
+
+ /* create left view */
+ video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+ focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+ guienv, skycolor);
+
+ /* create right view */
+ video::ITexture *right_image = draw_image(screensize, RIGHT, startMatrix,
+ focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+ guienv, skycolor);
+
+ /* create hud overlay */
+ video::ITexture *hudtexture = draw_hud(screensize, show_hud, hud, client, false,
+ skycolor, guienv, camera);
+ getVideoDriver()->makeColorKeyTexture(
+ hudtexture, irr::video::SColor(255, 0, 0, 0));
+ // makeColorKeyTexture mirrors texture so we do it twice to get it right again
+ getVideoDriver()->makeColorKeyTexture(
+ hudtexture, irr::video::SColor(255, 0, 0, 0));
+
+ draw2DImageFilterScaled(getVideoDriver(), left_image,
+ irr::core::rect<s32>(0, 0, screensize.X / 2, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ false);
+
+ draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+ irr::core::rect<s32>(0, 0, screensize.X / 2, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ true);
+
+ draw2DImageFilterScaled(getVideoDriver(), right_image,
+ irr::core::rect<s32>(
+ screensize.X / 2, 0, screensize.X, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ false);
+
+ draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+ irr::core::rect<s32>(
+ screensize.X / 2, 0, screensize.X, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ true);
+
+ left_image = nullptr;
+ right_image = nullptr;
+
+ /* cleanup */
+ camera->getCameraNode()->setPosition(oldPosition);
+ camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+ /* save current info */
+ irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+ irr::core::matrix4 startMatrix =
+ camera->getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint =
+ (camera->getCameraNode()->getTarget() -
+ camera->getCameraNode()->getAbsolutePosition())
+ .setLength(1) +
+ camera->getCameraNode()->getAbsolutePosition();
+
+ /* create left view */
+ video::ITexture *left_image = draw_image(screensize, LEFT, startMatrix,
+ focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+ guienv, skycolor);
+
+ /* create right view */
+ video::ITexture *right_image = draw_image(screensize, RIGHT, startMatrix,
+ focusPoint, show_hud, camera, hud, draw_wield_tool, client,
+ guienv, skycolor);
+
+ /* create hud overlay */
+ video::ITexture *hudtexture = draw_hud(screensize, show_hud, hud, client, false,
+ skycolor, guienv, camera);
+ getVideoDriver()->makeColorKeyTexture(
+ hudtexture, irr::video::SColor(255, 0, 0, 0));
+ // makeColorKeyTexture mirrors texture so we do it twice to get it right again
+ getVideoDriver()->makeColorKeyTexture(
+ hudtexture, irr::video::SColor(255, 0, 0, 0));
+
+ draw2DImageFilterScaled(getVideoDriver(), left_image,
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y / 2),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ false);
+
+ draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y / 2),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ true);
+
+ draw2DImageFilterScaled(getVideoDriver(), right_image,
+ irr::core::rect<s32>(
+ 0, screensize.Y / 2, screensize.X, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ false);
+
+ draw2DImageFilterScaled(getVideoDriver(), hudtexture,
+ irr::core::rect<s32>(
+ 0, screensize.Y / 2, screensize.X, screensize.Y),
+ irr::core::rect<s32>(0, 0, screensize.X, screensize.Y), 0, 0,
+ true);
+
+ left_image = NULL;
+ right_image = NULL;
+
+ /* cleanup */
+ camera->getCameraNode()->setPosition(oldPosition);
+ camera->getCameraNode()->setTarget(oldTarget);
+}
+
+void RenderingEngine::draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
+ errorstream << "Pageflip 3D mode is not supported"
+ << " with your Irrlicht version!" << std::endl;
+#else
+ /* preserve old setup*/
+ irr::core::vector3df oldPosition = camera->getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera->getCameraNode()->getTarget();
+
+ irr::core::matrix4 startMatrix =
+ camera->getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint =
+ (camera->getCameraNode()->getTarget() -
+ camera->getCameraNode()->getAbsolutePosition())
+ .setLength(1) +
+ camera->getCameraNode()->getAbsolutePosition();
+
+ // Left eye...
+ getVideoDriver()->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
+
+ irr::core::vector3df leftEye;
+ irr::core::matrix4 leftMove;
+ leftMove.setTranslation(irr::core::vector3df(
+ -g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+ leftEye = (startMatrix * leftMove).getTranslation();
+
+ // clear the depth buffer, and color
+ getVideoDriver()->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera->getCameraNode()->setPosition(leftEye);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&leftMove);
+ hud->drawHotbar(client->getPlayerItem());
+ hud->drawLuaElements(camera->getOffset());
+ camera->drawNametags();
+ }
+
+ guienv->drawAll();
+
+ // Right eye...
+ getVideoDriver()->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
+
+ irr::core::vector3df rightEye;
+ irr::core::matrix4 rightMove;
+ rightMove.setTranslation(irr::core::vector3df(
+ g_settings->getFloat("3d_paralax_strength"), 0.0f, 0.0f));
+ rightEye = (startMatrix * rightMove).getTranslation();
+
+ // clear the depth buffer, and color
+ getVideoDriver()->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera->getCameraNode()->setPosition(rightEye);
+ camera->getCameraNode()->setTarget(focusPoint);
+ get_scene_manager()->drawAll();
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool)
+ camera->drawWieldedTool(&rightMove);
+ hud->drawHotbar(client->getPlayerItem());
+ hud->drawLuaElements(camera->getOffset());
+ camera->drawNametags();
+ }
+
+ guienv->drawAll();
+
+ camera->getCameraNode()->setPosition(oldPosition);
+ camera->getCameraNode()->setTarget(oldTarget);
+#endif
+}
+
+// returns (size / coef), rounded upwards
+inline int scaledown(int coef, int size)
+{
+ return (size + coef - 1) / coef;
+}
+
+void RenderingEngine::draw_plain(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
+{
+ // Undersampling-specific stuff
+ static video::ITexture *image = NULL;
+ static v2u32 last_pixelated_size = v2u32(0, 0);
+ static thread_local int undersampling = g_settings->getU16("undersampling");
+ v2u32 pixelated_size;
+ v2u32 dest_size;
+ if (undersampling > 0) {
+ pixelated_size = v2u32(scaledown(undersampling, screensize.X),
+ scaledown(undersampling, screensize.Y));
+ dest_size = v2u32(undersampling * pixelated_size.X,
+ undersampling * pixelated_size.Y);
+ if (pixelated_size != last_pixelated_size) {
+ init_texture(pixelated_size, &image, "mt_drawimage_img1");
+ last_pixelated_size = pixelated_size;
+ }
+ getVideoDriver()->setRenderTarget(image, true, true, skycolor);
+ }
+
+ // Render
+ get_scene_manager()->drawAll();
+ getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+ if (show_hud) {
+ hud->drawSelectionMesh();
+ if (draw_wield_tool) {
+ camera->drawWieldedTool();
+ }
+ }
+
+ // Upscale lowres render
+ if (undersampling > 0) {
+ getVideoDriver()->setRenderTarget(0, true, true);
+ getVideoDriver()->draw2DImage(image,
+ irr::core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
+ irr::core::rect<s32>(0, 0, pixelated_size.X,
+ pixelated_size.Y));
+ }
+}
+
+const char *RenderingEngine::getVideoDriverName(irr::video::E_DRIVER_TYPE type)
+{
+ static const char *driver_ids[] = {
+ "null", "software", "burningsvideo", "direct3d8", "direct3d9",
+ "opengl", "ogles1", "ogles2",
+ };
+
+ return driver_ids[type];
+}
+
+const char *RenderingEngine::getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type)
+{
+ static const char *driver_names[] = {
+ "NULL Driver", "Software Renderer", "Burning's Video",
+ "Direct3D 8", "Direct3D 9", "OpenGL", "OpenGL ES1", "OpenGL ES2",
+ };
+
+ return driver_names[type];
+}
+
+#ifndef __ANDROID__
+#ifdef XORG_USED
+
+static float calcDisplayDensity()
+{
+ const char *current_display = getenv("DISPLAY");
+
+ if (current_display != NULL) {
+ Display *x11display = XOpenDisplay(current_display);
+
+ if (x11display != NULL) {
+ /* try x direct */
+ float dpi_height = floor(
+ DisplayHeight(x11display, 0) /
+ (DisplayHeightMM(x11display, 0) *
+ 0.039370) +
+ 0.5);
+ float dpi_width = floor(
+ DisplayWidth(x11display, 0) /
+ (DisplayWidthMM(x11display, 0) *
+ 0.039370) +
+ 0.5);
+
+ XCloseDisplay(x11display);
+
+ return std::max(dpi_height, dpi_width) / 96.0;
+ }
+ }
+
+ /* return manually specified dpi */
+ return g_settings->getFloat("screen_dpi") / 96.0;
+}
+
+float RenderingEngine::getDisplayDensity()
+{
+ static float cached_display_density = calcDisplayDensity();
+ return cached_display_density;
+}
+
+#else // XORG_USED
+float RenderingEngine::getDisplayDensity()
+{
+ return g_settings->getFloat("screen_dpi") / 96.0;
+}
+#endif // XORG_USED
+
+v2u32 RenderingEngine::getDisplaySize()
+{
+ IrrlichtDevice *nulldevice = createDevice(video::EDT_NULL);
+
+ core::dimension2d<u32> deskres =
+ nulldevice->getVideoModeList()->getDesktopResolution();
+ nulldevice->drop();
+
+ return deskres;
+}
+#endif // __ANDROID__
diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h
new file mode 100644
index 000000000..40fbaa87d
--- /dev/null
+++ b/src/client/renderingengine.h
@@ -0,0 +1,185 @@
+/*
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include <vector>
+#include <string>
+#include "irrlichttypes_extrabloated.h"
+#include "debug.h"
+
+class ITextureSource;
+class Camera;
+class Client;
+class LocalPlayer;
+class Hud;
+class Minimap;
+
+class RenderingEngine
+{
+public:
+ RenderingEngine(IEventReceiver *eventReceiver);
+ ~RenderingEngine();
+
+ v2u32 getWindowSize() const;
+ void setResizable(bool resize);
+
+ video::IVideoDriver *getVideoDriver();
+
+ static const char *getVideoDriverName(irr::video::E_DRIVER_TYPE type);
+ static const char *getVideoDriverFriendlyName(irr::video::E_DRIVER_TYPE type);
+ static float getDisplayDensity();
+ static v2u32 getDisplaySize();
+
+ static void setXorgClassHint(const video::SExposedVideoData &video_data,
+ const std::string &name);
+ bool setWindowIcon();
+ bool setXorgWindowIconFromPath(const std::string &icon_file);
+ static bool print_video_modes();
+
+ static RenderingEngine *get_instance() { return s_singleton; }
+
+ static io::IFileSystem *get_filesystem()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->getFileSystem();
+ }
+
+ static video::IVideoDriver *get_video_driver()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->getVideoDriver();
+ }
+
+ static scene::IMeshCache *get_mesh_cache()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->getSceneManager()->getMeshCache();
+ }
+
+ static scene::ISceneManager *get_scene_manager()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->getSceneManager();
+ }
+
+ static irr::IrrlichtDevice *get_raw_device()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device;
+ }
+
+ static u32 get_timer_time()
+ {
+ sanity_check(s_singleton && s_singleton->m_device &&
+ s_singleton->m_device->getTimer());
+ return s_singleton->m_device->getTimer()->getTime();
+ }
+
+ static gui::IGUIEnvironment *get_gui_env()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->getGUIEnvironment();
+ }
+
+ inline static void draw_load_screen(const std::wstring &text,
+ gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
+ float dtime = 0, int percent = 0, bool clouds = true)
+ {
+ s_singleton->_draw_load_screen(
+ text, guienv, tsrc, dtime, percent, clouds);
+ }
+
+ inline static void draw_scene(Camera *camera, Client *client, LocalPlayer *player,
+ Hud *hud, Minimap *mapper, gui::IGUIEnvironment *guienv,
+ const v2u32 &screensize, const video::SColor &skycolor,
+ bool show_hud, bool show_minimap)
+ {
+ s_singleton->_draw_scene(camera, client, player, hud, mapper, guienv,
+ screensize, skycolor, show_hud, show_minimap);
+ }
+
+ static bool run()
+ {
+ sanity_check(s_singleton && s_singleton->m_device);
+ return s_singleton->m_device->run();
+ }
+
+ static std::vector<core::vector3d<u32>> getSupportedVideoModes();
+ static std::vector<irr::video::E_DRIVER_TYPE> getSupportedVideoDrivers();
+
+private:
+ enum parallax_sign
+ {
+ LEFT = -1,
+ RIGHT = 1,
+ EYECOUNT = 2
+ };
+
+ void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv,
+ ITextureSource *tsrc, float dtime = 0, int percent = 0,
+ bool clouds = true);
+
+ void _draw_scene(Camera *camera, Client *client, LocalPlayer *player, Hud *hud,
+ Minimap *mapper, gui::IGUIEnvironment *guienv,
+ const v2u32 &screensize, const video::SColor &skycolor,
+ bool show_hud, bool show_minimap);
+
+ void draw_anaglyph_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv);
+
+ void draw_interlaced_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ void draw_sidebyside_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ void draw_top_bottom_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ void draw_pageflip_3d_mode(Camera *camera, bool show_hud, Hud *hud,
+ const v2u32 &screensize, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ void draw_plain(Camera *camera, bool show_hud, Hud *hud, const v2u32 &screensize,
+ bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ void init_texture(const v2u32 &screensize, video::ITexture **texture,
+ const char *name);
+
+ video::ITexture *draw_image(const v2u32 &screensize, parallax_sign psign,
+ const irr::core::matrix4 &startMatrix,
+ const irr::core::vector3df &focusPoint, bool show_hud,
+ Camera *camera, Hud *hud, bool draw_wield_tool, Client *client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor);
+
+ video::ITexture *draw_hud(const v2u32 &screensize, bool show_hud, Hud *hud,
+ Client *client, bool draw_crosshair,
+ const video::SColor &skycolor, gui::IGUIEnvironment *guienv,
+ Camera *camera);
+
+ irr::IrrlichtDevice *m_device = nullptr;
+ static RenderingEngine *s_singleton;
+};
diff --git a/src/client/tile.cpp b/src/client/tile.cpp
index e47a40ea1..1bcbdc6f9 100644
--- a/src/client/tile.cpp
+++ b/src/client/tile.cpp
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "imagefilters.h"
#include "guiscalingfilter.h"
#include "nodedef.h"
+#include "renderingengine.h"
#ifdef __ANDROID__
@@ -198,8 +199,7 @@ public:
}
m_images.clear();
}
- void insert(const std::string &name, video::IImage *img,
- bool prefer_local, video::IVideoDriver *driver)
+ void insert(const std::string &name, video::IImage *img, bool prefer_local)
{
assert(img); // Pre-condition
// Remove old image
@@ -217,7 +217,8 @@ public:
if (prefer_local){
std::string path = getTexturePath(name);
if (path != ""){
- video::IImage *img2 = driver->createImageFromFile(path.c_str());
+ video::IImage *img2 = RenderingEngine::get_video_driver()->
+ createImageFromFile(path.c_str());
if (img2){
toadd = img2;
need_to_grab = false;
@@ -238,7 +239,7 @@ public:
return NULL;
}
// Primarily fetches from cache, secondarily tries to read from filesystem
- video::IImage* getOrLoad(const std::string &name, IrrlichtDevice *device)
+ video::IImage *getOrLoad(const std::string &name)
{
std::map<std::string, video::IImage*>::iterator n;
n = m_images.find(name);
@@ -246,7 +247,7 @@ public:
n->second->grab(); // Grab for caller
return n->second;
}
- video::IVideoDriver* driver = device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
std::string path = getTexturePath(name);
if (path == ""){
infostream<<"SourceImageCache::getOrLoad(): No path found for \""
@@ -274,7 +275,7 @@ private:
class TextureSource : public IWritableTextureSource
{
public:
- TextureSource(IrrlichtDevice *device);
+ TextureSource();
virtual ~TextureSource();
/*
@@ -343,12 +344,6 @@ public:
virtual Palette* getPalette(const std::string &name);
- // Returns a pointer to the irrlicht device
- virtual IrrlichtDevice* getDevice()
- {
- return m_device;
- }
-
bool isKnownSourceImage(const std::string &name)
{
bool is_known = false;
@@ -387,8 +382,6 @@ private:
// The id of the thread that is allowed to use irrlicht directly
std::thread::id m_main_thread;
- // The irrlicht device
- IrrlichtDevice *m_device;
// Cache of source images
// This should be only accessed from the main thread
@@ -435,16 +428,13 @@ private:
bool m_setting_anisotropic_filter;
};
-IWritableTextureSource* createTextureSource(IrrlichtDevice *device)
+IWritableTextureSource *createTextureSource()
{
- return new TextureSource(device);
+ return new TextureSource();
}
-TextureSource::TextureSource(IrrlichtDevice *device):
- m_device(device)
+TextureSource::TextureSource()
{
- assert(m_device); // Pre-condition
-
m_main_thread = std::this_thread::get_id();
// Add a NULL TextureInfo as the first index, named ""
@@ -461,7 +451,7 @@ TextureSource::TextureSource(IrrlichtDevice *device):
TextureSource::~TextureSource()
{
- video::IVideoDriver* driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
unsigned int textures_before = driver->getTextureCount();
@@ -622,7 +612,7 @@ u32 TextureSource::generateTexture(const std::string &name)
return 0;
}
- video::IVideoDriver *driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver);
video::IImage *img = generateImage(name);
@@ -773,7 +763,7 @@ void TextureSource::insertSourceImage(const std::string &name, video::IImage *im
sanity_check(std::this_thread::get_id() == m_main_thread);
- m_sourcecache.insert(name, img, true, m_device->getVideoDriver());
+ m_sourcecache.insert(name, img, true);
m_source_image_existence.set(name, true);
}
@@ -781,7 +771,7 @@ void TextureSource::rebuildImagesAndTextures()
{
MutexAutoLock lock(m_textureinfo_cache_mutex);
- video::IVideoDriver* driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver);
// Recreate textures
@@ -810,7 +800,7 @@ void TextureSource::rebuildImagesAndTextures()
video::ITexture* TextureSource::generateTextureFromMesh(
const TextureFromMeshParams &params)
{
- video::IVideoDriver *driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver);
#ifdef __ANDROID__
@@ -935,8 +925,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
}
#endif
- if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET) == false)
- {
+ if (!driver->queryFeature(video::EVDF_RENDER_TO_TARGET)) {
static bool warned = false;
if (!warned)
{
@@ -967,7 +956,7 @@ video::ITexture* TextureSource::generateTextureFromMesh(
}
// Get a scene manager
- scene::ISceneManager *smgr_main = m_device->getSceneManager();
+ scene::ISceneManager *smgr_main = RenderingEngine::get_scene_manager();
assert(smgr_main);
scene::ISceneManager *smgr = smgr_main->createNewSceneManager();
assert(smgr);
@@ -1065,10 +1054,6 @@ video::IImage* TextureSource::generateImage(const std::string &name)
baseimg = generateImage(name.substr(0, last_separator_pos));
}
-
- video::IVideoDriver* driver = m_device->getVideoDriver();
- sanity_check(driver);
-
/*
Parse out the last part of the name of the image and act
according to it
@@ -1196,13 +1181,13 @@ bool TextureSource::generateImagePart(std::string part_of_name,
video::IImage *& baseimg)
{
const char escape = '\\'; // same as in generateImage()
- video::IVideoDriver* driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
sanity_check(driver);
// Stuff starting with [ are special commands
if (part_of_name.size() == 0 || part_of_name[0] != '[')
{
- video::IImage *image = m_sourcecache.getOrLoad(part_of_name, m_device);
+ video::IImage *image = m_sourcecache.getOrLoad(part_of_name);
#ifdef __ANDROID__
image = Align2Npot2(image, driver);
#endif
@@ -1275,7 +1260,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
blit_with_alpha(image, baseimg, pos_from, pos_to, dim);
} else if (dim.Width * dim.Height < dim_dst.Width * dim_dst.Height) {
// Upscale overlying image
- video::IImage* scaled_image = m_device->getVideoDriver()->
+ video::IImage *scaled_image = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim_dst);
image->copyToScaling(scaled_image);
@@ -1283,7 +1268,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
scaled_image->drop();
} else {
// Upscale base image
- video::IImage* scaled_base = m_device->getVideoDriver()->
+ video::IImage *scaled_base = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim);
baseimg->copyToScaling(scaled_base);
baseimg->drop();
@@ -1333,7 +1318,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
horizontally tiled.
*/
video::IImage *img_crack = m_sourcecache.getOrLoad(
- "crack_anylength.png", m_device);
+ "crack_anylength.png");
if (img_crack) {
draw_crack(img_crack, baseimg,
@@ -1855,7 +1840,7 @@ bool TextureSource::generateImagePart(std::string part_of_name,
u32 height = stoi(sf.next(""));
core::dimension2d<u32> dim(width, height);
- video::IImage* image = m_device->getVideoDriver()->
+ video::IImage *image = RenderingEngine::get_video_driver()->
createImage(video::ECF_A8R8G8B8, dim);
baseimg->copyToScaling(image);
baseimg->drop();
@@ -2356,7 +2341,7 @@ video::ITexture* TextureSource::getNormalTexture(const std::string &name)
video::SColor TextureSource::getTextureAverageColor(const std::string &name)
{
- video::IVideoDriver *driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
video::SColor c(0, 0, 0, 0);
video::ITexture *texture = getTexture(name);
video::IImage *image = driver->createImage(texture,
@@ -2400,7 +2385,7 @@ video::ITexture *TextureSource::getShaderFlagsTexture(bool normalmap_present)
if (isKnownSourceImage(tname)) {
return getTexture(tname);
} else {
- video::IVideoDriver *driver = m_device->getVideoDriver();
+ video::IVideoDriver *driver = RenderingEngine::get_video_driver();
video::IImage *flags_image = driver->createImage(
video::ECF_A8R8G8B8, core::dimension2d<u32>(1, 1));
sanity_check(flags_image != NULL);
diff --git a/src/client/tile.h b/src/client/tile.h
index a810aa8e5..b4d615427 100644
--- a/src/client/tile.h
+++ b/src/client/tile.h
@@ -114,7 +114,6 @@ public:
* Should be called from the main thread.
*/
virtual Palette* getPalette(const std::string &name) = 0;
- virtual IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh(
const TextureFromMeshParams &params)=0;
@@ -133,7 +132,6 @@ public:
virtual video::ITexture* getTexture(u32 id)=0;
virtual video::ITexture* getTexture(
const std::string &name, u32 *id = nullptr)=0;
- virtual IrrlichtDevice* getDevice()=0;
virtual bool isKnownSourceImage(const std::string &name)=0;
virtual video::ITexture* generateTextureFromMesh(
const TextureFromMeshParams &params)=0;
@@ -146,7 +144,7 @@ public:
virtual video::ITexture *getShaderFlagsTexture(bool normalmap_present)=0;
};
-IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
+IWritableTextureSource *createTextureSource();
#ifdef __ANDROID__
video::IImage * Align2Npot2(video::IImage * image, video::IVideoDriver* driver);
@@ -302,7 +300,7 @@ struct TileSpec
for (int layer = 0; layer < MAX_TILE_LAYERS; layer++)
layers[layer] = TileLayer();
}
-
+
/*!
* Returns true if this tile can be merged with the other tile.
*/