2 * Tests for the D3DX9 core interfaces
4 * Copyright 2009 Tony Wasserka
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
24 #include "d3dx9core.h"
26 static inline int get_ref(IUnknown *obj)
29 return IUnknown_Release(obj);
32 #define check_ref(obj, exp) _check_ref(__LINE__, obj, exp)
33 static inline void _check_ref(unsigned int line, IUnknown *obj, int exp)
35 int ref = get_ref(obj);
36 ok_(__FILE__, line)(exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
39 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
40 static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
42 int ref = IUnknown_Release(obj);
43 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
46 #define admitted_error 0.0001f
47 static inline void check_mat(D3DXMATRIX got, D3DXMATRIX exp)
52 if (fabs(U(exp).m[i][j]-U(got).m[i][j]) > admitted_error)
55 ok(equal, "Got matrix\n\t(%f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f)\n"
56 "Expected matrix=\n\t(%f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f)\n",
57 U(got).m[0][0],U(got).m[0][1],U(got).m[0][2],U(got).m[0][3],
58 U(got).m[1][0],U(got).m[1][1],U(got).m[1][2],U(got).m[1][3],
59 U(got).m[2][0],U(got).m[2][1],U(got).m[2][2],U(got).m[2][3],
60 U(got).m[3][0],U(got).m[3][1],U(got).m[3][2],U(got).m[3][3],
61 U(exp).m[0][0],U(exp).m[0][1],U(exp).m[0][2],U(exp).m[0][3],
62 U(exp).m[1][0],U(exp).m[1][1],U(exp).m[1][2],U(exp).m[1][3],
63 U(exp).m[2][0],U(exp).m[2][1],U(exp).m[2][2],U(exp).m[2][3],
64 U(exp).m[3][0],U(exp).m[3][1],U(exp).m[3][2],U(exp).m[3][3]);
67 static void test_ID3DXBuffer(void)
74 hr = D3DXCreateBuffer(10, NULL);
75 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
77 hr = D3DXCreateBuffer(0, &buffer);
78 ok(hr == D3D_OK, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3D_OK);
80 size = ID3DXBuffer_GetBufferSize(buffer);
81 ok(!size, "GetBufferSize failed, got %u, expected %u\n", size, 0);
83 count = ID3DXBuffer_Release(buffer);
84 ok(!count, "ID3DBuffer has %u references left\n", count);
86 hr = D3DXCreateBuffer(3, &buffer);
87 ok(hr == D3D_OK, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3D_OK);
89 size = ID3DXBuffer_GetBufferSize(buffer);
90 ok(size == 3, "GetBufferSize failed, got %u, expected %u\n", size, 3);
92 count = ID3DXBuffer_Release(buffer);
93 ok(!count, "ID3DBuffer has %u references left\n", count);
96 static void test_ID3DXSprite(IDirect3DDevice9 *device)
100 IDirect3DDevice9 *cmpdev;
101 IDirect3DTexture9 *tex1, *tex2;
102 D3DXMATRIX mat, cmpmat;
105 D3DXVECTOR3 pos, center;
108 IDirect3DDevice9_GetDirect3D(device, &d3d);
109 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
110 IDirect3D9_Release(d3d);
111 ok (hr == D3D_OK, "D3DFMT_A8R8G8B8 not supported\n");
112 if (FAILED(hr)) return;
114 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL);
115 ok (hr == D3D_OK, "Failed to create first texture (error code: %#x)\n", hr);
116 if (FAILED(hr)) return;
118 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
119 ok (hr == D3D_OK, "Failed to create second texture (error code: %#x)\n", hr);
121 IDirect3DTexture9_Release(tex1);
125 /* Test D3DXCreateSprite */
126 hr = D3DXCreateSprite(device, NULL);
127 ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
129 hr = D3DXCreateSprite(NULL, &sprite);
130 ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
132 hr = D3DXCreateSprite(device, &sprite);
133 ok (hr == D3D_OK, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3D_OK);
136 /* Test ID3DXSprite_GetDevice */
137 hr = ID3DXSprite_GetDevice(sprite, NULL);
138 ok (hr == D3DERR_INVALIDCALL, "GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
140 hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev == NULL */
141 ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
143 hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev != NULL */
144 ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
146 IDirect3DDevice9_Release(device);
147 IDirect3DDevice9_Release(device);
150 /* Test ID3DXSprite_GetTransform */
151 hr = ID3DXSprite_GetTransform(sprite, NULL);
152 ok (hr == D3DERR_INVALIDCALL, "GetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
153 hr = ID3DXSprite_GetTransform(sprite, &mat);
154 ok (hr == D3D_OK, "GetTransform returned %#x, expected %#x\n", hr, D3D_OK);
157 D3DXMatrixIdentity(&identity);
158 check_mat(mat, identity);
161 /* Test ID3DXSprite_SetTransform */
162 /* Set a transform and test if it gets returned correctly */
163 U(mat).m[0][0]=2.1f; U(mat).m[0][1]=6.5f; U(mat).m[0][2]=-9.6f; U(mat).m[0][3]=1.7f;
164 U(mat).m[1][0]=4.2f; U(mat).m[1][1]=-2.5f; U(mat).m[1][2]=2.1f; U(mat).m[1][3]=5.5f;
165 U(mat).m[2][0]=-2.6f; U(mat).m[2][1]=0.3f; U(mat).m[2][2]=8.6f; U(mat).m[2][3]=8.4f;
166 U(mat).m[3][0]=6.7f; U(mat).m[3][1]=-5.1f; U(mat).m[3][2]=6.1f; U(mat).m[3][3]=2.2f;
168 hr = ID3DXSprite_SetTransform(sprite, NULL);
169 ok (hr == D3DERR_INVALIDCALL, "SetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
171 hr = ID3DXSprite_SetTransform(sprite, &mat);
172 ok (hr == D3D_OK, "SetTransform returned %#x, expected %#x\n", hr, D3D_OK);
174 hr=ID3DXSprite_GetTransform(sprite, &cmpmat);
175 if(SUCCEEDED(hr)) check_mat(cmpmat, mat);
176 else skip("GetTransform returned %#x\n", hr);
179 /* Test ID3DXSprite_SetWorldViewLH/RH */
181 hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, &mat);
182 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
183 hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, &mat);
184 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
185 hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, NULL);
186 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
187 hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, NULL);
188 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
190 hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, &mat);
191 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
192 hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, &mat);
193 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
194 hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, NULL);
195 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
196 hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, NULL);
197 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
199 IDirect3DDevice9_BeginScene(device);
201 /* Test ID3DXSprite_Begin*/
202 hr = ID3DXSprite_Begin(sprite, 0);
203 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
205 IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &mat);
206 D3DXMatrixIdentity(&cmpmat);
207 check_mat(mat, cmpmat);
209 IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &mat);
210 check_mat(mat, cmpmat);
212 IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &mat);
213 IDirect3DDevice9_GetViewport(device, &vp);
214 D3DXMatrixOrthoOffCenterLH(&cmpmat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ);
215 check_mat(mat, cmpmat);
217 /* Test ID3DXSprite_Flush and ID3DXSprite_End */
218 hr = ID3DXSprite_Flush(sprite);
219 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
221 hr = ID3DXSprite_End(sprite);
222 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
224 hr = ID3DXSprite_Flush(sprite); /* May not be called before next Begin */
225 ok (hr == D3DERR_INVALIDCALL, "Flush returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
226 hr = ID3DXSprite_End(sprite);
227 ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
229 /* Test ID3DXSprite_Draw */
230 hr = ID3DXSprite_Begin(sprite, 0);
231 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
233 if(FAILED(hr)) skip("Couldn't ID3DXSprite_Begin, can't test ID3DXSprite_Draw\n");
234 else { /* Feed the sprite batch */
235 int texref1, texref2;
237 SetRect(&rect, 53, 12, 142, 165);
238 pos.x = 2.2f; pos.y = 4.5f; pos.z = 5.1f;
239 center.x = 11.3f; center.y = 3.4f; center.z = 1.2f;
241 texref1 = get_ref((IUnknown*)tex1);
242 texref2 = get_ref((IUnknown*)tex2);
244 hr = ID3DXSprite_Draw(sprite, NULL, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255));
245 ok (hr == D3DERR_INVALIDCALL, "Draw returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
247 hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255));
248 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
249 hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB( 3, 45, 66));
250 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
251 hr = ID3DXSprite_Draw(sprite, tex1, NULL, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255));
252 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
253 hr = ID3DXSprite_Draw(sprite, tex1, &rect, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255));
254 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
255 hr = ID3DXSprite_Draw(sprite, tex1, &rect, ¢er, NULL, D3DCOLOR_XRGB(255, 255, 255));
256 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
257 hr = ID3DXSprite_Draw(sprite, tex1, NULL, NULL, NULL, 0);
258 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
260 check_ref((IUnknown*)tex1, texref1+5); check_ref((IUnknown*)tex2, texref2+1);
261 hr = ID3DXSprite_Flush(sprite);
262 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
263 hr = ID3DXSprite_Flush(sprite); /* Flushing twice should work */
264 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
265 check_ref((IUnknown*)tex1, texref1); check_ref((IUnknown*)tex2, texref2);
267 hr = ID3DXSprite_End(sprite);
268 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
271 /* Test ID3DXSprite_OnLostDevice and ID3DXSprite_OnResetDevice */
272 /* Both can be called twice */
273 hr = ID3DXSprite_OnLostDevice(sprite);
274 ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK);
275 hr = ID3DXSprite_OnLostDevice(sprite);
276 ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK);
277 hr = ID3DXSprite_OnResetDevice(sprite);
278 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
279 hr = ID3DXSprite_OnResetDevice(sprite);
280 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
282 /* Make sure everything works like before */
283 hr = ID3DXSprite_Begin(sprite, 0);
284 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
285 hr = ID3DXSprite_Draw(sprite, tex2, &rect, ¢er, &pos, D3DCOLOR_XRGB(255, 255, 255));
286 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
287 hr = ID3DXSprite_Flush(sprite);
288 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
289 hr = ID3DXSprite_End(sprite);
290 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
292 /* OnResetDevice makes the interface "forget" the Begin call */
293 hr = ID3DXSprite_Begin(sprite, 0);
294 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
295 hr = ID3DXSprite_OnResetDevice(sprite);
296 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
297 hr = ID3DXSprite_End(sprite);
298 ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
300 IDirect3DDevice9_EndScene(device);
301 check_release((IUnknown*)sprite, 0);
302 check_release((IUnknown*)tex2, 0);
303 check_release((IUnknown*)tex1, 0);
306 static void test_ID3DXFont(IDirect3DDevice9 *device)
313 static const struct {
316 DWORD expected_levels;
317 } texture_tests[] = {
327 ref = get_ref((IUnknown*)device);
328 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
329 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
330 check_ref((IUnknown*)device, ref + 1);
331 check_release((IUnknown*)font, 0);
332 check_ref((IUnknown*)device, ref);
334 hr = D3DXCreateFontA(device, 0, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
335 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
336 ID3DXFont_Release(font);
338 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL, &font);
339 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
340 ID3DXFont_Release(font);
342 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "", &font);
343 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
344 ID3DXFont_Release(font);
346 hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
347 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
349 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", NULL);
350 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
352 hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", NULL);
353 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
356 /* D3DXCreateFontIndirect */
359 desc.Weight = FW_DONTCARE;
362 desc.CharSet = DEFAULT_CHARSET;
363 desc.OutputPrecision = OUT_DEFAULT_PRECIS;
364 desc.Quality = DEFAULT_QUALITY;
365 desc.PitchAndFamily = DEFAULT_PITCH;
366 strcpy(desc.FaceName, "Arial");
367 hr = D3DXCreateFontIndirectA(device, &desc, &font);
368 ok(hr == D3D_OK, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3D_OK);
369 ID3DXFont_Release(font);
371 hr = D3DXCreateFontIndirectA(NULL, &desc, &font);
372 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
374 hr = D3DXCreateFontIndirectA(device, NULL, &font);
375 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
377 hr = D3DXCreateFontIndirectA(device, &desc, NULL);
378 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
381 /* ID3DXFont_GetDevice */
382 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
384 IDirect3DDevice9 *bufdev;
386 hr = ID3DXFont_GetDevice(font, NULL);
387 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
389 ref = get_ref((IUnknown*)device);
390 hr = ID3DXFont_GetDevice(font, &bufdev);
391 ok(hr == D3D_OK, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
392 check_release((IUnknown*)bufdev, ref);
394 ID3DXFont_Release(font);
395 } else skip("Failed to create a ID3DXFont object\n");
398 /* ID3DXFont_GetDesc */
399 hr = D3DXCreateFontA(device, 12, 8, FW_BOLD, 2, TRUE, ANSI_CHARSET, OUT_RASTER_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, "Arial", &font);
401 hr = ID3DXFont_GetDescA(font, NULL);
402 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
404 hr = ID3DXFont_GetDescA(font, &desc);
405 ok(hr == D3D_OK, "ID3DXFont_GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
407 ok(desc.Height == 12, "ID3DXFont_GetDesc returned font height %d, expected %d\n", desc.Height, 12);
408 ok(desc.Width == 8, "ID3DXFont_GetDesc returned font width %d, expected %d\n", desc.Width, 8);
409 ok(desc.Weight == FW_BOLD, "ID3DXFont_GetDesc returned font weight %d, expected %d\n", desc.Weight, FW_BOLD);
410 ok(desc.MipLevels == 2, "ID3DXFont_GetDesc returned font miplevels %d, expected %d\n", desc.MipLevels, 2);
411 ok(desc.Italic == TRUE, "ID3DXFont_GetDesc says Italic was %d, but Italic should be %d\n", desc.Italic, TRUE);
412 ok(desc.CharSet == ANSI_CHARSET, "ID3DXFont_GetDesc returned font charset %d, expected %d\n", desc.CharSet, ANSI_CHARSET);
413 ok(desc.OutputPrecision == OUT_RASTER_PRECIS, "ID3DXFont_GetDesc returned an output precision of %d, expected %d\n", desc.OutputPrecision, OUT_RASTER_PRECIS);
414 ok(desc.Quality == ANTIALIASED_QUALITY, "ID3DXFont_GetDesc returned font quality %d, expected %d\n", desc.Quality, ANTIALIASED_QUALITY);
415 ok(desc.PitchAndFamily == VARIABLE_PITCH, "ID3DXFont_GetDesc returned pitch and family %d, expected %d\n", desc.PitchAndFamily, VARIABLE_PITCH);
416 ok(strcmp(desc.FaceName, "Arial") == 0, "ID3DXFont_GetDesc returned facename \"%s\", expected \"%s\"\n", desc.FaceName, "Arial");
418 ID3DXFont_Release(font);
419 } else skip("Failed to create a ID3DXFont object\n");
422 /* ID3DXFont_GetDC + ID3DXFont_GetTextMetrics */
423 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
427 hdc = ID3DXFont_GetDC(font);
428 ok(hdc != NULL, "ID3DXFont_GetDC returned an invalid handle\n");
430 TEXTMETRICA metrics, expmetrics;
433 ret = ID3DXFont_GetTextMetricsA(font, &metrics);
434 ok(ret, "ID3DXFont_GetTextMetricsA failed\n");
435 ret = GetTextMetricsA(hdc, &expmetrics);
436 ok(ret, "GetTextMetricsA failed\n");
438 ok(metrics.tmHeight == expmetrics.tmHeight, "Returned height %d, expected %d\n", metrics.tmHeight, expmetrics.tmHeight);
439 ok(metrics.tmAscent == expmetrics.tmAscent, "Returned ascent %d, expected %d\n", metrics.tmAscent, expmetrics.tmAscent);
440 ok(metrics.tmDescent == expmetrics.tmDescent, "Returned descent %d, expected %d\n", metrics.tmDescent, expmetrics.tmDescent);
441 ok(metrics.tmInternalLeading == expmetrics.tmInternalLeading, "Returned internal leading %d, expected %d\n", metrics.tmInternalLeading, expmetrics.tmInternalLeading);
442 ok(metrics.tmExternalLeading == expmetrics.tmExternalLeading, "Returned external leading %d, expected %d\n", metrics.tmExternalLeading, expmetrics.tmExternalLeading);
443 ok(metrics.tmAveCharWidth == expmetrics.tmAveCharWidth, "Returned average char width %d, expected %d\n", metrics.tmAveCharWidth, expmetrics.tmAveCharWidth);
444 ok(metrics.tmMaxCharWidth == expmetrics.tmMaxCharWidth, "Returned maximum char width %d, expected %d\n", metrics.tmMaxCharWidth, expmetrics.tmMaxCharWidth);
445 ok(metrics.tmWeight == expmetrics.tmWeight, "Returned weight %d, expected %d\n", metrics.tmWeight, expmetrics.tmWeight);
446 ok(metrics.tmOverhang == expmetrics.tmOverhang, "Returned overhang %d, expected %d\n", metrics.tmOverhang, expmetrics.tmOverhang);
447 ok(metrics.tmDigitizedAspectX == expmetrics.tmDigitizedAspectX, "Returned digitized x aspect %d, expected %d\n", metrics.tmDigitizedAspectX, expmetrics.tmDigitizedAspectX);
448 ok(metrics.tmDigitizedAspectY == expmetrics.tmDigitizedAspectY, "Returned digitized y aspect %d, expected %d\n", metrics.tmDigitizedAspectY, expmetrics.tmDigitizedAspectY);
449 ok(metrics.tmFirstChar == expmetrics.tmFirstChar, "Returned first char %d, expected %d\n", metrics.tmFirstChar, expmetrics.tmFirstChar);
450 ok(metrics.tmLastChar == expmetrics.tmLastChar, "Returned last char %d, expected %d\n", metrics.tmLastChar, expmetrics.tmLastChar);
451 ok(metrics.tmDefaultChar == expmetrics.tmDefaultChar, "Returned default char %d, expected %d\n", metrics.tmDefaultChar, expmetrics.tmDefaultChar);
452 ok(metrics.tmBreakChar == expmetrics.tmBreakChar, "Returned break char %d, expected %d\n", metrics.tmBreakChar, expmetrics.tmBreakChar);
453 ok(metrics.tmItalic == expmetrics.tmItalic, "Returned italic %d, expected %d\n", metrics.tmItalic, expmetrics.tmItalic);
454 ok(metrics.tmUnderlined == expmetrics.tmUnderlined, "Returned underlined %d, expected %d\n", metrics.tmUnderlined, expmetrics.tmUnderlined);
455 ok(metrics.tmStruckOut == expmetrics.tmStruckOut, "Returned struck out %d, expected %d\n", metrics.tmStruckOut, expmetrics.tmStruckOut);
456 ok(metrics.tmPitchAndFamily == expmetrics.tmPitchAndFamily, "Returned pitch and family %d, expected %d\n", metrics.tmPitchAndFamily, expmetrics.tmPitchAndFamily);
457 ok(metrics.tmCharSet == expmetrics.tmCharSet, "Returned charset %d, expected %d\n", metrics.tmCharSet, expmetrics.tmCharSet);
459 ID3DXFont_Release(font);
460 } else skip("Failed to create a ID3DXFont object\n");
463 /* ID3DXFont_PreloadText */
464 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
466 const WCHAR testW[] = {'t','e','s','t',0};
469 hr = ID3DXFont_PreloadTextA(font, NULL, -1);
470 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
471 hr = ID3DXFont_PreloadTextA(font, NULL, 0);
472 ok(hr == D3D_OK, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3D_OK);
473 hr = ID3DXFont_PreloadTextA(font, NULL, 1);
474 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
475 hr = ID3DXFont_PreloadTextA(font, "test", -1);
476 ok(hr == D3D_OK, "ID3DXFont_PreloadTextA returned %#x, expected %#x\n", hr, D3D_OK);
478 hr = ID3DXFont_PreloadTextW(font, NULL, -1);
479 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
480 hr = ID3DXFont_PreloadTextW(font, NULL, 0);
481 ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK);
482 hr = ID3DXFont_PreloadTextW(font, NULL, 1);
483 ok(hr == D3DERR_INVALIDCALL, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
484 hr = ID3DXFont_PreloadTextW(font, testW, -1);
485 ok(hr == D3D_OK, "ID3DXFont_PreloadTextW returned %#x, expected %#x\n", hr, D3D_OK);
488 check_release((IUnknown*)font, 0);
489 } else skip("Failed to create a ID3DXFont object\n");
492 /* ID3DXFont_GetGlyphData, ID3DXFont_PreloadGlyphs, ID3DXFont_PreloadCharacters */
493 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
501 IDirect3DTexture9 *texture;
503 hdc = ID3DXFont_GetDC(font);
506 hr = ID3DXFont_GetGlyphData(font, 0, NULL, &blackbox, &cellinc);
507 ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
508 hr = ID3DXFont_GetGlyphData(font, 0, &texture, NULL, &cellinc);
509 if(SUCCEEDED(hr)) check_release((IUnknown*)texture, 1);
510 ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
511 hr = ID3DXFont_GetGlyphData(font, 0, &texture, &blackbox, NULL);
512 if(SUCCEEDED(hr)) check_release((IUnknown*)texture, 1);
513 ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
515 hr = ID3DXFont_PreloadCharacters(font, 'b', 'a');
516 ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK);
517 hr = ID3DXFont_PreloadGlyphs(font, 1, 0);
518 ok(hr == D3D_OK, "ID3DXFont_PreloadGlyphs returned %#x, expected %#x\n", hr, D3D_OK);
520 hr = ID3DXFont_PreloadCharacters(font, 'a', 'a');
521 ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK);
524 for(c = 'b'; c <= 'z'; c++) {
527 ret = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0);
528 ok(ret != GDI_ERROR, "GetGlyphIndicesA failed\n");
530 hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc);
531 todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
534 D3DSURFACE_DESC desc;
536 levels = IDirect3DTexture9_GetLevelCount(texture);
537 ok(levels == 5, "Got levels %u, expected %u\n", levels, 5);
538 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
539 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc failed\n");
540 ok(desc.Format == D3DFMT_A8R8G8B8, "Got format %#x, expected %#x\n", desc.Format, D3DFMT_A8R8G8B8);
541 ok(desc.Usage == 0, "Got usage %#x, expected %#x\n", desc.Usage, 0);
542 ok(desc.Width == 256, "Got width %u, expected %u\n", desc.Width, 256);
543 ok(desc.Height == 256, "Got height %u, expected %u\n", desc.Height, 256);
544 ok(desc.Pool == D3DPOOL_MANAGED, "Got pool %u, expected %u\n", desc.Pool, D3DPOOL_MANAGED);
546 check_release((IUnknown*)texture, 1);
550 hr = ID3DXFont_PreloadCharacters(font, 'a', 'z');
551 todo_wine ok(hr == D3D_OK, "ID3DXFont_PreloadCharacters returned %#x, expected %#x\n", hr, D3D_OK);
553 check_release((IUnknown*)font, 0);
554 } else skip("Failed to create a ID3DXFont object\n");
556 for(i = 0; i < sizeof(texture_tests) / sizeof(texture_tests[0]); i++) {
562 IDirect3DTexture9 *texture;
564 hr = D3DXCreateFontA(device, texture_tests[i].font_height, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &font);
566 skip("Failed to create a ID3DXFont object\n");
570 hdc = ID3DXFont_GetDC(font);
572 ret = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0);
573 ok(ret != GDI_ERROR, "GetGlyphIndicesA failed\n");
575 hr = ID3DXFont_GetGlyphData(font, glyph, &texture, NULL, NULL);
576 todo_wine ok(hr == D3D_OK, "ID3DXFont_GetGlyphData returned %#x, expected %#x\n", hr, D3D_OK);
579 D3DSURFACE_DESC desc;
581 levels = IDirect3DTexture9_GetLevelCount(texture);
582 ok(levels == texture_tests[i].expected_levels, "Got levels %u, expected %u\n", levels, texture_tests[i].expected_levels);
583 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
584 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc failed\n");
585 ok(desc.Format == D3DFMT_A8R8G8B8, "Got format %#x, expected %#x\n", desc.Format, D3DFMT_A8R8G8B8);
586 ok(desc.Usage == 0, "Got usage %#x, expected %#x\n", desc.Usage, 0);
587 ok(desc.Width == texture_tests[i].expected_size, "Got width %u, expected %u\n", desc.Width, texture_tests[i].expected_size);
588 ok(desc.Height == texture_tests[i].expected_size, "Got height %u, expected %u\n", desc.Height, texture_tests[i].expected_size);
589 ok(desc.Pool == D3DPOOL_MANAGED, "Got pool %u, expected %u\n", desc.Pool, D3DPOOL_MANAGED);
591 IDirect3DTexture9_Release(texture);
593 ID3DXFont_Release(font);
597 static void test_D3DXCreateRenderToSurface(IDirect3DDevice9 *device)
603 ID3DXRenderToSurface *render = (void *)0xdeadbeef;
604 static const D3DXRTS_DESC tests[] =
606 { 0, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
607 { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
608 { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 },
609 { 256, 256, D3DFMT_UNKNOWN, FALSE, D3DFMT_R8G8B8 },
610 { 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN },
611 { -1, -1, MAKEFOURCC('B','A','D','F'), TRUE, MAKEFOURCC('B','A','D','F') }
614 hr = D3DXCreateRenderToSurface(NULL /* device */, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
615 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
616 ok(render == (void *)0xdeadbeef, "Got %p, expected %p\n", render, (void *)0xdeadbeef);
618 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, NULL /* out */);
619 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
621 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
623 hr = D3DXCreateRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil,
624 tests[i].DepthStencilFormat, &render);
625 ok(hr == D3D_OK, "%d: D3DXCreateRenderToSurface returned %#x, expected %#x\n", i, hr, D3D_OK);
628 hr = ID3DXRenderToSurface_GetDesc(render, &desc);
629 ok(hr == D3D_OK, "%d: GetDesc failed %#x\n", i, hr);
632 ok(desc.Width == tests[i].Width, "%d: Got width %u, expected %u\n", i, desc.Width, tests[i].Width);
633 ok(desc.Height == tests[i].Height, "%d: Got height %u, expected %u\n", i, desc.Height, tests[i].Height);
634 ok(desc.Format == tests[i].Format, "%d: Got format %#x, expected %#x\n", i, desc.Format, tests[i].Format);
635 ok(desc.DepthStencil == tests[i].DepthStencil, "%d: Got depth stencil %d, expected %d\n",
636 i, desc.DepthStencil, tests[i].DepthStencil);
637 ok(desc.DepthStencilFormat == tests[i].DepthStencilFormat, "%d: Got depth stencil format %#x, expected %#x\n",
638 i, desc.DepthStencilFormat, tests[i].DepthStencilFormat);
640 ID3DXRenderToSurface_Release(render);
644 /* check device ref count */
645 ref_count = get_ref((IUnknown *)device);
646 hr = D3DXCreateRenderToSurface(device, 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN, &render);
647 check_ref((IUnknown *)device, ref_count + 1);
648 if (SUCCEEDED(hr)) ID3DXRenderToSurface_Release(render);
651 /* runs a set of tests for the ID3DXRenderToSurface interface created with given parameters */
652 static void check_ID3DXRenderToSurface(IDirect3DDevice9 *device, UINT width, UINT height, D3DFORMAT format,
653 BOOL depth_stencil, D3DFORMAT depth_stencil_format, BOOL render_target)
657 HRESULT expected_value;
658 IDirect3DSurface9 *surface;
659 ID3DXRenderToSurface *render;
660 D3DVIEWPORT9 viewport = { 0, 0, width, height, 0.0, 1.0 };
662 hr = D3DXCreateRenderToSurface(device, width, height, format, depth_stencil, depth_stencil_format, &render);
665 skip("Failed to create ID3DXRenderToSurface\n");
670 hr = IDirect3DDevice9_CreateRenderTarget(device, width, height, format, D3DMULTISAMPLE_NONE, 0, FALSE, &surface, NULL);
672 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, D3DPOOL_DEFAULT, &surface, NULL);
675 skip("Failed to create surface\n");
676 ID3DXRenderToSurface_Release(render);
681 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
682 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
683 check_ref((IUnknown *)surface, 2);
684 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
686 /* invalid viewport */
687 viewport.Width = 2 * width;
688 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
689 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
691 viewport.X = width / 2;
692 viewport.Width = width;
693 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
694 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
697 viewport.Width = width;
698 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
699 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
701 /* rendering to a part of a surface is only allowed for render target surfaces */
702 expected_value = render_target ? D3D_OK : D3DERR_INVALIDCALL;
705 viewport.Width = width / 2;
706 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
707 ok(hr == expected_value, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_value);
708 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
710 viewport.X = width / 2;
711 viewport.Width = width - width / 2;
712 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
713 ok(hr == expected_value, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_value);
714 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
716 check_release((IUnknown *)surface, 0);
718 /* surfaces with different sizes */
719 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width / 2, width / 2, format, D3DPOOL_DEFAULT, &surface, NULL);
722 skip("Failed to create surface\n");
723 ID3DXRenderToSurface_Release(render);
726 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
727 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
728 check_release((IUnknown *)surface, 0);
730 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2 * width, 2 * height, format, D3DPOOL_DEFAULT, &surface, NULL);
733 skip("Failed to create surface\n");
734 ID3DXRenderToSurface_Release(render);
737 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
738 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
741 viewport.Width = width;
742 viewport.Height = height;
743 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
744 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
745 check_release((IUnknown *)surface, 0);
747 /* surfaces with different formats */
748 for (fmt = D3DFMT_A8R8G8B8; fmt <= D3DFMT_X8R8G8B8; fmt++)
750 HRESULT expected_result = (fmt != format) ? D3DERR_INVALIDCALL : D3D_OK;
752 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, fmt, D3DPOOL_DEFAULT, &surface, NULL);
755 skip("Failed to create surface\n");
759 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
760 ok(hr == expected_result, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_result);
762 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
763 check_release((IUnknown *)surface, 0);
766 check_release((IUnknown *)render, 0);
771 IDirect3DSurface9 *render_target;
772 IDirect3DSurface9 *depth_stencil;
773 D3DVIEWPORT9 viewport;
776 static void release_device_state(struct device_state *state)
778 if (state->render_target) IDirect3DSurface9_Release(state->render_target);
779 if (state->depth_stencil) IDirect3DSurface9_Release(state->depth_stencil);
780 memset(state, 0, sizeof(*state));
783 static HRESULT retrieve_device_state(IDirect3DDevice9 *device, struct device_state *state)
787 memset(state, 0, sizeof(*state));
789 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &state->render_target);
790 if (FAILED(hr)) goto cleanup;
792 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &state->depth_stencil);
793 if (hr == D3DERR_NOTFOUND)
794 state->depth_stencil = NULL;
798 hr = IDirect3DDevice9_GetViewport(device, &state->viewport);
799 if (SUCCEEDED(hr)) return hr;
802 release_device_state(state);
806 static HRESULT apply_device_state(IDirect3DDevice9 *device, struct device_state *state)
809 HRESULT status = D3D_OK;
811 hr = IDirect3DDevice9_SetRenderTarget(device, 0, state->render_target);
812 if (FAILED(hr)) status = hr;
814 hr = IDirect3DDevice9_SetDepthStencilSurface(device, state->depth_stencil);
815 if (FAILED(hr)) status = hr;
817 hr = IDirect3DDevice9_SetViewport(device, &state->viewport);
818 if (FAILED(hr)) status = hr;
823 static void compare_device_state(struct device_state *state1, struct device_state *state2, BOOL equal)
826 const char *message = equal ? "differs" : "is the same";
828 cmp = state1->render_target == state2->render_target;
829 ok(equal ? cmp : !cmp, "Render target %s %p, %p\n", message, state1->render_target, state2->render_target);
831 cmp = state1->depth_stencil == state2->depth_stencil;
832 ok(equal ? cmp : !cmp, "Depth stencil surface %s %p, %p\n", message, state1->depth_stencil, state2->depth_stencil);
834 cmp = state1->viewport.X == state2->viewport.X && state1->viewport.Y == state2->viewport.Y
835 && state1->viewport.Width == state2->viewport.Width && state1->viewport.Height == state2->viewport.Height;
836 ok(equal ? cmp : !cmp, "Viewport %s (%u, %u, %u, %u), (%u, %u, %u, %u)\n", message,
837 state1->viewport.X, state1->viewport.Y, state1->viewport.Width, state1->viewport.Height,
838 state2->viewport.X, state2->viewport.Y, state2->viewport.Width, state2->viewport.Height);
841 static void test_ID3DXRenderToSurface_device_state(IDirect3DDevice9 *device)
844 IDirect3DSurface9 *surface = NULL;
845 ID3DXRenderToSurface *render = NULL;
846 struct device_state pre_state;
847 struct device_state current_state;
848 IDirect3DSurface9 *depth_stencil_surface;
850 /* make sure there is a depth stencil surface present */
851 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &depth_stencil_surface);
854 IDirect3DSurface9_Release(depth_stencil_surface);
855 depth_stencil_surface = NULL;
857 else if (hr == D3DERR_NOTFOUND)
859 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24X8,
860 D3DMULTISAMPLE_NONE, 0, TRUE, &depth_stencil_surface, NULL);
861 if (SUCCEEDED(hr)) IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil_surface);
866 skip("Failed to create depth stencil surface\n");
870 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0,
871 FALSE, &surface, NULL);
874 skip("Failed to create render target\n");
878 hr = retrieve_device_state(device, &pre_state);
880 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8, &render);
881 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
884 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
885 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
887 hr = retrieve_device_state(device, ¤t_state);
888 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
889 compare_device_state(¤t_state, &pre_state, FALSE);
890 release_device_state(¤t_state);
892 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
893 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
895 hr = retrieve_device_state(device, ¤t_state);
896 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
897 compare_device_state(¤t_state, &pre_state, TRUE);
898 release_device_state(¤t_state);
900 check_release((IUnknown *)render, 0);
903 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
906 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
907 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
909 hr = retrieve_device_state(device, ¤t_state);
910 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
911 compare_device_state(¤t_state, &pre_state, FALSE);
912 release_device_state(¤t_state);
914 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
915 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
917 hr = retrieve_device_state(device, ¤t_state);
918 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
919 compare_device_state(¤t_state, &pre_state, TRUE);
920 release_device_state(¤t_state);
922 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
923 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
925 hr = retrieve_device_state(device, ¤t_state);
926 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
927 compare_device_state(¤t_state, &pre_state, FALSE);
928 release_device_state(¤t_state);
930 check_release((IUnknown *)render, 0);
932 /* if EndScene isn't called, the device state isn't restored */
933 hr = retrieve_device_state(device, ¤t_state);
934 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
935 compare_device_state(¤t_state, &pre_state, FALSE);
936 release_device_state(¤t_state);
938 hr = apply_device_state(device, &pre_state);
939 ok(SUCCEEDED(hr), "Failed to restore previous device state\n");
941 IDirect3DDevice9_EndScene(device);
944 release_device_state(&pre_state);
947 if (depth_stencil_surface)
949 IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
950 IDirect3DSurface9_Release(depth_stencil_surface);
953 if (surface) check_release((IUnknown *)surface, 0);
956 static void test_ID3DXRenderToSurface(IDirect3DDevice9 *device)
961 IDirect3DDevice9 *out_device;
962 ID3DXRenderToSurface *render;
963 IDirect3DSurface9 *surface;
964 D3DVIEWPORT9 viewport = { 0, 0, 256, 256, 0.0, 1.0 };
965 D3DXRTS_DESC tests[] = {
966 { 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
967 { 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24S8 },
968 { 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8 },
969 { 512, 512, D3DFMT_X8R8G8B8, FALSE, D3DFMT_X8R8G8B8 },
970 { 1024, 1024, D3DFMT_X8R8G8B8, TRUE, D3DFMT_D24S8 }
973 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
974 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
975 if (FAILED(hr)) return;
977 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
980 ID3DXRenderToSurface *render_surface;
983 hr = ID3DXRenderToSurface_GetDevice(render, NULL /* device */);
984 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
986 ref_count = get_ref((IUnknown *)device);
987 hr = ID3DXRenderToSurface_GetDevice(render, &out_device);
988 ok(hr == D3D_OK, "ID3DXRenderToSurface::GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
989 check_release((IUnknown *)out_device, ref_count);
991 /* BeginScene and EndScene */
992 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
993 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
995 hr = ID3DXRenderToSurface_BeginScene(render, NULL /* surface */, &viewport);
996 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
998 ref_count = get_ref((IUnknown *)surface);
999 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1000 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1003 check_ref((IUnknown *)surface, ref_count + 1);
1005 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1006 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1008 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1009 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
1011 check_ref((IUnknown *)surface, ref_count);
1014 /* error handling is deferred to BeginScene */
1015 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_UNKNOWN, &render_surface);
1016 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
1017 hr = ID3DXRenderToSurface_BeginScene(render_surface, surface, NULL);
1018 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1019 check_release((IUnknown *)render_surface, 0);
1021 check_release((IUnknown *)surface, 0);
1023 else skip("Failed to create surface\n");
1025 check_release((IUnknown *)render, 0);
1027 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
1029 check_ID3DXRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil, tests[i].DepthStencilFormat, TRUE);
1030 check_ID3DXRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil, tests[i].DepthStencilFormat, FALSE);
1033 test_ID3DXRenderToSurface_device_state(device);
1036 static void test_D3DXCreateRenderToEnvMap(IDirect3DDevice9 *device)
1042 ID3DXRenderToEnvMap *render;
1043 static const struct {
1044 D3DXRTE_DESC parameters;
1045 D3DXRTE_DESC expected_values;
1047 { { 0, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN }, { 1, 1, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN } },
1048 { { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN }, { 256, 9, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN } },
1049 { { 256, 4, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 }, { 256, 4, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 } },
1050 { { 256, 256, D3DFMT_UNKNOWN, FALSE, D3DFMT_R8G8B8 }, { 256, 9, D3DFMT_A8R8G8B8, FALSE, D3DFMT_R8G8B8 } },
1051 { { -1, -1, D3DFMT_A8R8G8B8, TRUE, D3DFMT_DXT1 }, { 256, 9, D3DFMT_A8R8G8B8, TRUE, D3DFMT_DXT1 } },
1052 { { 256, 1, D3DFMT_X8R8G8B8, TRUE, D3DFMT_UNKNOWN }, { 256, 1, D3DFMT_X8R8G8B8, TRUE, D3DFMT_UNKNOWN } }
1055 for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
1057 const D3DXRTE_DESC *parameters = &tests[i].parameters;
1058 const D3DXRTE_DESC *expected = &tests[i].expected_values;
1059 hr = D3DXCreateRenderToEnvMap(device, parameters->Size, parameters->MipLevels, parameters->Format,
1060 parameters->DepthStencil, parameters->DepthStencilFormat, &render);
1061 ok(hr == D3D_OK, "%d: D3DXCreateRenderToEnvMap returned %#x, expected %#x\n", i, hr, D3D_OK);
1064 hr = ID3DXRenderToEnvMap_GetDesc(render, &desc);
1065 ok(hr == D3D_OK, "%d: GetDesc failed %#x\n", i, hr);
1068 ok(desc.Size == expected->Size, "%d: Got size %u, expected %u\n", i, desc.Size, expected->Size);
1069 ok(desc.MipLevels == expected->MipLevels, "%d: Got miplevels %u, expected %u\n", i, desc.MipLevels, expected->MipLevels);
1070 ok(desc.Format == expected->Format, "%d: Got format %#x, expected %#x\n", i, desc.Format, expected->Format);
1071 ok(desc.DepthStencil == expected->DepthStencil, "%d: Got depth stencil %d, expected %d\n",
1072 i, expected->DepthStencil, expected->DepthStencil);
1073 ok(desc.DepthStencilFormat == expected->DepthStencilFormat, "%d: Got depth stencil format %#x, expected %#x\n",
1074 i, expected->DepthStencilFormat, expected->DepthStencilFormat);
1076 check_release((IUnknown *)render, 0);
1080 /* check device ref count */
1081 ref_count = get_ref((IUnknown *)device);
1082 hr = D3DXCreateRenderToEnvMap(device, 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN, &render);
1083 check_ref((IUnknown *)device, ref_count + 1);
1084 if (SUCCEEDED(hr)) ID3DXRenderToEnvMap_Release(render);
1087 static void test_ID3DXRenderToEnvMap_cube_map(IDirect3DDevice9 *device)
1090 IDirect3DCubeTexture9 *cube_texture = NULL;
1091 ID3DXRenderToEnvMap *render = NULL;
1092 struct device_state pre_state;
1093 struct device_state current_state;
1095 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
1096 &cube_texture, NULL);
1099 skip("Failed to create cube texture\n");
1103 hr = retrieve_device_state(device, &pre_state);
1105 hr = D3DXCreateRenderToEnvMap(device, 256, 0, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8, &render);
1106 ok(hr == D3D_OK, "D3DCreateRenderToEnvMap returned %#x, expected %#x\n", hr, D3D_OK);
1111 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_NONE);
1112 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1114 hr = ID3DXRenderToEnvMap_BeginCube(render, cube_texture);
1115 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::BeginCube returned %#x, expected %#x\n", hr, D3D_OK);
1117 hr = retrieve_device_state(device, ¤t_state);
1118 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1119 compare_device_state(¤t_state, &pre_state, TRUE);
1120 release_device_state(¤t_state);
1122 for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; face++)
1124 hr = ID3DXRenderToEnvMap_Face(render, face, D3DX_FILTER_POINT);
1125 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::Face returned %#x, expected %#x\n", hr, D3D_OK);
1127 hr = retrieve_device_state(device, ¤t_state);
1128 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1129 compare_device_state(¤t_state, &pre_state, FALSE);
1130 release_device_state(¤t_state);
1133 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_POINT);
1134 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3D_OK);
1136 hr = retrieve_device_state(device, ¤t_state);
1137 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1138 compare_device_state(¤t_state, &pre_state, TRUE);
1139 release_device_state(¤t_state);
1141 check_release((IUnknown *)render, 0);
1144 release_device_state(&pre_state);
1146 check_release((IUnknown *)cube_texture, 0);
1149 static void test_ID3DXRenderToEnvMap(IDirect3DDevice9 *device)
1152 ID3DXRenderToEnvMap *render;
1153 IDirect3DSurface9 *depth_stencil_surface;
1155 hr = D3DXCreateRenderToEnvMap(device, 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
1159 IDirect3DDevice9 *out_device;
1161 hr = ID3DXRenderToEnvMap_GetDesc(render, NULL);
1162 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::GetDesc returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1164 hr = ID3DXRenderToEnvMap_GetDevice(render, NULL);
1165 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1167 ref_count = get_ref((IUnknown *)device);
1168 hr = ID3DXRenderToEnvMap_GetDevice(render, &out_device);
1169 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
1170 ok(out_device == device, "ID3DXRenderToEnvMap::GetDevice returned different device\n");
1171 check_release((IUnknown *)device, ref_count);
1173 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_NONE);
1174 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3D_OK);
1176 hr = ID3DXRenderToEnvMap_BeginCube(render, NULL);
1177 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginCube returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1179 hr = ID3DXRenderToEnvMap_BeginHemisphere(render, NULL, NULL);
1180 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginHemisphere returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1182 hr = ID3DXRenderToEnvMap_BeginParabolic(render, NULL, NULL);
1183 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginParabolic returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1185 hr = ID3DXRenderToEnvMap_BeginSphere(render, NULL);
1186 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginSphere returned %#x, exected %#x\n", hr, D3DERR_INVALIDCALL);
1188 check_release((IUnknown *)render, 0);
1189 } else skip("Failed to create ID3DXRenderToEnvMap\n");
1191 /* make sure there is a depth stencil surface present */
1192 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &depth_stencil_surface);
1195 IDirect3DSurface9_Release(depth_stencil_surface);
1196 depth_stencil_surface = NULL;
1198 else if (hr == D3DERR_NOTFOUND)
1200 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24X8,
1201 D3DMULTISAMPLE_NONE, 0, TRUE, &depth_stencil_surface, NULL);
1202 if (SUCCEEDED(hr)) IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil_surface);
1207 skip("Failed to create depth stencil surface\n");
1211 test_ID3DXRenderToEnvMap_cube_map(device);
1213 if (depth_stencil_surface)
1215 IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
1216 IDirect3DSurface9_Release(depth_stencil_surface);
1224 IDirect3DDevice9 *device;
1225 D3DPRESENT_PARAMETERS d3dpp;
1228 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1229 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1231 skip("Couldn't create application window\n");
1235 skip("Couldn't create IDirect3D9 object\n");
1240 ZeroMemory(&d3dpp, sizeof(d3dpp));
1241 d3dpp.Windowed = TRUE;
1242 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1243 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1245 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1246 IDirect3D9_Release(d3d);
1252 test_ID3DXSprite(device);
1253 test_ID3DXFont(device);
1254 test_D3DXCreateRenderToSurface(device);
1255 test_ID3DXRenderToSurface(device);
1256 test_D3DXCreateRenderToEnvMap(device);
1257 test_ID3DXRenderToEnvMap(device);
1259 check_release((IUnknown*)device, 0);
1260 check_release((IUnknown*)d3d, 0);
1261 if (wnd) DestroyWindow(wnd);