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
24 #include "wine/test.h"
26 #include "resources.h"
28 static int has_2d_dxt3
, has_2d_dxt5
, has_cube_dxt5
, has_3d_dxt3
;
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 static const unsigned char png_grayscale
[] =
92 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
93 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
94 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
95 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
96 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
100 #define ADMITTED_ERROR 0.0001f
102 static inline float relative_error(float expected
, float got
)
104 return expected
== 0.0f
? fabs(expected
- got
) : fabs(1.0f
- got
/ expected
);
107 #define expect_vec4(expected, got) expect_vec4_(__LINE__, expected, got)
108 static inline void expect_vec4_(unsigned int line
, const D3DXVECTOR4
*expected
, const D3DXVECTOR4
*got
)
110 ok_(__FILE__
, line
)(relative_error(expected
->x
, got
->x
) < ADMITTED_ERROR
111 && relative_error(expected
->y
, got
->y
) < ADMITTED_ERROR
112 && relative_error(expected
->z
, got
->z
) < ADMITTED_ERROR
113 && relative_error(expected
->w
, got
->w
) < ADMITTED_ERROR
,
114 "Expected (%f, %f, %f, %f), got (%f, %f, %f, %f)\n",
115 expected
->x
, expected
->y
, expected
->z
, expected
->w
,
116 got
->x
, got
->y
, got
->z
, got
->w
);
119 static BOOL
compare_color(DWORD c1
, DWORD c2
, BYTE max_diff
)
121 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
124 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
127 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
130 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
)
135 static BOOL
is_autogenmipmap_supported(IDirect3DDevice9
*device
, D3DRESOURCETYPE resource_type
)
141 D3DDEVICE_CREATION_PARAMETERS params
;
143 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
144 IDirect3DDevice9_GetDirect3D(device
, &d3d9
);
145 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
146 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
148 if (!(caps
.Caps2
& D3DCAPS2_CANAUTOGENMIPMAP
))
151 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, params
.AdapterOrdinal
, params
.DeviceType
,
152 mode
.Format
, D3DUSAGE_AUTOGENMIPMAP
, resource_type
, D3DFMT_A8R8G8B8
);
154 IDirect3D9_Release(d3d9
);
155 return SUCCEEDED(hr
);
158 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9
*device
)
160 UINT width
, height
, mipmaps
;
161 D3DFORMAT format
, expected
;
165 D3DDEVICE_CREATION_PARAMETERS params
;
168 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
171 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
172 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
174 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
175 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
177 hr
= D3DXCheckTextureRequirements(NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
178 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
181 width
= height
= D3DX_DEFAULT
;
182 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
183 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
184 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
185 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
187 width
= D3DX_DEFAULT
;
188 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
189 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
190 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
192 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
193 skip("Hardware only supports pow2 textures\n");
197 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
198 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
199 ok(width
== 62, "Returned width %d, expected %d\n", width
, 62);
201 width
= D3DX_DEFAULT
; height
= 63;
202 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
203 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
204 ok(width
== height
, "Returned width %d, expected %d\n", width
, height
);
205 ok(height
== 63, "Returned height %d, expected %d\n", height
, 63);
208 width
= D3DX_DEFAULT
; height
= 0;
209 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
210 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
211 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
212 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
214 width
= 0; height
= 0;
215 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
216 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
217 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
218 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
221 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
222 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
223 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
226 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
227 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
228 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
);
230 width
= caps
.MaxTextureWidth
-1;
231 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
232 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
233 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
234 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
);
236 ok(width
== caps
.MaxTextureWidth
-1, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
-1);
239 width
= 64; height
= 63;
241 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
242 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
243 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
245 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
))
247 width
= 284; height
= 137;
249 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
250 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
251 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
255 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
256 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
257 ok(mipmaps
== 6, "Returned mipmaps %d, expected %d\n", mipmaps
, 6);
260 skip("Skipping some tests, npot2 textures unsupported\n");
263 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
264 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
265 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
268 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
269 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
270 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
272 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
273 if (is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
276 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
277 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
278 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
280 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
281 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
282 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
284 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
285 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
286 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
288 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
289 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
290 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
293 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
296 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
297 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
298 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
299 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
300 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
301 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
302 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
303 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
304 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
305 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
308 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
309 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
311 format
= D3DFMT_UNKNOWN
;
312 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
313 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
314 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
316 format
= D3DX_DEFAULT
;
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
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
321 format
= D3DFMT_R8G8B8
;
322 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
323 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
324 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
326 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
327 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
328 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
330 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
331 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_R3G3B2
)))
332 expected
= D3DFMT_R3G3B2
;
333 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
334 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X4R4G4B4
)))
335 expected
= D3DFMT_X4R4G4B4
;
336 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
337 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X1R5G5B5
)))
338 expected
= D3DFMT_X1R5G5B5
;
340 expected
= D3DFMT_R5G6B5
;
342 format
= D3DFMT_R3G3B2
;
343 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
344 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
345 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
347 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
348 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R3G3B2
)))
349 expected
= D3DFMT_A8R3G3B2
;
351 expected
= D3DFMT_A8R8G8B8
;
353 format
= D3DFMT_A8R3G3B2
;
354 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
355 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
356 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
358 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
359 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_P8
)))
360 expected
= D3DFMT_P8
;
362 expected
= D3DFMT_A8R8G8B8
;
365 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
366 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
367 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
369 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
370 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L8
)))
371 expected
= D3DFMT_L8
;
373 expected
= D3DFMT_X8R8G8B8
;
376 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
377 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
378 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
380 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
381 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L16
)))
382 expected
= D3DFMT_L16
;
384 expected
= D3DFMT_A16B16G16R16
;
387 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
388 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
389 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
391 /* Block-based texture formats and size < block size. */
394 format
= D3DFMT_DXT5
;
395 width
= 2; height
= 2;
397 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
398 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
399 ok(width
== 4, "Returned width %d, expected %d\n", width
, 4);
400 ok(height
== 4, "Returned height %d, expected %d\n", height
, 4);
401 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
402 ok(format
== D3DFMT_DXT5
, "Returned format %u, expected %u\n", format
, D3DFMT_DXT5
);
406 skip("D3DFMT_DXT5 textures are not supported, skipping a test.\n");
409 IDirect3D9_Release(d3d
);
412 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9
*device
)
414 UINT size
, mipmaps
, expected
;
419 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
421 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
423 skip("No cube textures support\n");
428 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
429 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
431 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
432 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
434 hr
= D3DXCheckCubeTextureRequirements(NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
435 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
439 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
440 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
441 ok(size
== 256, "Returned size %d, expected %d\n", size
, 256);
446 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
447 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
448 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
452 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 10 : 9;
453 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
454 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
455 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
456 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
460 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 7 : 6;
461 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
462 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
463 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
464 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
467 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
468 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
469 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
471 if (is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
474 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
475 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
476 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
479 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
482 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
483 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
484 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
485 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
486 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
487 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
488 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
489 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
490 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
491 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
494 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
495 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
497 format
= D3DFMT_UNKNOWN
;
498 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
499 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
500 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
502 format
= D3DX_DEFAULT
;
503 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
504 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
505 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
507 format
= D3DFMT_R8G8B8
;
508 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
509 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
510 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
513 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9
*device
)
515 UINT width
, height
, depth
, mipmaps
, expected
;
520 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
522 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
) || (caps
.MaxVolumeExtent
< 256))
524 skip("Limited or no volume textures support.\n");
529 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
530 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
532 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
533 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
535 hr
= D3DXCheckVolumeTextureRequirements(NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
536 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
538 /* width, height, depth */
539 width
= height
= depth
= D3DX_DEFAULT
;
540 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
541 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
542 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
543 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
544 ok(depth
== 1, "Returned depth %d, expected %d\n", depth
, 1);
546 width
= D3DX_DEFAULT
;
547 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
548 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
549 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
551 width
= D3DX_DEFAULT
; height
= 0; depth
= 0;
552 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
553 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
554 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
555 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
556 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
558 width
= 0; height
= 0; depth
= 0;
559 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
560 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
561 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
562 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
563 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
566 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
567 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
568 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
571 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
572 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
573 ok(width
== caps
.MaxVolumeExtent
, "Returned width %d, expected %d\n", width
, caps
.MaxVolumeExtent
);
576 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
577 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
579 format
= D3DFMT_UNKNOWN
;
580 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
581 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
582 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
584 format
= D3DX_DEFAULT
;
585 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
586 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
587 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
589 format
= D3DFMT_R8G8B8
;
590 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
591 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
592 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
594 format
= D3DFMT_DXT3
;
595 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
596 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
598 ok(format
== D3DFMT_DXT3
, "Returned format %u, expected %u\n", format
, D3DFMT_DXT3
);
600 todo_wine
ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
603 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
605 skip("No volume textures mipmapping support\n");
609 width
= height
= depth
= 64;
611 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
612 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
613 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
619 expected
= (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
&& caps
.MaxVolumeExtent
>= 512) ? 10 : 9;
620 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
621 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
622 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
625 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
626 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
627 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
629 if (!is_autogenmipmap_supported(device
, D3DRTYPE_VOLUMETEXTURE
))
631 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
635 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
637 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
638 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
639 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
641 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
642 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
643 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
645 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
646 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
647 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
650 static void test_D3DXCreateTexture(IDirect3DDevice9
*device
)
652 IDirect3DTexture9
*texture
;
653 D3DSURFACE_DESC desc
;
658 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
660 hr
= D3DXCreateTexture(NULL
, 0, 0, 0, 0, D3DX_DEFAULT
, D3DPOOL_DEFAULT
, NULL
);
661 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
663 /* width and height tests */
665 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, 0, D3DPOOL_DEFAULT
, &texture
);
666 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
670 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
671 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
672 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
674 ok(desc
.Width
== 256, "Returned width %d, expected %d\n", desc
.Width
, 256);
675 ok(desc
.Height
== 256, "Returned height %d, expected %d\n", desc
.Height
, 256);
677 IDirect3DTexture9_Release(texture
);
681 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
682 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
686 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
687 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
688 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
690 ok(desc
.Width
== 1, "Returned width %d, expected %d\n", desc
.Width
, 1);
691 ok(desc
.Height
== 1, "Returned height %d, expected %d\n", desc
.Height
, 1);
693 IDirect3DTexture9_Release(texture
);
697 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
698 skip("Hardware only supports pow2 textures\n");
701 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, 63, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
703 /* may not work with conditional NPOT */
704 ((hr
!= D3D_OK
) && (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)),
705 "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
709 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
710 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
711 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
713 /* Conditional NPOT may create a texture with different dimensions, so allow those
714 situations instead of returning a fail */
716 ok(desc
.Width
== 63 ||
717 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
718 "Returned width %d, expected %d\n", desc
.Width
, 63);
720 ok(desc
.Height
== 63 ||
721 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
722 "Returned height %d, expected %d\n", desc
.Height
, 63);
724 IDirect3DTexture9_Release(texture
);
730 hr
= D3DXCreateTexture(device
, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
731 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
735 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
736 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
738 IDirect3DTexture9_Release(texture
);
742 hr
= D3DXCreateTexture(device
, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
743 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
747 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
748 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
750 IDirect3DTexture9_Release(texture
);
754 hr
= D3DXCreateTexture(device
, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT
, &texture
);
755 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
759 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
760 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
762 IDirect3DTexture9_Release(texture
);
766 hr
= D3DXCreateTexture(device
, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT
, &texture
);
767 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
771 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
772 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
774 IDirect3DTexture9_Release(texture
);
779 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &texture
);
780 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
781 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_DONOTCLIP
, 0, D3DPOOL_DEFAULT
, &texture
);
782 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
783 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_POINTS
, 0, D3DPOOL_DEFAULT
, &texture
);
784 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
785 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_RTPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
786 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
787 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_NPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
788 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
792 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, &texture
);
793 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
797 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
798 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
799 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
801 IDirect3DTexture9_Release(texture
);
805 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
806 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
810 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
811 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
812 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
814 IDirect3DTexture9_Release(texture
);
817 /* D3DXCreateTextureFromResource */
818 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &texture
);
819 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
820 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
822 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
823 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
824 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
826 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDS_STRING
), &texture
);
827 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
829 hr
= D3DXCreateTextureFromResourceA(NULL
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
830 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
832 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, NULL
, &texture
);
833 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
835 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
);
836 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
839 /* D3DXCreateTextureFromResourceEx */
840 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
);
841 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3D_OK
);
842 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
844 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
);
845 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
847 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
);
848 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
850 hr
= D3DXCreateTextureFromResourceExA(device
, NULL
, NULL
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_MANAGED
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
851 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
853 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
);
854 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
857 static void test_D3DXFilterTexture(IDirect3DDevice9
*device
)
859 IDirect3DTexture9
*tex
;
860 IDirect3DCubeTexture9
*cubetex
;
861 IDirect3DVolumeTexture9
*voltex
;
864 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex
, NULL
);
868 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, D3DX_DEFAULT
, D3DX_FILTER_NONE
);
869 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
871 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
872 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
874 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
875 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
877 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
878 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
880 IDirect3DTexture9_Release(tex
);
883 skip("Failed to create texture\n");
885 hr
= D3DXFilterTexture(NULL
, NULL
, 0, D3DX_FILTER_NONE
);
886 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
888 /* Test different pools */
889 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
893 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
894 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
895 IDirect3DTexture9_Release(tex
);
898 skip("Failed to create texture\n");
900 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &tex
, NULL
);
904 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
905 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
906 IDirect3DTexture9_Release(tex
);
909 skip("Failed to create texture\n");
911 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
914 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
915 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
916 IDirect3DTexture9_Release(tex
);
919 skip("Failed to create texture\n");
921 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
924 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
925 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
926 IDirect3DTexture9_Release(tex
);
929 skip("Failed to create texture\n");
931 /* Cube texture test */
932 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &cubetex
, NULL
);
936 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_NONE
);
937 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
939 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
940 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
942 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
943 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
944 IDirect3DCubeTexture9_Release(cubetex
);
947 skip("Failed to create texture\n");
949 /* Volume texture test */
950 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &voltex
, NULL
);
953 DWORD level_count
= IDirect3DVolumeTexture9_GetLevelCount(voltex
);
955 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_NONE
);
956 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
958 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_DEFAULT
);
959 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
961 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_BOX
);
962 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
964 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
- 1, D3DX_DEFAULT
);
965 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
967 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
, D3DX_DEFAULT
);
968 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
970 IDirect3DVolumeTexture9_Release(voltex
);
973 skip("Failed to create volume texture\n");
975 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
976 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
978 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
982 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
985 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
986 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
987 IDirect3DTexture9_Release(tex
);
990 skip("Failed to create texture\n");
992 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
995 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
996 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
997 IDirect3DTexture9_Release(tex
);
1000 skip("Failed to create texture\n");
1003 static BOOL
color_match(const DWORD
*value
, const DWORD
*expected
)
1007 for (i
= 0; i
< 4; i
++)
1009 DWORD diff
= value
[i
] > expected
[i
] ? value
[i
] - expected
[i
] : expected
[i
] - value
[i
];
1010 if (diff
> 1) return FALSE
;
1015 static void WINAPI
fillfunc(D3DXVECTOR4
*value
, const D3DXVECTOR2
*texcoord
,
1016 const D3DXVECTOR2
*texelsize
, void *data
)
1018 value
->x
= texcoord
->x
;
1019 value
->y
= texcoord
->y
;
1020 value
->z
= texelsize
->x
;
1024 static void test_D3DXFillTexture(IDirect3DDevice9
*device
)
1026 IDirect3DTexture9
*tex
;
1028 D3DLOCKED_RECT lock_rect
;
1031 DWORD value
, expected
, size
, pitch
;
1034 hr
= IDirect3DDevice9_CreateTexture(device
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1035 D3DPOOL_MANAGED
, &tex
, NULL
);
1039 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1040 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1042 for (m
= 0; m
< 3; m
++)
1044 hr
= IDirect3DTexture9_LockRect(tex
, m
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1045 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1048 pitch
= lock_rect
.Pitch
/ sizeof(DWORD
);
1049 for (y
= 0; y
< size
; y
++)
1051 for (x
= 0; x
< size
; x
++)
1053 value
= ((DWORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1054 v
[0] = (value
>> 24) & 0xff;
1055 v
[1] = (value
>> 16) & 0xff;
1056 v
[2] = (value
>> 8) & 0xff;
1057 v
[3] = value
& 0xff;
1060 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1061 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1062 e
[3] = 255.0f
/ size
+ 0.5f
;
1063 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1065 ok(color_match(v
, e
),
1066 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1067 x
, y
, value
, expected
);
1070 IDirect3DTexture9_UnlockRect(tex
, m
);
1075 IDirect3DTexture9_Release(tex
);
1078 skip("Failed to create texture\n");
1080 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1081 D3DPOOL_MANAGED
, &tex
, NULL
);
1085 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1086 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1088 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1089 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1092 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1093 for (y
= 0; y
< 4; y
++)
1095 for (x
= 0; x
< 4; x
++)
1097 value
= ((WORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1099 v
[1] = value
>> 10 & 0x1f;
1100 v
[2] = value
>> 5 & 0x1f;
1101 v
[3] = value
& 0x1f;
1104 e
[1] = (x
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1105 e
[2] = (y
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1107 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1109 ok(color_match(v
, e
),
1110 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1111 x
, y
, value
, expected
);
1114 IDirect3DTexture9_UnlockRect(tex
, 0);
1117 IDirect3DTexture9_Release(tex
);
1120 skip("Failed to create texture\n");
1122 /* test floating-point textures */
1123 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A16B16G16R16F
,
1124 D3DPOOL_MANAGED
, &tex
, NULL
);
1128 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1129 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1131 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1134 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1135 for (y
= 0; y
< 4; y
++)
1137 WORD
*ptr
= (WORD
*)lock_rect
.pBits
+ y
* pitch
;
1138 for (x
= 0; x
< 4; x
++)
1140 D3DXVECTOR4 got
, expected
;
1142 D3DXFloat16To32Array((FLOAT
*)&got
, (D3DXFLOAT16
*)ptr
, 4);
1145 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1146 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1147 expected
.z
= 1.0f
/ 4.0f
;
1150 expect_vec4(&expected
, &got
);
1154 IDirect3DTexture9_UnlockRect(tex
, 0);
1157 skip("Failed to lock texture\n");
1159 IDirect3DTexture9_Release(tex
);
1162 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1164 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A32B32G32R32F
,
1165 D3DPOOL_MANAGED
, &tex
, NULL
);
1169 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1170 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1172 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1175 pitch
= lock_rect
.Pitch
/ sizeof(float);
1176 for (y
= 0; y
< 4; y
++)
1178 float *ptr
= (float *)lock_rect
.pBits
+ y
* pitch
;
1179 for (x
= 0; x
< 4; x
++)
1181 D3DXVECTOR4 got
, expected
;
1188 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1189 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1190 expected
.z
= 1.0f
/ 4.0f
;
1193 expect_vec4(&expected
, &got
);
1197 IDirect3DTexture9_UnlockRect(tex
, 0);
1200 skip("Failed to lock texture\n");
1202 IDirect3DTexture9_Release(tex
);
1205 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1207 /* test a compressed texture */
1208 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
,
1209 D3DPOOL_MANAGED
, &tex
, NULL
);
1213 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1214 todo_wine
ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1216 IDirect3DTexture9_Release(tex
);
1219 skip("Failed to create D3DFMT_DXT1 texture\n");
1222 static void WINAPI
fillfunc_cube(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1223 const D3DXVECTOR3
*texelsize
, void *data
)
1225 value
->x
= (texcoord
->x
+ 1.0f
) / 2.0f
;
1226 value
->y
= (texcoord
->y
+ 1.0f
) / 2.0f
;
1227 value
->z
= (texcoord
->z
+ 1.0f
) / 2.0f
;
1228 value
->w
= texelsize
->x
;
1241 static float get_cube_coord(enum cube_coord coord
, unsigned int x
, unsigned int y
, unsigned int size
)
1248 return size
- x
- 0.5f
;
1252 return size
- y
- 0.5f
;
1258 trace("Unexpected coordinate value\n");
1263 static void test_D3DXFillCubeTexture(IDirect3DDevice9
*device
)
1265 IDirect3DCubeTexture9
*tex
;
1267 D3DLOCKED_RECT lock_rect
;
1270 DWORD value
, expected
, size
, pitch
;
1271 enum cube_coord coordmap
[6][3] =
1273 {ONE
, YCOORDINV
, XCOORDINV
},
1274 {ZERO
, YCOORDINV
, XCOORD
},
1275 {XCOORD
, ONE
, YCOORD
},
1276 {XCOORD
, ZERO
, YCOORDINV
},
1277 {XCOORD
, YCOORDINV
, ONE
},
1278 {XCOORDINV
, YCOORDINV
, ZERO
}
1282 hr
= IDirect3DDevice9_CreateCubeTexture(device
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1283 D3DPOOL_MANAGED
, &tex
, NULL
);
1287 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1288 ok(hr
== D3D_OK
, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1290 for (m
= 0; m
< 3; m
++)
1292 for (f
= 0; f
< 6; f
++)
1294 hr
= IDirect3DCubeTexture9_LockRect(tex
, f
, m
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1295 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1298 pitch
= lock_rect
.Pitch
/ sizeof(DWORD
);
1299 for (y
= 0; y
< size
; y
++)
1301 for (x
= 0; x
< size
; x
++)
1303 value
= ((DWORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1304 v
[0] = (value
>> 24) & 0xff;
1305 v
[1] = (value
>> 16) & 0xff;
1306 v
[2] = (value
>> 8) & 0xff;
1307 v
[3] = value
& 0xff;
1309 e
[0] = (f
== 0) || (f
== 1) ?
1310 0 : (BYTE
)(255.0f
/ size
* 2.0f
+ 0.5f
);
1311 e
[1] = get_cube_coord(coordmap
[f
][0], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1312 e
[2] = get_cube_coord(coordmap
[f
][1], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1313 e
[3] = get_cube_coord(coordmap
[f
][2], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1314 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1316 ok(color_match(v
, e
),
1317 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1318 f
, x
, y
, value
, expected
);
1321 IDirect3DCubeTexture9_UnlockRect(tex
, f
, m
);
1327 IDirect3DCubeTexture9_Release(tex
);
1330 skip("Failed to create texture\n");
1332 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 4, 1, 0, D3DFMT_A1R5G5B5
,
1333 D3DPOOL_MANAGED
, &tex
, NULL
);
1337 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1338 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1339 for (f
= 0; f
< 6; f
++)
1341 hr
= IDirect3DCubeTexture9_LockRect(tex
, f
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1342 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1345 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1346 for (y
= 0; y
< 4; y
++)
1348 for (x
= 0; x
< 4; x
++)
1350 value
= ((WORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1352 v
[1] = value
>> 10 & 0x1f;
1353 v
[2] = value
>> 5 & 0x1f;
1354 v
[3] = value
& 0x1f;
1356 e
[0] = (f
== 0) || (f
== 1) ?
1357 0 : (BYTE
)(1.0f
/ size
* 2.0f
+ 0.5f
);
1358 e
[1] = get_cube_coord(coordmap
[f
][0], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1359 e
[2] = get_cube_coord(coordmap
[f
][1], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1360 e
[3] = get_cube_coord(coordmap
[f
][2], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1361 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1363 ok(color_match(v
, e
),
1364 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1365 f
, x
, y
, value
, expected
);
1368 IDirect3DCubeTexture9_UnlockRect(tex
, f
, 0);
1372 IDirect3DCubeTexture9_Release(tex
);
1375 skip("Failed to create texture\n");
1378 static void WINAPI
fillfunc_volume(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1379 const D3DXVECTOR3
*texelsize
, void *data
)
1381 value
->x
= texcoord
->x
;
1382 value
->y
= texcoord
->y
;
1383 value
->z
= texcoord
->z
;
1384 value
->w
= texelsize
->x
;
1387 static void test_D3DXFillVolumeTexture(IDirect3DDevice9
*device
)
1389 IDirect3DVolumeTexture9
*tex
;
1391 D3DLOCKED_BOX lock_box
;
1394 DWORD value
, expected
, size
, row_pitch
, slice_pitch
;
1397 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, size
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1398 D3DPOOL_MANAGED
, &tex
, NULL
);
1402 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1403 ok(hr
== D3D_OK
, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1405 for (m
= 0; m
< 3; m
++)
1407 hr
= IDirect3DVolumeTexture9_LockBox(tex
, m
, &lock_box
, NULL
, D3DLOCK_READONLY
);
1408 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1411 row_pitch
= lock_box
.RowPitch
/ sizeof(DWORD
);
1412 slice_pitch
= lock_box
.SlicePitch
/ sizeof(DWORD
);
1413 for (z
= 0; z
< size
; z
++)
1415 for (y
= 0; y
< size
; y
++)
1417 for (x
= 0; x
< size
; x
++)
1419 value
= ((DWORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1420 v
[0] = (value
>> 24) & 0xff;
1421 v
[1] = (value
>> 16) & 0xff;
1422 v
[2] = (value
>> 8) & 0xff;
1423 v
[3] = value
& 0xff;
1425 e
[0] = 255.0f
/ size
+ 0.5f
;
1426 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1427 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1428 e
[3] = (z
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1429 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1431 ok(color_match(v
, e
),
1432 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1433 x
, y
, z
, value
, expected
);
1437 IDirect3DVolumeTexture9_UnlockBox(tex
, m
);
1442 IDirect3DVolumeTexture9_Release(tex
);
1445 skip("Failed to create texture\n");
1447 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1448 D3DPOOL_MANAGED
, &tex
, NULL
);
1452 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1453 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1454 hr
= IDirect3DVolumeTexture9_LockBox(tex
, 0, &lock_box
, NULL
, D3DLOCK_READONLY
);
1455 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1458 row_pitch
= lock_box
.RowPitch
/ sizeof(WORD
);
1459 slice_pitch
= lock_box
.SlicePitch
/ sizeof(WORD
);
1460 for (z
= 0; z
< 4; z
++)
1462 for (y
= 0; y
< 4; y
++)
1464 for (x
= 0; x
< 4; x
++)
1466 value
= ((WORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1468 v
[1] = value
>> 10 & 0x1f;
1469 v
[2] = value
>> 5 & 0x1f;
1470 v
[3] = value
& 0x1f;
1473 e
[1] = (x
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1474 e
[2] = (y
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1475 e
[3] = (z
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1476 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1478 ok(color_match(v
, e
),
1479 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1480 x
, y
, z
, value
, expected
);
1484 IDirect3DVolumeTexture9_UnlockBox(tex
, 0);
1487 IDirect3DVolumeTexture9_Release(tex
);
1490 skip("Failed to create texture\n");
1493 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9
*device
)
1496 IDirect3DTexture9
*texture
;
1497 D3DRESOURCETYPE type
;
1498 D3DSURFACE_DESC desc
;
1499 D3DLOCKED_RECT lock_rect
;
1503 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_16bit
, sizeof(dds_16bit
), &texture
);
1504 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1505 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1507 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
), &texture
);
1508 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1509 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1511 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
) - 1, &texture
);
1512 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
1514 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1515 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &texture
);
1516 todo_wine_if (!has_2d_dxt5
)
1517 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr
, D3D_OK
);
1520 type
= IDirect3DTexture9_GetType(texture
);
1521 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u\n", type
, D3DRTYPE_TEXTURE
);
1522 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1523 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1524 ok(desc
.Width
== 4, "Width is %u, expected 4\n", desc
.Width
);
1525 ok(desc
.Height
== 4, "Height is %u, expected 4\n", desc
.Height
);
1526 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1527 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#x, expected %#x\n", hr
, D3D_OK
);
1530 for (i
= 0; i
< 16; i
++)
1531 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_cube_map
[128 + i
],
1532 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1533 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_cube_map
[128 + i
]);
1534 IDirect3DTexture9_UnlockRect(texture
, 0);
1536 IDirect3DTexture9_Release(texture
);
1540 /* Volume textures work too. */
1541 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &texture
);
1542 todo_wine_if (!has_2d_dxt3
)
1543 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr
, D3D_OK
);
1546 type
= IDirect3DTexture9_GetType(texture
);
1547 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type
, D3DRTYPE_TEXTURE
);
1548 level_count
= IDirect3DBaseTexture9_GetLevelCount((IDirect3DBaseTexture9
*)texture
);
1549 todo_wine
ok(level_count
== 3, "Texture has %u mip levels, 3 expected.\n", level_count
);
1550 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1551 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x.\n", hr
, D3D_OK
);
1552 ok(desc
.Width
== 4, "Width is %u, expected 4.\n", desc
.Width
);
1553 ok(desc
.Height
== 4, "Height is %u, expected 4.\n", desc
.Height
);
1555 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1556 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#x, expected %#x.\n", hr
, D3D_OK
);
1559 for (i
= 0; i
< 16; ++i
)
1560 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_volume_map
[128 + i
],
1561 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1562 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_volume_map
[128 + i
]);
1563 IDirect3DTexture9_UnlockRect(texture
, 0);
1565 /* The lower texture levels are apparently generated by filtering the level 0 surface
1566 * I.e. following levels from the file are ignored. */
1567 IDirect3DTexture9_Release(texture
);
1571 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
1574 IDirect3DTexture9
*texture
;
1575 unsigned int miplevels
;
1576 IDirect3DSurface9
*surface
;
1577 D3DSURFACE_DESC desc
;
1579 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1580 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1581 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1582 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1584 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1585 D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1586 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1587 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1589 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
), D3DX_DEFAULT
,
1590 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1591 D3DX_DEFAULT
, D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_FILTER_POINT
), 0, NULL
, NULL
, &texture
);
1592 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1595 miplevels
= IDirect3DTexture9_GetLevelCount(texture
);
1596 ok(miplevels
== 1, "Got miplevels %u, expected %u\n", miplevels
, 1);
1597 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1598 IDirect3DSurface9_GetDesc(surface
, &desc
);
1599 ok(desc
.Width
== 1 && desc
.Height
== 1,
1600 "Surface dimensions are %ux%u, expected 1x1.\n", desc
.Width
, desc
.Height
);
1601 IDirect3DSurface9_Release(surface
);
1602 IDirect3DTexture9_Release(texture
);
1605 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
1607 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1611 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1612 D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1613 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1614 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1616 /* Checking for color key format overrides. */
1617 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1618 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1619 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1620 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1623 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1624 IDirect3DSurface9_GetDesc(surface
, &desc
);
1625 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X1R5G5B5
);
1626 IDirect3DTexture9_Release(texture
);
1628 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1629 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1630 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1631 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1634 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1635 IDirect3DSurface9_GetDesc(surface
, &desc
);
1636 ok(desc
.Format
== D3DFMT_A1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A1R5G5B5
);
1637 IDirect3DTexture9_Release(texture
);
1639 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1640 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X1R5G5B5
, D3DPOOL_DEFAULT
,
1641 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1642 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1645 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1646 IDirect3DSurface9_GetDesc(surface
, &desc
);
1647 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X1R5G5B5
);
1648 IDirect3DTexture9_Release(texture
);
1651 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1652 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1653 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1654 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1657 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1658 IDirect3DSurface9_GetDesc(surface
, &desc
);
1659 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X8R8G8B8
);
1660 IDirect3DTexture9_Release(texture
);
1662 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1663 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1664 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1665 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1668 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1669 IDirect3DSurface9_GetDesc(surface
, &desc
);
1670 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
1671 IDirect3DTexture9_Release(texture
);
1673 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1674 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
,
1675 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1676 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1679 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1680 IDirect3DSurface9_GetDesc(surface
, &desc
);
1681 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X8R8G8B8
);
1682 IDirect3DTexture9_Release(texture
);
1685 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1686 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1687 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1688 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1691 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1692 IDirect3DSurface9_GetDesc(surface
, &desc
);
1693 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_L8
);
1694 IDirect3DTexture9_Release(texture
);
1696 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1697 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1698 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1699 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1702 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1703 IDirect3DSurface9_GetDesc(surface
, &desc
);
1704 ok(desc
.Format
== D3DFMT_A8L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8L8
);
1705 IDirect3DTexture9_Release(texture
);
1707 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1708 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_L8
, D3DPOOL_DEFAULT
,
1709 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1710 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1713 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1714 IDirect3DSurface9_GetDesc(surface
, &desc
);
1715 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_L8
);
1716 IDirect3DTexture9_Release(texture
);
1720 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9
*device
)
1725 IDirect3DCubeTexture9
*cube_texture
;
1726 D3DSURFACE_DESC surface_desc
;
1728 hr
= D3DXCreateCubeTextureFromFileInMemory(NULL
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
1729 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1731 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, NULL
, sizeof(dds_cube_map
), &cube_texture
);
1732 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1734 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, 0, &cube_texture
);
1735 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1737 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), NULL
);
1738 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1740 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
1743 levelcount
= IDirect3DCubeTexture9_GetLevelCount(cube_texture
);
1744 todo_wine
ok(levelcount
== 3, "GetLevelCount returned %u, expected 3\n", levelcount
);
1746 hr
= IDirect3DCubeTexture9_GetLevelDesc(cube_texture
, 0, &surface_desc
);
1747 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1748 ok(surface_desc
.Width
== 4, "Got width %u, expected 4\n", surface_desc
.Width
);
1749 ok(surface_desc
.Height
== 4, "Got height %u, expected 4\n", surface_desc
.Height
);
1751 ref
= IDirect3DCubeTexture9_Release(cube_texture
);
1752 ok(ref
== 0, "Invalid reference count. Got %u, expected 0\n", ref
);
1753 } else skip("Couldn't create cube texture\n");
1756 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
1759 IDirect3DCubeTexture9
*cube_texture
;
1761 if (!is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
1763 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1767 hr
= D3DXCreateCubeTextureFromFileInMemoryEx(device
, dds_cube_map
, sizeof(dds_cube_map
), D3DX_DEFAULT
, D3DX_DEFAULT
,
1768 D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &cube_texture
);
1769 todo_wine_if (!has_cube_dxt5
)
1770 ok(hr
== D3D_OK
, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1771 if (SUCCEEDED(hr
)) IDirect3DCubeTexture9_Release(cube_texture
);
1774 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9
*device
)
1779 IDirect3DVolumeTexture9
*volume_texture
;
1780 D3DVOLUME_DESC volume_desc
;
1782 hr
= D3DXCreateVolumeTextureFromFileInMemory(NULL
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
1783 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1785 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, NULL
, sizeof(dds_volume_map
), &volume_texture
);
1786 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1788 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, 0, &volume_texture
);
1789 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1791 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), NULL
);
1792 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1794 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
1795 todo_wine_if (!has_3d_dxt3
)
1796 ok(hr
== D3D_OK
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1799 levelcount
= IDirect3DVolumeTexture9_GetLevelCount(volume_texture
);
1800 ok(levelcount
== 3, "GetLevelCount returned %u, expected 3\n", levelcount
);
1802 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 0, &volume_desc
);
1803 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1804 ok(volume_desc
.Width
== 4, "Got width %u, expected 4\n", volume_desc
.Width
);
1805 ok(volume_desc
.Height
== 4, "Got height %u, expected 4\n", volume_desc
.Height
);
1806 ok(volume_desc
.Depth
== 2, "Got depth %u, expected 2\n", volume_desc
.Depth
);
1807 ok(volume_desc
.Pool
== D3DPOOL_MANAGED
, "Got pool %u, expected D3DPOOL_MANAGED\n", volume_desc
.Pool
);
1809 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 1, &volume_desc
);
1810 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1811 ok(volume_desc
.Width
== 2, "Got width %u, expected 2\n", volume_desc
.Width
);
1812 ok(volume_desc
.Height
== 2, "Got height %u, expected 2\n", volume_desc
.Height
);
1813 ok(volume_desc
.Depth
== 1, "Got depth %u, expected 1\n", volume_desc
.Depth
);
1815 ref
= IDirect3DVolumeTexture9_Release(volume_texture
);
1816 ok(ref
== 0, "Invalid reference count. Got %u, expected 0\n", ref
);
1820 /* fills positive x face with red color */
1821 static void WINAPI
fill_cube_positive_x(D3DXVECTOR4
*out
, const D3DXVECTOR3
*tex_coord
, const D3DXVECTOR3
*texel_size
, void *data
)
1823 memset(out
, 0, sizeof(*out
));
1824 if (tex_coord
->x
> 0 && fabs(tex_coord
->x
) > fabs(tex_coord
->y
) && fabs(tex_coord
->x
) > fabs(tex_coord
->z
))
1828 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9
*device
)
1831 IDirect3DTexture9
*texture
;
1832 IDirect3DCubeTexture9
*cube_texture
;
1833 IDirect3DVolumeTexture9
*volume_texture
;
1834 ID3DXBuffer
*buffer
;
1835 void *buffer_pointer
;
1837 D3DXIMAGE_INFO info
;
1838 D3DXIMAGE_FILEFORMAT file_format
;
1841 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
1844 skip("Failed to create texture\n");
1848 for (file_format
= D3DXIFF_BMP
; file_format
<= D3DXIFF_JPG
; file_format
++)
1850 hr
= D3DXSaveTextureToFileInMemory(&buffer
, file_format
, (IDirect3DBaseTexture9
*)texture
, NULL
);
1851 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1854 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1855 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1856 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1857 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1859 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1860 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1861 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1862 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1863 ok(info
.ImageFileFormat
== file_format
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, file_format
);
1864 ID3DXBuffer_Release(buffer
);
1869 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)texture
, NULL
);
1870 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1873 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1874 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1875 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1876 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1878 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1879 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1880 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
1881 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1882 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
1883 ID3DXBuffer_Release(buffer
);
1887 IDirect3DTexture9_Release(texture
);
1890 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &cube_texture
, NULL
);
1893 skip("Failed to create cube texture\n");
1897 hr
= D3DXFillCubeTexture(cube_texture
, fill_cube_positive_x
, NULL
);
1898 ok(hr
== D3D_OK
, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1900 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
1901 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1904 IDirect3DSurface9
*surface
;
1906 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1907 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1908 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1909 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1911 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1912 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1913 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1914 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1915 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
1917 /* positive x face is saved */
1918 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1921 D3DLOCKED_RECT locked_rect
;
1923 hr
= D3DXLoadSurfaceFromFileInMemory(surface
, NULL
, NULL
, buffer_pointer
, buffer_size
, NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1924 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1926 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, D3DLOCK_READONLY
);
1929 DWORD
*color
= locked_rect
.pBits
;
1930 ok(*color
== 0x00ff0000, "Got color %#x, expected %#x\n", *color
, 0x00ff0000);
1931 IDirect3DSurface9_UnlockRect(surface
);
1934 IDirect3DSurface9_Release(surface
);
1935 } else skip("Failed to create surface\n");
1937 ID3DXBuffer_Release(buffer
);
1941 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
1942 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1945 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1946 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1947 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1948 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1950 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1951 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1952 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
1953 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
1954 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
1955 ID3DXBuffer_Release(buffer
);
1959 IDirect3DCubeTexture9_Release(cube_texture
);
1961 /* volume textures */
1962 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &volume_texture
, NULL
);
1965 skip("Failed to create volume texture\n");
1970 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
1971 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1974 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1975 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1976 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1977 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1979 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1980 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1981 ok(info
.Depth
== 1, "Got depth %u, expected %u\n", info
.Depth
, 1);
1982 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1983 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1984 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
1985 ID3DXBuffer_Release(buffer
);
1988 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
1989 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1992 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1993 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1994 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1995 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1997 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1998 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1999 ok(info
.Depth
== 256, "Got depth %u, expected %u\n", info
.Depth
, 256);
2000 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
2001 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
2002 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
2003 ID3DXBuffer_Release(buffer
);
2007 IDirect3DVolumeTexture9_Release(volume_texture
);
2010 static void test_texture_shader(void)
2012 static const DWORD shader_zero
[] = {0x0};
2013 static const DWORD shader_invalid
[] = {0xeeee0100};
2014 static const DWORD shader_empty
[] = {0xfffe0200, 0x0000ffff};
2016 float4
main(float3 pos
: POSITION
, float3 size
: PSIZE
) : COLOR
2018 return float4(pos
, 1.0);
2021 static const DWORD shader_code
[] =
2023 0x54580100, 0x0015fffe, 0x42415443, 0x0000001c, 0x0000001f, 0x54580100, 0x00000000, 0x00000000,
2024 0x00000100, 0x0000001c, 0x4d007874, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
2025 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932, 0x332e3235, 0x00313131, 0x000afffe,
2026 0x54494c43, 0x00000004, 0x00000000, 0x3ff00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2027 0x00000000, 0x00000000, 0x0014fffe, 0x434c5846, 0x00000002, 0x10000003, 0x00000001, 0x00000000,
2028 0x00000003, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x10000001, 0x00000001, 0x00000000,
2029 0x00000001, 0x00000000, 0x00000000, 0x00000004, 0x00000003, 0xf0f0f0f0, 0x0f0f0f0f, 0x0000ffff,
2031 IDirect3DVolumeTexture9
*volume_texture
;
2032 IDirect3DCubeTexture9
*cube_texture
;
2033 D3DPRESENT_PARAMETERS d3dpp
;
2034 IDirect3DTexture9
*texture
;
2035 IDirect3DDevice9
*device
;
2036 ID3DXTextureShader
*tx
;
2037 unsigned int x
, y
, z
;
2038 ID3DXBuffer
*buffer
;
2047 hr
= D3DXCreateTextureShader(NULL
, NULL
);
2048 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
2050 hr
= D3DXCreateTextureShader(NULL
, &tx
);
2051 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#x.\n", hr
);
2053 hr
= D3DXCreateTextureShader(shader_invalid
, &tx
);
2054 todo_wine
ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#x.\n", hr
);
2056 hr
= D3DXCreateTextureShader(shader_zero
, &tx
);
2057 todo_wine
ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#x.\n", hr
);
2059 hr
= D3DXCreateTextureShader(shader_empty
, &tx
);
2060 todo_wine
ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#x.\n", hr
);
2062 hr
= D3DXCreateTextureShader(shader_code
, &tx
);
2063 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2065 hr
= tx
->lpVtbl
->GetFunction(tx
, &buffer
);
2066 todo_wine
ok(SUCCEEDED(hr
), "Failed to get texture shader bytecode.\n");
2069 skip("Texture shaders not supported, skipping further tests.\n");
2070 IUnknown_Release(tx
);
2073 ID3DXBuffer_Release(buffer
);
2075 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
2076 640, 480, NULL
, NULL
, NULL
, NULL
)))
2078 skip("Couldn't create application window.\n");
2079 IUnknown_Release(tx
);
2082 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2085 skip("Couldn't create IDirect3D9 object.\n");
2087 IUnknown_Release(tx
);
2091 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
2092 d3dpp
.Windowed
= TRUE
;
2093 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2094 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
,
2095 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
2098 skip("Failed to create IDirect3DDevice9 object, hr %#x.\n", hr
);
2099 IDirect3D9_Release(d3d
);
2101 IUnknown_Release(tx
);
2105 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
2107 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
,
2109 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2111 hr
= D3DXFillTextureTX(texture
, tx
);
2112 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2114 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, D3DLOCK_READONLY
);
2115 ok(SUCCEEDED(hr
), "Locking texture failed, hr %#x.\n", hr
);
2117 for (y
= 0; y
< 256; ++y
)
2119 for (x
= 0; x
< 256; ++x
)
2121 unsigned int expected
= 0xff000000 | x
<< 16 | y
<< 8;
2122 /* The third position coordinate is apparently undefined for 2D textures. */
2123 unsigned int color
= data
[y
* lr
.Pitch
/ sizeof(*data
) + x
] & 0xffffff00;
2125 ok(compare_color(color
, expected
, 1), "Unexpected color %08x at (%u, %u).\n", color
, x
, y
);
2128 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
2129 ok(SUCCEEDED(hr
), "Unlocking texture failed, hr %#x.\n", hr
);
2131 IDirect3DTexture9_Release(texture
);
2133 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2135 skip("Cube textures not supported, skipping tests.\n");
2139 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
,
2140 &cube_texture
, NULL
);
2141 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2143 hr
= D3DXFillCubeTextureTX(cube_texture
, tx
);
2144 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2146 for (z
= 0; z
< 6; ++z
)
2148 static const char * const mapping
[6][3] =
2158 hr
= IDirect3DCubeTexture9_LockRect(cube_texture
, z
, 0, &lr
, NULL
, D3DLOCK_READONLY
);
2159 ok(SUCCEEDED(hr
), "Locking texture failed, hr %#x.\n", hr
);
2161 for (y
= 0; y
< 256; ++y
)
2163 for (x
= 0; x
< 256; ++x
)
2165 unsigned int color
= data
[y
* lr
.Pitch
/ sizeof(*data
) + x
];
2166 unsigned int expected
= 0xff000000;
2169 for (i
= 0; i
< 3; ++i
)
2173 if (mapping
[z
][i
][0] == '0')
2175 else if (mapping
[z
][i
][0] == '1')
2178 component
= mapping
[z
][i
][1] == 'x' ? x
* 2 - 255 : y
* 2 - 255;
2179 if (mapping
[z
][i
][0] == '-')
2180 component
= -component
;
2181 expected
|= max(component
, 0) << i
* 8;
2183 ok(compare_color(color
, expected
, 1), "Unexpected color %08x at (%u, %u, %u).\n",
2187 hr
= IDirect3DCubeTexture9_UnlockRect(cube_texture
, z
, 0);
2188 ok(SUCCEEDED(hr
), "Unlocking texture failed, hr %#x.\n", hr
);
2191 IDirect3DCubeTexture9_Release(cube_texture
);
2193 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
) || caps
.MaxVolumeExtent
< 64)
2195 skip("Volume textures not supported, skipping test.\n");
2198 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 64, 64, 64, 1, 0, D3DFMT_A8R8G8B8
,
2199 D3DPOOL_SYSTEMMEM
, &volume_texture
, NULL
);
2200 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2202 hr
= D3DXFillVolumeTextureTX(volume_texture
, tx
);
2203 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
2205 hr
= IDirect3DVolumeTexture9_LockBox(volume_texture
, 0, &lb
, NULL
, D3DLOCK_READONLY
);
2206 ok(SUCCEEDED(hr
), "Locking texture failed, hr %#x.\n", hr
);
2208 for (z
= 0; z
< 64; ++z
)
2210 for (y
= 0; y
< 64; ++y
)
2212 for (x
= 0; x
< 64; ++x
)
2214 unsigned int expected
= 0xff000000 | ((x
* 4 + 2) << 16) | ((y
* 4 + 2) << 8) | (z
* 4 + 2);
2215 unsigned int color
= data
[z
* lb
.SlicePitch
/ sizeof(*data
) + y
* lb
.RowPitch
/ sizeof(*data
) + x
];
2217 ok(compare_color(color
, expected
, 1), "Unexpected color %08x at (%u, %u, %u).\n",
2222 hr
= IDirect3DVolumeTexture9_UnlockBox(volume_texture
, 0);
2223 ok(SUCCEEDED(hr
), "Unlocking texture failed, hr %#x.\n", hr
);
2225 IDirect3DVolumeTexture9_Release(volume_texture
);
2228 IDirect3DDevice9_Release(device
);
2229 IDirect3D9_Release(d3d
);
2231 IUnknown_Release(tx
);
2238 IDirect3DDevice9
*device
;
2239 D3DPRESENT_PARAMETERS d3dpp
;
2242 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
2243 640, 480, NULL
, NULL
, NULL
, NULL
)))
2245 skip("Couldn't create application window\n");
2248 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2250 skip("Couldn't create IDirect3D9 object\n");
2255 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
2256 d3dpp
.Windowed
= TRUE
;
2257 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2258 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
2260 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
2261 IDirect3D9_Release(d3d
);
2266 /* Check whether DXTn textures are supported. */
2267 has_2d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2268 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT3
));
2269 hr
= IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2270 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT5
);
2271 has_2d_dxt5
= SUCCEEDED(hr
);
2272 hr
= IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2273 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, D3DFMT_DXT5
);
2274 has_cube_dxt5
= SUCCEEDED(hr
);
2275 has_3d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2276 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_VOLUMETEXTURE
, D3DFMT_DXT3
));
2278 test_D3DXCheckTextureRequirements(device
);
2279 test_D3DXCheckCubeTextureRequirements(device
);
2280 test_D3DXCheckVolumeTextureRequirements(device
);
2281 test_D3DXCreateTexture(device
);
2282 test_D3DXFilterTexture(device
);
2283 test_D3DXFillTexture(device
);
2284 test_D3DXFillCubeTexture(device
);
2285 test_D3DXFillVolumeTexture(device
);
2286 test_D3DXCreateTextureFromFileInMemory(device
);
2287 test_D3DXCreateTextureFromFileInMemoryEx(device
);
2288 test_D3DXCreateCubeTextureFromFileInMemory(device
);
2289 test_D3DXCreateCubeTextureFromFileInMemoryEx(device
);
2290 test_D3DXCreateVolumeTextureFromFileInMemory(device
);
2291 test_D3DXSaveTextureToFileInMemory(device
);
2293 IDirect3DDevice9_Release(device
);
2294 IDirect3D9_Release(d3d
);
2297 test_texture_shader();