sdl2-compat: updated for latest SDL3 changes as of bcbf09acdef71b550e837c8aaca67b08b:

From f539d9fb0a6ed4ecce8f6492eef32119bf98277a Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 10 May 2024 01:11:10 +0300
Subject: [PATCH] updated for latest SDL3 changes as of
 bcbf09acdef71b550e837c8aaca67b08b:

- struct SDL_RendererInfo changed: add a compat SDL2_RendererInfo, copy
  only up to 16 texture formats SDL_GetRendererInfo()
- adjust after AttachVirtualJoystickEx rename to AttachVirtualJoystick :
  copy the removed procedure from SDL3 as an SDL2 compat procedure.
---
 src/dynapi/SDL_dynapi_procs.h |  4 ++--
 src/sdl2_compat.c             | 43 ++++++++++++++++++++++++++++++++---
 src/sdl2_compat.h             | 11 +++++++++
 src/sdl2_protos.h             |  4 ++--
 src/sdl3_include_wrapper.h    | 10 ++++----
 src/sdl3_syms.h               |  5 ++--
 6 files changed, 62 insertions(+), 15 deletions(-)

diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index b0c3089..9985131 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -329,12 +329,12 @@ SDL_DYNAPI_PROC(void,SDL_UnionRect,(const SDL_Rect *a, const SDL_Rect *b, SDL_Re
 SDL_DYNAPI_PROC(SDL_bool,SDL_EnclosePoints,(const SDL_Point *a, int b, const SDL_Rect *c, SDL_Rect *d),(a,b,c,d),return)
 SDL_DYNAPI_PROC(SDL_bool,SDL_IntersectRectAndLine,(const SDL_Rect *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(int,SDL_GetNumRenderDrivers,(void),(),return)
-SDL_DYNAPI_PROC(int,SDL_GetRenderDriverInfo,(int a, SDL_RendererInfo *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRenderDriverInfo,(int a, SDL2_RendererInfo *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, int b, Uint32 c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return)
 SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRenderer,(SDL_Window *a),(a),return)
-SDL_DYNAPI_PROC(int,SDL_GetRendererInfo,(SDL_Renderer *a, SDL_RendererInfo *b),(a,b),return)
+SDL_DYNAPI_PROC(int,SDL_GetRendererInfo,(SDL_Renderer *a, SDL2_RendererInfo *b),(a,b),return)
 SDL_DYNAPI_PROC(int,SDL_GetRendererOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTexture,(SDL_Renderer *a, Uint32 b, int c, int d, int e),(a,b,c,d,e),return)
 SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index f29b898..847ca38 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3821,7 +3821,34 @@ SDL_GetShapedWindowMode(SDL_Window *window, SDL_WindowShapeMode *shape_mode)
 
 
 DECLSPEC int SDLCALL
-SDL_GetRenderDriverInfo(int idx, SDL_RendererInfo *info)
+SDL_GetRendererInfo(SDL_Renderer *renderer, SDL2_RendererInfo *info)
+{
+    SDL_RendererInfo info3;
+    unsigned int i;
+
+    SDL3_zerop(info);
+    if (SDL3_GetRendererInfo(renderer, &info3) < 0) {
+        return -1;
+    }
+
+    info->name = info3.name;
+    info->flags = info3.flags;
+    info->num_texture_formats = info3.num_texture_formats;
+    info->max_texture_width = info3.max_texture_width;
+    info->max_texture_height = info3.max_texture_height;
+
+    if (info->num_texture_formats > 16) {
+        info->num_texture_formats = 16;
+    }
+    for (i = 0; i < info->num_texture_formats; ++i) {
+        info->texture_formats[i] = info3.texture_formats[i];
+    }
+
+    return 0;
+}
+
+DECLSPEC int SDLCALL
+SDL_GetRenderDriverInfo(int idx, SDL2_RendererInfo *info)
 {
     const char *name = SDL3_GetRenderDriver(idx);
     if (!name) {
@@ -7391,7 +7418,17 @@ SDL_GameControllerHasRumbleTriggers(SDL_Gamepad *gamepad)
 DECLSPEC int SDLCALL
 SDL_JoystickAttachVirtual(SDL_JoystickType type, int naxes, int nbuttons, int nhats)
 {
-    const SDL_JoystickID jid = SDL3_AttachVirtualJoystick(type, naxes, nbuttons, nhats);
+    SDL_JoystickID jid;
+    SDL_VirtualJoystickDesc desc3;
+
+    SDL3_zero(desc3);
+    desc3.type = (Uint16)type;
+    desc3.naxes = (Uint16)naxes;
+    desc3.nbuttons = (Uint16)nbuttons;
+    desc3.nhats = (Uint16)nhats;
+
+    jid = SDL3_AttachVirtualJoystick(&desc3);
+
     SDL_NumJoysticks(); /* Refresh */
     return GetIndexFromJoystickInstance(jid);
 }
@@ -7428,7 +7465,7 @@ SDL_JoystickAttachVirtualEx(const SDL2_VirtualJoystickDesc *desc2)
     SETDESCFIELD(SendEffect);
     #undef SETDESCFIELD
 
-    jid = SDL3_AttachVirtualJoystickEx(&desc3);
+    jid = SDL3_AttachVirtualJoystick(&desc3);
     SDL_NumJoysticks(); /* Refresh */
     return GetIndexFromJoystickInstance(jid);
 }
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index a0610f5..458c5f2 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -369,6 +369,17 @@ typedef enum
     SDL_YUV_CONVERSION_AUTOMATIC    /**< BT.601 for SD content, BT.709 for HD content */
 } SDL_YUV_CONVERSION_MODE;
 
+
+typedef struct SDL2_RendererInfo
+{
+    const char *name;           /**< The name of the renderer */
+    Uint32 flags;               /**< Supported ::SDL_RendererFlags */
+    Uint32 num_texture_formats; /**< The number of available texture formats */
+    Uint32 texture_formats[16]; /**< The available texture formats */
+    int max_texture_width;      /**< The maximum texture width */
+    int max_texture_height;     /**< The maximum texture height */
+} SDL2_RendererInfo;
+
 #define SDL_VIRTUAL_JOYSTICK_DESC_VERSION 1
 
 typedef struct SDL2_VirtualJoystickDesc
diff --git a/src/sdl2_protos.h b/src/sdl2_protos.h
index 648365d..943d260 100644
--- a/src/sdl2_protos.h
+++ b/src/sdl2_protos.h
@@ -319,12 +319,12 @@ SDL2_PROTO(void,UnionRect,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c))
 SDL2_PROTO(SDL_bool,EnclosePoints,(const SDL_Point *a, int b, const SDL_Rect *c, SDL_Rect *d))
 SDL2_PROTO(SDL_bool,IntersectRectAndLine,(const SDL_Rect *a, int *b, int *c, int *d, int *e))
 SDL2_PROTO(int,GetNumRenderDrivers,(void))
-SDL2_PROTO(int,GetRenderDriverInfo,(int a, SDL_RendererInfo *b))
+SDL2_PROTO(int,GetRenderDriverInfo,(int a, SDL2_RendererInfo *b))
 SDL2_PROTO(int,CreateWindowAndRenderer,(int a, int b, Uint32 c, SDL_Window **d, SDL_Renderer **e))
 SDL2_PROTO(SDL_Renderer*,CreateRenderer,(SDL_Window *a, int b, Uint32 c))
 SDL2_PROTO(SDL_Renderer*,CreateSoftwareRenderer,(SDL_Surface *a))
 SDL2_PROTO(SDL_Renderer*,GetRenderer,(SDL_Window *a))
-SDL2_PROTO(int,GetRendererInfo,(SDL_Renderer *a, SDL_RendererInfo *b))
+SDL2_PROTO(int,GetRendererInfo,(SDL_Renderer *a, SDL2_RendererInfo *b))
 SDL2_PROTO(int,GetRendererOutputSize,(SDL_Renderer *a, int *b, int *c))
 SDL2_PROTO(SDL_Texture*,CreateTexture,(SDL_Renderer *a, Uint32 b, int c, int d, int e))
 SDL2_PROTO(SDL_Texture*,CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b))
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index f43b5b5..164dde6 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -60,7 +60,6 @@
 #define SDL_AtomicSet IGNORE_THIS_VERSION_OF_SDL_AtomicSet
 #define SDL_AtomicSetPtr IGNORE_THIS_VERSION_OF_SDL_AtomicSetPtr
 #define SDL_AttachVirtualJoystick IGNORE_THIS_VERSION_OF_SDL_AttachVirtualJoystick
-#define SDL_AttachVirtualJoystickEx IGNORE_THIS_VERSION_OF_SDL_AttachVirtualJoystickEx
 #define SDL_AudioDevicePaused IGNORE_THIS_VERSION_OF_SDL_AudioDevicePaused
 #define SDL_BindAudioStream IGNORE_THIS_VERSION_OF_SDL_BindAudioStream
 #define SDL_BindAudioStreams IGNORE_THIS_VERSION_OF_SDL_BindAudioStreams
@@ -235,6 +234,7 @@
 #define SDL_GetCurrentTime IGNORE_THIS_VERSION_OF_SDL_GetCurrentTime
 #define SDL_GetCurrentVideoDriver IGNORE_THIS_VERSION_OF_SDL_GetCurrentVideoDriver
 #define SDL_GetCursor IGNORE_THIS_VERSION_OF_SDL_GetCursor
+#define SDL_GetDateTimeLocalePreferences IGNORE_THIS_VERSION_OF_SDL_GetDateTimeLocalePreferences
 #define SDL_GetDayOfWeek IGNORE_THIS_VERSION_OF_SDL_GetDayOfWeek
 #define SDL_GetDayOfYear IGNORE_THIS_VERSION_OF_SDL_GetDayOfYear
 #define SDL_GetDaysInMonth IGNORE_THIS_VERSION_OF_SDL_GetDaysInMonth
@@ -1178,10 +1178,6 @@
 #undef SDL_AttachVirtualJoystick
 #endif
 
-#ifdef SDL_AttachVirtualJoystickEx
-#undef SDL_AttachVirtualJoystickEx
-#endif
-
 #ifdef SDL_AudioDevicePaused
 #undef SDL_AudioDevicePaused
 #endif
@@ -1878,6 +1874,10 @@
 #undef SDL_GetCursor
 #endif
 
+#ifdef SDL_GetDateTimeLocalePreferences
+#undef SDL_GetDateTimeLocalePreferences
+#endif
+
 #ifdef SDL_GetDayOfWeek
 #undef SDL_GetDayOfWeek
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 11c880b..a990117 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -305,7 +305,7 @@ SDL3_SYM(int,CreateWindowAndRenderer,(const char *a, int b, int c, SDL_WindowFla
 SDL3_SYM(SDL_Renderer*,CreateRenderer,(SDL_Window *a, const char *b, SDL_RendererFlags 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)
+SDL3_SYM(int,GetRendererInfo,(SDL_Renderer *a, SDL_RendererInfo *b),(a,b),return)
 SDL3_SYM_RENAMED(int,GetRendererOutputSize,GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return)
 SDL3_SYM(SDL_Texture*,CreateTexture,(SDL_Renderer *a, SDL_PixelFormatEnum b, int c, int d, int e),(a,b,c,d,e),return)
 SDL3_SYM(SDL_Texture*,CreateTextureFromSurface,(SDL_Renderer *a, SDL_Surface *b),(a,b),return)
@@ -643,9 +643,8 @@ SDL3_SYM_PASSTHROUGH(int,isupper,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,islower,(int a),(a),return)
 SDL3_SYM_RENAMED(int,JoystickGetPlayerIndex,GetJoystickPlayerIndex,(SDL_Joystick *a),(a),return)
 SDL3_SYM_RENAMED(int,GameControllerGetPlayerIndex,GetGamepadPlayerIndex,(SDL_GameController *a),(a),return)
-SDL3_SYM(SDL_JoystickID,AttachVirtualJoystick,(SDL_JoystickType a, int b, int c, int d),(a,b,c,d),return)
 SDL3_SYM(int,DetachVirtualJoystick,(SDL_JoystickID a),(a),return)
-SDL3_SYM(SDL_JoystickID,AttachVirtualJoystickEx,(const SDL_VirtualJoystickDesc *a),(a),return)
+SDL3_SYM(SDL_JoystickID,AttachVirtualJoystick,(const SDL_VirtualJoystickDesc *a),(a),return)
 SDL3_SYM_RENAMED(int,JoystickSetVirtualAxis,SetJoystickVirtualAxis,(SDL_Joystick *a, int b, Sint16 c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,JoystickSetVirtualButton,SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,JoystickSetVirtualHat,SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)