sdl2-compat: Updated to the latest SDL3 changes, including joystick/gamepad properties

From be9aa9e0e26b7b94abf074fe11a5f212c8f4626a Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 27 Jan 2024 19:29:39 -0800
Subject: [PATCH] Updated to the latest SDL3 changes, including
 joystick/gamepad properties

---
 src/sdl2_compat.c          | 74 +++++++++++++++-----------------------
 src/sdl3_include_wrapper.h | 10 ------
 src/sdl3_syms.h            |  4 +--
 3 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 62727f4..107f93e 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -6444,11 +6444,11 @@ SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh)
     /* always flush the renderer here; good enough. SDL2 only flushed if the texture might have changed, but we'll be conservative. */
     SDL3_FlushRenderer(renderer);
 
-    if ((tex = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_NUMBER, -1)) != -1) {  // opengl renderer.
-        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_TARGET, 0);
-        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_UV_NUMBER, 0);
-        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_U_NUMBER, 0);
-        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_V_NUMBER, 0);
+    if ((tex = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1)) != -1) {  // opengl renderer.
+        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET, 0);
+        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER, 0);
+        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER, 0);
+        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER, 0);
 
         SDL_bool okay = SDL_TRUE;
         GLFN(glEnable);
@@ -6475,16 +6475,16 @@ SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh)
         pglBindTexture((GLenum) target, (GLuint) tex);
 
         if (texw) {
-            *texw = SDL3_GetFloatProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEX_W_FLOAT, 1.0f);
+            *texw = SDL3_GetFloatProperty(props, SDL_PROP_TEXTURE_OPENGL_TEX_W_FLOAT, 1.0f);
         }
         if (texh) {
-            *texh = SDL3_GetFloatProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEX_H_FLOAT, 1.0f);
+            *texh = SDL3_GetFloatProperty(props, SDL_PROP_TEXTURE_OPENGL_TEX_H_FLOAT, 1.0f);
         }
-    } else if ((tex = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_NUMBER, -1)) != -1) {  // opengles2 renderer.
-        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_TARGET, 0);
-        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, 0);
-        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, 0);
-        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER, 0);
+    } else if ((tex = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER, -1)) != -1) {  // opengles2 renderer.
+        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET, 0);
+        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, 0);
+        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, 0);
+        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER, 0);
 
         SDL_bool okay = SDL_TRUE;
         GLFN(glActiveTexture);
@@ -6536,11 +6536,11 @@ SDL_GL_UnbindTexture(SDL_Texture *texture)
         return -1;
     }
 
-    if ((tex = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_NUMBER, -1)) != -1) {  // opengl renderer.
-        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_TARGET, 0);
-        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_UV_NUMBER, 0);
-        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_U_NUMBER, 0);
-        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGL_TEXTURE_V_NUMBER, 0);
+    if ((tex = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_NUMBER, -1)) != -1) {  // opengl renderer.
+        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_TARGET, 0);
+        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER, 0);
+        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER, 0);
+        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER, 0);
 
         SDL_bool okay = SDL_TRUE;
         GLFN(glDisable);
@@ -6567,11 +6567,11 @@ SDL_GL_UnbindTexture(SDL_Texture *texture)
         }
         pglBindTexture((GLenum) target, 0);
         pglDisable((GLenum) target);
-    } else if ((tex = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_NUMBER, -1)) != -1) {  // opengles2 renderer.
-        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_TARGET, 0);
-        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, 0);
-        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, 0);
-        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROPERTY_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER, 0);
+    } else if ((tex = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER, -1)) != -1) {  // opengles2 renderer.
+        const Sint64 target = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET, 0);
+        const Sint64 uv = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, 0);
+        const Sint64 u = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, 0);
+        const Sint64 v = SDL3_GetNumberProperty(props, SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER, 0);
 
         SDL_bool okay = SDL_TRUE;
         GLFN(glActiveTexture);
