Skip to content

Commit efe122b

Browse files
committed
Removed width/height parameters from LoadTexture()
You can directly access the texture width and height now.
1 parent dcb97a5 commit efe122b

14 files changed

+49
-70
lines changed

VisualC-GDK/tests/testgdk/src/testgdk.cpp

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ static struct
5656
static SDL_AudioStream *stream;
5757

5858
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
59-
static void
60-
quit(int rc)
59+
static void quit(int rc)
6160
{
6261
SDL_free(sprites);
6362
SDL_DestroyAudioStream(stream);
@@ -80,8 +79,7 @@ static int fillerup(void)
8079
return 0;
8180
}
8281

83-
void
84-
UserLoggedIn(XUserHandle user)
82+
static void UserLoggedIn(XUserHandle user)
8583
{
8684
HRESULT hr;
8785
char gamertag[128];
@@ -96,8 +94,7 @@ UserLoggedIn(XUserHandle user)
9694
XUserCloseHandle(user);
9795
}
9896

99-
void
100-
AddUserUICallback(XAsyncBlock *asyncBlock)
97+
static void AddUserUICallback(XAsyncBlock *asyncBlock)
10198
{
10299
HRESULT hr;
103100
XUserHandle user = NULL;
@@ -123,8 +120,7 @@ AddUserUICallback(XAsyncBlock *asyncBlock)
123120
delete asyncBlock;
124121
}
125122

126-
void
127-
AddUserUI()
123+
static void AddUserUI()
128124
{
129125
HRESULT hr;
130126
XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -141,8 +137,7 @@ AddUserUI()
141137
}
142138
}
143139

144-
void
145-
AddUserSilentCallback(XAsyncBlock *asyncBlock)
140+
static void AddUserSilentCallback(XAsyncBlock *asyncBlock)
146141
{
147142
HRESULT hr;
148143
XUserHandle user = NULL;
@@ -168,8 +163,7 @@ AddUserSilentCallback(XAsyncBlock *asyncBlock)
168163
delete asyncBlock;
169164
}
170165

171-
void
172-
AddUserSilent()
166+
static void AddUserSilent()
173167
{
174168
HRESULT hr;
175169
XAsyncBlock *asyncBlock = new XAsyncBlock;
@@ -186,30 +180,27 @@ AddUserSilent()
186180
}
187181
}
188182

189-
int
190-
LoadSprite(const char *file)
183+
static bool LoadSprite(const char *file)
191184
{
192185
int i;
193186

194187
for (i = 0; i < state->num_windows; ++i) {
195188
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
196-
sprites[i] = LoadTexture(state->renderers[i], file, true, &sprite_w, &sprite_h);
189+
sprites[i] = LoadTexture(state->renderers[i], file, true);
197190
if (!sprites[i]) {
198-
return -1;
199-
}
200-
if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) {
201-
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s", SDL_GetError());
202-
SDL_DestroyTexture(sprites[i]);
203-
return -1;
191+
return false;
204192
}
193+
sprite_w = sprites[i]->w;
194+
sprite_h = sprites[i]->h;
195+
196+
SDL_SetTextureBlendMode(sprites[i], blendMode);
205197
}
206198

207199
/* We're ready to roll. :) */
208-
return 0;
200+
return true;
209201
}
210202

211-
void
212-
DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
203+
static void DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
213204
{
214205
SDL_Rect viewport;
215206
SDL_FRect temp;
@@ -300,8 +291,7 @@ DrawSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
300291
SDL_RenderPresent(renderer);
301292
}
302293

303-
void
304-
loop()
294+
static void loop()
305295
{
306296
int i;
307297
SDL_Event event;
@@ -329,8 +319,7 @@ loop()
329319
fillerup();
330320
}
331321

