3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
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.
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.
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.
21 #include "interlaced.h"
22 #include "client/client.h"
23 #include "client/shader.h"
24 #include "client/tile.h"
26 RenderingCoreInterlaced::RenderingCoreInterlaced(
27 IrrlichtDevice *_device, Client *_client, Hud *_hud)
28 : RenderingCoreStereo(_device, _client, _hud)
33 void RenderingCoreInterlaced::initMaterial()
35 IShaderSource *s = client->getShaderSource();
36 mat.UseMipMaps = false;
38 #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8
39 mat.ZWriteEnable = video::EZW_OFF;
41 mat.ZWriteEnable = false;
43 u32 shader = s->getShader("3d_interlaced_merge", TILE_MATERIAL_BASIC);
44 mat.MaterialType = s->getShaderInfo(shader).material;
45 for (int k = 0; k < 3; ++k) {
46 mat.TextureLayer[k].AnisotropicFilter = false;
47 mat.TextureLayer[k].BilinearFilter = false;
48 mat.TextureLayer[k].TrilinearFilter = false;
49 mat.TextureLayer[k].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
50 mat.TextureLayer[k].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
54 void RenderingCoreInterlaced::initTextures()
56 v2u32 image_size{screensize.X, screensize.Y / 2};
57 left = driver->addRenderTargetTexture(
58 image_size, "3d_render_left", video::ECF_A8R8G8B8);
59 right = driver->addRenderTargetTexture(
60 image_size, "3d_render_right", video::ECF_A8R8G8B8);
61 mask = driver->addTexture(screensize, "3d_render_mask", video::ECF_A8R8G8B8);
63 mat.TextureLayer[0].Texture = left;
64 mat.TextureLayer[1].Texture = right;
65 mat.TextureLayer[2].Texture = mask;
68 void RenderingCoreInterlaced::clearTextures()
70 driver->removeTexture(left);
71 driver->removeTexture(right);
72 driver->removeTexture(mask);
75 void RenderingCoreInterlaced::initMask()
77 u8 *data = reinterpret_cast<u8 *>(mask->lock());
78 for (u32 j = 0; j < screensize.Y; j++) {
79 u8 val = j % 2 ? 0xff : 0x00;
80 memset(data, val, 4 * screensize.X);
81 data += 4 * screensize.X;
86 void RenderingCoreInterlaced::drawAll()
93 void RenderingCoreInterlaced::merge()
95 static const video::S3DVertex vertices[4] = {
96 video::S3DVertex(1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
97 video::SColor(255, 0, 255, 255), 1.0, 0.0),
98 video::S3DVertex(-1.0, -1.0, 0.0, 0.0, 0.0, -1.0,
99 video::SColor(255, 255, 0, 255), 0.0, 0.0),
100 video::S3DVertex(-1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
101 video::SColor(255, 255, 255, 0), 0.0, 1.0),
102 video::S3DVertex(1.0, 1.0, 0.0, 0.0, 0.0, -1.0,
103 video::SColor(255, 255, 255, 255), 1.0, 1.0),
105 static const u16 indices[6] = {0, 1, 2, 2, 3, 0};
106 driver->setMaterial(mat);
107 driver->drawVertexPrimitiveList(&vertices, 4, &indices, 2);
110 void RenderingCoreInterlaced::useEye(bool _right)
112 driver->setRenderTarget(_right ? right : left, true, true, skycolor);
113 RenderingCoreStereo::useEye(_right);
116 void RenderingCoreInterlaced::resetEye()
118 driver->setRenderTarget(nullptr, false, false, skycolor);
119 RenderingCoreStereo::resetEye();