Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/servers/rendering/renderer_rd/renderer_compositor_rd.h
21689 views
1
/**************************************************************************/
2
/* renderer_compositor_rd.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/io/image.h"
34
#include "servers/rendering/renderer_compositor.h"
35
#include "servers/rendering/renderer_rd/environment/fog.h"
36
#include "servers/rendering/renderer_rd/framebuffer_cache_rd.h"
37
#include "servers/rendering/renderer_rd/renderer_canvas_render_rd.h"
38
#include "servers/rendering/renderer_rd/renderer_scene_render_rd.h"
39
#include "servers/rendering/renderer_rd/shaders/blit.glsl.gen.h"
40
#include "servers/rendering/renderer_rd/storage_rd/light_storage.h"
41
#include "servers/rendering/renderer_rd/storage_rd/material_storage.h"
42
#include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h"
43
#include "servers/rendering/renderer_rd/storage_rd/particles_storage.h"
44
#include "servers/rendering/renderer_rd/storage_rd/texture_storage.h"
45
#include "servers/rendering/renderer_rd/storage_rd/utilities.h"
46
#include "servers/rendering/renderer_rd/uniform_set_cache_rd.h"
47
48
class RendererCompositorRD : public RendererCompositor {
49
protected:
50
UniformSetCacheRD *uniform_set_cache = nullptr;
51
FramebufferCacheRD *framebuffer_cache = nullptr;
52
RendererCanvasRenderRD *canvas = nullptr;
53
RendererRD::Utilities *utilities = nullptr;
54
RendererRD::LightStorage *light_storage = nullptr;
55
RendererRD::MaterialStorage *material_storage = nullptr;
56
RendererRD::MeshStorage *mesh_storage = nullptr;
57
RendererRD::ParticlesStorage *particles_storage = nullptr;
58
RendererRD::TextureStorage *texture_storage = nullptr;
59
RendererRD::Fog *fog = nullptr;
60
RendererSceneRenderRD *scene = nullptr;
61
62
enum BlitMode {
63
BLIT_MODE_NORMAL,
64
BLIT_MODE_USE_LAYER,
65
BLIT_MODE_LENS,
66
BLIT_MODE_NORMAL_ALPHA,
67
BLIT_MODE_MAX
68
};
69
70
struct BlitPushConstant {
71
float src_rect[4]; // 16 - 16
72
float dst_rect[4]; // 16 - 32
73
74
float rotation_sin; // 4 - 36
75
float rotation_cos; // 4 - 40
76
float eye_center[2]; // 8 - 48
77
78
float k1; // 4 - 52
79
float k2; // 4 - 56
80
float upscale; // 4 - 60
81
float aspect_ratio; // 4 - 64
82
83
uint32_t layer; // 4 - 68
84
uint32_t source_is_srgb; // 4 - 72
85
uint32_t use_debanding; // 4 - 76
86
uint32_t target_color_space; // 4 - 80
87
88
float reference_multiplier; // 4 - 84
89
float output_max_value; // 4 - 88
90
uint32_t pad[2]; // 8 - 96 (padding to reach 16-byte boundary)
91
};
92
93
struct BlitPipelines {
94
RID pipelines[BLIT_MODE_MAX];
95
};
96
97
struct Blit {
98
BlitPushConstant push_constant;
99
BlitShaderRD shader;
100
RID shader_version;
101
HashMap<RenderingDevice::FramebufferFormatID, BlitPipelines> pipelines_by_format;
102
RID index_buffer;
103
RID array;
104
RID sampler;
105
} blit;
106
107
HashMap<RID, RID> render_target_descriptors;
108
109
double time = 0.0;
110
double delta = 0.0;
111
112
static uint64_t frame;
113
static RendererCompositorRD *singleton;
114
115
BlitPipelines _get_blit_pipelines_for_format(RenderingDevice::FramebufferFormatID format);
116
float _compute_reference_multiplier(RD::ColorSpace p_color_space, const float p_reference_luminance, const float p_linear_luminance_scale);
117
118
public:
119
virtual RendererUtilities *get_utilities() override { return utilities; }
120
virtual RendererLightStorage *get_light_storage() override { return light_storage; }
121
virtual RendererMaterialStorage *get_material_storage() override { return material_storage; }
122
virtual RendererMeshStorage *get_mesh_storage() override { return mesh_storage; }
123
virtual RendererParticlesStorage *get_particles_storage() override { return particles_storage; }
124
virtual RendererTextureStorage *get_texture_storage() override { return texture_storage; }
125
virtual RendererGI *get_gi() override {
126
ERR_FAIL_NULL_V(scene, nullptr);
127
return scene->get_gi();
128
}
129
virtual RendererFog *get_fog() override { return fog; }
130
virtual RendererCanvasRender *get_canvas() override { return canvas; }
131
virtual RendererSceneRender *get_scene() override { return scene; }
132
133
virtual void set_boot_image_with_stretch(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) override;
134
135
virtual void initialize() override;
136
virtual void begin_frame(double frame_step) override;
137
virtual void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount) override;
138
139
virtual bool is_opengl() override { return false; }
140
virtual void gl_end_frame(bool p_swap_buffers) override {}
141
virtual void end_frame(bool p_present) override;
142
virtual void finalize() override;
143
144
_ALWAYS_INLINE_ virtual uint64_t get_frame_number() const override { return frame; }
145
_ALWAYS_INLINE_ virtual double get_frame_delta_time() const override { return delta; }
146
_ALWAYS_INLINE_ virtual double get_total_time() const override { return time; }
147
_ALWAYS_INLINE_ virtual bool can_create_resources_async() const override { return true; }
148
149
virtual bool is_xr_enabled() const override { return RendererCompositor::is_xr_enabled(); }
150
151
static Error is_viable() {
152
return OK;
153
}
154
155
static RendererCompositor *_create_current() {
156
return memnew(RendererCompositorRD);
157
}
158
159
static void make_current() {
160
_create_func = _create_current;
161
low_end = false;
162
}
163
164
static RendererCompositorRD *get_singleton() { return singleton; }
165
RendererCompositorRD();
166
~RendererCompositorRD();
167
};
168
169