Fixed bug 1878 - Scaled texture draws with filtering produce wrapping artifacts.
authorSam Lantinga <slouken@libsdl.org>
Fri, 08 Dec 2017 11:09:05 -0800
changeset 117370c134b939fd9
parent 11736 e54b6d8ffca8
child 11738 5fd4a464dee5
Fixed bug 1878 - Scaled texture draws with filtering produce wrapping artifacts.

Yuri K. Schlesner

When using texture filtering, there are filtering artifacts visible on the edges of scaled textures, where the texture filtering pulls in texels from the other side of the texture. Using clamping texture modes wouldn't completely fix this since source rectangles don't need to cover the whole texture. (See screenshot attached in next post.)

The opengl driver uses clamping on textures and so avoid this at least in the cases where the source rect is the whole texture. The direct3d driver does not and so has problems in every case. I'm not sure if it can actually completely be fixed, but at least enabling clamping for direct3d would be one step in the right direction.
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Fri Dec 08 00:49:35 2017 -0500
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Fri Dec 08 11:09:05 2017 -0800
     1.3 @@ -1412,6 +1412,10 @@
     1.4                                           texturedata->scaleMode);
     1.5          IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_MAGFILTER,
     1.6                                           texturedata->scaleMode);
     1.7 +        IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_ADDRESSU,
     1.8 +                                         D3DTADDRESS_CLAMP);
     1.9 +        IDirect3DDevice9_SetSamplerState(data->device, index, D3DSAMP_ADDRESSV,
    1.10 +                                         D3DTADDRESS_CLAMP);
    1.11          data->scaleMode[index] = texturedata->scaleMode;
    1.12      }
    1.13  }