Skip to content

Commit 4bb3c2a

Browse files
committed
render: Some cleanups.
Mostly setting NULL pointers to a local struct instead of copying non-NULL pointers' contents into the local struct.
1 parent 61bdbac commit 4bb3c2a

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/render/SDL_render.c

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,9 +3869,6 @@ static bool SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *textu
38693869

38703870
bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect)
38713871
{
3872-
SDL_FRect real_srcrect;
3873-
SDL_FRect real_dstrect;
3874-
38753872
CHECK_RENDERER_MAGIC(renderer, false);
38763873
CHECK_TEXTURE_MAGIC(texture, false);
38773874

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

3886+
SDL_FRect real_srcrect;
38893887
real_srcrect.x = 0.0f;
38903888
real_srcrect.y = 0.0f;
38913889
real_srcrect.w = (float)texture->w;
@@ -3896,9 +3894,10 @@ bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_F
38963894
}
38973895
}
38983896

3899-
GetRenderViewportSize(renderer, &real_dstrect);
3900-
if (dstrect) {
3901-
real_dstrect = *dstrect;
3897+
SDL_FRect full_dstrect;
3898+
if (!dstrect) {
3899+
GetRenderViewportSize(renderer, &full_dstrect);
3900+
dstrect = &full_dstrect;
39023901
}
39033902

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

39083907
texture->last_command_generation = renderer->render_command_generation;
39093908

3910-
return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, &real_dstrect);
3909+
return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, dstrect);
39113910
}
39123911

39133912
bool SDL_RenderTextureAffine(SDL_Renderer *renderer, SDL_Texture *texture,
@@ -4032,7 +4031,6 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
40324031
const double angle, const SDL_FPoint *center, const SDL_FlipMode flip)
40334032
{
40344033
SDL_FRect real_srcrect;
4035-
SDL_FRect real_dstrect;
40364034
SDL_FPoint real_center;
40374035
bool result;
40384036

@@ -4068,10 +4066,10 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
40684066
}
40694067

40704068
// We don't intersect the dstrect with the viewport as RenderCopy does because of potential rotation clipping issues... TODO: should we?
4071-
if (dstrect) {
4072-
real_dstrect = *dstrect;
4073-
} else {
4074-
GetRenderViewportSize(renderer, &real_dstrect);
4069+
SDL_FRect full_dstrect;
4070+
if (!dstrect) {
4071+
GetRenderViewportSize(renderer, &full_dstrect);
4072+
dstrect = &full_dstrect;
40754073
}
40764074

40774075
if (texture->native) {
@@ -4081,8 +4079,8 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
40814079
if (center) {
40824080
real_center = *center;
40834081
} else {
4084-
real_center.x = real_dstrect.w / 2.0f;
4085-
real_center.y = real_dstrect.h / 2.0f;
4082+
real_center.x = dstrect->w / 2.0f;
4083+
real_center.y = dstrect->h / 2.0f;
40864084
}
40874085

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

4119-
centerx = real_center.x + real_dstrect.x;
4120-
centery = real_center.y + real_dstrect.y;
4117+
centerx = real_center.x + dstrect->x;
4118+
centery = real_center.y + dstrect->y;
41214119

41224120
if (flip & SDL_FLIP_HORIZONTAL) {
4123-
minx = real_dstrect.x + real_dstrect.w;
4124-
maxx = real_dstrect.x;
4121+
minx = dstrect->x + dstrect->w;
4122+
maxx = dstrect->x;
41254123
} else {
4126-
minx = real_dstrect.x;
4127-
maxx = real_dstrect.x + real_dstrect.w;
4124+
minx = dstrect->x;
4125+
maxx = dstrect->x + dstrect->w;
41284126
}
41294127

41304128
if (flip & SDL_FLIP_VERTICAL) {
4131-
miny = real_dstrect.y + real_dstrect.h;
4132-
maxy = real_dstrect.y;
4129+
miny = dstrect->y + dstrect->h;
4130+
maxy = dstrect->y;
41334131
} else {
4134-
miny = real_dstrect.y;
4135-
maxy = real_dstrect.y + real_dstrect.h;
4132+
miny = dstrect->y;
4133+
maxy = dstrect->y + dstrect->h;
41364134
}
41374135

41384136
uv[0] = minu;
@@ -4173,7 +4171,7 @@ bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
41734171
num_vertices, indices, num_indices, size_indices,
41744172
scale_x, scale_y, SDL_TEXTURE_ADDRESS_CLAMP);
41754173
} else {
4176-
result = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip, scale_x, scale_y);
4174+
result = QueueCmdCopyEx(renderer, texture, &real_srcrect, dstrect, angle, &real_center, flip, scale_x, scale_y);
41774175
}
41784176
return result;
41794177
}

0 commit comments

Comments
 (0)