summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-19 00:38:40 +0100
committerGitHub <noreply@github.com>2022-01-19 00:38:40 +0100
commitf8b8d0d4b82a5eb6ea3829398fd5076f1c49c148 (patch)
tree176154a1ea3e516f18448d03f8bdf96e7c8d6958 /drivers
parent7a9c006b6e9064a0ec897cf071fc49d260034ed2 (diff)
parentfcc9f5ce396ff921ed8253f657a8c9c38e7a878d (diff)
Merge pull request #22488 from samuelpedrajas/splash_new_scaling_modes
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/rasterizer_gles3.cpp87
-rw-r--r--drivers/gles3/rasterizer_gles3.h2
2 files changed, 62 insertions, 27 deletions
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index 32ead8aa7e..f7b33763ce 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<Image> &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<Image> &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;
-
- } 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();
+ 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;
+
+ 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 a641e189c5..24e9e99ae2 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<Image> &p_image, const Color &p_color, bool p_scale, bool p_use_filter = true);
+ void set_boot_image(const Ref<Image> &p_image, const Color &p_color, RenderingServer::SplashStretchMode p_stretch_mode, bool p_use_filter = true);
void initialize();
void begin_frame(double frame_step);