d3dx9_36: Make sure return values are used (LLVM/Clang).
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blobc5753463a0f14bc6784a669539dfde2ccb397267
1 /*
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
23 #define COBJMACROS
24 #include "wine/test.h"
25 #include "d3dx9tex.h"
26 #include "resources.h"
28 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
30 UINT width, height, mipmaps;
31 D3DFORMAT format, expected;
32 D3DCAPS9 caps;
33 HRESULT hr;
34 IDirect3D9 *d3d;
35 D3DDEVICE_CREATION_PARAMETERS params;
36 D3DDISPLAYMODE mode;
38 IDirect3DDevice9_GetDeviceCaps(device, &caps);
40 /* general tests */
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);
50 /* width & height */
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);
57 width = D3DX_DEFAULT;
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");
64 else
66 width = 62;
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);
90 width = 0;
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);
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 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
114 width = 284; height = 137;
115 mipmaps = 20;
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);
120 width = height = 63;
121 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);
126 else
127 skip("Skipping some tests, npot2 textures unsupported\n");
129 mipmaps = 20;
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 mipmaps = 0;
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);
139 /* usage */
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");
151 /* format */
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, &params);
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;
177 else
179 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
180 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
181 expected = D3DFMT_X4R4G4B4;
182 else
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;
194 else
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;
208 D3DFORMAT format;
209 D3DCAPS9 caps;
210 HRESULT hr;
212 IDirect3DDevice9_GetDeviceCaps(device, &caps);
214 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
216 skip("No cube textures support\n");
217 return;
220 /* general tests */
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);
230 /* size */
231 size = D3DX_DEFAULT;
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);
236 /* mipmaps */
237 size = 64;
238 mipmaps = 9;
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);
243 size = 284;
244 mipmaps = 20;
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);
250 size = 63;
251 mipmaps = 9;
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);
257 mipmaps = 0;
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);
262 /* usage */
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");
274 /* format */
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;
297 D3DFORMAT format;
298 D3DCAPS9 caps;
299 HRESULT hr;
301 IDirect3DDevice9_GetDeviceCaps(device, &caps);
303 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
305 skip("No volume textures support\n");
306 return;
309 /* general tests */
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);
346 width = 0;
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);
351 width = 0xFFFFFFFE;
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);
356 /* format */
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);
375 /* mipmaps */
376 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
378 skip("No volume textures mipmapping support\n");
379 return;
382 width = height = depth = 64;
383 mipmaps = 9;
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);
388 width = 284;
389 height = 143;
390 depth = 55;
391 mipmaps = 20;
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);
397 mipmaps = 0;
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;
407 D3DCAPS9 caps;
408 UINT mipmaps;
409 HRESULT hr;
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);
421 if (texture)
423 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
424 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
425 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
427 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
428 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
430 IDirect3DTexture9_Release(texture);
434 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
435 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
437 if (texture)
439 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
440 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
441 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
443 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
444 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
446 IDirect3DTexture9_Release(texture);
450 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
451 skip("Hardware only supports pow2 textures\n");
452 else
454 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
455 ok((hr == D3D_OK) ||
456 /* may not work with conditional NPOT */
457 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
458 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
460 if (texture)
462 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
463 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
464 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
466 /* Conditional NPOT may create a texture with different dimensions, so allow those
467 situations instead of returning a fail */
469 ok(desc.Width == 63 ||
470 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
471 "Returned width %d, expected %d\n", desc.Width, 63);
473 ok(desc.Height == 63 ||
474 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
475 "Returned height %d, expected %d\n", desc.Height, 63);
477 IDirect3DTexture9_Release(texture);
481 /* mipmaps */
483 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
484 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
486 if (texture)
488 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
489 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
491 IDirect3DTexture9_Release(texture);
495 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
496 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
498 if (texture)
500 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
501 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
503 IDirect3DTexture9_Release(texture);
507 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
508 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
510 if (texture)
512 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
513 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
515 IDirect3DTexture9_Release(texture);
519 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
520 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
522 if (texture)
524 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
525 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
527 IDirect3DTexture9_Release(texture);
530 /* usage */
532 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
533 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
534 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
535 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
536 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
537 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
538 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
539 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
540 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
541 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
543 /* format */
545 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
546 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
548 if (texture)
550 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
551 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
552 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
554 IDirect3DTexture9_Release(texture);
558 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
559 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
561 if (texture)
563 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
564 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
565 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
567 IDirect3DTexture9_Release(texture);
570 /* D3DXCreateTextureFromResource */
571 todo_wine {
572 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
573 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
574 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
576 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
577 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
578 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
580 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
581 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
583 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
584 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
586 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
587 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
589 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
590 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
593 /* D3DXCreateTextureFromResourceEx */
594 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);
595 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
596 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
598 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);
599 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
601 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);
602 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
604 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
605 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
607 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);
608 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
611 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
613 IDirect3DTexture9 *tex;
614 IDirect3DCubeTexture9 *cubetex;
615 HRESULT hr;
617 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
619 if (SUCCEEDED(hr))
621 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
622 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
624 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
625 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
627 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
628 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
630 else
631 skip("Failed to create texture\n");
633 IDirect3DTexture9_Release(tex);
635 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
636 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
638 /* Test different pools */
639 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
641 if (SUCCEEDED(hr))
643 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
644 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
645 IDirect3DTexture9_Release(tex);
647 else
648 skip("Failed to create texture\n");
650 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
652 if (SUCCEEDED(hr))
654 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
655 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
656 IDirect3DTexture9_Release(tex);
658 else
659 skip("Failed to create texture\n");
661 /* Cube texture test */
662 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
664 if (SUCCEEDED(hr))
666 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
667 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
669 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
670 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
672 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
673 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
675 else
676 skip("Failed to create texture\n");
678 IDirect3DCubeTexture9_Release(cubetex);
681 static BOOL color_match(const DWORD *value, const DWORD *expected)
683 int i;
685 for (i = 0; i < 4; i++)
687 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
688 if (diff > 1) return FALSE;
690 return TRUE;
693 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
694 const D3DXVECTOR2 *texelsize, void *data)
696 value->x = texcoord->x;
697 value->y = texcoord->y;
698 value->z = texelsize->x;
699 value->w = 1.0f;
702 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
704 IDirect3DTexture9 *tex;
705 HRESULT hr;
706 D3DLOCKED_RECT lock_rect;
707 DWORD x, y, m;
708 DWORD v[4], e[4];
709 DWORD value, expected, size, pitch;
711 size = 4;
712 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
713 D3DPOOL_MANAGED, &tex, NULL);
715 if (SUCCEEDED(hr))
717 hr = D3DXFillTexture(tex, fillfunc, NULL);
718 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
720 for (m = 0; m < 3; m++)
722 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
723 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
724 if (SUCCEEDED(hr))
726 pitch = lock_rect.Pitch / sizeof(DWORD);
727 for (y = 0; y < size; y++)
729 for (x = 0; x < size; x++)
731 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
732 v[0] = (value >> 24) & 0xff;
733 v[1] = (value >> 16) & 0xff;
734 v[2] = (value >> 8) & 0xff;
735 v[3] = value & 0xff;
737 e[0] = 0xff;
738 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
739 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
740 e[3] = 255.0f / size + 0.5f;
741 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
743 ok(color_match(v, e),
744 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
745 x, y, value, expected);
748 IDirect3DTexture9_UnlockRect(tex, m);
750 size >>= 1;
753 else
754 skip("Failed to create texture\n");
756 IDirect3DTexture9_Release(tex);
758 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
759 D3DPOOL_MANAGED, &tex, NULL);
761 if (SUCCEEDED(hr))
763 hr = D3DXFillTexture(tex, fillfunc, NULL);
764 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
766 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
767 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
768 if (SUCCEEDED(hr))
770 pitch = lock_rect.Pitch / sizeof(WORD);
771 for (y = 0; y < 4; y++)
773 for (x = 0; x < 4; x++)
775 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
776 v[0] = value >> 15;
777 v[1] = value >> 10 & 0x1f;
778 v[2] = value >> 5 & 0x1f;
779 v[3] = value & 0x1f;
781 e[0] = 1;
782 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
783 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
784 e[3] = 8;
785 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
787 ok(color_match(v, e),
788 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
789 x, y, value, expected);
792 IDirect3DTexture9_UnlockRect(tex, 0);
795 else
796 skip("Failed to create texture\n");
798 IDirect3DTexture9_Release(tex);
801 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
802 const D3DXVECTOR3 *texelsize, void *data)
804 value->x = (texcoord->x + 1.0f) / 2.0f;
805 value->y = (texcoord->y + 1.0f) / 2.0f;
806 value->z = (texcoord->z + 1.0f) / 2.0f;
807 value->w = texelsize->x;
810 enum cube_coord
812 XCOORD = 0,
813 XCOORDINV = 1,
814 YCOORD = 2,
815 YCOORDINV = 3,
816 ZERO = 4,
817 ONE = 5
820 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
822 switch (coord)
824 case XCOORD:
825 return x + 0.5f;
826 case XCOORDINV:
827 return size - x - 0.5f;
828 case YCOORD:
829 return y + 0.5f;
830 case YCOORDINV:
831 return size - y - 0.5f;
832 case ZERO:
833 return 0.0f;
834 case ONE:
835 return size;
836 default:
837 trace("Unexpected coordinate value\n");
838 return 0.0f;
842 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
844 IDirect3DCubeTexture9 *tex;
845 HRESULT hr;
846 D3DLOCKED_RECT lock_rect;
847 DWORD x, y, f, m;
848 DWORD v[4], e[4];
849 DWORD value, expected, size, pitch;
850 enum cube_coord coordmap[6][3] =
852 {ONE, YCOORDINV, XCOORDINV},
853 {ZERO, YCOORDINV, XCOORD},
854 {XCOORD, ONE, YCOORD},
855 {XCOORD, ZERO, YCOORDINV},
856 {XCOORD, YCOORDINV, ONE},
857 {XCOORDINV, YCOORDINV, ZERO}
860 size = 4;
861 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
862 D3DPOOL_MANAGED, &tex, NULL);
864 if (SUCCEEDED(hr))
866 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
867 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
869 for (m = 0; m < 3; m++)
871 for (f = 0; f < 6; f++)
873 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
874 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
875 if (SUCCEEDED(hr))
877 pitch = lock_rect.Pitch / sizeof(DWORD);
878 for (y = 0; y < size; y++)
880 for (x = 0; x < size; x++)
882 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
883 v[0] = (value >> 24) & 0xff;
884 v[1] = (value >> 16) & 0xff;
885 v[2] = (value >> 8) & 0xff;
886 v[3] = value & 0xff;
888 e[0] = (f == 0) || (f == 1) ?
889 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
890 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
891 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
892 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
893 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
895 ok(color_match(v, e),
896 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
897 f, x, y, value, expected);
900 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
903 size >>= 1;
906 else
907 skip("Failed to create texture\n");
909 IDirect3DCubeTexture9_Release(tex);
911 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
912 D3DPOOL_MANAGED, &tex, NULL);
914 if (SUCCEEDED(hr))
916 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
917 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
918 for (f = 0; f < 6; f++)
920 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
921 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
922 if (SUCCEEDED(hr))
924 pitch = lock_rect.Pitch / sizeof(WORD);
925 for (y = 0; y < 4; y++)
927 for (x = 0; x < 4; x++)
929 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
930 v[0] = value >> 15;
931 v[1] = value >> 10 & 0x1f;
932 v[2] = value >> 5 & 0x1f;
933 v[3] = value & 0x1f;
935 e[0] = (f == 0) || (f == 1) ?
936 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
937 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
938 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
939 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
940 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
942 ok(color_match(v, e),
943 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
944 f, x, y, value, expected);
947 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
951 else
952 skip("Failed to create texture\n");
954 IDirect3DCubeTexture9_Release(tex);
957 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
958 const D3DXVECTOR3 *texelsize, void *data)
960 value->x = texcoord->x;
961 value->y = texcoord->y;
962 value->z = texcoord->z;
963 value->w = texelsize->x;
966 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
968 IDirect3DVolumeTexture9 *tex;
969 HRESULT hr;
970 D3DLOCKED_BOX lock_box;
971 DWORD x, y, z, m;
972 DWORD v[4], e[4];
973 DWORD value, expected, size, row_pitch, slice_pitch;
975 size = 4;
976 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
977 D3DPOOL_MANAGED, &tex, NULL);
979 if (SUCCEEDED(hr))
981 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
982 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
984 for (m = 0; m < 3; m++)
986 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
987 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
988 if (SUCCEEDED(hr))
990 row_pitch = lock_box.RowPitch / sizeof(DWORD);
991 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
992 for (z = 0; z < size; z++)
994 for (y = 0; y < size; y++)
996 for (x = 0; x < size; x++)
998 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
999 v[0] = (value >> 24) & 0xff;
1000 v[1] = (value >> 16) & 0xff;
1001 v[2] = (value >> 8) & 0xff;
1002 v[3] = value & 0xff;
1004 e[0] = 255.0f / size + 0.5f;
1005 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1006 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1007 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1008 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1010 ok(color_match(v, e),
1011 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1012 x, y, z, value, expected);
1016 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1018 size >>= 1;
1021 else
1022 skip("Failed to create texture\n");
1024 IDirect3DVolumeTexture9_Release(tex);
1026 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1027 D3DPOOL_MANAGED, &tex, NULL);
1029 if (SUCCEEDED(hr))
1031 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1032 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1033 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1034 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1035 if (SUCCEEDED(hr))
1037 row_pitch = lock_box.RowPitch / sizeof(WORD);
1038 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1039 for (z = 0; z < 4; z++)
1041 for (y = 0; y < 4; y++)
1043 for (x = 0; x < 4; x++)
1045 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1046 v[0] = value >> 15;
1047 v[1] = value >> 10 & 0x1f;
1048 v[2] = value >> 5 & 0x1f;
1049 v[3] = value & 0x1f;
1051 e[0] = 1;
1052 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1053 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1054 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1055 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1057 ok(color_match(v, e),
1058 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1059 x, y, z, value, expected);
1063 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1066 else
1067 skip("Failed to create texture\n");
1069 IDirect3DVolumeTexture9_Release(tex);
1072 START_TEST(texture)
1074 HWND wnd;
1075 IDirect3D9 *d3d;
1076 IDirect3DDevice9 *device;
1077 D3DPRESENT_PARAMETERS d3dpp;
1078 HRESULT hr;
1080 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1081 if (!wnd) {
1082 skip("Couldn't create application window\n");
1083 return;
1085 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1086 if (!d3d) {
1087 skip("Couldn't create IDirect3D9 object\n");
1088 DestroyWindow(wnd);
1089 return;
1092 ZeroMemory(&d3dpp, sizeof(d3dpp));
1093 d3dpp.Windowed = TRUE;
1094 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1095 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1096 if (FAILED(hr)) {
1097 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1098 IDirect3D9_Release(d3d);
1099 DestroyWindow(wnd);
1100 return;
1103 test_D3DXCheckTextureRequirements(device);
1104 test_D3DXCheckCubeTextureRequirements(device);
1105 test_D3DXCheckVolumeTextureRequirements(device);
1106 test_D3DXCreateTexture(device);
1107 test_D3DXFilterTexture(device);
1108 test_D3DXFillTexture(device);
1109 test_D3DXFillCubeTexture(device);
1110 test_D3DXFillVolumeTexture(device);
1112 IDirect3DDevice9_Release(device);
1113 IDirect3D9_Release(d3d);
1114 DestroyWindow(wnd);