Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
pipeline.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2022 x2048, Dmitry Kostenko <codeforsmile@gmail.com>
4#pragma once
5
7#include <IrrlichtDevice.h> // used in all render/*.cpp
8#include <IVideoDriver.h> // used in all render/*.cpp
9
10#include <vector>
11#include <memory>
12#include <string>
13
14class RenderSource;
15class RenderTarget;
16class RenderStep;
17class Client;
18class Hud;
19class ShadowRenderer;
20
21namespace irr::video
22{
23 class IRenderTarget;
24}
25
27{
28 PipelineContext(IrrlichtDevice *_device, Client *_client, Hud *_hud, ShadowRenderer *_shadow_renderer, video::SColor _color, v2u32 _target_size)
29 : device(_device), client(_client), hud(_hud), shadow_renderer(_shadow_renderer), clear_color(_color), target_size(_target_size)
30 {
31 }
32
33 IrrlichtDevice *device;
37 video::SColor clear_color;
39
40 bool show_hud {true};
41 bool draw_wield_tool {true};
42 bool draw_crosshair {true};
43};
44
50{
51public:
52 virtual ~RenderPipelineObject() = default;
53 virtual void reset(PipelineContext &context) {}
54};
55
59class RenderSource : virtual public RenderPipelineObject
60{
61public:
65 virtual u8 getTextureCount() = 0;
66
71 virtual video::ITexture *getTexture(u8 index) = 0;
72};
73
77class RenderTarget : virtual public RenderPipelineObject
78{
79public:
84 virtual void activate(PipelineContext &context)
85 {
86 m_clear = false;
87 }
88
92 virtual void reset(PipelineContext &context) override
93 {
94 m_clear = true;
95 }
96
97protected:
98 bool m_clear {true};
99};
100
107{
108public:
109 virtual ~TextureBuffer() override;
110
120 void setTexture(u8 index, core::dimension2du size, const std::string& name, video::ECOLOR_FORMAT format, bool clear = false);
121
130 void setTexture(u8 index, v2f scale_factor, const std::string& name, video::ECOLOR_FORMAT format, bool clear = false);
131
132 virtual u8 getTextureCount() override { return m_textures.size(); }
133 virtual video::ITexture *getTexture(u8 index) override;
134 virtual void reset(PipelineContext &context) override;
135 void swapTextures(u8 texture_a, u8 texture_b);
136private:
137 static const u8 NO_DEPTH_TEXTURE = 255;
138
140 {
141 bool valid { false };
142 bool fixed_size { false };
143 bool dirty { false };
144 bool clear { false };
146 core::dimension2du size;
147 std::string name;
148 video::ECOLOR_FORMAT format;
149 };
150
159 bool ensureTexture(video::ITexture **textureSlot, const TextureDefinition& definition, PipelineContext &context);
160
161 video::IVideoDriver *m_driver { nullptr };
162 std::vector<TextureDefinition> m_definitions;
163 core::array<video::ITexture *> m_textures;
164};
165
170{
171public:
172 TextureBufferOutput(TextureBuffer *buffer, u8 texture_index);
173 TextureBufferOutput(TextureBuffer *buffer, const std::vector<u8> &texture_map);
175 virtual ~TextureBufferOutput() override;
176 void activate(PipelineContext &context) override;
177private:
178 static const u8 NO_DEPTH_TEXTURE = 255;
179
181 std::vector<u8> texture_map;
183 video::IRenderTarget* render_target { nullptr };
184 video::IVideoDriver* driver { nullptr };
185};
186
193{
194public:
196 : m_source(source)
197 {}
198
205 void setMapping(u8 index, u8 target_index)
206 {
207 if (index >= m_mappings.size()) {
208 u8 start = m_mappings.size();
209 m_mappings.resize(index);
210 for (u8 i = start; i < m_mappings.size(); ++i)
211 m_mappings[i] = i;
212 }
213
214 m_mappings[index] = target_index;
215 }
216
217 virtual u8 getTextureCount() override
218 {
219 return m_mappings.size();
220 }
221
222 virtual video::ITexture *getTexture(u8 index) override
223 {
224 if (index < m_mappings.size())
225 index = m_mappings[index];
226
227 return m_source->getTexture(index);
228 }
229public:
231 std::vector<u8> m_mappings;
232};
233
235{
236public:
237 bool isConfigured() { return upstream != nullptr; }
238 void setRenderSource(RenderSource *value) { upstream = value; }
239
243 virtual u8 getTextureCount() override;
244
249 virtual video::ITexture *getTexture(u8 index) override;
250private:
251 RenderSource *upstream { nullptr };
252};
253
258{
259public:
260 virtual void activate(PipelineContext &context) override;
261 virtual void reset(PipelineContext &context) override;
262private:
263 core::dimension2du size;
264};
265
267{
268public:
269 bool isConfigured() { return upstream != nullptr; }
270 void setRenderTarget(RenderTarget *value) { upstream = value; }
271 virtual void activate(PipelineContext &context) override;
272private:
273 RenderTarget *upstream { nullptr };
274};
275
279class RenderStep : virtual public RenderPipelineObject
280{
281public:
287 virtual void setRenderSource(RenderSource *source) = 0;
288
294 virtual void setRenderTarget(RenderTarget *target) = 0;
295
299 virtual void run(PipelineContext &context) = 0;
300};
301
306{
307public:
308 virtual void setRenderSource(RenderSource *source) override {}
309 virtual void setRenderTarget(RenderTarget *target) override {}
310 virtual void reset(PipelineContext &) override {}
311};
312
319{
320public:
322 virtual void run(PipelineContext &context) override;
323private:
326};
327
333{
334public:
336 virtual void run(PipelineContext &context) override;
337private:
341};
342
349{
350public:
357 {
358 m_pipeline.push_back(step);
359 return step;
360 }
361
370 template<typename T>
371 T *own(std::unique_ptr<T> &&object)
372 {
373 T* result = object.release();
374 m_objects.push_back(std::unique_ptr<RenderPipelineObject>(result));
375 return result;
376 }
377
386 template<typename T, typename... Args>
387 T *createOwned(Args&&... args) {
388 return own(std::make_unique<T>(std::forward<Args>(args)...));
389 }
390
400 template<typename T, typename... Args>
401 T *addStep(Args&&... args) {
402 T* result = own(std::make_unique<T>(std::forward<Args>(args)...));
403 addStep(result);
404 return result;
405 }
406
409
410 v2f getScale() { return scale; }
411 void setScale(v2f value) { scale = value; }
412
413 virtual void reset(PipelineContext &context) override {}
414 virtual void run(PipelineContext &context) override;
415
416 virtual void setRenderSource(RenderSource *source) override;
417 virtual void setRenderTarget(RenderTarget *target) override;
418private:
419 std::vector<RenderStep *> m_pipeline;
420 std::vector< std::unique_ptr<RenderPipelineObject> > m_objects;
423 v2f scale { 1.0f, 1.0f };
424};
Definition client.h:105
Definition pipeline.h:235
bool isConfigured()
Definition pipeline.h:237
void setRenderSource(RenderSource *value)
Definition pipeline.h:238
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.cpp:199
RenderSource * upstream
Definition pipeline.h:251
virtual video::ITexture * getTexture(u8 index) override
Get a texture by index.
Definition pipeline.cpp:205
Definition pipeline.h:267
virtual void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:219
RenderTarget * upstream
Definition pipeline.h:273
bool isConfigured()
Definition pipeline.h:269
void setRenderTarget(RenderTarget *value)
Definition pipeline.h:270
Definition hud.h:35
Allows remapping texture indicies in another RenderSource.
Definition pipeline.h:193
void setMapping(u8 index, u8 target_index)
Maps texture index to a different index in the dependent source.
Definition pipeline.h:205
std::vector< u8 > m_mappings
Definition pipeline.h:231
virtual video::ITexture * getTexture(u8 index) override
Get a texture by index.
Definition pipeline.h:222
RenderSource * m_source
Definition pipeline.h:230
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.h:217
RemappingSource(RenderSource *source)
Definition pipeline.h:195
Base object that can be owned by RenderPipeline.
Definition pipeline.h:50
virtual void reset(PipelineContext &context)
Definition pipeline.h:53
virtual ~RenderPipelineObject()=default
Render Pipeline provides a flexible way to execute rendering steps in the engine.
Definition pipeline.h:349
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:262
DynamicTarget m_output
Definition pipeline.h:422
RenderTarget * getOutput()
Definition pipeline.cpp:257
virtual void setRenderTarget(RenderTarget *target) override
Assigned render target to this step.
Definition pipeline.cpp:281
v2f getScale()
Definition pipeline.h:410
void setScale(v2f value)
Definition pipeline.h:411
std::vector< std::unique_ptr< RenderPipelineObject > > m_objects
Definition pipeline.h:420
virtual void setRenderSource(RenderSource *source) override
Assigns render source to this step.
Definition pipeline.cpp:276
RenderSource * getInput()
Definition pipeline.cpp:252
DynamicSource m_input
Definition pipeline.h:421
T * addStep(Args &&... args)
Create and add a step managed by the pipeline and return a pointer to the step for further configurat...
Definition pipeline.h:401
virtual void reset(PipelineContext &context) override
Definition pipeline.h:413
v2f scale
Definition pipeline.h:423
RenderStep * addStep(RenderStep *step)
Add a step to the end of the pipeline.
Definition pipeline.h:356
std::vector< RenderStep * > m_pipeline
Definition pipeline.h:419
T * createOwned(Args &&... args)
Create a new object that will be managed by the pipeline.
Definition pipeline.h:387
T * own(std::unique_ptr< T > &&object)
Capture ownership of a dynamically created.
Definition pipeline.h:371
Represents a source of rendering information such as textures.
Definition pipeline.h:60
virtual u8 getTextureCount()=0
Return the number of textures in the source.
virtual video::ITexture * getTexture(u8 index)=0
Get a texture by index.
Base class for rendering steps in the pipeline.
Definition pipeline.h:280
virtual void run(PipelineContext &context)=0
Runs the step.
virtual void setRenderSource(RenderSource *source)=0
Assigns render source to this step.
virtual void setRenderTarget(RenderTarget *target)=0
Assigned render target to this step.
Represents a render target (screen or framebuffer)
Definition pipeline.h:78
bool m_clear
Definition pipeline.h:98
virtual void activate(PipelineContext &context)
Activate the render target and configure OpenGL state for the output.
Definition pipeline.h:84
virtual void reset(PipelineContext &context) override
Resets the state of the object for the next pipeline iteration.
Definition pipeline.h:92
Implements direct output to screen framebuffer.
Definition pipeline.h:258
core::dimension2du size
Definition pipeline.h:263
virtual void reset(PipelineContext &context) override
Resets the state of the object for the next pipeline iteration.
Definition pipeline.cpp:226
virtual void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:211
Dynamically changes render target of another step.
Definition pipeline.h:319
RenderStep * step
Definition pipeline.h:324
RenderTarget * target
Definition pipeline.h:325
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:237
SetRenderTargetStep(RenderStep *step, RenderTarget *target)
Definition pipeline.cpp:232
Definition dynamicshadowsrender.h:39
Swaps two textures in the texture buffer.
Definition pipeline.h:333
TextureBuffer * buffer
Definition pipeline.h:338
u8 texture_b
Definition pipeline.h:340
u8 texture_a
Definition pipeline.h:339
SwapTexturesStep(TextureBuffer *buffer, u8 texture_a, u8 texture_b)
Definition pipeline.cpp:242
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:247
Targets output to designated texture in texture buffer.
Definition pipeline.h:170
TextureBuffer * buffer
Definition pipeline.h:180
TextureBufferOutput(TextureBuffer *buffer, u8 texture_index)
Definition pipeline.cpp:145
virtual ~TextureBufferOutput() override
Definition pipeline.cpp:157
video::IRenderTarget * render_target
Definition pipeline.h:183
void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:163
static const u8 NO_DEPTH_TEXTURE
Definition pipeline.h:178
std::vector< u8 > texture_map
Definition pipeline.h:181
u8 depth_stencil
Definition pipeline.h:182
video::IVideoDriver * driver
Definition pipeline.h:184
Texture buffer represents a framebuffer with a multiple attached textures.
Definition pipeline.h:107
void swapTextures(u8 texture_a, u8 texture_b)
Definition pipeline.cpp:92
std::vector< TextureDefinition > m_definitions
Definition pipeline.h:162
bool ensureTexture(video::ITexture **textureSlot, const TextureDefinition &definition, PipelineContext &context)
Make sure the texture in the given slot matches the texture definition given the current context.
Definition pipeline.cpp:102
static const u8 NO_DEPTH_TEXTURE
Definition pipeline.h:137
virtual video::ITexture * getTexture(u8 index) override
Get a texture by index.
Definition pipeline.cpp:21
virtual ~TextureBuffer() override
Definition pipeline.cpp:14
core::array< video::ITexture * > m_textures
Definition pipeline.h:163
virtual void reset(PipelineContext &context) override
Definition pipeline.cpp:63
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.h:132
video::IVideoDriver * m_driver
Definition pipeline.h:161
void setTexture(u8 index, core::dimension2du size, const std::string &name, video::ECOLOR_FORMAT format, bool clear=false)
Configure fixed-size texture for the specific index.
Definition pipeline.cpp:29
Provides default empty implementation of supporting methods in a rendering step.
Definition pipeline.h:306
virtual void reset(PipelineContext &) override
Definition pipeline.h:310
virtual void setRenderTarget(RenderTarget *target) override
Assigned render target to this step.
Definition pipeline.h:309
virtual void setRenderSource(RenderSource *source) override
Assigns render source to this step.
Definition pipeline.h:308
core::vector2d< f32 > v2f
Definition irr_v2d.h:11
core::vector2d< u32 > v2u32
Definition irr_v2d.h:14
Definition activeobjectmgr.cpp:11
Definition clientmap.h:35
Definition pipeline.h:27
Hud * hud
Definition pipeline.h:35
bool draw_wield_tool
Definition pipeline.h:41
bool show_hud
Definition pipeline.h:40
video::SColor clear_color
Definition pipeline.h:37
bool draw_crosshair
Definition pipeline.h:42
ShadowRenderer * shadow_renderer
Definition pipeline.h:36
IrrlichtDevice * device
Definition pipeline.h:33
PipelineContext(IrrlichtDevice *_device, Client *_client, Hud *_hud, ShadowRenderer *_shadow_renderer, video::SColor _color, v2u32 _target_size)
Definition pipeline.h:28
Client * client
Definition pipeline.h:34
v2u32 target_size
Definition pipeline.h:38
Definition pipeline.h:140
bool valid
Definition pipeline.h:141
core::dimension2du size
Definition pipeline.h:146
bool dirty
Definition pipeline.h:143
video::ECOLOR_FORMAT format
Definition pipeline.h:148
v2f scale_factor
Definition pipeline.h:145
std::string name
Definition pipeline.h:147
bool clear
Definition pipeline.h:144
bool fixed_size
Definition pipeline.h:142