Henri Verbeet : ddraw: Fix and clarify texture filter state mappings.

Alexandre Julliard julliard at winehq.org
Tue Apr 6 11:20:06 CDT 2010


Module: wine
Branch: master
Commit: f97a9e3c0f35156193d1a001501b1ca0f0588a3d
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=f97a9e3c0f35156193d1a001501b1ca0f0588a3d

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Mon Apr  5 21:10:17 2010 +0200

ddraw: Fix and clarify texture filter state mappings.

---

 dlls/ddraw/device.c |   89 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index f70fdba..aba7bdc 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -2409,22 +2409,60 @@ IDirect3DDeviceImpl_7_GetRenderState(IDirect3DDevice7 *iface,
         case D3DRENDERSTATE_TEXTUREMIN:
         {
             WINED3DTEXTUREFILTERTYPE tex_min;
+            WINED3DTEXTUREFILTERTYPE tex_mip;
 
             hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
-                                                0, WINED3DSAMP_MINFILTER,
-                                                &tex_min);
+                    0, WINED3DSAMP_MINFILTER, &tex_min);
+            if (FAILED(hr))
+            {
+                LeaveCriticalSection(&ddraw_cs);
+                return hr;
+            }
+            hr = IWineD3DDevice_GetSamplerState(This->wineD3DDevice,
+                    0, WINED3DSAMP_MIPFILTER, &tex_mip);
 
             switch (tex_min)
             {
                 case WINED3DTEXF_POINT:
-                    *Value = D3DFILTER_NEAREST;
+                    switch (tex_mip)
+                    {
+                        case WINED3DTEXF_NONE:
+                            *Value = D3DFILTER_NEAREST;
+                            break;
+                        case WINED3DTEXF_POINT:
+                            *Value = D3DFILTER_MIPNEAREST;
+                            break;
+                        case WINED3DTEXF_LINEAR:
+                            *Value = D3DFILTER_LINEARMIPNEAREST;
+                            break;
+                        default:
+                            ERR("Unhandled mip filter %#x.\n", tex_mip);
+                            *Value = D3DFILTER_NEAREST;
+                            break;
+                    }
                     break;
                 case WINED3DTEXF_LINEAR:
-                    *Value = D3DFILTER_LINEAR;
+                    switch (tex_mip)
+                    {
+                        case WINED3DTEXF_NONE:
+                            *Value = D3DFILTER_LINEAR;
+                            break;
+                        case WINED3DTEXF_POINT:
+                            *Value = D3DFILTER_MIPLINEAR;
+                            break;
+                        case WINED3DTEXF_LINEAR:
+                            *Value = D3DFILTER_LINEARMIPLINEAR;
+                            break;
+                        default:
+                            ERR("Unhandled mip filter %#x.\n", tex_mip);
+                            *Value = D3DFILTER_LINEAR;
+                            break;
+                    }
                     break;
                 default:
-                    ERR("Unhandled texture mag %d !\n",tex_min);
-                    *Value = 0;
+                    ERR("Unhandled texture min filter %#x.\n",tex_min);
+                    *Value = D3DFILTER_NEAREST;
+                    break;
             }
             break;
         }
@@ -2652,22 +2690,39 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
     /* Some render states need special care */
     switch(RenderStateType)
     {
+        /*
+         * The ddraw texture filter mapping works like this:
+         *     D3DFILTER_NEAREST            Point min/mag, no mip
+         *     D3DFILTER_MIPNEAREST         Point min/mag, point mip
+         *     D3DFILTER_LINEARMIPNEAREST:  Point min/mag, linear mip
+         *
+         *     D3DFILTER_LINEAR             Linear min/mag, no mip
+         *     D3DFILTER_MIPLINEAR          Linear min/mag, point mip
+         *     D3DFILTER_LINEARMIPLINEAR    Linear min/mag, linear mip
+         *
+         * This is the opposite of the GL naming convention,
+         * D3DFILTER_LINEARMIPNEAREST corresponds to GL_NEAREST_MIPMAP_LINEAR.
+         */
         case D3DRENDERSTATE_TEXTUREMAG:
         {
-            WINED3DTEXTUREFILTERTYPE tex_mag = WINED3DTEXF_POINT;
+            WINED3DTEXTUREFILTERTYPE tex_mag;
 
-            switch ((D3DTEXTUREFILTER) Value)
+            switch (Value)
             {
                 case D3DFILTER_NEAREST:
+                case D3DFILTER_MIPNEAREST:
                 case D3DFILTER_LINEARMIPNEAREST:
                     tex_mag = WINED3DTEXF_POINT;
                     break;
                 case D3DFILTER_LINEAR:
+                case D3DFILTER_MIPLINEAR:
                 case D3DFILTER_LINEARMIPLINEAR:
                     tex_mag = WINED3DTEXF_LINEAR;
                     break;
                 default:
+                    tex_mag = WINED3DTEXF_POINT;
                     ERR("Unhandled texture mag %d !\n",Value);
+                    break;
             }
 
             hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
@@ -2678,24 +2733,26 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
 
         case D3DRENDERSTATE_TEXTUREMIN:
         {
-            WINED3DTEXTUREFILTERTYPE tex_min = WINED3DTEXF_POINT;
-            WINED3DTEXTUREFILTERTYPE tex_mip = WINED3DTEXF_NONE;
+            WINED3DTEXTUREFILTERTYPE tex_min;
+            WINED3DTEXTUREFILTERTYPE tex_mip;
 
             switch ((D3DTEXTUREFILTER) Value)
             {
                 case D3DFILTER_NEAREST:
                     tex_min = WINED3DTEXF_POINT;
+                    tex_mip = WINED3DTEXF_NONE;
                     break;
                 case D3DFILTER_LINEAR:
                     tex_min = WINED3DTEXF_LINEAR;
+                    tex_mip = WINED3DTEXF_NONE;
                     break;
                 case D3DFILTER_MIPNEAREST:
                     tex_min = WINED3DTEXF_POINT;
                     tex_mip = WINED3DTEXF_POINT;
                     break;
                 case D3DFILTER_MIPLINEAR:
-                    tex_min = WINED3DTEXF_POINT;
-                    tex_mip = WINED3DTEXF_LINEAR;
+                    tex_min = WINED3DTEXF_LINEAR;
+                    tex_mip = WINED3DTEXF_POINT;
                     break;
                 case D3DFILTER_LINEARMIPNEAREST:
                     tex_min = WINED3DTEXF_POINT;
@@ -2708,11 +2765,13 @@ IDirect3DDeviceImpl_7_SetRenderState(IDirect3DDevice7 *iface,
 
                 default:
                     ERR("Unhandled texture min %d !\n",Value);
+                    tex_min = WINED3DTEXF_POINT;
+                    tex_mip = WINED3DTEXF_NONE;
+                    break;
             }
 
-                   IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
-                                                  0, WINED3DSAMP_MIPFILTER,
-                                                  tex_mip);
+            IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
+                    0, WINED3DSAMP_MIPFILTER, tex_mip);
             hr = IWineD3DDevice_SetSamplerState(This->wineD3DDevice,
                                                 0, WINED3DSAMP_MINFILTER,
                                                 tex_min);




More information about the wine-cvs mailing list