This commit is contained in:
Samuel 2021-11-11 18:23:41 +11:00 committed by GitHub
commit 09b724838f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 103 additions and 15 deletions

View file

@ -196,11 +196,14 @@
Background color for the boot splash.
</member>
<member name="application/boot_splash/fullsize" type="bool" setter="" getter="" default="true">
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.
</member>
<member name="application/boot_splash/image" type="String" setter="" getter="" default="&quot;&quot;">
Path to an image used as the boot splash.
</member>
<member name="application/boot_splash/stretch_mode" type="String" setter="" getter="" default="&quot;keep&quot;">
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.
</member>
<member name="application/boot_splash/use_filter" type="bool" setter="" getter="" default="true">
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).
</member>

View file

@ -2623,10 +2623,10 @@
<return type="void" />
<argument index="0" name="image" type="Image" />
<argument index="1" name="color" type="Color" />
<argument index="2" name="scale" type="bool" />
<argument index="2" name="stretch_mode" type="int" enum="RenderingServer.SplashStretchMode" />
<argument index="3" name="use_filter" type="bool" default="true" />
<description>
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.
</description>
</method>
<method name="set_debug_generate_wireframes">
@ -4427,5 +4427,23 @@
<constant name="FEATURE_MULTITHREADED" value="1" enum="Features">
Hardware supports multithreading. This enum is currently unused in Godot 3.x.
</constant>
<constant name="SPLASH_STRETCH_MODE_KEEP" value="0" enum="SplashStretchMode">
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.
</constant>
<constant name="SPLASH_STRETCH_MODE_KEEP_WIDTH" value="1" enum="SplashStretchMode">
The splash image is stretched to have the same width as the window. It keeps the image's aspect ratio.
</constant>
<constant name="SPLASH_STRETCH_MODE_KEEP_HEIGHT" value="2" enum="SplashStretchMode">
The splash image is stretched to have the same height as the window. It keeps the image's aspect ratio.
</constant>
<constant name="SPLASH_STRETCH_MODE_COVER" value="3" enum="SplashStretchMode">
The splash image covers the window while keeping the aspect ratio.
</constant>
<constant name="SPLASH_STRETCH_MODE_EXPAND" value="4" enum="SplashStretchMode">
The splash image covers the window witohut keeping the aspect ratio.
</constant>
<constant name="SPLASH_STRETCH_MODE_DISABLED" value="5" enum="SplashStretchMode">
The splash image uses its default pixel size.
</constant>
</constants>
</class>

View file

@ -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<Image> 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
}

View file

@ -757,7 +757,7 @@ public:
RendererCanvasRender *get_canvas() override { return &canvas; }
RendererSceneRender *get_scene() override { return &scene; }
void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override {}
void set_boot_image(const Ref<Image> &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 {

View file

@ -75,7 +75,7 @@ public:
virtual RendererCanvasRender *get_canvas() = 0;
virtual RendererSceneRender *get_scene() = 0;
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) = 0;
virtual void set_boot_image(const Ref<Image> &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;

View file

@ -159,7 +159,7 @@ 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) {
void RendererCompositorRD::set_boot_image(const Ref<Image> &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<Image> &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;

View file

@ -90,7 +90,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, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter);
void initialize();
void begin_frame(double frame_step);

View file

@ -269,9 +269,9 @@ Vector<RenderingServer::FrameProfileArea> RenderingServerDefault::get_frame_prof
/* TESTING */
void RenderingServerDefault::set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter) {
void RenderingServerDefault::set_boot_image(const Ref<Image> &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) {

View file

@ -898,7 +898,7 @@ public:
virtual double get_frame_setup_time_cpu() const override;
virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true) override;
virtual void set_boot_image(const Ref<Image> &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;

View file

@ -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"));

View file

@ -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<Plane> &p_planes);
virtual void set_boot_image(const Ref<Image> &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<Image> &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