diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 80ef73d824..99c7dfa6c2 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -196,11 +196,14 @@ Background color for the boot splash. - If [code]true[/code], scale the boot splash image to the full window length when engine starts. If [code]false[/code], the engine will leave it at the default pixel size. + If [code]true[/code], scale the boot splash image according to the mode selected in the stretch_mode property. If [code]false[/code], the engine will leave it at the default pixel size. Path to an image used as the boot splash. + + Specifies how the splash image will be stretched. Takes no effect if fullsize is false. For more information about available stretch modes look for SPLASH_STRETCH_MODE* constants in the documentation. + If [code]true[/code], applies linear filtering when scaling the image (recommended for high resolution artwork). If [code]false[/code], uses nearest-neighbor interpolation (recommended for pixel art). diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index 68b79ff749..2b8ca821b7 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -2623,10 +2623,10 @@ - + - Sets a boot image. The color defines the background color. If [code]scale[/code] is [code]true[/code], the image will be scaled to fit the screen size. If [code]use_filter[/code] is [code]true[/code], the image will be scaled with linear interpolation. If [code]use_filter[/code] is [code]false[/code], the image will be scaled with nearest-neighbor interpolation. + Sets a boot image. The color defines the background color. The value of [code]stretch_mode[/code] indicates how the image will be stretched (for more information about stretch modes see SPLASH_STRETCH_MODE* constants). If [code]use_filter[/code] is [code]true[/code], the image will be scaled with linear interpolation. If [code]use_filter[/code] is [code]false[/code], the image will be scaled with nearest-neighbor interpolation. @@ -4427,5 +4427,23 @@ Hardware supports multithreading. This enum is currently unused in Godot 3.x. + + If the window width is greater than its height, the splash image will be stretched to have the same height as the window. Otherwise, the image will be stretched to have the same width as the window. Both cases keep the original image's aspect ratio. + + + The splash image is stretched to have the same width as the window. It keeps the image's aspect ratio. + + + The splash image is stretched to have the same height as the window. It keeps the image's aspect ratio. + + + The splash image covers the window while keeping the aspect ratio. + + + The splash image covers the window witohut keeping the aspect ratio. + + + The splash image uses its default pixel size. + diff --git a/main/main.cpp b/main/main.cpp index 7355493677..578a767173 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1703,12 +1703,22 @@ Error Main::setup2(Thread::ID p_main_tid_override) { if (show_logo) { //boot logo! String boot_logo_path = GLOBAL_DEF("application/boot_splash/image", String()); bool boot_logo_scale = GLOBAL_DEF("application/boot_splash/fullsize", true); + String boot_stretch_mode = GLOBAL_DEF("application/boot_splash/stretch_mode", "keep"); bool boot_logo_filter = GLOBAL_DEF("application/boot_splash/use_filter", true); + + ProjectSettings::get_singleton()->set_custom_property_info("application/boot_splash/stretch_mode", + PropertyInfo(Variant::STRING, + "application/boot_splash/stretch_mode", + PROPERTY_HINT_ENUM, "keep,keep_width,keep_height,cover,expand")); ProjectSettings::get_singleton()->set_custom_property_info("application/boot_splash/image", PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png")); + if (!boot_logo_scale) { // ignore stretch mode if logo scaling is disabled + boot_stretch_mode = "disabled"; + } + Ref boot_logo; boot_logo_path = boot_logo_path.strip_edges(); @@ -1729,7 +1739,19 @@ Error Main::setup2(Thread::ID p_main_tid_override) { const Color boot_bg_color = GLOBAL_DEF("application/boot_splash/bg_color", boot_splash_bg_color); #endif if (boot_logo.is_valid()) { - RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, + RenderingServer::SplashStretchMode vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_DISABLED; + if (boot_stretch_mode == "keep") + vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_KEEP; + else if (boot_stretch_mode == "keep_width") + vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_KEEP_WIDTH; + else if (boot_stretch_mode == "keep_height") + vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_KEEP_HEIGHT; + else if (boot_stretch_mode == "cover") + vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_COVER; + else if (boot_stretch_mode == "expand") + vs_boot_stretch_mode = RenderingServer::SPLASH_STRETCH_MODE_EXPAND; + + RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, vs_boot_stretch_mode, boot_logo_filter); } else { @@ -1744,7 +1766,7 @@ Error Main::setup2(Thread::ID p_main_tid_override) { MAIN_PRINT("Main: ClearColor"); RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color); MAIN_PRINT("Main: Image"); - RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false); + RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, RenderingServer::SPLASH_STRETCH_MODE_DISABLED); #endif } diff --git a/servers/rendering/rasterizer_dummy.h b/servers/rendering/rasterizer_dummy.h index 44e07a1853..2d45faeafe 100644 --- a/servers/rendering/rasterizer_dummy.h +++ b/servers/rendering/rasterizer_dummy.h @@ -757,7 +757,7 @@ public: RendererCanvasRender *get_canvas() override { return &canvas; } RendererSceneRender *get_scene() override { return &scene; } - void set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override {} + void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true) override {} void initialize() override {} void begin_frame(double frame_step) override { diff --git a/servers/rendering/renderer_compositor.h b/servers/rendering/renderer_compositor.h index 1971c3e781..461f430ee4 100644 --- a/servers/rendering/renderer_compositor.h +++ b/servers/rendering/renderer_compositor.h @@ -75,7 +75,7 @@ public: virtual RendererCanvasRender *get_canvas() = 0; virtual RendererSceneRender *get_scene() = 0; - virtual void set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0; + virtual void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true) = 0; virtual void initialize() = 0; virtual void begin_frame(double frame_step) = 0; diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp index 559e6d5ad7..1c5d6ebc65 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp @@ -159,7 +159,7 @@ void RendererCompositorRD::finalize() { RD::get_singleton()->free(blit.sampler); } -void RendererCompositorRD::set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { +void RendererCompositorRD::set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) { RD::get_singleton()->prepare_screen_for_drawing(); RID texture = storage->texture_allocate(); @@ -182,7 +182,35 @@ void RendererCompositorRD::set_boot_image(const Ref &p_image, const Color Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height()); Rect2 screenrect; - if (p_scale) { + if (p_stretch_mode == RenderingServer::SPLASH_STRETCH_MODE_KEEP_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 if (p_stretch_mode == RenderingServer::SPLASH_STRETCH_MODE_KEEP_WIDTH) { + //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 if (p_stretch_mode == RenderingServer::SPLASH_STRETCH_MODE_COVER) { + double window_aspect = (double)window_size.width / window_size.height; + double img_aspect = imgrect.size.x / imgrect.size.y; + + if (window_aspect > img_aspect) { + //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 { + //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 if (p_stretch_mode == RenderingServer::SPLASH_STRETCH_MODE_EXPAND) { + screenrect.size.x = window_size.width; + screenrect.size.y = window_size.height; + } else if (p_stretch_mode == RenderingServer::SPLASH_STRETCH_MODE_KEEP) { if (window_size.width > window_size.height) { //scale horizontally screenrect.size.y = window_size.height; diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.h b/servers/rendering/renderer_rd/renderer_compositor_rd.h index 0230c46800..2094f0e235 100644 --- a/servers/rendering/renderer_rd/renderer_compositor_rd.h +++ b/servers/rendering/renderer_rd/renderer_compositor_rd.h @@ -90,7 +90,7 @@ public: RendererCanvasRender *get_canvas() { return canvas; } RendererSceneRender *get_scene() { return scene; } - void set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter); + void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter); void initialize(); void begin_frame(double frame_step); diff --git a/servers/rendering/rendering_server_default.cpp b/servers/rendering/rendering_server_default.cpp index 2ce9a20b6b..791a5ed20f 100644 --- a/servers/rendering/rendering_server_default.cpp +++ b/servers/rendering/rendering_server_default.cpp @@ -269,9 +269,9 @@ Vector RenderingServerDefault::get_frame_prof /* TESTING */ -void RenderingServerDefault::set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter) { +void RenderingServerDefault::set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) { redraw_request(); - RSG::rasterizer->set_boot_image(p_image, p_color, p_scale, p_use_filter); + RSG::rasterizer->set_boot_image(p_image, p_color, p_stretch_mode, p_use_filter); } void RenderingServerDefault::set_default_clear_color(const Color &p_color) { diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 9a592a9265..56f39d887e 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -898,7 +898,7 @@ public: virtual double get_frame_setup_time_cpu() const override; - virtual void set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override; + virtual void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true) override; virtual void set_default_clear_color(const Color &p_color) override; virtual bool has_feature(Features p_feature) const override; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index cdf7fa530e..478c27d27e 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2713,7 +2713,7 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_test_texture"), &RenderingServer::get_test_texture); ClassDB::bind_method(D_METHOD("get_white_texture"), &RenderingServer::get_white_texture); - ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "scale", "use_filter"), &RenderingServer::set_boot_image, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_boot_image", "image", "color", "stretch_mode", "use_filter"), &RenderingServer::set_boot_image, DEFVAL(true)); ClassDB::bind_method(D_METHOD("set_default_clear_color", "color"), &RenderingServer::set_default_clear_color); ClassDB::bind_method(D_METHOD("has_feature", "feature"), &RenderingServer::has_feature); @@ -2737,6 +2737,13 @@ void RenderingServer::_bind_methods() { BIND_ENUM_CONSTANT(FEATURE_SHADERS); BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_KEEP); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_KEEP_WIDTH); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_KEEP_HEIGHT); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_COVER); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_EXPAND); + BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_DISABLED); + ADD_SIGNAL(MethodInfo("frame_pre_draw")); ADD_SIGNAL(MethodInfo("frame_post_draw")); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index f35a633bf3..32f6a82d1b 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -1489,7 +1489,16 @@ public: virtual void mesh_add_surface_from_mesh_data(RID p_mesh, const Geometry3D::MeshData &p_mesh_data); virtual void mesh_add_surface_from_planes(RID p_mesh, const Vector &p_planes); - virtual void set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0; + enum SplashStretchMode { + SPLASH_STRETCH_MODE_KEEP, + SPLASH_STRETCH_MODE_KEEP_WIDTH, + SPLASH_STRETCH_MODE_KEEP_HEIGHT, + SPLASH_STRETCH_MODE_COVER, + SPLASH_STRETCH_MODE_EXPAND, + SPLASH_STRETCH_MODE_DISABLED, + }; + + virtual void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true) = 0; virtual void set_default_clear_color(const Color &p_color) = 0; enum Features { @@ -1605,6 +1614,7 @@ VARIANT_ENUM_CAST(RenderingServer::RenderingInfo); VARIANT_ENUM_CAST(RenderingServer::Features); VARIANT_ENUM_CAST(RenderingServer::CanvasTextureChannel); VARIANT_ENUM_CAST(RenderingServer::BakeChannels); +VARIANT_ENUM_CAST(RenderingServer::SplashStretchMode); // Alias to make it easier to use. #define RS RenderingServer