]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/render/plain.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / render / plain.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 "plain.h"
22 #include "settings.h"
23
24 inline u32 scaledown(u32 coef, u32 size)
25 {
26         return (size + coef - 1) / coef;
27 }
28
29 RenderingCorePlain::RenderingCorePlain(
30         IrrlichtDevice *_device, Client *_client, Hud *_hud)
31         : RenderingCore(_device, _client, _hud)
32 {
33         scale = g_settings->getU16("undersampling");
34 }
35
36 void RenderingCorePlain::initTextures()
37 {
38         if (scale <= 1)
39                 return;
40         v2u32 size{scaledown(scale, screensize.X), scaledown(scale, screensize.Y)};
41         lowres = driver->addRenderTargetTexture(
42                         size, "render_lowres", video::ECF_A8R8G8B8);
43 }
44
45 void RenderingCorePlain::clearTextures()
46 {
47         if (scale <= 1)
48                 return;
49         driver->removeTexture(lowres);
50 }
51
52 void RenderingCorePlain::beforeDraw()
53 {
54         if (scale <= 1)
55                 return;
56         driver->setRenderTarget(lowres, true, true, skycolor);
57 }
58
59 void RenderingCorePlain::upscale()
60 {
61         if (scale <= 1)
62                 return;
63         driver->setRenderTarget(0, true, true);
64         v2u32 size{scaledown(scale, screensize.X), scaledown(scale, screensize.Y)};
65         v2u32 dest_size{scale * size.X, scale * size.Y};
66         driver->draw2DImage(lowres, core::rect<s32>(0, 0, dest_size.X, dest_size.Y),
67                         core::rect<s32>(0, 0, size.X, size.Y));
68 }
69
70 void RenderingCorePlain::drawAll()
71 {
72         draw3D();
73         drawPostFx();
74         upscale();
75         drawHUD();
76 }