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