Commit bbf313e7 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

d3d9: Test for fixed function value clamping.

parent bab367e1
......@@ -9298,6 +9298,116 @@ static void yuv_color_test(IDirect3DDevice9 *device) {
IDirect3D9_Release(d3d);
}
static void texop_range_test(IDirect3DDevice9 *device)
{
static const struct {
float x, y, z;
D3DCOLOR diffuse;
} quad[] = {
{-1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
{-1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
{ 1.0f, -1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)},
{ 1.0f, 1.0f, 0.1f, D3DCOLOR_ARGB(0xff, 0xff, 0xff, 0xff)}
};
HRESULT hr;
IDirect3DTexture9 *texture;
D3DLOCKED_RECT locked_rect;
D3DCAPS9 caps;
DWORD color;
/* We need ADD and SUBTRACT operations */
hr = IDirect3DDevice9_GetDeviceCaps(device, &caps);
ok(SUCCEEDED(hr), "GetDeviceCaps failed with 0x%08x\n", hr);
if (!(caps.TextureOpCaps & D3DTEXOPCAPS_ADD)) {
skip("D3DTOP_ADD is not supported, skipping value range test\n");
}
if (!(caps.TextureOpCaps & D3DTEXOPCAPS_SUBTRACT)) {
skip("D3DTEXOPCAPS_SUBTRACT is not supported, skipping value range test\n");
}
hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE);
ok(SUCCEEDED(hr), "SetFVF failed with 0x%08x\n", hr);
/* Stage 1: result = diffuse(=1.0) + diffuse
* stage 2: result = result - tfactor(= 0.5)
*/
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_ADD);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_TFACTOR);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
color = getPixelColor(device, 320, 240);
ok(color_match(color, 0x00808080, 1), "texop Range > 1.0 returned 0x%08x, expected 0x00808080\n",
color);
hr = IDirect3DDevice9_CreateTexture(device, 1, 1, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
ok(SUCCEEDED(hr), "IDirect3DDevice9_CreateTexture failed with 0x%08x\n", hr);
hr = IDirect3DTexture9_LockRect(texture, 0, &locked_rect, NULL, 0);
ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
*((DWORD *)locked_rect.pBits) = D3DCOLOR_ARGB(0x00, 0x00, 0x00, 0x00);
hr = IDirect3DTexture9_UnlockRect(texture, 0);
ok(SUCCEEDED(hr), "LockRect failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTexture(device, 0, (IDirect3DBaseTexture9 *)texture);
ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
/* Stage 1: result = texture(=0.0) - tfactor(= 0.5)
* stage 2: result = result + diffuse(1.0)
*/
hr = IDirect3DDevice9_SetRenderState(device, D3DRS_TEXTUREFACTOR, 0x80808080);
ok(SUCCEEDED(hr), "SetRenderState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_SUBTRACT);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG1, D3DTA_CURRENT);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_ADD);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_BeginScene(device);
ok(SUCCEEDED(hr), "BeginScene failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad));
ok(SUCCEEDED(hr), "DrawPrimitiveUP failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_EndScene(device);
ok(SUCCEEDED(hr), "EndScene failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
ok(SUCCEEDED(hr), "Present failed with 0x%08x\n", hr);
color = getPixelColor(device, 320, 240);
ok(color_match(color, 0x00ffffff, 1), "texop Range < 0.0 returned 0x%08x, expected 0x00ffffff\n",
color);
hr = IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP, D3DTOP_DISABLE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP, D3DTOP_DISABLE);
ok(SUCCEEDED(hr), "SetTextureStageState failed with 0x%08x\n", hr);
hr = IDirect3DDevice9_SetTexture(device, 1, (IDirect3DBaseTexture9 *)NULL);
ok(SUCCEEDED(hr), "SetTexture failed with 0x%08x\n", hr);
IDirect3DTexture9_Release(texture);
}
START_TEST(visual)
{
IDirect3DDevice9 *device_ptr;
......@@ -9455,6 +9565,7 @@ START_TEST(visual)
}
else skip("No ps_1_1 support\n");
texop_test(device_ptr);
texop_range_test(device_ptr);
cleanup:
if(device_ptr) {
......
......@@ -2561,9 +2561,9 @@ static void gen_ffp_instr(SHADER_BUFFER *buffer, unsigned int stage, BOOL color,
}
if(mul == 2) {
shader_addline(buffer, "MUL %s%s, %s, const.y;\n", mul_final_dest ? "result.color" : dstreg, dstmask, dstreg);
shader_addline(buffer, "MUL_SAT %s%s, %s, const.y;\n", mul_final_dest ? "result.color" : dstreg, dstmask, dstreg);
} else if(mul == 4) {
shader_addline(buffer, "MUL %s%s, %s, const.z;\n", mul_final_dest ? "result.color" : dstreg, dstmask, dstreg);
shader_addline(buffer, "MUL_SAT %s%s, %s, const.z;\n", mul_final_dest ? "result.color" : dstreg, dstmask, dstreg);
}
}
......
......@@ -105,8 +105,8 @@ static GLenum d3dta_to_combiner_input(DWORD d3dta, DWORD stage, INT texture_idx)
}
static GLenum invert_mapping(GLenum mapping) {
if (mapping == GL_UNSIGNED_INVERT_NV) return GL_SIGNED_IDENTITY_NV;
else if (mapping == GL_SIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
if (mapping == GL_UNSIGNED_INVERT_NV) return GL_UNSIGNED_IDENTITY_NV;
else if (mapping == GL_UNSIGNED_IDENTITY_NV) return GL_UNSIGNED_INVERT_NV;
FIXME("Unhandled mapping %#x\n", mapping);
return mapping;
......@@ -116,7 +116,7 @@ static void get_src_and_opr_nvrc(DWORD stage, DWORD arg, BOOL is_alpha, GLenum*
/* The WINED3DTA_COMPLEMENT flag specifies the complement of the input should
* be used. */
if (arg & WINED3DTA_COMPLEMENT) *mapping = GL_UNSIGNED_INVERT_NV;
else *mapping = GL_SIGNED_IDENTITY_NV;
else *mapping = GL_UNSIGNED_IDENTITY_NV; /* Clamp all values to positive ranges */
/* The WINED3DTA_ALPHAREPLICATE flag specifies the alpha component of the input
* should be used for all input components. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment