[2/2] wined3d: Cleanup the pixelshader() state handler a little bit

H. Verbeet hverbeet at gmail.com
Mon Feb 12 19:24:08 CST 2007


Essentially the same block for selecting the shader pair is executed
both when a pixel shader is used and when it isn't, so move that out
of the if/else block and use a construction similar to what's used in
the vertexdeclaration() state handler.

Changelog:
  - Cleanup the pixelshader() state handler a little bit
-------------- next part --------------
---

 dlls/wined3d/state.c |   32 ++++++++++----------------------
 1 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index c5f54ab..618ecb7 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -1904,9 +1904,11 @@ static void shaderconstant(DWORD state, IWineD3DStateBlockImpl *stateblock) {
 }
 
 static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
+    BOOL use_ps = stateblock->pixelShader && ((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.function != NULL;
+    BOOL use_vs = stateblock->vertexShader && ((IWineD3DVertexShaderImpl *)stateblock->vertexShader)->baseShader.function != NULL;
     int i;
 
-    if(stateblock->pixelShader && ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.function != NULL) {
+    if (use_ps) {
         if(!stateblock->wineD3DDevice->last_was_pshader) {
             /* Former draw without a pixel shader, some samplers
              * may be disabled because of WINED3DTSS_COLOROP = WINED3DTOP_DISABLE
@@ -1925,18 +1927,6 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
 
         /* Compile and bind the shader */
         IWineD3DPixelShader_CompileShader(stateblock->pixelShader);
-
-        if(!isStateDirty(stateblock->wineD3DDevice, StateTable[STATE_VSHADER].representative)) {
-            stateblock->wineD3DDevice->shader_backend->shader_select(
-                    (IWineD3DDevice *) stateblock->wineD3DDevice,
-                    TRUE,
-                    !stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
-            
-            if(!isStateDirty(stateblock->wineD3DDevice, STATE_VERTEXSHADERCONSTANT)) {
-                shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock);
-            }
-        }
-        stateblock->wineD3DDevice->last_was_pshader = TRUE;
     } else {
         /* Disabled the pixel shader - color ops weren't applied
          * while it was enabled, so re-apply them.
@@ -1946,19 +1936,17 @@ static void pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock) {
                 tex_colorop(STATE_TEXTURESTAGE(i, WINED3DTSS_COLOROP), stateblock);
             }
         }
-        stateblock->wineD3DDevice->last_was_pshader = FALSE;
+    }
 
-        if(!isStateDirty(stateblock->wineD3DDevice, StateTable[STATE_VSHADER].representative)) {
-            stateblock->wineD3DDevice->shader_backend->shader_select(
-                    (IWineD3DDevice *) stateblock->wineD3DDevice,
-                    FALSE,
-                    !stateblock->vertexShader ? FALSE : ((IWineD3DVertexShaderImpl *) stateblock->vertexShader)->baseShader.function != NULL);
+    if(!isStateDirty(stateblock->wineD3DDevice, StateTable[STATE_VSHADER].representative)) {
+        stateblock->wineD3DDevice->shader_backend->shader_select((IWineD3DDevice *)stateblock->wineD3DDevice, use_ps, use_vs);
 
-            if(!isStateDirty(stateblock->wineD3DDevice, STATE_VERTEXSHADERCONSTANT)) {
-                shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock);
-            }
+        if(!isStateDirty(stateblock->wineD3DDevice, STATE_VERTEXSHADERCONSTANT) && (use_vs || use_ps)) {
+            shaderconstant(STATE_VERTEXSHADERCONSTANT, stateblock);
         }
     }
+
+    stateblock->wineD3DDevice->last_was_pshader = use_ps;
 }
 
 static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock) {


More information about the wine-patches mailing list