sdl2-compat: SDL_RenderTexture() and SDL_RenderTextureRotated() take floating point source coordinates

From aebae2e74f2a19504f18f2839ca39a5ca78378b0 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 2 Mar 2023 10:46:56 -0800
Subject: [PATCH] SDL_RenderTexture() and SDL_RenderTextureRotated() take
 floating point source coordinates

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

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index a50aaaf..336b6ef 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -4214,8 +4214,17 @@ SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 DECLSPEC int SDLCALL
 SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
 {
+    SDL_FRect srcfrect;
+    SDL_FRect *psrcfrect = NULL;
     SDL_FRect dstfrect;
     SDL_FRect *pdstfrect = NULL;
+    if (srcrect) {
+        srcfrect.x = (float)srcrect->x;
+        srcfrect.y = (float)srcrect->y;
+        srcfrect.w = (float)srcrect->w;
+        srcfrect.h = (float)srcrect->h;
+        psrcfrect = &srcfrect;
+    }
     if (dstrect) {
         dstfrect.x = (float)dstrect->x;
         dstfrect.y = (float)dstrect->y;
@@ -4223,7 +4232,22 @@ SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *src
         dstfrect.h = (float)dstrect->h;
         pdstfrect = &dstfrect;
     }
-    return SDL3_RenderTexture(renderer, texture, srcrect, pdstfrect);
+    return SDL3_RenderTexture(renderer, texture, psrcfrect, pdstfrect);
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_FRect *dstrect)
+{
+    SDL_FRect srcfrect;
+    SDL_FRect *psrcfrect = NULL;
+    if (srcrect) {
+        srcfrect.x = (float)srcrect->x;
+        srcfrect.y = (float)srcrect->y;
+        srcfrect.w = (float)srcrect->w;
+        srcfrect.h = (float)srcrect->h;
+        psrcfrect = &srcfrect;
+    }
+    return SDL3_RenderTexture(renderer, texture, psrcfrect, dstrect);
 }
 
 DECLSPEC int SDLCALL
@@ -4231,11 +4255,21 @@ SDL_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
                      const SDL_Rect *srcrect, const SDL_Rect *dstrect,
                      const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
 {
+    SDL_FRect srcfrect;
+    SDL_FRect *psrcfrect = NULL;
     SDL_FRect dstfrect;
     SDL_FRect *pdstfrect = NULL;
     SDL_FPoint fcenter;
     SDL_FPoint *pfcenter = NULL;
 
+    if (srcrect) {
+        srcfrect.x = (float)srcrect->x;
+        srcfrect.y = (float)srcrect->y;
+        srcfrect.w = (float)srcrect->w;
+        srcfrect.h = (float)srcrect->h;
+        psrcfrect = &srcfrect;
+    }
+
     if (dstrect) {
         dstfrect.x = (float)dstrect->x;
         dstfrect.y = (float)dstrect->y;
@@ -4250,7 +4284,34 @@ SDL_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
         pfcenter = &fcenter;
     }
 
-    return SDL3_RenderTextureRotated(renderer, texture, srcrect, pdstfrect, angle, pfcenter, flip);
+    return SDL3_RenderTextureRotated(renderer, texture, psrcfrect, pdstfrect, angle, pfcenter, flip);
+}
+
+DECLSPEC int SDLCALL
+SDL_RenderCopyExF(SDL_Renderer *renderer, SDL_Texture *texture,
+                     const SDL_Rect *srcrect, const SDL_FRect *dstrect,
+                     const double angle, const SDL_Point *center, const SDL_RendererFlip flip)
+{
+    SDL_FRect srcfrect;
+    SDL_FRect *psrcfrect = NULL;
+    SDL_FPoint fcenter;
+    SDL_FPoint *pfcenter = NULL;
+
+    if (srcrect) {
+        srcfrect.x = (float)srcrect->x;
+        srcfrect.y = (float)srcrect->y;
+        srcfrect.w = (float)srcrect->w;
+        srcfrect.h = (float)srcrect->h;
+        psrcfrect = &srcfrect;
+    }
+
+    if (center) {
+        fcenter.x = (float)center->x;
+        fcenter.y = (float)center->y;
+        pfcenter = &fcenter;
+    }
+
+    return SDL3_RenderTextureRotated(renderer, texture, psrcfrect, dstrect, angle, pfcenter, flip);
 }
 
 /* SDL3 removed window parameter from SDL_Vulkan_GetInstanceExtensions() */
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 5c1fb10..6bdc036 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -675,8 +675,8 @@ SDL3_SYM_RENAMED(int,RenderDrawRectF,RenderRect,(SDL_Renderer *a, const SDL_FRec
 SDL3_SYM_RENAMED(int,RenderDrawRectsF,RenderRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,RenderFillRectF,RenderFillRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return)
 SDL3_SYM_RENAMED(int,RenderFillRectsF,RenderFillRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED(int,RenderCopyF,RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d),(a,b,c,d),return)
-SDL3_SYM_RENAMED(int,RenderCopyExF,RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_Rect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
+SDL3_SYM(int,RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d),(a,b,c,d),return)
+SDL3_SYM(int,RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_RendererFlip g),(a,b,c,d,e,f,g),return)
 SDL3_SYM_PASSTHROUGH(SDL_TouchDeviceType,GetTouchDeviceType,(SDL_TouchID a),(a),return)
 SDL3_SYM_PASSTHROUGH(size_t,SIMDGetAlignment,(void),(),return)
 SDL3_SYM(void*,aligned_alloc,(size_t a, size_t b),(a,b),return)