src/render/direct3d/SDL_render_d3d.c
changeset 5484 e20c93bc9122
parent 5299 33987021a1ed
child 5535 96594ac5fd1a
     1.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sun Mar 13 11:17:11 2011 -0700
     1.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sun Mar 13 11:18:35 2011 -0700
     1.3 @@ -26,6 +26,7 @@
     1.4  
     1.5  #include "../../core/windows/SDL_windows.h"
     1.6  
     1.7 +#include "SDL_hints.h"
     1.8  #include "SDL_loadso.h"
     1.9  #include "SDL_syswm.h"
    1.10  #include "../SDL_sysrender.h"
    1.11 @@ -137,11 +138,13 @@
    1.12      D3DPRESENT_PARAMETERS pparams;
    1.13      SDL_bool updateSize;
    1.14      SDL_bool beginScene;
    1.15 +    D3DTEXTUREFILTERTYPE scaleMode;
    1.16  } D3D_RenderData;
    1.17  
    1.18  typedef struct
    1.19  {
    1.20      IDirect3DTexture9 *texture;
    1.21 +    D3DTEXTUREFILTERTYPE scaleMode;
    1.22  } D3D_TextureData;
    1.23  
    1.24  typedef struct
    1.25 @@ -451,6 +454,7 @@
    1.26          return NULL;
    1.27      }
    1.28      data->beginScene = SDL_TRUE;
    1.29 +    data->scaleMode = D3DTEXF_FORCE_DWORD;
    1.30  
    1.31      /* Get presentation parameters to fill info */
    1.32      result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
    1.33 @@ -537,6 +541,20 @@
    1.34      }
    1.35  }
    1.36  
    1.37 +static D3DTEXTUREFILTERTYPE
    1.38 +GetScaleQuality(void)
    1.39 +{
    1.40 +    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
    1.41 +
    1.42 +    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
    1.43 +        return D3DTEXF_POINT;
    1.44 +    } else if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) {
    1.45 +        return D3DTEXF_LINEAR;
    1.46 +    } else {
    1.47 +        return D3DTEXF_ANISOTROPIC;
    1.48 +    }
    1.49 +}
    1.50 +
    1.51  static int
    1.52  D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.53  {
    1.54 @@ -553,6 +571,7 @@
    1.55          SDL_OutOfMemory();
    1.56          return -1;
    1.57      }
    1.58 +    data->scaleMode = GetScaleQuality();
    1.59  
    1.60      texture->driverdata = data;
    1.61  
    1.62 @@ -1018,10 +1037,13 @@
    1.63  
    1.64      D3D_SetBlendMode(data, texture->blendMode);
    1.65  
    1.66 -    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
    1.67 -                                     D3DTEXF_LINEAR);
    1.68 -    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
    1.69 -                                     D3DTEXF_LINEAR);
    1.70 +    if (texturedata->scaleMode != data->scaleMode) {
    1.71 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
    1.72 +                                         texturedata->scaleMode);
    1.73 +        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
    1.74 +                                         texturedata->scaleMode);
    1.75 +        data->scaleMode = texturedata->scaleMode;
    1.76 +    }
    1.77  
    1.78      result =
    1.79          IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)