[3/15] WineD3D: Move material applying to the state table

Stefan Dösinger stefan at codeweavers.com
Wed Jan 10 04:26:12 CST 2007


-------------- next part --------------
From 90d250a42a4ea396672635d53f00c562f8e1932f Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Sat, 6 Jan 2007 20:33:52 +0100
Subject: [PATCH] WineD3D: Move the material applying to the state table

---
 dlls/wined3d/drawprim.c |   34 ----------------------------------
 dlls/wined3d/state.c    |   35 ++++++++++++++++++++++++-----------
 2 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 2e4a694..b46192e 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -90,37 +90,6 @@ static DWORD primitiveToGl(WINED3DPRIMITIVETYPE PrimitiveType,
     return NumVertexes;
 }
 
-/* Ensure the appropriate material states are set up - only change
-   state if really required                                        */
-static void init_materials(IWineD3DDevice *iface, BOOL isDiffuseSupplied) {
-
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    if (This->tracking_color == NEEDS_TRACKING && isDiffuseSupplied) {
-        /* If we have not set up the material color tracking, do it now as required */
-        glDisable(GL_COLOR_MATERIAL); /* Note: Man pages state must enable AFTER calling glColorMaterial! Required?*/
-        checkGLcall("glDisable GL_COLOR_MATERIAL");
-        TRACE("glColorMaterial Parm=%x\n", This->tracking_parm);
-        glColorMaterial(GL_FRONT_AND_BACK, This->tracking_parm);
-        checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
-        glEnable(GL_COLOR_MATERIAL);
-        checkGLcall("glEnable GL_COLOR_MATERIAL");
-        This->tracking_color = IS_TRACKING;
-    } else if ((This->tracking_color == IS_TRACKING && !isDiffuseSupplied) ||
-               (This->tracking_color == NEEDS_TRACKING && !isDiffuseSupplied)) {
-        /* If we are tracking the current color but one isn't supplied, don't! */
-        glDisable(GL_COLOR_MATERIAL);
-        checkGLcall("glDisable GL_COLOR_MATERIAL");
-        This->tracking_color = NEEDS_TRACKING;
-    } else if (This->tracking_color == IS_TRACKING && isDiffuseSupplied) {
-        /* No need to reset material colors since no change to gl_color_material */
-    } else if (This->tracking_color == NEEDS_DISABLE) {
-        glDisable(GL_COLOR_MATERIAL);
-        checkGLcall("glDisable GL_COLOR_MATERIAL");
-        This->tracking_color = DISABLED_TRACKING;
-    }
-}
-
 static BOOL fixed_get_input(
     BYTE usage, BYTE usage_idx,
     unsigned int* regnum) {
@@ -1248,9 +1217,6 @@ void drawPrimitive(IWineD3DDevice *iface,
     }
     This->depth_copy_state = WINED3D_DCS_INITIAL;
 
-    /* Now initialize the materials state */
-    init_materials(iface, (This->strided_streams.u.s.diffuse.lpData != NULL || This->strided_streams.u.s.diffuse.VBO != 0));
-
     {
         GLenum glPrimType;
         /* Ok, Work out which primitive is requested and how many vertexes that
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index af899e5..bfcd0eb 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -806,7 +806,18 @@ static void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock) {
 
 /* TODO: Merge with primitive type + init_materials()!! */
 static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock) {
-    GLenum Parm = GL_AMBIENT_AND_DIFFUSE;
+    GLenum Parm = -1;
+    WineDirect3DStridedData *diffuse = &stateblock->wineD3DDevice->strided_streams.u.s.diffuse;
+    BOOL isDiffuseSupplied;
+
+    /* Depends on the decoded vertex declaration to read the existance of diffuse data.
+     * The vertex declaration will call this function if the fixed function pipeline is used.
+     */
+    if(isStateDirty(stateblock->wineD3DDevice, STATE_VDECL)) {
+        return;
+    }
+
+    isDiffuseSupplied = diffuse->lpData || diffuse->VBO;
 
     if (stateblock->renderState[WINED3DRS_COLORVERTEX]) {
         TRACE("diff %d, amb %d, emis %d, spec %d\n",
@@ -827,19 +838,17 @@ static void state_colormat(DWORD state, IWineD3DStateBlockImpl *stateblock) {
             Parm = GL_EMISSION;
         } else if (stateblock->renderState[WINED3DRS_SPECULARMATERIALSOURCE] == D3DMCS_COLOR1) {
             Parm = GL_SPECULAR;
-        } else {
-            Parm = -1;
-        }
-
-        if (Parm == -1) {
-            if (stateblock->wineD3DDevice->tracking_color != DISABLED_TRACKING) stateblock->wineD3DDevice->tracking_color = NEEDS_DISABLE;
-        } else {
-            stateblock->wineD3DDevice->tracking_color = NEEDS_TRACKING;
-            stateblock->wineD3DDevice->tracking_parm  = Parm;
         }
+    }
 
+    if(Parm == -1 || !isDiffuseSupplied) {
+        glDisable(GL_COLOR_MATERIAL);
+        checkGLcall("glDisable GL_COLOR_MATERIAL");
     } else {
-        if (stateblock->wineD3DDevice->tracking_color != DISABLED_TRACKING) stateblock->wineD3DDevice->tracking_color = NEEDS_DISABLE;
+        glColorMaterial(GL_FRONT_AND_BACK, Parm);
+        checkGLcall("glColorMaterial(GL_FRONT_AND_BACK, Parm)");
+        glEnable(GL_COLOR_MATERIAL);
+        checkGLcall("glEnable(GL_COLOR_MATERIAL)");
     }
 }
 
@@ -2678,6 +2687,10 @@ static void vertexdeclaration(DWORD state, IWineD3DStateBlockImpl *stateblock) {
            !isStateDirty(stateblock->wineD3DDevice, STATE_TRANSFORM(WINED3DTS_VIEW))) {
             transform_world(STATE_TRANSFORM(WINED3DTS_WORLDMATRIX(0)), stateblock);
         }
+
+        if(!isStateDirty(stateblock->wineD3DDevice, STATE_RENDER(WINED3DRS_COLORVERTEX))) {
+            state_colormat(STATE_RENDER(WINED3DRS_COLORVERTEX), stateblock);
+        }
     } else {
         /* We compile the shader here because we need the vertex declaration
          * in order to determine if we need to do any swizzling for D3DCOLOR
-- 
1.4.4.3



More information about the wine-patches mailing list