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
10278 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];
72
float dst_rect[4];
73
74
float rotation_sin;
75
float rotation_cos;
76
77
float eye_center[2];
78
float k1;
79
float k2;
80
81
float upscale;
82
float aspect_ratio;
83
uint32_t layer;
84
uint32_t convert_to_srgb;
85
uint32_t use_debanding;
86
float pad;
87
};
88
89
struct Blit {
90
BlitPushConstant push_constant;
91
BlitShaderRD shader;
92
RID shader_version;
93
RID pipelines[BLIT_MODE_MAX];
94
RID index_buffer;
95
RID array;
96
RID sampler;
97
} blit;
98
99
HashMap<RID, RID> render_target_descriptors;
100
101
double time = 0.0;
102
double delta = 0.0;
103
104
static uint64_t frame;
105
static RendererCompositorRD *singleton;
106
107
public:
108
RendererUtilities *get_utilities() { return utilities; }
109
RendererLightStorage *get_light_storage() { return light_storage; }
110
RendererMaterialStorage *get_material_storage() { return material_storage; }
111
RendererMeshStorage *get_mesh_storage() { return mesh_storage; }
112
RendererParticlesStorage *get_particles_storage() { return particles_storage; }
113
RendererTextureStorage *get_texture_storage() { return texture_storage; }
114
RendererGI *get_gi() {
115
ERR_FAIL_NULL_V(scene, nullptr);
116
return scene->get_gi();
117
}
118
RendererFog *get_fog() { return fog; }
119
RendererCanvasRender *get_canvas() { return canvas; }
120
RendererSceneRender *get_scene() { return scene; }
121
122
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter);
123
124
void initialize();
125
void begin_frame(double frame_step);
126
void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount);
127
128
bool is_opengl() { return false; }
129
void gl_end_frame(bool p_swap_buffers) {}
130
void end_frame(bool p_present);
131
void finalize();
132
133
_ALWAYS_INLINE_ uint64_t get_frame_number() const { return frame; }
134
_ALWAYS_INLINE_ double get_frame_delta_time() const { return delta; }
135
_ALWAYS_INLINE_ double get_total_time() const { return time; }
136
_ALWAYS_INLINE_ bool can_create_resources_async() const { return true; }
137
138
virtual bool is_xr_enabled() const { return RendererCompositor::is_xr_enabled(); }
139
140
static Error is_viable() {
141
return OK;
142
}
143
144
static RendererCompositor *_create_current() {
145
return memnew(RendererCompositorRD);
146
}
147
148
static void make_current() {
149
_create_func = _create_current;
150
low_end = false;
151
}
152
153
static RendererCompositorRD *get_singleton() { return singleton; }
154
RendererCompositorRD();
155
~RendererCompositorRD();
156
};
157
158