Release 1.6-rc2.
[wine/testsucceed.git] / dlls / d3dx9_36 / tests / texture.c
blobfd072c83a066bf1208b3c7640f3fe78a84ab2b85
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 static int has_dxt5;
30 /* 2x2 16-bit dds, no mipmaps */
31 static const unsigned char dds_16bit[] = {
32 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
33 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
37 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
38 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
39 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
43 /* 2x2 24-bit dds, 2 mipmaps */
44 static const unsigned char dds_24bit[] = {
45 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
46 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
47 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
48 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
49 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
50 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
51 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
52 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
53 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
56 /* 4x4 cube map dds */
57 static const unsigned char dds_cube_map[] = {
58 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
59 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
60 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
61 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
63 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
64 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
65 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
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,0x51,
68 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x52,
69 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x53,
70 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x54,
71 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x55
74 /* 4x4x2 volume map dds, 2 mipmaps */
75 static const unsigned char dds_volume_map[] = {
76 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
77 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
78 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
81 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
83 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
85 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
86 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
87 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
90 #define ADMITTED_ERROR 0.0001f
92 static inline float relative_error(float expected, float got)
94 return expected == 0.0f ? fabs(expected - got) : fabs(1.0f - got / expected);
97 #define expect_vec4(expected, got) expect_vec4_(__LINE__, expected, got)
98 static inline void expect_vec4_(unsigned int line, const D3DXVECTOR4 *expected, const D3DXVECTOR4 *got)
100 ok_(__FILE__, line)(relative_error(expected->x, got->x) < ADMITTED_ERROR
101 && relative_error(expected->y, got->y) < ADMITTED_ERROR
102 && relative_error(expected->z, got->z) < ADMITTED_ERROR
103 && relative_error(expected->w, got->w) < ADMITTED_ERROR,
104 "Expected (%f, %f, %f, %f), got (%f, %f, %f, %f)\n",
105 expected->x, expected->y, expected->z, expected->w,
106 got->x, got->y, got->z, got->w);
109 static BOOL is_autogenmipmap_supported(IDirect3DDevice9 *device, D3DRESOURCETYPE resource_type)
111 HRESULT hr;
112 D3DCAPS9 caps;
113 IDirect3D9 *d3d9;
114 D3DDISPLAYMODE mode;
115 D3DDEVICE_CREATION_PARAMETERS params;
117 IDirect3DDevice9_GetDeviceCaps(device, &caps);
118 IDirect3DDevice9_GetDirect3D(device, &d3d9);
119 IDirect3DDevice9_GetCreationParameters(device, &params);
120 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
122 if (!(caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP))
123 return FALSE;
125 hr = IDirect3D9_CheckDeviceFormat(d3d9, params.AdapterOrdinal, params.DeviceType,
126 mode.Format, D3DUSAGE_AUTOGENMIPMAP, resource_type, D3DFMT_A8R8G8B8);
128 IDirect3D9_Release(d3d9);
129 return SUCCEEDED(hr);
132 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
134 UINT width, height, mipmaps;
135 D3DFORMAT format, expected;
136 D3DCAPS9 caps;
137 HRESULT hr;
138 IDirect3D9 *d3d;
139 D3DDEVICE_CREATION_PARAMETERS params;
140 D3DDISPLAYMODE mode;
142 IDirect3DDevice9_GetDeviceCaps(device, &caps);
144 /* general tests */
145 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
146 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
148 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
149 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
151 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
152 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
154 /* width & height */
155 width = height = D3DX_DEFAULT;
156 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
157 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
158 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
159 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
161 width = D3DX_DEFAULT;
162 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
163 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
164 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
166 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
167 skip("Hardware only supports pow2 textures\n");
168 else
170 width = 62;
171 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
172 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
173 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
175 width = D3DX_DEFAULT; height = 63;
176 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
177 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
178 ok(width == height, "Returned width %d, expected %d\n", width, height);
179 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
182 width = D3DX_DEFAULT; height = 0;
183 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
184 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
185 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
186 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
188 width = 0; height = 0;
189 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
190 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
191 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
192 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
194 width = 0;
195 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
196 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
197 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
199 width = 0xFFFFFFFE;
200 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
201 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
202 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
204 width = caps.MaxTextureWidth-1;
205 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
206 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
207 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
208 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
209 else
210 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
212 /* mipmaps */
213 width = 64; height = 63;
214 mipmaps = 9;
215 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
216 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
217 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
219 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
221 width = 284; height = 137;
222 mipmaps = 20;
223 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
224 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
225 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
227 width = height = 63;
228 mipmaps = 9;
229 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
230 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
231 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
233 else
234 skip("Skipping some tests, npot2 textures unsupported\n");
236 mipmaps = 20;
237 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
238 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
239 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
241 mipmaps = 0;
242 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
243 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
244 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
246 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
247 if (is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
249 mipmaps = 0;
250 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
251 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
252 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
253 mipmaps = 1;
254 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
255 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
256 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
257 mipmaps = 2;
258 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
259 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
260 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
261 mipmaps = 6;
262 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
263 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
264 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
266 else
267 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
269 /* usage */
270 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
271 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
272 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
273 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
274 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
275 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
276 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
277 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
278 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
279 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
281 /* format */
282 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
283 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
285 format = D3DFMT_UNKNOWN;
286 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
287 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
288 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
290 format = D3DX_DEFAULT;
291 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
292 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
293 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
295 format = D3DFMT_R8G8B8;
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 == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
300 IDirect3DDevice9_GetDirect3D(device, &d3d);
301 IDirect3DDevice9_GetCreationParameters(device, &params);
302 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
304 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
305 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
306 expected = D3DFMT_R3G3B2;
307 else
309 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
310 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
311 expected = D3DFMT_X4R4G4B4;
312 else
313 expected = D3DFMT_X1R5G5B5;
316 format = D3DFMT_R3G3B2;
317 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
318 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
319 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
321 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
322 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
323 expected = D3DFMT_A8R3G3B2;
324 else
325 expected = D3DFMT_A8R8G8B8;
327 format = D3DFMT_A8R3G3B2;
328 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
329 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
330 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
332 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
333 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_P8)))
334 expected = D3DFMT_P8;
335 else
336 expected = D3DFMT_A8R8G8B8;
338 format = D3DFMT_P8;
339 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
340 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
341 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
343 IDirect3D9_Release(d3d);
346 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
348 UINT size, mipmaps, expected;
349 D3DFORMAT format;
350 D3DCAPS9 caps;
351 HRESULT hr;
353 IDirect3DDevice9_GetDeviceCaps(device, &caps);
355 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
357 skip("No cube textures support\n");
358 return;
361 /* general tests */
362 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
363 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
365 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
366 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
368 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
369 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
371 /* size */
372 size = D3DX_DEFAULT;
373 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
374 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
375 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
377 /* mipmaps */
378 size = 64;
379 mipmaps = 9;
380 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
381 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
382 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
384 size = 284;
385 mipmaps = 20;
386 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
387 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
388 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
389 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
391 size = 63;
392 mipmaps = 9;
393 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
394 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
395 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
396 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
398 mipmaps = 0;
399 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
400 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
401 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
403 if (is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
405 mipmaps = 3;
406 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
407 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
408 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
410 else
411 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
413 /* usage */
414 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
415 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
416 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
417 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
418 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
419 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
420 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
421 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
422 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
423 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
425 /* format */
426 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
427 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
429 format = D3DFMT_UNKNOWN;
430 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
431 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
432 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
434 format = D3DX_DEFAULT;
435 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
436 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
437 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
439 format = D3DFMT_R8G8B8;
440 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
441 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
442 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
445 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
447 UINT width, height, depth, mipmaps, expected;
448 D3DFORMAT format;
449 D3DCAPS9 caps;
450 HRESULT hr;
452 IDirect3DDevice9_GetDeviceCaps(device, &caps);
454 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
456 skip("No volume textures support\n");
457 return;
460 /* general tests */
461 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
462 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
464 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
465 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
467 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
468 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
470 /* width, height, depth */
471 width = height = depth = D3DX_DEFAULT;
472 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
473 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
474 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
475 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
476 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
478 width = D3DX_DEFAULT;
479 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
480 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
481 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
483 width = D3DX_DEFAULT; height = 0; depth = 0;
484 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
485 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
486 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
487 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
488 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
490 width = 0; height = 0; depth = 0;
491 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
492 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
493 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
494 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
495 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
497 width = 0;
498 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
499 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
500 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
502 width = 0xFFFFFFFE;
503 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
504 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
505 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
507 /* format */
508 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
509 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
511 format = D3DFMT_UNKNOWN;
512 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
513 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
514 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
516 format = D3DX_DEFAULT;
517 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
518 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
519 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
521 format = D3DFMT_R8G8B8;
522 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
523 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
524 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
526 /* mipmaps */
527 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
529 skip("No volume textures mipmapping support\n");
530 return;
533 width = height = depth = 64;
534 mipmaps = 9;
535 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
536 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
537 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
539 width = 284;
540 height = 143;
541 depth = 55;
542 mipmaps = 20;
543 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
544 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
545 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
546 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
548 mipmaps = 0;
549 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
550 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
551 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
553 if (!is_autogenmipmap_supported(device, D3DRTYPE_VOLUMETEXTURE))
555 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
556 return;
559 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
560 mipmaps = 0;
561 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
562 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
563 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
564 mipmaps = 1;
565 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
566 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
567 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
568 mipmaps = 3;
569 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
570 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
571 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
574 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
576 IDirect3DTexture9 *texture;
577 D3DSURFACE_DESC desc;
578 D3DCAPS9 caps;
579 UINT mipmaps;
580 HRESULT hr;
582 IDirect3DDevice9_GetDeviceCaps(device, &caps);
584 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, D3DPOOL_DEFAULT, NULL);
585 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
587 /* width and height tests */
589 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
590 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
592 if (texture)
594 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
595 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
596 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
598 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
599 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
601 IDirect3DTexture9_Release(texture);
605 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
606 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
608 if (texture)
610 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
611 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
612 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
614 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
615 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
617 IDirect3DTexture9_Release(texture);
621 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
622 skip("Hardware only supports pow2 textures\n");
623 else
625 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
626 ok((hr == D3D_OK) ||
627 /* may not work with conditional NPOT */
628 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
629 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
631 if (texture)
633 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
634 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
635 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
637 /* Conditional NPOT may create a texture with different dimensions, so allow those
638 situations instead of returning a fail */
640 ok(desc.Width == 63 ||
641 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
642 "Returned width %d, expected %d\n", desc.Width, 63);
644 ok(desc.Height == 63 ||
645 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
646 "Returned height %d, expected %d\n", desc.Height, 63);
648 IDirect3DTexture9_Release(texture);
652 /* mipmaps */
654 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
655 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
657 if (texture)
659 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
660 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
662 IDirect3DTexture9_Release(texture);
666 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
667 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
669 if (texture)
671 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
672 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
674 IDirect3DTexture9_Release(texture);
678 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
679 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
681 if (texture)
683 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
684 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
686 IDirect3DTexture9_Release(texture);
690 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
691 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
693 if (texture)
695 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
696 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
698 IDirect3DTexture9_Release(texture);
701 /* usage */
703 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
704 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
705 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
706 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
707 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
708 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
709 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
710 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
711 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
712 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
714 /* format */
716 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
717 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
719 if (texture)
721 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
722 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
723 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
725 IDirect3DTexture9_Release(texture);
729 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
730 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
732 if (texture)
734 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
735 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
736 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
738 IDirect3DTexture9_Release(texture);
741 /* D3DXCreateTextureFromResource */
742 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
743 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
744 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
746 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
747 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
748 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
750 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
751 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
753 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
754 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
756 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
757 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
759 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
760 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
763 /* D3DXCreateTextureFromResourceEx */
764 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);
765 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
766 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
768 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);
769 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
771 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);
772 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
774 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
775 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
777 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);
778 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
781 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
783 IDirect3DTexture9 *tex;
784 IDirect3DCubeTexture9 *cubetex;
785 IDirect3DVolumeTexture9 *voltex;
786 HRESULT hr;
788 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
790 if (SUCCEEDED(hr))
792 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, D3DX_DEFAULT, D3DX_FILTER_NONE);
793 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
795 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
796 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
798 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
799 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
801 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
802 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
804 IDirect3DTexture9_Release(tex);
806 else
807 skip("Failed to create texture\n");
809 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
810 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
812 /* Test different pools */
813 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
815 if (SUCCEEDED(hr))
817 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
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 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
826 if (SUCCEEDED(hr))
828 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
829 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
830 IDirect3DTexture9_Release(tex);
832 else
833 skip("Failed to create texture\n");
835 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
836 if (SUCCEEDED(hr))
838 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
839 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
840 IDirect3DTexture9_Release(tex);
842 else
843 skip("Failed to create texture\n");
845 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
846 if (SUCCEEDED(hr))
848 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
849 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
850 IDirect3DTexture9_Release(tex);
852 else
853 skip("Failed to create texture\n");
855 /* Cube texture test */
856 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
858 if (SUCCEEDED(hr))
860 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
861 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
863 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
864 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
866 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
867 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
868 IDirect3DCubeTexture9_Release(cubetex);
870 else
871 skip("Failed to create texture\n");
873 /* Volume texture test */
874 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &voltex, NULL);
875 if (SUCCEEDED(hr))
877 DWORD level_count = IDirect3DVolumeTexture9_GetLevelCount(voltex);
879 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_NONE);
880 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
882 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_DEFAULT);
883 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
885 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_BOX);
886 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
888 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count - 1, D3DX_DEFAULT);
889 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
891 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count, D3DX_DEFAULT);
892 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
894 IDirect3DVolumeTexture9_Release(voltex);
896 else
897 skip("Failed to create volume texture\n");
899 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
900 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
902 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
903 return;
906 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
907 if (SUCCEEDED(hr))
909 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
910 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
911 IDirect3DTexture9_Release(tex);
913 else
914 skip("Failed to create texture\n");
916 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
917 if (SUCCEEDED(hr))
919 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
920 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
921 IDirect3DTexture9_Release(tex);
923 else
924 skip("Failed to create texture\n");
927 static BOOL color_match(const DWORD *value, const DWORD *expected)
929 int i;
931 for (i = 0; i < 4; i++)
933 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
934 if (diff > 1) return FALSE;
936 return TRUE;
939 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
940 const D3DXVECTOR2 *texelsize, void *data)
942 value->x = texcoord->x;
943 value->y = texcoord->y;
944 value->z = texelsize->x;
945 value->w = 1.0f;
948 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
950 IDirect3DTexture9 *tex;
951 HRESULT hr;
952 D3DLOCKED_RECT lock_rect;
953 DWORD x, y, m;
954 DWORD v[4], e[4];
955 DWORD value, expected, size, pitch;
957 size = 4;
958 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
959 D3DPOOL_MANAGED, &tex, NULL);
961 if (SUCCEEDED(hr))
963 hr = D3DXFillTexture(tex, fillfunc, NULL);
964 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
966 for (m = 0; m < 3; m++)
968 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
969 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
970 if (SUCCEEDED(hr))
972 pitch = lock_rect.Pitch / sizeof(DWORD);
973 for (y = 0; y < size; y++)
975 for (x = 0; x < size; x++)
977 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
978 v[0] = (value >> 24) & 0xff;
979 v[1] = (value >> 16) & 0xff;
980 v[2] = (value >> 8) & 0xff;
981 v[3] = value & 0xff;
983 e[0] = 0xff;
984 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
985 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
986 e[3] = 255.0f / size + 0.5f;
987 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
989 ok(color_match(v, e),
990 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
991 x, y, value, expected);
994 IDirect3DTexture9_UnlockRect(tex, m);
996 size >>= 1;
999 IDirect3DTexture9_Release(tex);
1001 else
1002 skip("Failed to create texture\n");
1004 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1005 D3DPOOL_MANAGED, &tex, NULL);
1007 if (SUCCEEDED(hr))
1009 hr = D3DXFillTexture(tex, fillfunc, NULL);
1010 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1012 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1013 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1014 if (SUCCEEDED(hr))
1016 pitch = lock_rect.Pitch / sizeof(WORD);
1017 for (y = 0; y < 4; y++)
1019 for (x = 0; x < 4; x++)
1021 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1022 v[0] = value >> 15;
1023 v[1] = value >> 10 & 0x1f;
1024 v[2] = value >> 5 & 0x1f;
1025 v[3] = value & 0x1f;
1027 e[0] = 1;
1028 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
1029 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
1030 e[3] = 8;
1031 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1033 ok(color_match(v, e),
1034 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1035 x, y, value, expected);
1038 IDirect3DTexture9_UnlockRect(tex, 0);
1041 IDirect3DTexture9_Release(tex);
1043 else
1044 skip("Failed to create texture\n");
1046 /* test floating-point textures */
1047 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A16B16G16R16F,
1048 D3DPOOL_MANAGED, &tex, NULL);
1050 if (SUCCEEDED(hr))
1052 hr = D3DXFillTexture(tex, fillfunc, NULL);
1053 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1055 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1056 if (SUCCEEDED(hr))
1058 pitch = lock_rect.Pitch / sizeof(WORD);
1059 for (y = 0; y < 4; y++)
1061 WORD *ptr = (WORD *)lock_rect.pBits + y * pitch;
1062 for (x = 0; x < 4; x++)
1064 D3DXVECTOR4 got, expected;
1066 D3DXFloat16To32Array((FLOAT *)&got, (D3DXFLOAT16 *)ptr, 4);
1067 ptr += 4;
1069 expected.x = (x + 0.5f) / 4.0f;
1070 expected.y = (y + 0.5f) / 4.0f;
1071 expected.z = 1.0f / 4.0f;
1072 expected.w = 1.0f;
1074 expect_vec4(&expected, &got);
1078 IDirect3DTexture9_UnlockRect(tex, 0);
1080 else
1081 skip("Failed to lock texture\n");
1083 IDirect3DTexture9_Release(tex);
1085 else
1086 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1088 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A32B32G32R32F,
1089 D3DPOOL_MANAGED, &tex, NULL);
1091 if (SUCCEEDED(hr))
1093 hr = D3DXFillTexture(tex, fillfunc, NULL);
1094 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1096 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1097 if (SUCCEEDED(hr))
1099 pitch = lock_rect.Pitch / sizeof(float);
1100 for (y = 0; y < 4; y++)
1102 float *ptr = (float *)lock_rect.pBits + y * pitch;
1103 for (x = 0; x < 4; x++)
1105 D3DXVECTOR4 got, expected;
1107 got.x = *ptr++;
1108 got.y = *ptr++;
1109 got.z = *ptr++;
1110 got.w = *ptr++;
1112 expected.x = (x + 0.5f) / 4.0f;
1113 expected.y = (y + 0.5f) / 4.0f;
1114 expected.z = 1.0f / 4.0f;
1115 expected.w = 1.0f;
1117 expect_vec4(&expected, &got);
1121 IDirect3DTexture9_UnlockRect(tex, 0);
1123 else
1124 skip("Failed to lock texture\n");
1126 IDirect3DTexture9_Release(tex);
1128 else
1129 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1131 /* test a compressed texture */
1132 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1,
1133 D3DPOOL_MANAGED, &tex, NULL);
1135 if (SUCCEEDED(hr))
1137 hr = D3DXFillTexture(tex, fillfunc, NULL);
1138 todo_wine ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1140 IDirect3DTexture9_Release(tex);
1142 else
1143 skip("Failed to create D3DFMT_DXT1 texture\n");
1146 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1147 const D3DXVECTOR3 *texelsize, void *data)
1149 value->x = (texcoord->x + 1.0f) / 2.0f;
1150 value->y = (texcoord->y + 1.0f) / 2.0f;
1151 value->z = (texcoord->z + 1.0f) / 2.0f;
1152 value->w = texelsize->x;
1155 enum cube_coord
1157 XCOORD = 0,
1158 XCOORDINV = 1,
1159 YCOORD = 2,
1160 YCOORDINV = 3,
1161 ZERO = 4,
1162 ONE = 5
1165 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1167 switch (coord)
1169 case XCOORD:
1170 return x + 0.5f;
1171 case XCOORDINV:
1172 return size - x - 0.5f;
1173 case YCOORD:
1174 return y + 0.5f;
1175 case YCOORDINV:
1176 return size - y - 0.5f;
1177 case ZERO:
1178 return 0.0f;
1179 case ONE:
1180 return size;
1181 default:
1182 trace("Unexpected coordinate value\n");
1183 return 0.0f;
1187 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
1189 IDirect3DCubeTexture9 *tex;
1190 HRESULT hr;
1191 D3DLOCKED_RECT lock_rect;
1192 DWORD x, y, f, m;
1193 DWORD v[4], e[4];
1194 DWORD value, expected, size, pitch;
1195 enum cube_coord coordmap[6][3] =
1197 {ONE, YCOORDINV, XCOORDINV},
1198 {ZERO, YCOORDINV, XCOORD},
1199 {XCOORD, ONE, YCOORD},
1200 {XCOORD, ZERO, YCOORDINV},
1201 {XCOORD, YCOORDINV, ONE},
1202 {XCOORDINV, YCOORDINV, ZERO}
1205 size = 4;
1206 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1207 D3DPOOL_MANAGED, &tex, NULL);
1209 if (SUCCEEDED(hr))
1211 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1212 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1214 for (m = 0; m < 3; m++)
1216 for (f = 0; f < 6; f++)
1218 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1219 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1220 if (SUCCEEDED(hr))
1222 pitch = lock_rect.Pitch / sizeof(DWORD);
1223 for (y = 0; y < size; y++)
1225 for (x = 0; x < size; x++)
1227 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1228 v[0] = (value >> 24) & 0xff;
1229 v[1] = (value >> 16) & 0xff;
1230 v[2] = (value >> 8) & 0xff;
1231 v[3] = value & 0xff;
1233 e[0] = (f == 0) || (f == 1) ?
1234 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1235 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1236 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1237 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1238 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1240 ok(color_match(v, e),
1241 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1242 f, x, y, value, expected);
1245 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1248 size >>= 1;
1251 IDirect3DCubeTexture9_Release(tex);
1253 else
1254 skip("Failed to create texture\n");
1256 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1257 D3DPOOL_MANAGED, &tex, NULL);
1259 if (SUCCEEDED(hr))
1261 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1262 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1263 for (f = 0; f < 6; f++)
1265 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1266 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1267 if (SUCCEEDED(hr))
1269 pitch = lock_rect.Pitch / sizeof(WORD);
1270 for (y = 0; y < 4; y++)
1272 for (x = 0; x < 4; x++)
1274 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1275 v[0] = value >> 15;
1276 v[1] = value >> 10 & 0x1f;
1277 v[2] = value >> 5 & 0x1f;
1278 v[3] = value & 0x1f;
1280 e[0] = (f == 0) || (f == 1) ?
1281 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1282 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1283 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1284 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1285 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1287 ok(color_match(v, e),
1288 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1289 f, x, y, value, expected);
1292 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1296 IDirect3DCubeTexture9_Release(tex);
1298 else
1299 skip("Failed to create texture\n");
1302 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1303 const D3DXVECTOR3 *texelsize, void *data)
1305 value->x = texcoord->x;
1306 value->y = texcoord->y;
1307 value->z = texcoord->z;
1308 value->w = texelsize->x;
1311 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1313 IDirect3DVolumeTexture9 *tex;
1314 HRESULT hr;
1315 D3DLOCKED_BOX lock_box;
1316 DWORD x, y, z, m;
1317 DWORD v[4], e[4];
1318 DWORD value, expected, size, row_pitch, slice_pitch;
1320 size = 4;
1321 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1322 D3DPOOL_MANAGED, &tex, NULL);
1324 if (SUCCEEDED(hr))
1326 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1327 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1329 for (m = 0; m < 3; m++)
1331 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1332 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1333 if (SUCCEEDED(hr))
1335 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1336 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1337 for (z = 0; z < size; z++)
1339 for (y = 0; y < size; y++)
1341 for (x = 0; x < size; x++)
1343 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1344 v[0] = (value >> 24) & 0xff;
1345 v[1] = (value >> 16) & 0xff;
1346 v[2] = (value >> 8) & 0xff;
1347 v[3] = value & 0xff;
1349 e[0] = 255.0f / size + 0.5f;
1350 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1351 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1352 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1353 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1355 ok(color_match(v, e),
1356 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1357 x, y, z, value, expected);
1361 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1363 size >>= 1;
1366 IDirect3DVolumeTexture9_Release(tex);
1368 else
1369 skip("Failed to create texture\n");
1371 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1372 D3DPOOL_MANAGED, &tex, NULL);
1374 if (SUCCEEDED(hr))
1376 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1377 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1378 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1379 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1380 if (SUCCEEDED(hr))
1382 row_pitch = lock_box.RowPitch / sizeof(WORD);
1383 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1384 for (z = 0; z < 4; z++)
1386 for (y = 0; y < 4; y++)
1388 for (x = 0; x < 4; x++)
1390 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1391 v[0] = value >> 15;
1392 v[1] = value >> 10 & 0x1f;
1393 v[2] = value >> 5 & 0x1f;
1394 v[3] = value & 0x1f;
1396 e[0] = 1;
1397 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1398 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1399 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1400 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1402 ok(color_match(v, e),
1403 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1404 x, y, z, value, expected);
1408 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1411 IDirect3DVolumeTexture9_Release(tex);
1413 else
1414 skip("Failed to create texture\n");
1417 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1419 HRESULT hr;
1420 IDirect3DTexture9 *texture;
1421 D3DRESOURCETYPE type;
1422 D3DSURFACE_DESC desc;
1423 D3DLOCKED_RECT lock_rect;
1424 int i;
1426 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1427 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1428 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1430 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1431 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1432 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1434 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1435 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1437 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1438 hr = D3DXCreateTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &texture);
1439 if (!has_dxt5 && hr == E_NOTIMPL)
1441 skip("DXT5 is not supported, skipping the D3DXCreateTextureFromFileInMemory() tests\n");
1442 return;
1444 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1445 if (SUCCEEDED(hr))
1447 type = IDirect3DTexture9_GetType(texture);
1448 ok(type == D3DRTYPE_TEXTURE, "IDirect3DTexture9_GetType returned %u, expected %u\n", type, D3DRTYPE_TEXTURE);
1449 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
1450 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1451 ok(desc.Width == 4, "Width is %u, expected 4\n", desc.Width);
1452 ok(desc.Height == 4, "Height is %u, expected 4\n", desc.Height);
1453 hr = IDirect3DTexture9_LockRect(texture, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1454 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %#x, expected %#x\n", hr, D3D_OK);
1455 if (SUCCEEDED(hr))
1457 for (i = 0; i < 16; i++)
1458 ok(((BYTE*)lock_rect.pBits)[i] == dds_cube_map[128+i], "Byte at index %u is 0x%02x, expected 0x%02x\n", i, ((BYTE*)lock_rect.pBits)[i], dds_cube_map[144+i]);
1459 IDirect3DTexture9_UnlockRect(texture, 0);
1461 IDirect3DTexture9_Release(texture);
1466 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1468 HRESULT hr;
1469 IDirect3DTexture9 *texture;
1471 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1472 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1473 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1474 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1476 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1477 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1478 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1479 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1481 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
1483 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1484 return;
1487 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1488 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1489 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1490 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1493 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1495 HRESULT hr;
1496 ULONG ref;
1497 DWORD levelcount;
1498 IDirect3DCubeTexture9 *cube_texture;
1499 D3DSURFACE_DESC surface_desc;
1501 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1502 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1504 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1505 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1507 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1508 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1510 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1511 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1513 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1514 if (SUCCEEDED(hr))
1516 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1517 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1519 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1520 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1521 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1522 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1524 ref = IDirect3DCubeTexture9_Release(cube_texture);
1525 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1526 } else skip("Couldn't create cube texture\n");
1529 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1531 HRESULT hr;
1532 IDirect3DCubeTexture9 *cube_texture;
1534 if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
1536 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1537 return;
1540 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT,
1541 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
1542 if (!has_dxt5 && hr == E_NOTIMPL)
1544 skip("DXT5 is not supported, skipping the D3DXCreateCubeTextureFromFileInMemoryEx() tests\n");
1545 return;
1547 ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1548 if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture);
1551 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1553 HRESULT hr;
1554 ULONG ref;
1555 DWORD levelcount;
1556 IDirect3DVolumeTexture9 *volume_texture;
1557 D3DVOLUME_DESC volume_desc;
1559 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1560 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1562 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1563 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1565 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1566 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1568 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1569 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1571 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1572 if (!has_dxt5 && hr == E_NOTIMPL)
1574 skip("DXT5 is not supported, skipping the D3DXCreateVolumeTextureFromFileInMemory() tests\n");
1575 return;
1577 ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1578 if (SUCCEEDED(hr))
1580 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1581 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1583 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1584 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1585 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1586 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1587 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1589 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1590 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1591 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1592 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1593 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1595 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1596 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1600 /* fills positive x face with red color */
1601 static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data)
1603 memset(out, 0, sizeof(*out));
1604 if (tex_coord->x > 0 && fabs(tex_coord->x) > fabs(tex_coord->y) && fabs(tex_coord->x) > fabs(tex_coord->z))
1605 out->x = 1;
1608 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device)
1610 HRESULT hr;
1611 IDirect3DTexture9 *texture;
1612 IDirect3DCubeTexture9 *cube_texture;
1613 IDirect3DVolumeTexture9 *volume_texture;
1614 ID3DXBuffer *buffer;
1615 void *buffer_pointer;
1616 DWORD buffer_size;
1617 D3DXIMAGE_INFO info;
1618 D3DXIMAGE_FILEFORMAT file_format;
1620 /* textures */
1621 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
1622 if (FAILED(hr))
1624 skip("Failed to create texture\n");
1625 return;
1628 for (file_format = D3DXIFF_BMP; file_format <= D3DXIFF_JPG; file_format++)
1630 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, (IDirect3DBaseTexture9 *)texture, NULL);
1631 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1632 if (SUCCEEDED(hr))
1634 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1635 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1636 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1637 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1639 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1640 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1641 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1642 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1643 ok(info.ImageFileFormat == file_format, "Got file format %#x, expected %#x\n", info.ImageFileFormat, file_format);
1644 ID3DXBuffer_Release(buffer);
1648 todo_wine {
1649 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)texture, NULL);
1650 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1651 if (SUCCEEDED(hr))
1653 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1654 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1655 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1656 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1658 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1659 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1660 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1661 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1662 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1663 ID3DXBuffer_Release(buffer);
1667 IDirect3DTexture9_Release(texture);
1669 /* cube textures */
1670 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &cube_texture, NULL);
1671 if (FAILED(hr))
1673 skip("Failed to create cube texture\n");
1674 return;
1677 hr = D3DXFillCubeTexture(cube_texture, fill_cube_positive_x, NULL);
1678 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1680 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1681 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1682 if (SUCCEEDED(hr))
1684 IDirect3DSurface9 *surface;
1686 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1687 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1688 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1689 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1691 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1692 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1693 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1694 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1695 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1697 /* positive x face is saved */
1698 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1699 if (SUCCEEDED(hr))
1701 D3DLOCKED_RECT locked_rect;
1703 hr = D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, buffer_pointer, buffer_size, NULL, D3DX_FILTER_NONE, 0, NULL);
1704 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1706 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1707 if (SUCCEEDED(hr))
1709 DWORD *color = locked_rect.pBits;
1710 ok(*color == 0x00ff0000, "Got color %#x, expected %#x\n", *color, 0x00ff0000);
1711 IDirect3DSurface9_UnlockRect(surface);
1714 IDirect3DSurface9_Release(surface);
1715 } else skip("Failed to create surface\n");
1717 ID3DXBuffer_Release(buffer);
1720 todo_wine {
1721 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1722 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1723 if (SUCCEEDED(hr))
1725 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1726 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1727 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1728 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1730 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1731 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1732 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1733 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
1734 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1735 ID3DXBuffer_Release(buffer);
1739 IDirect3DCubeTexture9_Release(cube_texture);
1741 /* volume textures */
1742 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &volume_texture, NULL);
1743 if (FAILED(hr))
1745 skip("Failed to create volume texture\n");
1746 return;
1749 todo_wine {
1750 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1751 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1752 if (SUCCEEDED(hr))
1754 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1755 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1756 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1757 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1759 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1760 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1761 ok(info.Depth == 1, "Got depth %u, expected %u\n", info.Depth, 1);
1762 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1763 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1764 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1765 ID3DXBuffer_Release(buffer);
1768 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1769 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1770 if (SUCCEEDED(hr))
1772 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1773 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1774 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1775 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1777 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1778 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1779 ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256);
1780 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1781 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
1782 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1783 ID3DXBuffer_Release(buffer);
1787 IDirect3DVolumeTexture9_Release(volume_texture);
1790 START_TEST(texture)
1792 HWND wnd;
1793 IDirect3D9 *d3d;
1794 IDirect3DDevice9 *device;
1795 D3DPRESENT_PARAMETERS d3dpp;
1796 HRESULT hr;
1798 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1799 if (!wnd) {
1800 skip("Couldn't create application window\n");
1801 return;
1803 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1804 if (!d3d) {
1805 skip("Couldn't create IDirect3D9 object\n");
1806 DestroyWindow(wnd);
1807 return;
1810 ZeroMemory(&d3dpp, sizeof(d3dpp));
1811 d3dpp.Windowed = TRUE;
1812 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1813 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1814 if (FAILED(hr)) {
1815 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1816 IDirect3D9_Release(d3d);
1817 DestroyWindow(wnd);
1818 return;
1821 /* Check whether DXT5 textures are supported */
1822 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1823 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5);
1824 has_dxt5 = SUCCEEDED(hr);
1826 test_D3DXCheckTextureRequirements(device);
1827 test_D3DXCheckCubeTextureRequirements(device);
1828 test_D3DXCheckVolumeTextureRequirements(device);
1829 test_D3DXCreateTexture(device);
1830 test_D3DXFilterTexture(device);
1831 test_D3DXFillTexture(device);
1832 test_D3DXFillCubeTexture(device);
1833 test_D3DXFillVolumeTexture(device);
1834 test_D3DXCreateTextureFromFileInMemory(device);
1835 test_D3DXCreateTextureFromFileInMemoryEx(device);
1836 test_D3DXCreateCubeTextureFromFileInMemory(device);
1837 test_D3DXCreateCubeTextureFromFileInMemoryEx(device);
1838 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1839 test_D3DXSaveTextureToFileInMemory(device);
1841 IDirect3DDevice9_Release(device);
1842 IDirect3D9_Release(d3d);
1843 DestroyWindow(wnd);