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 | #ifndef RENDERER_COMPOSITOR_RD_H |
32 | #define RENDERER_COMPOSITOR_RD_H |
33 | |
34 | #include "core/os/os.h" |
35 | #include "servers/rendering/renderer_compositor.h" |
36 | #include "servers/rendering/renderer_rd/environment/fog.h" |
37 | #include "servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.h" |
38 | #include "servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.h" |
39 | #include "servers/rendering/renderer_rd/framebuffer_cache_rd.h" |
40 | #include "servers/rendering/renderer_rd/renderer_canvas_render_rd.h" |
41 | #include "servers/rendering/renderer_rd/shaders/blit.glsl.gen.h" |
42 | #include "servers/rendering/renderer_rd/storage_rd/light_storage.h" |
43 | #include "servers/rendering/renderer_rd/storage_rd/material_storage.h" |
44 | #include "servers/rendering/renderer_rd/storage_rd/mesh_storage.h" |
45 | #include "servers/rendering/renderer_rd/storage_rd/particles_storage.h" |
46 | #include "servers/rendering/renderer_rd/storage_rd/texture_storage.h" |
47 | #include "servers/rendering/renderer_rd/storage_rd/utilities.h" |
48 | #include "servers/rendering/renderer_rd/uniform_set_cache_rd.h" |
49 | |
50 | class RendererCompositorRD : public RendererCompositor { |
51 | protected: |
52 | UniformSetCacheRD *uniform_set_cache = nullptr; |
53 | FramebufferCacheRD *framebuffer_cache = nullptr; |
54 | RendererCanvasRenderRD *canvas = nullptr; |
55 | RendererRD::Utilities *utilities = nullptr; |
56 | RendererRD::LightStorage *light_storage = nullptr; |
57 | RendererRD::MaterialStorage *material_storage = nullptr; |
58 | RendererRD::MeshStorage *mesh_storage = nullptr; |
59 | RendererRD::ParticlesStorage *particles_storage = nullptr; |
60 | RendererRD::TextureStorage *texture_storage = nullptr; |
61 | RendererRD::Fog *fog = nullptr; |
62 | RendererSceneRenderRD *scene = nullptr; |
63 | |
64 | enum BlitMode { |
65 | BLIT_MODE_NORMAL, |
66 | BLIT_MODE_USE_LAYER, |
67 | BLIT_MODE_LENS, |
68 | BLIT_MODE_NORMAL_ALPHA, |
69 | BLIT_MODE_MAX |
70 | }; |
71 | |
72 | struct BlitPushConstant { |
73 | float src_rect[4]; |
74 | float dst_rect[4]; |
75 | |
76 | float eye_center[2]; |
77 | float k1; |
78 | float k2; |
79 | |
80 | float upscale; |
81 | float aspect_ratio; |
82 | uint32_t layer; |
83 | uint32_t convert_to_srgb; |
84 | }; |
85 | |
86 | struct Blit { |
87 | BlitPushConstant push_constant; |
88 | BlitShaderRD shader; |
89 | RID shader_version; |
90 | RID pipelines[BLIT_MODE_MAX]; |
91 | RID index_buffer; |
92 | RID array; |
93 | RID sampler; |
94 | } blit; |
95 | |
96 | HashMap<RID, RID> render_target_descriptors; |
97 | |
98 | double time = 0.0; |
99 | double delta = 0.0; |
100 | |
101 | static uint64_t frame; |
102 | static RendererCompositorRD *singleton; |
103 | |
104 | public: |
105 | RendererUtilities *get_utilities() { return utilities; }; |
106 | RendererLightStorage *get_light_storage() { return light_storage; } |
107 | RendererMaterialStorage *get_material_storage() { return material_storage; } |
108 | RendererMeshStorage *get_mesh_storage() { return mesh_storage; } |
109 | RendererParticlesStorage *get_particles_storage() { return particles_storage; } |
110 | RendererTextureStorage *get_texture_storage() { return texture_storage; } |
111 | RendererGI *get_gi() { |
112 | ERR_FAIL_NULL_V(scene, nullptr); |
113 | return scene->get_gi(); |
114 | } |
115 | RendererFog *get_fog() { return fog; } |
116 | RendererCanvasRender *get_canvas() { return canvas; } |
117 | RendererSceneRender *get_scene() { return scene; } |
118 | |
119 | void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter); |
120 | |
121 | void initialize(); |
122 | void begin_frame(double frame_step); |
123 | void prepare_for_blitting_render_targets(); |
124 | void blit_render_targets_to_screen(DisplayServer::WindowID p_screen, const BlitToScreen *p_render_targets, int p_amount); |
125 | |
126 | void end_frame(bool p_swap_buffers); |
127 | void finalize(); |
128 | |
129 | _ALWAYS_INLINE_ uint64_t get_frame_number() const { return frame; } |
130 | _ALWAYS_INLINE_ double get_frame_delta_time() const { return delta; } |
131 | _ALWAYS_INLINE_ double get_total_time() const { return time; } |
132 | |
133 | static Error is_viable() { |
134 | return OK; |
135 | } |
136 | |
137 | static RendererCompositor *_create_current() { |
138 | return memnew(RendererCompositorRD); |
139 | } |
140 | |
141 | static void make_current() { |
142 | _create_func = _create_current; |
143 | low_end = false; |
144 | } |
145 | |
146 | static RendererCompositorRD *get_singleton() { return singleton; } |
147 | RendererCompositorRD(); |
148 | ~RendererCompositorRD(); |
149 | }; |
150 | |
151 | #endif // RENDERER_COMPOSITOR_RD_H |
152 | |