2017-10-31 19:27:10 +01:00
|
|
|
/*
|
|
|
|
Minetest
|
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2018-02-15 21:19:34 +01:00
|
|
|
Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
|
2017-10-31 19:27:10 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sidebyside.h"
|
2018-01-20 14:09:58 +01:00
|
|
|
#include "client/hud.h"
|
2022-09-06 08:25:18 +02:00
|
|
|
#include "client/camera.h"
|
2017-10-31 19:27:10 +01:00
|
|
|
|
2022-09-06 08:25:18 +02:00
|
|
|
DrawImageStep::DrawImageStep(u8 texture_index, v2f _offset) :
|
|
|
|
texture_index(texture_index), offset(_offset)
|
|
|
|
{}
|
2017-10-31 19:27:10 +01:00
|
|
|
|
2022-09-06 08:25:18 +02:00
|
|
|
void DrawImageStep::setRenderSource(RenderSource *_source)
|
2017-10-31 19:27:10 +01:00
|
|
|
{
|
2022-09-06 08:25:18 +02:00
|
|
|
source = _source;
|
2017-10-31 19:27:10 +01:00
|
|
|
}
|
2022-09-06 08:25:18 +02:00
|
|
|
void DrawImageStep::setRenderTarget(RenderTarget *_target)
|
2017-10-31 19:27:10 +01:00
|
|
|
{
|
2022-09-06 08:25:18 +02:00
|
|
|
target = _target;
|
2017-10-31 19:27:10 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:25:18 +02:00
|
|
|
void DrawImageStep::run(PipelineContext &context)
|
2017-10-31 19:27:10 +01:00
|
|
|
{
|
2022-09-06 08:25:18 +02:00
|
|
|
if (target)
|
|
|
|
target->activate(context);
|
|
|
|
|
|
|
|
auto texture = source->getTexture(texture_index);
|
|
|
|
core::dimension2du output_size = context.device->getVideoDriver()->getScreenSize();
|
|
|
|
v2s32 pos(offset.X * output_size.Width, offset.Y * output_size.Height);
|
|
|
|
context.device->getVideoDriver()->draw2DImage(texture, pos);
|
2017-10-31 19:27:10 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 08:25:18 +02:00
|
|
|
void populateSideBySidePipeline(RenderPipeline *pipeline, Client *client, bool horizontal, bool flipped, v2f &virtual_size_scale)
|
2017-10-31 19:27:10 +01:00
|
|
|
{
|
2022-09-06 08:25:18 +02:00
|
|
|
static const u8 TEXTURE_LEFT = 0;
|
|
|
|
static const u8 TEXTURE_RIGHT = 1;
|
2017-10-31 19:27:10 +01:00
|
|
|
|
2022-09-06 08:25:18 +02:00
|
|
|
v2f offset;
|
|
|
|
if (horizontal) {
|
|
|
|
virtual_size_scale = v2f(1.0f, 0.5f);
|
|
|
|
offset = v2f(0.0f, 0.5f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
virtual_size_scale = v2f(0.5f, 1.0f);
|
|
|
|
offset = v2f(0.5f, 0.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureBuffer *buffer = pipeline->createOwned<TextureBuffer>();
|
|
|
|
buffer->setTexture(TEXTURE_LEFT, virtual_size_scale, "3d_render_left", video::ECF_A8R8G8B8);
|
|
|
|
buffer->setTexture(TEXTURE_RIGHT, virtual_size_scale, "3d_render_right", video::ECF_A8R8G8B8);
|
|
|
|
|
|
|
|
auto step3D = pipeline->own(create3DStage(client, virtual_size_scale));
|
|
|
|
|
|
|
|
// eyes
|
|
|
|
for (bool right : { false, true }) {
|
|
|
|
pipeline->addStep<OffsetCameraStep>(flipped ? !right : right);
|
|
|
|
auto output = pipeline->createOwned<TextureBufferOutput>(buffer, right ? TEXTURE_RIGHT : TEXTURE_LEFT);
|
|
|
|
pipeline->addStep<SetRenderTargetStep>(step3D, output);
|
|
|
|
pipeline->addStep(step3D);
|
2023-03-19 21:31:15 +01:00
|
|
|
pipeline->addStep<DrawWield>();
|
2022-09-06 08:25:18 +02:00
|
|
|
pipeline->addStep<MapPostFxStep>();
|
|
|
|
pipeline->addStep<DrawHUD>();
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline->addStep<OffsetCameraStep>(0.0f);
|
|
|
|
|
|
|
|
auto screen = pipeline->createOwned<ScreenTarget>();
|
|
|
|
|
|
|
|
for (bool right : { false, true }) {
|
|
|
|
auto step = pipeline->addStep<DrawImageStep>(
|
|
|
|
right ? TEXTURE_RIGHT : TEXTURE_LEFT,
|
|
|
|
right ? offset : v2f());
|
|
|
|
step->setRenderSource(buffer);
|
|
|
|
step->setRenderTarget(screen);
|
|
|
|
}
|
|
|
|
}
|