src/render/direct3d/SDL_render_d3d.c
changeset 5484 e20c93bc9122
parent 5299 33987021a1ed
child 5535 96594ac5fd1a
--- a/src/render/direct3d/SDL_render_d3d.c	Sun Mar 13 11:17:11 2011 -0700
+++ b/src/render/direct3d/SDL_render_d3d.c	Sun Mar 13 11:18:35 2011 -0700
@@ -26,6 +26,7 @@
 
 #include "../../core/windows/SDL_windows.h"
 
+#include "SDL_hints.h"
 #include "SDL_loadso.h"
 #include "SDL_syswm.h"
 #include "../SDL_sysrender.h"
@@ -137,11 +138,13 @@
     D3DPRESENT_PARAMETERS pparams;
     SDL_bool updateSize;
     SDL_bool beginScene;
+    D3DTEXTUREFILTERTYPE scaleMode;
 } D3D_RenderData;
 
 typedef struct
 {
     IDirect3DTexture9 *texture;
+    D3DTEXTUREFILTERTYPE scaleMode;
 } D3D_TextureData;
 
 typedef struct
@@ -451,6 +454,7 @@
         return NULL;
     }
     data->beginScene = SDL_TRUE;
+    data->scaleMode = D3DTEXF_FORCE_DWORD;
 
     /* Get presentation parameters to fill info */
     result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
@@ -537,6 +541,20 @@
     }
 }
 
+static D3DTEXTUREFILTERTYPE
+GetScaleQuality(void)
+{
+    const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY);
+
+    if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
+        return D3DTEXF_POINT;
+    } else if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) {
+        return D3DTEXF_LINEAR;
+    } else {
+        return D3DTEXF_ANISOTROPIC;
+    }
+}
+
 static int
 D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 {
@@ -553,6 +571,7 @@
         SDL_OutOfMemory();
         return -1;
     }
+    data->scaleMode = GetScaleQuality();
 
     texture->driverdata = data;
 
@@ -1018,10 +1037,13 @@
 
     D3D_SetBlendMode(data, texture->blendMode);
 
-    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
-                                     D3DTEXF_LINEAR);
-    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
-                                     D3DTEXF_LINEAR);
+    if (texturedata->scaleMode != data->scaleMode) {
+        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
+                                         texturedata->scaleMode);
+        IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
+                                         texturedata->scaleMode);
+        data->scaleMode = texturedata->scaleMode;
+    }
 
     result =
         IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)