diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 357186b9179..bcd576d7ab6 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -196,9 +196,6 @@
Background color for the boot splash.
-
- 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.
-
Path to an image used as the boot splash. If left empty, the default Godot Engine splash will be displayed instead.
[b]Note:[/b] Only effective if [member application/boot_splash/show_image] is [code]true[/code].
@@ -206,6 +203,9 @@
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].
+
+ Specifies how the splash image will be stretched. See [enum RenderingServer.SplashStretchMode] constants for more information.
+
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 9e783720139..9c41b7472b8 100644
--- a/doc/classes/RenderingServer.xml
+++ b/doc/classes/RenderingServer.xml
@@ -2657,10 +2657,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 (see [enum SplashStretchMode] for possible values). 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.
@@ -4504,6 +4504,24 @@
+
+ The splash image uses its default pixel size.
+
+
+ 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 without keeping the aspect ratio.
+
Hardware supports shaders. This enum is currently unused in Godot 3.x.
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index 32ead8aa7ee..f7b33763ce9 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -298,54 +298,89 @@ void RasterizerGLES3::blit_render_targets_to_screen(DisplayServer::WindowID p_sc
}
}
-void RasterizerGLES3::set_boot_image(const Ref &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
- if (p_image.is_null() || p_image->is_empty())
+void RasterizerGLES3::set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter) {
+ if (p_image.is_null() || p_image->is_empty()) {
return;
+ }
- Size2i win_size = DisplayServer::get_singleton()->screen_get_size();
+ Size2 window_size = DisplayServer::get_singleton()->screen_get_size();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
- glViewport(0, 0, win_size.width, win_size.height);
+ glViewport(0, 0, window_size.width, window_size.height);
glDisable(GL_BLEND);
glDepthMask(GL_FALSE);
- if (false) {
- // if (OS::get_singleton()->get_window_per_pixel_transparency_enabled()) {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- } else {
- glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
- }
+ glClearColor(p_color.r, p_color.g, p_color.b, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
canvas.canvas_begin();
RID texture = storage.texture_create();
+ // FIXME: Handle p_filter.
//storage.texture_allocate(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), VS::TEXTURE_TYPE_2D, p_use_filter ? VS::TEXTURE_FLAG_FILTER : 0);
storage._texture_allocate_internal(texture, p_image->get_width(), p_image->get_height(), 0, p_image->get_format(), RenderingDevice::TEXTURE_TYPE_2D);
storage.texture_set_data(texture, p_image);
+ // Stretch code synced with RendererCompositorRD.
Rect2 imgrect(0, 0, p_image->get_width(), p_image->get_height());
Rect2 screenrect;
- if (p_scale) {
- if (win_size.width > win_size.height) {
- //scale horizontally
- screenrect.size.y = win_size.height;
- screenrect.size.x = imgrect.size.x * win_size.height / imgrect.size.y;
- screenrect.position.x = (win_size.width - screenrect.size.x) / 2;
+ switch (p_stretch_mode) {
+ case RenderingServer::SPLASH_STRETCH_MODE_DISABLED: {
+ screenrect = imgrect;
+ screenrect.position += ((window_size - screenrect.size) / 2.0).floor();
+ } break;
+ case RenderingServer::SPLASH_STRETCH_MODE_KEEP: {
+ 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;
+ }
+ } break;
+ case 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;
+ } break;
+ case 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;
+ } break;
+ case RenderingServer::SPLASH_STRETCH_MODE_COVER: {
+ double window_aspect = (double)window_size.width / window_size.height;
+ double img_aspect = imgrect.size.x / imgrect.size.y;
- } else {
- //scale vertically
- screenrect.size.x = win_size.width;
- screenrect.size.y = imgrect.size.y * win_size.width / imgrect.size.x;
- screenrect.position.y = (win_size.height - screenrect.size.y) / 2;
- }
- } else {
- screenrect = imgrect;
- screenrect.position += ((Size2(win_size.width, win_size.height) - screenrect.size) / 2.0).floor();
+ 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;
+ }
+ } break;
+ case RenderingServer::SPLASH_STRETCH_MODE_EXPAND: {
+ screenrect.size.x = window_size.width;
+ screenrect.size.y = window_size.height;
+ } break;
}
+ // FIXME: Actually draw the image after binding it, using screenrect for scaling.
+
RasterizerStorageGLES3::Texture *t = storage.texture_owner.get_or_null(texture);
glActiveTexture(GL_TEXTURE0 + storage.config.max_texture_image_units - 1);
glBindTexture(GL_TEXTURE_2D, t->tex_id);
+ //canvas->draw_generic_textured_rect(screenrect, Rect2(0, 0, 1, 1));
glBindTexture(GL_TEXTURE_2D, 0);
canvas.canvas_end();
diff --git a/drivers/gles3/rasterizer_gles3.h b/drivers/gles3/rasterizer_gles3.h
index a641e189c5f..24e9e99ae24 100644
--- a/drivers/gles3/rasterizer_gles3.h
+++ b/drivers/gles3/rasterizer_gles3.h
@@ -57,7 +57,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 = true);
+ void set_boot_image(const Ref &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true);
void initialize();
void begin_frame(double frame_step);
diff --git a/main/main.cpp b/main/main.cpp
index 8b586414618..add37def8ca 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1728,11 +1728,15 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
if (show_logo) { //boot logo!
const bool boot_logo_image = GLOBAL_DEF("application/boot_splash/show_image", true);
const String boot_logo_path = String(GLOBAL_DEF("application/boot_splash/image", String())).strip_edges();
- const bool boot_logo_scale = GLOBAL_DEF("application/boot_splash/fullsize", true);
+ const RenderingServer::SplashStretchMode boot_stretch_mode =
+ (RenderingServer::SplashStretchMode)(int)GLOBAL_DEF("application/boot_splash/stretch_mode", RenderingServer::SPLASH_STRETCH_MODE_KEEP);
const 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::INT, "application/boot_splash/stretch_mode",
+ PROPERTY_HINT_ENUM, "Disabled,Keep,Keep Width,Keep Height,Cover,Expand")); // Sync with RenderingServer::SplashStretchMode.
ProjectSettings::get_singleton()->set_custom_property_info("application/boot_splash/image",
- PropertyInfo(Variant::STRING,
- "application/boot_splash/image",
+ PropertyInfo(Variant::STRING, "application/boot_splash/image",
PROPERTY_HINT_FILE, "*.png"));
Ref boot_logo;
@@ -1760,9 +1764,8 @@ 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,
- boot_logo_filter);
-
+ RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color,
+ boot_stretch_mode, boot_logo_filter);
} else {
#ifndef NO_DEFAULT_BOOT_LOGO
MAIN_PRINT("Main: Create bootsplash");
@@ -1775,7 +1778,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 83da8388e41..5b12b757a34 100644
--- a/servers/rendering/rasterizer_dummy.h
+++ b/servers/rendering/rasterizer_dummy.h
@@ -763,7 +763,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 f245af9a4ad..96a3c8af9f0 100644
--- a/servers/rendering/renderer_compositor.h
+++ b/servers/rendering/renderer_compositor.h
@@ -76,7 +76,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 2f8ef696cdd..009a39749cc 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,22 +182,56 @@ 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 (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
+ switch (p_stretch_mode) {
+ case RenderingServer::SPLASH_STRETCH_MODE_DISABLED: {
+ screenrect = imgrect;
+ screenrect.position += ((window_size - screenrect.size) / 2.0).floor();
+ } break;
+ case RenderingServer::SPLASH_STRETCH_MODE_KEEP: {
+ 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;
+ }
+ } break;
+ case 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 {
- screenrect = imgrect;
- screenrect.position += ((window_size - screenrect.size) / 2.0).floor();
+ } break;
+ case 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;
+ } break;
+ case 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;
+ }
+ } break;
+ case RenderingServer::SPLASH_STRETCH_MODE_EXPAND: {
+ screenrect.size.x = window_size.width;
+ screenrect.size.y = window_size.height;
+ } break;
}
screenrect.position /= window_size;
diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.h b/servers/rendering/renderer_rd/renderer_compositor_rd.h
index 9a992d58196..6cfd6fa11bc 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 d7e9d210db5..734206c70bf 100644
--- a/servers/rendering/rendering_server_default.cpp
+++ b/servers/rendering/rendering_server_default.cpp
@@ -273,9 +273,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 ee684c69ed9..dabea9175ef 100644
--- a/servers/rendering/rendering_server_default.h
+++ b/servers/rendering/rendering_server_default.h
@@ -907,7 +907,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 863aae6e4c2..786cd8ad92b 100644
--- a/servers/rendering_server.cpp
+++ b/servers/rendering_server.cpp
@@ -2730,7 +2730,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);
@@ -2751,6 +2751,13 @@ void RenderingServer::_bind_methods() {
BIND_ENUM_CONSTANT(RENDERING_INFO_BUFFER_MEM_USED);
BIND_ENUM_CONSTANT(RENDERING_INFO_VIDEO_MEM_USED);
+ BIND_ENUM_CONSTANT(SPLASH_STRETCH_MODE_DISABLED);
+ 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(FEATURE_SHADERS);
BIND_ENUM_CONSTANT(FEATURE_MULTITHREADED);
diff --git a/servers/rendering_server.h b/servers/rendering_server.h
index 945fd052c6e..21728af8c40 100644
--- a/servers/rendering_server.h
+++ b/servers/rendering_server.h
@@ -1510,7 +1510,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_DISABLED,
+ SPLASH_STRETCH_MODE_KEEP,
+ SPLASH_STRETCH_MODE_KEEP_WIDTH,
+ SPLASH_STRETCH_MODE_KEEP_HEIGHT,
+ SPLASH_STRETCH_MODE_COVER,
+ SPLASH_STRETCH_MODE_EXPAND,
+ };
+
+ 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 {
@@ -1624,6 +1633,7 @@ VARIANT_ENUM_CAST(RenderingServer::CanvasLightShadowFilter);
VARIANT_ENUM_CAST(RenderingServer::CanvasOccluderPolygonCullMode);
VARIANT_ENUM_CAST(RenderingServer::GlobalVariableType);
VARIANT_ENUM_CAST(RenderingServer::RenderingInfo);
+VARIANT_ENUM_CAST(RenderingServer::SplashStretchMode);
VARIANT_ENUM_CAST(RenderingServer::Features);
VARIANT_ENUM_CAST(RenderingServer::CanvasTextureChannel);
VARIANT_ENUM_CAST(RenderingServer::BakeChannels);