sdl2-compat: render: SDL_GetRenderDriverInfo removed and SDL_CreateRenderer changed.

From 6de111771ae347356637b344d10420a9df7ba3f1 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 13 Dec 2022 23:25:17 -0500
Subject: [PATCH] render: SDL_GetRenderDriverInfo removed and
 SDL_CreateRenderer changed.

---
 src/sdl2_compat.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++
 src/sdl3_syms.h   |  4 +--
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 5c81a1f..1f58efe 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -2267,6 +2267,87 @@ static void GestureProcessEvent(const SDL_Event *event3)
     }
 }
 
+
+DECLSPEC int SDLCALL
+SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
+{
+    const char *name = SDL3_GetRenderDriver(index);
+    if (!name) {
+        return -1;  /* assume SDL3_GetRenderDriver set the SDL error. */
+    }
+
+    SDL_zerop(info);
+    info->name = name;
+
+    /* these are the values that SDL2 returns. */
+    if ((SDL3_strcmp(name, "opengl") == 0) || (SDL3_strcmp(name, "opengles2") == 0)) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 4;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+        info->texture_formats[1] = SDL_PIXELFORMAT_ABGR8888;
+        info->texture_formats[2] = SDL_PIXELFORMAT_RGB888;
+        info->texture_formats[3] = SDL_PIXELFORMAT_BGR888;
+    } else if (SDL3_strcmp(name, "opengles") == 0) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
+        info->num_texture_formats = 1;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ABGR8888;
+    } else if (SDL3_strcmp(name, "direct3d") == 0) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 1;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+    } else if (SDL3_strcmp(name, "direct3d11") == 0) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 6;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+        info->texture_formats[1] = SDL_PIXELFORMAT_RGB888;
+        info->texture_formats[2] = SDL_PIXELFORMAT_YV12;
+        info->texture_formats[3] = SDL_PIXELFORMAT_IYUV;
+        info->texture_formats[4] = SDL_PIXELFORMAT_NV12;
+        info->texture_formats[5] = SDL_PIXELFORMAT_NV21;
+    } else if (SDL3_strcmp(name, "direct3d12") == 0) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 6;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+        info->texture_formats[1] = SDL_PIXELFORMAT_RGB888;
+        info->texture_formats[2] = SDL_PIXELFORMAT_YV12;
+        info->texture_formats[3] = SDL_PIXELFORMAT_IYUV;
+        info->texture_formats[4] = SDL_PIXELFORMAT_NV12;
+        info->texture_formats[5] = SDL_PIXELFORMAT_NV21;
+        info->max_texture_width = 16384;
+        info->max_texture_height = 16384;
+    } else if (SDL3_strcmp(name, "metal") == 0) {
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 6;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+        info->texture_formats[1] = SDL_PIXELFORMAT_ABGR8888;
+        info->texture_formats[2] = SDL_PIXELFORMAT_YV12;
+        info->texture_formats[3] = SDL_PIXELFORMAT_IYUV;
+        info->texture_formats[4] = SDL_PIXELFORMAT_NV12;
+        info->texture_formats[5] = SDL_PIXELFORMAT_NV21;
+    } else if (SDL3_strcmp(name, "software") == 0) {
+        info->flags = SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+    } else {  /* this seems reasonable if something currently-unknown shows up in SDL3. */
+        info->flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE;
+        info->num_texture_formats = 1;
+        info->texture_formats[0] = SDL_PIXELFORMAT_ARGB8888;
+    }
+    return 0;
+}
+
+/* Second parameter changed from an index to a string in SDL3. */
+DECLSPEC SDL_Renderer *SDLCALL
+SDL_CreateRenderer(SDL_Window *window, int index, Uint32 flags)
+{
+    const char *name = NULL;
+    if (index != -1) {
+        name = SDL3_GetRenderDriver(index);
+        if (!name) {
+            return NULL;  /* assume SDL3_GetRenderDriver set the SDL error. */
+        }
+    }
+    return SDL3_CreateRenderer(window, name, flags);
+}
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 07a5cfb..e19aeff 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -312,9 +312,9 @@ SDL3_SYM_PASSTHROUGH(void,UnionRect,(const SDL_Rect *a, const SDL_Rect *b, SDL_R
 SDL3_SYM_PASSTHROUGH(SDL_bool,EnclosePoints,(const SDL_Point *a, int b, const SDL_Rect *c, SDL_Rect *d),(a,b,c,d),return)
 SDL3_SYM_PASSTHROUGH(SDL_bool,IntersectRectAndLine,(const SDL_Rect *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
 SDL3_SYM_PASSTHROUGH(int,GetNumRenderDrivers,(void),(),return)
-SDL3_SYM_PASSTHROUGH(int,GetRenderDriverInfo,(int a, SDL_RendererInfo *b),(a,b),return)
+SDL3_SYM(const char *,GetRenderDriver,(int a),(a),return);
 SDL3_SYM_PASSTHROUGH(int,CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return)
-SDL3_SYM_PASSTHROUGH(SDL_Renderer*,CreateRenderer,(SDL_Window *a, int b, Uint32 c),(a,b,c),return)
+SDL3_SYM(SDL_Renderer*,CreateRenderer,(SDL_Window *a, const char *b, Uint32 c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(SDL_Renderer*,CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_Renderer*,GetRenderer,(SDL_Window *a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,GetRendererInfo,(SDL_Renderer *a, SDL_RendererInfo *b),(a,b),return)