mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-03 22:29:19 +00:00
Made texture size and format public in the API
Also added refcount to textures so they can be retained by application code.
This commit is contained in:
@@ -239,8 +239,7 @@ static int SDLCALL render_testBlit(void *arg)
|
||||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
float tw, th;
|
||||
float i, j, ni, nj;
|
||||
int i, j, ni, nj;
|
||||
int checkFailCount1;
|
||||
|
||||
/* Clear surface. */
|
||||
@@ -257,19 +256,18 @@ static int SDLCALL render_testBlit(void *arg)
|
||||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - tw;
|
||||
nj = TESTRENDER_SCREEN_H - th;
|
||||
rect.w = (float)tface->w;
|
||||
rect.h = (float)tface->h;
|
||||
ni = TESTRENDER_SCREEN_W - tface->w;
|
||||
nj = TESTRENDER_SCREEN_H - tface->h;
|
||||
|
||||
/* Loop blit. */
|
||||
checkFailCount1 = 0;
|
||||
for (j = 0; j <= nj; j += 4) {
|
||||
for (i = 0; i <= ni; i += 4) {
|
||||
/* Blitting. */
|
||||
rect.x = i;
|
||||
rect.y = j;
|
||||
rect.x = (float)i;
|
||||
rect.y = (float)j;
|
||||
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
|
||||
if (!ret) {
|
||||
checkFailCount1++;
|
||||
@@ -631,7 +629,6 @@ static int SDLCALL render_testBlitColor(void *arg)
|
||||
SDL_FRect rect;
|
||||
SDL_Texture *tface;
|
||||
SDL_Surface *referenceSurface = NULL;
|
||||
float tw, th;
|
||||
int i, j, ni, nj;
|
||||
int checkFailCount1;
|
||||
int checkFailCount2;
|
||||
@@ -647,11 +644,10 @@ static int SDLCALL render_testBlitColor(void *arg)
|
||||
}
|
||||
|
||||
/* Constant values. */
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw;
|
||||
rect.h = th;
|
||||
ni = TESTRENDER_SCREEN_W - (int)tw;
|
||||
nj = TESTRENDER_SCREEN_H - (int)th;
|
||||
rect.w = (float)tface->w;
|
||||
rect.h = (float)tface->h;
|
||||
ni = TESTRENDER_SCREEN_W - tface->w;
|
||||
nj = TESTRENDER_SCREEN_H - tface->h;
|
||||
|
||||
/* Test blitting with color mod. */
|
||||
checkFailCount1 = 0;
|
||||
@@ -1423,7 +1419,6 @@ static int SDLCALL render_testUVWrapping(void *arg)
|
||||
SDL_Vertex vertices[6];
|
||||
SDL_Vertex *verts = vertices;
|
||||
SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
float tw, th;
|
||||
SDL_FRect rect;
|
||||
float min_U = -0.5f;
|
||||
float max_U = 1.5f;
|
||||
@@ -1442,11 +1437,10 @@ static int SDLCALL render_testUVWrapping(void *arg)
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
|
||||
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
|
||||
rect.w = tw * 2;
|
||||
rect.h = th * 2;
|
||||
rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
|
||||
rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
|
||||
rect.w = (float)tface->w * 2;
|
||||
rect.h = (float)tface->h * 2;
|
||||
rect.x = (float)(TESTRENDER_SCREEN_W - rect.w) / 2;
|
||||
rect.y = (float)(TESTRENDER_SCREEN_H - rect.h) / 2;
|
||||
|
||||
/*
|
||||
* 0--1
|
||||
|
||||
@@ -278,7 +278,6 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
int win_w, win_h;
|
||||
float tw, th;
|
||||
SDL_FRect d;
|
||||
Uint64 timestampNS = 0;
|
||||
SDL_Surface *frame_next = camera ? SDL_AcquireCameraFrame(camera, ×tampNS) : NULL;
|
||||
@@ -305,8 +304,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
|
||||
if (frame_current) {
|
||||
if (!texture ||
|
||||
!SDL_GetTextureSize(texture, &tw, &th) ||
|
||||
(int)tw != frame_current->w || (int)th != frame_current->h) {
|
||||
texture->w != frame_current->w || texture->h != frame_current->h) {
|
||||
/* Resize the window to match */
|
||||
SDL_SetWindowSize(window, frame_current->w, frame_current->h);
|
||||
|
||||
@@ -337,12 +335,11 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
texture_updated = true;
|
||||
}
|
||||
|
||||
SDL_GetTextureSize(texture, &tw, &th);
|
||||
SDL_GetRenderOutputSize(renderer, &win_w, &win_h);
|
||||
d.x = ((win_w - tw) / 2);
|
||||
d.y = ((win_h - th) / 2);
|
||||
d.w = tw;
|
||||
d.h = th;
|
||||
d.x = ((win_w - texture->w) / 2.0f);
|
||||
d.y = ((win_h - texture->h) / 2.0f);
|
||||
d.w = (float)texture->w;
|
||||
d.h = (float)texture->h;
|
||||
SDL_RenderTexture(renderer, texture, NULL, &d);
|
||||
}
|
||||
|
||||
|
||||
@@ -63,14 +63,12 @@ quit(int rc)
|
||||
|
||||
static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
{
|
||||
float sprite_w, sprite_h;
|
||||
int i;
|
||||
SDL_Rect viewport;
|
||||
SDL_FRect *position, *velocity;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_GetRenderViewport(renderer, &viewport);
|
||||
SDL_GetTextureSize(sprite, &sprite_w, &sprite_h);
|
||||
|
||||
/* Draw a gray background */
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
@@ -81,12 +79,12 @@ static void MoveSprites(SDL_Renderer *renderer, SDL_Texture *sprite)
|
||||
position = &positions[i];
|
||||
velocity = &velocities[i];
|
||||
position->x += velocity->x;
|
||||
if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
|
||||
if ((position->x < 0) || (position->x >= (viewport.w - sprite->w))) {
|
||||
velocity->x = -velocity->x;
|
||||
position->x += velocity->x;
|
||||
}
|
||||
position->y += velocity->y;
|
||||
if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
|
||||
if ((position->y < 0) || (position->y >= (viewport.h - sprite->h))) {
|
||||
velocity->y = -velocity->y;
|
||||
position->y += velocity->y;
|
||||
}
|
||||
@@ -108,7 +106,6 @@ int main(int argc, char *argv[])
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Texture *sprite;
|
||||
int window_w, window_h;
|
||||
float sprite_w, sprite_h;
|
||||
SDL_Event event;
|
||||
|
||||
/* Initialize test framework */
|
||||
@@ -178,7 +175,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Allocate memory for the sprite info */
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
SDL_GetTextureSize(sprite, &sprite_w, &sprite_h);
|
||||
positions = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*positions));
|
||||
velocities = (SDL_FRect *)SDL_malloc(NUM_SPRITES * sizeof(*velocities));
|
||||
if (!positions || !velocities) {
|
||||
@@ -186,10 +182,10 @@ int main(int argc, char *argv[])
|
||||
quit(2);
|
||||
}
|
||||
for (i = 0; i < NUM_SPRITES; ++i) {
|
||||
positions[i].x = (float)(SDL_rand(window_w - (int)sprite_w));
|
||||
positions[i].y = (float)(SDL_rand(window_h - (int)sprite_h));
|
||||
positions[i].w = sprite_w;
|
||||
positions[i].h = sprite_h;
|
||||
positions[i].x = (float)SDL_rand(window_w - sprite->w);
|
||||
positions[i].y = (float)SDL_rand(window_h - sprite->h);
|
||||
positions[i].w = (float)sprite->w;
|
||||
positions[i].h = (float)sprite->h;
|
||||
velocities[i].x = 0.0f;
|
||||
velocities[i].y = 0.0f;
|
||||
while (velocities[i].x == 0.f && velocities[i].y == 0.f) {
|
||||
|
||||
@@ -48,7 +48,6 @@ static void DrawOnViewport(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_FRect rect;
|
||||
SDL_Rect cliprect;
|
||||
float w, h;
|
||||
|
||||
/* Set the viewport */
|
||||
SDL_SetRenderViewport(renderer, &viewport);
|
||||
@@ -91,15 +90,11 @@ static void DrawOnViewport(SDL_Renderer *renderer)
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
|
||||
/* Add a clip rect and fill it with the sprite */
|
||||
SDL_GetTextureSize(sprite, &w, &h);
|
||||
rect.x = (viewport.w - w) / 2;
|
||||
rect.y = (viewport.h - h) / 2;
|
||||
rect.w = w;
|
||||
rect.h = h;
|
||||
cliprect.x = (int)rect.x;
|
||||
cliprect.y = (int)rect.y;
|
||||
cliprect.w = (int)rect.w;
|
||||
cliprect.h = (int)rect.h;
|
||||
cliprect.x = (viewport.w - sprite->w) / 2;
|
||||
cliprect.y = (viewport.h - sprite->h) / 2;
|
||||
cliprect.w = sprite->w;
|
||||
cliprect.h = sprite->h;
|
||||
SDL_RectToFRect(&cliprect, &rect);
|
||||
SDL_SetRenderClipRect(renderer, &cliprect);
|
||||
SDL_RenderTexture(renderer, sprite, NULL, &rect);
|
||||
SDL_SetRenderClipRect(renderer, NULL);
|
||||
|
||||
Reference in New Issue
Block a user