332-
int
333-
main(int argc, char *argv[])
322+
int main(int argc, char *argv[])
334323
{
335324
int i;
336325
const char *icon = "icon.bmp";
@@ -413,7 +402,7 @@ main(int argc, char *argv[])
413402
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
414403
SDL_RenderClear(renderer);
415404
}
416-
if (LoadSprite(icon) < 0) {
405+
if (!LoadSprite(icon)) {
417406
quit(2);
418407
}
419408

test/testaudio.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,16 +718,15 @@ static Texture *CreateTexture(const char *fname)
718718
if (!tex) {
719719
SDL_Log("Out of memory!");
720720
} else {
721-
int texw, texh;
722-
tex->texture = LoadTexture(state->renderers[0], fname, true, &texw, &texh);
721+
tex->texture = LoadTexture(state->renderers[0], fname, true);
723722
if (!tex->texture) {
724723
SDL_Log("Failed to load '%s': %s", fname, SDL_GetError());
725724
SDL_free(tex);
726725
return NULL;
727726
}
728727
SDL_SetTextureBlendMode(tex->texture, SDL_BLENDMODE_BLEND);
729-
tex->w = (float) texw;
730-
tex->h = (float) texh;
728+
tex->w = (float)tex->texture->w;
729+
tex->h = (float)tex->texture->h;
731730
}
732731
return tex;
733732
}

test/testgeometry.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ static bool use_texture = false;
2828
static SDL_Texture **sprites;
2929
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
3030
static float angle = 0.0f;
31-
static int sprite_w, sprite_h;
3231
static int translate_cx = 0;
3332
static int translate_cy = 0;
3433

@@ -52,7 +51,7 @@ static int LoadSprite(const char *file)
5251

5352
for (i = 0; i < state->num_windows; ++i) {
5453
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
55-
sprites[i] = LoadTexture(state->renderers[i], file, true, &sprite_w, &sprite_h);
54+
sprites[i] = LoadTexture(state->renderers[i], file, true);
5655
if (!sprites[i]) {
5756
return -1;
5857
}

test/testgpurender_effects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,13 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
263263
return SDL_APP_FAILURE;
264264
}
265265

266-
background = LoadTexture(renderer, "sample.bmp", false, NULL, NULL);
266+
background = LoadTexture(renderer, "sample.bmp", false);
267267
if (!background) {
268268
SDL_Log("Couldn't create background: %s", SDL_GetError());
269269
return SDL_APP_FAILURE;
270270
}
271271

