2 * Tests for the D3DX9 texture functions
4 * Copyright 2009 Tony Wasserka
5 * Copyright 2010 Owen Rudge for CodeWeavers
6 * Copyright 2010 Matteo Bruni for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 #include "resources.h"
28 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
30 UINT width, height, mipmaps;
31 D3DFORMAT format, expected;
35 D3DDEVICE_CREATION_PARAMETERS params;
38 IDirect3DDevice9_GetDeviceCaps(device, &caps);
41 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
42 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
44 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
45 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
47 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
48 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
51 width = height = D3DX_DEFAULT;
52 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
53 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
54 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
55 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
58 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
59 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
60 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
62 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
63 skip("Hardware only supports pow2 textures\n");
67 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
68 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
69 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
71 width = D3DX_DEFAULT; height = 63;
72 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
73 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
74 ok(width == height, "Returned width %d, expected %d\n", width, height);
75 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
78 width = D3DX_DEFAULT; height = 0;
79 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
80 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
81 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
82 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
84 width = 0; height = 0;
85 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
86 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
87 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
88 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
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 == 1, "Returned width %d, expected %d\n", width, 1);
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 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
104 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
106 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
109 width = 64; height = 63;
111 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
112 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
113 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
115 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
117 width = 284; height = 137;
119 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
120 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
121 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
125 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
126 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
130 skip("Skipping some tests, npot2 textures unsupported\n");
133 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
134 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
135 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
138 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
139 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
140 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
143 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
144 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
145 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
146 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
147 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
148 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
149 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
150 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
151 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
152 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
155 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
156 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
158 format = D3DFMT_UNKNOWN;
159 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
160 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
161 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
163 format = D3DX_DEFAULT;
164 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
165 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
166 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
168 format = D3DFMT_R8G8B8;
169 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
170 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
171 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
173 IDirect3DDevice9_GetDirect3D(device, &d3d);
174 IDirect3DDevice9_GetCreationParameters(device, ¶ms);
175 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
177 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
178 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
179 expected = D3DFMT_R3G3B2;
182 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
183 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
184 expected = D3DFMT_X4R4G4B4;
186 expected = D3DFMT_X1R5G5B5;
189 format = D3DFMT_R3G3B2;
190 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
191 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
192 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
194 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
195 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
196 expected = D3DFMT_A8R3G3B2;
198 expected = D3DFMT_A8R8G8B8;
200 format = D3DFMT_A8R3G3B2;
201 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
202 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
203 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
205 IDirect3D9_Release(d3d);
208 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
210 UINT size, mipmaps, expected;
215 IDirect3DDevice9_GetDeviceCaps(device, &caps);
217 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
219 skip("No cube textures support\n");
224 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
225 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
227 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
228 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
230 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
231 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
235 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
236 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
237 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
242 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
243 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
244 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
248 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
249 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
250 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
251 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
255 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
256 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
257 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
258 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
261 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
262 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
263 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
266 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
267 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
268 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
269 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
270 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
271 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
272 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
273 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
274 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
275 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
278 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
279 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
281 format = D3DFMT_UNKNOWN;
282 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
283 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
284 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
286 format = D3DX_DEFAULT;
287 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
288 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
289 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
291 format = D3DFMT_R8G8B8;
292 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
293 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
294 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
297 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
299 UINT width, height, depth, mipmaps, expected;
304 IDirect3DDevice9_GetDeviceCaps(device, &caps);
306 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
308 skip("No volume textures support\n");
313 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
314 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
316 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
317 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
319 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
320 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
322 /* width, height, depth */
323 width = height = depth = D3DX_DEFAULT;
324 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
325 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
326 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
327 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
328 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
330 width = D3DX_DEFAULT;
331 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
332 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
333 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
335 width = D3DX_DEFAULT; height = 0; depth = 0;
336 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
337 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
338 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
339 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
340 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
342 width = 0; height = 0; depth = 0;
343 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
344 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
345 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
346 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
347 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
350 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
351 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
352 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
355 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
356 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
357 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
360 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
361 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
363 format = D3DFMT_UNKNOWN;
364 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
365 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
366 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
368 format = D3DX_DEFAULT;
369 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
370 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
371 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
373 format = D3DFMT_R8G8B8;
374 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
375 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
376 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
379 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
381 skip("No volume textures mipmapping support\n");
385 width = height = depth = 64;
387 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
388 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
389 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
395 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
396 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
397 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
398 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
401 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
402 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
403 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
406 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
408 IDirect3DTexture9 *texture;
409 D3DSURFACE_DESC desc;
414 IDirect3DDevice9_GetDeviceCaps(device, &caps);
416 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
417 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
419 /* width and height tests */
421 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
422 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
426 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
427 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
428 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
430 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
431 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
433 IDirect3DTexture9_Release(texture);
437 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
438 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
442 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
443 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
444 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
446 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
447 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
449 IDirect3DTexture9_Release(texture);
453 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
454 skip("Hardware only supports pow2 textures\n");
457 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
459 /* may not work with conditional NPOT */
460 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
461 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
465 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
466 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
467 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
469 /* Conditional NPOT may create a texture with different dimensions, so allow those
470 situations instead of returning a fail */
472 ok(desc.Width == 63 ||
473 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
474 "Returned width %d, expected %d\n", desc.Width, 63);
476 ok(desc.Height == 63 ||
477 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
478 "Returned height %d, expected %d\n", desc.Height, 63);
480 IDirect3DTexture9_Release(texture);
486 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
487 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
491 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
492 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
494 IDirect3DTexture9_Release(texture);
498 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
499 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
503 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
504 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
506 IDirect3DTexture9_Release(texture);
510 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
511 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
515 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
516 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
518 IDirect3DTexture9_Release(texture);
522 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
523 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
527 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
528 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
530 IDirect3DTexture9_Release(texture);
535 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
536 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
537 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
538 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
539 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
540 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
541 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
542 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
543 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
544 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
548 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
549 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
553 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
554 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
555 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
557 IDirect3DTexture9_Release(texture);
561 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
562 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
566 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
567 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
568 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
570 IDirect3DTexture9_Release(texture);
573 /* D3DXCreateTextureFromResource */
575 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
576 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
577 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
579 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
580 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
581 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
583 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
584 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
586 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
587 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
589 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
590 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
592 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
593 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
596 /* D3DXCreateTextureFromResourceEx */
597 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
598 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
599 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
601 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
602 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
604 hr = D3DXCreateTextureFromResourceExA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
605 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
607 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
608 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
610 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, NULL);
611 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
614 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
616 IDirect3DTexture9 *tex;
617 IDirect3DCubeTexture9 *cubetex;
620 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
624 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
625 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
627 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
628 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
630 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
631 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
634 skip("Failed to create texture\n");
636 IDirect3DTexture9_Release(tex);
638 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
639 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
641 /* Test different pools */
642 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
646 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
647 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
648 IDirect3DTexture9_Release(tex);
651 skip("Failed to create texture\n");
653 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
657 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
658 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
659 IDirect3DTexture9_Release(tex);
662 skip("Failed to create texture\n");
664 /* Cube texture test */
665 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
669 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
670 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
672 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
673 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
675 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
676 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
679 skip("Failed to create texture\n");
681 IDirect3DCubeTexture9_Release(cubetex);
684 static BOOL color_match(const DWORD *value, const DWORD *expected)
688 for (i = 0; i < 4; i++)
690 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
691 if (diff > 1) return FALSE;
696 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
697 const D3DXVECTOR2 *texelsize, void *data)
699 value->x = texcoord->x;
700 value->y = texcoord->y;
701 value->z = texelsize->x;
705 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
707 IDirect3DTexture9 *tex;
709 D3DLOCKED_RECT lock_rect;
712 DWORD value, expected, size, pitch;
715 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
716 D3DPOOL_MANAGED, &tex, NULL);
720 hr = D3DXFillTexture(tex, fillfunc, NULL);
721 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
723 for (m = 0; m < 3; m++)
725 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
726 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
729 pitch = lock_rect.Pitch / sizeof(DWORD);
730 for (y = 0; y < size; y++)
732 for (x = 0; x < size; x++)
734 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
735 v[0] = (value >> 24) & 0xff;
736 v[1] = (value >> 16) & 0xff;
737 v[2] = (value >> 8) & 0xff;
741 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
742 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
743 e[3] = 255.0f / size + 0.5f;
744 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
746 ok(color_match(v, e),
747 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
748 x, y, value, expected);
751 IDirect3DTexture9_UnlockRect(tex, m);
757 skip("Failed to create texture\n");
759 IDirect3DTexture9_Release(tex);
761 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
762 D3DPOOL_MANAGED, &tex, NULL);
766 hr = D3DXFillTexture(tex, fillfunc, NULL);
767 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
769 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
770 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
773 pitch = lock_rect.Pitch / sizeof(WORD);
774 for (y = 0; y < 4; y++)
776 for (x = 0; x < 4; x++)
778 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
780 v[1] = value >> 10 & 0x1f;
781 v[2] = value >> 5 & 0x1f;
785 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
786 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
788 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
790 ok(color_match(v, e),
791 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
792 x, y, value, expected);
795 IDirect3DTexture9_UnlockRect(tex, 0);
799 skip("Failed to create texture\n");
801 IDirect3DTexture9_Release(tex);
804 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
805 const D3DXVECTOR3 *texelsize, void *data)
807 value->x = (texcoord->x + 1.0f) / 2.0f;
808 value->y = (texcoord->y + 1.0f) / 2.0f;
809 value->z = (texcoord->z + 1.0f) / 2.0f;
810 value->w = texelsize->x;
823 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
830 return size - x - 0.5f;
834 return size - y - 0.5f;
840 trace("Unexpected coordinate value\n");
845 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
847 IDirect3DCubeTexture9 *tex;
849 D3DLOCKED_RECT lock_rect;
852 DWORD value, expected, size, pitch;
853 enum cube_coord coordmap[6][3] =
855 {ONE, YCOORDINV, XCOORDINV},
856 {ZERO, YCOORDINV, XCOORD},
857 {XCOORD, ONE, YCOORD},
858 {XCOORD, ZERO, YCOORDINV},
859 {XCOORD, YCOORDINV, ONE},
860 {XCOORDINV, YCOORDINV, ZERO}
864 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
865 D3DPOOL_MANAGED, &tex, NULL);
869 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
870 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
872 for (m = 0; m < 3; m++)
874 for (f = 0; f < 6; f++)
876 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
877 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
880 pitch = lock_rect.Pitch / sizeof(DWORD);
881 for (y = 0; y < size; y++)
883 for (x = 0; x < size; x++)
885 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
886 v[0] = (value >> 24) & 0xff;
887 v[1] = (value >> 16) & 0xff;
888 v[2] = (value >> 8) & 0xff;
891 e[0] = (f == 0) || (f == 1) ?
892 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
893 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
894 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
895 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
896 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
898 ok(color_match(v, e),
899 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
900 f, x, y, value, expected);
903 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
910 skip("Failed to create texture\n");
912 IDirect3DCubeTexture9_Release(tex);
914 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
915 D3DPOOL_MANAGED, &tex, NULL);
919 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
920 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
921 for (f = 0; f < 6; f++)
923 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
924 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
927 pitch = lock_rect.Pitch / sizeof(WORD);
928 for (y = 0; y < 4; y++)
930 for (x = 0; x < 4; x++)
932 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
934 v[1] = value >> 10 & 0x1f;
935 v[2] = value >> 5 & 0x1f;
938 e[0] = (f == 0) || (f == 1) ?
939 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
940 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
941 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
942 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
943 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
945 ok(color_match(v, e),
946 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
947 f, x, y, value, expected);
950 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
955 skip("Failed to create texture\n");
957 IDirect3DCubeTexture9_Release(tex);
960 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
961 const D3DXVECTOR3 *texelsize, void *data)
963 value->x = texcoord->x;
964 value->y = texcoord->y;
965 value->z = texcoord->z;
966 value->w = texelsize->x;
969 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
971 IDirect3DVolumeTexture9 *tex;
973 D3DLOCKED_BOX lock_box;
976 DWORD value, expected, size, row_pitch, slice_pitch;
979 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
980 D3DPOOL_MANAGED, &tex, NULL);
984 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
985 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
987 for (m = 0; m < 3; m++)
989 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
990 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
993 row_pitch = lock_box.RowPitch / sizeof(DWORD);
994 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
995 for (z = 0; z < size; z++)
997 for (y = 0; y < size; y++)
999 for (x = 0; x < size; x++)
1001 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1002 v[0] = (value >> 24) & 0xff;
1003 v[1] = (value >> 16) & 0xff;
1004 v[2] = (value >> 8) & 0xff;
1005 v[3] = value & 0xff;
1007 e[0] = 255.0f / size + 0.5f;
1008 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1009 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1010 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1011 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1013 ok(color_match(v, e),
1014 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1015 x, y, z, value, expected);
1019 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1025 skip("Failed to create texture\n");
1027 IDirect3DVolumeTexture9_Release(tex);
1029 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1030 D3DPOOL_MANAGED, &tex, NULL);
1034 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1035 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1036 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1037 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1040 row_pitch = lock_box.RowPitch / sizeof(WORD);
1041 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1042 for (z = 0; z < 4; z++)
1044 for (y = 0; y < 4; y++)
1046 for (x = 0; x < 4; x++)
1048 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1050 v[1] = value >> 10 & 0x1f;
1051 v[2] = value >> 5 & 0x1f;
1052 v[3] = value & 0x1f;
1055 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1056 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1057 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1058 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1060 ok(color_match(v, e),
1061 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1062 x, y, z, value, expected);
1066 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1070 skip("Failed to create texture\n");
1072 IDirect3DVolumeTexture9_Release(tex);
1079 IDirect3DDevice9 *device;
1080 D3DPRESENT_PARAMETERS d3dpp;
1083 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1085 skip("Couldn't create application window\n");
1088 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1090 skip("Couldn't create IDirect3D9 object\n");
1095 ZeroMemory(&d3dpp, sizeof(d3dpp));
1096 d3dpp.Windowed = TRUE;
1097 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1098 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1100 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1101 IDirect3D9_Release(d3d);
1106 test_D3DXCheckTextureRequirements(device);
1107 test_D3DXCheckCubeTextureRequirements(device);
1108 test_D3DXCheckVolumeTextureRequirements(device);
1109 test_D3DXCreateTexture(device);
1110 test_D3DXFilterTexture(device);
1111 test_D3DXFillTexture(device);
1112 test_D3DXFillCubeTexture(device);
1113 test_D3DXFillVolumeTexture(device);
1115 IDirect3DDevice9_Release(device);
1116 IDirect3D9_Release(d3d);