[CSM] Add basic HUD manipulation. (#6067)
[oweals/minetest.git] / src / client / render / sidebyside.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachesky Vitaly <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 "sidebyside.h"
22 #include <ICameraSceneNode.h>
23 #include "client/hud.h"
24
25 RenderingCoreSideBySide::RenderingCoreSideBySide(
26         IrrlichtDevice *_device, Client *_client, Hud *_hud, bool _horizontal)
27         : RenderingCoreStereo(_device, _client, _hud), horizontal(_horizontal)
28 {
29 }
30
31 void RenderingCoreSideBySide::initTextures()
32 {
33         if (horizontal) {
34                 image_size = {screensize.X, screensize.Y / 2};
35                 rpos = v2s32(0, screensize.Y / 2);
36         } else {
37                 image_size = {screensize.X / 2, screensize.Y};
38                 rpos = v2s32(screensize.X / 2, 0);
39         }
40         virtual_size = image_size;
41         left = driver->addRenderTargetTexture(
42                         image_size, "3d_render_left", video::ECF_A8R8G8B8);
43         right = driver->addRenderTargetTexture(
44                         image_size, "3d_render_right", video::ECF_A8R8G8B8);
45 }
46
47 void RenderingCoreSideBySide::clearTextures()
48 {
49         driver->removeTexture(left);
50         driver->removeTexture(right);
51 }
52
53 void RenderingCoreSideBySide::drawAll()
54 {
55         driver->OnResize(image_size); // HACK to make GUI smaller
56         renderBothImages();
57         driver->OnResize(screensize);
58         driver->draw2DImage(left, {});
59         driver->draw2DImage(right, rpos);
60 }
61
62 void RenderingCoreSideBySide::useEye(bool _right)
63 {
64         driver->setRenderTarget(_right ? right : left, true, true, skycolor);
65         RenderingCoreStereo::useEye(_right);
66 }
67
68 void RenderingCoreSideBySide::resetEye()
69 {
70         hud->resizeHotbar();
71         drawHUD();
72         driver->setRenderTarget(nullptr, false, false, skycolor);
73         RenderingCoreStereo::resetEye();
74 }