wer: Add new stubbed wer.dll.
[wine/hramrach.git] / dlls / d3dx9_36 / tests / texture.c
blob9a3b3bcace558374ad01fb71dc7a207947972627
1 /*
2 * Tests for the D3DX9 texture functions
4 * Copyright 2009 Tony Wasserka
5 * Copyright 2010 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define COBJMACROS
23 #include "wine/test.h"
24 #include "d3dx9tex.h"
26 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
28 UINT width, height, mipmaps;
29 D3DFORMAT format;
30 D3DCAPS9 caps;
31 HRESULT hr;
33 IDirect3DDevice9_GetDeviceCaps(device, &caps);
35 /* general tests */
36 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
37 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
39 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
40 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
42 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
43 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
45 /* width & height */
46 width = height = D3DX_DEFAULT;
47 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
48 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
49 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
50 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
52 width = D3DX_DEFAULT;
53 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
54 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
55 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
57 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
58 skip("Hardware only supports pow2 textures\n");
59 else
61 width = 62;
62 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
63 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
64 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
66 width = D3DX_DEFAULT; height = 63;
67 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
68 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
69 ok(width == height, "Returned width %d, expected %d\n", width, height);
70 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
73 width = D3DX_DEFAULT; height = 0;
74 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
75 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
76 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
77 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
79 width = 0; height = 0;
80 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
81 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
82 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
83 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
85 width = 0;
86 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
87 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
88 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
90 width = D3DX_DEFAULT;
91 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
92 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
93 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
95 width = 0xFFFFFFFE;
96 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
97 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
98 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
100 width = caps.MaxTextureWidth-1;
101 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
102 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
103 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
105 /* mipmaps */
106 width = 64; height = 63;
107 mipmaps = 9;
108 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
109 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
110 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
112 width = 284; height = 137;
113 mipmaps = 20;
114 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
115 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
116 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
118 width = height = 63;
119 mipmaps = 9;
120 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
121 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
122 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
124 mipmaps = 20;
125 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
126 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
129 mipmaps = 0;
130 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
131 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
132 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
134 /* usage */
135 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
136 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
137 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
138 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
139 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
140 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
141 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
142 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
143 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
144 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
146 /* format */
147 format = D3DFMT_UNKNOWN;
148 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
149 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
150 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
152 format = 0;
153 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
154 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
155 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
158 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
160 IDirect3DTexture9 *texture;
161 D3DSURFACE_DESC desc;
162 D3DCAPS9 caps;
163 UINT mipmaps;
164 HRESULT hr;
166 IDirect3DDevice9_GetDeviceCaps(device, &caps);
168 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
169 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
171 /* width and height tests */
173 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
174 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
176 if (texture)
178 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
180 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
181 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
183 IDirect3DTexture9_Release(texture);
187 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
188 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
190 if (texture)
192 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
194 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
195 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
197 IDirect3DTexture9_Release(texture);
201 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
202 skip("Hardware only supports pow2 textures\n");
203 else
205 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
206 ok((hr == D3D_OK) ||
207 /* may not work with conditional NPOT */
208 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
209 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
211 if (texture)
213 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
215 /* Conditional NPOT may create a texture with different dimensions, so allow those
216 situations instead of returning a fail */
218 ok(desc.Width == 63 ||
219 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
220 "Returned width %d, expected %d\n", desc.Width, 63);
222 ok(desc.Height == 63 ||
223 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
224 "Returned height %d, expected %d\n", desc.Height, 63);
226 IDirect3DTexture9_Release(texture);
230 /* mipmaps */
232 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
233 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
235 if (texture)
237 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
238 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
240 IDirect3DTexture9_Release(texture);
244 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
245 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
247 if (texture)
249 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
250 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
252 IDirect3DTexture9_Release(texture);
256 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
257 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
259 if (texture)
261 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
262 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
264 IDirect3DTexture9_Release(texture);
268 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
269 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
271 if (texture)
273 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
274 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
276 IDirect3DTexture9_Release(texture);
279 /* usage */
281 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
282 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
283 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
284 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
285 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
286 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
287 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
288 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
289 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
290 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
292 /* format */
294 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
295 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
297 if (texture)
299 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
300 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
302 IDirect3DTexture9_Release(texture);
306 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
307 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
309 if (texture)
311 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
312 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
314 IDirect3DTexture9_Release(texture);
318 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
320 IDirect3DTexture9 *tex;
321 HRESULT hr;
323 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
325 if (SUCCEEDED(hr))
327 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
328 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
330 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
331 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
333 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Last miplevel */
334 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
336 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 20, D3DX_FILTER_NONE); /* Invalid miplevel */
337 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
339 else
340 skip("Failed to create texture\n");
342 IDirect3DTexture9_Release(tex);
344 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
345 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
347 /* Test different pools */
348 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
350 if (SUCCEEDED(hr))
352 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
353 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
354 IDirect3DTexture9_Release(tex);
356 else
357 skip("Failed to create texture\n");
360 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
362 if (SUCCEEDED(hr))
364 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
365 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
366 IDirect3DTexture9_Release(tex);
368 else
369 skip("Failed to create texture\n");
372 START_TEST(texture)
374 HWND wnd;
375 IDirect3D9 *d3d;
376 IDirect3DDevice9 *device;
377 D3DPRESENT_PARAMETERS d3dpp;
378 HRESULT hr;
380 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
381 if (!wnd) {
382 skip("Couldn't create application window\n");
383 return;
385 d3d = Direct3DCreate9(D3D_SDK_VERSION);
386 if (!d3d) {
387 skip("Couldn't create IDirect3D9 object\n");
388 DestroyWindow(wnd);
389 return;
392 ZeroMemory(&d3dpp, sizeof(d3dpp));
393 d3dpp.Windowed = TRUE;
394 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
395 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
396 if (FAILED(hr)) {
397 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
398 IDirect3D9_Release(d3d);
399 DestroyWindow(wnd);
400 return;
403 test_D3DXCheckTextureRequirements(device);
404 test_D3DXCreateTexture(device);
405 test_D3DXFilterTexture(device);
407 IDirect3DDevice9_Release(device);
408 IDirect3D9_Release(d3d);
409 DestroyWindow(wnd);