Fix imgui being upside down on some backends.

Fixes #21761
This commit is contained in:
Henrik Rydgård
2026-06-01 10:53:41 +02:00
parent b164621606
commit 054a10d46b
4 changed files with 8 additions and 18 deletions
+4 -14
View File
@@ -116,28 +116,18 @@ void DisplayProperties::Print() {
rot_matrix.print();
}
Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordConvention, bool compensateYFlip) {
// Y-flip compensation is done elsewhere now.
Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordConvention) {
using namespace Lin;
// TODO: Should be able to share the y-flip logic here with the one in postprocessing/presentation, for example.
Matrix4x4 ortho;
switch (coordConvention) {
case CoordConvention::Vulkan:
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
break;
case CoordConvention::Direct3D11:
if (compensateYFlip) {
ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
} else {
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
}
ortho.setOrthoD3D(0.0f, xres, 0, yres, -1.0f, 1.0f);
break;
case CoordConvention::OpenGL:
default:
if (compensateYFlip) {
ortho.setOrthoGL(0.0f, xres, 0, yres, -1.0f, 1.0f);
} else {
ortho.setOrthoGL(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
}
ortho.setOrthoGL(0.0f, xres, yres, 0.0f, -1.0f, 1.0f);
break;
}
// Compensate for rotated display if needed.
+1 -1
View File
@@ -61,7 +61,7 @@ struct DisplayRect {
void RotateRectToDisplay(DisplayRect<float> &rect, float rtWidth, float rtHeight);
void RotateRectToDisplay(DisplayRect<int> &rect, int rtWidth, int rtHeight);
Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordConvention, bool compensateYFlip);
Lin::Matrix4x4 ComputeOrthoMatrix(float xres, float yres, CoordConvention coordConvention);
// Take this and run through translation. Returns "Portrait", "Landscape" or later "Square" (the latter being the square shape you get when you open a foldable phone).
std::string_view DeviceOrientationToString(DeviceOrientation orientation);
+2 -2
View File
@@ -1072,8 +1072,8 @@ void NativeFrame(GraphicsContext *graphicsContext) {
g_breakpoints.Frame();
// Apply the UIContext bounds as a 2D transformation matrix.
// NOTE: We compensate for the Y convention in the shaders, so we can use the same matrices in all backends.
Matrix4x4 ortho = ComputeOrthoMatrix(g_display.dp_xres, g_display.dp_yres, g_draw->GetDeviceCaps().coordConvention, false);
// NOTE: We compensate for the Y and Z conventions in the shaders, so we can use the same matrices in all backends.
Matrix4x4 ortho = ComputeOrthoMatrix(g_display.dp_xres, g_display.dp_yres, g_draw->GetDeviceCaps().coordConvention);
// Can be overridden by sceDisplay which may pass true for the second argument.
g_frameTiming.ComputePresentMode(g_draw, false);
+1 -1
View File
@@ -73,7 +73,7 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
viewport.MaxDepth = 1.0f;
draw->SetViewport(viewport);
Lin::Matrix4x4 mtx = ComputeOrthoMatrix(draw_data->DisplaySize.x, draw_data->DisplaySize.y, draw->GetDeviceCaps().coordConvention, true);
Lin::Matrix4x4 mtx = ComputeOrthoMatrix(draw_data->DisplaySize.x, draw_data->DisplaySize.y, draw->GetDeviceCaps().coordConvention);
Draw::VsTexColUB ub{};
memcpy(ub.WorldViewProj, mtx.getReadPtr(), sizeof(Lin::Matrix4x4));