renderer: Don't use wrapping on NPOT textures if the renderer can't handle it.

Fixes #13887.
This commit is contained in:
Ryan C. Gordon
2025-09-08 17:06:59 -04:00
parent 2f5bc17ea6
commit 11411bb5ef
4 changed files with 26 additions and 4 deletions

View File

@@ -4306,6 +4306,11 @@ static bool SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *
return true;
}
static bool IsNPOT(int x)
{
return (x <= 0) || ((x & (x - 1)) != 0);
}
bool SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect)
{
SDL_FRect real_srcrect;
@@ -4350,11 +4355,18 @@ bool SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const
texture->last_command_generation = renderer->render_command_generation;
bool do_wrapping = !renderer->software &&
(!srcrect ||
(real_srcrect.x == 0.0f && real_srcrect.y == 0.0f &&
real_srcrect.w == (float)texture->w && real_srcrect.h == (float)texture->h));
if (do_wrapping) {
if (renderer->npot_texture_wrap_unsupported && (IsNPOT((int) real_srcrect.w) || IsNPOT((int) real_srcrect.h))) {
do_wrapping = false;
}
}
// See if we can use geometry with repeating texture coordinates
if (!renderer->software &&
(!srcrect ||
(real_srcrect.x == 0.0f && real_srcrect.y == 0.0f &&
real_srcrect.w == (float)texture->w && real_srcrect.h == (float)texture->h))) {
if (do_wrapping) {
return SDL_RenderTextureTiled_Wrap(renderer, texture, &real_srcrect, scale, dstrect);
} else {
return SDL_RenderTextureTiled_Iterate(renderer, texture, &real_srcrect, scale, dstrect);