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 /* 4x4 cube map dds */
29 static const unsigned char dds_cube_map[] = {
30 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
31 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
35 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
37 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
39 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
40 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
41 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
42 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
43 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
46 /* 4x4x2 volume map dds, 2 mipmaps */
47 static const unsigned char dds_volume_map[] = {
48 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
49 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
50 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
51 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
52 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
53 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
54 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
55 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
56 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
57 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
58 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
59 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
62 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
64 UINT width, height, mipmaps;
65 D3DFORMAT format, expected;
69 D3DDEVICE_CREATION_PARAMETERS params;
72 IDirect3DDevice9_GetDeviceCaps(device, &caps);
75 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
76 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
78 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
79 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
81 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
82 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
85 width = height = D3DX_DEFAULT;
86 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
87 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
88 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
89 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
92 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
93 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
94 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
96 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
97 skip("Hardware only supports pow2 textures\n");
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 == 62, "Returned width %d, expected %d\n", width, 62);
105 width = D3DX_DEFAULT; height = 63;
106 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
107 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
108 ok(width == height, "Returned width %d, expected %d\n", width, height);
109 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
112 width = D3DX_DEFAULT; height = 0;
113 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
114 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
115 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
116 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
118 width = 0; height = 0;
119 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
120 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
121 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
122 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
125 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
126 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
130 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
131 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
132 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
134 width = caps.MaxTextureWidth-1;
135 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
136 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
137 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
138 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
140 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
143 width = 64; height = 63;
145 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
146 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
147 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
149 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
151 width = 284; height = 137;
153 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
154 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
155 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
159 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
160 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
161 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
164 skip("Skipping some tests, npot2 textures unsupported\n");
167 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
168 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
169 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
172 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
173 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
174 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
177 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
178 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
179 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
180 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
181 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
182 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
183 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
184 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
185 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
186 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
189 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
190 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
192 format = D3DFMT_UNKNOWN;
193 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
194 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
195 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
197 format = D3DX_DEFAULT;
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 == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
202 format = D3DFMT_R8G8B8;
203 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
204 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
205 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
207 IDirect3DDevice9_GetDirect3D(device, &d3d);
208 IDirect3DDevice9_GetCreationParameters(device, ¶ms);
209 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
211 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
212 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
213 expected = D3DFMT_R3G3B2;
216 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
217 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
218 expected = D3DFMT_X4R4G4B4;
220 expected = D3DFMT_X1R5G5B5;
223 format = D3DFMT_R3G3B2;
224 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
225 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
226 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
228 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
229 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
230 expected = D3DFMT_A8R3G3B2;
232 expected = D3DFMT_A8R8G8B8;
234 format = D3DFMT_A8R3G3B2;
235 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
236 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
237 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
239 IDirect3D9_Release(d3d);
242 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
244 UINT size, mipmaps, expected;
249 IDirect3DDevice9_GetDeviceCaps(device, &caps);
251 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
253 skip("No cube textures support\n");
258 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
259 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
261 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
262 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
264 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
265 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
269 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
270 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
271 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
276 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
277 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
278 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
282 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
283 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
284 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
285 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
289 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
290 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
291 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
292 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
295 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
296 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
297 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
300 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
301 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
302 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
303 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
304 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
305 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
306 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
307 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
308 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
309 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
312 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
313 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
315 format = D3DFMT_UNKNOWN;
316 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
317 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
318 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
320 format = D3DX_DEFAULT;
321 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
322 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
323 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
325 format = D3DFMT_R8G8B8;
326 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
327 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
328 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
331 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
333 UINT width, height, depth, mipmaps, expected;
338 IDirect3DDevice9_GetDeviceCaps(device, &caps);
340 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
342 skip("No volume textures support\n");
347 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
348 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
350 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
351 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
353 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
354 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
356 /* width, height, depth */
357 width = height = depth = D3DX_DEFAULT;
358 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
359 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
360 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
361 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
362 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
364 width = D3DX_DEFAULT;
365 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
366 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
367 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
369 width = D3DX_DEFAULT; height = 0; depth = 0;
370 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
371 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
372 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
373 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
374 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
376 width = 0; height = 0; depth = 0;
377 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
378 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
379 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
380 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
381 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
384 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
385 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
386 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
389 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
390 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
391 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
394 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
395 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
397 format = D3DFMT_UNKNOWN;
398 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
399 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
400 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
402 format = D3DX_DEFAULT;
403 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
404 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
405 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
407 format = D3DFMT_R8G8B8;
408 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
409 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
410 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
413 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
415 skip("No volume textures mipmapping support\n");
419 width = height = depth = 64;
421 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
422 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
423 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
429 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
430 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
431 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
432 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
435 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
436 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
437 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
440 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
442 IDirect3DTexture9 *texture;
443 D3DSURFACE_DESC desc;
448 IDirect3DDevice9_GetDeviceCaps(device, &caps);
450 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
451 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
453 /* width and height tests */
455 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
456 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
460 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
461 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
462 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
464 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
465 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
467 IDirect3DTexture9_Release(texture);
471 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
472 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
476 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
477 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
478 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
480 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
481 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
483 IDirect3DTexture9_Release(texture);
487 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
488 skip("Hardware only supports pow2 textures\n");
491 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
493 /* may not work with conditional NPOT */
494 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
495 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
499 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
500 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
501 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
503 /* Conditional NPOT may create a texture with different dimensions, so allow those
504 situations instead of returning a fail */
506 ok(desc.Width == 63 ||
507 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
508 "Returned width %d, expected %d\n", desc.Width, 63);
510 ok(desc.Height == 63 ||
511 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
512 "Returned height %d, expected %d\n", desc.Height, 63);
514 IDirect3DTexture9_Release(texture);
520 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
521 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
525 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
526 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
528 IDirect3DTexture9_Release(texture);
532 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
533 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
537 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
538 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
540 IDirect3DTexture9_Release(texture);
544 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
545 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
549 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
550 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
552 IDirect3DTexture9_Release(texture);
556 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
557 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
561 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
562 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
564 IDirect3DTexture9_Release(texture);
569 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
570 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
571 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
572 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
573 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
574 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
575 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
576 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
577 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
578 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
582 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
583 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
587 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
588 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
589 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
591 IDirect3DTexture9_Release(texture);
595 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
596 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
600 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
601 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
602 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
604 IDirect3DTexture9_Release(texture);
607 /* D3DXCreateTextureFromResource */
609 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
610 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
611 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
613 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
614 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
615 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
617 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
618 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
620 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
621 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
623 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
624 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
626 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
627 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
630 /* D3DXCreateTextureFromResourceEx */
631 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);
632 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
633 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
635 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);
636 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
638 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);
639 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
641 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
642 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
644 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);
645 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
648 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
650 IDirect3DTexture9 *tex;
651 IDirect3DCubeTexture9 *cubetex;
654 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
658 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
659 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
661 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, 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*) tex, 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 IDirect3DTexture9_Release(tex);
672 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
673 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
675 /* Test different pools */
676 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
680 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
681 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
682 IDirect3DTexture9_Release(tex);
685 skip("Failed to create texture\n");
687 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
691 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
692 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
693 IDirect3DTexture9_Release(tex);
696 skip("Failed to create texture\n");
698 /* Cube texture test */
699 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
703 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
704 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
706 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
707 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
709 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
710 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
713 skip("Failed to create texture\n");
715 IDirect3DCubeTexture9_Release(cubetex);
718 static BOOL color_match(const DWORD *value, const DWORD *expected)
722 for (i = 0; i < 4; i++)
724 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
725 if (diff > 1) return FALSE;
730 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
731 const D3DXVECTOR2 *texelsize, void *data)
733 value->x = texcoord->x;
734 value->y = texcoord->y;
735 value->z = texelsize->x;
739 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
741 IDirect3DTexture9 *tex;
743 D3DLOCKED_RECT lock_rect;
746 DWORD value, expected, size, pitch;
749 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
750 D3DPOOL_MANAGED, &tex, NULL);
754 hr = D3DXFillTexture(tex, fillfunc, NULL);
755 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
757 for (m = 0; m < 3; m++)
759 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
760 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
763 pitch = lock_rect.Pitch / sizeof(DWORD);
764 for (y = 0; y < size; y++)
766 for (x = 0; x < size; x++)
768 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
769 v[0] = (value >> 24) & 0xff;
770 v[1] = (value >> 16) & 0xff;
771 v[2] = (value >> 8) & 0xff;
775 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
776 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
777 e[3] = 255.0f / size + 0.5f;
778 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
780 ok(color_match(v, e),
781 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
782 x, y, value, expected);
785 IDirect3DTexture9_UnlockRect(tex, m);
791 skip("Failed to create texture\n");
793 IDirect3DTexture9_Release(tex);
795 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
796 D3DPOOL_MANAGED, &tex, NULL);
800 hr = D3DXFillTexture(tex, fillfunc, NULL);
801 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
803 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
804 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
807 pitch = lock_rect.Pitch / sizeof(WORD);
808 for (y = 0; y < 4; y++)
810 for (x = 0; x < 4; x++)
812 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
814 v[1] = value >> 10 & 0x1f;
815 v[2] = value >> 5 & 0x1f;
819 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
820 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
822 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
824 ok(color_match(v, e),
825 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
826 x, y, value, expected);
829 IDirect3DTexture9_UnlockRect(tex, 0);
833 skip("Failed to create texture\n");
835 IDirect3DTexture9_Release(tex);
838 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
839 const D3DXVECTOR3 *texelsize, void *data)
841 value->x = (texcoord->x + 1.0f) / 2.0f;
842 value->y = (texcoord->y + 1.0f) / 2.0f;
843 value->z = (texcoord->z + 1.0f) / 2.0f;
844 value->w = texelsize->x;
857 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
864 return size - x - 0.5f;
868 return size - y - 0.5f;
874 trace("Unexpected coordinate value\n");
879 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
881 IDirect3DCubeTexture9 *tex;
883 D3DLOCKED_RECT lock_rect;
886 DWORD value, expected, size, pitch;
887 enum cube_coord coordmap[6][3] =
889 {ONE, YCOORDINV, XCOORDINV},
890 {ZERO, YCOORDINV, XCOORD},
891 {XCOORD, ONE, YCOORD},
892 {XCOORD, ZERO, YCOORDINV},
893 {XCOORD, YCOORDINV, ONE},
894 {XCOORDINV, YCOORDINV, ZERO}
898 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
899 D3DPOOL_MANAGED, &tex, NULL);
903 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
904 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
906 for (m = 0; m < 3; m++)
908 for (f = 0; f < 6; f++)
910 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
911 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
914 pitch = lock_rect.Pitch / sizeof(DWORD);
915 for (y = 0; y < size; y++)
917 for (x = 0; x < size; x++)
919 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
920 v[0] = (value >> 24) & 0xff;
921 v[1] = (value >> 16) & 0xff;
922 v[2] = (value >> 8) & 0xff;
925 e[0] = (f == 0) || (f == 1) ?
926 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
927 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
928 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
929 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
930 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
932 ok(color_match(v, e),
933 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
934 f, x, y, value, expected);
937 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
944 skip("Failed to create texture\n");
946 IDirect3DCubeTexture9_Release(tex);
948 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
949 D3DPOOL_MANAGED, &tex, NULL);
953 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
954 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
955 for (f = 0; f < 6; f++)
957 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
958 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
961 pitch = lock_rect.Pitch / sizeof(WORD);
962 for (y = 0; y < 4; y++)
964 for (x = 0; x < 4; x++)
966 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
968 v[1] = value >> 10 & 0x1f;
969 v[2] = value >> 5 & 0x1f;
972 e[0] = (f == 0) || (f == 1) ?
973 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
974 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
975 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
976 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
977 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
979 ok(color_match(v, e),
980 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
981 f, x, y, value, expected);
984 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
989 skip("Failed to create texture\n");
991 IDirect3DCubeTexture9_Release(tex);
994 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
995 const D3DXVECTOR3 *texelsize, void *data)
997 value->x = texcoord->x;
998 value->y = texcoord->y;
999 value->z = texcoord->z;
1000 value->w = texelsize->x;
1003 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1005 IDirect3DVolumeTexture9 *tex;
1007 D3DLOCKED_BOX lock_box;
1010 DWORD value, expected, size, row_pitch, slice_pitch;
1013 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1014 D3DPOOL_MANAGED, &tex, NULL);
1018 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1019 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1021 for (m = 0; m < 3; m++)
1023 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1024 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1027 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1028 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1029 for (z = 0; z < size; z++)
1031 for (y = 0; y < size; y++)
1033 for (x = 0; x < size; x++)
1035 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1036 v[0] = (value >> 24) & 0xff;
1037 v[1] = (value >> 16) & 0xff;
1038 v[2] = (value >> 8) & 0xff;
1039 v[3] = value & 0xff;
1041 e[0] = 255.0f / size + 0.5f;
1042 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1043 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1044 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1045 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1047 ok(color_match(v, e),
1048 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1049 x, y, z, value, expected);
1053 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1059 skip("Failed to create texture\n");
1061 IDirect3DVolumeTexture9_Release(tex);
1063 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1064 D3DPOOL_MANAGED, &tex, NULL);
1068 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1069 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1070 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1071 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1074 row_pitch = lock_box.RowPitch / sizeof(WORD);
1075 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1076 for (z = 0; z < 4; z++)
1078 for (y = 0; y < 4; y++)
1080 for (x = 0; x < 4; x++)
1082 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1084 v[1] = value >> 10 & 0x1f;
1085 v[2] = value >> 5 & 0x1f;
1086 v[3] = value & 0x1f;
1089 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1090 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1091 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1092 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1094 ok(color_match(v, e),
1095 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1096 x, y, z, value, expected);
1100 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1104 skip("Failed to create texture\n");
1106 IDirect3DVolumeTexture9_Release(tex);
1109 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1114 IDirect3DCubeTexture9 *cube_texture;
1115 D3DSURFACE_DESC surface_desc;
1118 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1119 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1121 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1122 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1124 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1125 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1127 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1128 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1130 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1133 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1134 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1136 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1137 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1138 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1139 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1141 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 3, &surface_desc);
1142 ok(hr == D3DERR_INVALIDCALL, "GetLevelDesc returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1144 ref = IDirect3DCubeTexture9_Release(cube_texture);
1145 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1146 } else skip("Couldn't create cube texture\n");
1150 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1155 IDirect3DVolumeTexture9 *volume_texture;
1156 D3DVOLUME_DESC volume_desc;
1159 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1160 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1162 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1163 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1165 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1166 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1168 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1169 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1171 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1174 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1175 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1177 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1178 ok(hr == D3D_OK, "GetLevelDesc returend %#x, expected %#x\n", hr, D3D_OK);
1179 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1180 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1181 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1183 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1184 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1185 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1186 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1187 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1189 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1190 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1199 IDirect3DDevice9 *device;
1200 D3DPRESENT_PARAMETERS d3dpp;
1203 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1205 skip("Couldn't create application window\n");
1208 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1210 skip("Couldn't create IDirect3D9 object\n");
1215 ZeroMemory(&d3dpp, sizeof(d3dpp));
1216 d3dpp.Windowed = TRUE;
1217 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1218 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1220 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1221 IDirect3D9_Release(d3d);
1226 test_D3DXCheckTextureRequirements(device);
1227 test_D3DXCheckCubeTextureRequirements(device);
1228 test_D3DXCheckVolumeTextureRequirements(device);
1229 test_D3DXCreateTexture(device);
1230 test_D3DXFilterTexture(device);
1231 test_D3DXFillTexture(device);
1232 test_D3DXFillCubeTexture(device);
1233 test_D3DXFillVolumeTexture(device);
1234 test_D3DXCreateCubeTextureFromFileInMemory(device);
1235 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1237 IDirect3DDevice9_Release(device);
1238 IDirect3D9_Release(d3d);