d3dx9: Properly check if a texture is lockable in D3DXCreateTextureFromFileInMemoryEx.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob1314fa2037b5bea33a9570d12e3b8c2fe1ce6728
1 /*
2 * Tests for the D3DX9 texture functions
4 * Copyright 2009 Tony Wasserka
5 * Copyright 2010 Owen Rudge for CodeWeavers
6 * Copyright 2010 Matteo Bruni for CodeWeavers
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.
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.
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
23 #define COBJMACROS
24 #include "wine/test.h"
25 #include "d3dx9tex.h"
26 #include "resources.h"
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
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
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
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
88 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
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;
98 IDirect3DDevice9_GetDeviceCaps(device, &caps);
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);
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);
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);
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);
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);
122 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
123 skip("Hardware only supports pow2 textures\n");
124 else
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);
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);
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);
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);
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);
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);
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);
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);
175 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
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);
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);
189 else
190 skip("Skipping some tests, npot2 textures unsupported\n");
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);
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);
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");
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);
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);
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);
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);
233 IDirect3DDevice9_GetDirect3D(device, &d3d);
234 IDirect3DDevice9_GetCreationParameters(device, &params);
235 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
237 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
238 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
239 expected = D3DFMT_R3G3B2;
240 else
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;
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);
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;
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);
265 IDirect3D9_Release(d3d);
268 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
270 UINT size, mipmaps, expected;
271 D3DFORMAT format;
272 D3DCAPS9 caps;
273 HRESULT hr;
275 IDirect3DDevice9_GetDeviceCaps(device, &caps);
277 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
279 skip("No cube textures support\n");
280 return;
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);
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);
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);
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);
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);
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);
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);
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);
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");
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);
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);
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);
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);
357 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
359 UINT width, height, depth, mipmaps, expected;
360 D3DFORMAT format;
361 D3DCAPS9 caps;
362 HRESULT hr;
364 IDirect3DDevice9_GetDeviceCaps(device, &caps);
366 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
368 skip("No volume textures support\n");
369 return;
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
438 /* mipmaps */
439 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
441 skip("No volume textures mipmapping support\n");
442 return;
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);
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);
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);
466 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
468 IDirect3DTexture9 *texture;
469 D3DSURFACE_DESC desc;
470 D3DCAPS9 caps;
471 UINT mipmaps;
472 HRESULT hr;
474 IDirect3DDevice9_GetDeviceCaps(device, &caps);
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);
479 /* width and height tests */
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);
484 if (texture)
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);
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);
493 IDirect3DTexture9_Release(texture);
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);
500 if (texture)
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);
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);
509 IDirect3DTexture9_Release(texture);
513 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
514 skip("Hardware only supports pow2 textures\n");
515 else
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);
523 if (texture)
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);
529 /* Conditional NPOT may create a texture with different dimensions, so allow those
530 situations instead of returning a fail */
532 ok(desc.Width == 63 ||
533 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
534 "Returned width %d, expected %d\n", desc.Width, 63);
536 ok(desc.Height == 63 ||
537 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
538 "Returned height %d, expected %d\n", desc.Height, 63);
540 IDirect3DTexture9_Release(texture);
544 /* mipmaps */
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);
549 if (texture)
551 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
552 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
554 IDirect3DTexture9_Release(texture);
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);
561 if (texture)
563 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
564 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
566 IDirect3DTexture9_Release(texture);
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);
573 if (texture)
575 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
576 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
578 IDirect3DTexture9_Release(texture);
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);
585 if (texture)
587 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
588 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
590 IDirect3DTexture9_Release(texture);
593 /* usage */
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");
606 /* format */
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);
611 if (texture)
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);
617 IDirect3DTexture9_Release(texture);
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);
624 if (texture)
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);
630 IDirect3DTexture9_Release(texture);
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);
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);
643 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
644 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
646 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
647 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
649 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
650 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
652 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
653 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
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);
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);
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);
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);
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);
674 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
676 IDirect3DTexture9 *tex;
677 IDirect3DCubeTexture9 *cubetex;
678 HRESULT hr;
680 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
682 if (SUCCEEDED(hr))
684 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
685 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
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);
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);
693 else
694 skip("Failed to create texture\n");
696 IDirect3DTexture9_Release(tex);
698 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
699 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
701 /* Test different pools */
702 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
704 if (SUCCEEDED(hr))
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);
710 else
711 skip("Failed to create texture\n");
713 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
715 if (SUCCEEDED(hr))
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);
721 else
722 skip("Failed to create texture\n");
724 /* Cube texture test */
725 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
727 if (SUCCEEDED(hr))
729 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
730 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
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);
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);
738 else
739 skip("Failed to create texture\n");
741 IDirect3DCubeTexture9_Release(cubetex);
744 static BOOL color_match(const DWORD *value, const DWORD *expected)
746 int i;
748 for (i = 0; i < 4; i++)
750 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
751 if (diff > 1) return FALSE;
753 return TRUE;
756 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
757 const D3DXVECTOR2 *texelsize, void *data)
759 value->x = texcoord->x;
760 value->y = texcoord->y;
761 value->z = texelsize->x;
762 value->w = 1.0f;
765 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
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;
774 size = 4;
775 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
776 D3DPOOL_MANAGED, &tex, NULL);
778 if (SUCCEEDED(hr))
780 hr = D3DXFillTexture(tex, fillfunc, NULL);
781 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
783 for (m = 0; m < 3; m++)
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))
789 pitch = lock_rect.Pitch / sizeof(DWORD);
790 for (y = 0; y < size; y++)
792 for (x = 0; x < size; x++)
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;
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];
806 ok(color_match(v, e),
807 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
808 x, y, value, expected);
811 IDirect3DTexture9_UnlockRect(tex, m);
813 size >>= 1;
816 else
817 skip("Failed to create texture\n");
819 IDirect3DTexture9_Release(tex);
821 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
822 D3DPOOL_MANAGED, &tex, NULL);
824 if (SUCCEEDED(hr))
826 hr = D3DXFillTexture(tex, fillfunc, NULL);
827 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
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))
833 pitch = lock_rect.Pitch / sizeof(WORD);
834 for (y = 0; y < 4; y++)
836 for (x = 0; x < 4; x++)
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;
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];
850 ok(color_match(v, e),
851 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
852 x, y, value, expected);
855 IDirect3DTexture9_UnlockRect(tex, 0);
858 else
859 skip("Failed to create texture\n");
861 IDirect3DTexture9_Release(tex);
864 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
865 const D3DXVECTOR3 *texelsize, void *data)
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;
873 enum cube_coord
875 XCOORD = 0,
876 XCOORDINV = 1,
877 YCOORD = 2,
878 YCOORDINV = 3,
879 ZERO = 4,
880 ONE = 5
883 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
885 switch (coord)
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;
905 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
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] =
915 {ONE, YCOORDINV, XCOORDINV},
916 {ZERO, YCOORDINV, XCOORD},
917 {XCOORD, ONE, YCOORD},
918 {XCOORD, ZERO, YCOORDINV},
919 {XCOORD, YCOORDINV, ONE},
920 {XCOORDINV, YCOORDINV, ZERO}
923 size = 4;
924 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
925 D3DPOOL_MANAGED, &tex, NULL);
927 if (SUCCEEDED(hr))
929 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
930 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
932 for (m = 0; m < 3; m++)
934 for (f = 0; f < 6; f++)
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))
940 pitch = lock_rect.Pitch / sizeof(DWORD);
941 for (y = 0; y < size; y++)
943 for (x = 0; x < size; x++)
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;
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];
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);
963 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
966 size >>= 1;
969 else
970 skip("Failed to create texture\n");
972 IDirect3DCubeTexture9_Release(tex);
974 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
975 D3DPOOL_MANAGED, &tex, NULL);
977 if (SUCCEEDED(hr))
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++)
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))
987 pitch = lock_rect.Pitch / sizeof(WORD);
988 for (y = 0; y < 4; y++)
990 for (x = 0; x < 4; x++)
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;
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];
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);
1010 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1014 else
1015 skip("Failed to create texture\n");
1017 IDirect3DCubeTexture9_Release(tex);
1020 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1021 const D3DXVECTOR3 *texelsize, void *data)
1023 value->x = texcoord->x;
1024 value->y = texcoord->y;
1025 value->z = texcoord->z;
1026 value->w = texelsize->x;
1029 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
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;
1038 size = 4;
1039 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1040 D3DPOOL_MANAGED, &tex, NULL);
1042 if (SUCCEEDED(hr))
1044 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1045 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1047 for (m = 0; m < 3; m++)
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))
1053 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1054 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1055 for (z = 0; z < size; z++)
1057 for (y = 0; y < size; y++)
1059 for (x = 0; x < size; x++)
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;
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];
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);
1079 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1081 size >>= 1;
1084 else
1085 skip("Failed to create texture\n");
1087 IDirect3DVolumeTexture9_Release(tex);
1089 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1090 D3DPOOL_MANAGED, &tex, NULL);
1092 if (SUCCEEDED(hr))
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))
1100 row_pitch = lock_box.RowPitch / sizeof(WORD);
1101 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1102 for (z = 0; z < 4; z++)
1104 for (y = 0; y < 4; y++)
1106 for (x = 0; x < 4; x++)
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;
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];
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);
1126 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1129 else
1130 skip("Failed to create texture\n");
1132 IDirect3DVolumeTexture9_Release(tex);
1135 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1137 HRESULT hr;
1138 IDirect3DTexture9 *texture;
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);
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);
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);
1152 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1154 HRESULT hr;
1155 IDirect3DTexture9 *texture;
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);
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);
1168 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1170 HRESULT hr;
1171 ULONG ref;
1172 DWORD levelcount;
1173 IDirect3DCubeTexture9 *cube_texture;
1174 D3DSURFACE_DESC surface_desc;
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);
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);
1182 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1183 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
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);
1188 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1189 if (SUCCEEDED(hr))
1191 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1192 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
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);
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);
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");
1207 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1209 HRESULT hr;
1210 ULONG ref;
1211 DWORD levelcount;
1212 IDirect3DVolumeTexture9 *volume_texture;
1213 D3DVOLUME_DESC volume_desc;
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);
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);
1222 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1223 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
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);
1228 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1229 if (SUCCEEDED(hr))
1231 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1232 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
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);
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);
1246 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1247 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1252 START_TEST(texture)
1254 HWND wnd;
1255 IDirect3D9 *d3d;
1256 IDirect3DDevice9 *device;
1257 D3DPRESENT_PARAMETERS d3dpp;
1258 HRESULT hr;
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;
1265 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1266 if (!d3d) {
1267 skip("Couldn't create IDirect3D9 object\n");
1268 DestroyWindow(wnd);
1269 return;
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;
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);
1296 IDirect3DDevice9_Release(device);
1297 IDirect3D9_Release(d3d);
1298 DestroyWindow(wnd);