d3dx9: Properly evaluate fallbacks for luminance texture formats in D3DXCheckTextureR...
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob61132bb8296b3497d6f053aa8e67b38a68b28e37
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_2d_dxt3, has_2d_dxt5, has_cube_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 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
308 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
309 expected = D3DFMT_X4R4G4B4;
310 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
311 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X1R5G5B5)))
312 expected = D3DFMT_X1R5G5B5;
313 else
314 expected = D3DFMT_R5G6B5;
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 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
344 mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L8)))
345 expected = D3DFMT_L8;
346 else
347 expected = D3DFMT_X8R8G8B8;
349 format = D3DFMT_L8;
350 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
351 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
352 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
354 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
355 mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L16)))
356 expected = D3DFMT_L16;
357 else
358 expected = D3DFMT_A16B16G16R16;
360 format = D3DFMT_L16;
361 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
362 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
363 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
365 /* Block-based texture formats and size < block size. */
366 if (has_2d_dxt5)
368 format = D3DFMT_DXT5;
369 width = 2; height = 2;
370 mipmaps = 1;
371 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, &format, D3DPOOL_DEFAULT);
372 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
373 ok(width == 4, "Returned width %d, expected %d\n", width, 4);
374 ok(height == 4, "Returned height %d, expected %d\n", height, 4);
375 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
376 ok(format == D3DFMT_DXT5, "Returned format %u, expected %u\n", format, D3DFMT_DXT5);
378 else
380 skip("D3DFMT_DXT5 textures are not supported, skipping a test.\n");
383 IDirect3D9_Release(d3d);
386 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
388 UINT size, mipmaps, expected;
389 D3DFORMAT format;
390 D3DCAPS9 caps;
391 HRESULT hr;
393 IDirect3DDevice9_GetDeviceCaps(device, &caps);
395 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
397 skip("No cube textures support\n");
398 return;
401 /* general tests */
402 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
403 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
405 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
406 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
408 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
409 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
411 /* size */
412 size = D3DX_DEFAULT;
413 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
414 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
415 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
417 /* mipmaps */
418 size = 64;
419 mipmaps = 9;
420 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
421 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
422 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
424 size = 284;
425 mipmaps = 20;
426 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
427 expected = caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP ? expected : 1;
428 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
429 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
430 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
432 size = 63;
433 mipmaps = 9;
434 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
435 expected = caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP ? expected : 1;
436 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
437 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
438 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
440 mipmaps = 0;
441 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
442 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
443 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
445 if (is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
447 mipmaps = 3;
448 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
449 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
450 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
452 else
453 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
455 /* usage */
456 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
457 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
458 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
459 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
460 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
461 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
462 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
463 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
464 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
465 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
467 /* format */
468 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
469 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
471 format = D3DFMT_UNKNOWN;
472 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
473 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
474 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
476 format = D3DX_DEFAULT;
477 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
478 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
479 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
481 format = D3DFMT_R8G8B8;
482 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
483 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
484 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
487 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
489 UINT width, height, depth, mipmaps, expected;
490 D3DFORMAT format;
491 D3DCAPS9 caps;
492 HRESULT hr;
494 IDirect3DDevice9_GetDeviceCaps(device, &caps);
496 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) || (caps.MaxVolumeExtent < 256))
498 skip("Limited or no volume textures support.\n");
499 return;
502 /* general tests */
503 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
504 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
506 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
507 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
509 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
510 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
512 /* width, height, depth */
513 width = height = depth = D3DX_DEFAULT;
514 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
515 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
516 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
517 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
518 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
520 width = D3DX_DEFAULT;
521 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
522 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
523 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
525 width = D3DX_DEFAULT; height = 0; depth = 0;
526 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
527 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
528 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
529 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
530 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
532 width = 0; height = 0; depth = 0;
533 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
534 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
535 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
536 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
537 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
539 width = 0;
540 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
541 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
542 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
544 width = 0xFFFFFFFE;
545 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
546 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
547 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
549 /* format */
550 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
551 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
553 format = D3DFMT_UNKNOWN;
554 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
555 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
556 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
558 format = D3DX_DEFAULT;
559 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
560 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
561 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
563 format = D3DFMT_R8G8B8;
564 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
565 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
566 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
568 /* mipmaps */
569 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
571 skip("No volume textures mipmapping support\n");
572 return;
575 width = height = depth = 64;
576 mipmaps = 9;
577 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
578 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
579 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
581 width = 284;
582 height = 143;
583 depth = 55;
584 mipmaps = 20;
585 expected = (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 && caps.MaxVolumeExtent >= 512) ? 10 : 9;
586 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
587 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
588 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
590 mipmaps = 0;
591 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
592 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
593 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
595 if (!is_autogenmipmap_supported(device, D3DRTYPE_VOLUMETEXTURE))
597 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
598 return;
601 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
602 mipmaps = 0;
603 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
604 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
605 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
606 mipmaps = 1;
607 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
608 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
609 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
610 mipmaps = 3;
611 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
612 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
613 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
616 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
618 IDirect3DTexture9 *texture;
619 D3DSURFACE_DESC desc;
620 D3DCAPS9 caps;
621 UINT mipmaps;
622 HRESULT hr;
624 IDirect3DDevice9_GetDeviceCaps(device, &caps);
626 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, D3DPOOL_DEFAULT, NULL);
627 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
629 /* width and height tests */
631 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
632 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
634 if (texture)
636 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
637 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
638 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
640 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
641 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
643 IDirect3DTexture9_Release(texture);
647 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
648 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
650 if (texture)
652 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
653 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
654 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
656 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
657 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
659 IDirect3DTexture9_Release(texture);
663 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
664 skip("Hardware only supports pow2 textures\n");
665 else
667 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
668 ok((hr == D3D_OK) ||
669 /* may not work with conditional NPOT */
670 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
671 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
673 if (texture)
675 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
676 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
677 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
679 /* Conditional NPOT may create a texture with different dimensions, so allow those
680 situations instead of returning a fail */
682 ok(desc.Width == 63 ||
683 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
684 "Returned width %d, expected %d\n", desc.Width, 63);
686 ok(desc.Height == 63 ||
687 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
688 "Returned height %d, expected %d\n", desc.Height, 63);
690 IDirect3DTexture9_Release(texture);
694 /* mipmaps */
696 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
697 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
699 if (texture)
701 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
702 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
704 IDirect3DTexture9_Release(texture);
708 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
709 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
711 if (texture)
713 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
714 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
716 IDirect3DTexture9_Release(texture);
720 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
721 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
723 if (texture)
725 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
726 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
728 IDirect3DTexture9_Release(texture);
732 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
733 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
735 if (texture)
737 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
738 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
740 IDirect3DTexture9_Release(texture);
743 /* usage */
745 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
746 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
747 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
748 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
749 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
750 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
751 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
752 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
753 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
754 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
756 /* format */
758 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
759 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
761 if (texture)
763 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
764 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
765 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
767 IDirect3DTexture9_Release(texture);
771 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
772 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
774 if (texture)
776 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
777 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
778 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
780 IDirect3DTexture9_Release(texture);
783 /* D3DXCreateTextureFromResource */
784 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
785 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
786 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
788 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
789 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
790 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
792 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
793 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
795 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
796 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
798 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
799 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
801 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
802 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
805 /* D3DXCreateTextureFromResourceEx */
806 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);
807 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
808 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
810 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);
811 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
813 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);
814 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
816 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
817 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
819 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);
820 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
823 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
825 IDirect3DTexture9 *tex;
826 IDirect3DCubeTexture9 *cubetex;
827 IDirect3DVolumeTexture9 *voltex;
828 HRESULT hr;
830 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
832 if (SUCCEEDED(hr))
834 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, D3DX_DEFAULT, D3DX_FILTER_NONE);
835 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
837 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
838 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
840 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
841 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
843 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
844 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
846 IDirect3DTexture9_Release(tex);
848 else
849 skip("Failed to create texture\n");
851 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
852 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
854 /* Test different pools */
855 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
857 if (SUCCEEDED(hr))
859 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
860 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
861 IDirect3DTexture9_Release(tex);
863 else
864 skip("Failed to create texture\n");
866 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
868 if (SUCCEEDED(hr))
870 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
871 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
872 IDirect3DTexture9_Release(tex);
874 else
875 skip("Failed to create texture\n");
877 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
878 if (SUCCEEDED(hr))
880 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
881 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
882 IDirect3DTexture9_Release(tex);
884 else
885 skip("Failed to create texture\n");
887 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
888 if (SUCCEEDED(hr))
890 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
891 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
892 IDirect3DTexture9_Release(tex);
894 else
895 skip("Failed to create texture\n");
897 /* Cube texture test */
898 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
900 if (SUCCEEDED(hr))
902 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
903 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
905 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
906 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
908 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
909 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
910 IDirect3DCubeTexture9_Release(cubetex);
912 else
913 skip("Failed to create texture\n");
915 /* Volume texture test */
916 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &voltex, NULL);
917 if (SUCCEEDED(hr))
919 DWORD level_count = IDirect3DVolumeTexture9_GetLevelCount(voltex);
921 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_NONE);
922 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
924 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_DEFAULT);
925 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
927 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_BOX);
928 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
930 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count - 1, D3DX_DEFAULT);
931 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
933 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count, D3DX_DEFAULT);
934 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
936 IDirect3DVolumeTexture9_Release(voltex);
938 else
939 skip("Failed to create volume texture\n");
941 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
942 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
944 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
945 return;
948 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
949 if (SUCCEEDED(hr))
951 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
952 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
953 IDirect3DTexture9_Release(tex);
955 else
956 skip("Failed to create texture\n");
958 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
959 if (SUCCEEDED(hr))
961 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
962 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
963 IDirect3DTexture9_Release(tex);
965 else
966 skip("Failed to create texture\n");
969 static BOOL color_match(const DWORD *value, const DWORD *expected)
971 int i;
973 for (i = 0; i < 4; i++)
975 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
976 if (diff > 1) return FALSE;
978 return TRUE;
981 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
982 const D3DXVECTOR2 *texelsize, void *data)
984 value->x = texcoord->x;
985 value->y = texcoord->y;
986 value->z = texelsize->x;
987 value->w = 1.0f;
990 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
992 IDirect3DTexture9 *tex;
993 HRESULT hr;
994 D3DLOCKED_RECT lock_rect;
995 DWORD x, y, m;
996 DWORD v[4], e[4];
997 DWORD value, expected, size, pitch;
999 size = 4;
1000 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
1001 D3DPOOL_MANAGED, &tex, NULL);
1003 if (SUCCEEDED(hr))
1005 hr = D3DXFillTexture(tex, fillfunc, NULL);
1006 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1008 for (m = 0; m < 3; m++)
1010 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
1011 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1012 if (SUCCEEDED(hr))
1014 pitch = lock_rect.Pitch / sizeof(DWORD);
1015 for (y = 0; y < size; y++)
1017 for (x = 0; x < size; x++)
1019 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1020 v[0] = (value >> 24) & 0xff;
1021 v[1] = (value >> 16) & 0xff;
1022 v[2] = (value >> 8) & 0xff;
1023 v[3] = value & 0xff;
1025 e[0] = 0xff;
1026 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1027 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1028 e[3] = 255.0f / size + 0.5f;
1029 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1031 ok(color_match(v, e),
1032 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1033 x, y, value, expected);
1036 IDirect3DTexture9_UnlockRect(tex, m);
1038 size >>= 1;
1041 IDirect3DTexture9_Release(tex);
1043 else
1044 skip("Failed to create texture\n");
1046 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1047 D3DPOOL_MANAGED, &tex, NULL);
1049 if (SUCCEEDED(hr))
1051 hr = D3DXFillTexture(tex, fillfunc, NULL);
1052 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1054 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1055 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1056 if (SUCCEEDED(hr))
1058 pitch = lock_rect.Pitch / sizeof(WORD);
1059 for (y = 0; y < 4; y++)
1061 for (x = 0; x < 4; x++)
1063 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1064 v[0] = value >> 15;
1065 v[1] = value >> 10 & 0x1f;
1066 v[2] = value >> 5 & 0x1f;
1067 v[3] = value & 0x1f;
1069 e[0] = 1;
1070 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
1071 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
1072 e[3] = 8;
1073 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1075 ok(color_match(v, e),
1076 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1077 x, y, value, expected);
1080 IDirect3DTexture9_UnlockRect(tex, 0);
1083 IDirect3DTexture9_Release(tex);
1085 else
1086 skip("Failed to create texture\n");
1088 /* test floating-point textures */
1089 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A16B16G16R16F,
1090 D3DPOOL_MANAGED, &tex, NULL);
1092 if (SUCCEEDED(hr))
1094 hr = D3DXFillTexture(tex, fillfunc, NULL);
1095 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1097 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1098 if (SUCCEEDED(hr))
1100 pitch = lock_rect.Pitch / sizeof(WORD);
1101 for (y = 0; y < 4; y++)
1103 WORD *ptr = (WORD *)lock_rect.pBits + y * pitch;
1104 for (x = 0; x < 4; x++)
1106 D3DXVECTOR4 got, expected;
1108 D3DXFloat16To32Array((FLOAT *)&got, (D3DXFLOAT16 *)ptr, 4);
1109 ptr += 4;
1111 expected.x = (x + 0.5f) / 4.0f;
1112 expected.y = (y + 0.5f) / 4.0f;
1113 expected.z = 1.0f / 4.0f;
1114 expected.w = 1.0f;
1116 expect_vec4(&expected, &got);
1120 IDirect3DTexture9_UnlockRect(tex, 0);
1122 else
1123 skip("Failed to lock texture\n");
1125 IDirect3DTexture9_Release(tex);
1127 else
1128 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1130 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A32B32G32R32F,
1131 D3DPOOL_MANAGED, &tex, NULL);
1133 if (SUCCEEDED(hr))
1135 hr = D3DXFillTexture(tex, fillfunc, NULL);
1136 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1138 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1139 if (SUCCEEDED(hr))
1141 pitch = lock_rect.Pitch / sizeof(float);
1142 for (y = 0; y < 4; y++)
1144 float *ptr = (float *)lock_rect.pBits + y * pitch;
1145 for (x = 0; x < 4; x++)
1147 D3DXVECTOR4 got, expected;
1149 got.x = *ptr++;
1150 got.y = *ptr++;
1151 got.z = *ptr++;
1152 got.w = *ptr++;
1154 expected.x = (x + 0.5f) / 4.0f;
1155 expected.y = (y + 0.5f) / 4.0f;
1156 expected.z = 1.0f / 4.0f;
1157 expected.w = 1.0f;
1159 expect_vec4(&expected, &got);
1163 IDirect3DTexture9_UnlockRect(tex, 0);
1165 else
1166 skip("Failed to lock texture\n");
1168 IDirect3DTexture9_Release(tex);
1170 else
1171 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1173 /* test a compressed texture */
1174 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1,
1175 D3DPOOL_MANAGED, &tex, NULL);
1177 if (SUCCEEDED(hr))
1179 hr = D3DXFillTexture(tex, fillfunc, NULL);
1180 todo_wine ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1182 IDirect3DTexture9_Release(tex);
1184 else
1185 skip("Failed to create D3DFMT_DXT1 texture\n");
1188 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1189 const D3DXVECTOR3 *texelsize, void *data)
1191 value->x = (texcoord->x + 1.0f) / 2.0f;
1192 value->y = (texcoord->y + 1.0f) / 2.0f;
1193 value->z = (texcoord->z + 1.0f) / 2.0f;
1194 value->w = texelsize->x;
1197 enum cube_coord
1199 XCOORD = 0,
1200 XCOORDINV = 1,
1201 YCOORD = 2,
1202 YCOORDINV = 3,
1203 ZERO = 4,
1204 ONE = 5
1207 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1209 switch (coord)
1211 case XCOORD:
1212 return x + 0.5f;
1213 case XCOORDINV:
1214 return size - x - 0.5f;
1215 case YCOORD:
1216 return y + 0.5f;
1217 case YCOORDINV:
1218 return size - y - 0.5f;
1219 case ZERO:
1220 return 0.0f;
1221 case ONE:
1222 return size;
1223 default:
1224 trace("Unexpected coordinate value\n");
1225 return 0.0f;
1229 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
1231 IDirect3DCubeTexture9 *tex;
1232 HRESULT hr;
1233 D3DLOCKED_RECT lock_rect;
1234 DWORD x, y, f, m;
1235 DWORD v[4], e[4];
1236 DWORD value, expected, size, pitch;
1237 enum cube_coord coordmap[6][3] =
1239 {ONE, YCOORDINV, XCOORDINV},
1240 {ZERO, YCOORDINV, XCOORD},
1241 {XCOORD, ONE, YCOORD},
1242 {XCOORD, ZERO, YCOORDINV},
1243 {XCOORD, YCOORDINV, ONE},
1244 {XCOORDINV, YCOORDINV, ZERO}
1247 size = 4;
1248 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1249 D3DPOOL_MANAGED, &tex, NULL);
1251 if (SUCCEEDED(hr))
1253 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1254 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1256 for (m = 0; m < 3; m++)
1258 for (f = 0; f < 6; f++)
1260 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1261 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1262 if (SUCCEEDED(hr))
1264 pitch = lock_rect.Pitch / sizeof(DWORD);
1265 for (y = 0; y < size; y++)
1267 for (x = 0; x < size; x++)
1269 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1270 v[0] = (value >> 24) & 0xff;
1271 v[1] = (value >> 16) & 0xff;
1272 v[2] = (value >> 8) & 0xff;
1273 v[3] = value & 0xff;
1275 e[0] = (f == 0) || (f == 1) ?
1276 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1277 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1278 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1279 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1280 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1282 ok(color_match(v, e),
1283 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1284 f, x, y, value, expected);
1287 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1290 size >>= 1;
1293 IDirect3DCubeTexture9_Release(tex);
1295 else
1296 skip("Failed to create texture\n");
1298 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1299 D3DPOOL_MANAGED, &tex, NULL);
1301 if (SUCCEEDED(hr))
1303 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1304 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1305 for (f = 0; f < 6; f++)
1307 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1308 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1309 if (SUCCEEDED(hr))
1311 pitch = lock_rect.Pitch / sizeof(WORD);
1312 for (y = 0; y < 4; y++)
1314 for (x = 0; x < 4; x++)
1316 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1317 v[0] = value >> 15;
1318 v[1] = value >> 10 & 0x1f;
1319 v[2] = value >> 5 & 0x1f;
1320 v[3] = value & 0x1f;
1322 e[0] = (f == 0) || (f == 1) ?
1323 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1324 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1325 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1326 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1327 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1329 ok(color_match(v, e),
1330 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1331 f, x, y, value, expected);
1334 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1338 IDirect3DCubeTexture9_Release(tex);
1340 else
1341 skip("Failed to create texture\n");
1344 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1345 const D3DXVECTOR3 *texelsize, void *data)
1347 value->x = texcoord->x;
1348 value->y = texcoord->y;
1349 value->z = texcoord->z;
1350 value->w = texelsize->x;
1353 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1355 IDirect3DVolumeTexture9 *tex;
1356 HRESULT hr;
1357 D3DLOCKED_BOX lock_box;
1358 DWORD x, y, z, m;
1359 DWORD v[4], e[4];
1360 DWORD value, expected, size, row_pitch, slice_pitch;
1362 size = 4;
1363 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1364 D3DPOOL_MANAGED, &tex, NULL);
1366 if (SUCCEEDED(hr))
1368 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1369 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1371 for (m = 0; m < 3; m++)
1373 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1374 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1375 if (SUCCEEDED(hr))
1377 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1378 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1379 for (z = 0; z < size; z++)
1381 for (y = 0; y < size; y++)
1383 for (x = 0; x < size; x++)
1385 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1386 v[0] = (value >> 24) & 0xff;
1387 v[1] = (value >> 16) & 0xff;
1388 v[2] = (value >> 8) & 0xff;
1389 v[3] = value & 0xff;
1391 e[0] = 255.0f / size + 0.5f;
1392 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1393 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1394 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1395 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1397 ok(color_match(v, e),
1398 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1399 x, y, z, value, expected);
1403 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1405 size >>= 1;
1408 IDirect3DVolumeTexture9_Release(tex);
1410 else
1411 skip("Failed to create texture\n");
1413 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1414 D3DPOOL_MANAGED, &tex, NULL);
1416 if (SUCCEEDED(hr))
1418 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1419 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1420 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1421 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1422 if (SUCCEEDED(hr))
1424 row_pitch = lock_box.RowPitch / sizeof(WORD);
1425 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1426 for (z = 0; z < 4; z++)
1428 for (y = 0; y < 4; y++)
1430 for (x = 0; x < 4; x++)
1432 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1433 v[0] = value >> 15;
1434 v[1] = value >> 10 & 0x1f;
1435 v[2] = value >> 5 & 0x1f;
1436 v[3] = value & 0x1f;
1438 e[0] = 1;
1439 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1440 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1441 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1442 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1444 ok(color_match(v, e),
1445 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1446 x, y, z, value, expected);
1450 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1453 IDirect3DVolumeTexture9_Release(tex);
1455 else
1456 skip("Failed to create texture\n");
1459 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1461 HRESULT hr;
1462 IDirect3DTexture9 *texture;
1463 D3DRESOURCETYPE type;
1464 D3DSURFACE_DESC desc;
1465 D3DLOCKED_RECT lock_rect;
1466 int i;
1467 DWORD level_count;
1469 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1470 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1471 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1473 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1474 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1475 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1477 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1478 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1480 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1481 hr = D3DXCreateTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &texture);
1482 if (has_2d_dxt5)
1483 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1484 else
1485 todo_wine ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1486 if (SUCCEEDED(hr))
1488 type = IDirect3DTexture9_GetType(texture);
1489 ok(type == D3DRTYPE_TEXTURE, "IDirect3DTexture9_GetType returned %u, expected %u\n", type, D3DRTYPE_TEXTURE);
1490 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
1491 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1492 ok(desc.Width == 4, "Width is %u, expected 4\n", desc.Width);
1493 ok(desc.Height == 4, "Height is %u, expected 4\n", desc.Height);
1494 hr = IDirect3DTexture9_LockRect(texture, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1495 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %#x, expected %#x\n", hr, D3D_OK);
1496 if (SUCCEEDED(hr))
1498 for (i = 0; i < 16; i++)
1499 ok(((BYTE *)lock_rect.pBits)[i] == dds_cube_map[128 + i],
1500 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1501 i, ((BYTE *)lock_rect.pBits)[i], dds_cube_map[128 + i]);
1502 IDirect3DTexture9_UnlockRect(texture, 0);
1504 IDirect3DTexture9_Release(texture);
1508 /* Volume textures work too. */
1509 hr = D3DXCreateTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &texture);
1510 if (has_2d_dxt3)
1511 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1512 else
1513 todo_wine ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1514 if (SUCCEEDED(hr))
1516 type = IDirect3DTexture9_GetType(texture);
1517 ok(type == D3DRTYPE_TEXTURE, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type, D3DRTYPE_TEXTURE);
1518 level_count = IDirect3DBaseTexture9_GetLevelCount((IDirect3DBaseTexture9 *)texture);
1519 todo_wine ok(level_count == 3, "Texture has %u mip levels, 3 expected.\n", level_count);
1520 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
1521 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x.\n", hr, D3D_OK);
1522 ok(desc.Width == 4, "Width is %u, expected 4.\n", desc.Width);
1523 ok(desc.Height == 4, "Height is %u, expected 4.\n", desc.Height);
1525 hr = IDirect3DTexture9_LockRect(texture, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1526 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %#x, expected %#x.\n", hr, D3D_OK);
1527 if (SUCCEEDED(hr))
1529 for (i = 0; i < 16; ++i)
1530 ok(((BYTE *)lock_rect.pBits)[i] == dds_volume_map[128 + i],
1531 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1532 i, ((BYTE *)lock_rect.pBits)[i], dds_volume_map[128 + i]);
1533 IDirect3DTexture9_UnlockRect(texture, 0);
1535 /* The lower texture levels are apparently generated by filtering the level 0 surface
1536 * I.e. following levels from the file are ignored. */
1537 IDirect3DTexture9_Release(texture);
1541 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1543 HRESULT hr;
1544 IDirect3DTexture9 *texture;
1545 unsigned int miplevels;
1546 IDirect3DSurface9 *surface;
1547 D3DSURFACE_DESC desc;
1549 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1550 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1551 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1552 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1554 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1555 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1556 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1557 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1559 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit), D3DX_DEFAULT,
1560 D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1561 D3DX_DEFAULT, D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_FILTER_POINT), 0, NULL, NULL, &texture);
1562 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1563 if (SUCCEEDED(hr))
1565 miplevels = IDirect3DTexture9_GetLevelCount(texture);
1566 ok(miplevels == 1, "Got miplevels %u, expected %u\n", miplevels, 1);
1567 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1568 IDirect3DSurface9_GetDesc(surface, &desc);
1569 ok(desc.Width == 1 && desc.Height == 1,
1570 "Surface dimensions are %ux%u, expected 1x1.\n", desc.Width, desc.Height);
1571 IDirect3DSurface9_Release(surface);
1572 IDirect3DTexture9_Release(texture);
1575 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
1577 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1578 return;
1581 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1582 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1583 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1584 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1587 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1589 HRESULT hr;
1590 ULONG ref;
1591 DWORD levelcount;
1592 IDirect3DCubeTexture9 *cube_texture;
1593 D3DSURFACE_DESC surface_desc;
1595 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1596 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1598 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1599 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1601 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1602 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1604 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1605 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1607 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1608 if (SUCCEEDED(hr))
1610 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1611 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1613 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1614 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1615 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1616 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1618 ref = IDirect3DCubeTexture9_Release(cube_texture);
1619 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1620 } else skip("Couldn't create cube texture\n");
1623 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1625 HRESULT hr;
1626 IDirect3DCubeTexture9 *cube_texture;
1628 if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
1630 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1631 return;
1634 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT,
1635 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
1636 if (has_cube_dxt5)
1637 ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1638 else
1639 todo_wine ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1640 if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture);
1643 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1645 HRESULT hr;
1646 ULONG ref;
1647 DWORD levelcount;
1648 IDirect3DVolumeTexture9 *volume_texture;
1649 D3DVOLUME_DESC volume_desc;
1651 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1652 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1654 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1655 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1657 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1658 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1660 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1661 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1663 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1664 if (has_2d_dxt3)
1665 ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1666 else
1667 todo_wine ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1668 if (SUCCEEDED(hr))
1670 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1671 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1673 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1674 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1675 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1676 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1677 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1679 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1680 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1681 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1682 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1683 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1685 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1686 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1690 /* fills positive x face with red color */
1691 static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data)
1693 memset(out, 0, sizeof(*out));
1694 if (tex_coord->x > 0 && fabs(tex_coord->x) > fabs(tex_coord->y) && fabs(tex_coord->x) > fabs(tex_coord->z))
1695 out->x = 1;
1698 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device)
1700 HRESULT hr;
1701 IDirect3DTexture9 *texture;
1702 IDirect3DCubeTexture9 *cube_texture;
1703 IDirect3DVolumeTexture9 *volume_texture;
1704 ID3DXBuffer *buffer;
1705 void *buffer_pointer;
1706 DWORD buffer_size;
1707 D3DXIMAGE_INFO info;
1708 D3DXIMAGE_FILEFORMAT file_format;
1710 /* textures */
1711 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
1712 if (FAILED(hr))
1714 skip("Failed to create texture\n");
1715 return;
1718 for (file_format = D3DXIFF_BMP; file_format <= D3DXIFF_JPG; file_format++)
1720 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, (IDirect3DBaseTexture9 *)texture, NULL);
1721 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1722 if (SUCCEEDED(hr))
1724 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1725 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1726 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1727 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1729 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1730 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1731 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1732 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1733 ok(info.ImageFileFormat == file_format, "Got file format %#x, expected %#x\n", info.ImageFileFormat, file_format);
1734 ID3DXBuffer_Release(buffer);
1738 todo_wine {
1739 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)texture, NULL);
1740 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1741 if (SUCCEEDED(hr))
1743 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1744 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1745 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1746 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1748 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1749 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1750 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1751 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1752 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1753 ID3DXBuffer_Release(buffer);
1757 IDirect3DTexture9_Release(texture);
1759 /* cube textures */
1760 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &cube_texture, NULL);
1761 if (FAILED(hr))
1763 skip("Failed to create cube texture\n");
1764 return;
1767 hr = D3DXFillCubeTexture(cube_texture, fill_cube_positive_x, NULL);
1768 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1770 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1771 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1772 if (SUCCEEDED(hr))
1774 IDirect3DSurface9 *surface;
1776 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1777 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1778 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1779 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1781 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1782 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1783 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1784 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1785 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1787 /* positive x face is saved */
1788 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1789 if (SUCCEEDED(hr))
1791 D3DLOCKED_RECT locked_rect;
1793 hr = D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, buffer_pointer, buffer_size, NULL, D3DX_FILTER_NONE, 0, NULL);
1794 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1796 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1797 if (SUCCEEDED(hr))
1799 DWORD *color = locked_rect.pBits;
1800 ok(*color == 0x00ff0000, "Got color %#x, expected %#x\n", *color, 0x00ff0000);
1801 IDirect3DSurface9_UnlockRect(surface);
1804 IDirect3DSurface9_Release(surface);
1805 } else skip("Failed to create surface\n");
1807 ID3DXBuffer_Release(buffer);
1810 todo_wine {
1811 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1812 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1813 if (SUCCEEDED(hr))
1815 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1816 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1817 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1818 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1820 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1821 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1822 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1823 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
1824 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1825 ID3DXBuffer_Release(buffer);
1829 IDirect3DCubeTexture9_Release(cube_texture);
1831 /* volume textures */
1832 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &volume_texture, NULL);
1833 if (FAILED(hr))
1835 skip("Failed to create volume texture\n");
1836 return;
1839 todo_wine {
1840 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1841 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1842 if (SUCCEEDED(hr))
1844 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1845 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1846 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1847 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1849 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1850 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1851 ok(info.Depth == 1, "Got depth %u, expected %u\n", info.Depth, 1);
1852 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1853 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1854 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1855 ID3DXBuffer_Release(buffer);
1858 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1859 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1860 if (SUCCEEDED(hr))
1862 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1863 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1864 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1865 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1867 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1868 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1869 ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256);
1870 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1871 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
1872 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1873 ID3DXBuffer_Release(buffer);
1877 IDirect3DVolumeTexture9_Release(volume_texture);
1880 START_TEST(texture)
1882 HWND wnd;
1883 IDirect3D9 *d3d;
1884 IDirect3DDevice9 *device;
1885 D3DPRESENT_PARAMETERS d3dpp;
1886 HRESULT hr;
1888 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
1889 640, 480, NULL, NULL, NULL, NULL)))
1891 skip("Couldn't create application window\n");
1892 return;
1894 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1895 if (!d3d) {
1896 skip("Couldn't create IDirect3D9 object\n");
1897 DestroyWindow(wnd);
1898 return;
1901 ZeroMemory(&d3dpp, sizeof(d3dpp));
1902 d3dpp.Windowed = TRUE;
1903 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1904 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1905 if (FAILED(hr)) {
1906 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1907 IDirect3D9_Release(d3d);
1908 DestroyWindow(wnd);
1909 return;
1912 /* Check whether DXTn textures are supported. */
1913 has_2d_dxt3 = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1914 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3));
1915 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1916 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5);
1917 has_2d_dxt5 = SUCCEEDED(hr);
1918 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
1919 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, D3DFMT_DXT5);
1920 has_cube_dxt5 = SUCCEEDED(hr);
1922 test_D3DXCheckTextureRequirements(device);
1923 test_D3DXCheckCubeTextureRequirements(device);
1924 test_D3DXCheckVolumeTextureRequirements(device);
1925 test_D3DXCreateTexture(device);
1926 test_D3DXFilterTexture(device);
1927 test_D3DXFillTexture(device);
1928 test_D3DXFillCubeTexture(device);
1929 test_D3DXFillVolumeTexture(device);
1930 test_D3DXCreateTextureFromFileInMemory(device);
1931 test_D3DXCreateTextureFromFileInMemoryEx(device);
1932 test_D3DXCreateCubeTextureFromFileInMemory(device);
1933 test_D3DXCreateCubeTextureFromFileInMemoryEx(device);
1934 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1935 test_D3DXSaveTextureToFileInMemory(device);
1937 IDirect3DDevice9_Release(device);
1938 IDirect3D9_Release(d3d);
1939 DestroyWindow(wnd);