Skip to content

Commit 3f34e38

Browse files
committed
Merge pull request godotengine#109596 from atlasapplications/splash-screen-stretch-mode
Add Stretch Modes for Splash Screen
2 parents 84d516f + b6b3e1e commit 3f34e38

File tree

16 files changed

+178
-46
lines changed

16 files changed

+178
-46
lines changed

core/config/project_settings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "core/variant/typed_array.h"
4444
#include "core/variant/variant_parser.h"
4545
#include "core/version.h"
46+
#include "servers/rendering/rendering_server.h"
4647

4748
#ifdef TOOLS_ENABLED
4849
#include "modules/modules_enabled.gen.h" // For mono.
@@ -600,6 +601,12 @@ void ProjectSettings::_convert_to_last_version(int p_from_version) {
600601
E.value.variant = action;
601602
}
602603
}
604+
} else if (p_from_version <= 6) {
605+
// Check if we still have legacy boot splash (removed in 4.6), map it to new project setting, then remove legacy setting.
606+
if (has_setting("application/boot_splash/fullsize")) {
607+
set_setting("application/boot_splash/stretch_mode", RenderingServer::map_scaling_option_to_stretch_mode(get_setting("application/boot_splash/fullsize")));
608+
set_setting("application/boot_splash/fullsize", Variant());
609+
}
603610
}
604611
#endif // DISABLE_DEPRECATED
605612
}

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,6 @@
278278
<member name="application/boot_splash/bg_color" type="Color" setter="" getter="" default="Color(0.14, 0.14, 0.14, 1)">
279279
Background color for the boot splash.
280280
</member>
281-
<member name="application/boot_splash/fullsize" type="bool" setter="" getter="" default="true">
282-
If [code]true[/code], scale the boot splash image to the full window size (preserving the aspect ratio) when the engine starts. If [code]false[/code], the engine will leave it at the default pixel size.
283-
</member>
284281
<member name="application/boot_splash/image" type="String" setter="" getter="" default="&quot;&quot;">
285282
Path to an image used as the boot splash. If left empty, the default Godot Engine splash will be displayed instead.
286283
[b]Note:[/b] Only effective if [member application/boot_splash/show_image] is [code]true[/code].
@@ -293,6 +290,9 @@
293290
<member name="application/boot_splash/show_image" type="bool" setter="" getter="" default="true">
294291
If [code]true[/code], displays the image specified in [member application/boot_splash/image] when the engine starts. If [code]false[/code], only displays the plain color specified in [member application/boot_splash/bg_color].
295292
</member>
293+
<member name="application/boot_splash/stretch_mode" type="int" setter="" getter="" default="1">
294+
Specifies how the splash image will be stretched. For the original size without stretching, set to disabled. See [enum RenderingServer.SplashStretchMode] constants for more information.
295+
</member>
296296
<member name="application/boot_splash/use_filter" type="bool" setter="" getter="" default="true">
297297
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).
298298
</member>

