]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/render/interlaced.cpp
Revert "Make Lint Happy"
[dragonfireclient.git] / src / client / render / interlaced.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 "interlaced.h"
22 #include "client/client.h"
23 #include "client/shader.h"
24 #include "client/tile.h"
25
26 RenderingCoreInterlaced::RenderingCoreInterlaced(
27         IrrlichtDevice *_device, Client *_client, Hud *_hud)
28         : RenderingCoreStereo(_device, _client, _hud)
29 {
30         initMaterial();
31 }
32
33 void RenderingCoreInterlaced::initMaterial()
34 {
35         IShaderSource *s = client->getShaderSource();
36         mat.UseMipMaps = false;
37         mat.ZBuffer = false;
38         mat.ZWriteEnable = false;
39         u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC, 0);
40         mat.MaterialType = s->getShaderInfo(shader).material;
41         for (int k = 0; k < 3; ++k) {
42                 mat.TextureLayer[k].AnisotropicFilter = false;
43                 mat.TextureLayer[k].BilinearFilter = false;
44                 mat.TextureLayer[k].TrilinearFilter = false;
45                 mat.TextureLayer[k].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
46                 mat.TextureLayer[k].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
47         }
48 }
49
50 void RenderingCoreInterlaced::initTextures()
51 {
52         v2u32 image_size{screensize.X, screensize.Y / 2};
53         left = driver->addRenderTargetTexture(
54                         image_size, "3d_render_left", video::ECF_A8R8G8B8);
55         right = driver->addRenderTargetTexture(
56                         image_size, "3d_render_right", video::ECF_A8R8G8B8);
57         mask = driver->addTexture(screensize, "3d_render_mask", video::ECF_A8R8G8B8);
58         initMask();
59         mat.TextureLayer[0].Texture = left;
60         mat.TextureLayer[1].Texture = right;
61         mat.TextureLayer[2].Texture = mask;
62 }
63
64 void RenderingCoreInterlaced::clearTextures()
65 {
66         driver->removeTexture(left);
67         driver->removeTexture(right);
68         driver->removeTexture(mask);
69 }
70
71 void RenderingCoreInterlaced::initMask()
72 {
73         u8 *data = reinterpret_cast<u8 *>(mask->lock());
74         for (u32 j = 0; j < screensize.Y; j++) {
75                 u8 val = j % 2 ? 0xff : 0x00;
76                 memset(data, val, 4 * screensize.X);
77                 data += 4 * screensize.X;
78         }
79         mask->unlock();
80 }
81
82 void RenderingCoreInterlaced::drawAll()
83 {
84         renderBothImages();
85         merge();
86         drawHUD();
87 }
88
89 void RenderingCoreInterlaced::merge()
90 {
91         static const video::S3DVertex vertices[4] = {
92                         video::S3DVertex(1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
93                                         video::SColor(255, 0, 255, 255), 1.0, 0.0),
94                         video::S3DVertex(-1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
95                                         video::SColor(255, 255, 0, 255), 0.0, 0.0),
96                         video::S3DVertex(-1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
97                                         video::SColor(255, 255, 255, 0), 0.0, 1.0),
98                         video::S3DVertex(1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
99                                         video::SColor(255, 255, 255, 255), 1.0, 1.0),
100         };
101         static const u16 indices[6] = {0, 1, 2, 2, 3, 0};
102         driver->setMaterial(mat);
103         driver->drawVertexPrimitiveList(&vertices, 4, &indices, 2);
104 }
105
106 void RenderingCoreInterlaced::useEye(bool _right)
107 {
108         driver->setRenderTarget(_right ? right : left, true, true, skycolor);
109         RenderingCoreStereo::useEye(_right);
110 }
111
112 void RenderingCoreInterlaced::resetEye()
113 {
114         driver->setRenderTarget(nullptr, false, false, skycolor);
115         RenderingCoreStereo::resetEye();
116 }