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
is_autogenmipmap_supported(IDirect3DDevice9
*device
, D3DRESOURCETYPE resource_type
)
125 D3DDEVICE_CREATION_PARAMETERS params
;
127 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
128 IDirect3DDevice9_GetDirect3D(device
, &d3d9
);
129 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
130 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
132 if (!(caps
.Caps2
& D3DCAPS2_CANAUTOGENMIPMAP
))
135 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, params
.AdapterOrdinal
, params
.DeviceType
,
136 mode
.Format
, D3DUSAGE_AUTOGENMIPMAP
, resource_type
, D3DFMT_A8R8G8B8
);
138 IDirect3D9_Release(d3d9
);
139 return SUCCEEDED(hr
);
142 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9
*device
)
144 UINT width
, height
, mipmaps
;
145 D3DFORMAT format
, expected
;
149 D3DDEVICE_CREATION_PARAMETERS params
;
152 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
155 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
156 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
158 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
159 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
161 hr
= D3DXCheckTextureRequirements(NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
162 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
165 width
= height
= D3DX_DEFAULT
;
166 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
167 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
168 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
169 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
171 width
= D3DX_DEFAULT
;
172 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
173 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
174 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
176 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
177 skip("Hardware only supports pow2 textures\n");
181 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
182 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
183 ok(width
== 62, "Returned width %d, expected %d\n", width
, 62);
185 width
= D3DX_DEFAULT
; height
= 63;
186 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
187 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
188 ok(width
== height
, "Returned width %d, expected %d\n", width
, height
);
189 ok(height
== 63, "Returned height %d, expected %d\n", height
, 63);
192 width
= D3DX_DEFAULT
; height
= 0;
193 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
194 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
195 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
196 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
198 width
= 0; height
= 0;
199 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
200 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
201 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
202 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
205 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
206 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
207 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
210 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
211 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
212 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
);
214 width
= caps
.MaxTextureWidth
-1;
215 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
216 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
217 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
218 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
);
220 ok(width
== caps
.MaxTextureWidth
-1, "Returned width %d, expected %d\n", width
, caps
.MaxTextureWidth
-1);
223 width
= 64; height
= 63;
225 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
226 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
227 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
229 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
))
231 width
= 284; height
= 137;
233 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
234 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
235 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
239 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
240 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
241 ok(mipmaps
== 6, "Returned mipmaps %d, expected %d\n", mipmaps
, 6);
244 skip("Skipping some tests, npot2 textures unsupported\n");
247 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
248 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
249 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
252 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
253 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
254 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
256 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
257 if (is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
260 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
261 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
262 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
264 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
265 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
266 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
268 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
269 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
270 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
272 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
273 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
274 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
277 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
280 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
281 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
282 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
283 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
284 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
285 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
286 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
287 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
288 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
289 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
292 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
293 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
295 format
= D3DFMT_UNKNOWN
;
296 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
297 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
298 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
300 format
= D3DX_DEFAULT
;
301 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
302 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
303 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
305 format
= D3DFMT_R8G8B8
;
306 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
307 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
308 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
310 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
311 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
312 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
314 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
315 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_R3G3B2
)))
316 expected
= D3DFMT_R3G3B2
;
317 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
318 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X4R4G4B4
)))
319 expected
= D3DFMT_X4R4G4B4
;
320 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
321 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X1R5G5B5
)))
322 expected
= D3DFMT_X1R5G5B5
;
324 expected
= D3DFMT_R5G6B5
;
326 format
= D3DFMT_R3G3B2
;
327 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
328 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
329 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
331 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
332 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R3G3B2
)))
333 expected
= D3DFMT_A8R3G3B2
;
335 expected
= D3DFMT_A8R8G8B8
;
337 format
= D3DFMT_A8R3G3B2
;
338 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
339 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
340 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
342 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
343 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_P8
)))
344 expected
= D3DFMT_P8
;
346 expected
= D3DFMT_A8R8G8B8
;
349 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
350 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
351 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
353 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
354 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L8
)))
355 expected
= D3DFMT_L8
;
357 expected
= D3DFMT_X8R8G8B8
;
360 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
361 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
362 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
364 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
365 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L16
)))
366 expected
= D3DFMT_L16
;
368 expected
= D3DFMT_A16B16G16R16
;
371 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
372 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
373 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
375 /* Block-based texture formats and size < block size. */
378 format
= D3DFMT_DXT5
;
379 width
= 2; height
= 2;
381 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
382 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
383 ok(width
== 4, "Returned width %d, expected %d\n", width
, 4);
384 ok(height
== 4, "Returned height %d, expected %d\n", height
, 4);
385 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
386 ok(format
== D3DFMT_DXT5
, "Returned format %u, expected %u\n", format
, D3DFMT_DXT5
);
390 skip("D3DFMT_DXT5 textures are not supported, skipping a test.\n");
393 IDirect3D9_Release(d3d
);
396 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9
*device
)
398 UINT size
, mipmaps
, expected
;
403 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
405 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
407 skip("No cube textures support\n");
412 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
413 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
415 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
416 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
418 hr
= D3DXCheckCubeTextureRequirements(NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
419 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
423 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
424 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
425 ok(size
== 256, "Returned size %d, expected %d\n", size
, 256);
430 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
431 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
432 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
436 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 10 : 9;
437 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
438 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
439 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
440 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
444 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 7 : 6;
445 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
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
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
451 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
452 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
453 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
455 if (is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
458 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
459 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
460 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
463 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
466 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
467 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
468 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
469 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
470 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
471 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
472 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
473 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
474 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
475 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
478 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
479 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
481 format
= D3DFMT_UNKNOWN
;
482 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
483 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
484 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
486 format
= D3DX_DEFAULT
;
487 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
488 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
489 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
491 format
= D3DFMT_R8G8B8
;
492 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
493 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
494 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
497 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9
*device
)
499 UINT width
, height
, depth
, mipmaps
, expected
;
504 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
506 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
) || (caps
.MaxVolumeExtent
< 256))
508 skip("Limited or no volume textures support.\n");
513 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
514 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
516 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
517 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
519 hr
= D3DXCheckVolumeTextureRequirements(NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
520 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
522 /* width, height, depth */
523 width
= height
= depth
= D3DX_DEFAULT
;
524 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
525 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
526 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
527 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
528 ok(depth
== 1, "Returned depth %d, expected %d\n", depth
, 1);
530 width
= D3DX_DEFAULT
;
531 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
532 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
533 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
535 width
= D3DX_DEFAULT
; height
= 0; depth
= 0;
536 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
537 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
538 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
539 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
540 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
542 width
= 0; height
= 0; depth
= 0;
543 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
544 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
545 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
546 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
547 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
550 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
551 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
552 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
555 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
556 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
557 ok(width
== caps
.MaxVolumeExtent
, "Returned width %d, expected %d\n", width
, caps
.MaxVolumeExtent
);
560 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
561 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
563 format
= D3DFMT_UNKNOWN
;
564 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
565 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
566 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
568 format
= D3DX_DEFAULT
;
569 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
570 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
571 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
573 format
= D3DFMT_R8G8B8
;
574 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
575 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
576 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
578 format
= D3DFMT_DXT3
;
579 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
580 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
582 ok(format
== D3DFMT_DXT3
, "Returned format %u, expected %u\n", format
, D3DFMT_DXT3
);
584 todo_wine
ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
587 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
589 skip("No volume textures mipmapping support\n");
593 width
= height
= depth
= 64;
595 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
596 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
597 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
603 expected
= (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
&& caps
.MaxVolumeExtent
>= 512) ? 10 : 9;
604 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
605 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
606 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
609 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
610 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
611 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
613 if (!is_autogenmipmap_supported(device
, D3DRTYPE_VOLUMETEXTURE
))
615 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
619 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
621 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
622 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
623 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
625 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
626 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
627 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
629 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
,NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
630 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr
, D3D_OK
);
631 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
634 static void test_D3DXCreateTexture(IDirect3DDevice9
*device
)
636 IDirect3DTexture9
*texture
;
637 D3DSURFACE_DESC desc
;
642 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
644 hr
= D3DXCreateTexture(NULL
, 0, 0, 0, 0, D3DX_DEFAULT
, D3DPOOL_DEFAULT
, NULL
);
645 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
647 /* width and height tests */
649 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, 0, D3DPOOL_DEFAULT
, &texture
);
650 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
654 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
655 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
656 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
658 ok(desc
.Width
== 256, "Returned width %d, expected %d\n", desc
.Width
, 256);
659 ok(desc
.Height
== 256, "Returned height %d, expected %d\n", desc
.Height
, 256);
661 IDirect3DTexture9_Release(texture
);
665 hr
= D3DXCreateTexture(device
, 0, 0, 0, 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
== 1, "Returned width %d, expected %d\n", desc
.Width
, 1);
675 ok(desc
.Height
== 1, "Returned height %d, expected %d\n", desc
.Height
, 1);
677 IDirect3DTexture9_Release(texture
);
681 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
682 skip("Hardware only supports pow2 textures\n");
685 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, 63, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
687 /* may not work with conditional NPOT */
688 ((hr
!= D3D_OK
) && (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)),
689 "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
693 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
694 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
695 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
697 /* Conditional NPOT may create a texture with different dimensions, so allow those
698 situations instead of returning a fail */
700 ok(desc
.Width
== 63 ||
701 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
702 "Returned width %d, expected %d\n", desc
.Width
, 63);
704 ok(desc
.Height
== 63 ||
705 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
706 "Returned height %d, expected %d\n", desc
.Height
, 63);
708 IDirect3DTexture9_Release(texture
);
714 hr
= D3DXCreateTexture(device
, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
715 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
719 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
720 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
722 IDirect3DTexture9_Release(texture
);
726 hr
= D3DXCreateTexture(device
, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
727 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
731 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
732 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
734 IDirect3DTexture9_Release(texture
);
738 hr
= D3DXCreateTexture(device
, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT
, &texture
);
739 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
743 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
744 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
746 IDirect3DTexture9_Release(texture
);
750 hr
= D3DXCreateTexture(device
, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT
, &texture
);
751 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
755 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
756 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
758 IDirect3DTexture9_Release(texture
);
763 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &texture
);
764 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
765 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_DONOTCLIP
, 0, D3DPOOL_DEFAULT
, &texture
);
766 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
767 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_POINTS
, 0, D3DPOOL_DEFAULT
, &texture
);
768 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
769 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_RTPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
770 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
771 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_NPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
772 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
776 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, &texture
);
777 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
781 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
782 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
783 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
785 IDirect3DTexture9_Release(texture
);
789 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
790 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
794 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
795 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
796 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
798 IDirect3DTexture9_Release(texture
);
801 /* D3DXCreateTextureFromResource */
802 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &texture
);
803 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
804 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
806 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
807 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3D_OK
);
808 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
810 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDS_STRING
), &texture
);
811 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
813 hr
= D3DXCreateTextureFromResourceA(NULL
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
814 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
816 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, NULL
, &texture
);
817 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
819 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
);
820 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
823 /* D3DXCreateTextureFromResourceEx */
824 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
);
825 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3D_OK
);
826 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
828 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
);
829 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
831 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
);
832 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
834 hr
= D3DXCreateTextureFromResourceExA(device
, NULL
, NULL
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_MANAGED
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
835 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
837 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
);
838 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
841 static void test_D3DXFilterTexture(IDirect3DDevice9
*device
)
843 IDirect3DTexture9
*tex
;
844 IDirect3DCubeTexture9
*cubetex
;
845 IDirect3DVolumeTexture9
*voltex
;
848 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex
, NULL
);
852 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, D3DX_DEFAULT
, D3DX_FILTER_NONE
);
853 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
855 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
856 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
858 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
859 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
861 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
862 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
864 IDirect3DTexture9_Release(tex
);
867 skip("Failed to create texture\n");
869 hr
= D3DXFilterTexture(NULL
, NULL
, 0, D3DX_FILTER_NONE
);
870 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
872 /* Test different pools */
873 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
877 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
878 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
879 IDirect3DTexture9_Release(tex
);
882 skip("Failed to create texture\n");
884 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &tex
, NULL
);
888 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
889 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
890 IDirect3DTexture9_Release(tex
);
893 skip("Failed to create texture\n");
895 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
898 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
899 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
900 IDirect3DTexture9_Release(tex
);
903 skip("Failed to create texture\n");
905 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
908 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
909 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
910 IDirect3DTexture9_Release(tex
);
913 skip("Failed to create texture\n");
915 /* Cube texture test */
916 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &cubetex
, NULL
);
920 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_NONE
);
921 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
923 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
924 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
926 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
927 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
928 IDirect3DCubeTexture9_Release(cubetex
);
931 skip("Failed to create texture\n");
933 /* Volume texture test */
934 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &voltex
, NULL
);
937 DWORD level_count
= IDirect3DVolumeTexture9_GetLevelCount(voltex
);
939 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_NONE
);
940 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
942 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_DEFAULT
);
943 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
945 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_BOX
);
946 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
948 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
- 1, D3DX_DEFAULT
);
949 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
951 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
, D3DX_DEFAULT
);
952 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
954 IDirect3DVolumeTexture9_Release(voltex
);
957 skip("Failed to create volume texture\n");
959 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
960 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
962 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
966 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
969 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
970 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
971 IDirect3DTexture9_Release(tex
);
974 skip("Failed to create texture\n");
976 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
979 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
980 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
981 IDirect3DTexture9_Release(tex
);
984 skip("Failed to create texture\n");
987 static BOOL
color_match(const DWORD
*value
, const DWORD
*expected
)
991 for (i
= 0; i
< 4; i
++)
993 DWORD diff
= value
[i
] > expected
[i
] ? value
[i
] - expected
[i
] : expected
[i
] - value
[i
];
994 if (diff
> 1) return FALSE
;
999 static void WINAPI
fillfunc(D3DXVECTOR4
*value
, const D3DXVECTOR2
*texcoord
,
1000 const D3DXVECTOR2
*texelsize
, void *data
)
1002 value
->x
= texcoord
->x
;
1003 value
->y
= texcoord
->y
;
1004 value
->z
= texelsize
->x
;
1008 static void test_D3DXFillTexture(IDirect3DDevice9
*device
)
1010 IDirect3DTexture9
*tex
;
1012 D3DLOCKED_RECT lock_rect
;
1015 DWORD value
, expected
, size
, pitch
;
1018 hr
= IDirect3DDevice9_CreateTexture(device
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1019 D3DPOOL_MANAGED
, &tex
, NULL
);
1023 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1024 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1026 for (m
= 0; m
< 3; m
++)
1028 hr
= IDirect3DTexture9_LockRect(tex
, m
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1029 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1032 pitch
= lock_rect
.Pitch
/ sizeof(DWORD
);
1033 for (y
= 0; y
< size
; y
++)
1035 for (x
= 0; x
< size
; x
++)
1037 value
= ((DWORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1038 v
[0] = (value
>> 24) & 0xff;
1039 v
[1] = (value
>> 16) & 0xff;
1040 v
[2] = (value
>> 8) & 0xff;
1041 v
[3] = value
& 0xff;
1044 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1045 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1046 e
[3] = 255.0f
/ size
+ 0.5f
;
1047 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1049 ok(color_match(v
, e
),
1050 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1051 x
, y
, value
, expected
);
1054 IDirect3DTexture9_UnlockRect(tex
, m
);
1059 IDirect3DTexture9_Release(tex
);
1062 skip("Failed to create texture\n");
1064 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1065 D3DPOOL_MANAGED
, &tex
, NULL
);
1069 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1070 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1072 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1073 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1076 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1077 for (y
= 0; y
< 4; y
++)
1079 for (x
= 0; x
< 4; x
++)
1081 value
= ((WORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1083 v
[1] = value
>> 10 & 0x1f;
1084 v
[2] = value
>> 5 & 0x1f;
1085 v
[3] = value
& 0x1f;
1088 e
[1] = (x
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1089 e
[2] = (y
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1091 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1093 ok(color_match(v
, e
),
1094 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1095 x
, y
, value
, expected
);
1098 IDirect3DTexture9_UnlockRect(tex
, 0);
1101 IDirect3DTexture9_Release(tex
);
1104 skip("Failed to create texture\n");
1106 /* test floating-point textures */
1107 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A16B16G16R16F
,
1108 D3DPOOL_MANAGED
, &tex
, NULL
);
1112 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1113 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1115 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1118 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1119 for (y
= 0; y
< 4; y
++)
1121 WORD
*ptr
= (WORD
*)lock_rect
.pBits
+ y
* pitch
;
1122 for (x
= 0; x
< 4; x
++)
1124 D3DXVECTOR4 got
, expected
;
1126 D3DXFloat16To32Array((FLOAT
*)&got
, (D3DXFLOAT16
*)ptr
, 4);
1129 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1130 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1131 expected
.z
= 1.0f
/ 4.0f
;
1134 expect_vec4(&expected
, &got
);
1138 IDirect3DTexture9_UnlockRect(tex
, 0);
1141 skip("Failed to lock texture\n");
1143 IDirect3DTexture9_Release(tex
);
1146 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1148 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A32B32G32R32F
,
1149 D3DPOOL_MANAGED
, &tex
, NULL
);
1153 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1154 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1156 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1159 pitch
= lock_rect
.Pitch
/ sizeof(float);
1160 for (y
= 0; y
< 4; y
++)
1162 float *ptr
= (float *)lock_rect
.pBits
+ y
* pitch
;
1163 for (x
= 0; x
< 4; x
++)
1165 D3DXVECTOR4 got
, expected
;
1172 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1173 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1174 expected
.z
= 1.0f
/ 4.0f
;
1177 expect_vec4(&expected
, &got
);
1181 IDirect3DTexture9_UnlockRect(tex
, 0);
1184 skip("Failed to lock texture\n");
1186 IDirect3DTexture9_Release(tex
);
1189 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1191 /* test a compressed texture */
1192 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
,
1193 D3DPOOL_MANAGED
, &tex
, NULL
);
1197 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1198 todo_wine
ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1200 IDirect3DTexture9_Release(tex
);
1203 skip("Failed to create D3DFMT_DXT1 texture\n");
1206 static void WINAPI
fillfunc_cube(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1207 const D3DXVECTOR3
*texelsize
, void *data
)
1209 value
->x
= (texcoord
->x
+ 1.0f
) / 2.0f
;
1210 value
->y
= (texcoord
->y
+ 1.0f
) / 2.0f
;
1211 value
->z
= (texcoord
->z
+ 1.0f
) / 2.0f
;
1212 value
->w
= texelsize
->x
;
1225 static float get_cube_coord(enum cube_coord coord
, unsigned int x
, unsigned int y
, unsigned int size
)
1232 return size
- x
- 0.5f
;
1236 return size
- y
- 0.5f
;
1242 trace("Unexpected coordinate value\n");
1247 static void test_D3DXFillCubeTexture(IDirect3DDevice9
*device
)
1249 IDirect3DCubeTexture9
*tex
;
1251 D3DLOCKED_RECT lock_rect
;
1254 DWORD value
, expected
, size
, pitch
;
1255 enum cube_coord coordmap
[6][3] =
1257 {ONE
, YCOORDINV
, XCOORDINV
},
1258 {ZERO
, YCOORDINV
, XCOORD
},
1259 {XCOORD
, ONE
, YCOORD
},
1260 {XCOORD
, ZERO
, YCOORDINV
},
1261 {XCOORD
, YCOORDINV
, ONE
},
1262 {XCOORDINV
, YCOORDINV
, ZERO
}
1266 hr
= IDirect3DDevice9_CreateCubeTexture(device
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1267 D3DPOOL_MANAGED
, &tex
, NULL
);
1271 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1272 ok(hr
== D3D_OK
, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1274 for (m
= 0; m
< 3; m
++)
1276 for (f
= 0; f
< 6; f
++)
1278 hr
= IDirect3DCubeTexture9_LockRect(tex
, f
, m
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1279 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1282 pitch
= lock_rect
.Pitch
/ sizeof(DWORD
);
1283 for (y
= 0; y
< size
; y
++)
1285 for (x
= 0; x
< size
; x
++)
1287 value
= ((DWORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1288 v
[0] = (value
>> 24) & 0xff;
1289 v
[1] = (value
>> 16) & 0xff;
1290 v
[2] = (value
>> 8) & 0xff;
1291 v
[3] = value
& 0xff;
1293 e
[0] = (f
== 0) || (f
== 1) ?
1294 0 : (BYTE
)(255.0f
/ size
* 2.0f
+ 0.5f
);
1295 e
[1] = get_cube_coord(coordmap
[f
][0], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1296 e
[2] = get_cube_coord(coordmap
[f
][1], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1297 e
[3] = get_cube_coord(coordmap
[f
][2], x
, y
, size
) / size
* 255.0f
+ 0.5f
;
1298 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1300 ok(color_match(v
, e
),
1301 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1302 f
, x
, y
, value
, expected
);
1305 IDirect3DCubeTexture9_UnlockRect(tex
, f
, m
);
1311 IDirect3DCubeTexture9_Release(tex
);
1314 skip("Failed to create texture\n");
1316 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 4, 1, 0, D3DFMT_A1R5G5B5
,
1317 D3DPOOL_MANAGED
, &tex
, NULL
);
1321 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1322 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1323 for (f
= 0; f
< 6; f
++)
1325 hr
= IDirect3DCubeTexture9_LockRect(tex
, f
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1326 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1329 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1330 for (y
= 0; y
< 4; y
++)
1332 for (x
= 0; x
< 4; x
++)
1334 value
= ((WORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1336 v
[1] = value
>> 10 & 0x1f;
1337 v
[2] = value
>> 5 & 0x1f;
1338 v
[3] = value
& 0x1f;
1340 e
[0] = (f
== 0) || (f
== 1) ?
1341 0 : (BYTE
)(1.0f
/ size
* 2.0f
+ 0.5f
);
1342 e
[1] = get_cube_coord(coordmap
[f
][0], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1343 e
[2] = get_cube_coord(coordmap
[f
][1], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1344 e
[3] = get_cube_coord(coordmap
[f
][2], x
, y
, 4) / 4 * 31.0f
+ 0.5f
;
1345 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1347 ok(color_match(v
, e
),
1348 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1349 f
, x
, y
, value
, expected
);
1352 IDirect3DCubeTexture9_UnlockRect(tex
, f
, 0);
1356 IDirect3DCubeTexture9_Release(tex
);
1359 skip("Failed to create texture\n");
1362 static void WINAPI
fillfunc_volume(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1363 const D3DXVECTOR3
*texelsize
, void *data
)
1365 value
->x
= texcoord
->x
;
1366 value
->y
= texcoord
->y
;
1367 value
->z
= texcoord
->z
;
1368 value
->w
= texelsize
->x
;
1371 static void test_D3DXFillVolumeTexture(IDirect3DDevice9
*device
)
1373 IDirect3DVolumeTexture9
*tex
;
1375 D3DLOCKED_BOX lock_box
;
1378 DWORD value
, expected
, size
, row_pitch
, slice_pitch
;
1381 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, size
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1382 D3DPOOL_MANAGED
, &tex
, NULL
);
1386 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1387 ok(hr
== D3D_OK
, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1389 for (m
= 0; m
< 3; m
++)
1391 hr
= IDirect3DVolumeTexture9_LockBox(tex
, m
, &lock_box
, NULL
, D3DLOCK_READONLY
);
1392 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1395 row_pitch
= lock_box
.RowPitch
/ sizeof(DWORD
);
1396 slice_pitch
= lock_box
.SlicePitch
/ sizeof(DWORD
);
1397 for (z
= 0; z
< size
; z
++)
1399 for (y
= 0; y
< size
; y
++)
1401 for (x
= 0; x
< size
; x
++)
1403 value
= ((DWORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1404 v
[0] = (value
>> 24) & 0xff;
1405 v
[1] = (value
>> 16) & 0xff;
1406 v
[2] = (value
>> 8) & 0xff;
1407 v
[3] = value
& 0xff;
1409 e
[0] = 255.0f
/ size
+ 0.5f
;
1410 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1411 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1412 e
[3] = (z
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1413 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1415 ok(color_match(v
, e
),
1416 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1417 x
, y
, z
, value
, expected
);
1421 IDirect3DVolumeTexture9_UnlockBox(tex
, m
);
1426 IDirect3DVolumeTexture9_Release(tex
);
1429 skip("Failed to create texture\n");
1431 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1432 D3DPOOL_MANAGED
, &tex
, NULL
);
1436 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1437 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1438 hr
= IDirect3DVolumeTexture9_LockBox(tex
, 0, &lock_box
, NULL
, D3DLOCK_READONLY
);
1439 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#x\n", hr
);
1442 row_pitch
= lock_box
.RowPitch
/ sizeof(WORD
);
1443 slice_pitch
= lock_box
.SlicePitch
/ sizeof(WORD
);
1444 for (z
= 0; z
< 4; z
++)
1446 for (y
= 0; y
< 4; y
++)
1448 for (x
= 0; x
< 4; x
++)
1450 value
= ((WORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1452 v
[1] = value
>> 10 & 0x1f;
1453 v
[2] = value
>> 5 & 0x1f;
1454 v
[3] = value
& 0x1f;
1457 e
[1] = (x
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1458 e
[2] = (y
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1459 e
[3] = (z
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1460 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1462 ok(color_match(v
, e
),
1463 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1464 x
, y
, z
, value
, expected
);
1468 IDirect3DVolumeTexture9_UnlockBox(tex
, 0);
1471 IDirect3DVolumeTexture9_Release(tex
);
1474 skip("Failed to create texture\n");
1477 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9
*device
)
1480 IDirect3DTexture9
*texture
;
1481 D3DRESOURCETYPE type
;
1482 D3DSURFACE_DESC desc
;
1483 D3DLOCKED_RECT lock_rect
;
1487 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_16bit
, sizeof(dds_16bit
), &texture
);
1488 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1489 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1491 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
), &texture
);
1492 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1493 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1495 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
) - 1, &texture
);
1496 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
1498 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1499 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &texture
);
1500 todo_wine_if (!has_2d_dxt5
)
1501 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr
, D3D_OK
);
1504 type
= IDirect3DTexture9_GetType(texture
);
1505 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u\n", type
, D3DRTYPE_TEXTURE
);
1506 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1507 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1508 ok(desc
.Width
== 4, "Width is %u, expected 4\n", desc
.Width
);
1509 ok(desc
.Height
== 4, "Height is %u, expected 4\n", desc
.Height
);
1510 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1511 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#x, expected %#x\n", hr
, D3D_OK
);
1514 for (i
= 0; i
< 16; i
++)
1515 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_cube_map
[128 + i
],
1516 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1517 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_cube_map
[128 + i
]);
1518 IDirect3DTexture9_UnlockRect(texture
, 0);
1520 IDirect3DTexture9_Release(texture
);
1524 /* Volume textures work too. */
1525 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &texture
);
1526 todo_wine_if (!has_2d_dxt3
)
1527 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr
, D3D_OK
);
1530 type
= IDirect3DTexture9_GetType(texture
);
1531 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type
, D3DRTYPE_TEXTURE
);
1532 level_count
= IDirect3DBaseTexture9_GetLevelCount((IDirect3DBaseTexture9
*)texture
);
1533 todo_wine
ok(level_count
== 3, "Texture has %u mip levels, 3 expected.\n", level_count
);
1534 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1535 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x.\n", hr
, D3D_OK
);
1536 ok(desc
.Width
== 4, "Width is %u, expected 4.\n", desc
.Width
);
1537 ok(desc
.Height
== 4, "Height is %u, expected 4.\n", desc
.Height
);
1539 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1540 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#x, expected %#x.\n", hr
, D3D_OK
);
1543 for (i
= 0; i
< 16; ++i
)
1544 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_volume_map
[128 + i
],
1545 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1546 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_volume_map
[128 + i
]);
1547 IDirect3DTexture9_UnlockRect(texture
, 0);
1549 /* The lower texture levels are apparently generated by filtering the level 0 surface
1550 * I.e. following levels from the file are ignored. */
1551 IDirect3DTexture9_Release(texture
);
1555 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
1558 IDirect3DTexture9
*texture
;
1559 unsigned int miplevels
;
1560 IDirect3DSurface9
*surface
;
1561 D3DSURFACE_DESC desc
;
1563 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1564 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1565 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1566 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1568 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1569 D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1570 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1571 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1573 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
), D3DX_DEFAULT
,
1574 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1575 D3DX_DEFAULT
, D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_FILTER_POINT
), 0, NULL
, NULL
, &texture
);
1576 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1579 miplevels
= IDirect3DTexture9_GetLevelCount(texture
);
1580 ok(miplevels
== 1, "Got miplevels %u, expected %u\n", miplevels
, 1);
1581 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1582 IDirect3DSurface9_GetDesc(surface
, &desc
);
1583 ok(desc
.Width
== 1 && desc
.Height
== 1,
1584 "Surface dimensions are %ux%u, expected 1x1.\n", desc
.Width
, desc
.Height
);
1585 IDirect3DSurface9_Release(surface
);
1586 IDirect3DTexture9_Release(texture
);
1589 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
1591 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1595 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1596 D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1597 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr
, D3D_OK
);
1598 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1600 /* Checking for color key format overrides. */
1601 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1602 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1603 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1604 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1607 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1608 IDirect3DSurface9_GetDesc(surface
, &desc
);
1609 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X1R5G5B5
);
1610 IDirect3DTexture9_Release(texture
);
1612 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1613 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1614 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1615 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1618 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1619 IDirect3DSurface9_GetDesc(surface
, &desc
);
1620 ok(desc
.Format
== D3DFMT_A1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A1R5G5B5
);
1621 IDirect3DTexture9_Release(texture
);
1623 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1624 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X1R5G5B5
, D3DPOOL_DEFAULT
,
1625 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1626 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1629 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1630 IDirect3DSurface9_GetDesc(surface
, &desc
);
1631 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X1R5G5B5
);
1632 IDirect3DTexture9_Release(texture
);
1635 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1636 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1637 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1638 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1641 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1642 IDirect3DSurface9_GetDesc(surface
, &desc
);
1643 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X8R8G8B8
);
1644 IDirect3DTexture9_Release(texture
);
1646 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1647 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1648 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1649 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1652 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1653 IDirect3DSurface9_GetDesc(surface
, &desc
);
1654 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
1655 IDirect3DTexture9_Release(texture
);
1657 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
1658 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
,
1659 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1660 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1663 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1664 IDirect3DSurface9_GetDesc(surface
, &desc
);
1665 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_X8R8G8B8
);
1666 IDirect3DTexture9_Release(texture
);
1669 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1670 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1671 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1672 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1675 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1676 IDirect3DSurface9_GetDesc(surface
, &desc
);
1677 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_L8
);
1678 IDirect3DTexture9_Release(texture
);
1680 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1681 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1682 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1683 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1686 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1687 IDirect3DSurface9_GetDesc(surface
, &desc
);
1688 ok(desc
.Format
== D3DFMT_A8L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8L8
);
1689 IDirect3DTexture9_Release(texture
);
1691 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
1692 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_L8
, D3DPOOL_DEFAULT
,
1693 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1694 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1697 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1698 IDirect3DSurface9_GetDesc(surface
, &desc
);
1699 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_L8
);
1700 IDirect3DTexture9_Release(texture
);
1704 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9
*device
)
1709 IDirect3DCubeTexture9
*cube_texture
;
1710 D3DSURFACE_DESC surface_desc
;
1712 hr
= D3DXCreateCubeTextureFromFileInMemory(NULL
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
1713 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1715 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, NULL
, sizeof(dds_cube_map
), &cube_texture
);
1716 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1718 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, 0, &cube_texture
);
1719 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1721 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), NULL
);
1722 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1724 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
1727 levelcount
= IDirect3DCubeTexture9_GetLevelCount(cube_texture
);
1728 todo_wine
ok(levelcount
== 3, "GetLevelCount returned %u, expected 3\n", levelcount
);
1730 hr
= IDirect3DCubeTexture9_GetLevelDesc(cube_texture
, 0, &surface_desc
);
1731 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1732 ok(surface_desc
.Width
== 4, "Got width %u, expected 4\n", surface_desc
.Width
);
1733 ok(surface_desc
.Height
== 4, "Got height %u, expected 4\n", surface_desc
.Height
);
1735 ref
= IDirect3DCubeTexture9_Release(cube_texture
);
1736 ok(ref
== 0, "Invalid reference count. Got %u, expected 0\n", ref
);
1737 } else skip("Couldn't create cube texture\n");
1740 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
1743 IDirect3DCubeTexture9
*cube_texture
;
1745 if (!is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
1747 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1751 hr
= D3DXCreateCubeTextureFromFileInMemoryEx(device
, dds_cube_map
, sizeof(dds_cube_map
), D3DX_DEFAULT
, D3DX_DEFAULT
,
1752 D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &cube_texture
);
1753 todo_wine_if (!has_cube_dxt5
)
1754 ok(hr
== D3D_OK
, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr
, D3D_OK
);
1755 if (SUCCEEDED(hr
)) IDirect3DCubeTexture9_Release(cube_texture
);
1758 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9
*device
)
1763 IDirect3DVolumeTexture9
*volume_texture
;
1764 D3DVOLUME_DESC volume_desc
;
1766 hr
= D3DXCreateVolumeTextureFromFileInMemory(NULL
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
1767 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1769 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, NULL
, sizeof(dds_volume_map
), &volume_texture
);
1770 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1772 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, 0, &volume_texture
);
1773 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1775 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), NULL
);
1776 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3DERR_INVALIDCALL
);
1778 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
1779 todo_wine_if (!has_3d_dxt3
)
1780 ok(hr
== D3D_OK
, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1783 levelcount
= IDirect3DVolumeTexture9_GetLevelCount(volume_texture
);
1784 ok(levelcount
== 3, "GetLevelCount returned %u, expected 3\n", levelcount
);
1786 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 0, &volume_desc
);
1787 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1788 ok(volume_desc
.Width
== 4, "Got width %u, expected 4\n", volume_desc
.Width
);
1789 ok(volume_desc
.Height
== 4, "Got height %u, expected 4\n", volume_desc
.Height
);
1790 ok(volume_desc
.Depth
== 2, "Got depth %u, expected 2\n", volume_desc
.Depth
);
1791 ok(volume_desc
.Pool
== D3DPOOL_MANAGED
, "Got pool %u, expected D3DPOOL_MANAGED\n", volume_desc
.Pool
);
1793 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 1, &volume_desc
);
1794 ok(hr
== D3D_OK
, "GetLevelDesc returned %#x, expected %#x\n", hr
, D3D_OK
);
1795 ok(volume_desc
.Width
== 2, "Got width %u, expected 2\n", volume_desc
.Width
);
1796 ok(volume_desc
.Height
== 2, "Got height %u, expected 2\n", volume_desc
.Height
);
1797 ok(volume_desc
.Depth
== 1, "Got depth %u, expected 1\n", volume_desc
.Depth
);
1799 ref
= IDirect3DVolumeTexture9_Release(volume_texture
);
1800 ok(ref
== 0, "Invalid reference count. Got %u, expected 0\n", ref
);
1804 /* fills positive x face with red color */
1805 static void WINAPI
fill_cube_positive_x(D3DXVECTOR4
*out
, const D3DXVECTOR3
*tex_coord
, const D3DXVECTOR3
*texel_size
, void *data
)
1807 memset(out
, 0, sizeof(*out
));
1808 if (tex_coord
->x
> 0 && fabs(tex_coord
->x
) > fabs(tex_coord
->y
) && fabs(tex_coord
->x
) > fabs(tex_coord
->z
))
1812 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9
*device
)
1815 IDirect3DTexture9
*texture
;
1816 IDirect3DCubeTexture9
*cube_texture
;
1817 IDirect3DVolumeTexture9
*volume_texture
;
1818 ID3DXBuffer
*buffer
;
1819 void *buffer_pointer
;
1821 D3DXIMAGE_INFO info
;
1822 D3DXIMAGE_FILEFORMAT file_format
;
1825 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
1828 skip("Failed to create texture\n");
1832 for (file_format
= D3DXIFF_BMP
; file_format
<= D3DXIFF_JPG
; file_format
++)
1834 hr
= D3DXSaveTextureToFileInMemory(&buffer
, file_format
, (IDirect3DBaseTexture9
*)texture
, NULL
);
1835 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1838 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1839 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1840 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1841 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1843 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1844 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1845 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1846 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1847 ok(info
.ImageFileFormat
== file_format
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, file_format
);
1848 ID3DXBuffer_Release(buffer
);
1853 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)texture
, NULL
);
1854 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1857 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1858 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1859 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1860 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1862 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1863 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1864 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
1865 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1866 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
1867 ID3DXBuffer_Release(buffer
);
1871 IDirect3DTexture9_Release(texture
);
1874 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &cube_texture
, NULL
);
1877 skip("Failed to create cube texture\n");
1881 hr
= D3DXFillCubeTexture(cube_texture
, fill_cube_positive_x
, NULL
);
1882 ok(hr
== D3D_OK
, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr
, D3D_OK
);
1884 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
1885 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1888 IDirect3DSurface9
*surface
;
1890 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1891 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1892 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1893 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1895 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1896 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1897 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1898 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1899 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
1901 /* positive x face is saved */
1902 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
1905 D3DLOCKED_RECT locked_rect
;
1907 hr
= D3DXLoadSurfaceFromFileInMemory(surface
, NULL
, NULL
, buffer_pointer
, buffer_size
, NULL
, D3DX_FILTER_NONE
, 0, NULL
);
1908 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1910 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, D3DLOCK_READONLY
);
1913 DWORD
*color
= locked_rect
.pBits
;
1914 ok(*color
== 0x00ff0000, "Got color %#x, expected %#x\n", *color
, 0x00ff0000);
1915 IDirect3DSurface9_UnlockRect(surface
);
1918 IDirect3DSurface9_Release(surface
);
1919 } else skip("Failed to create surface\n");
1921 ID3DXBuffer_Release(buffer
);
1925 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
1926 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1929 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1930 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1931 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1932 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1934 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1935 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1936 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
1937 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
1938 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
1939 ID3DXBuffer_Release(buffer
);
1943 IDirect3DCubeTexture9_Release(cube_texture
);
1945 /* volume textures */
1946 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &volume_texture
, NULL
);
1949 skip("Failed to create volume texture\n");
1954 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
1955 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1958 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1959 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1960 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1961 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1963 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1964 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1965 ok(info
.Depth
== 1, "Got depth %u, expected %u\n", info
.Depth
, 1);
1966 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
1967 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
1968 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
1969 ID3DXBuffer_Release(buffer
);
1972 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
1973 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1976 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
1977 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
1978 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
1979 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr
, D3D_OK
);
1981 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
1982 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
1983 ok(info
.Depth
== 256, "Got depth %u, expected %u\n", info
.Depth
, 256);
1984 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
1985 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
1986 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
1987 ID3DXBuffer_Release(buffer
);
1991 IDirect3DVolumeTexture9_Release(volume_texture
);
1998 IDirect3DDevice9
*device
;
1999 D3DPRESENT_PARAMETERS d3dpp
;
2002 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
2003 640, 480, NULL
, NULL
, NULL
, NULL
)))
2005 skip("Couldn't create application window\n");
2008 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2010 skip("Couldn't create IDirect3D9 object\n");
2015 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
2016 d3dpp
.Windowed
= TRUE
;
2017 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2018 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
2020 skip("Failed to create IDirect3DDevice9 object %#x\n", hr
);
2021 IDirect3D9_Release(d3d
);
2026 /* Check whether DXTn textures are supported. */
2027 has_2d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2028 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT3
));
2029 hr
= IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2030 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT5
);
2031 has_2d_dxt5
= SUCCEEDED(hr
);
2032 hr
= IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2033 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, D3DFMT_DXT5
);
2034 has_cube_dxt5
= SUCCEEDED(hr
);
2035 has_3d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2036 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_VOLUMETEXTURE
, D3DFMT_DXT3
));
2038 test_D3DXCheckTextureRequirements(device
);
2039 test_D3DXCheckCubeTextureRequirements(device
);
2040 test_D3DXCheckVolumeTextureRequirements(device
);
2041 test_D3DXCreateTexture(device
);
2042 test_D3DXFilterTexture(device
);
2043 test_D3DXFillTexture(device
);
2044 test_D3DXFillCubeTexture(device
);
2045 test_D3DXFillVolumeTexture(device
);
2046 test_D3DXCreateTextureFromFileInMemory(device
);
2047 test_D3DXCreateTextureFromFileInMemoryEx(device
);
2048 test_D3DXCreateCubeTextureFromFileInMemory(device
);
2049 test_D3DXCreateCubeTextureFromFileInMemoryEx(device
);
2050 test_D3DXCreateVolumeTextureFromFileInMemory(device
);
2051 test_D3DXSaveTextureToFileInMemory(device
);
2053 IDirect3DDevice9_Release(device
);
2054 IDirect3D9_Release(d3d
);