[13/16] WineD3D: Break out the lighting state from the vertex declaration

Stefan Dösinger stefandoesinger at gmx.at
Mon Jan 1 18:34:22 CST 2007


The vertex declaration affects lighting, but it is pointless to  
reparse and apply the vdecl and stream sources when just the lighting  
is changed. The reenabled state_lighting function reads the decoded  
vertex declaration, and it does not perform anything if a vdecl  
update is sheduled. vertexdeclaration() will call lighting to update  
the lights, but only if the light state is not dirty yet.

Yes, states are marked clean before the apply func is called ;-)

-------------- next part --------------
From 7949b28ed42d67d5e596c4efee49390042c83e3d Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Stefan_D=C3=B6singer?= <stefan at imac.local>
Date: Wed, 27 Dec 2006 16:16:11 +0100
Subject: [PATCH] WineD3D: Break out lighting from the vertex declaration state

---
 dlls/wined3d/state.c |   35 ++++++++++++++++++-----------------
 1 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 3922ecf..a12f3aa 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -71,15 +71,23 @@ static void state_fillmode(DWORD state, 
     }
 }
 
-#if 0
-/* if 0ed because it will be revived later */
 static void state_lighting(DWORD state, IWineD3DStateBlockImpl *stateblock) {
+    BOOL normals;
 
-    /* TODO: Lighting is only enabled if Vertex normals are passed by the application,
-     * so merge the lighting render state with the vertex declaration once it is available
+    /* Lighting is only enabled if Vertex normals are passed by the application,
+     * but lighting does not affect the stream sources, so it is not grouped for performance reasons.
+     * This state reads the decoded vertex decl, so if it is dirty don't do anything. The
+     * vertex declaration appplying function calls this function for updating
      */
 
-    if (stateblock->renderState[WINED3DRS_LIGHTING]) {
+	if(isStateDirty(stateblock->wineD3DDevice, STATE_VDECL)) {
+		return;
+	}
+
+    normals = stateblock->wineD3DDevice->strided_streams.u.s.normal.lpData != NULL ||
+              stateblock->wineD3DDevice->strided_streams.u.s.normal.VBO != 0;
+
+    if (stateblock->renderState[WINED3DRS_LIGHTING] && normals) {
         glEnable(GL_LIGHTING);
         checkGLcall("glEnable GL_LIGHTING");
     } else {
@@ -87,7 +95,6 @@ static void state_lighting(DWORD state, 
         checkGLcall("glDisable GL_LIGHTING");
     }
 }
-#endif
 
 static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock) {
     switch ((WINED3DZBUFFERTYPE) stateblock->renderState[WINED3DRS_ZENABLE]) {
@@ -1947,16 +1954,10 @@ static void vertexdeclaration(DWORD stat
 		updateFog = TRUE;
 	}
 
-	/* TODO: The vertex declaration changes lighting, but lighting doesn't affect the vertex declaration and the
-	 * stream sources. This can be handled nicer
-	 */
-	if(stateblock->renderState[WINED3DRS_LIGHTING] && !lit) {
-		glEnable(GL_LIGHTING);
-		checkGLcall("glEnable(GL_LIGHTING)");
-	} else {
-		glDisable(GL_LIGHTING);
-		checkGLcall("glDisable(GL_LIGHTING");
-	}
+    /* Reapply lighting if it is not sheduled for reapplication already */
+    if(!isStateDirty(stateblock->wineD3DDevice, STATE_RENDER(WINED3DRS_LIGHTING))) {
+        state_lighting(STATE_RENDER(WINED3DRS_LIGHTING), stateblock);
+    }
 
     if (!useVertexShaderFunction && transformed) {
         d3ddevice_set_ortho(stateblock->wineD3DDevice);
@@ -2165,7 +2166,7 @@ const struct StateEntry StateTable[] =
     { /*134, WINED3DRS_WRAP6                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
     { /*135, WINED3DRS_WRAP7                        */      STATE_RENDER(WINED3DRS_WRAP0),                      state_wrap          },
     { /*136, WINED3DRS_CLIPPING                     */      STATE_RENDER(WINED3DRS_CLIPPING),                   state_clipping      },
-    { /*137, WINED3DRS_LIGHTING                     */      STATE_VDECL,                                        vertexdeclaration   },
+    { /*137, WINED3DRS_LIGHTING                     */      STATE_RENDER(WINED3DRS_LIGHTING),                   state_lighting      },
     { /*138, WINED3DRS_EXTENTS                      */      STATE_RENDER(WINED3DRS_EXTENTS),                    state_extents       },
     { /*139, WINED3DRS_AMBIENT                      */      STATE_RENDER(WINED3DRS_AMBIENT),                    state_ambient       },
     { /*140, WINED3DRS_FOGVERTEXMODE                */      STATE_RENDER(WINED3DRS_FOGENABLE),                  state_fog           },
-- 
1.4.2.4



More information about the wine-patches mailing list