WINED3D: Fix specular color handling for register combiners

H. Verbeet hverbeet at gmail.com
Tue Jul 11 17:44:15 CDT 2006


By default the FinalCombiner is setup to add the specular color to the
final result of the combiner operations. However, it should only do
this when the WINED3DRS_SPECULARENABLE renderstate is enabled. This
fixes a regression in HL2 where some objects had wrong specular
colors, while they shouldn't have specular colors at all.
-------------- next part --------------
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 45dd144..082f92b 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3842,6 +3842,26 @@ static HRESULT WINAPI IWineD3DDeviceImpl
                NOTE: If not supported don't give FIXMEs the impact is really minimal and very few people are
                   running 1.4 yet!
              */
+            /*
+             * If register combiners are enabled, enabling / disabling GL_COLOR_SUM has no effect.
+             * Instead, we need to setup the FinalCombiner properly.
+             *
+             * The default setup for the FinalCombiner is:
+             *
+             * <variable>       <input>                             <mapping>               <usage>
+             * GL_VARIABLE_A_NV GL_FOG,                             GL_UNSIGNED_IDENTITY_NV GL_ALPHA
+             * GL_VARIABLE_B_NV GL_SPARE0_PLUS_SECONDARY_COLOR_NV   GL_UNSIGNED_IDENTITY_NV GL_RGB
+             * GL_VARIABLE_C_NV GL_FOG                              GL_UNSIGNED_IDENTITY_NV GL_RGB
+             * GL_VARIABLE_D_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
+             * GL_VARIABLE_E_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
+             * GL_VARIABLE_F_NV GL_ZERO                             GL_UNSIGNED_IDENTITY_NV GL_RGB
+             * GL_VARIABLE_G_NV GL_SPARE0_NV                        GL_UNSIGNED_IDENTITY_NV GL_ALPHA
+             *
+             * That's pretty much fine as it is, except for variable B, which needs to take
+             * either GL_SPARE0_PLUS_SECONDARY_COLOR_NV or GL_SPARE0_NV, depending on
+             * whether WINED3DRS_SPECULARENABLE is enabled or not.
+             */
+
               if (Value) {
                 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (float*) &This->updateStateBlock->material.Specular);
                 checkGLcall("glMaterialfv");
@@ -3851,6 +3871,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl
                   TRACE("Specular colors cannot be enabled in this version of opengl\n");
                 }
                 checkGLcall("glEnable(GL_COLOR_SUM)");
+
+                if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
+                    GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_PLUS_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
+                    checkGLcall("glFinalCombinerInputNV()");
+                }
               } else {
                 float black[4] = {0.0f, 0.0f, 0.0f, 0.0f};
 
@@ -3865,6 +3890,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl
                   TRACE("Specular colors cannot be disabled in this version of opengl\n");
                 }
                 checkGLcall("glDisable(GL_COLOR_SUM)");
+
+                if (GL_SUPPORT(NV_REGISTER_COMBINERS)) {
+                    GL_EXTCALL(glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB));
+                    checkGLcall("glFinalCombinerInputNV()");
+                }
               }
         }
         break;
diff --git a/include/wine/wined3d_gl.h b/include/wine/wined3d_gl.h
index 038cbaf..c8d9402 100644
--- a/include/wine/wined3d_gl.h
+++ b/include/wine/wined3d_gl.h
@@ -1537,6 +1537,7 @@ #define GL_EXT_FUNCS_GEN \
     USE_GL_FUNC(PGLFNCOMBINERPARAMETERFVNVPROC,                 glCombinerParameterfvNV); \
     USE_GL_FUNC(PGLFNCOMBINERPARAMETERINVPROC,                  glCombinerParameteriNV); \
     USE_GL_FUNC(PGLFNCOMBINERPARAMETERIVNVPROC,                 glCombinerParameterivNV); \
+    USE_GL_FUNC(PGLFNFINALCOMBINERINPUTNVPROC,                  glFinalCombinerInputNV); \
 
 /* OpenGL 2.0 functions */
 #define GL2_FUNCS_GEN \





More information about the wine-patches mailing list