2 * Copyright 2010 Christian Costa
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "wine/test.h"
22 #define admitted_error 0.0001f
24 #define relative_error(exp, out) ((exp == 0.0f) ? fabs(exp - out) : (fabs(1.0f - out/ exp) ))
26 static inline BOOL compare_matrix(const D3DXMATRIX *m1, const D3DXMATRIX *m2)
30 for (i = 0; i < 4; ++i)
32 for (j = 0; j < 4; ++j)
34 if (relative_error(U(*m1).m[i][j], U(*m2).m[i][j]) > admitted_error)
42 #define expect_mat(expectedmat, gotmat) \
44 const D3DXMATRIX *__m1 = (expectedmat); \
45 const D3DXMATRIX *__m2 = (gotmat); \
46 ok(compare_matrix(__m1, __m2), "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n" \
47 "Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n", \
48 U(*__m1).m[0][0], U(*__m1).m[0][1], U(*__m1).m[0][2], U(*__m1).m[0][3], \
49 U(*__m1).m[1][0], U(*__m1).m[1][1], U(*__m1).m[1][2], U(*__m1).m[1][3], \
50 U(*__m1).m[2][0], U(*__m1).m[2][1], U(*__m1).m[2][2], U(*__m1).m[2][3], \
51 U(*__m1).m[3][0], U(*__m1).m[3][1], U(*__m1).m[3][2], U(*__m1).m[3][3], \
52 U(*__m2).m[0][0], U(*__m2).m[0][1], U(*__m2).m[0][2], U(*__m2).m[0][3], \
53 U(*__m2).m[1][0], U(*__m2).m[1][1], U(*__m2).m[1][2], U(*__m2).m[1][3], \
54 U(*__m2).m[2][0], U(*__m2).m[2][1], U(*__m2).m[2][2], U(*__m2).m[2][3], \
55 U(*__m2).m[3][0], U(*__m2).m[3][1], U(*__m2).m[3][2], U(*__m2).m[3][3]); \
58 static void test_create_line(IDirect3DDevice9* device)
61 LPD3DXLINE line = NULL;
62 LPDIRECT3DDEVICE9 return_device;
63 D3DXMATRIX world, identity, result;
64 FLOAT r11, r12, r13, r14;
67 /* Arbitrary values for matrix tests. */
68 r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587;
70 hr = D3DXCreateLine(NULL, &line);
71 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
73 hr = D3DXCreateLine(device, NULL);
74 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
76 hr = D3DXCreateLine(device, &line);
77 ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr);
84 hr = ID3DXLine_GetDevice(line, NULL);
85 ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL);
87 hr = ID3DXLine_GetDevice(line, &return_device);
88 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
89 ok(return_device == device, "Expected line device %p, got %p\n", device, return_device);
91 D3DXMatrixIdentity(&world);
92 D3DXMatrixIdentity(&identity);
93 S(U(world))._11 = r11; S(U(world))._12 = r12; S(U(world))._13 = r13; S(U(world))._14 = r14;
95 hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world);
96 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
98 hr = ID3DXLine_Begin(line);
99 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
101 hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
102 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
103 expect_mat(&identity, &result);
105 hr = ID3DXLine_End(line);
106 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
108 hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result);
109 ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK);
110 expect_mat(&world, &result);
112 ref = IDirect3DDevice9_Release(return_device);
113 ok(ref == 2, "Got %x references to device %p, expected 2\n", ref, return_device);
115 ref = ID3DXLine_Release(line);
116 ok(ref == 0, "Got %x references to line %p, expected 0\n", ref, line);
123 IDirect3DDevice9* device;
124 D3DPRESENT_PARAMETERS d3dpp;
127 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
128 d3d = Direct3DCreate9(D3D_SDK_VERSION);
130 skip("Couldn't create application window\n");
134 skip("Couldn't create IDirect3D9 object\n");
139 ZeroMemory(&d3dpp, sizeof(d3dpp));
140 d3dpp.Windowed = TRUE;
141 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
142 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
144 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
145 IDirect3D9_Release(d3d);
150 test_create_line(device);
152 IDirect3DDevice9_Release(device);
153 IDirect3D9_Release(d3d);