doc/classes/RenderingServer.xml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3446,14 +3446,24 @@
34463446
Sets the screen-space roughness limiter parameters, such as whether it should be enabled and its thresholds. Equivalent to [member ProjectSettings.rendering/anti_aliasing/screen_space_roughness_limiter/enabled], [member ProjectSettings.rendering/anti_aliasing/screen_space_roughness_limiter/amount] and [member ProjectSettings.rendering/anti_aliasing/screen_space_roughness_limiter/limit].
34473447
</description>
34483448
</method>
3449-
<method name="set_boot_image">
3449+
<method name="set_boot_image" deprecated="Use [method set_boot_image_with_stretch] instead.">
34503450
<return type="void" />
34513451
<param index="0" name="image" type="Image" />
34523452
<param index="1" name="color" type="Color" />
34533453
<param index="2" name="scale" type="bool" />
34543454
<param index="3" name="use_filter" type="bool" default="true" />
34553455
<description>
3456-
Sets a boot image. The color defines the background color. If [param scale] is [code]true[/code], the image will be scaled to fit the screen size. If [param use_filter] is [code]true[/code], the image will be scaled with linear interpolation. If [param use_filter] is [code]false[/code], the image will be scaled with nearest-neighbor interpolation.
3456+
Sets a boot image. The [param color] defines the background color. The value of [param scale] indicates if the image will be scaled to fit the screen size. If [param use_filter] is [code]true[/code], the image will be scaled with linear interpolation. If [param use_filter] is [code]false[/code], the image will be scaled with nearest-neighbor interpolation.
3457+
</description>
3458+
</method>
3459+
<method name="set_boot_image_with_stretch">
3460+
<return type="void" />
3461+
<param index="0" name="image" type="Image" />
3462+
<param index="1" name="color" type="Color" />
3463+
<param index="2" name="stretch_mode" type="int" enum="RenderingServer.SplashStretchMode" />
3464+
<param index="3" name="use_filter" type="bool" default="true" />
3465+
<description>
3466+
Sets a boot image. The [param color] defines the background color. The value of [param stretch_mode] indicates how the image will be stretched (see [enum SplashStretchMode] for possible values). If [param use_filter] is [code]true[/code], the image will be scaled with linear interpolation. If [param use_filter] is [code]false[/code], the image will be scaled with nearest-neighbor interpolation.
34573467
</description>
34583468
</method>
34593469
<method name="set_debug_generate_wireframes">
@@ -5982,6 +5992,24 @@
59825992
<constant name="PIPELINE_SOURCE_MAX" value="5" enum="PipelineSource">
59835993
Represents the size of the [enum PipelineSource] enum.
59845994
</constant>
5995+
<constant name="SPLASH_STRETCH_MODE_DISABLED" value="0" enum="SplashStretchMode">
5996+
No stretching is applied.
5997+
</constant>
5998+
<constant name="SPLASH_STRETCH_MODE_KEEP" value="1" enum="SplashStretchMode">
5999+
Stretches image to fullscreen while preserving aspect ratio.
6000+
</constant>
6001+
<constant name="SPLASH_STRETCH_MODE_KEEP_WIDTH" value="2" enum="SplashStretchMode">
6002+
Stretches the height of the image based on the width of the screen.
6003+
</constant>
6004+
<constant name="SPLASH_STRETCH_MODE_KEEP_HEIGHT" value="3" enum="SplashStretchMode">
6005+
Stretches the width of the image based on the height of the screen.
6006+
</constant>
6007+
<constant name="SPLASH_STRETCH_MODE_COVER" value="4" enum="SplashStretchMode">
6008+
Stretches the image to cover the entire screen while preserving aspect ratio.
6009+
</constant>
6010+
<constant name="SPLASH_STRETCH_MODE_IGNORE" value="5" enum="SplashStretchMode">
6011+
Stretches the image to cover the entire screen but doesn't preserve aspect ratio.
6012+
</constant>
59856013
<constant name="FEATURE_SHADERS" value="0" enum="Features" deprecated="This constant has not been used since Godot 3.0.">
59866014
</constant>
59876015
<constant name="FEATURE_MULTITHREADED" value="1" enum="Features" deprecated="This constant has not been used since Godot 3.0.">

drivers/gles3/rasterizer_gles3.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ void RasterizerGLES3::blit_render_targets_to_screen(DisplayServer::WindowID p_sc
463463
}
464464
}
465465

