[PATCH] WineD3D: Remove the pixelshader fogstart/fogend =

Stefan Doesinger stefan at codeweavers.com
Sun Dec 14 17:00:21 CST 2008


optimization=0A=
=0A=
This optimization is implemented in a rather hacky way and blocks any =
effort=0A=
to clean up state_fog. Remove it for now. We can readd it later.=0A=
=0A=
In the ARB_fragment_program code we do not need it at all. We can use the=0A=
OPTION FOG_xxxx options to use the hardware's fog calculation code, =
which was=0A=
made impossible by that optimization anyway.=0A=
=0A=
in GLSL it is trickier. At least with a full GLSL pipeline we can readd =
this=0A=
in a non-hacky way later.=0A=
---=0A=
 dlls/wined3d/arb_program_shader.c |    9 ++-=0A=
 dlls/wined3d/glsl_shader.c        |    4 +-=0A=
 dlls/wined3d/state.c              |  103 =
++++++++-----------------------------=0A=
 3 files changed, 31 insertions(+), 85 deletions(-)=0A=
=0A=
diff --git a/dlls/wined3d/arb_program_shader.c =
b/dlls/wined3d/arb_program_shader.c=0A=
index cd6ba29..438b025 100644=0A=
--- a/dlls/wined3d/arb_program_shader.c=0A=
+++ b/dlls/wined3d/arb_program_shader.c=0A=
@@ -1969,9 +1969,12 @@ static GLuint =
shader_arb_generate_pshader(IWineD3DPixelShader *iface, SHADER_BUF=0A=
                 shader_addline(buffer, "MOV result.color, %s;\n", =
fragcolor);=0A=
                 break;=0A=
             case FOG_LINEAR:=0A=
-                shader_addline(buffer, "MAD_SAT TMP_FOG, =
fragment.fogcoord, state.fog.params.y, state.fog.params.z;\n");=0A=
-                shader_addline(buffer, "LRP result.color.xyz, =
TMP_FOG.x, %s, state.fog.color;\n", fragcolor);=0A=
-                shader_addline(buffer, "MOV result.color.w, %s.w;\n", =
fragcolor);=0A=
+                shader_addline(buffer, "SUB TMP_FOG.x, =
state.fog.params.z, state.fog.params.y;\n");=0A=
+                shader_addline(buffer, "RCP TMP_FOG, -TMP_FOG.x;\n");=0A=
+                shader_addline(buffer, "MUL TMP_FOG.y, -TMP_FOG.y, =
state.fog.params.z;\n");=0A=
+                shader_addline(buffer, "MAD_SAT TMP_FOG, =
fragment.fogcoord, TMP_FOG.x, TMP_FOG.y;\n");=0A=
+                shader_addline(buffer, "LRP result.color.rgb, =
TMP_FOG.x, %s, state.fog.color;\n", fragcolor);=0A=
+                shader_addline(buffer, "MOV result.color.a, %s.a;\n", =
fragcolor);=0A=
                 break;=0A=
             case FOG_EXP:=0A=
                 FIXME("Implement EXP fog in ARB\n");=0A=
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c=0A=
index 0acdcad..8dfb416 100644=0A=
--- a/dlls/wined3d/glsl_shader.c=0A=
+++ b/dlls/wined3d/glsl_shader.c=0A=
@@ -3844,7 +3844,9 @@ static GLuint =
shader_glsl_generate_pshader(IWineD3DPixelShader *iface, SHADER_BU=0A=
         switch(args->fog) {=0A=
             case FOG_OFF: break;=0A=
             case FOG_LINEAR:=0A=
-                shader_addline(buffer, "float Fog =3D =
clamp(gl_FogFragCoord * gl_Fog.start + gl_Fog.end, 0.0, 1.0);\n");=0A=
+                shader_addline(buffer, "float fogstart =3D -1.0 / =
(gl_Fog.end - gl_Fog.start);\n");=0A=
+                shader_addline(buffer, "float fogend =3D gl_Fog.end * =
-fogstart;\n");=0A=
+                shader_addline(buffer, "float Fog =3D =
clamp(gl_FogFragCoord * fogstart + fogend, 0.0, 1.0);\n");=0A=
                 shader_addline(buffer, "%s.xyz =3D =
mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);=0A=
                 break;=0A=
             case FOG_EXP:=0A=
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c=0A=
index b054ee1..e2989f3 100644=0A=
--- a/dlls/wined3d/state.c=0A=
+++ b/dlls/wined3d/state.c=0A=
@@ -897,9 +897,6 @@ static void state_stencilwrite(DWORD state, =
IWineD3DStateBlockImpl *stateblock,=0A=
 }=0A=
 =0A=
 static void state_fog(DWORD state, IWineD3DStateBlockImpl *stateblock, =
WineD3DContext *context) {=0A=
-    BOOL fogenable =3D stateblock->renderState[WINED3DRS_FOGENABLE];=0A=
-    IWineD3DPixelShaderImpl *ps_impl =3D (IWineD3DPixelShaderImpl =
*)stateblock->pixelShader;=0A=
-    BOOL is_ps3 =3D use_ps(stateblock) && =
ps_impl->baseShader.reg_maps.shader_version >=3D WINED3DPS_VERSION(3,0);=0A=
     float fogstart, fogend;=0A=
 =0A=
     union {=0A=
@@ -907,7 +904,7 @@ static void state_fog(DWORD state, =
IWineD3DStateBlockImpl *stateblock, WineD3DCo=0A=
         float f;=0A=
     } tmpvalue;=0A=
 =0A=
-    if (!fogenable) {=0A=
+    if (!stateblock->renderState[WINED3DRS_FOGENABLE]) {=0A=
         /* No fog? Disable it, and we're done :-) */=0A=
         glDisable(GL_FOG);=0A=
         checkGLcall("glDisable GL_FOG");=0A=
@@ -955,19 +952,9 @@ static void state_fog(DWORD state, =
IWineD3DStateBlockImpl *stateblock, WineD3DCo=0A=
      * without shaders).=0A=
      */=0A=
 =0A=
-    if( is_ps3 ) {=0A=
-        if (!use_vs(stateblock) && =
stateblock->renderState[WINED3DRS_FOGTABLEMODE] =3D=3D WINED3DFOG_NONE)=0A=
-        {=0A=
-            FIXME("Implement vertex fog for pixel shader >=3D 3.0 and =
fixed function pipeline\n");=0A=
-        }=0A=
-    }=0A=
-=0A=
-    if (use_vs(stateblock) && ((IWineD3DVertexShaderImpl =
*)stateblock->vertexShader)->baseShader.reg_maps.fog)=0A=
-    {=0A=
+    if (use_vs(stateblock) && ((IWineD3DVertexShaderImpl =
*)stateblock->vertexShader)->baseShader.reg_maps.fog) {=0A=
         if( stateblock->renderState[WINED3DRS_FOGTABLEMODE] !=3D =
WINED3DFOG_NONE ) {=0A=
-            if(!is_ps3) FIXME("Implement table fog for foggy vertex =
shader\n");=0A=
-            /* Disable fog */=0A=
-            fogenable =3D FALSE;=0A=
+            FIXME("vertex shader with table fog used\n");=0A=
         } else {=0A=
             /* Set fog computation in the rasterizer to pass through =
the value (just blend it) */=0A=
             glFogi(GL_FOG_MODE, GL_LINEAR);=0A=
@@ -983,47 +970,6 @@ static void state_fog(DWORD state, =
IWineD3DStateBlockImpl *stateblock, WineD3DCo=0A=
         }=0A=
         context->last_was_foggy_shader =3D TRUE;=0A=
     }=0A=
-    else if (use_ps(stateblock))=0A=
-    {=0A=
-        /* NOTE: For pixel shader, GL_FOG_START and GL_FOG_END don't =
hold fog start s and end e but=0A=
-         * -1/(e-s) and e/(e-s) respectively to simplify fog =
computation in the shader.=0A=
-         */=0A=
-        WINED3DFOGMODE mode;=0A=
-        context->last_was_foggy_shader =3D FALSE;=0A=
-=0A=
-        /* If both fogmodes are set use the table fog mode */=0A=
-        if(stateblock->renderState[WINED3DRS_FOGTABLEMODE] =3D=3D =
WINED3DFOG_NONE)=0A=
-            mode =3D stateblock->renderState[WINED3DRS_FOGVERTEXMODE];=0A=
-        else=0A=
-            mode =3D stateblock->renderState[WINED3DRS_FOGTABLEMODE];=0A=
-=0A=
-        switch (mode) {=0A=
-            case WINED3DFOG_EXP:=0A=
-            case WINED3DFOG_EXP2:=0A=
-                if(!is_ps3) FIXME("Implement non linear fog for pixel =
shader < 3.0\n");=0A=
-                /* Disable fog */=0A=
-                fogenable =3D FALSE;=0A=
-                break;=0A=
-=0A=
-            case WINED3DFOG_LINEAR:=0A=
-                fogstart =3D -1.0f/(fogend-fogstart);=0A=
-                fogend *=3D -fogstart;=0A=
-                break;=0A=
-=0A=
-            case WINED3DFOG_NONE:=0A=
-                if(!is_ps3) FIXME("Implement software vertex fog for =
pixel shader < 3.0\n");=0A=
-                /* Disable fog */=0A=
-                fogenable =3D FALSE;=0A=
-                break;=0A=
-            default: FIXME("Unexpected WINED3DRS_FOGVERTEXMODE %d\n", =
stateblock->renderState[WINED3DRS_FOGVERTEXMODE]);=0A=
-        }=0A=
-=0A=
-        if(context->fog_coord) {=0A=
-            glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);=0A=
-            checkGLcall("glFogi(GL_FOG_COORDINATE_SOURCE_EXT, =
GL_FRAGMENT_DEPTH_EXT)");=0A=
-            context->fog_coord =3D FALSE;=0A=
-        }=0A=
-    }=0A=
     /* DX 7 sdk: "If both render states(vertex and table fog) are set =
to valid modes,=0A=
      * the system will apply only pixel(=3Dtable) fog effects."=0A=
      */=0A=
@@ -1130,33 +1076,28 @@ static void state_fog(DWORD state, =
IWineD3DStateBlockImpl *stateblock, WineD3DCo=0A=
         }=0A=
     }=0A=
 =0A=
-    if(fogenable) {=0A=
-        glEnable(GL_FOG);=0A=
-        checkGLcall("glEnable GL_FOG");=0A=
+    glEnable(GL_FOG);=0A=
+    checkGLcall("glEnable GL_FOG");=0A=
 =0A=
-        if(fogstart !=3D fogend)=0A=
-        {=0A=
-            glFogfv(GL_FOG_START, &fogstart);=0A=
-            checkGLcall("glFogf(GL_FOG_START, fogstart)");=0A=
-            TRACE("Fog Start =3D=3D %f\n", fogstart);=0A=
+    if(fogstart !=3D fogend)=0A=
+    {=0A=
+        glFogfv(GL_FOG_START, &fogstart);=0A=
+        checkGLcall("glFogf(GL_FOG_START, fogstart)");=0A=
+        TRACE("Fog Start =3D=3D %f\n", fogstart);=0A=
 =0A=
-            glFogfv(GL_FOG_END, &fogend);=0A=
-            checkGLcall("glFogf(GL_FOG_END, fogend)");=0A=
-            TRACE("Fog End =3D=3D %f\n", fogend);=0A=
-        }=0A=
-        else=0A=
-        {=0A=
-            glFogf(GL_FOG_START, -1.0 / 0.0);=0A=
-            checkGLcall("glFogf(GL_FOG_START, fogstart)");=0A=
-            TRACE("Fog Start =3D=3D %f\n", fogstart);=0A=
+        glFogfv(GL_FOG_END, &fogend);=0A=
+        checkGLcall("glFogf(GL_FOG_END, fogend)");=0A=
+        TRACE("Fog End =3D=3D %f\n", fogend);=0A=
+    }=0A=
+    else=0A=
+    {=0A=
+        glFogf(GL_FOG_START, -1.0 / 0.0);=0A=
+        checkGLcall("glFogf(GL_FOG_START, fogstart)");=0A=
+        TRACE("Fog Start =3D=3D %f\n", fogstart);=0A=
 =0A=
-            glFogf(GL_FOG_END, 0.0);=0A=
-            checkGLcall("glFogf(GL_FOG_END, fogend)");=0A=
-            TRACE("Fog End =3D=3D %f\n", fogend);=0A=
-        }=0A=
-    } else {=0A=
-        glDisable(GL_FOG);=0A=
-        checkGLcall("glDisable GL_FOG");=0A=
+        glFogf(GL_FOG_END, 0.0);=0A=
+        checkGLcall("glFogf(GL_FOG_END, fogend)");=0A=
+        TRACE("Fog End =3D=3D %f\n", fogend);=0A=
     }=0A=
 }=0A=
 =0A=
-- =0A=
1.6.0.6=0A=
=0A=

------=_NextPart_000_0001_01C97342.A4962970--




More information about the wine-patches mailing list