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