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 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
106 width = 64; height = 63;
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 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
114 width = 284; height = 137;
116 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
117 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
118 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
122 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
123 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
124 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
127 skip("Skipping some tests, npot2 textures unsupported\n");
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);
135 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
136 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
137 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
140 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
141 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
142 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
143 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
144 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
145 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
146 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
147 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
148 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
149 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
152 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
153 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
155 format = D3DFMT_UNKNOWN;
156 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
157 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
158 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
160 format = D3DX_DEFAULT;
161 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
162 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
163 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
165 format = D3DFMT_R8G8B8;
166 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
167 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
168 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
170 IDirect3DDevice9_GetDirect3D(device, &d3d);
171 IDirect3DDevice9_GetCreationParameters(device, ¶ms);
172 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
174 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
175 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
176 expected = D3DFMT_R3G3B2;
179 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
180 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
181 expected = D3DFMT_X4R4G4B4;
183 expected = D3DFMT_X1R5G5B5;
186 format = D3DFMT_R3G3B2;
187 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
188 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
189 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
191 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
192 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
193 expected = D3DFMT_A8R3G3B2;
195 expected = D3DFMT_A8R8G8B8;
197 format = D3DFMT_A8R3G3B2;
198 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
199 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
200 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
202 IDirect3D9_Release(d3d);
205 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
207 UINT size, mipmaps, expected;
212 IDirect3DDevice9_GetDeviceCaps(device, &caps);
214 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
216 skip("No cube textures support\n");
221 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
222 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
224 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
225 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
227 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
228 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
232 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
233 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
234 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
239 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
240 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
241 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
245 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
246 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
247 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
248 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
252 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
253 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
254 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
255 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
258 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
259 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
260 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
263 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
264 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
265 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
266 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
267 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
268 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
269 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
270 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
271 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
272 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
275 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
276 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
278 format = D3DFMT_UNKNOWN;
279 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
280 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
281 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
283 format = D3DX_DEFAULT;
284 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
285 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
286 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
288 format = D3DFMT_R8G8B8;
289 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
290 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
291 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
294 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
296 UINT width, height, depth, mipmaps, expected;
301 IDirect3DDevice9_GetDeviceCaps(device, &caps);
303 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
305 skip("No volume textures support\n");
310 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
311 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
313 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
314 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
316 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
317 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
319 /* width, height, depth */
320 width = height = depth = D3DX_DEFAULT;
321 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
322 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
323 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
324 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
325 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
327 width = D3DX_DEFAULT;
328 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
329 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
330 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
332 width = D3DX_DEFAULT; height = 0; depth = 0;
333 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
334 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
335 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
336 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
337 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
339 width = 0; height = 0; depth = 0;
340 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
341 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
342 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
343 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
344 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
347 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
348 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
349 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
352 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
353 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
354 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
357 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
358 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
360 format = D3DFMT_UNKNOWN;
361 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
362 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
363 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
365 format = D3DX_DEFAULT;
366 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
367 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
368 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
370 format = D3DFMT_R8G8B8;
371 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
372 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
373 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
376 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
378 skip("No volume textures mipmapping support\n");
382 width = height = depth = 64;
384 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
385 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
386 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
392 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
393 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
394 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
395 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
398 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
399 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
400 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
403 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
405 IDirect3DTexture9 *texture;
406 D3DSURFACE_DESC desc;
411 IDirect3DDevice9_GetDeviceCaps(device, &caps);
413 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
414 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
416 /* width and height tests */
418 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
419 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
423 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
425 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
426 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
428 IDirect3DTexture9_Release(texture);
432 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
433 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
437 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
439 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
440 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
442 IDirect3DTexture9_Release(texture);
446 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
447 skip("Hardware only supports pow2 textures\n");
450 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
452 /* may not work with conditional NPOT */
453 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
454 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
458 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
460 /* Conditional NPOT may create a texture with different dimensions, so allow those
461 situations instead of returning a fail */
463 ok(desc.Width == 63 ||
464 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
465 "Returned width %d, expected %d\n", desc.Width, 63);
467 ok(desc.Height == 63 ||
468 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
469 "Returned height %d, expected %d\n", desc.Height, 63);
471 IDirect3DTexture9_Release(texture);
477 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
478 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
482 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
483 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
485 IDirect3DTexture9_Release(texture);
489 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
490 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
494 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
495 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
497 IDirect3DTexture9_Release(texture);
501 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
502 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
506 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
507 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
509 IDirect3DTexture9_Release(texture);
513 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
514 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
518 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
519 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
521 IDirect3DTexture9_Release(texture);
526 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
527 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
528 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
529 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
530 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
531 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
532 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
533 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
534 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
535 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
539 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
540 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
544 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
545 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
547 IDirect3DTexture9_Release(texture);
551 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
552 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
556 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
557 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
559 IDirect3DTexture9_Release(texture);
562 /* D3DXCreateTextureFromResource */
564 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
565 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
566 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
568 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
569 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
570 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
572 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
573 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
575 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
576 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
578 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
579 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
581 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
582 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
585 /* D3DXCreateTextureFromResourceEx */
586 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);
587 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
588 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
590 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);
591 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
593 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);
594 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
596 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
597 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
599 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);
600 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
603 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
605 IDirect3DTexture9 *tex;
606 IDirect3DCubeTexture9 *cubetex;
609 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
613 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
614 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
616 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
617 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
619 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
620 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
623 skip("Failed to create texture\n");
625 IDirect3DTexture9_Release(tex);
627 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
628 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
630 /* Test different pools */
631 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
635 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
636 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
637 IDirect3DTexture9_Release(tex);
640 skip("Failed to create texture\n");
642 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &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 /* Cube texture test */
654 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
658 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
659 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
661 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
662 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
664 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
665 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
668 skip("Failed to create texture\n");
670 IDirect3DCubeTexture9_Release(cubetex);
673 static BOOL color_match(const DWORD *value, const DWORD *expected)
677 for (i = 0; i < 4; i++)
679 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
680 if (diff > 1) return FALSE;
685 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
686 const D3DXVECTOR2 *texelsize, void *data)
688 value->x = texcoord->x;
689 value->y = texcoord->y;
690 value->z = texelsize->x;
694 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
696 IDirect3DTexture9 *tex;
698 D3DLOCKED_RECT lock_rect;
701 DWORD value, expected, size, pitch;
704 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
705 D3DPOOL_MANAGED, &tex, NULL);
709 hr = D3DXFillTexture(tex, fillfunc, NULL);
710 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
712 for (m = 0; m < 3; m++)
714 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
715 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
718 pitch = lock_rect.Pitch / sizeof(DWORD);
719 for (y = 0; y < size; y++)
721 for (x = 0; x < size; x++)
723 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
724 v[0] = (value >> 24) & 0xff;
725 v[1] = (value >> 16) & 0xff;
726 v[2] = (value >> 8) & 0xff;
730 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
731 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
732 e[3] = 255.0f / size + 0.5f;
733 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
735 ok(color_match(v, e),
736 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
737 x, y, value, expected);
740 IDirect3DTexture9_UnlockRect(tex, m);
746 skip("Failed to create texture\n");
748 IDirect3DTexture9_Release(tex);
750 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
751 D3DPOOL_MANAGED, &tex, NULL);
755 hr = D3DXFillTexture(tex, fillfunc, NULL);
756 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
758 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
759 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
762 pitch = lock_rect.Pitch / sizeof(WORD);
763 for (y = 0; y < 4; y++)
765 for (x = 0; x < 4; x++)
767 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
769 v[1] = value >> 10 & 0x1f;
770 v[2] = value >> 5 & 0x1f;
774 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
775 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
777 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
779 ok(color_match(v, e),
780 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
781 x, y, value, expected);
784 IDirect3DTexture9_UnlockRect(tex, 0);
788 skip("Failed to create texture\n");
790 IDirect3DTexture9_Release(tex);
793 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
794 const D3DXVECTOR3 *texelsize, void *data)
796 value->x = (texcoord->x + 1.0f) / 2.0f;
797 value->y = (texcoord->y + 1.0f) / 2.0f;
798 value->z = (texcoord->z + 1.0f) / 2.0f;
799 value->w = texelsize->x;
812 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
819 return size - x - 0.5f;
823 return size - y - 0.5f;
829 trace("Unexpected coordinate value\n");
834 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
836 IDirect3DCubeTexture9 *tex;
838 D3DLOCKED_RECT lock_rect;
841 DWORD value, expected, size, pitch;
842 enum cube_coord coordmap[6][3] =
844 {ONE, YCOORDINV, XCOORDINV},
845 {ZERO, YCOORDINV, XCOORD},
846 {XCOORD, ONE, YCOORD},
847 {XCOORD, ZERO, YCOORDINV},
848 {XCOORD, YCOORDINV, ONE},
849 {XCOORDINV, YCOORDINV, ZERO}
853 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
854 D3DPOOL_MANAGED, &tex, NULL);
858 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
859 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
861 for (m = 0; m < 3; m++)
863 for (f = 0; f < 6; f++)
865 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
866 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
869 pitch = lock_rect.Pitch / sizeof(DWORD);
870 for (y = 0; y < size; y++)
872 for (x = 0; x < size; x++)
874 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
875 v[0] = (value >> 24) & 0xff;
876 v[1] = (value >> 16) & 0xff;
877 v[2] = (value >> 8) & 0xff;
880 e[0] = (f == 0) || (f == 1) ?
881 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
882 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
883 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
884 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
885 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
887 ok(color_match(v, e),
888 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
889 f, x, y, value, expected);
892 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
899 skip("Failed to create texture\n");
901 IDirect3DCubeTexture9_Release(tex);
903 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
904 D3DPOOL_MANAGED, &tex, NULL);
908 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
909 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
910 for (f = 0; f < 6; f++)
912 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
913 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
916 pitch = lock_rect.Pitch / sizeof(WORD);
917 for (y = 0; y < 4; y++)
919 for (x = 0; x < 4; x++)
921 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
923 v[1] = value >> 10 & 0x1f;
924 v[2] = value >> 5 & 0x1f;
927 e[0] = (f == 0) || (f == 1) ?
928 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
929 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
930 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
931 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
932 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
934 ok(color_match(v, e),
935 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
936 f, x, y, value, expected);
939 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
944 skip("Failed to create texture\n");
946 IDirect3DCubeTexture9_Release(tex);
949 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
950 const D3DXVECTOR3 *texelsize, void *data)
952 value->x = texcoord->x;
953 value->y = texcoord->y;
954 value->z = texcoord->z;
955 value->w = texelsize->x;
958 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
960 IDirect3DVolumeTexture9 *tex;
962 D3DLOCKED_BOX lock_box;
965 DWORD value, expected, size, row_pitch, slice_pitch;
968 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
969 D3DPOOL_MANAGED, &tex, NULL);
973 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
974 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
976 for (m = 0; m < 3; m++)
978 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
979 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
982 row_pitch = lock_box.RowPitch / sizeof(DWORD);
983 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
984 for (z = 0; z < size; z++)
986 for (y = 0; y < size; y++)
988 for (x = 0; x < size; x++)
990 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
991 v[0] = (value >> 24) & 0xff;
992 v[1] = (value >> 16) & 0xff;
993 v[2] = (value >> 8) & 0xff;
996 e[0] = 255.0f / size + 0.5f;
997 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
998 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
999 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1000 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1002 ok(color_match(v, e),
1003 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1004 x, y, z, value, expected);
1008 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1014 skip("Failed to create texture\n");
1016 IDirect3DVolumeTexture9_Release(tex);
1018 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1019 D3DPOOL_MANAGED, &tex, NULL);
1023 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1024 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1025 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1026 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1029 row_pitch = lock_box.RowPitch / sizeof(WORD);
1030 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1031 for (z = 0; z < 4; z++)
1033 for (y = 0; y < 4; y++)
1035 for (x = 0; x < 4; x++)
1037 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1039 v[1] = value >> 10 & 0x1f;
1040 v[2] = value >> 5 & 0x1f;
1041 v[3] = value & 0x1f;
1044 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1045 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1046 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1047 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1049 ok(color_match(v, e),
1050 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1051 x, y, z, value, expected);
1055 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1059 skip("Failed to create texture\n");
1061 IDirect3DVolumeTexture9_Release(tex);
1068 IDirect3DDevice9 *device;
1069 D3DPRESENT_PARAMETERS d3dpp;
1072 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1074 skip("Couldn't create application window\n");
1077 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1079 skip("Couldn't create IDirect3D9 object\n");
1084 ZeroMemory(&d3dpp, sizeof(d3dpp));
1085 d3dpp.Windowed = TRUE;
1086 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1087 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1089 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1090 IDirect3D9_Release(d3d);
1095 test_D3DXCheckTextureRequirements(device);
1096 test_D3DXCheckCubeTextureRequirements(device);
1097 test_D3DXCheckVolumeTextureRequirements(device);
1098 test_D3DXCreateTexture(device);
1099 test_D3DXFilterTexture(device);
1100 test_D3DXFillTexture(device);
1101 test_D3DXFillCubeTexture(device);
1102 test_D3DXFillVolumeTexture(device);
1104 IDirect3DDevice9_Release(device);
1105 IDirect3D9_Release(d3d);