diff options
author | reduz <reduzio@gmail.com> | 2021-07-03 18:09:19 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-07-03 18:09:19 -0300 |
commit | 6e1c5e346ac216ed0a61ac5ed1dee0148c7b33ca (patch) | |
tree | 8691dfc5c794c61d8cf9cfe901ff3759b0f11a62 /servers/rendering | |
parent | cb4e42155dd3a0e513106d7a219366dd355e9483 (diff) |
Fix Boot Splash
* Implements the code to show the boot splash on load using RenderingDevice
* Does not work on X11 when maximized, some platform specific hack will be needed there.
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/renderer_rd/renderer_compositor_rd.cpp | 81 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/renderer_compositor_rd.h | 3 |
2 files changed, 80 insertions, 4 deletions
diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index f9ac7c8fa3..a8f086b0f9 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -60,8 +60,7 @@ void RendererCompositorRD::blit_render_targets_to_screen(DisplayServer::WindowID } Size2 screen_size(RD::get_singleton()->screen_get_width(p_screen), RD::get_singleton()->screen_get_height(p_screen)); - BlitMode mode = p_render_targets[i].lens_distortion.apply ? BLIT_MODE_LENS : p_render_targets[i].multi_view.use_layer ? BLIT_MODE_USE_LAYER : - BLIT_MODE_NORMAL; + BlitMode mode = p_render_targets[i].lens_distortion.apply ? BLIT_MODE_LENS : (p_render_targets[i].multi_view.use_layer ? BLIT_MODE_USE_LAYER : BLIT_MODE_NORMAL); RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blit.pipelines[mode]); RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array); RD::get_singleton()->draw_list_bind_uniform_set(draw_list, render_target_descriptors[rd_texture], 0); @@ -111,13 +110,14 @@ void RendererCompositorRD::initialize() { blit_modes.push_back("\n"); blit_modes.push_back("\n#define USE_LAYER\n"); blit_modes.push_back("\n#define USE_LAYER\n#define APPLY_LENS_DISTORTION\n"); + blit_modes.push_back("\n"); blit.shader.initialize(blit_modes); blit.shader_version = blit.shader.version_create(); for (int i = 0; i < BLIT_MODE_MAX; i++) { - blit.pipelines[i] = RD::get_singleton()->render_pipeline_create(blit.shader.version_get_shader(blit.shader_version, i), RD::get_singleton()->screen_get_framebuffer_format(), RD::INVALID_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), RenderingDevice::PipelineColorBlendState::create_disabled(), 0); + blit.pipelines[i] = RD::get_singleton()->render_pipeline_create(blit.shader.version_get_shader(blit.shader_version, i), RD::get_singleton()->screen_get_framebuffer_format(), RD::INVALID_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), RD::PipelineDepthStencilState(), i == BLIT_MODE_NORMAL_ALPHA ? RenderingDevice::PipelineColorBlendState::create_blend() : RenderingDevice::PipelineColorBlendState::create_disabled(), 0); } //create index array for copy shader @@ -153,6 +153,81 @@ void RendererCompositorRD::finalize() { RD::get_singleton()->free(blit.sampler); } +void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { + RD::get_singleton()->prepare_screen_for_drawing(); + + RID texture = storage->texture_allocate(); + storage->texture_2d_initialize(texture, p_image); + RID rd_texture = storage->texture_get_rd_texture(texture); + + RID uset; + { + Vector<RD::Uniform> uniforms; + RD::Uniform u; + u.uniform_type = RD::UNIFORM_TYPE_SAMPLER_WITH_TEXTURE; + u.binding = 0; + u.ids.push_back(blit.sampler); + u.ids.push_back(rd_texture); + uniforms.push_back(u); + uset = RD::get_singleton()->uniform_set_create(uniforms, blit.shader.version_get_shader(blit.shader_version, BLIT_MODE_NORMAL), 0); + } + + Size2 window_size = DisplayServer::get_singleton()->window_get_size(); + print_line("window size: " + window_size); + + Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); + Rect2 screenrect; + if (p_scale) { + if (window_size.width > window_size.height) { + //scale horizontally + screenrect.size.y = window_size.height; + screenrect.size.x = imgrect.size.x * window_size.height / imgrect.size.y; + screenrect.position.x = (window_size.width - screenrect.size.x) / 2; + + } else { + //scale vertically + screenrect.size.x = window_size.width; + screenrect.size.y = imgrect.size.y * window_size.width / imgrect.size.x; + screenrect.position.y = (window_size.height - screenrect.size.y) / 2; + } + } else { + screenrect = imgrect; + screenrect.position += ((Size2(window_size.width, window_size.height) - screenrect.size) / 2.0).floor(); + } + + screenrect.position /= window_size; + screenrect.size /= window_size; + + RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin_for_screen(DisplayServer::MAIN_WINDOW_ID, p_color); + + RD::get_singleton()->draw_list_bind_render_pipeline(draw_list, blit.pipelines[BLIT_MODE_NORMAL_ALPHA]); + RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array); + RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uset, 0); + + blit.push_constant.rect[0] = screenrect.position.x; + blit.push_constant.rect[1] = screenrect.position.y; + blit.push_constant.rect[2] = screenrect.size.width; + blit.push_constant.rect[3] = screenrect.size.height; + blit.push_constant.layer = 0; + blit.push_constant.eye_center[0] = 0; + blit.push_constant.eye_center[1] = 0; + blit.push_constant.k1 = 0; + blit.push_constant.k2 = 0; + blit.push_constant.upscale = 1.0; + blit.push_constant.aspect_ratio = 1.0; + + print_line("rect: " + screenrect); + + RD::get_singleton()->draw_list_set_push_constant(draw_list, &blit.push_constant, sizeof(BlitPushConstant)); + RD::get_singleton()->draw_list_draw(draw_list, true); + + RD::get_singleton()->draw_list_end(); + + RD::get_singleton()->swap_buffers(); + + RD::get_singleton()->free(texture); +} + RendererCompositorRD *RendererCompositorRD::singleton = nullptr; RendererCompositorRD::RendererCompositorRD() { diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.h b/servers/rendering/renderer_rd/renderer_compositor_rd.h index 7a78322051..15b3b77ed9 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.h +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.h @@ -50,6 +50,7 @@ protected: BLIT_MODE_NORMAL, BLIT_MODE_USE_LAYER, BLIT_MODE_LENS, + BLIT_MODE_NORMAL_ALPHA, BLIT_MODE_MAX }; @@ -88,7 +89,7 @@ public: RendererCanvasRender *get_canvas() { return canvas; } RendererSceneRender *get_scene() { return scene; } - void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {} + void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter); void initialize(); void begin_frame(double frame_step); |