From 3e5899b38dee014756e55d9bb7c35257bae7611e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20D=C3=B6singer?= Date: Mon, 7 Apr 2008 14:36:53 +0200 Subject: [PATCH] d3d9: Some Windows drivers set undefined attributes to 0.0. --- dlls/d3d9/tests/visual.c | 15 +++++++++------ dlls/wined3d/state.c | 8 ++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/dlls/d3d9/tests/visual.c b/dlls/d3d9/tests/visual.c index 969f79bbb0e..e8866c0cc8a 100644 --- a/dlls/d3d9/tests/visual.c +++ b/dlls/d3d9/tests/visual.c @@ -6078,11 +6078,13 @@ void test_vshader_input(IDirect3DDevice9 *device) ok(color == 0x00FFFF80 || color == 0x00FFFF7f || color == 0x00FFFF81, "Input test: Quad 1(2crd) returned color 0x%08x, expected 0x00FFFF80\n", color); - /* The last value of the read but undefined stream is used */ + /* The last value of the read but undefined stream is used, it is 0x00. The defined input is vec4(1, 0, 0, 0) */ color = getPixelColor(device, 480, 360); - ok(color == 0x00FFFF00, "Input test: Quad 2(1crd) returned color 0x%08x, expected 0x00FFFF00\n", color); + ok(color == 0x00FFFF00 || color ==0x00FF0000, + "Input test: Quad 2(1crd) returned color 0x%08x, expected 0x00FFFF00\n", color); color = getPixelColor(device, 160, 120); - ok(color == 0x00FF0080 || color == 0x00FF007f || color == 0x00FF0081, + /* Same as above, accept both the last used value and 0.0 for the undefined streams */ + ok(color == 0x00FF0080 || color == 0x00FF007f || color == 0x00FF0081 || color == 0x00FF0000, "Input test: Quad 3(2crd-wrongidx) returned color 0x%08x, expected 0x00FF0080\n", color); color = getPixelColor(device, 480, 160); @@ -6149,7 +6151,8 @@ void test_vshader_input(IDirect3DDevice9 *device) ok(hr == D3D_OK, "IDirect3DDevice9_Present failed with %s\n", DXGetErrorString9(hr)); color = getPixelColor(device, 480, 350); - /* vs_1_1 may fail, accept the clear color + /* vs_1_1 may fail, accept the clear color. Some drivers also set the undefined streams to 0, accept that + * as well. * * NOTE: This test fails on the reference rasterizer. In the refrast, the 4 vertices have different colors, * i.e., the whole old stream is read, and not just the last used attribute. Some games require that this @@ -6158,8 +6161,8 @@ void test_vshader_input(IDirect3DDevice9 *device) * * A test app for this behavior is Half Life 2 Episode 2 in dxlevel 95, and related games(Portal, TF2). */ - ok(color == 0x000000FF || color == 0x00808080, - "Input test: Quad 2(different colors) returned color 0x%08x, expected 0x000000FF\n", color); + ok(color == 0x000000FF || color == 0x00808080 || color == 0x00000000, + "Input test: Quad 2(different colors) returned color 0x%08x, expected 0x000000FF, 0x00808080 or 0x00000000\n", color); color = getPixelColor(device, 160, 120); IDirect3DDevice9_SetVertexShader(device, NULL); diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 7ec40511ef7..55d37a77b19 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -3017,6 +3017,14 @@ static inline void unloadNumberedArrays(IWineD3DStateBlockImpl *stateblock) { for (i = 0; i < maxAttribs; ++i) { GL_EXTCALL(glDisableVertexAttribArrayARB(i)); checkGLcall("glDisableVertexAttribArrayARB(reg)"); + /* Some Windows drivers(NV GF 7) use the latest value that was used when drawing with the now + * deactivated stream disabled, some other drivers(ATI, NV GF 8) set the undefined values to 0x00. + * Let's set them to 0x00 to avoid hitting some undefined aspects of OpenGL. All that is really + * important here is the glDisableVertexAttribArrayARB call above. The test shows that the refrast + * keeps dereferencing the pointers, which would cause crashes in some games like Half Life 2 Eposide 2 + */ + GL_EXTCALL(glVertexAttrib4NubARB(i, 0, 0, 0, 0)); + checkGLcall("glVertexAttrib4NubARB(i, 0, 0, 0, 0)"); } }