Skip to content

Commit

Permalink
render: Some cleanups.
Browse files Browse the repository at this point in the history
Mostly setting NULL pointers to a local struct instead of copying non-NULL
pointers' contents into the local struct.
  • Loading branch information
icculus committed Jan 8, 2025
1 parent 61bdbac commit 4bb3c2a
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions src/render/SDL_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -3869,9 +3869,6 @@ static bool SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *textu

bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
{
SDL_FRect real_srcrect;
SDL_FRect real_dstrect;

CHECK_RENDERER_MAGIC(renderer, false);
CHECK_TEXTURE_MAGIC(texture, false);

Expand All @@ -3886,6 +3883,7 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
}
#endif

SDL_FRect real_srcrect;
real_srcrect.x = 0.0f;
real_srcrect.y = 0.0f;
real_srcrect.w = (float)texture->w;
Expand All @@ -3896,9 +3894,10 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
}
}

GetRenderViewportSize(renderer, &real_dstrect);
if (dstrect) {
real_dstrect = *dstrect;
SDL_FRect full_dstrect;
if (!dstrect) {
GetRenderViewportSize(renderer, &full_dstrect);
dstrect = &full_dstrect;
}

if (texture->native) {
Expand All @@ -3907,7 +3906,7 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F

texture->last_command_generation = renderer->render_command_generation;

return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, &real_dstrect);
return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, dstrect);
}

bool SDL_RenderTextureAffine(SDL_Renderer *renderer, SDL_Texture *texture,
Expand Down Expand Up @@ -4032,7 +4031,6 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip)
{
SDL_FRect real_srcrect;
SDL_FRect real_dstrect;
SDL_FPoint real_center;
bool result;

Expand Down Expand Up @@ -4068,10 +4066,10 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
}

// We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we?
if (dstrect) {
real_dstrect = *dstrect;
} else {
GetRenderViewportSize(renderer, &real_dstrect);
SDL_FRect full_dstrect;
if (!dstrect) {
GetRenderViewportSize(renderer, &full_dstrect);
dstrect = &full_dstrect;
}

if (texture->native) {
Expand All @@ -4081,8 +4079,8 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
if (center) {
real_center = *center;
} else {
real_center.x = real_dstrect.w / 2.0f;
real_center.y = real_dstrect.h / 2.0f;
real_center.x = dstrect->w / 2.0f;
real_center.y = dstrect->h / 2.0f;
}

texture->last_command_generation = renderer->render_command_generation;
Expand Down Expand Up @@ -4116,23 +4114,23 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
maxu = (real_srcrect.x + real_srcrect.w) / texture->w;
maxv = (real_srcrect.y + real_srcrect.h) / texture->h;

centerx = real_center.x + real_dstrect.x;
centery = real_center.y + real_dstrect.y;
centerx = real_center.x + dstrect->x;
centery = real_center.y + dstrect->y;

if (flip & SDL_FLIP_HORIZONTAL) {
minx = real_dstrect.x + real_dstrect.w;
maxx = real_dstrect.x;
minx = dstrect->x + dstrect->w;
maxx = dstrect->x;
} else {
minx = real_dstrect.x;
maxx = real_dstrect.x + real_dstrect.w;
minx = dstrect->x;
maxx = dstrect->x + dstrect->w;
}

if (flip & SDL_FLIP_VERTICAL) {
miny = real_dstrect.y + real_dstrect.h;
maxy = real_dstrect.y;
miny = dstrect->y + dstrect->h;
maxy = dstrect->y;
} else {
miny = real_dstrect.y;
maxy = real_dstrect.y + real_dstrect.h;
miny = dstrect->y;
maxy = dstrect->y + dstrect->h;
}

uv[0] = minu;
Expand Down Expand Up @@ -4173,7 +4171,7 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
num_vertices, indices, num_indices, size_indices,
scale_x, scale_y, SDL_TEXTURE_ADDRESS_CLAMP);
} else {
result = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip, scale_x, scale_y);
result = QueueCmdCopyEx(renderer, texture, &real_srcrect, dstrect, angle, &real_center, flip, scale_x, scale_y);
}
return result;
}
Expand Down

3 comments on commit 4bb3c2a

@sezero
Copy link
Contributor

@sezero sezero commented on 4bb3c2a Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing: Either because of this or because of 61bdbac, or because of the two combined. (Haven't looked at the failures.)

@icculus
Copy link
Collaborator Author

@icculus icculus commented on 4bb3c2a Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fa7a529 specifcally; I'm looking into it.

@icculus
Copy link
Collaborator Author

@icculus icculus commented on 4bb3c2a Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test was wrong, once the renderer was right. :) Fixed in f61860f.

Please sign in to comment.