Add AppDefaults app selection to control panel
[wine/gsoc-2012-control.git] / dlls / d3dx9_36 / tests / texture.c
blob1edfe9e0bcc60730e7ee0d53ec0b318a296fb1c1
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 BOOL is_autogenmipmap_supported(IDirect3DDevice9 *device, D3DRESOURCETYPE resource_type)
90 HRESULT hr;
91 D3DCAPS9 caps;
92 IDirect3D9 *d3d9;
93 D3DDISPLAYMODE mode;
94 D3DDEVICE_CREATION_PARAMETERS params;
96 IDirect3DDevice9_GetDeviceCaps(device, &caps);
97 IDirect3DDevice9_GetDirect3D(device, &d3d9);
98 IDirect3DDevice9_GetCreationParameters(device, &params);
99 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
101 if (!(caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP))
102 return FALSE;
104 hr = IDirect3D9_CheckDeviceFormat(d3d9, params.AdapterOrdinal, params.DeviceType,
105 mode.Format, D3DUSAGE_AUTOGENMIPMAP, resource_type, D3DFMT_A8R8G8B8);
107 IDirect3D9_Release(d3d9);
108 return SUCCEEDED(hr);
111 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
113 UINT width, height, mipmaps;
114 D3DFORMAT format, expected;
115 D3DCAPS9 caps;
116 HRESULT hr;
117 IDirect3D9 *d3d;
118 D3DDEVICE_CREATION_PARAMETERS params;
119 D3DDISPLAYMODE mode;
121 IDirect3DDevice9_GetDeviceCaps(device, &caps);
123 /* general tests */
124 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
125 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
128 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
130 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
131 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
133 /* width & height */
134 width = height = D3DX_DEFAULT;
135 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
136 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
137 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
138 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
140 width = D3DX_DEFAULT;
141 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
142 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
143 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
145 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
146 skip("Hardware only supports pow2 textures\n");
147 else
149 width = 62;
150 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
151 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
152 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
154 width = D3DX_DEFAULT; height = 63;
155 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
156 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
157 ok(width == height, "Returned width %d, expected %d\n", width, height);
158 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
161 width = D3DX_DEFAULT; height = 0;
162 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
163 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
164 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
165 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
167 width = 0; height = 0;
168 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
169 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
170 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
171 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
173 width = 0;
174 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
175 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
176 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
178 width = 0xFFFFFFFE;
179 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
180 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
181 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
183 width = caps.MaxTextureWidth-1;
184 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
185 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
186 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
187 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
188 else
189 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
191 /* mipmaps */
192 width = 64; height = 63;
193 mipmaps = 9;
194 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
195 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
196 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
198 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
200 width = 284; height = 137;
201 mipmaps = 20;
202 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
203 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
204 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
206 width = height = 63;
207 mipmaps = 9;
208 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
209 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
210 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
212 else
213 skip("Skipping some tests, npot2 textures unsupported\n");
215 mipmaps = 20;
216 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
217 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
218 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
220 mipmaps = 0;
221 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
222 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
223 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
225 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
226 if (is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
228 mipmaps = 0;
229 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
230 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
231 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
232 mipmaps = 1;
233 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
234 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
235 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
236 mipmaps = 2;
237 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
238 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
239 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
240 mipmaps = 6;
241 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
242 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
243 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
245 else
246 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
248 /* usage */
249 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
250 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
251 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
252 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
253 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
254 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
255 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
256 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
257 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
258 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
260 /* format */
261 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
262 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
264 format = D3DFMT_UNKNOWN;
265 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
266 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
267 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
269 format = D3DX_DEFAULT;
270 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
271 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
272 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
274 format = D3DFMT_R8G8B8;
275 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
276 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
277 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
279 IDirect3DDevice9_GetDirect3D(device, &d3d);
280 IDirect3DDevice9_GetCreationParameters(device, &params);
281 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
283 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
284 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
285 expected = D3DFMT_R3G3B2;
286 else
288 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
289 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
290 expected = D3DFMT_X4R4G4B4;
291 else
292 expected = D3DFMT_X1R5G5B5;
295 format = D3DFMT_R3G3B2;
296 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
297 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
298 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
300 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
301 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
302 expected = D3DFMT_A8R3G3B2;
303 else
304 expected = D3DFMT_A8R8G8B8;
306 format = D3DFMT_A8R3G3B2;
307 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
308 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
309 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
311 IDirect3D9_Release(d3d);
314 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
316 UINT size, mipmaps, expected;
317 D3DFORMAT format;
318 D3DCAPS9 caps;
319 HRESULT hr;
321 IDirect3DDevice9_GetDeviceCaps(device, &caps);
323 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
325 skip("No cube textures support\n");
326 return;
329 /* general tests */
330 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
331 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
333 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
334 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
336 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
337 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
339 /* size */
340 size = D3DX_DEFAULT;
341 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
342 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
343 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
345 /* mipmaps */
346 size = 64;
347 mipmaps = 9;
348 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
349 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
350 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
352 size = 284;
353 mipmaps = 20;
354 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
355 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
356 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
357 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
359 size = 63;
360 mipmaps = 9;
361 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
362 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
363 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
364 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
366 mipmaps = 0;
367 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
368 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
369 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
371 if (is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
373 mipmaps = 3;
374 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
375 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
376 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
378 else
379 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
381 /* usage */
382 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
383 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
384 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
385 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
386 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
387 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
388 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
389 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
390 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
391 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
393 /* format */
394 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
395 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
397 format = D3DFMT_UNKNOWN;
398 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
399 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
400 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
402 format = D3DX_DEFAULT;
403 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
404 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
405 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
407 format = D3DFMT_R8G8B8;
408 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
409 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
410 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
413 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
415 UINT width, height, depth, mipmaps, expected;
416 D3DFORMAT format;
417 D3DCAPS9 caps;
418 HRESULT hr;
420 IDirect3DDevice9_GetDeviceCaps(device, &caps);
422 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
424 skip("No volume textures support\n");
425 return;
428 /* general tests */
429 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
430 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
432 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
433 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
435 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
436 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
438 /* width, height, depth */
439 width = height = depth = D3DX_DEFAULT;
440 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
441 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
442 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
443 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
444 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
446 width = D3DX_DEFAULT;
447 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
448 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
449 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
451 width = D3DX_DEFAULT; height = 0; depth = 0;
452 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
453 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
454 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
455 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
456 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
458 width = 0; height = 0; depth = 0;
459 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
460 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
461 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
462 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
463 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
465 width = 0;
466 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
467 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
468 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
470 width = 0xFFFFFFFE;
471 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
472 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
473 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
475 /* format */
476 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
477 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
479 format = D3DFMT_UNKNOWN;
480 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
481 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
482 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
484 format = D3DX_DEFAULT;
485 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
486 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
487 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
489 format = D3DFMT_R8G8B8;
490 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
491 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
492 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
494 /* mipmaps */
495 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
497 skip("No volume textures mipmapping support\n");
498 return;
501 width = height = depth = 64;
502 mipmaps = 9;
503 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
504 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
505 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
507 width = 284;
508 height = 143;
509 depth = 55;
510 mipmaps = 20;
511 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
512 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
513 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
514 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
516 mipmaps = 0;
517 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
518 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
519 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
521 if (!is_autogenmipmap_supported(device, D3DRTYPE_VOLUMETEXTURE))
523 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
524 return;
527 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
528 mipmaps = 0;
529 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
530 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
531 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
532 mipmaps = 1;
533 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
534 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
535 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
536 mipmaps = 3;
537 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
538 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
539 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
542 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
544 IDirect3DTexture9 *texture;
545 D3DSURFACE_DESC desc;
546 D3DCAPS9 caps;
547 UINT mipmaps;
548 HRESULT hr;
550 IDirect3DDevice9_GetDeviceCaps(device, &caps);
552 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, D3DPOOL_DEFAULT, NULL);
553 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
555 /* width and height tests */
557 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
558 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
560 if (texture)
562 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
563 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
564 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
566 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
567 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
569 IDirect3DTexture9_Release(texture);
573 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
574 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
576 if (texture)
578 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
579 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
580 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
582 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
583 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
585 IDirect3DTexture9_Release(texture);
589 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
590 skip("Hardware only supports pow2 textures\n");
591 else
593 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
594 ok((hr == D3D_OK) ||
595 /* may not work with conditional NPOT */
596 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
597 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
599 if (texture)
601 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
602 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
603 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
605 /* Conditional NPOT may create a texture with different dimensions, so allow those
606 situations instead of returning a fail */
608 ok(desc.Width == 63 ||
609 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
610 "Returned width %d, expected %d\n", desc.Width, 63);
612 ok(desc.Height == 63 ||
613 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
614 "Returned height %d, expected %d\n", desc.Height, 63);
616 IDirect3DTexture9_Release(texture);
620 /* mipmaps */
622 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
623 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
625 if (texture)
627 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
628 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
630 IDirect3DTexture9_Release(texture);
634 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
635 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
637 if (texture)
639 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
640 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
642 IDirect3DTexture9_Release(texture);
646 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
647 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
649 if (texture)
651 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
652 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
654 IDirect3DTexture9_Release(texture);
658 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
659 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
661 if (texture)
663 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
664 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
666 IDirect3DTexture9_Release(texture);
669 /* usage */
671 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
672 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
673 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
674 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
675 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
676 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
677 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
678 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
679 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
680 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
682 /* format */
684 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
685 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
687 if (texture)
689 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
690 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
691 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
693 IDirect3DTexture9_Release(texture);
697 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
698 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
700 if (texture)
702 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
703 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
704 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
706 IDirect3DTexture9_Release(texture);
709 /* D3DXCreateTextureFromResource */
710 todo_wine {
711 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
712 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
713 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
715 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
716 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
717 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
719 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
720 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
722 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
723 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
725 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
726 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
728 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
729 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
732 /* D3DXCreateTextureFromResourceEx */
733 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);
734 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
735 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
737 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);
738 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
740 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);
741 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
743 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
744 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
746 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);
747 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
750 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
752 IDirect3DTexture9 *tex;
753 IDirect3DCubeTexture9 *cubetex;
754 IDirect3DVolumeTexture9 *voltex;
755 HRESULT hr;
757 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
759 if (SUCCEEDED(hr))
761 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, D3DX_DEFAULT, D3DX_FILTER_NONE);
762 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
764 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
765 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
767 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
768 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
770 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
771 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
773 IDirect3DTexture9_Release(tex);
775 else
776 skip("Failed to create texture\n");
778 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
779 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
781 /* Test different pools */
782 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
784 if (SUCCEEDED(hr))
786 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
787 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
788 IDirect3DTexture9_Release(tex);
790 else
791 skip("Failed to create texture\n");
793 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
795 if (SUCCEEDED(hr))
797 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
798 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
799 IDirect3DTexture9_Release(tex);
801 else
802 skip("Failed to create texture\n");
804 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
805 if (SUCCEEDED(hr))
807 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
808 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
809 IDirect3DTexture9_Release(tex);
811 else
812 skip("Failed to create texture\n");
814 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
815 if (SUCCEEDED(hr))
817 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
818 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
819 IDirect3DTexture9_Release(tex);
821 else
822 skip("Failed to create texture\n");
824 /* Cube texture test */
825 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
827 if (SUCCEEDED(hr))
829 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
830 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
832 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
833 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
835 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
836 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
837 IDirect3DCubeTexture9_Release(cubetex);
839 else
840 skip("Failed to create texture\n");
842 /* Volume texture test */
843 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &voltex, NULL);
844 if (SUCCEEDED(hr))
846 DWORD level_count = IDirect3DVolumeTexture9_GetLevelCount(voltex);
848 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_NONE);
849 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
851 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_DEFAULT);
852 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
854 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_BOX);
855 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
857 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count - 1, D3DX_DEFAULT);
858 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
860 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count, D3DX_DEFAULT);
861 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
863 IDirect3DVolumeTexture9_Release(voltex);
865 else
866 skip("Failed to create volume texture\n");
868 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
869 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
871 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
872 return;
875 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
876 if (SUCCEEDED(hr))
878 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
879 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
880 IDirect3DTexture9_Release(tex);
882 else
883 skip("Failed to create texture\n");
885 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
886 if (SUCCEEDED(hr))
888 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
889 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
890 IDirect3DTexture9_Release(tex);
892 else
893 skip("Failed to create texture\n");
896 static BOOL color_match(const DWORD *value, const DWORD *expected)
898 int i;
900 for (i = 0; i < 4; i++)
902 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
903 if (diff > 1) return FALSE;
905 return TRUE;
908 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
909 const D3DXVECTOR2 *texelsize, void *data)
911 value->x = texcoord->x;
912 value->y = texcoord->y;
913 value->z = texelsize->x;
914 value->w = 1.0f;
917 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
919 IDirect3DTexture9 *tex;
920 HRESULT hr;
921 D3DLOCKED_RECT lock_rect;
922 DWORD x, y, m;
923 DWORD v[4], e[4];
924 DWORD value, expected, size, pitch;
926 size = 4;
927 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
928 D3DPOOL_MANAGED, &tex, NULL);
930 if (SUCCEEDED(hr))
932 hr = D3DXFillTexture(tex, fillfunc, NULL);
933 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
935 for (m = 0; m < 3; m++)
937 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
938 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
939 if (SUCCEEDED(hr))
941 pitch = lock_rect.Pitch / sizeof(DWORD);
942 for (y = 0; y < size; y++)
944 for (x = 0; x < size; x++)
946 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
947 v[0] = (value >> 24) & 0xff;
948 v[1] = (value >> 16) & 0xff;
949 v[2] = (value >> 8) & 0xff;
950 v[3] = value & 0xff;
952 e[0] = 0xff;
953 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
954 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
955 e[3] = 255.0f / size + 0.5f;
956 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
958 ok(color_match(v, e),
959 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
960 x, y, value, expected);
963 IDirect3DTexture9_UnlockRect(tex, m);
965 size >>= 1;
968 else
969 skip("Failed to create texture\n");
971 IDirect3DTexture9_Release(tex);
973 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
974 D3DPOOL_MANAGED, &tex, NULL);
976 if (SUCCEEDED(hr))
978 hr = D3DXFillTexture(tex, fillfunc, NULL);
979 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
981 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
982 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
983 if (SUCCEEDED(hr))
985 pitch = lock_rect.Pitch / sizeof(WORD);
986 for (y = 0; y < 4; y++)
988 for (x = 0; x < 4; x++)
990 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
991 v[0] = value >> 15;
992 v[1] = value >> 10 & 0x1f;
993 v[2] = value >> 5 & 0x1f;
994 v[3] = value & 0x1f;
996 e[0] = 1;
997 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
998 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
999 e[3] = 8;
1000 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1002 ok(color_match(v, e),
1003 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1004 x, y, value, expected);
1007 IDirect3DTexture9_UnlockRect(tex, 0);
1010 else
1011 skip("Failed to create texture\n");
1013 IDirect3DTexture9_Release(tex);
1016 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1017 const D3DXVECTOR3 *texelsize, void *data)
1019 value->x = (texcoord->x + 1.0f) / 2.0f;
1020 value->y = (texcoord->y + 1.0f) / 2.0f;
1021 value->z = (texcoord->z + 1.0f) / 2.0f;
1022 value->w = texelsize->x;
1025 enum cube_coord
1027 XCOORD = 0,
1028 XCOORDINV = 1,
1029 YCOORD = 2,
1030 YCOORDINV = 3,
1031 ZERO = 4,
1032 ONE = 5
1035 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1037 switch (coord)
1039 case XCOORD:
1040 return x + 0.5f;
1041 case XCOORDINV:
1042 return size - x - 0.5f;
1043 case YCOORD:
1044 return y + 0.5f;
1045 case YCOORDINV:
1046 return size - y - 0.5f;
1047 case ZERO:
1048 return 0.0f;
1049 case ONE:
1050 return size;
1051 default:
1052 trace("Unexpected coordinate value\n");
1053 return 0.0f;
1057 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
1059 IDirect3DCubeTexture9 *tex;
1060 HRESULT hr;
1061 D3DLOCKED_RECT lock_rect;
1062 DWORD x, y, f, m;
1063 DWORD v[4], e[4];
1064 DWORD value, expected, size, pitch;
1065 enum cube_coord coordmap[6][3] =
1067 {ONE, YCOORDINV, XCOORDINV},
1068 {ZERO, YCOORDINV, XCOORD},
1069 {XCOORD, ONE, YCOORD},
1070 {XCOORD, ZERO, YCOORDINV},
1071 {XCOORD, YCOORDINV, ONE},
1072 {XCOORDINV, YCOORDINV, ZERO}
1075 size = 4;
1076 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1077 D3DPOOL_MANAGED, &tex, NULL);
1079 if (SUCCEEDED(hr))
1081 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1082 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1084 for (m = 0; m < 3; m++)
1086 for (f = 0; f < 6; f++)
1088 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1089 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1090 if (SUCCEEDED(hr))
1092 pitch = lock_rect.Pitch / sizeof(DWORD);
1093 for (y = 0; y < size; y++)
1095 for (x = 0; x < size; x++)
1097 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1098 v[0] = (value >> 24) & 0xff;
1099 v[1] = (value >> 16) & 0xff;
1100 v[2] = (value >> 8) & 0xff;
1101 v[3] = value & 0xff;
1103 e[0] = (f == 0) || (f == 1) ?
1104 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1105 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1106 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1107 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1108 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1110 ok(color_match(v, e),
1111 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1112 f, x, y, value, expected);
1115 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1118 size >>= 1;
1121 else
1122 skip("Failed to create texture\n");
1124 IDirect3DCubeTexture9_Release(tex);
1126 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1127 D3DPOOL_MANAGED, &tex, NULL);
1129 if (SUCCEEDED(hr))
1131 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1132 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1133 for (f = 0; f < 6; f++)
1135 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1136 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1137 if (SUCCEEDED(hr))
1139 pitch = lock_rect.Pitch / sizeof(WORD);
1140 for (y = 0; y < 4; y++)
1142 for (x = 0; x < 4; x++)
1144 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1145 v[0] = value >> 15;
1146 v[1] = value >> 10 & 0x1f;
1147 v[2] = value >> 5 & 0x1f;
1148 v[3] = value & 0x1f;
1150 e[0] = (f == 0) || (f == 1) ?
1151 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1152 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1153 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1154 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1155 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1157 ok(color_match(v, e),
1158 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1159 f, x, y, value, expected);
1162 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1166 else
1167 skip("Failed to create texture\n");
1169 IDirect3DCubeTexture9_Release(tex);
1172 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1173 const D3DXVECTOR3 *texelsize, void *data)
1175 value->x = texcoord->x;
1176 value->y = texcoord->y;
1177 value->z = texcoord->z;
1178 value->w = texelsize->x;
1181 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1183 IDirect3DVolumeTexture9 *tex;
1184 HRESULT hr;
1185 D3DLOCKED_BOX lock_box;
1186 DWORD x, y, z, m;
1187 DWORD v[4], e[4];
1188 DWORD value, expected, size, row_pitch, slice_pitch;
1190 size = 4;
1191 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1192 D3DPOOL_MANAGED, &tex, NULL);
1194 if (SUCCEEDED(hr))
1196 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1197 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1199 for (m = 0; m < 3; m++)
1201 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1202 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1203 if (SUCCEEDED(hr))
1205 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1206 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1207 for (z = 0; z < size; z++)
1209 for (y = 0; y < size; y++)
1211 for (x = 0; x < size; x++)
1213 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1214 v[0] = (value >> 24) & 0xff;
1215 v[1] = (value >> 16) & 0xff;
1216 v[2] = (value >> 8) & 0xff;
1217 v[3] = value & 0xff;
1219 e[0] = 255.0f / size + 0.5f;
1220 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1221 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1222 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1223 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1225 ok(color_match(v, e),
1226 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1227 x, y, z, value, expected);
1231 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1233 size >>= 1;
1236 else
1237 skip("Failed to create texture\n");
1239 IDirect3DVolumeTexture9_Release(tex);
1241 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1242 D3DPOOL_MANAGED, &tex, NULL);
1244 if (SUCCEEDED(hr))
1246 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1247 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1248 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1249 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1250 if (SUCCEEDED(hr))
1252 row_pitch = lock_box.RowPitch / sizeof(WORD);
1253 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1254 for (z = 0; z < 4; z++)
1256 for (y = 0; y < 4; y++)
1258 for (x = 0; x < 4; x++)
1260 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1261 v[0] = value >> 15;
1262 v[1] = value >> 10 & 0x1f;
1263 v[2] = value >> 5 & 0x1f;
1264 v[3] = value & 0x1f;
1266 e[0] = 1;
1267 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1268 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1269 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1270 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1272 ok(color_match(v, e),
1273 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1274 x, y, z, value, expected);
1278 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1281 else
1282 skip("Failed to create texture\n");
1284 IDirect3DVolumeTexture9_Release(tex);
1287 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1289 HRESULT hr;
1290 IDirect3DTexture9 *texture;
1292 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1293 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1294 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1296 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1297 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1298 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1300 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1301 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1304 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1306 HRESULT hr;
1307 IDirect3DTexture9 *texture;
1309 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1310 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1311 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1312 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1314 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1315 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1316 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1317 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1319 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
1321 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1322 return;
1325 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1326 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1327 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1328 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1331 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1333 HRESULT hr;
1334 ULONG ref;
1335 DWORD levelcount;
1336 IDirect3DCubeTexture9 *cube_texture;
1337 D3DSURFACE_DESC surface_desc;
1339 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1340 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1342 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1343 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1345 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1346 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1348 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1349 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1351 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1352 if (SUCCEEDED(hr))
1354 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1355 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1357 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1358 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1359 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1360 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1362 ref = IDirect3DCubeTexture9_Release(cube_texture);
1363 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1364 } else skip("Couldn't create cube texture\n");
1367 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1369 HRESULT hr;
1370 IDirect3DCubeTexture9 *cube_texture;
1372 if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
1374 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1375 return;
1378 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT,
1379 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
1380 ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1381 if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture);
1384 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1386 HRESULT hr;
1387 ULONG ref;
1388 DWORD levelcount;
1389 IDirect3DVolumeTexture9 *volume_texture;
1390 D3DVOLUME_DESC volume_desc;
1392 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1393 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1395 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1396 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1398 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1399 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1401 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1402 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1404 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1405 ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1406 if (SUCCEEDED(hr))
1408 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1409 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1411 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1412 ok(hr == D3D_OK, "GetLevelDesc returend %#x, expected %#x\n", hr, D3D_OK);
1413 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1414 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1415 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1417 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1418 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1419 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1420 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1421 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1423 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1424 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1428 /* fills positive x face with red color */
1429 static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data)
1431 memset(out, 0, sizeof(*out));
1432 if (tex_coord->x > 0 && fabs(tex_coord->x) > fabs(tex_coord->y) && fabs(tex_coord->x) > fabs(tex_coord->z))
1433 out->x = 1;
1436 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device)
1438 HRESULT hr;
1439 IDirect3DTexture9 *texture;
1440 IDirect3DCubeTexture9 *cube_texture;
1441 IDirect3DVolumeTexture9 *volume_texture;
1442 ID3DXBuffer *buffer;
1443 void *buffer_pointer;
1444 DWORD buffer_size;
1445 D3DXIMAGE_INFO info;
1446 D3DXIMAGE_FILEFORMAT file_format;
1448 /* textures */
1449 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
1450 if (FAILED(hr))
1452 skip("Failed to create texture\n");
1453 return;
1456 for (file_format = D3DXIFF_BMP; file_format <= D3DXIFF_JPG; file_format++)
1458 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, (IDirect3DBaseTexture9 *)texture, NULL);
1459 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1460 if (SUCCEEDED(hr))
1462 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1463 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1464 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1465 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1467 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1468 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1469 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1470 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1471 ok(info.ImageFileFormat == file_format, "Got file format %#x, expected %#x\n", info.ImageFileFormat, file_format);
1472 ID3DXBuffer_Release(buffer);
1476 todo_wine {
1477 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)texture, NULL);
1478 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1479 if (SUCCEEDED(hr))
1481 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1482 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1483 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1484 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1486 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1487 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1488 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1489 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1490 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1491 ID3DXBuffer_Release(buffer);
1495 IDirect3DTexture9_Release(texture);
1497 /* cube textures */
1498 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &cube_texture, NULL);
1499 if (FAILED(hr))
1501 skip("Failed to create cube texture\n");
1502 return;
1505 hr = D3DXFillCubeTexture(cube_texture, fill_cube_positive_x, NULL);
1506 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1508 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1509 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1510 if (SUCCEEDED(hr))
1512 IDirect3DSurface9 *surface;
1514 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1515 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1516 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1517 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1519 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1520 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1521 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1522 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1523 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1525 /* positive x face is saved */
1526 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1527 if (SUCCEEDED(hr))
1529 D3DLOCKED_RECT locked_rect;
1531 hr = D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, buffer_pointer, buffer_size, NULL, D3DX_FILTER_NONE, 0, NULL);
1532 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1534 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1535 if (SUCCEEDED(hr))
1537 DWORD *color = locked_rect.pBits;
1538 ok(*color == 0x00ff0000, "Got color %#x, expected %#x\n", *color, 0x00ff0000);
1539 IDirect3DSurface9_UnlockRect(surface);
1542 IDirect3DSurface9_Release(surface);
1543 } else skip("Failed to create surface\n");
1545 ID3DXBuffer_Release(buffer);
1548 todo_wine {
1549 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1550 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1551 if (SUCCEEDED(hr))
1553 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1554 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1555 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1556 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1558 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1559 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1560 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1561 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
1562 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1563 ID3DXBuffer_Release(buffer);
1567 IDirect3DCubeTexture9_Release(cube_texture);
1569 /* volume textures */
1570 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &volume_texture, NULL);
1571 if (FAILED(hr))
1573 skip("Failed to create volume texture\n");
1574 return;
1577 todo_wine {
1578 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1579 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1580 if (SUCCEEDED(hr))
1582 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1583 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1584 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1585 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1587 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1588 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1589 ok(info.Depth == 1, "Got depth %u, expected %u\n", info.Depth, 1);
1590 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1591 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1592 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1593 ID3DXBuffer_Release(buffer);
1596 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1597 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1598 if (SUCCEEDED(hr))
1600 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1601 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1602 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1603 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1605 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1606 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1607 ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256);
1608 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1609 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
1610 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1611 ID3DXBuffer_Release(buffer);
1615 IDirect3DVolumeTexture9_Release(volume_texture);
1618 START_TEST(texture)
1620 HWND wnd;
1621 IDirect3D9 *d3d;
1622 IDirect3DDevice9 *device;
1623 D3DPRESENT_PARAMETERS d3dpp;
1624 HRESULT hr;
1626 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1627 if (!wnd) {
1628 skip("Couldn't create application window\n");
1629 return;
1631 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1632 if (!d3d) {
1633 skip("Couldn't create IDirect3D9 object\n");
1634 DestroyWindow(wnd);
1635 return;
1638 ZeroMemory(&d3dpp, sizeof(d3dpp));
1639 d3dpp.Windowed = TRUE;
1640 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1641 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1642 if (FAILED(hr)) {
1643 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1644 IDirect3D9_Release(d3d);
1645 DestroyWindow(wnd);
1646 return;
1649 test_D3DXCheckTextureRequirements(device);
1650 test_D3DXCheckCubeTextureRequirements(device);
1651 test_D3DXCheckVolumeTextureRequirements(device);
1652 test_D3DXCreateTexture(device);
1653 test_D3DXFilterTexture(device);
1654 test_D3DXFillTexture(device);
1655 test_D3DXFillCubeTexture(device);
1656 test_D3DXFillVolumeTexture(device);
1657 test_D3DXCreateTextureFromFileInMemory(device);
1658 test_D3DXCreateTextureFromFileInMemoryEx(device);
1659 test_D3DXCreateCubeTextureFromFileInMemory(device);
1660 test_D3DXCreateCubeTextureFromFileInMemoryEx(device);
1661 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1662 test_D3DXSaveTextureToFileInMemory(device);
1664 IDirect3DDevice9_Release(device);
1665 IDirect3D9_Release(d3d);
1666 DestroyWindow(wnd);