hlink/tests: Don't check results in disabled tests (LLVM/Clang).
[wine] / dlls / d3dx9_36 / tests / texture.c
1 /*
2  * Tests for the D3DX9 texture functions
3  *
4  * Copyright 2009 Tony Wasserka
5  * Copyright 2010 Owen Rudge for CodeWeavers
6  * Copyright 2010 Matteo Bruni for CodeWeavers
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #define COBJMACROS
24 #include "wine/test.h"
25 #include "d3dx9tex.h"
26 #include "resources.h"
27
28 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
29 {
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;
37
38     IDirect3DDevice9_GetDeviceCaps(device, &caps);
39
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);
43
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);
46
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);
49
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);
56
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);
61
62     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
63         skip("Hardware only supports pow2 textures\n");
64     else
65     {
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);
70
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);
76     }
77
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);
83
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);
89
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);
94
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);
99
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);
104
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);
111
112     if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
113     {
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);
119
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);
125     }
126     else
127         skip("Skipping some tests, npot2 textures unsupported\n");
128
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);
133
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);
138
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");
150
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);
154
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);
159
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);
164
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);
169
170     IDirect3DDevice9_GetDirect3D(device, &d3d);
171     IDirect3DDevice9_GetCreationParameters(device, &params);
172     IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
173
174     if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
175                                                mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
176         expected = D3DFMT_R3G3B2;
177     else
178     {
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;
184     }
185
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);
190
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;
196
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);
201
202     IDirect3D9_Release(d3d);
203 }
204
205 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
206 {
207     UINT size, mipmaps, expected;
208     D3DFORMAT format;
209     D3DCAPS9 caps;
210     HRESULT hr;
211
212     IDirect3DDevice9_GetDeviceCaps(device, &caps);
213
214     if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
215     {
216         skip("No cube textures support\n");
217         return;
218     }
219
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);
223
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);
226
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);
229
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);
235
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);
242
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);
249
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);
256
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);
261
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");
273
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);
277
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);
282
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);
287
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);
292 }
293
294 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
295 {
296     UINT width, height, depth, mipmaps, expected;
297     D3DFORMAT format;
298     D3DCAPS9 caps;
299     HRESULT hr;
300
301     IDirect3DDevice9_GetDeviceCaps(device, &caps);
302
303     if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
304     {
305         skip("No volume textures support\n");
306         return;
307     }
308
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);
312
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);
315
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);
318
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);
326
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);
331
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);
338
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);
345
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);
350
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);
355
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);
359
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);
364
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);
369
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);
374
375     /* mipmaps */
376     if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
377     {
378         skip("No volume textures mipmapping support\n");
379         return;
380     }
381
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);
387
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);
396
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);
401 }
402
403 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
404 {
405     IDirect3DTexture9 *texture;
406     D3DSURFACE_DESC desc;
407     D3DCAPS9 caps;
408     UINT mipmaps;
409     HRESULT hr;
410
411     IDirect3DDevice9_GetDeviceCaps(device, &caps);
412
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);
415
416     /* width and height tests */
417
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);
420
421     if (texture)
422     {
423         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
424
425         ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
426         ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
427
428         IDirect3DTexture9_Release(texture);
429     }
430
431
432     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
433     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
434
435     if (texture)
436     {
437         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
438
439         ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
440         ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
441
442         IDirect3DTexture9_Release(texture);
443     }
444
445
446     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
447         skip("Hardware only supports pow2 textures\n");
448     else
449     {
450         hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
451         ok((hr == D3D_OK) ||
452            /* may not work with conditional NPOT */
453            ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
454            "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
455
456         if (texture)
457         {
458             hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
459
460             /* Conditional NPOT may create a texture with different dimensions, so allow those
461                situations instead of returning a fail */
462
463             ok(desc.Width == 63 ||
464                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
465                "Returned width %d, expected %d\n", desc.Width, 63);
466
467             ok(desc.Height == 63 ||
468                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
469                "Returned height %d, expected %d\n", desc.Height, 63);
470
471             IDirect3DTexture9_Release(texture);
472         }
473     }
474
475     /* mipmaps */
476
477     hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
478     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
479
480     if (texture)
481     {
482         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
483         ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
484
485         IDirect3DTexture9_Release(texture);
486     }
487
488
489     hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
490     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
491
492     if (texture)
493     {
494         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
495         ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
496
497         IDirect3DTexture9_Release(texture);
498     }
499
500
501     hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
502     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
503
504     if (texture)
505     {
506         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
507         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
508
509         IDirect3DTexture9_Release(texture);
510     }
511
512
513     hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
514     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
515
516     if (texture)
517     {
518         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
519         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
520
521         IDirect3DTexture9_Release(texture);
522     }
523
524     /* usage */
525
526     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
527     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
528     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
529     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
530     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
531     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
532     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
533     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
534     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
535     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
536
537     /* format */
538
539     hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
540     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
541
542     if (texture)
543     {
544         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
545         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
546
547         IDirect3DTexture9_Release(texture);
548     }
549
550
551     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
552     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
553
554     if (texture)
555     {
556         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
557         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
558
559         IDirect3DTexture9_Release(texture);
560     }
561
562     /* D3DXCreateTextureFromResource */
563     todo_wine {
564         hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
565         ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
566         if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
567     }
568     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
569     ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
570     if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
571
572     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
573     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
574
575     hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
576     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
577
578     hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
579     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
580
581     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
582     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
583
584
585     /* D3DXCreateTextureFromResourceEx */
586     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
587     ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
588     if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
589
590     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
591     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
592
593     hr = D3DXCreateTextureFromResourceExA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
594     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
595
596     hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
597     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
598
599     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, NULL);
600     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
601 }
602
603 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
604 {
605     IDirect3DTexture9 *tex;
606     IDirect3DCubeTexture9 *cubetex;
607     HRESULT hr;
608
609     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
610
611     if (SUCCEEDED(hr))
612     {
613         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
614         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
615
616         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
617         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
618
619         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
620         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
621     }
622     else
623         skip("Failed to create texture\n");
624
625     IDirect3DTexture9_Release(tex);
626
627     hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
628     ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
629
630     /* Test different pools */
631     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
632
633     if (SUCCEEDED(hr))
634     {
635         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
636         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
637         IDirect3DTexture9_Release(tex);
638     }
639     else
640         skip("Failed to create texture\n");
641
642     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
643
644     if (SUCCEEDED(hr))
645     {
646         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
647         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
648         IDirect3DTexture9_Release(tex);
649     }
650     else
651         skip("Failed to create texture\n");
652
653     /* Cube texture test */
654     hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
655
656     if (SUCCEEDED(hr))
657     {
658         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
659         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
660
661         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
662         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
663
664         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
665         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
666     }
667     else
668         skip("Failed to create texture\n");
669
670     IDirect3DCubeTexture9_Release(cubetex);
671 }
672
673 static BOOL color_match(const DWORD *value, const DWORD *expected)
674 {
675     int i;
676
677     for (i = 0; i < 4; i++)
678     {
679         DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
680         if (diff > 1) return FALSE;
681     }
682     return TRUE;
683 }
684
685 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
686                             const D3DXVECTOR2 *texelsize, void *data)
687 {
688     value->x = texcoord->x;
689     value->y = texcoord->y;
690     value->z = texelsize->x;
691     value->w = 1.0f;
692 }
693
694 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
695 {
696     IDirect3DTexture9 *tex;
697     HRESULT hr;
698     D3DLOCKED_RECT lock_rect;
699     DWORD x, y, m;
700     DWORD v[4], e[4];
701     DWORD value, expected, size, pitch;
702
703     size = 4;
704     hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
705                                         D3DPOOL_MANAGED, &tex, NULL);
706
707     if (SUCCEEDED(hr))
708     {
709         hr = D3DXFillTexture(tex, fillfunc, NULL);
710         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
711
712         for (m = 0; m < 3; m++)
713         {
714             hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
715             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
716             if (SUCCEEDED(hr))
717             {
718                 pitch = lock_rect.Pitch / sizeof(DWORD);
719                 for (y = 0; y < size; y++)
720                 {
721                     for (x = 0; x < size; x++)
722                     {
723                         value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
724                         v[0] = (value >> 24) & 0xff;
725                         v[1] = (value >> 16) & 0xff;
726                         v[2] = (value >> 8) & 0xff;
727                         v[3] = value & 0xff;
728
729                         e[0] = 0xff;
730                         e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
731                         e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
732                         e[3] = 255.0f / size + 0.5f;
733                         expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
734
735                         ok(color_match(v, e),
736                            "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
737                            x, y, value, expected);
738                     }
739                 }
740                 IDirect3DTexture9_UnlockRect(tex, m);
741             }
742             size >>= 1;
743         }
744     }
745     else
746         skip("Failed to create texture\n");
747
748     IDirect3DTexture9_Release(tex);
749
750     hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
751                                         D3DPOOL_MANAGED, &tex, NULL);
752
753     if (SUCCEEDED(hr))
754     {
755         hr = D3DXFillTexture(tex, fillfunc, NULL);
756         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
757
758         hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
759         ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
760         if (SUCCEEDED(hr))
761         {
762             pitch = lock_rect.Pitch / sizeof(WORD);
763             for (y = 0; y < 4; y++)
764             {
765                 for (x = 0; x < 4; x++)
766                 {
767                     value = ((WORD *)lock_rect.pBits)[y * pitch + x];
768                     v[0] = value >> 15;
769                     v[1] = value >> 10 & 0x1f;
770                     v[2] = value >> 5 & 0x1f;
771                     v[3] = value & 0x1f;
772
773                     e[0] = 1;
774                     e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
775                     e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
776                     e[3] = 8;
777                     expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
778
779                     ok(color_match(v, e),
780                        "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
781                        x, y, value, expected);
782                 }
783             }
784             IDirect3DTexture9_UnlockRect(tex, 0);
785         }
786     }
787     else
788         skip("Failed to create texture\n");
789
790     IDirect3DTexture9_Release(tex);
791 }
792
793 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
794                                  const D3DXVECTOR3 *texelsize, void *data)
795 {
796     value->x = (texcoord->x + 1.0f) / 2.0f;
797     value->y = (texcoord->y + 1.0f) / 2.0f;
798     value->z = (texcoord->z + 1.0f) / 2.0f;
799     value->w = texelsize->x;
800 }
801
802 enum cube_coord
803 {
804     XCOORD = 0,
805     XCOORDINV = 1,
806     YCOORD = 2,
807     YCOORDINV = 3,
808     ZERO = 4,
809     ONE = 5
810 };
811
812 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
813 {
814     switch (coord)
815     {
816         case XCOORD:
817             return x + 0.5f;
818         case XCOORDINV:
819             return size - x - 0.5f;
820         case YCOORD:
821             return y + 0.5f;
822         case YCOORDINV:
823             return size - y - 0.5f;
824         case ZERO:
825             return 0.0f;
826         case ONE:
827             return size;
828         default:
829            trace("Unexpected coordinate value\n");
830            return 0.0f;
831     }
832 }
833
834 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
835 {
836     IDirect3DCubeTexture9 *tex;
837     HRESULT hr;
838     D3DLOCKED_RECT lock_rect;
839     DWORD x, y, f, m;
840     DWORD v[4], e[4];
841     DWORD value, expected, size, pitch;
842     enum cube_coord coordmap[6][3] =
843         {
844             {ONE, YCOORDINV, XCOORDINV},
845             {ZERO, YCOORDINV, XCOORD},
846             {XCOORD, ONE, YCOORD},
847             {XCOORD, ZERO, YCOORDINV},
848             {XCOORD, YCOORDINV, ONE},
849             {XCOORDINV, YCOORDINV, ZERO}
850         };
851
852     size = 4;
853     hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
854                                             D3DPOOL_MANAGED, &tex, NULL);
855
856     if (SUCCEEDED(hr))
857     {
858         hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
859         ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
860
861         for (m = 0; m < 3; m++)
862         {
863             for (f = 0; f < 6; f++)
864             {
865                 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
866                 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
867                 if (SUCCEEDED(hr))
868                 {
869                     pitch = lock_rect.Pitch / sizeof(DWORD);
870                     for (y = 0; y < size; y++)
871                     {
872                         for (x = 0; x < size; x++)
873                         {
874                             value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
875                             v[0] = (value >> 24) & 0xff;
876                             v[1] = (value >> 16) & 0xff;
877                             v[2] = (value >> 8) & 0xff;
878                             v[3] = value & 0xff;
879
880                             e[0] = (f == 0) || (f == 1) ?
881                                 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
882                             e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
883                             e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
884                             e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
885                             expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
886
887                             ok(color_match(v, e),
888                                "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
889                                f, x, y, value, expected);
890                         }
891                     }
892                     IDirect3DCubeTexture9_UnlockRect(tex, f, m);
893                 }
894             }
895             size >>= 1;
896         }
897     }
898     else
899         skip("Failed to create texture\n");
900
901     IDirect3DCubeTexture9_Release(tex);
902
903     hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
904                                             D3DPOOL_MANAGED, &tex, NULL);
905
906     if (SUCCEEDED(hr))
907     {
908         hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
909         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
910         for (f = 0; f < 6; f++)
911         {
912             hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
913             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
914             if (SUCCEEDED(hr))
915             {
916                 pitch = lock_rect.Pitch / sizeof(WORD);
917                 for (y = 0; y < 4; y++)
918                 {
919                     for (x = 0; x < 4; x++)
920                     {
921                         value = ((WORD *)lock_rect.pBits)[y * pitch + x];
922                         v[0] = value >> 15;
923                         v[1] = value >> 10 & 0x1f;
924                         v[2] = value >> 5 & 0x1f;
925                         v[3] = value & 0x1f;
926
927                         e[0] = (f == 0) || (f == 1) ?
928                             0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
929                         e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
930                         e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
931                         e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
932                         expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
933
934                         ok(color_match(v, e),
935                            "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
936                            f, x, y, value, expected);
937                     }
938                 }
939                 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
940             }
941         }
942     }
943     else
944         skip("Failed to create texture\n");
945
946     IDirect3DCubeTexture9_Release(tex);
947 }
948
949 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
950                                    const D3DXVECTOR3 *texelsize, void *data)
951 {
952     value->x = texcoord->x;
953     value->y = texcoord->y;
954     value->z = texcoord->z;
955     value->w = texelsize->x;
956 }
957
958 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
959 {
960     IDirect3DVolumeTexture9 *tex;
961     HRESULT hr;
962     D3DLOCKED_BOX lock_box;
963     DWORD x, y, z, m;
964     DWORD v[4], e[4];
965     DWORD value, expected, size, row_pitch, slice_pitch;
966
967     size = 4;
968     hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
969                                               D3DPOOL_MANAGED, &tex, NULL);
970
971     if (SUCCEEDED(hr))
972     {
973         hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
974         ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
975
976         for (m = 0; m < 3; m++)
977         {
978             hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
979             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
980             if (SUCCEEDED(hr))
981             {
982                 row_pitch = lock_box.RowPitch / sizeof(DWORD);
983                 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
984                 for (z = 0; z < size; z++)
985                 {
986                     for (y = 0; y < size; y++)
987                     {
988                         for (x = 0; x < size; x++)
989                         {
990                             value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
991                             v[0] = (value >> 24) & 0xff;
992                             v[1] = (value >> 16) & 0xff;
993                             v[2] = (value >> 8) & 0xff;
994                             v[3] = value & 0xff;
995
996                             e[0] = 255.0f / size + 0.5f;
997                             e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
998                             e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
999                             e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1000                             expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1001
1002                             ok(color_match(v, e),
1003                                "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1004                                x, y, z, value, expected);
1005                         }
1006                     }
1007                 }
1008                 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1009             }
1010             size >>= 1;
1011         }
1012     }
1013     else
1014         skip("Failed to create texture\n");
1015
1016     IDirect3DVolumeTexture9_Release(tex);
1017
1018     hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1019                                               D3DPOOL_MANAGED, &tex, NULL);
1020
1021     if (SUCCEEDED(hr))
1022     {
1023         hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1024         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1025         hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1026         ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1027         if (SUCCEEDED(hr))
1028         {
1029             row_pitch = lock_box.RowPitch / sizeof(WORD);
1030             slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1031             for (z = 0; z < 4; z++)
1032             {
1033                 for (y = 0; y < 4; y++)
1034                 {
1035                     for (x = 0; x < 4; x++)
1036                     {
1037                         value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1038                         v[0] = value >> 15;
1039                         v[1] = value >> 10 & 0x1f;
1040                         v[2] = value >> 5 & 0x1f;
1041                         v[3] = value & 0x1f;
1042
1043                         e[0] = 1;
1044                         e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1045                         e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1046                         e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1047                         expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1048
1049                         ok(color_match(v, e),
1050                            "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1051                            x, y, z, value, expected);
1052                     }
1053                 }
1054             }
1055             IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1056         }
1057     }
1058     else
1059         skip("Failed to create texture\n");
1060
1061     IDirect3DVolumeTexture9_Release(tex);
1062 }
1063
1064 START_TEST(texture)
1065 {
1066     HWND wnd;
1067     IDirect3D9 *d3d;
1068     IDirect3DDevice9 *device;
1069     D3DPRESENT_PARAMETERS d3dpp;
1070     HRESULT hr;
1071
1072     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1073     if (!wnd) {
1074         skip("Couldn't create application window\n");
1075         return;
1076     }
1077     d3d = Direct3DCreate9(D3D_SDK_VERSION);
1078     if (!d3d) {
1079         skip("Couldn't create IDirect3D9 object\n");
1080         DestroyWindow(wnd);
1081         return;
1082     }
1083
1084     ZeroMemory(&d3dpp, sizeof(d3dpp));
1085     d3dpp.Windowed   = TRUE;
1086     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1087     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1088     if (FAILED(hr)) {
1089         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1090         IDirect3D9_Release(d3d);
1091         DestroyWindow(wnd);
1092         return;
1093     }
1094
1095     test_D3DXCheckTextureRequirements(device);
1096     test_D3DXCheckCubeTextureRequirements(device);
1097     test_D3DXCheckVolumeTextureRequirements(device);
1098     test_D3DXCreateTexture(device);
1099     test_D3DXFilterTexture(device);
1100     test_D3DXFillTexture(device);
1101     test_D3DXFillCubeTexture(device);
1102     test_D3DXFillVolumeTexture(device);
1103
1104     IDirect3DDevice9_Release(device);
1105     IDirect3D9_Release(d3d);
1106     DestroyWindow(wnd);
1107 }