Skip to content

Commit 2884196

Browse files
numberZeronerzhul
authored andcommittedOct 31, 2017
Rewrite rendering engine (#6253)
* Clean draw_*() arguments * Split rendering core * Add anaglyph 3D * Interlaced 3D * Drop obsolete methods
1 parent 65c5539 commit 2884196

25 files changed

+1008
-618
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ fall_bobbing_amount (Fall bobbing factor) float 0.0
608608
# - topbottom: split screen top/bottom.
609609
# - sidebyside: split screen side by side.
610610
# - pageflip: quadbuffer based 3d.
611+
# Note that the interlaced mode requires shaders to be enabled.
611612
3d_mode (3D mode) enum none none,anaglyph,interlaced,topbottom,sidebyside,pageflip
612613

613614
# In-game chat console height, between 0.1 (10%) and 1.0 (100%).
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
uniform sampler2D baseTexture;
2+
uniform sampler2D normalTexture;
3+
uniform sampler2D textureFlags;
4+
5+
#define leftImage baseTexture
6+
#define rightImage normalTexture
7+
#define maskImage textureFlags
8+
9+
void main(void)
10+
{
11+
vec2 uv = gl_TexCoord[0].st;
12+
vec4 left = texture2D(leftImage, uv).rgba;
13+
vec4 right = texture2D(rightImage, uv).rgba;
14+
vec4 mask = texture2D(maskImage, uv).rgba;
15+
vec4 color;
16+
if (mask.r > 0.5)
17+
color = right;
18+
else
19+
color = left;
20+
gl_FragColor = color;
21+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void main(void)
2+
{
3+
gl_TexCoord[0] = gl_MultiTexCoord0;
4+
gl_Position = gl_Vertex;
5+
gl_FrontColor = gl_BackColor = gl_Color;
6+
}

Diff for: ‎minetest.conf.example

+1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@
700700
# - topbottom: split screen top/bottom.
701701
# - sidebyside: split screen side by side.
702702
# - pageflip: quadbuffer based 3d.
703+
# Note that the interlaced mode requires shaders to be enabled.
703704
# type: enum values: none, anaglyph, interlaced, topbottom, sidebyside, pageflip
704705
# 3d_mode = none
705706

Diff for: ‎src/client/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
set(client_SRCS
2+
${CMAKE_CURRENT_SOURCE_DIR}/render/anaglyph.cpp
3+
${CMAKE_CURRENT_SOURCE_DIR}/render/core.cpp
4+
${CMAKE_CURRENT_SOURCE_DIR}/render/factory.cpp
5+
${CMAKE_CURRENT_SOURCE_DIR}/render/interlaced.cpp
6+
${CMAKE_CURRENT_SOURCE_DIR}/render/pageflip.cpp
7+
${CMAKE_CURRENT_SOURCE_DIR}/render/plain.cpp
8+
${CMAKE_CURRENT_SOURCE_DIR}/render/sidebyside.cpp
9+
${CMAKE_CURRENT_SOURCE_DIR}/render/stereo.cpp
210
${CMAKE_CURRENT_SOURCE_DIR}/renderingengine.cpp
311
${CMAKE_CURRENT_SOURCE_DIR}/clientlauncher.cpp
412
${CMAKE_CURRENT_SOURCE_DIR}/inputhandler.cpp
513
${CMAKE_CURRENT_SOURCE_DIR}/tile.cpp
614
${CMAKE_CURRENT_SOURCE_DIR}/joystick_controller.cpp
715
PARENT_SCOPE
816
)
9-

Diff for: ‎src/client/render/anaglyph.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 "anaglyph.h"
22+
23+
void RenderingCoreAnaglyph::drawAll()
24+
{
25+
renderBothImages();
26+
drawPostFx();
27+
drawHUD();
28+
}
29+
30+
void RenderingCoreAnaglyph::setupMaterial(int color_mask)
31+
{
32+
video::SOverrideMaterial &mat = driver->getOverrideMaterial();
33+
mat.Material.ColorMask = color_mask;
34+
mat.EnableFlags = video::EMF_COLOR_MASK;
35+
mat.EnablePasses = scene::ESNRP_SKY_BOX | scene::ESNRP_SOLID |
36+
scene::ESNRP_TRANSPARENT | scene::ESNRP_TRANSPARENT_EFFECT |
37+
scene::ESNRP_SHADOW;
38+
}
39+
40+
void RenderingCoreAnaglyph::useEye(bool right)
41+
{
42+
RenderingCoreStereo::useEye(right);
43+
driver->clearZBuffer();
44+
setupMaterial(right ? video::ECP_GREEN | video::ECP_BLUE : video::ECP_RED);
45+
}
46+
47+
void RenderingCoreAnaglyph::resetEye()
48+
{
49+
setupMaterial(video::ECP_ALL);
50+
RenderingCoreStereo::resetEye();
51+
}

Diff for: ‎src/client/render/anaglyph.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#pragma once
22+
#include "stereo.h"
23+
24+
class RenderingCoreAnaglyph : public RenderingCoreStereo
25+
{
26+
protected:
27+
void setupMaterial(int color_mask);
28+
void useEye(bool right) override;
29+
void resetEye() override;
30+
31+
public:
32+
using RenderingCoreStereo::RenderingCoreStereo;
33+
void drawAll() override;
34+
};

Diff for: ‎src/client/render/core.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 "core.h"
22+
#include "camera.h"
23+
#include "client.h"
24+
#include "clientmap.h"
25+
#include "hud.h"
26+
#include "minimap.h"
27+
28+
RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
29+
: device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
30+
guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
31+
mapper(client->getMinimap()), hud(_hud)
32+
{
33+
screensize = driver->getScreenSize();
34+
virtual_size = screensize;
35+
}
36+
37+
RenderingCore::~RenderingCore()
38+
{
39+
clearTextures();
40+
}
41+
42+
void RenderingCore::initialize()
43+
{
44+
// have to be called late as the VMT is not ready in the constructor:
45+
initTextures();
46+
}
47+
48+
void RenderingCore::updateScreenSize()
49+
{
50+
virtual_size = screensize;
51+
clearTextures();
52+
initTextures();
53+
}
54+
55+
void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
56+
bool _draw_wield_tool, bool _draw_crosshair)
57+
{
58+
v2u32 ss = driver->getScreenSize();
59+
if (screensize != ss) {
60+
screensize = ss;
61+
updateScreenSize();
62+
}
63+
skycolor = _skycolor;
64+
show_hud = _show_hud;
65+
show_minimap = _show_minimap;
66+
draw_wield_tool = _draw_wield_tool;
67+
draw_crosshair = _draw_crosshair;
68+
69+
beforeDraw();
70+
drawAll();
71+
}
72+
73+
void RenderingCore::draw3D()
74+
{
75+
smgr->drawAll();
76+
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
77+
if (!show_hud)
78+
return;
79+
hud->drawSelectionMesh();
80+
if (draw_wield_tool)
81+
camera->drawWieldedTool();
82+
}
83+
84+
void RenderingCore::drawHUD()
85+
{
86+
if (show_hud) {
87+
if (draw_crosshair)
88+
hud->drawCrosshair();
89+
hud->drawHotbar(client->getPlayerItem());
90+
hud->drawLuaElements(camera->getOffset());
91+
camera->drawNametags();
92+
if (mapper && show_minimap)
93+
mapper->drawMinimap();
94+
}
95+
guienv->drawAll();
96+
}
97+
98+
void RenderingCore::drawPostFx()
99+
{
100+
client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());
101+
}

