SDL: Account for indexed formats when matching texture formats

From c61497b744f64806eeea1b3d8289a5c97ca862da Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 3 Dec 2025 21:21:52 -0800
Subject: [PATCH] Account for indexed formats when matching texture formats

Fixes https://github.com/libsdl-org/SDL/issues/14569
---
 src/render/SDL_render.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index a3c063215cc54..c33a232099010 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1476,11 +1476,13 @@ static SDL_PixelFormat GetClosestSupportedFormat(SDL_Renderer *renderer, SDL_Pix
         }
     } else {
         bool hasAlpha = SDL_ISPIXELFORMAT_ALPHA(format);
+        bool isIndexed = SDL_ISPIXELFORMAT_INDEXED(format);
 
         // We just want to match the first format that has the same channels
         for (i = 0; i < renderer->num_texture_formats; ++i) {
             if (!SDL_ISPIXELFORMAT_FOURCC(renderer->texture_formats[i]) &&
-                SDL_ISPIXELFORMAT_ALPHA(renderer->texture_formats[i]) == hasAlpha) {
+                SDL_ISPIXELFORMAT_ALPHA(renderer->texture_formats[i]) == hasAlpha &&
+                SDL_ISPIXELFORMAT_INDEXED(renderer->texture_formats[i]) == isIndexed) {
                 return renderer->texture_formats[i];
             }
         }