d3dx9: Search for a compatible pixel format in D3DXCheckTextureRequirements.
[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  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #define COBJMACROS
23 #include "wine/test.h"
24 #include "d3dx9tex.h"
25 #include "resources.h"
26
27 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
28 {
29     UINT width, height, mipmaps;
30     D3DFORMAT format, expected;
31     D3DCAPS9 caps;
32     HRESULT hr;
33     IDirect3D9 *d3d;
34     D3DDEVICE_CREATION_PARAMETERS params;
35     D3DDISPLAYMODE mode;
36
37     IDirect3DDevice9_GetDeviceCaps(device, &caps);
38
39     /* general tests */
40     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
41     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
42
43     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
44     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
45
46     hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
47     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
48
49     /* width & height */
50     width = height = D3DX_DEFAULT;
51     hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
52     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
53     ok(width == 256, "Returned width %d, expected %d\n", width, 256);
54     ok(height == 256, "Returned height %d, expected %d\n", height, 256);
55
56     width = D3DX_DEFAULT;
57     hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
58     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
59     ok(width == 256, "Returned width %d, expected %d\n", width, 256);
60
61     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
62         skip("Hardware only supports pow2 textures\n");
63     else
64     {
65         width = 62;
66         hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
67         ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
68         ok(width == 62, "Returned width %d, expected %d\n", width, 62);
69
70         width = D3DX_DEFAULT; height = 63;
71         hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
72         ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
73         ok(width == height, "Returned width %d, expected %d\n", width, height);
74         ok(height == 63, "Returned height %d, expected %d\n", height, 63);
75     }
76
77     width = D3DX_DEFAULT; height = 0;
78     hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
79     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
80     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
81     ok(height == 1, "Returned height %d, expected %d\n", height, 1);
82
83     width = 0; height = 0;
84     hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
85     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
86     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
87     ok(height == 1, "Returned height %d, expected %d\n", height, 1);
88
89     width = 0;
90     hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
91     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
92     ok(width == 1, "Returned width %d, expected %d\n", width, 1);
93
94     width = D3DX_DEFAULT;
95     hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
96     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
97     ok(width == 256, "Returned width %d, expected %d\n", width, 256);
98
99     width = 0xFFFFFFFE;
100     hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
101     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
102     ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
103
104     width = caps.MaxTextureWidth-1;
105     hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
106     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
107     ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
108
109     /* mipmaps */
110     width = 64; height = 63;
111     mipmaps = 9;
112     hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
113     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
114     ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
115
116     width = 284; height = 137;
117     mipmaps = 20;
118     hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
119     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
120     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
121
122     width = height = 63;
123     mipmaps = 9;
124     hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
125     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
126     ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
127
128     mipmaps = 20;
129     hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
130     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
131     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
132
133     mipmaps = 0;
134     hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
135     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
136     ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
137
138     /* usage */
139     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
140     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
141     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
142     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
143     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
144     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
145     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
146     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
147     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
148     ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
149
150     /* format */
151     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
152     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
153
154     format = D3DFMT_UNKNOWN;
155     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
156     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
157     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
158
159     format = D3DX_DEFAULT;
160     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
161     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
162     ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
163
164     format = D3DFMT_R8G8B8;
165     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
166     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
167     ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
168
169     IDirect3DDevice9_GetDirect3D(device, &d3d);
170     IDirect3DDevice9_GetCreationParameters(device, &params);
171     IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
172
173     if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
174                                               mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
175         expected = D3DFMT_R3G3B2;
176     else
177         expected = D3DFMT_X4R4G4B4;
178
179     format = D3DFMT_R3G3B2;
180     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
181     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
182     ok(format == expected, "Returned format %u, expected %u\n", format, expected);
183
184     if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
185                                               mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
186         expected = D3DFMT_A8R3G3B2;
187     else
188         expected = D3DFMT_A8R8G8B8;
189
190     format = D3DFMT_A8R3G3B2;
191     hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
192     ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
193     ok(format == expected, "Returned format %u, expected %u\n", format, expected);
194
195     IDirect3D9_Release(d3d);
196 }
197
198 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
199 {
200     IDirect3DTexture9 *texture;
201     D3DSURFACE_DESC desc;
202     D3DCAPS9 caps;
203     UINT mipmaps;
204     HRESULT hr;
205
206     IDirect3DDevice9_GetDeviceCaps(device, &caps);
207
208     hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
209     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
210
211     /* width and height tests */
212
213     hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
214     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
215
216     if (texture)
217     {
218         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
219
220         ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
221         ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
222
223         IDirect3DTexture9_Release(texture);
224     }
225
226
227     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
228     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
229
230     if (texture)
231     {
232         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
233
234         ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
235         ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
236
237         IDirect3DTexture9_Release(texture);
238     }
239
240
241     if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
242         skip("Hardware only supports pow2 textures\n");
243     else
244     {
245         hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
246         ok((hr == D3D_OK) ||
247            /* may not work with conditional NPOT */
248            ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
249            "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
250
251         if (texture)
252         {
253             hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
254
255             /* Conditional NPOT may create a texture with different dimensions, so allow those
256                situations instead of returning a fail */
257
258             ok(desc.Width == 63 ||
259                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
260                "Returned width %d, expected %d\n", desc.Width, 63);
261
262             ok(desc.Height == 63 ||
263                (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
264                "Returned height %d, expected %d\n", desc.Height, 63);
265
266             IDirect3DTexture9_Release(texture);
267         }
268     }
269
270     /* mipmaps */
271
272     hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
273     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
274
275     if (texture)
276     {
277         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
278         ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
279
280         IDirect3DTexture9_Release(texture);
281     }
282
283
284     hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
285     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
286
287     if (texture)
288     {
289         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
290         ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
291
292         IDirect3DTexture9_Release(texture);
293     }
294
295
296     hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
297     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
298
299     if (texture)
300     {
301         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
302         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
303
304         IDirect3DTexture9_Release(texture);
305     }
306
307
308     hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
309     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
310
311     if (texture)
312     {
313         mipmaps = IDirect3DTexture9_GetLevelCount(texture);
314         ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
315
316         IDirect3DTexture9_Release(texture);
317     }
318
319     /* usage */
320
321     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
322     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
323     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
324     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
325     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
326     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
327     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
328     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
329     hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
330     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
331
332     /* format */
333
334     hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
335     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
336
337     if (texture)
338     {
339         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
340         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
341
342         IDirect3DTexture9_Release(texture);
343     }
344
345
346     hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
347     ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
348
349     if (texture)
350     {
351         hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
352         ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
353
354         IDirect3DTexture9_Release(texture);
355     }
356
357     /* D3DXCreateTextureFromResource */
358     todo_wine {
359         hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
360         ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
361         if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
362
363         hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
364         ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
365         if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
366     }
367
368     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
369     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
370
371     hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
372     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
373
374     hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
375     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
376
377     hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
378     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
379
380
381     /* D3DXCreateTextureFromResourceEx */
382     todo_wine {
383         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);
384         ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
385         if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
386     }
387
388     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);
389     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
390
391     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);
392     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
393
394     hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
395     ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
396
397     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);
398     ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
399 }
400
401 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
402 {
403     IDirect3DTexture9 *tex;
404     HRESULT hr;
405
406     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
407
408     if (SUCCEEDED(hr))
409     {
410         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
411         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
412
413         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
414         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
415
416         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Last miplevel */
417         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
418
419         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 20, D3DX_FILTER_NONE); /* Invalid miplevel */
420         ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
421     }
422     else
423         skip("Failed to create texture\n");
424
425     IDirect3DTexture9_Release(tex);
426
427     hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
428     ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
429
430     /* Test different pools */
431     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
432
433     if (SUCCEEDED(hr))
434     {
435         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
436         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
437         IDirect3DTexture9_Release(tex);
438     }
439     else
440         skip("Failed to create texture\n");
441
442
443     hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
444
445     if (SUCCEEDED(hr))
446     {
447         hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
448         ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
449         IDirect3DTexture9_Release(tex);
450     }
451     else
452         skip("Failed to create texture\n");
453 }
454
455 START_TEST(texture)
456 {
457     HWND wnd;
458     IDirect3D9 *d3d;
459     IDirect3DDevice9 *device;
460     D3DPRESENT_PARAMETERS d3dpp;
461     HRESULT hr;
462
463     wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
464     if (!wnd) {
465         skip("Couldn't create application window\n");
466         return;
467     }
468     d3d = Direct3DCreate9(D3D_SDK_VERSION);
469     if (!d3d) {
470         skip("Couldn't create IDirect3D9 object\n");
471         DestroyWindow(wnd);
472         return;
473     }
474
475     ZeroMemory(&d3dpp, sizeof(d3dpp));
476     d3dpp.Windowed   = TRUE;
477     d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
478     hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
479     if (FAILED(hr)) {
480         skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
481         IDirect3D9_Release(d3d);
482         DestroyWindow(wnd);
483         return;
484     }
485
486     test_D3DXCheckTextureRequirements(device);
487     test_D3DXCreateTexture(device);
488     test_D3DXFilterTexture(device);
489
490     IDirect3DDevice9_Release(device);
491     IDirect3D9_Release(d3d);
492     DestroyWindow(wnd);
493 }