Luanti 5.11.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, u8 msaa = 0);
121
130 void setTexture(u8 index, v2f scale_factor, const std::string& name, video::ECOLOR_FORMAT format, bool clear = false, u8 msaa = 0);
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;
150 };
151
160 bool ensureTexture(video::ITexture **textureSlot, const TextureDefinition& definition, PipelineContext &context);
161
162 video::IVideoDriver *m_driver { nullptr };
163 std::vector<TextureDefinition> m_definitions;
164 core::array<video::ITexture *> m_textures;
165};
166
171{
172public:
173 TextureBufferOutput(TextureBuffer *buffer, u8 texture_index);
174 TextureBufferOutput(TextureBuffer *buffer, const std::vector<u8> &texture_map);
176 virtual ~TextureBufferOutput() override;
177 void activate(PipelineContext &context) override;
178
179 video::IRenderTarget *getIrrRenderTarget(PipelineContext &context);
180
181private:
182 static const u8 NO_DEPTH_TEXTURE = 255;
183
185 std::vector<u8> texture_map;
187 video::IRenderTarget* render_target { nullptr };
188 video::IVideoDriver* driver { nullptr };
189};
190
197{
198public:
200 : m_source(source)
201 {}
202
209 void setMapping(u8 index, u8 target_index)
210 {
211 if (index >= m_mappings.size()) {
212 u8 start = m_mappings.size();
213 m_mappings.resize(index);
214 for (u8 i = start; i < m_mappings.size(); ++i)
215 m_mappings[i] = i;
216 }
217
218 m_mappings[index] = target_index;
219 }
220
221 virtual u8 getTextureCount() override
222 {
223 return m_mappings.size();
224 }
225
226 virtual video::ITexture *getTexture(u8 index) override
227 {
228 if (index < m_mappings.size())
229 index = m_mappings[index];
230
231 return m_source->getTexture(index);
232 }
233public:
235 std::vector<u8> m_mappings;
236};
237
239{
240public:
241 bool isConfigured() { return upstream != nullptr; }
242 void setRenderSource(RenderSource *value) { upstream = value; }
243
247 virtual u8 getTextureCount() override;
248
253 virtual video::ITexture *getTexture(u8 index) override;
254private:
255 RenderSource *upstream { nullptr };
256};
257
262{
263public:
264 virtual void activate(PipelineContext &context) override;
265 virtual void reset(PipelineContext &context) override;
266private:
267 core::dimension2du size;
268};
269
271{
272public:
273 bool isConfigured() { return upstream != nullptr; }
274 void setRenderTarget(RenderTarget *value) { upstream = value; }
275 virtual void activate(PipelineContext &context) override;
276private:
277 RenderTarget *upstream { nullptr };
278};
279
283class RenderStep : virtual public RenderPipelineObject
284{
285public:
291 virtual void setRenderSource(RenderSource *source) = 0;
292
298 virtual void setRenderTarget(RenderTarget *target) = 0;
299
303 virtual void run(PipelineContext &context) = 0;
304};
305
310{
311public:
312 virtual void setRenderSource(RenderSource *source) override {}
313 virtual void setRenderTarget(RenderTarget *target) override {}
314 virtual void reset(PipelineContext &) override {}
315};
316
323{
324public:
326 virtual void run(PipelineContext &context) override;
327private:
330};
331
337{
338public:
340 virtual void run(PipelineContext &context) override;
341private:
345};
346
353{
354public:
361 {
362 m_pipeline.push_back(step);
363 return step;
364 }
365
374 template<typename T>
375 T *own(std::unique_ptr<T> &&object)
376 {
377 T* result = object.release();
378 m_objects.push_back(std::unique_ptr<RenderPipelineObject>(result));
379 return result;
380 }
381
390 template<typename T, typename... Args>
391 T *createOwned(Args&&... args) {
392 return own(std::make_unique<T>(std::forward<Args>(args)...));
393 }
394
404 template<typename T, typename... Args>
405 T *addStep(Args&&... args) {
406 T* result = own(std::make_unique<T>(std::forward<Args>(args)...));
407 addStep(result);
408 return result;
409 }
410
413
414 v2f getScale() { return scale; }
415 void setScale(v2f value) { scale = value; }
416
417 virtual void reset(PipelineContext &context) override {}
418 virtual void run(PipelineContext &context) override;
419
420 virtual void setRenderSource(RenderSource *source) override;
421 virtual void setRenderTarget(RenderTarget *target) override;
422private:
423 std::vector<RenderStep *> m_pipeline;
424 std::vector< std::unique_ptr<RenderPipelineObject> > m_objects;
427 v2f scale { 1.0f, 1.0f };
428};
Definition client.h:105
Definition pipeline.h:239
bool isConfigured()
Definition pipeline.h:241
void setRenderSource(RenderSource *value)
Definition pipeline.h:242
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.cpp:206
RenderSource * upstream
Definition pipeline.h:255
virtual video::ITexture * getTexture(u8 index) override
Get a texture by index.
Definition pipeline.cpp:212
Definition pipeline.h:271
virtual void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:226
RenderTarget * upstream
Definition pipeline.h:277
bool isConfigured()
Definition pipeline.h:273
void setRenderTarget(RenderTarget *value)
Definition pipeline.h:274
Definition hud.h:35
Allows remapping texture indicies in another RenderSource.
Definition pipeline.h:197
void setMapping(u8 index, u8 target_index)
Maps texture index to a different index in the dependent source.
Definition pipeline.h:209
std::vector< u8 > m_mappings
Definition pipeline.h:235
virtual video::ITexture * getTexture(u8 index) override
Get a texture by index.
Definition pipeline.h:226
RenderSource * m_source
Definition pipeline.h:234
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.h:221
RemappingSource(RenderSource *source)
Definition pipeline.h:199
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:353
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:269
DynamicTarget m_output
Definition pipeline.h:426
RenderTarget * getOutput()
Definition pipeline.cpp:264
virtual void setRenderTarget(RenderTarget *target) override
Assigned render target to this step.
Definition pipeline.cpp:288
v2f getScale()
Definition pipeline.h:414
void setScale(v2f value)
Definition pipeline.h:415
std::vector< std::unique_ptr< RenderPipelineObject > > m_objects
Definition pipeline.h:424
virtual void setRenderSource(RenderSource *source) override
Assigns render source to this step.
Definition pipeline.cpp:283
RenderSource * getInput()
Definition pipeline.cpp:259
DynamicSource m_input
Definition pipeline.h:425
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:405
virtual void reset(PipelineContext &context) override
Definition pipeline.h:417
v2f scale
Definition pipeline.h:427
RenderStep * addStep(RenderStep *step)
Add a step to the end of the pipeline.
Definition pipeline.h:360
std::vector< RenderStep * > m_pipeline
Definition pipeline.h:423
T * createOwned(Args &&... args)
Create a new object that will be managed by the pipeline.
Definition pipeline.h:391
T * own(std::unique_ptr< T > &&object)
Capture ownership of a dynamically created.
Definition pipeline.h:375
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:284
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:262
core::dimension2du size
Definition pipeline.h:267
virtual void reset(PipelineContext &context) override
Resets the state of the object for the next pipeline iteration.
Definition pipeline.cpp:233
virtual void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:218
Dynamically changes render target of another step.
Definition pipeline.h:323
RenderStep * step
Definition pipeline.h:328
RenderTarget * target
Definition pipeline.h:329
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:244
SetRenderTargetStep(RenderStep *step, RenderTarget *target)
Definition pipeline.cpp:239
Definition dynamicshadowsrender.h:39
Swaps two textures in the texture buffer.
Definition pipeline.h:337
TextureBuffer * buffer
Definition pipeline.h:342
u8 texture_b
Definition pipeline.h:344
u8 texture_a
Definition pipeline.h:343
SwapTexturesStep(TextureBuffer *buffer, u8 texture_a, u8 texture_b)
Definition pipeline.cpp:249
virtual void run(PipelineContext &context) override
Runs the step.
Definition pipeline.cpp:254
Targets output to designated texture in texture buffer.
Definition pipeline.h:171
video::IRenderTarget * getIrrRenderTarget(PipelineContext &context)
Definition pipeline.cpp:200
TextureBuffer * buffer
Definition pipeline.h:184
TextureBufferOutput(TextureBuffer *buffer, u8 texture_index)
Definition pipeline.cpp:153
virtual ~TextureBufferOutput() override
Definition pipeline.cpp:165
video::IRenderTarget * render_target
Definition pipeline.h:187
void activate(PipelineContext &context) override
Activate the render target and configure OpenGL state for the output.
Definition pipeline.cpp:171
static const u8 NO_DEPTH_TEXTURE
Definition pipeline.h:182
std::vector< u8 > texture_map
Definition pipeline.h:185
u8 depth_stencil
Definition pipeline.h:186
video::IVideoDriver * driver
Definition pipeline.h:188
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:94
std::vector< TextureDefinition > m_definitions
Definition pipeline.h:163
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:104
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:164
virtual void reset(PipelineContext &context) override
Definition pipeline.cpp:65
virtual u8 getTextureCount() override
Return the number of textures in the source.
Definition pipeline.h:132
video::IVideoDriver * m_driver
Definition pipeline.h:162
void setTexture(u8 index, core::dimension2du size, const std::string &name, video::ECOLOR_FORMAT format, bool clear=false, u8 msaa=0)
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:310
virtual void reset(PipelineContext &) override
Definition pipeline.h:314
virtual void setRenderTarget(RenderTarget *target) override
Assigned render target to this step.
Definition pipeline.h:313
virtual void setRenderSource(RenderSource *source) override
Assigns render source to this step.
Definition pipeline.h:312
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
u8 msaa
Definition pipeline.h:149
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