@@ -6834,28 +6834,19 @@ SDL_JoystickPathForIndex(int idx)
 DECLSPEC SDL_bool SDLCALL
 SDL_JoystickHasLED(SDL_Joystick *joystick)
 {
-    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_RGB_LED) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC SDL_bool SDLCALL
 SDL_JoystickHasRumble(SDL_Joystick *joystick)
 {
-    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_RUMBLE) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetJoystickProperties(joystick), SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC SDL_bool SDLCALL
 SDL_JoystickHasRumbleTriggers(SDL_Joystick *joystick)
 {
-    if (SDL3_GetJoystickCaps(joystick) & SDL_JOYSTICK_CAP_TRIGGER_RUMBLE) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetJoystickProperties(joystick), SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC char* SDLCALL
@@ -7056,28 +7047,19 @@ SDL_GameControllerGetBindForButton(SDL_GameController *controller,
 DECLSPEC SDL_bool SDLCALL
 SDL_GameControllerHasLED(SDL_Gamepad *gamepad)
 {
-    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_RGB_LED) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetGamepadProperties(gamepad), SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC SDL_bool SDLCALL
 SDL_GameControllerHasRumble(SDL_Gamepad *gamepad)
 {
-    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_RUMBLE) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetGamepadProperties(gamepad), SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC SDL_bool SDLCALL
 SDL_GameControllerHasRumbleTriggers(SDL_Gamepad *gamepad)
 {
-    if (SDL3_GetGamepadCaps(gamepad) & SDL_GAMEPAD_CAP_TRIGGER_RUMBLE) {
-        return SDL_TRUE;
-    }
-    return SDL_FALSE;
+    return SDL3_GetBooleanProperty(SDL3_GetGamepadProperties(gamepad), SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN, SDL_FALSE);
 }
 
 DECLSPEC int SDLCALL
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index b234268..f665cda 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -993,8 +993,6 @@
 #define SDL_GetHapticName IGNORE_THIS_VERSION_OF_SDL_GetHapticName
 #define SDL_ReadSurfacePixel IGNORE_THIS_VERSION_OF_SDL_ReadSurfacePixel
 #define SDL_FlipSurface IGNORE_THIS_VERSION_OF_SDL_FlipSurface
-#define SDL_GetJoystickCaps IGNORE_THIS_VERSION_OF_SDL_GetJoystickCaps
-#define SDL_GetGamepadCaps IGNORE_THIS_VERSION_OF_SDL_GetGamepadCaps
 
 
 #define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
@@ -4859,14 +4857,6 @@
 #undef SDL_FlipSurface
 #endif
 
-#ifdef SDL_GetJoystickCaps
-#undef SDL_GetJoystickCaps
-#endif
-
-#ifdef SDL_GetGamepadCaps
-#undef SDL_GetGamepadCaps
-#endif
-
 #undef SDL_ThreadID /* see at top. */
 
 /* undefine these macros, too: redefine as SDL3_xxx, if needed. */
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index a6dd3f9..5fe0f52 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -861,8 +861,8 @@ SDL3_SYM(SDL_HapticID *,GetHaptics,(int *a),(a),return)
 SDL3_SYM(const char *,GetHapticInstanceName,(SDL_HapticID a),(a),return)
 SDL3_SYM(SDL_Haptic *,GetHapticFromInstanceID,(SDL_HapticID a),(a),return)
 SDL3_SYM(SDL_HapticID,GetHapticInstanceID,(SDL_Haptic *a),(a),return)
-SDL3_SYM(Uint32,GetJoystickCaps,(SDL_Joystick *a),(a),return)
-SDL3_SYM(Uint32,GetGamepadCaps,(SDL_GameController *a),(a),return)
+SDL3_SYM(SDL_PropertiesID,GetJoystickProperties,(SDL_Joystick *a),(a),return)
+SDL3_SYM(SDL_PropertiesID,GetGamepadProperties,(SDL_GameController *a),(a),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH