SDL: Removed width/height parameters from LoadTexture()

From efe122be4dfa5ee82f8452a5e7d312a4ad58ca90 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 14 Mar 2025 10:38:11 -0700
Subject: [PATCH] Removed width/height parameters from LoadTexture()

You can directly access the texture width and height now.
---
 VisualC-GDK/tests/testgdk/src/testgdk.cpp | 47 +++++++++--------------
 test/testaudio.c                          |  7 ++--
 test/testgeometry.c                       |  3 +-
 test/testgpurender_effects.c              |  4 +-
 test/testgpurender_msdf.c                 |  2 +-
 test/testime.c                            | 13 ++++---
 test/testnative.c                         |  2 +-
 test/testrendercopyex.c                   |  4 +-
 test/testrendertarget.c                   |  6 +--
 test/testscale.c                          |  4 +-
 test/testsprite.c                         | 10 +++--
 test/testutils.c                          | 10 +----
 test/testutils.h                          |  3 +-
 test/testviewport.c                       |  4 +-
 14 files changed, 49 insertions(+), 70 deletions(-)

diff --git a/VisualC-GDK/tests/testgdk/src/testgdk.cpp b/VisualC-GDK/tests/testgdk/src/testgdk.cpp
index 51fc75bc08cc5..20bc03ff6bae0 100644
--- a/VisualC-GDK/tests/testgdk/src/testgdk.cpp
+++ b/VisualC-GDK/tests/testgdk/src/testgdk.cpp
@@ -56,8 +56,7 @@ static struct
 static SDL_AudioStream *stream;
 
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
-static void
-quit(int rc)
+static void quit(int rc)
 {
     SDL_free(sprites);
     SDL_DestroyAudioStream(stream);
@@ -80,8 +79,7 @@ static int fillerup(void)
     return 0;
 }
 
-void
-UserLoggedIn(XUserHandle user)
+static void UserLoggedIn(XUserHandle user)
 {
     HRESULT hr;
     char gamertag[128];
@@ -96,8 +94,7 @@ UserLoggedIn(XUserHandle user)
     XUserCloseHandle(user);
 }
 
-void
-AddUserUICallback(XAsyncBlock *asyncBlock)
+static void AddUserUICallback(XAsyncBlock *asyncBlock)
 {
     HRESULT hr;
     XUserHandle user = NULL;
@@ -123,8 +120,7 @@ AddUserUICallback(XAsyncBlock *asyncBlock)
     delete asyncBlock;
 }
 
-void
-AddUserUI()
+static void AddUserUI()
 {
     HRESULT hr;
     XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -141,8 +137,7 @@ AddUserUI()
     }
 }
 
-void
-AddUserSilentCallback(XAsyncBlock *asyncBlock)
+static void AddUserSilentCallback(XAsyncBlock *asyncBlock)
 {
     HRESULT hr;
     XUserHandle user = NULL;
@@ -168,8 +163,7 @@ AddUserSilentCallback(XAsyncBlock *asyncBlock)
     delete asyncBlock;
 }
 
-void
-AddUserSilent()
+static void AddUserSilent()
 {
     HRESULT hr;
     XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -186,30 +180,27 @@ AddUserSilent()
     }
 }
 
-int
-LoadSprite(const char *file)
+static bool LoadSprite(const char *file)
 {
     int i;
 
     for (i = 0; i < state->num_windows; ++i) {
         /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
-        sprites[i] = LoadTexture(state->renderers[i], file, true, &sprite_w, &sprite_h);
+        sprites[i] = LoadTexture(state->renderers[i], file, true);
         if (!sprites[i]) {
-            return -1;
-        }
-        if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) {
-            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s", SDL_GetError());
-            SDL_DestroyTexture(sprites[i]);
-            return -1;
+            return false;
         }
+        sprite_w = sprites[i]->w;
+        sprite_h = sprites[i]->h;
+
+        SDL_SetTextureBlendMode(sprites[i], blendMode);
     }
 
     /* We're ready to roll. :) */
-    return 0;
+    return true;
 }
 
-void
-DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
+static void DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
 {
     SDL_Rect viewport;
     SDL_FRect temp;
@@ -300,8 +291,7 @@ DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
     SDL_RenderPresent(renderer);
 }
 
-void
-loop()
+static void loop()
 {
     int i;
     SDL_Event event;
@@ -329,8 +319,7 @@ loop()
     fillerup();
 }
 
-int
-main(int argc, char *argv[])
+int main(int argc, char *argv[])
 {
     int i;
     const char *icon = "icon.bmp";
@@ -413,7 +402,7 @@ main(int argc, char *argv[])
         SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
         SDL_RenderClear(renderer);
     }
-    if (LoadSprite(icon) < 0) {
+    if (!LoadSprite(icon)) {
         quit(2);
     }
 
diff --git a/test/testaudio.c b/test/testaudio.c
index 8abb3b2d95630..ce9f798c75791 100644
--- a/test/testaudio.c
+++ b/test/testaudio.c
@@ -718,16 +718,15 @@ static Texture *CreateTexture(const char *fname)
     if (!tex) {
         SDL_Log("Out of memory!");
     } else {
-        int texw, texh;
-        tex->texture = LoadTexture(state->renderers[0], fname, true, &texw, &texh);
+        tex->texture = LoadTexture(state->renderers[0], fname, true);
         if (!tex->texture) {
             SDL_Log("Failed to load '%s': %s", fname, SDL_GetError());
             SDL_free(tex);
             return NULL;
         }
         SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_BLEND);
-        tex->w = (float) texw;
-        tex->h = (float) texh;
+        tex->w = (float)tex->texture->w;
+        tex->h = (float)tex->texture->h;
     }
     return tex;
 }
diff --git a/test/testgeometry.c b/test/testgeometry.c
index a510cfd410d85..971de0ff72d1e 100644
--- a/test/testgeometry.c
+++ b/test/testgeometry.c
@@ -28,7 +28,6 @@ static bool use_texture = false;
 static SDL_Texture **sprites;
 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
 static float angle = 0.0f;
-static int sprite_w, sprite_h;
 static int translate_cx = 0;
 static int translate_cy = 0;
 
@@ -52,7 +51,7 @@ static int LoadSprite(const char *file)
 
     for (i = 0; i < state->num_windows; ++i) {
         /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
-        sprites[i] = LoadTexture(state->renderers[i], file, true, &sprite_w, &sprite_h);
+        sprites[i] = LoadTexture(state->renderers[i], file, true);
         if (!sprites[i]) {
             return -1;
         }
diff --git a/test/testgpurender_effects.c b/test/testgpurender_effects.c
index efda08171297d..62df028dabda0 100644
--- a/test/testgpurender_effects.c
+++ b/test/testgpurender_effects.c
@@ -263,13 +263,13 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
         return SDL_APP_FAILURE;
     }
 
-    background = LoadTexture(renderer, "sample.bmp", false, NULL, NULL);
+    background = LoadTexture(renderer, "sample.bmp", false);
     if (!background) {
         SDL_Log("Couldn't create background: %s", SDL_GetError());
         return SDL_APP_FAILURE;
     }
 
-    sprite = LoadTexture(renderer, "icon.bmp", true, NULL, NULL);
+    sprite = LoadTexture(renderer, "icon.bmp", true);
     if (!sprite) {
         SDL_Log("Couldn't create sprite: %s", SDL_GetError());
         return SDL_APP_FAILURE;
diff --git a/test/testgpurender_msdf.c b/test/testgpurender_msdf.c
index a822f9e385bb9..299d8beb03b54 100644
--- a/test/testgpurender_msdf.c
+++ b/test/testgpurender_msdf.c
@@ -55,7 +55,7 @@ static GlyphInfo glyphs[128];
 
 static bool LoadFontTexture(void)
 {
-    font_texture = LoadTexture(renderer, "msdf_font.bmp", false, NULL, NULL);
+    font_texture = LoadTexture(renderer, "msdf_font.bmp", false);
     if (!font_texture) {
         SDL_Log("Failed to create font texture: %s", SDL_GetError());
         return false;
diff --git a/test/testime.c b/test/testime.c
index ea56d3c8070cd..a1a7e44299f2c 100644
--- a/test/testime.c
+++ b/test/testime.c
@@ -987,18 +987,19 @@ int main(int argc, char *argv[])
         WindowState *ctx = &windowstate[i];
         SDL_Window *window = state->windows[i];
         SDL_Renderer *renderer = state->renderers[i];
-        int icon_w = 0, icon_h = 0;
 
         SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
 
         ctx->window = window;
         ctx->renderer = renderer;
         ctx->rendererID = i;
-        ctx->settings_icon = LoadTexture(renderer, "icon.bmp", true, &icon_w, &icon_h);
-        ctx->settings_rect.x = (float)WINDOW_WIDTH - icon_w - MARGIN;
-        ctx->settings_rect.y = MARGIN;
-        ctx->settings_rect.w = (float)icon_w;
-        ctx->settings_rect.h = (float)icon_h;
+        ctx->settings_icon = LoadTexture(renderer, "icon.bmp", true);
+        if (ctx->settings_icon) {
+            ctx->settings_rect.w = (float)ctx->settings_icon->w;
+            ctx->settings_rect.h = (float)ctx->settings_icon->h;
+            ctx->settings_rect.x = (float)WINDOW_WIDTH - ctx->settings_rect.w - MARGIN;
+            ctx->settings_rect.y = MARGIN;
+        }
 
         InitInput(ctx);
 
diff --git a/test/testnative.c b/test/testnative.c
index a4b58fa421e27..5ee3bff71e4d3 100644
--- a/test/testnative.c
+++ b/test/testnative.c
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
     SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
     SDL_RenderClear(renderer);
 
-    sprite = LoadTexture(renderer, "icon.bmp", true, NULL, NULL);
+    sprite = LoadTexture(renderer, "icon.bmp", true);
     if (!sprite) {
         quit(6);
     }
diff --git a/test/testrendercopyex.c b/test/testrendercopyex.c
index e46d522a4722d..eba31e6190f48 100644
--- a/test/testrendercopyex.c
+++ b/test/testrendercopyex.c
@@ -135,8 +135,8 @@ int main(int argc, char *argv[])
 
         drawstate->window = state->windows[i];
         drawstate->renderer = state->renderers[i];
-        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
-        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
+        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
+        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
         if (!drawstate->sprite || !drawstate->background) {
             quit(2);
         }
diff --git a/test/testrendertarget.c b/test/testrendertarget.c
index bad57fdc5c39d..ab830efa5db13 100644
--- a/test/testrendertarget.c
+++ b/test/testrendertarget.c
@@ -253,11 +253,11 @@ int main(int argc, char *argv[])
         drawstate->window = state->windows[i];
         drawstate->renderer = state->renderers[i];
         if (test_composite) {
-            drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", true, NULL, NULL);
+            drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", true);
         } else {
-            drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
+            drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
         }
-        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
+        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
         if (!drawstate->sprite || !drawstate->background) {
             quit(2);
         }
diff --git a/test/testscale.c b/test/testscale.c
index d92d5ce1be1bc..766a2af2a0a74 100644
--- a/test/testscale.c
+++ b/test/testscale.c
@@ -126,8 +126,8 @@ int main(int argc, char *argv[])
 
         drawstate->window = state->windows[i];
         drawstate->renderer = state->renderers[i];
-        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
-        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
+        drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
+        drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
         if (!drawstate->sprite || !drawstate->background) {
             quit(2);
         }
diff --git a/test/testsprite.c b/test/testsprite.c
index 2f202d6da9ea2..dd146a9bc4047 100644
--- a/test/testsprite.c
+++ b/test/testsprite.c
@@ -53,16 +53,18 @@ void SDL_AppQuit(void *appstate, SDL_AppResult result)
 
 static int LoadSprite(const char *file)
 {
-    int i, w, h;
+    int i;
 
     for (i = 0; i < state->num_windows; ++i) {
         /* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
         if (sprites[i]) {
             SDL_DestroyTexture(sprites[i]);
         }
-        sprites[i] = LoadTexture(state->renderers[i], file, true, &w, &h);
-        sprite_w = (float)w;
-        sprite_h = (float)h;
+        sprites[i] = LoadTexture(state->renderers[i], file, true);
+        if (sprites[i]) {
+            sprite_w = (float)sprites[i]->w;
+            sprite_h = (float)sprites[i]->h;
+        }
         if (!sprites[i]) {
             return -1;
         }
diff --git a/test/testutils.c b/test/testutils.c
index ab044bf21c2c4..36445d5b450a5 100644
--- a/test/testutils.c
+++ b/test/testutils.c
@@ -72,7 +72,7 @@ char *GetResourceFilename(const char *user_specified, const char *def)
  *
  * If height_out is non-NULL, set it to the texture height.
  */
-SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent, int *width_out, int *height_out)
+SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent)
 {
     SDL_Surface *temp = NULL;
     SDL_Texture *texture = NULL;
@@ -117,14 +117,6 @@ SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transpar
             }
         }
 
-        if (width_out) {
-            *width_out = temp->w;
-        }
-
-        if (height_out) {
-            *height_out = temp->h;
-        }
-
         texture = SDL_CreateTextureFromSurface(renderer, temp);
         if (!texture) {
             SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s", SDL_GetError());
diff --git a/test/testutils.h b/test/testutils.h
index 1429d756c00be..65030cd2264fe 100644
--- a/test/testutils.h
+++ b/test/testutils.h
@@ -16,8 +16,7 @@
 
 #include <SDL3/SDL.h>
 
-SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent,
-                         int *width_out, int *height_out);
+SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent);
 char *GetNearbyFilename(const char *file);
 char *GetResourceFilename(const char *user_specified, const char *def);
 
diff --git a/test/testviewport.c b/test/testviewport.c
index 01e27e7bd832e..e0ba1a1abc76c 100644
--- a/test/testviewport.c
+++ b/test/testviewport.c
@@ -31,7 +31,6 @@ static bool use_target = false;
 static Uint32 wait_start;
 #endif
 static SDL_Texture *sprite;
-static int sprite_w, sprite_h;
 
 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
 static void
@@ -184,8 +183,7 @@ int main(int argc, char *argv[])
         quit(2);
     }
 
-    sprite = LoadTexture(state->renderers[0], "icon.bmp", true, &sprite_w, &sprite_h);
-
+    sprite = LoadTexture(state->renderers[0], "icon.bmp", true);
     if (!sprite) {
         quit(2);
     }