3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachesky Vitaly <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"
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 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;
50 void RenderingCoreInterlaced::initTextures()
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);
59 mat.TextureLayer[0].Texture = left;
60 mat.TextureLayer[1].Texture = right;
61 mat.TextureLayer[2].Texture = mask;
64 void RenderingCoreInterlaced::clearTextures()
66 driver->removeTexture(left);
67 driver->removeTexture(right);
68 driver->removeTexture(mask);
71 void RenderingCoreInterlaced::initMask()
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;
82 void RenderingCoreInterlaced::drawAll()
89 void RenderingCoreInterlaced::merge()
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),
101 static const u16 indices[6] = {0, 1, 2, 2, 3, 0};
102 driver->setMaterial(mat);
103 driver->drawVertexPrimitiveList(&vertices, 4, &indices, 2);
106 void RenderingCoreInterlaced::useEye(bool _right)
108 driver->setRenderTarget(_right ? right : left, true, true, skycolor);
109 RenderingCoreStereo::useEye(_right);
112 void RenderingCoreInterlaced::resetEye()
114 driver->setRenderTarget(nullptr, false, false, skycolor);
115 RenderingCoreStereo::resetEye();