summaryrefslogtreecommitdiffstats
path: root/servers/rendering/renderer_rd
diff options
context:
space:
mode:
authorClay John <claynjohn@gmail.com>2024-10-29 12:34:40 -0700
committerGitHub <noreply@github.com>2024-10-29 12:34:40 -0700
commit748f4079e387fb555ee64c1619e94ba099bfa77a (patch)
treee296233766ae58d195f16c5e9f30191f7ba64ad8 /servers/rendering/renderer_rd
parent08f9cba0fbf27f171dea55de6f8274928b9f0d84 (diff)
parentaaa0e2fddfead4a31afddc07a26cd6af0c19dacd (diff)
downloadredot-engine-748f4079e387fb555ee64c1619e94ba099bfa77a.tar.gz
Merge pull request #96439 from darksylinc/matias-TheForge-pr03-rebased
Add Swappy & Pre-Transformed Swapchain
Diffstat (limited to 'servers/rendering/renderer_rd')
-rw-r--r--servers/rendering/renderer_rd/renderer_compositor_rd.cpp14
-rw-r--r--servers/rendering/renderer_rd/renderer_compositor_rd.h4
-rw-r--r--servers/rendering/renderer_rd/shaders/blit.glsl18
3 files changed, 34 insertions, 2 deletions
diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
index 84ea6a5da2..d04285fbb4 100644
--- a/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
+++ b/servers/rendering/renderer_rd/renderer_compositor_rd.cpp
@@ -66,6 +66,16 @@ void RendererCompositorRD::blit_render_targets_to_screen(DisplayServer::WindowID
RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array);
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, render_target_descriptors[rd_texture], 0);
+ // We need to invert the phone rotation.
+ int screen_rotation_degrees = -DisplayServer::get_singleton()->screen_get_internal_current_rotation();
+ float screen_rotation = Math::deg_to_rad((float)screen_rotation_degrees);
+
+ blit.push_constant.rotation_cos = Math::cos(screen_rotation);
+ blit.push_constant.rotation_sin = Math::sin(screen_rotation);
+ // Swap width and height when the orientation is not the native one.
+ if (screen_rotation_degrees % 180 != 0) {
+ SWAP(screen_size.width, screen_size.height);
+ }
blit.push_constant.src_rect[0] = p_render_targets[i].src_rect.position.x;
blit.push_constant.src_rect[1] = p_render_targets[i].src_rect.position.y;
blit.push_constant.src_rect[2] = p_render_targets[i].src_rect.size.width;
@@ -228,6 +238,10 @@ void RendererCompositorRD::set_boot_image(const Ref<Image> &p_image, const Color
RD::get_singleton()->draw_list_bind_index_array(draw_list, blit.array);
RD::get_singleton()->draw_list_bind_uniform_set(draw_list, uset, 0);
+ int screen_rotation_degrees = DisplayServer::get_singleton()->screen_get_internal_current_rotation();
+ float screen_rotation = Math::deg_to_rad((float)screen_rotation_degrees);
+ blit.push_constant.rotation_cos = Math::cos(screen_rotation);
+ blit.push_constant.rotation_sin = Math::sin(screen_rotation);
blit.push_constant.src_rect[0] = 0.0;
blit.push_constant.src_rect[1] = 0.0;
blit.push_constant.src_rect[2] = 1.0;
diff --git a/servers/rendering/renderer_rd/renderer_compositor_rd.h b/servers/rendering/renderer_rd/renderer_compositor_rd.h
index 2547f08715..121ed4cdb1 100644
--- a/servers/rendering/renderer_rd/renderer_compositor_rd.h
+++ b/servers/rendering/renderer_rd/renderer_compositor_rd.h
@@ -74,6 +74,10 @@ protected:
float src_rect[4];
float dst_rect[4];
+ float rotation_sin;
+ float rotation_cos;
+ float pad[2];
+
float eye_center[2];
float k1;
float k2;
diff --git a/servers/rendering/renderer_rd/shaders/blit.glsl b/servers/rendering/renderer_rd/shaders/blit.glsl
index d451647bec..fe6416f03c 100644
--- a/servers/rendering/renderer_rd/shaders/blit.glsl
+++ b/servers/rendering/renderer_rd/shaders/blit.glsl
@@ -8,6 +8,10 @@ layout(push_constant, std140) uniform Pos {
vec4 src_rect;
vec4 dst_rect;
+ float rotation_sin;
+ float rotation_cos;
+ vec2 pad;
+
vec2 eye_center;
float k1;
float k2;
@@ -15,17 +19,23 @@ layout(push_constant, std140) uniform Pos {
float upscale;
float aspect_ratio;
uint layer;
- uint pad1;
+ bool convert_to_srgb;
}
data;
layout(location = 0) out vec2 uv;
void main() {
+ mat4 swapchain_transform = mat4(1.0);
+ swapchain_transform[0][0] = data.rotation_cos;
+ swapchain_transform[0][1] = -data.rotation_sin;
+ swapchain_transform[1][0] = data.rotation_sin;
+ swapchain_transform[1][1] = data.rotation_cos;
+
vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0));
uv = data.src_rect.xy + base_arr[gl_VertexIndex] * data.src_rect.zw;
vec2 vtx = data.dst_rect.xy + base_arr[gl_VertexIndex] * data.dst_rect.zw;
- gl_Position = vec4(vtx * 2.0 - 1.0, 0.0, 1.0);
+ gl_Position = swapchain_transform * vec4(vtx * 2.0 - 1.0, 0.0, 1.0);
}
#[fragment]
@@ -38,6 +48,10 @@ layout(push_constant, std140) uniform Pos {
vec4 src_rect;
vec4 dst_rect;
+ float rotation_sin;
+ float rotation_cos;
+ vec2 pad;
+
vec2 eye_center;
float k1;
float k2;