466-
void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
466+
void RasterizerGLES3::set_boot_image_with_stretch(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) {
467467
if (p_image.is_null() || p_image->is_empty()) {
468468
return;
469469
}
@@ -481,25 +481,7 @@ void RasterizerGLES3::set_boot_image(const Ref<Image> &p_image, const Color &p_c
481481
RID texture = texture_storage->texture_allocate();
482482
texture_storage->texture_2d_initialize(texture, p_image);
483483

484-
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
485-
Rect2 screenrect;
486-
if (p_scale) {
487-
if (win_size.width > win_size.height) {
488-
//scale horizontally
489-
screenrect.size.y = win_size.height;
490-
screenrect.size.x = imgrect.size.x * win_size.height / imgrect.size.y;
491-
screenrect.position.x = (win_size.width - screenrect.size.x) / 2;
492-
493-
} else {
494-
//scale vertically
495-
screenrect.size.x = win_size.width;
496-
screenrect.size.y = imgrect.size.y * win_size.width / imgrect.size.x;
497-
screenrect.position.y = (win_size.height - screenrect.size.y) / 2;
498-
}
499-
} else {
500-
screenrect = imgrect;
501-
screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor();
502-
}
484+
Rect2 screenrect = RenderingServer::get_splash_stretched_screen_rect(p_image->get_size(), win_size, p_stretch_mode);
503485

504486
#ifdef WINDOWS_ENABLED
505487
if (!screen_flipped_y)

drivers/gles3/rasterizer_gles3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class RasterizerGLES3 : public RendererCompositor {
9696
RendererCanvasRender *get_canvas() { return canvas; }
9797
RendererSceneRender *get_scene() { return scene; }
9898

99-
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
99+
void set_boot_image_with_stretch(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true);
100100

101101
void initialize();
102102
void begin_frame(double frame_step);

main/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3681,7 +3681,8 @@ void Main::setup_boot_logo() {
36813681

36823682
if (show_logo) { //boot logo!
36833683
const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
3684-
const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
3684+
3685+
const RenderingServer::SplashStretchMode boot_stretch_mode = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "application/boot_splash/stretch_mode", PROPERTY_HINT_ENUM, "Disabled,Keep,Keep Width,Keep Height,Cover,Ignore"), 1);
36853686
const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);
36863687
String boot_logo_path = GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String());
36873688

@@ -3721,7 +3722,7 @@ void Main::setup_boot_logo() {
37213722
boot_bg_color = GLOBAL_DEF_BASIC("application/boot_splash/bg_color", (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color);
37223723
#endif
37233724
if (boot_logo.is_valid()) {
3724-
RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, boot_logo_filter);
3725+
RenderingServer::get_singleton()->set_boot_image_with_stretch(boot_logo, boot_bg_color, boot_stretch_mode, boot_logo_filter);
37253726

37263727
} else {
37273728
#ifndef NO_DEFAULT_BOOT_LOGO
@@ -3735,7 +3736,7 @@ void Main::setup_boot_logo() {
37353736
MAIN_PRINT("Main: ClearColor");
37363737
RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
37373738
MAIN_PRINT("Main: Image");
3738-
RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
3739+
RenderingServer::get_singleton()->set_boot_image_with_stretch(splash, boot_bg_color, RenderingServer::SPLASH_STRETCH_MODE_DISABLED);
37393740
#endif
37403741
}
37413742

platform/ios/export/export_plugin.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,32 @@ HashMap<String, Variant> EditorExportPlatformIOS::get_custom_project_settings(co
9898
switch (image_scale_mode) {
9999
case 0: {
100100
String logo_path = get_project_setting(p_preset, "application/boot_splash/image");
101-
bool is_on = get_project_setting(p_preset, "application/boot_splash/fullsize");
101+
RenderingServer::SplashStretchMode stretch_mode = get_project_setting(p_preset, "application/boot_splash/stretch_mode");
102102
// If custom logo is not specified, Godot does not scale default one, so we should do the same.
103-
value = (is_on && logo_path.length() > 0) ? "scaleAspectFit" : "center";
103+
if (logo_path.is_empty()) {
104+
value = "center";
105+
} else {
106+
switch (stretch_mode) {
107+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_DISABLED: {
108+
value = "center";
109+
} break;
110+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_KEEP: {
111+
value = "scaleAspectFit";
112+
} break;
113+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_KEEP_WIDTH: {
114+
value = "scaleAspectFit";
115+
} break;
116+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_KEEP_HEIGHT: {
117+
value = "scaleAspectFit";
118+
} break;
119+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_COVER: {
120+
value = "scaleAspectFill";
121+
} break;
122+
case RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_IGNORE: {
123+
value = "scaleToFill";
124+
} break;
125+
}
126+
}
104127
} break;
105128
default: {
106129
value = storyboard_image_scale_mode[image_scale_mode - 1];

platform/web/export/export_plugin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ void EditorExportPlatformWeb::_fix_html(Vector<uint8_t> &p_html, const Ref<Edito
174174

175175
Vector<String> godot_splash_classes;
176176
godot_splash_classes.push_back("show-image--" + String(get_project_setting(p_preset, "application/boot_splash/show_image")));
177-
godot_splash_classes.push_back("fullsize--" + String(get_project_setting(p_preset, "application/boot_splash/fullsize")));
177+
RenderingServer::SplashStretchMode boot_splash_stretch_mode = get_project_setting(p_preset, "application/boot_splash/stretch_mode");
178+
godot_splash_classes.push_back("fullsize--" + String(((boot_splash_stretch_mode != RenderingServer::SplashStretchMode::SPLASH_STRETCH_MODE_DISABLED) ? "true" : "false")));
178179
godot_splash_classes.push_back("use-filter--" + String(get_project_setting(p_preset, "application/boot_splash/use_filter")));
179180
replaces["$GODOT_SPLASH_CLASSES"] = String(" ").join(godot_splash_classes);
180181
replaces["$GODOT_SPLASH"] = p_name + ".png";

servers/rendering/dummy/rasterizer_dummy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class RasterizerDummy : public RendererCompositor {
7676
RendererCanvasRender *get_canvas() override { return &canvas; }
7777
RendererSceneRender *get_scene() override { return &scene; }
7878

79+
void set_boot_image_with_stretch(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true) override {}
7980
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override {}
8081

8182
void initialize() override {}

servers/rendering/renderer_compositor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ RendererCompositor *RendererCompositor::create() {
4545
return _create_func();
4646
}
4747

48+
void RendererCompositor::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
49+
RenderingServer::SplashStretchMode stretch_mode = RenderingServer::map_scaling_option_to_stretch_mode(p_scale);
50+
set_boot_image_with_stretch(p_image, p_color, stretch_mode, p_use_filter);
51+
}
52+
4853
bool RendererCompositor::is_xr_enabled() const {
4954
return xr_enabled;
5055
}

0 commit comments

Comments
 (0)