SDL: PS2: allow setting framebuffer color depth (#16442)

From 659ec63b2eb9f36221a76f28c14453867d9b3409 Mon Sep 17 00:00:00 2001
From: Sawkez <[EMAIL REDACTED]>
Date: Sun, 4 Oct 2026 18:29:01 +0000
Subject: [PATCH] PS2: allow setting framebuffer color depth (#16442)

---
 docs/README-ps2.md              |  1 +
 include/SDL3/SDL_hints.h        | 13 +++++++++++++
 src/render/ps2/SDL_render_ps2.c | 13 +++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/docs/README-ps2.md b/docs/README-ps2.md
index 89916d59124d8..9d424d2668755 100644
--- a/docs/README-ps2.md
+++ b/docs/README-ps2.md
@@ -22,6 +22,7 @@ cmake --install build
 ## Hints
 - `SDL_HINT_PS2_GS_WIDTH`: Width of the framebuffer. Defaults to 640.
 - `SDL_HINT_PS2_GS_HEIGHT`: Height of the framebuffer. Defaults to 448.
+- `SDL_HINT_PS2_GS_COLOR_DEPTH`: Color depth of the framebuffer. Can be "32", "24" or "16". Defaults to 24.
 - `SDL_HINT_PS2_GS_PROGRESSIVE`: Whether to use progressive, instead of interlaced. Defaults to 0.
 - `SDL_HINT_PS2_GS_MODE`: Regional standard of the signal. "NTSC" (60hz), "PAL" (50hz) or "" (the console's region, default).
 
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 59b9a86001144..68b67cc071a75 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -3632,6 +3632,19 @@ extern "C" {
  */
 #define SDL_HINT_PS2_GS_MODE    "SDL_PS2_GS_MODE"
 
+/**
+ * A variable controlling the pixel storage mode of the PS2's framebuffer.
+ *
+ * The variable can be set to the following values:
+ *
+ * - "32"
+ * - "24" (default)
+ * - "16"
+ *
+ * \since This hint is available since SDL 3.4.20.
+ */
+#define SDL_HINT_PS2_GS_COLOR_DEPTH "SDL_PS2_GS_COLOR_DEPTH"
+
 /**
  * A variable controlling which Dispmanx layer to use on a Raspberry PI.
  *
diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c
index c469b24891ecd..55539fae23ab6 100644
--- a/src/render/ps2/SDL_render_ps2.c
+++ b/src/render/ps2/SDL_render_ps2.c
@@ -713,7 +713,20 @@ static bool PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_P
         }
     }
 
+    // GS color depth
     gsGlobal->PSM = GS_PSM_CT24;
+
+    hint = SDL_GetHint(SDL_HINT_PS2_GS_COLOR_DEPTH);
+    if (hint) {
+        if (SDL_strcmp(hint, "32") == 0) {
+            gsGlobal->PSM = GS_PSM_CT32;
+        } else if (SDL_strcmp(hint, "24") == 0) {
+            gsGlobal->PSM = GS_PSM_CT24;
+        } else if (SDL_strcmp(hint, "16") == 0) {
+            gsGlobal->PSM = GS_PSM_CT16;
+        }
+    }
+
     gsGlobal->PSMZ = GS_PSMZ_16S;
     gsGlobal->ZBuffering = GS_SETTING_OFF;
     gsGlobal->DoubleBuffering = GS_SETTING_ON;