272-
sprite = LoadTexture(renderer, "icon.bmp", true, NULL, NULL);
272+
sprite = LoadTexture(renderer, "icon.bmp", true);
273273
if (!sprite) {
274274
SDL_Log("Couldn't create sprite: %s", SDL_GetError());
275275
return SDL_APP_FAILURE;

test/testgpurender_msdf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static GlyphInfo glyphs[128];
5555

5656
static bool LoadFontTexture(void)
5757
{
58-
font_texture = LoadTexture(renderer, "msdf_font.bmp", false, NULL, NULL);
58+
font_texture = LoadTexture(renderer, "msdf_font.bmp", false);
5959
if (!font_texture) {
6060
SDL_Log("Failed to create font texture: %s", SDL_GetError());
6161
return false;

test/testime.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,19 @@ int main(int argc, char *argv[])
987987
WindowState *ctx = &windowstate[i];
988988
SDL_Window *window = state->windows[i];
989989
SDL_Renderer *renderer = state->renderers[i];
990-
int icon_w = 0, icon_h = 0;
991990

992991
SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
993992

994993
ctx->window = window;
995994
ctx->renderer = renderer;
996995
ctx->rendererID = i;
997-
ctx->settings_icon = LoadTexture(renderer, "icon.bmp", true, &icon_w, &icon_h);
998-
ctx->settings_rect.x = (float)WINDOW_WIDTH - icon_w - MARGIN;
999-
ctx->settings_rect.y = MARGIN;
1000-
ctx->settings_rect.w = (float)icon_w;
1001-
ctx->settings_rect.h = (float)icon_h;
996+
ctx->settings_icon = LoadTexture(renderer, "icon.bmp", true);
997+
if (ctx->settings_icon) {
998+
ctx->settings_rect.w = (float)ctx->settings_icon->w;
999+
ctx->settings_rect.h = (float)ctx->settings_icon->h;
1000+
ctx->settings_rect.x = (float)WINDOW_WIDTH - ctx->settings_rect.w - MARGIN;
1001+
ctx->settings_rect.y = MARGIN;
1002+
}
10021003

10031004
InitInput(ctx);
10041005

test/testnative.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int main(int argc, char *argv[])
168168
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
169169
SDL_RenderClear(renderer);
170170

171-
sprite = LoadTexture(renderer, "icon.bmp", true, NULL, NULL);
171+
sprite = LoadTexture(renderer, "icon.bmp", true);
172172
if (!sprite) {
173173
quit(6);
174174
}

test/testrendercopyex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ int main(int argc, char *argv[])
135135

136136
drawstate->window = state->windows[i];
137137
drawstate->renderer = state->renderers[i];
138-
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
139-
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
138+
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
139+
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
140140
if (!drawstate->sprite || !drawstate->background) {
141141
quit(2);
142142
}

test/testrendertarget.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,11 @@ int main(int argc, char *argv[])
253253
drawstate->window = state->windows[i];
254254
drawstate->renderer = state->renderers[i];
255255
if (test_composite) {
256-
drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", true, NULL, NULL);
256+
drawstate->sprite = LoadTexture(drawstate->renderer, "icon-alpha.bmp", true);
257257
} else {
258-
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
258+
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
259259
}
260-
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
260+
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
261261
if (!drawstate->sprite || !drawstate->background) {
262262
quit(2);
263263
}

test/testscale.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ int main(int argc, char *argv[])
126126

127127
drawstate->window = state->windows[i];
128128
drawstate->renderer = state->renderers[i];
129-
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true, NULL, NULL);
130-
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false, NULL, NULL);
129+
drawstate->sprite = LoadTexture(drawstate->renderer, "icon.bmp", true);
130+
drawstate->background = LoadTexture(drawstate->renderer, "sample.bmp", false);
131131
if (!drawstate->sprite || !drawstate->background) {
132132
quit(2);
133133
}

test/testsprite.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ void SDL_AppQuit(void *appstate, SDL_AppResult result)
5353

5454
static int LoadSprite(const char *file)
5555
{
56-
int i, w, h;
56+
int i;
5757

5858
for (i = 0; i < state->num_windows; ++i) {
5959
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
6060
if (sprites[i]) {
6161
SDL_DestroyTexture(sprites[i]);
6262
}
63-
sprites[i] = LoadTexture(state->renderers[i], file, true, &w, &h);
64-
sprite_w = (float)w;
65-
sprite_h = (float)h;
63+
sprites[i] = LoadTexture(state->renderers[i], file, true);
64+
if (sprites[i]) {
65+
sprite_w = (float)sprites[i]->w;
66+
sprite_h = (float)sprites[i]->h;
67+
}
6668
if (!sprites[i]) {
6769
return -1;
6870
}

test/testutils.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ char *GetResourceFilename(const char *user_specified, const char *def)
7272
*
7373
* If height_out is non-NULL, set it to the texture height.
7474
*/
75-
SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent, int *width_out, int *height_out)
75+
SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent)
7676
{
7777
SDL_Surface *temp = NULL;
7878
SDL_Texture *texture = NULL;
@@ -117,14 +117,6 @@ SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transpar
117117
}
118118
}
119119

120-
if (width_out) {
121-
*width_out = temp->w;
122-
}
123-
124-
if (height_out) {
125-
*height_out = temp->h;
126-
}
127-
128120
texture = SDL_CreateTextureFromSurface(renderer, temp);
129121
if (!texture) {
130122
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s", SDL_GetError());

test/testutils.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
#include <SDL3/SDL.h>
1818

19-
SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent,
20-
int *width_out, int *height_out);
19+
SDL_Texture *LoadTexture(SDL_Renderer *renderer, const char *file, bool transparent);
2120
char *GetNearbyFilename(const char *file);
2221
char *GetResourceFilename(const char *user_specified, const char *def);
2322

test/testviewport.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static bool use_target = false;
3131
static Uint32 wait_start;
3232
#endif
3333
static SDL_Texture *sprite;
34-
static int sprite_w, sprite_h;
3534

3635
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
3736
static void
@@ -184,8 +183,7 @@ int main(int argc, char *argv[])
184183
quit(2);
185184
}
186185

187-
sprite = LoadTexture(state->renderers[0], "icon.bmp", true, &sprite_w, &sprite_h);
188-
186+
sprite = LoadTexture(state->renderers[0], "icon.bmp", true);
189187
if (!sprite) {
190188
quit(2);
191189
}

0 commit comments

Comments
 (0)