Stefan Dösinger : wined3d: Color keying emulation.

Alexandre Julliard julliard at wine.codeweavers.com
Thu May 25 04:15:54 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 93db443319ae99e1f499a9b2982ddfae19828040
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=93db443319ae99e1f499a9b2982ddfae19828040

Author: Stefan Dösinger <stefan at codeweavers.com>
Date:   Wed May 24 17:15:24 2006 +0200

wined3d: Color keying emulation.

---

 dlls/wined3d/device.c |   92 +++++++++++++++++++++++++++++++------------------
 1 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 5ac899c..efa6836 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3212,46 +3212,55 @@ HRESULT WINAPI IWineD3DDeviceImpl_SetRen
         break;
 
     case WINED3DRS_ALPHATESTENABLE           :
-        if (Value) {
-            glEnable(GL_ALPHA_TEST);
-            checkGLcall("glEnable GL_ALPHA_TEST");
-        } else {
-            glDisable(GL_ALPHA_TEST);
-            checkGLcall("glDisable GL_ALPHA_TEST");
-        }
-        break;
-
     case WINED3DRS_ALPHAFUNC                 :
+    case WINED3DRS_ALPHAREF                  :
+    case WINED3DRS_COLORKEYENABLE            :
         {
-            int glParm = GL_LESS;
-            float ref = ((float) This->stateBlock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
+            int glParm = 0.0;
+            float ref = GL_LESS;
+            BOOL enable_ckey = FALSE;
 
-            switch ((D3DCMPFUNC) Value) {
-            case D3DCMP_NEVER:         glParm = GL_NEVER; break;
-            case D3DCMP_LESS:          glParm = GL_LESS; break;
-            case D3DCMP_EQUAL:         glParm = GL_EQUAL; break;
-            case D3DCMP_LESSEQUAL:     glParm = GL_LEQUAL; break;
-            case D3DCMP_GREATER:       glParm = GL_GREATER; break;
-            case D3DCMP_NOTEQUAL:      glParm = GL_NOTEQUAL; break;
-            case D3DCMP_GREATEREQUAL:  glParm = GL_GEQUAL; break;
-            case D3DCMP_ALWAYS:        glParm = GL_ALWAYS; break;
-            default:
-                FIXME("Unrecognized/Unhandled D3DCMPFUNC value %ld\n", Value);
+            IWineD3DSurfaceImpl *surf;
+
+            /* Find out if the texture on the first stage has a ckey set */
+            if(This->stateBlock->textures[0]) {
+                surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)This->stateBlock->textures[0])->surfaces[0];
+                if(surf->CKeyFlags & DDSD_CKSRCBLT) enable_ckey = TRUE;
             }
-            TRACE("glAlphaFunc with Parm=%x, ref=%f\n", glParm, ref);
-            glAlphaFunc(glParm, ref);
-            This->alphafunc = glParm;
-            checkGLcall("glAlphaFunc");
-        }
-        break;
 
-    case WINED3DRS_ALPHAREF                  :
-        {
-            int glParm = This->alphafunc;
-            float ref = 1.0f;
+            if (This->stateBlock->renderState[WINED3DRS_ALPHATESTENABLE] ||
+                (This->stateBlock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey)) {
+                glEnable(GL_ALPHA_TEST);
+                checkGLcall("glEnable GL_ALPHA_TEST");
+            } else {
+                glDisable(GL_ALPHA_TEST);
+                checkGLcall("glDisable GL_ALPHA_TEST");
+                /* Alpha test is disabled, don't bother setting the params - it will happen on the next
+                 * enable call
+                 */
+                 break;
+            }
 
-            ref = ((float) Value) / 255.0f;
-            TRACE("glAlphaFunc with Parm=%x, ref=%f\n", glParm, ref);
+            if(This->stateBlock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey) {
+                glParm = GL_NOTEQUAL;
+                ref = 0.0;
+            } else {
+                ref = ((float) This->stateBlock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
+
+                switch ((D3DCMPFUNC) This->stateBlock->renderState[WINED3DRS_ALPHAFUNC]) {
+                case D3DCMP_NEVER:         glParm = GL_NEVER; break;
+                case D3DCMP_LESS:          glParm = GL_LESS; break;
+                case D3DCMP_EQUAL:         glParm = GL_EQUAL; break;
+                case D3DCMP_LESSEQUAL:     glParm = GL_LEQUAL; break;
+                case D3DCMP_GREATER:       glParm = GL_GREATER; break;
+                case D3DCMP_NOTEQUAL:      glParm = GL_NOTEQUAL; break;
+                case D3DCMP_GREATEREQUAL:  glParm = GL_GEQUAL; break;
+                case D3DCMP_ALWAYS:        glParm = GL_ALWAYS; break;
+                default:
+                    FIXME("Unrecognized/Unhandled D3DCMPFUNC value %ld\n", Value);
+                }
+            }
+            This->alphafunc = glParm;
             glAlphaFunc(glParm, ref);
             checkGLcall("glAlphaFunc");
         }
@@ -5231,6 +5240,21 @@ #endif
         IWineD3DBaseTexture_Release(oldTexture);
     }
 
+    /* Reset color keying */
+    if(Stage == 0 && This->stateBlock->renderState[WINED3DRS_COLORKEYENABLE]) {
+        BOOL enable_ckey = FALSE;
+
+        if(pTexture) {
+            IWineD3DSurfaceImpl *surf = (IWineD3DSurfaceImpl *) ((IWineD3DTextureImpl *)pTexture)->surfaces[0];
+            if(surf->CKeyFlags & DDSD_CKSRCBLT) enable_ckey = TRUE;
+        }
+
+        if(enable_ckey) {
+            glAlphaFunc(GL_NOTEQUAL, 0.0);
+            checkGLcall("glAlphaFunc");
+        }
+    }
+
     return WINED3D_OK;
 }
 




More information about the wine-cvs mailing list