d3dx9/tests: Add effect parameter value GetInt() test.
[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     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
104         ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
105     else
106         ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
107
108     /* mipmaps */
109     width = 64; height = 63;
110     mipmaps = 9;
111     hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
112     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
113     ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
114
115     if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
116     {
117         width = 284; height = 137;
118         mipmaps = 20;
119         hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
120         ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
121         ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
122
123         width = height = 63;
124         mipmaps = 9;
125         hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
126         ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127         ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
128     }
129     else
130         skip("Skipping some tests, npot2 textures unsupported\n");
131
132     mipmaps = 20;
133     hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
134     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
135     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
136
137     mipmaps = 0;
138     hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
139     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
140     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
141
142     /* usage */
143     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
144     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
145     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
146     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
147     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
148     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
149     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
150     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
151     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
152     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
153
154     /* format */
155     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
156     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
157
158     format = D3DFMT_UNKNOWN;
159     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
160     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
161     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
162
163     format = D3DX_DEFAULT;
164     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
165     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
166     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
167
168     format = D3DFMT_R8G8B8;
169     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
170     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
171     ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
172
173     IDirect3DDevice9_GetDirect3D(device, &d3d);
174     IDirect3DDevice9_GetCreationParameters(device, &params);
175     IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
176
177     if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
178                                                mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
179         expected = D3DFMT_R3G3B2;
180     else
181     {
182         if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
183                                                    mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
184             expected = D3DFMT_X4R4G4B4;
185         else
186             expected = D3DFMT_X1R5G5B5;
187     }
188
189     format = D3DFMT_R3G3B2;
190     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
191     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
192     ok(format == expected, "Returned format %u, expected %u\n", format, expected);
193
194     if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
195                                               mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
196         expected = D3DFMT_A8R3G3B2;
197     else
198         expected = D3DFMT_A8R8G8B8;
199
200     format = D3DFMT_A8R3G3B2;
201     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
202     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
203     ok(format == expected, "Returned format %u, expected %u\n", format, expected);
204
205     IDirect3D9_Release(d3d);
206 }
207
208 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
209 {
210     UINT size, mipmaps, expected;
211     D3DFORMAT format;
212     D3DCAPS9 caps;
213     HRESULT hr;
214
215     IDirect3DDevice9_GetDeviceCaps(device, &caps);
216
217     if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
218     {
219         skip("No cube textures support\n");
220         return;
221     }
222
223     /* general tests */
224     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
225     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
226
227     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
228     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
229
230     hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
231     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
232
233     /* size */
234     size = D3DX_DEFAULT;
235     hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
236     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
237     ok(size == 256, "Returned size %d, expected %d\n", size, 256);
238
239     /* mipmaps */
240     size = 64;
241     mipmaps = 9;
242     hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
243     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
244     ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
245
246     size = 284;
247     mipmaps = 20;
248     expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
249     hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
250     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
251     ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
252
253     size = 63;
254     mipmaps = 9;
255     expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
256     hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
257     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
258     ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
259
260     mipmaps = 0;
261     hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
262     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
263     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
264
265     /* usage */
266     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
267     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
268     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
269     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
270     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
271     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
272     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
273     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
274     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
275     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
276
277     /* format */
278     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
279     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
280
281     format = D3DFMT_UNKNOWN;
282     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
283     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
284     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
285
286     format = D3DX_DEFAULT;
287     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
288     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
289     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
290
291     format = D3DFMT_R8G8B8;
292     hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
293     ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
294     ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
295 }
296
297 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
298 {
299     UINT width, height, depth, mipmaps, expected;
300     D3DFORMAT format;
301     D3DCAPS9 caps;
302     HRESULT hr;
303
304     IDirect3DDevice9_GetDeviceCaps(device, &caps);
305
306     if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
307     {
308         skip("No volume textures support\n");
309         return;
310     }
311
312     /* general tests */
313     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
314     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
315
316     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
317     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
318
319     hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
320     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
321
322     /* width, height, depth */
323     width = height = depth = D3DX_DEFAULT;
324     hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
325     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
326     ok(width == 256, "Returned width %d, expected %d\n", width, 256);
327     ok(height == 256, "Returned height %d, expected %d\n", height, 256);
328     ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
329
330     width = D3DX_DEFAULT;
331     hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
332     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
333     ok(width == 256, "Returned width %d, expected %d\n", width, 256);
334
335     width = D3DX_DEFAULT; height = 0; depth = 0;
336     hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
337     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
338     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
339     ok(height == 1, "Returned height %d, expected %d\n", height, 1);
340     ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
341
342     width = 0; height = 0; depth = 0;
343     hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
344     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
345     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
346     ok(height == 1, "Returned height %d, expected %d\n", height, 1);
347     ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
348
349     width = 0;
350     hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
351     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
352     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
353
354     width = 0xFFFFFFFE;
355     hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
356     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
357     ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
358
359     /* format */
360     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
361     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
362
363     format = D3DFMT_UNKNOWN;
364     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
365     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
366     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
367
368     format = D3DX_DEFAULT;
369     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
370     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
371     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
372
373     format = D3DFMT_R8G8B8;
374     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
375     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
376     ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
377
378     /* mipmaps */
379     if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
380     {
381         skip("No volume textures mipmapping support\n");
382         return;
383     }
384
385     width = height = depth = 64;
386     mipmaps = 9;
387     hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
388     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
389     ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
390
391     width = 284;
392     height = 143;
393     depth = 55;
394     mipmaps = 20;
395     expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
396     hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
397     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
398     ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
399
400     mipmaps = 0;
401     hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
402     ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
403     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
404 }
405
406 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
407 {
408     IDirect3DTexture9 *texture;
409     D3DSURFACE_DESC desc;
410     D3DCAPS9 caps;
411     UINT mipmaps;
412     HRESULT hr;
413
414     IDirect3DDevice9_GetDeviceCaps(device, &caps);
415
416     hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
417     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
418
419     /* width and height tests */
420
421     hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
422     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
423
424     if (texture)
425     {
426         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
427         ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
428         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
429
430         ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
431         ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
432
433         IDirect3DTexture9_Release(texture);
434     }
435
436
437     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
438     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
439
440     if (texture)
441     {
442         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
443         ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
444         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
445
446         ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
447         ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
448
449         IDirect3DTexture9_Release(texture);
450     }
451
452
453     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
454         skip("Hardware only supports pow2 textures\n");
455     else
456     {
457         hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
458         ok((hr == D3D_OK) ||
459            /* may not work with conditional NPOT */
460            ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
461            "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
462
463         if (texture)
464         {
465             hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
466             ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
467             ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
468
469             /* Conditional NPOT may create a texture with different dimensions, so allow those
470                situations instead of returning a fail */
471
472             ok(desc.Width == 63 ||
473                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
474                "Returned width %d, expected %d\n", desc.Width, 63);
475
476             ok(desc.Height == 63 ||
477                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
478                "Returned height %d, expected %d\n", desc.Height, 63);
479
480             IDirect3DTexture9_Release(texture);
481         }
482     }
483
484     /* mipmaps */
485
486     hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
487     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
488
489     if (texture)
490     {
491         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
492         ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
493
494         IDirect3DTexture9_Release(texture);
495     }
496
497
498     hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
499     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
500
501     if (texture)
502     {
503         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
504         ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
505
506         IDirect3DTexture9_Release(texture);
507     }
508
509
510     hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
511     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
512
513     if (texture)
514     {
515         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
516         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
517
518         IDirect3DTexture9_Release(texture);
519     }
520
521
522     hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
523     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
524
525     if (texture)
526     {
527         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
528         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
529
530         IDirect3DTexture9_Release(texture);
531     }
532
533     /* usage */
534
535     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
536     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
537     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
538     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
539     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
540     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
541     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
542     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
543     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
544     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
545
546     /* format */
547
548     hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
549     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
550
551     if (texture)
552     {
553         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
554         ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
555         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
556
557         IDirect3DTexture9_Release(texture);
558     }
559
560
561     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
562     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
563
564     if (texture)
565     {
566         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
567         ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
568         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
569
570         IDirect3DTexture9_Release(texture);
571     }
572
573     /* D3DXCreateTextureFromResource */
574     todo_wine {
575         hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
576         ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
577         if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
578     }
579     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
580     ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
581     if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
582
583     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
584     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
585
586     hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
587     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
588
589     hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
590     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
591
592     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
593     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
594
595
596     /* D3DXCreateTextureFromResourceEx */
597     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
598     ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
599     if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
600
601     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
602     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
603
604     hr = D3DXCreateTextureFromResourceExA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
605     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
606
607     hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
608     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
609
610     hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, NULL);
611     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
612 }
613
614 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
615 {
616     IDirect3DTexture9 *tex;
617     IDirect3DCubeTexture9 *cubetex;
618     HRESULT hr;
619
620     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
621
622     if (SUCCEEDED(hr))
623     {
624         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
625         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
626
627         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
628         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
629
630         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
631         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
632     }
633     else
634         skip("Failed to create texture\n");
635
636     IDirect3DTexture9_Release(tex);
637
638     hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
639     ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
640
641     /* Test different pools */
642     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &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     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
654
655     if (SUCCEEDED(hr))
656     {
657         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
658         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
659         IDirect3DTexture9_Release(tex);
660     }
661     else
662         skip("Failed to create texture\n");
663
664     /* Cube texture test */
665     hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
666
667     if (SUCCEEDED(hr))
668     {
669         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
670         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
671
672         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
673         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
674
675         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
676         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
677     }
678     else
679         skip("Failed to create texture\n");
680
681     IDirect3DCubeTexture9_Release(cubetex);
682 }
683
684 static BOOL color_match(const DWORD *value, const DWORD *expected)
685 {
686     int i;
687
688     for (i = 0; i < 4; i++)
689     {
690         DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
691         if (diff > 1) return FALSE;
692     }
693     return TRUE;
694 }
695
696 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
697                             const D3DXVECTOR2 *texelsize, void *data)
698 {
699     value->x = texcoord->x;
700     value->y = texcoord->y;
701     value->z = texelsize->x;
702     value->w = 1.0f;
703 }
704
705 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
706 {
707     IDirect3DTexture9 *tex;
708     HRESULT hr;
709     D3DLOCKED_RECT lock_rect;
710     DWORD x, y, m;
711     DWORD v[4], e[4];
712     DWORD value, expected, size, pitch;
713
714     size = 4;
715     hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
716                                         D3DPOOL_MANAGED, &tex, NULL);
717
718     if (SUCCEEDED(hr))
719     {
720         hr = D3DXFillTexture(tex, fillfunc, NULL);
721         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
722
723         for (m = 0; m < 3; m++)
724         {
725             hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
726             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
727             if (SUCCEEDED(hr))
728             {
729                 pitch = lock_rect.Pitch / sizeof(DWORD);
730                 for (y = 0; y < size; y++)
731                 {
732                     for (x = 0; x < size; x++)
733                     {
734                         value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
735                         v[0] = (value >> 24) & 0xff;
736                         v[1] = (value >> 16) & 0xff;
737                         v[2] = (value >> 8) & 0xff;
738                         v[3] = value & 0xff;
739
740                         e[0] = 0xff;
741                         e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
742                         e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
743                         e[3] = 255.0f / size + 0.5f;
744                         expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
745
746                         ok(color_match(v, e),
747                            "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
748                            x, y, value, expected);
749                     }
750                 }
751                 IDirect3DTexture9_UnlockRect(tex, m);
752             }
753             size >>= 1;
754         }
755     }
756     else
757         skip("Failed to create texture\n");
758
759     IDirect3DTexture9_Release(tex);
760
761     hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
762                                         D3DPOOL_MANAGED, &tex, NULL);
763
764     if (SUCCEEDED(hr))
765     {
766         hr = D3DXFillTexture(tex, fillfunc, NULL);
767         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
768
769         hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
770         ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
771         if (SUCCEEDED(hr))
772         {
773             pitch = lock_rect.Pitch / sizeof(WORD);
774             for (y = 0; y < 4; y++)
775             {
776                 for (x = 0; x < 4; x++)
777                 {
778                     value = ((WORD *)lock_rect.pBits)[y * pitch + x];
779                     v[0] = value >> 15;
780                     v[1] = value >> 10 & 0x1f;
781                     v[2] = value >> 5 & 0x1f;
782                     v[3] = value & 0x1f;
783
784                     e[0] = 1;
785                     e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
786                     e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
787                     e[3] = 8;
788                     expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
789
790                     ok(color_match(v, e),
791                        "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
792                        x, y, value, expected);
793                 }
794             }
795             IDirect3DTexture9_UnlockRect(tex, 0);
796         }
797     }
798     else
799         skip("Failed to create texture\n");
800
801     IDirect3DTexture9_Release(tex);
802 }
803
804 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
805                                  const D3DXVECTOR3 *texelsize, void *data)
806 {
807     value->x = (texcoord->x + 1.0f) / 2.0f;
808     value->y = (texcoord->y + 1.0f) / 2.0f;
809     value->z = (texcoord->z + 1.0f) / 2.0f;
810     value->w = texelsize->x;
811 }
812
813 enum cube_coord
814 {
815     XCOORD = 0,
816     XCOORDINV = 1,
817     YCOORD = 2,
818     YCOORDINV = 3,
819     ZERO = 4,
820     ONE = 5
821 };
822
823 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
824 {
825     switch (coord)
826     {
827         case XCOORD:
828             return x + 0.5f;
829         case XCOORDINV:
830             return size - x - 0.5f;
831         case YCOORD:
832             return y + 0.5f;
833         case YCOORDINV:
834             return size - y - 0.5f;
835         case ZERO:
836             return 0.0f;
837         case ONE:
838             return size;
839         default:
840            trace("Unexpected coordinate value\n");
841            return 0.0f;
842     }
843 }
844
845 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
846 {
847     IDirect3DCubeTexture9 *tex;
848     HRESULT hr;
849     D3DLOCKED_RECT lock_rect;
850     DWORD x, y, f, m;
851     DWORD v[4], e[4];
852     DWORD value, expected, size, pitch;
853     enum cube_coord coordmap[6][3] =
854         {
855             {ONE, YCOORDINV, XCOORDINV},
856             {ZERO, YCOORDINV, XCOORD},
857             {XCOORD, ONE, YCOORD},
858             {XCOORD, ZERO, YCOORDINV},
859             {XCOORD, YCOORDINV, ONE},
860             {XCOORDINV, YCOORDINV, ZERO}
861         };
862
863     size = 4;
864     hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
865                                             D3DPOOL_MANAGED, &tex, NULL);
866
867     if (SUCCEEDED(hr))
868     {
869         hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
870         ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
871
872         for (m = 0; m < 3; m++)
873         {
874             for (f = 0; f < 6; f++)
875             {
876                 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
877                 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
878                 if (SUCCEEDED(hr))
879                 {
880                     pitch = lock_rect.Pitch / sizeof(DWORD);
881                     for (y = 0; y < size; y++)
882                     {
883                         for (x = 0; x < size; x++)
884                         {
885                             value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
886                             v[0] = (value >> 24) & 0xff;
887                             v[1] = (value >> 16) & 0xff;
888                             v[2] = (value >> 8) & 0xff;
889                             v[3] = value & 0xff;
890
891                             e[0] = (f == 0) || (f == 1) ?
892                                 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
893                             e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
894                             e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
895                             e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
896                             expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
897
898                             ok(color_match(v, e),
899                                "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
900                                f, x, y, value, expected);
901                         }
902                     }
903                     IDirect3DCubeTexture9_UnlockRect(tex, f, m);
904                 }
905             }
906             size >>= 1;
907         }
908     }
909     else
910         skip("Failed to create texture\n");
911
912     IDirect3DCubeTexture9_Release(tex);
913
914     hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
915                                             D3DPOOL_MANAGED, &tex, NULL);
916
917     if (SUCCEEDED(hr))
918     {
919         hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
920         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
921         for (f = 0; f < 6; f++)
922         {
923             hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
924             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
925             if (SUCCEEDED(hr))
926             {
927                 pitch = lock_rect.Pitch / sizeof(WORD);
928                 for (y = 0; y < 4; y++)
929                 {
930                     for (x = 0; x < 4; x++)
931                     {
932                         value = ((WORD *)lock_rect.pBits)[y * pitch + x];
933                         v[0] = value >> 15;
934                         v[1] = value >> 10 & 0x1f;
935                         v[2] = value >> 5 & 0x1f;
936                         v[3] = value & 0x1f;
937
938                         e[0] = (f == 0) || (f == 1) ?
939                             0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
940                         e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
941                         e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
942                         e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
943                         expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
944
945                         ok(color_match(v, e),
946                            "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
947                            f, x, y, value, expected);
948                     }
949                 }
950                 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
951             }
952         }
953     }
954     else
955         skip("Failed to create texture\n");
956
957     IDirect3DCubeTexture9_Release(tex);
958 }
959
960 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
961                                    const D3DXVECTOR3 *texelsize, void *data)
962 {
963     value->x = texcoord->x;
964     value->y = texcoord->y;
965     value->z = texcoord->z;
966     value->w = texelsize->x;
967 }
968
969 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
970 {
971     IDirect3DVolumeTexture9 *tex;
972     HRESULT hr;
973     D3DLOCKED_BOX lock_box;
974     DWORD x, y, z, m;
975     DWORD v[4], e[4];
976     DWORD value, expected, size, row_pitch, slice_pitch;
977
978     size = 4;
979     hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
980                                               D3DPOOL_MANAGED, &tex, NULL);
981
982     if (SUCCEEDED(hr))
983     {
984         hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
985         ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
986
987         for (m = 0; m < 3; m++)
988         {
989             hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
990             ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
991             if (SUCCEEDED(hr))
992             {
993                 row_pitch = lock_box.RowPitch / sizeof(DWORD);
994                 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
995                 for (z = 0; z < size; z++)
996                 {
997                     for (y = 0; y < size; y++)
998                     {
999                         for (x = 0; x < size; x++)
1000                         {
1001                             value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1002                             v[0] = (value >> 24) & 0xff;
1003                             v[1] = (value >> 16) & 0xff;
1004                             v[2] = (value >> 8) & 0xff;
1005                             v[3] = value & 0xff;
1006
1007                             e[0] = 255.0f / size + 0.5f;
1008                             e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1009                             e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1010                             e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1011                             expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1012
1013                             ok(color_match(v, e),
1014                                "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1015                                x, y, z, value, expected);
1016                         }
1017                     }
1018                 }
1019                 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1020             }
1021             size >>= 1;
1022         }
1023     }
1024     else
1025         skip("Failed to create texture\n");
1026
1027     IDirect3DVolumeTexture9_Release(tex);
1028
1029     hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1030                                               D3DPOOL_MANAGED, &tex, NULL);
1031
1032     if (SUCCEEDED(hr))
1033     {
1034         hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1035         ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1036         hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1037         ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1038         if (SUCCEEDED(hr))
1039         {
1040             row_pitch = lock_box.RowPitch / sizeof(WORD);
1041             slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1042             for (z = 0; z < 4; z++)
1043             {
1044                 for (y = 0; y < 4; y++)
1045                 {
1046                     for (x = 0; x < 4; x++)
1047                     {
1048                         value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1049                         v[0] = value >> 15;
1050                         v[1] = value >> 10 & 0x1f;
1051                         v[2] = value >> 5 & 0x1f;
1052                         v[3] = value & 0x1f;
1053
1054                         e[0] = 1;
1055                         e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1056                         e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1057                         e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1058                         expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1059
1060                         ok(color_match(v, e),
1061                            "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1062                            x, y, z, value, expected);
1063                     }
1064                 }
1065             }
1066             IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1067         }
1068     }
1069     else
1070         skip("Failed to create texture\n");
1071
1072     IDirect3DVolumeTexture9_Release(tex);
1073 }
1074
1075 START_TEST(texture)
1076 {
1077     HWND wnd;
1078     IDirect3D9 *d3d;
1079     IDirect3DDevice9 *device;
1080     D3DPRESENT_PARAMETERS d3dpp;
1081     HRESULT hr;
1082
1083     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1084     if (!wnd) {
1085         skip("Couldn't create application window\n");
1086         return;
1087     }
1088     d3d = Direct3DCreate9(D3D_SDK_VERSION);
1089     if (!d3d) {
1090         skip("Couldn't create IDirect3D9 object\n");
1091         DestroyWindow(wnd);
1092         return;
1093     }
1094
1095     ZeroMemory(&d3dpp, sizeof(d3dpp));
1096     d3dpp.Windowed   = TRUE;
1097     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1098     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1099     if (FAILED(hr)) {
1100         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1101         IDirect3D9_Release(d3d);
1102         DestroyWindow(wnd);
1103         return;
1104     }
1105
1106     test_D3DXCheckTextureRequirements(device);
1107     test_D3DXCheckCubeTextureRequirements(device);
1108     test_D3DXCheckVolumeTextureRequirements(device);
1109     test_D3DXCreateTexture(device);
1110     test_D3DXFilterTexture(device);
1111     test_D3DXFillTexture(device);
1112     test_D3DXFillCubeTexture(device);
1113     test_D3DXFillVolumeTexture(device);
1114
1115     IDirect3DDevice9_Release(device);
1116     IDirect3D9_Release(d3d);
1117     DestroyWindow(wnd);
1118 }