Diff for: ‎src/client/render/core.h

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
#pragma once
22+
#include "irrlichttypes_extrabloated.h"
23+
24+
class Camera;
25+
class Client;
26+
class Hud;
27+
class Minimap;
28+
29+
class RenderingCore
30+
{
31+
protected:
32+
v2u32 screensize;
33+
v2u32 virtual_size;
34+
video::SColor skycolor;
35+
bool show_hud;
36+
bool show_minimap;
37+
bool draw_wield_tool;
38+
bool draw_crosshair;
39+
40+
IrrlichtDevice *device;
41+
video::IVideoDriver *driver;
42+
scene::ISceneManager *smgr;
43+
gui::IGUIEnvironment *guienv;
44+
45+
Client *client;
46+
Camera *camera;
47+
Minimap *mapper;
48+
Hud *hud;
49+
50+
void updateScreenSize();
51+
virtual void initTextures() {}
52+
virtual void clearTextures() {}
53+
54+
virtual void beforeDraw() {}
55+
virtual void drawAll() = 0;
56+
57+
void draw3D();
58+
void drawHUD();
59+
void drawPostFx();
60+
61+
public:
62+
RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud);
63+
RenderingCore(const RenderingCore &) = delete;
64+
RenderingCore(RenderingCore &&) = delete;
65+
virtual ~RenderingCore();
66+
67+
RenderingCore &operator=(const RenderingCore &) = delete;
68+
RenderingCore &operator=(RenderingCore &&) = delete;
69+
70+
void initialize();
71+
void draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
72+
bool _draw_wield_tool, bool _draw_crosshair);
73+
74+
inline v2u32 getVirtualSize() const { return virtual_size; }
75+
};

Diff for: ‎src/client/render/factory.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 "factory.h"
22+
#include <stdexcept>
23+
#include "plain.h"
24+
#include "anaglyph.h"
25+
#include "interlaced.h"
26+
#include "pageflip.h"
27+
#include "sidebyside.h"
28+
29+
RenderingCore *createRenderingCore(const std::string &stereo_mode, IrrlichtDevice *device,
30+
Client *client, Hud *hud)
31+
{
32+
if (stereo_mode == "none")
33+
return new RenderingCorePlain(device, client, hud);
34+
if (stereo_mode == "anaglyph")
35+
return new RenderingCoreAnaglyph(device, client, hud);
36+
if (stereo_mode == "interlaced")
37+
return new RenderingCoreInterlaced(device, client, hud);
38+
if (stereo_mode == "pageflip")
39+
return new RenderingCorePageflip(device, client, hud);
40+
if (stereo_mode == "sidebyside")
41+
return new RenderingCoreSideBySide(device, client, hud);
42+
if (stereo_mode == "topbottom")
43+
return new RenderingCoreSideBySide(device, client, hud, true);
44+
throw std::invalid_argument("Invalid rendering mode: " + stereo_mode);
45+
}

Diff for: ‎src/client/render/factory.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 <string>
22+
#include "core.h"
23+
24+
RenderingCore *createRenderingCore(const std::string &stereo_mode, IrrlichtDevice *device,
25+
Client *client, Hud *hud);

0 commit comments

Comments
 (0)
Please sign in to comment.