]> git.lizzy.rs Git - minetest.git/blob - src/client/render/core.cpp
Fix scaled world-aligned textures being aligned inconsistently for non-normal drawtypes
[minetest.git] / src / client / render / core.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
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 #include "core.h"
22 #include "client/camera.h"
23 #include "client/client.h"
24 #include "client/clientmap.h"
25 #include "client/hud.h"
26 #include "client/minimap.h"
27 #include "client/shadows/dynamicshadowsrender.h"
28
29 RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
30         : device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
31         guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
32         mapper(client->getMinimap()), hud(_hud),
33         shadow_renderer(nullptr)
34 {
35         screensize = driver->getScreenSize();
36         virtual_size = screensize;
37
38         if (g_settings->getBool("enable_shaders") &&
39                         g_settings->getBool("enable_dynamic_shadows")) {
40                 shadow_renderer = new ShadowRenderer(device, client);
41         }
42 }
43
44 RenderingCore::~RenderingCore()
45 {
46         clearTextures();
47         delete shadow_renderer;
48 }
49
50 void RenderingCore::initialize()
51 {
52         // have to be called late as the VMT is not ready in the constructor:
53         initTextures();
54         if (shadow_renderer)
55                 shadow_renderer->initialize();
56 }
57
58 void RenderingCore::updateScreenSize()
59 {
60         virtual_size = screensize;
61         clearTextures();
62         initTextures();
63 }
64
65 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
66                 bool _draw_wield_tool, bool _draw_crosshair)
67 {
68         v2u32 ss = driver->getScreenSize();
69         if (screensize != ss) {
70                 screensize = ss;
71                 updateScreenSize();
72         }
73         skycolor = _skycolor;
74         show_hud = _show_hud;
75         show_minimap = _show_minimap;
76         draw_wield_tool = _draw_wield_tool;
77         draw_crosshair = _draw_crosshair;
78
79         if (shadow_renderer)
80                 shadow_renderer->update();
81
82         beforeDraw();
83         drawAll();
84 }
85
86 void RenderingCore::draw3D()
87 {
88         smgr->drawAll();
89         if (shadow_renderer)
90                 shadow_renderer->drawDebug();
91
92         driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
93         if (!show_hud)
94                 return;
95         hud->drawBlockBounds();
96         hud->drawSelectionMesh();
97         if (draw_wield_tool)
98                 camera->drawWieldedTool();
99 }
100
101 void RenderingCore::drawHUD()
102 {
103         if (show_hud) {
104                 if (draw_crosshair)
105                         hud->drawCrosshair();
106         
107                 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
108                 hud->drawLuaElements(camera->getOffset());
109                 camera->drawNametags();
110                 if (mapper && show_minimap)
111                         mapper->drawMinimap();
112         }
113         guienv->drawAll();
114 }
115
116 void RenderingCore::drawPostFx()
117 {
118         client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
119 }