From f757f3fb7d8a1cccecc496834d8d82516676792f Mon Sep 17 00:00:00 2001 From: Nozomi Kodama Date: Fri, 13 Jul 2012 02:53:18 +0200 Subject: [PATCH] d3dx9: Implementation of D3DXSHMultiply2. --- dlls/d3dx9_36/d3dx9_36.spec | 2 +- dlls/d3dx9_36/math.c | 17 +++++++++++++++++ dlls/d3dx9_36/tests/math.c | 23 +++++++++++++++++++++++ include/d3dx9math.h | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/dlls/d3dx9_36/d3dx9_36.spec b/dlls/d3dx9_36/d3dx9_36.spec index 58e863684de..9230d55be23 100644 --- a/dlls/d3dx9_36/d3dx9_36.spec +++ b/dlls/d3dx9_36/d3dx9_36.spec @@ -279,7 +279,7 @@ @ stub D3DXSHEvalDirectionalLight(long ptr long long long long ptr ptr ptr) @ stub D3DXSHEvalHemisphereLight(long ptr long long ptr ptr ptr) @ stub D3DXSHEvalSphericalLight(long ptr long long long long ptr ptr ptr) -@ stub D3DXSHMultiply2(ptr ptr ptr) +@ stdcall D3DXSHMultiply2(ptr ptr ptr) @ stdcall D3DXSHMultiply3(ptr ptr ptr) @ stub D3DXSHMultiply4(ptr ptr ptr) @ stub D3DXSHMultiply5(ptr ptr ptr) diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c index 24069291782..79a0bca6572 100644 --- a/dlls/d3dx9_36/math.c +++ b/dlls/d3dx9_36/math.c @@ -1995,6 +1995,23 @@ FLOAT WINAPI D3DXSHDot(UINT order, CONST FLOAT *a, CONST FLOAT *b) return s; } +FLOAT* WINAPI D3DXSHMultiply2(FLOAT *out, CONST FLOAT *a, CONST FLOAT *b) +{ + FLOAT ta, tb; + + TRACE("(%p, %p, %p)\n", out, a, b); + + ta = 0.28209479f * a[0]; + tb = 0.28209479f * b[0]; + + out[0]= 0.28209479f * D3DXSHDot(2, a, b); + out[1] = ta * b[1] + tb * a[1]; + out[2] = ta * b[2] + tb * a[2]; + out[3] = ta * b[3] + tb * a[3]; + + return out; +} + FLOAT* WINAPI D3DXSHMultiply3(FLOAT *out, CONST FLOAT *a, CONST FLOAT *b) { FLOAT t, ta, tb; diff --git a/dlls/d3dx9_36/tests/math.c b/dlls/d3dx9_36/tests/math.c index 018081cf3b8..66d4689fcf3 100644 --- a/dlls/d3dx9_36/tests/math.c +++ b/dlls/d3dx9_36/tests/math.c @@ -2422,6 +2422,28 @@ static void test_D3DXSHDot(void) return; } +static void test_D3DXSHMultiply2(void) +{ + unsigned int i; + FLOAT a[20], b[20], c[20]; + /* D3DXSHMultiply2 only modifies the first 4 elements of the array */ + const FLOAT expected[20] = + { 3.418594f, 1.698211f, 1.703853f, 1.709494f, 4.0f, 5.0f, + 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, + 14.0f, 15.0f, 16.0f, 17.0f, 18.0f, 19.0f }; + + for (i = 0; i < 20; i++) + { + a[i] = 1.0f + i / 100.0f; + b[i] = 3.0f - i / 100.0f; + c[i] = i; + } + + D3DXSHMultiply2(c, a, b); + for (i = 0; i < 20; i++) + ok(relative_error(c[i], expected[i]) < admitted_error, "Expected[%d] = %f, received = %f\n", i, expected[i], c[i]); +} + static void test_D3DXSHMultiply3(void) { unsigned int i; @@ -2490,6 +2512,7 @@ START_TEST(math) test_D3DXFloat_Array(); test_D3DXSHAdd(); test_D3DXSHDot(); + test_D3DXSHMultiply2(); test_D3DXSHMultiply3(); test_D3DXSHScale(); } diff --git a/include/d3dx9math.h b/include/d3dx9math.h index e31d432fa85..ab3e2b06e19 100644 --- a/include/d3dx9math.h +++ b/include/d3dx9math.h @@ -379,6 +379,7 @@ FLOAT *WINAPI D3DXFloat16To32Array(FLOAT *pout, CONST D3DXFLOAT16 *pin, UINT n); FLOAT* WINAPI D3DXSHAdd(FLOAT *out, UINT order, CONST FLOAT *a, CONST FLOAT *b); FLOAT WINAPI D3DXSHDot(UINT order, CONST FLOAT *a, CONST FLOAT *b); +FLOAT* WINAPI D3DXSHMultiply2(FLOAT *out, CONST FLOAT *a, CONST FLOAT *b); FLOAT* WINAPI D3DXSHMultiply3(FLOAT *out, CONST FLOAT *a, CONST FLOAT *b); FLOAT* WINAPI D3DXSHScale(FLOAT *out, UINT order, CONST FLOAT *a, CONST FLOAT scale);