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_dxt1
, 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
91 static const BYTE dds_dxt5
[] =
93 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
94 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
95 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
96 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
97 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
98 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
99 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
100 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
101 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
104 static const BYTE dds_dxt5_8_8
[] =
106 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x08,0x00,0x00,0x00,
107 0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
108 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
109 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
110 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
111 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
112 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
113 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
114 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x00,0xe0,0x07,0x05,0x05,0x50,0x50,
115 0x3f,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xff,0x07,0x05,0x05,0x50,0x50,
116 0x7f,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0xf8,0xe0,0xff,0x05,0x05,0x50,0x50,
117 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x00,0x00,0x05,0x05,0x50,0x50,
120 static const unsigned char png_grayscale
[] =
122 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
123 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
124 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
125 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
126 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
130 #define ADMITTED_ERROR 0.0001f
132 static inline float relative_error(float expected
, float got
)
134 return expected
== 0.0f
? fabs(expected
- got
) : fabs(1.0f
- got
/ expected
);
137 #define expect_vec4(expected, got) expect_vec4_(__LINE__, expected, got)
138 static inline void expect_vec4_(unsigned int line
, const D3DXVECTOR4
*expected
, const D3DXVECTOR4
*got
)
140 ok_(__FILE__
, line
)(relative_error(expected
->x
, got
->x
) < ADMITTED_ERROR
141 && relative_error(expected
->y
, got
->y
) < ADMITTED_ERROR
142 && relative_error(expected
->z
, got
->z
) < ADMITTED_ERROR
143 && relative_error(expected
->w
, got
->w
) < ADMITTED_ERROR
,
144 "Expected (%f, %f, %f, %f), got (%f, %f, %f, %f)\n",
145 expected
->x
, expected
->y
, expected
->z
, expected
->w
,
146 got
->x
, got
->y
, got
->z
, got
->w
);
149 static BOOL
compare_uint(unsigned int x
, unsigned int y
, unsigned int max_diff
)
151 unsigned int diff
= x
> y
? x
- y
: y
- x
;
153 return diff
<= max_diff
;
156 static BOOL
compare_color(DWORD c1
, DWORD c2
, BYTE max_diff
)
158 return compare_uint(c1
& 0xff, c2
& 0xff, max_diff
)
159 && compare_uint((c1
>> 8) & 0xff, (c2
>> 8) & 0xff, max_diff
)
160 && compare_uint((c1
>> 16) & 0xff, (c2
>> 16) & 0xff, max_diff
)
161 && compare_uint((c1
>> 24) & 0xff, (c2
>> 24) & 0xff, max_diff
);
164 static BOOL
is_autogenmipmap_supported(IDirect3DDevice9
*device
, D3DRESOURCETYPE resource_type
)
170 D3DDEVICE_CREATION_PARAMETERS params
;
172 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
173 IDirect3DDevice9_GetDirect3D(device
, &d3d9
);
174 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
175 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
177 if (!(caps
.Caps2
& D3DCAPS2_CANAUTOGENMIPMAP
))
180 hr
= IDirect3D9_CheckDeviceFormat(d3d9
, params
.AdapterOrdinal
, params
.DeviceType
,
181 mode
.Format
, D3DUSAGE_AUTOGENMIPMAP
, resource_type
, D3DFMT_A8R8G8B8
);
183 IDirect3D9_Release(d3d9
);
187 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9
*device
)
189 UINT width
, height
, mipmaps
;
190 D3DFORMAT format
, expected
;
194 D3DDEVICE_CREATION_PARAMETERS params
;
197 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
200 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
201 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
203 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
204 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
206 hr
= D3DXCheckTextureRequirements(NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
207 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
210 width
= height
= D3DX_DEFAULT
;
211 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
212 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
213 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
214 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
216 width
= D3DX_DEFAULT
;
217 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
218 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
219 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
221 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
222 skip("Hardware only supports pow2 textures\n");
226 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
227 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
228 ok(width
== 62, "Returned width %d, expected %d\n", width
, 62);
230 width
= D3DX_DEFAULT
; height
= 63;
231 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
232 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
233 ok(width
== height
, "Returned width %d, expected %d\n", width
, height
);
234 ok(height
== 63, "Returned height %d, expected %d\n", height
, 63);
237 width
= D3DX_DEFAULT
; height
= 0;
238 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
239 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
240 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
241 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
243 width
= 0; height
= 0;
244 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
245 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
246 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
247 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
250 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
251 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
252 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
255 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
256 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
257 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %ld\n", width
, caps
.MaxTextureWidth
);
259 width
= caps
.MaxTextureWidth
-1;
260 hr
= D3DXCheckTextureRequirements(device
, &width
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
261 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
262 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
263 ok(width
== caps
.MaxTextureWidth
, "Returned width %d, expected %ld\n", width
, caps
.MaxTextureWidth
);
265 ok(width
== caps
.MaxTextureWidth
-1, "Returned width %d, expected %ld\n", width
, caps
.MaxTextureWidth
-1);
268 width
= 64; height
= 63;
270 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
271 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
272 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
274 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
))
276 width
= 284; height
= 137;
278 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
279 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
280 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
284 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
285 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
286 ok(mipmaps
== 6, "Returned mipmaps %d, expected %d\n", mipmaps
, 6);
289 skip("Skipping some tests, npot2 textures unsupported\n");
292 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
293 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
294 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
297 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
298 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
299 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
301 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
302 if (is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
305 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
306 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
307 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
309 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
310 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
311 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
313 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
314 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
315 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
317 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
318 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
319 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
322 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
325 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
326 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
327 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
328 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
329 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
330 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
331 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
332 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
333 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
334 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
337 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
338 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
340 format
= D3DFMT_UNKNOWN
;
341 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
342 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
343 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
345 format
= D3DX_DEFAULT
;
346 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
347 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
348 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
350 format
= D3DFMT_R8G8B8
;
351 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
352 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
353 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
355 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
356 IDirect3DDevice9_GetCreationParameters(device
, ¶ms
);
357 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
359 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
360 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_R3G3B2
)))
361 expected
= D3DFMT_R3G3B2
;
362 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
363 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X4R4G4B4
)))
364 expected
= D3DFMT_X4R4G4B4
;
365 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
366 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_X1R5G5B5
)))
367 expected
= D3DFMT_X1R5G5B5
;
369 expected
= D3DFMT_R5G6B5
;
371 format
= D3DFMT_R3G3B2
;
372 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
373 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
374 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
376 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
377 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R3G3B2
)))
378 expected
= D3DFMT_A8R3G3B2
;
380 expected
= D3DFMT_A8R8G8B8
;
382 format
= D3DFMT_A8R3G3B2
;
383 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
384 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
385 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
387 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
388 mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_P8
)))
389 expected
= D3DFMT_P8
;
391 expected
= D3DFMT_A8R8G8B8
;
394 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
395 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
396 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
398 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
399 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L8
)))
400 expected
= D3DFMT_L8
;
402 expected
= D3DFMT_X8R8G8B8
;
405 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
406 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
407 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
409 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, params
.AdapterOrdinal
, params
.DeviceType
,
410 mode
.Format
, D3DUSAGE_RENDERTARGET
, D3DRTYPE_TEXTURE
, D3DFMT_L16
)))
411 expected
= D3DFMT_L16
;
413 expected
= D3DFMT_A16B16G16R16
;
416 hr
= D3DXCheckTextureRequirements(device
, NULL
, NULL
, NULL
, D3DUSAGE_RENDERTARGET
, &format
, D3DPOOL_DEFAULT
);
417 ok(hr
== D3D_OK
, "D3DXCheckTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
418 ok(format
== expected
, "Returned format %u, expected %u\n", format
, expected
);
420 /* Block-based texture formats and size < block size. */
421 format
= D3DFMT_DXT1
;
422 width
= 2; height
= 2;
424 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
425 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
426 ok(mipmaps
== 1, "Got unexpected level count %u.\n", mipmaps
);
429 ok(width
== 4, "Got unexpected width %d.\n", width
);
430 ok(height
== 4, "Got unexpected height %d.\n", height
);
431 ok(format
== D3DFMT_DXT1
, "Got unexpected format %u.\n", format
);
435 ok(width
== 2, "Got unexpected width %d.\n", width
);
436 ok(height
== 2, "Got unexpected height %d.\n", height
);
437 ok(format
== D3DFMT_A8R8G8B8
, "Got unexpected format %u.\n", format
);
440 format
= D3DFMT_DXT5
;
441 width
= 2; height
= 2;
442 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
443 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
444 ok(mipmaps
== 1, "Got unexpected level count %u.\n", mipmaps
);
447 ok(width
== 4, "Got unexpected width %d.\n", width
);
448 ok(height
== 4, "Got unexpected height %d.\n", height
);
449 ok(format
== D3DFMT_DXT5
, "Got unexpected format %u.\n", format
);
453 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
454 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
455 ok(width
== 12, "Got unexpected width %u.\n", width
);
456 ok(height
== 12, "Got unexpected height %u.\n", height
);
457 ok(mipmaps
== 1, "Got unexpected level count %u.\n", mipmaps
);
458 ok(format
== D3DFMT_DXT5
, "Got unexpected format %u.\n", format
);
462 ok(width
== 2, "Got unexpected width %d.\n", width
);
463 ok(height
== 2, "Got unexpected height %d.\n", height
);
464 ok(format
== D3DFMT_A8R8G8B8
, "Got unexpected format %u.\n", format
);
468 hr
= D3DXCheckTextureRequirements(device
, &width
, &height
, &mipmaps
, 0, &format
, D3DPOOL_DEFAULT
);
469 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
470 ok(width
== 4, "Got unexpected width %u.\n", width
);
471 ok(mipmaps
== 1, "Got unexpected level count %u.\n", mipmaps
);
474 ok(height
== 4, "Got unexpected height %u.\n", height
);
475 ok(format
== D3DFMT_DXT5
, "Got unexpected format %u.\n", format
);
479 ok(height
== 2, "Got unexpected height %u.\n", height
);
480 ok(format
== D3DFMT_A8R8G8B8
, "Got unexpected format %u.\n", format
);
483 IDirect3D9_Release(d3d
);
486 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9
*device
)
488 UINT size
, mipmaps
, expected
;
493 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
495 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
497 skip("No cube textures support\n");
502 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
503 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
505 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
506 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
508 hr
= D3DXCheckCubeTextureRequirements(NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
509 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
513 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
514 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
515 ok(size
== 256, "Returned size %d, expected %d\n", size
, 256);
520 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
521 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
522 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
526 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 10 : 9;
527 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
528 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
529 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
530 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
534 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP_POW2
? 7 : 6;
535 expected
= caps
.TextureCaps
& D3DPTEXTURECAPS_MIPCUBEMAP
? expected
: 1;
536 hr
= D3DXCheckCubeTextureRequirements(device
, &size
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
537 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
538 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
541 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
542 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
543 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
545 if (is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
548 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, &mipmaps
, D3DUSAGE_AUTOGENMIPMAP
, NULL
, D3DPOOL_DEFAULT
);
549 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
550 ok(mipmaps
== 0, "Returned mipmaps %d, expected %d\n", mipmaps
, 0);
553 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
556 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_WRITEONLY
, NULL
, D3DPOOL_DEFAULT
);
557 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
558 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_DONOTCLIP
, NULL
, D3DPOOL_DEFAULT
);
559 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
560 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_POINTS
, NULL
, D3DPOOL_DEFAULT
);
561 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
562 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_RTPATCHES
, NULL
, D3DPOOL_DEFAULT
);
563 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
564 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, D3DUSAGE_NPATCHES
, NULL
, D3DPOOL_DEFAULT
);
565 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
568 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
569 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
571 format
= D3DFMT_UNKNOWN
;
572 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
573 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
574 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
576 format
= D3DX_DEFAULT
;
577 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
578 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
579 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
581 format
= D3DFMT_R8G8B8
;
582 hr
= D3DXCheckCubeTextureRequirements(device
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
583 ok(hr
== D3D_OK
, "D3DXCheckCubeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
584 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
587 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9
*device
)
589 UINT width
, height
, depth
, mipmaps
, expected
;
594 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
596 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
) || (caps
.MaxVolumeExtent
< 256))
598 skip("Limited or no volume textures support.\n");
603 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
604 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
606 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
607 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
609 hr
= D3DXCheckVolumeTextureRequirements(NULL
, NULL
, NULL
, NULL
, NULL
, D3DX_DEFAULT
, NULL
, D3DPOOL_DEFAULT
);
610 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
612 /* width, height, depth */
613 width
= height
= depth
= D3DX_DEFAULT
;
614 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
615 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
616 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
617 ok(height
== 256, "Returned height %d, expected %d\n", height
, 256);
618 ok(depth
== 1, "Returned depth %d, expected %d\n", depth
, 1);
620 width
= D3DX_DEFAULT
;
621 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
622 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
623 ok(width
== 256, "Returned width %d, expected %d\n", width
, 256);
625 width
= D3DX_DEFAULT
; height
= 0; depth
= 0;
626 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
627 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
628 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
629 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
630 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
632 width
= 0; height
= 0; depth
= 0;
633 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
634 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
635 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
636 ok(height
== 1, "Returned height %d, expected %d\n", height
, 1);
637 ok(depth
== 1, "Returned height %d, expected %d\n", depth
, 1);
640 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
641 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
642 ok(width
== 1, "Returned width %d, expected %d\n", width
, 1);
645 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
646 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
647 ok(width
== caps
.MaxVolumeExtent
, "Returned width %d, expected %ld\n", width
, caps
.MaxVolumeExtent
);
650 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, D3DPOOL_DEFAULT
);
651 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
653 format
= D3DFMT_UNKNOWN
;
654 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
655 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
656 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
658 format
= D3DX_DEFAULT
;
659 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
660 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
661 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
663 format
= D3DFMT_R8G8B8
;
664 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
665 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
666 ok(format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_X8R8G8B8
);
668 format
= D3DFMT_DXT3
;
669 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, NULL
, 0, &format
, D3DPOOL_DEFAULT
);
670 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
672 ok(format
== D3DFMT_DXT3
, "Returned format %u, expected %u\n", format
, D3DFMT_DXT3
);
674 ok(format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", format
, D3DFMT_A8R8G8B8
);
677 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_MIPVOLUMEMAP
))
679 skip("No volume textures mipmapping support\n");
683 width
= height
= depth
= 64;
685 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
686 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
687 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
693 expected
= (caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP_POW2
&& caps
.MaxVolumeExtent
>= 512) ? 10 : 9;
694 hr
= D3DXCheckVolumeTextureRequirements(device
, &width
, &height
, &depth
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
695 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
696 ok(mipmaps
== expected
, "Returned mipmaps %d, expected %d\n", mipmaps
, expected
);
699 hr
= D3DXCheckVolumeTextureRequirements(device
, NULL
, NULL
, NULL
, &mipmaps
, 0, NULL
, D3DPOOL_DEFAULT
);
700 ok(hr
== D3D_OK
, "D3DXCheckVolumeTextureRequirements returned %#lx, expected %#lx\n", hr
, D3D_OK
);
701 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
703 /* D3DUSAGE_AUTOGENMIPMAP is never supported for volume textures. */
704 ok(!is_autogenmipmap_supported(device
, D3DRTYPE_VOLUMETEXTURE
),
705 "D3DUSAGE_AUTOGENMIPMAP is unexpectedly supported on volume textures.\n");
708 static void test_D3DXCreateTexture(IDirect3DDevice9
*device
)
710 IDirect3DTexture9
*texture
;
711 D3DSURFACE_DESC desc
;
716 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
718 hr
= D3DXCreateTexture(NULL
, 0, 0, 0, 0, D3DX_DEFAULT
, D3DPOOL_DEFAULT
, NULL
);
719 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
721 /* width and height tests */
723 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, 0, D3DPOOL_DEFAULT
, &texture
);
724 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
728 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
729 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
730 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
732 ok(desc
.Width
== 256, "Returned width %d, expected %d\n", desc
.Width
, 256);
733 ok(desc
.Height
== 256, "Returned height %d, expected %d\n", desc
.Height
, 256);
735 IDirect3DTexture9_Release(texture
);
739 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
740 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
744 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
745 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
746 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
748 ok(desc
.Width
== 1, "Returned width %d, expected %d\n", desc
.Width
, 1);
749 ok(desc
.Height
== 1, "Returned height %d, expected %d\n", desc
.Height
, 1);
751 IDirect3DTexture9_Release(texture
);
755 if (caps
.TextureCaps
& D3DPTEXTURECAPS_POW2
)
756 skip("Hardware only supports pow2 textures\n");
759 hr
= D3DXCreateTexture(device
, D3DX_DEFAULT
, 63, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
761 /* may not work with conditional NPOT */
762 ((hr
!= D3D_OK
) && (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
)),
763 "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
767 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
768 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
769 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
771 /* Conditional NPOT may create a texture with different dimensions, so allow those
772 situations instead of returning a fail */
774 ok(desc
.Width
== 63 ||
775 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
776 "Returned width %d, expected %d\n", desc
.Width
, 63);
778 ok(desc
.Height
== 63 ||
779 (caps
.TextureCaps
& D3DPTEXTURECAPS_NONPOW2CONDITIONAL
),
780 "Returned height %d, expected %d\n", desc
.Height
, 63);
782 IDirect3DTexture9_Release(texture
);
788 hr
= D3DXCreateTexture(device
, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
789 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
793 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
794 ok(mipmaps
== 7, "Returned mipmaps %d, expected %d\n", mipmaps
, 7);
796 IDirect3DTexture9_Release(texture
);
800 hr
= D3DXCreateTexture(device
, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT
, &texture
);
801 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
805 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
806 ok(mipmaps
== 9, "Returned mipmaps %d, expected %d\n", mipmaps
, 9);
808 IDirect3DTexture9_Release(texture
);
812 hr
= D3DXCreateTexture(device
, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT
, &texture
);
813 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
817 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
818 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
820 IDirect3DTexture9_Release(texture
);
824 hr
= D3DXCreateTexture(device
, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT
, &texture
);
825 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
829 mipmaps
= IDirect3DTexture9_GetLevelCount(texture
);
830 ok(mipmaps
== 1, "Returned mipmaps %d, expected %d\n", mipmaps
, 1);
832 IDirect3DTexture9_Release(texture
);
837 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_WRITEONLY
, 0, D3DPOOL_DEFAULT
, &texture
);
838 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
839 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_DONOTCLIP
, 0, D3DPOOL_DEFAULT
, &texture
);
840 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
841 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_POINTS
, 0, D3DPOOL_DEFAULT
, &texture
);
842 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
843 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_RTPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
844 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
845 hr
= D3DXCreateTexture(device
, 0, 0, 0, D3DUSAGE_NPATCHES
, 0, D3DPOOL_DEFAULT
, &texture
);
846 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTexture succeeded, but should have failed.\n");
850 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, &texture
);
851 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
855 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
856 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
857 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
859 IDirect3DTexture9_Release(texture
);
863 hr
= D3DXCreateTexture(device
, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT
, &texture
);
864 ok(hr
== D3D_OK
, "D3DXCreateTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
868 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
869 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
870 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u\n", desc
.Format
, D3DFMT_A8R8G8B8
);
872 IDirect3DTexture9_Release(texture
);
875 /* D3DXCreateTextureFromResource */
876 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDB_BITMAP_1x1
), &texture
);
877 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#lx, expected %#lx\n", hr
, D3D_OK
);
878 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
880 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
881 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResource returned %#lx, expected %#lx\n", hr
, D3D_OK
);
882 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
884 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDS_STRING
), &texture
);
885 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#lx, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
887 hr
= D3DXCreateTextureFromResourceA(NULL
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), &texture
);
888 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
890 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, NULL
, &texture
);
891 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResource returned %#lx, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
893 hr
= D3DXCreateTextureFromResourceA(device
, NULL
, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1
), NULL
);
894 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResource returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
897 /* D3DXCreateTextureFromResourceEx */
898 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
);
899 ok(hr
== D3D_OK
, "D3DXCreateTextureFromResourceEx returned %#lx, expected %#lx\n", hr
, D3D_OK
);
900 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
902 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
);
903 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#lx, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
905 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
);
906 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
908 hr
= D3DXCreateTextureFromResourceExA(device
, NULL
, NULL
, D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_MANAGED
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
909 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromResourceEx returned %#lx, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
911 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
);
912 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateTextureFromResourceEx returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
915 static void test_D3DXFilterTexture(IDirect3DDevice9
*device
)
917 IDirect3DTexture9
*tex
;
918 IDirect3DCubeTexture9
*cubetex
;
919 IDirect3DVolumeTexture9
*voltex
;
922 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex
, NULL
);
926 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, D3DX_DEFAULT
, D3DX_FILTER_NONE
);
927 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
929 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
930 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
932 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
933 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
935 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
936 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
938 IDirect3DTexture9_Release(tex
);
941 skip("Failed to create texture\n");
943 hr
= D3DXFilterTexture(NULL
, NULL
, 0, D3DX_FILTER_NONE
);
944 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
946 /* Test different pools */
947 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
, &tex
, NULL
);
951 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
952 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
953 IDirect3DTexture9_Release(tex
);
956 skip("Failed to create texture\n");
958 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SCRATCH
, &tex
, NULL
);
962 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
963 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
964 IDirect3DTexture9_Release(tex
);
967 skip("Failed to create texture\n");
969 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
972 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
973 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
974 IDirect3DTexture9_Release(tex
);
977 skip("Failed to create texture\n");
979 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
982 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_POINT
);
983 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
984 IDirect3DTexture9_Release(tex
);
987 skip("Failed to create texture\n");
989 /* Cube texture test */
990 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 5, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &cubetex
, NULL
);
994 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_NONE
);
995 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
997 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 0, D3DX_FILTER_BOX
+ 1); /* Invalid filter */
998 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
1000 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) cubetex
, NULL
, 5, D3DX_FILTER_NONE
); /* Invalid miplevel */
1001 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
1002 IDirect3DCubeTexture9_Release(cubetex
);
1005 skip("Failed to create texture\n");
1007 /* Volume texture test */
1008 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &voltex
, NULL
);
1011 DWORD level_count
= IDirect3DVolumeTexture9_GetLevelCount(voltex
);
1013 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_NONE
);
1014 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1016 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_DEFAULT
);
1017 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1019 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, 0, D3DX_FILTER_BOX
);
1020 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1022 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
- 1, D3DX_DEFAULT
);
1023 ok(hr
== D3D_OK
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1025 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) voltex
, NULL
, level_count
, D3DX_DEFAULT
);
1026 ok(hr
== D3DERR_INVALIDCALL
, "D3DXFilterTexture returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
1028 IDirect3DVolumeTexture9_Release(voltex
);
1031 skip("Failed to create volume texture\n");
1033 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
1034 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
1036 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
1040 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
1043 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
1044 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1045 IDirect3DTexture9_Release(tex
);
1048 skip("Failed to create texture\n");
1050 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_A8R8G8B8
, D3DPOOL_DEFAULT
, &tex
, NULL
);
1053 hr
= D3DXFilterTexture((IDirect3DBaseTexture9
*) tex
, NULL
, 0, D3DX_FILTER_NONE
);
1054 ok(hr
== D3D_OK
, "D3dXFilteTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1055 IDirect3DTexture9_Release(tex
);
1058 skip("Failed to create texture\n");
1061 static BOOL
color_match(const DWORD
*value
, const DWORD
*expected
)
1065 for (i
= 0; i
< 4; i
++)
1067 DWORD diff
= value
[i
] > expected
[i
] ? value
[i
] - expected
[i
] : expected
[i
] - value
[i
];
1068 if (diff
> 1) return FALSE
;
1073 static void WINAPI
fillfunc(D3DXVECTOR4
*value
, const D3DXVECTOR2
*texcoord
,
1074 const D3DXVECTOR2
*texelsize
, void *data
)
1076 value
->x
= texcoord
->x
;
1077 value
->y
= texcoord
->y
;
1078 value
->z
= texelsize
->x
;
1082 static void test_D3DXFillTexture(IDirect3DDevice9
*device
)
1089 test_access_types
[] =
1091 {0, D3DPOOL_MANAGED
},
1092 {0, D3DPOOL_DEFAULT
},
1093 {D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
},
1096 IDirect3DTexture9
*tex
;
1098 D3DLOCKED_RECT lock_rect
;
1101 DWORD value
, expected
, size
, pitch
;
1104 for (i
= 0; i
< ARRAY_SIZE(test_access_types
); ++i
)
1107 hr
= IDirect3DDevice9_CreateTexture(device
, size
, size
, 0, test_access_types
[i
].usage
,
1108 D3DFMT_A8R8G8B8
, test_access_types
[i
].pool
, &tex
, NULL
);
1109 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u.\n", hr
, i
);
1111 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1112 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u.\n", hr
, i
);
1114 for (m
= 0; m
< 3; m
++)
1116 IDirect3DSurface9
*src_surface
, *temp_surface
;
1118 hr
= IDirect3DTexture9_GetSurfaceLevel(tex
, m
, &src_surface
);
1119 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u, m %lu.\n", hr
, i
, m
);
1120 temp_surface
= src_surface
;
1122 if (FAILED(hr
= IDirect3DSurface9_LockRect(src_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
)))
1124 hr
= IDirect3DDevice9_CreateRenderTarget(device
, size
, size
,
1125 D3DFMT_A8R8G8B8
, D3DMULTISAMPLE_NONE
, 0, TRUE
, &temp_surface
, NULL
);
1126 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u, m %lu.\n", hr
, i
, m
);
1127 hr
= IDirect3DDevice9_StretchRect(device
, src_surface
, NULL
, temp_surface
, NULL
, D3DTEXF_NONE
);
1128 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u, m %lu.\n", hr
, i
, m
);
1129 hr
= IDirect3DSurface9_LockRect(temp_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1130 ok(hr
== D3D_OK
, "Unexpected hr %#lx, i %u, m %lu.\n", hr
, i
, m
);
1133 pitch
= lock_rect
.Pitch
/ sizeof(DWORD
);
1134 for (y
= 0; y
< size
; y
++)
1136 for (x
= 0; x
< size
; x
++)
1138 value
= ((DWORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1139 v
[0] = (value
>> 24) & 0xff;
1140 v
[1] = (value
>> 16) & 0xff;
1141 v
[2] = (value
>> 8) & 0xff;
1142 v
[3] = value
& 0xff;
1145 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1146 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1147 e
[3] = 255.0f
/ size
+ 0.5f
;
1148 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1150 ok(color_match(v
, e
),
1151 "Texel at (%lu, %lu) doesn't match: %#lx, expected %#lx, i %u, m %lu.\n",
1152 x
, y
, value
, expected
, i
, m
);
1155 IDirect3DSurface9_UnlockRect(temp_surface
);
1156 if (temp_surface
!= src_surface
)
1157 IDirect3DSurface9_Release(temp_surface
);
1158 IDirect3DSurface9_Release(src_surface
);
1161 IDirect3DTexture9_Release(tex
);
1164 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DEPTHSTENCIL
,
1165 D3DFMT_D16_LOCKABLE
, D3DPOOL_DEFAULT
, &tex
, NULL
);
1168 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1169 todo_wine
ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1170 IDirect3DTexture9_Release(tex
);
1173 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, D3DUSAGE_DEPTHSTENCIL
,
1174 D3DFMT_D16
, D3DPOOL_DEFAULT
, &tex
, NULL
);
1177 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1178 ok(hr
== D3DERR_INVALIDCALL
, "Unexpected hr %#lx.\n", hr
);
1179 IDirect3DTexture9_Release(tex
);
1182 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1183 D3DPOOL_MANAGED
, &tex
, NULL
);
1187 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1188 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1190 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1191 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#lx\n", hr
);
1194 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1195 for (y
= 0; y
< 4; y
++)
1197 for (x
= 0; x
< 4; x
++)
1199 value
= ((WORD
*)lock_rect
.pBits
)[y
* pitch
+ x
];
1201 v
[1] = value
>> 10 & 0x1f;
1202 v
[2] = value
>> 5 & 0x1f;
1203 v
[3] = value
& 0x1f;
1206 e
[1] = (x
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1207 e
[2] = (y
+ 0.5f
) / 4.0f
* 31.0f
+ 0.5f
;
1209 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1211 ok(color_match(v
, e
),
1212 "Texel at (%lu, %lu) doesn't match: %#lx, expected %#lx\n",
1213 x
, y
, value
, expected
);
1216 IDirect3DTexture9_UnlockRect(tex
, 0);
1219 IDirect3DTexture9_Release(tex
);
1222 skip("Failed to create texture\n");
1224 /* test floating-point textures */
1225 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A16B16G16R16F
,
1226 D3DPOOL_MANAGED
, &tex
, NULL
);
1230 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1231 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1233 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1236 pitch
= lock_rect
.Pitch
/ sizeof(WORD
);
1237 for (y
= 0; y
< 4; y
++)
1239 WORD
*ptr
= (WORD
*)lock_rect
.pBits
+ y
* pitch
;
1240 for (x
= 0; x
< 4; x
++)
1242 D3DXVECTOR4 got
, expected
;
1244 D3DXFloat16To32Array((FLOAT
*)&got
, (D3DXFLOAT16
*)ptr
, 4);
1247 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1248 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1249 expected
.z
= 1.0f
/ 4.0f
;
1252 expect_vec4(&expected
, &got
);
1256 IDirect3DTexture9_UnlockRect(tex
, 0);
1259 skip("Failed to lock texture\n");
1261 IDirect3DTexture9_Release(tex
);
1264 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1266 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_A32B32G32R32F
,
1267 D3DPOOL_MANAGED
, &tex
, NULL
);
1271 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1272 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1274 hr
= IDirect3DTexture9_LockRect(tex
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1277 pitch
= lock_rect
.Pitch
/ sizeof(float);
1278 for (y
= 0; y
< 4; y
++)
1280 float *ptr
= (float *)lock_rect
.pBits
+ y
* pitch
;
1281 for (x
= 0; x
< 4; x
++)
1283 D3DXVECTOR4 got
, expected
;
1290 expected
.x
= (x
+ 0.5f
) / 4.0f
;
1291 expected
.y
= (y
+ 0.5f
) / 4.0f
;
1292 expected
.z
= 1.0f
/ 4.0f
;
1295 expect_vec4(&expected
, &got
);
1299 IDirect3DTexture9_UnlockRect(tex
, 0);
1302 skip("Failed to lock texture\n");
1304 IDirect3DTexture9_Release(tex
);
1307 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1309 /* test a compressed texture */
1310 hr
= IDirect3DDevice9_CreateTexture(device
, 4, 4, 1, 0, D3DFMT_DXT1
,
1311 D3DPOOL_MANAGED
, &tex
, NULL
);
1315 hr
= D3DXFillTexture(tex
, fillfunc
, NULL
);
1316 todo_wine
ok(hr
== D3D_OK
, "D3DXFillTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1318 IDirect3DTexture9_Release(tex
);
1321 skip("Failed to create D3DFMT_DXT1 texture\n");
1324 static void WINAPI
fillfunc_cube(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1325 const D3DXVECTOR3
*texelsize
, void *data
)
1327 value
->x
= (texcoord
->x
+ 1.0f
) / 2.0f
;
1328 value
->y
= (texcoord
->y
+ 1.0f
) / 2.0f
;
1329 value
->z
= (texcoord
->z
+ 1.0f
) / 2.0f
;
1330 value
->w
= texelsize
->x
;
1333 static void WINAPI
fillfunc_cube_coord(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1334 const D3DXVECTOR3
*texelsize
, void *data
)
1336 value
->x
= texcoord
->x
;
1337 value
->y
= texcoord
->y
;
1338 value
->z
= texcoord
->z
;
1352 static float get_cube_coord(enum cube_coord coord
, unsigned int x
, unsigned int y
, unsigned int size
)
1359 return size
- x
- 0.5f
;
1363 return size
- y
- 0.5f
;
1369 trace("Unexpected coordinate value\n");
1374 static DWORD
get_argb_color(D3DFORMAT format
, DWORD x
, DWORD y
, const D3DLOCKED_RECT
*lock_rect
)
1381 case D3DFMT_A8R8G8B8
:
1382 pitch
= lock_rect
->Pitch
/ sizeof(DWORD
);
1383 return ((DWORD
*)lock_rect
->pBits
)[y
* pitch
+ x
];
1384 case D3DFMT_A1R5G5B5
:
1385 pitch
= lock_rect
->Pitch
/ sizeof(WORD
);
1386 value
= ((WORD
*)lock_rect
->pBits
)[y
* pitch
+ x
];
1388 ret
= (value
>> 15 & 0x1) << 24
1389 | (value
>> 10 & 0x1f) << 16
1390 | (value
>> 5 & 0x1f) << 8
1400 static BYTE
get_s8_clipped(float v
)
1402 return (BYTE
)(v
>= 0.0f
? v
* 255 + 0.5f
: 0.0f
);
1405 static DWORD
get_expected_argb_color(D3DFORMAT format
, const D3DXVECTOR4
*v
)
1409 case D3DFMT_A8R8G8B8
:
1410 return get_s8_clipped(v
->w
) << 24
1411 | get_s8_clipped(v
->x
) << 16
1412 | get_s8_clipped(v
->y
) << 8
1413 | get_s8_clipped(v
->z
);
1415 case D3DFMT_A1R5G5B5
:
1416 return (BYTE
)(v
->w
+ 0.5f
) << 24
1417 | (BYTE
)(v
->x
* 31 + 0.5f
) << 16
1418 | (BYTE
)(v
->y
* 31 + 0.5f
) << 8
1419 | (BYTE
)(v
->z
* 31 + 0.5f
);
1425 #define compare_cube_texture(t,f,d) compare_cube_texture_(t,f,d,__LINE__)
1426 static void compare_cube_texture_(IDirect3DCubeTexture9
*texture
,
1427 LPD3DXFILL3D func
, BYTE diff
, unsigned int line
)
1429 static const enum cube_coord coordmap
[6][3] =
1431 {ONE
, YCOORDINV
, XCOORDINV
},
1432 {ZERO
, YCOORDINV
, XCOORD
},
1433 {XCOORD
, ONE
, YCOORD
},
1434 {XCOORD
, ZERO
, YCOORDINV
},
1435 {XCOORD
, YCOORDINV
, ONE
},
1436 {XCOORDINV
, YCOORDINV
, ZERO
}
1439 DWORD x
, y
, m
, f
, levels
, size
, value
, expected
;
1440 D3DXVECTOR3 coord
, texelsize
;
1441 D3DLOCKED_RECT lock_rect
;
1442 D3DSURFACE_DESC desc
;
1446 levels
= IDirect3DCubeTexture9_GetLevelCount(texture
);
1448 for (m
= 0; m
< levels
; ++m
)
1450 hr
= IDirect3DCubeTexture9_GetLevelDesc(texture
, m
, &desc
);
1451 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1455 for (f
= 0; f
< 6; f
++)
1457 texelsize
.x
= (f
== 0) || (f
== 1) ? 0.0f
: 2.0f
/ size
;
1458 texelsize
.y
= (f
== 2) || (f
== 3) ? 0.0f
: 2.0f
/ size
;
1459 texelsize
.z
= (f
== 4) || (f
== 5) ? 0.0f
: 2.0f
/ size
;
1461 hr
= IDirect3DCubeTexture9_LockRect(texture
, f
, m
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1462 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#lx.\n", hr
);
1464 for (y
= 0; y
< size
; y
++)
1466 for (x
= 0; x
< size
; x
++)
1468 coord
.x
= get_cube_coord(coordmap
[f
][0], x
, y
, size
) / size
* 2.0f
- 1.0f
;
1469 coord
.y
= get_cube_coord(coordmap
[f
][1], x
, y
, size
) / size
* 2.0f
- 1.0f
;
1470 coord
.z
= get_cube_coord(coordmap
[f
][2], x
, y
, size
) / size
* 2.0f
- 1.0f
;
1472 func(&out
, &coord
, &texelsize
, NULL
);
1474 value
= get_argb_color(desc
.Format
, x
, y
, &lock_rect
);
1475 expected
= get_expected_argb_color(desc
.Format
, &out
);
1477 ok_(__FILE__
, line
)(compare_color(value
, expected
, diff
),
1478 "Texel at face %lu (%lu, %lu) doesn't match: %08lx, expected %08lx.\n",
1479 f
, x
, y
, value
, expected
);
1482 IDirect3DCubeTexture9_UnlockRect(texture
, f
, m
);
1487 static void test_D3DXFillCubeTexture(IDirect3DDevice9
*device
)
1489 IDirect3DCubeTexture9
*tex
;
1493 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 4, 0, 0, D3DFMT_A8R8G8B8
, D3DPOOL_MANAGED
, &tex
, NULL
);
1494 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1496 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1497 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1498 compare_cube_texture(tex
, fillfunc_cube
, 1);
1500 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube_coord
, NULL
);
1501 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1502 compare_cube_texture(tex
, fillfunc_cube_coord
, 1);
1504 IDirect3DCubeTexture9_Release(tex
);
1507 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 4, 1, 0, D3DFMT_A1R5G5B5
,
1508 D3DPOOL_MANAGED
, &tex
, NULL
);
1509 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1510 hr
= D3DXFillCubeTexture(tex
, fillfunc_cube
, NULL
);
1511 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1512 compare_cube_texture(tex
, fillfunc_cube
, 2);
1513 IDirect3DCubeTexture9_Release(tex
);
1516 static void WINAPI
fillfunc_volume(D3DXVECTOR4
*value
, const D3DXVECTOR3
*texcoord
,
1517 const D3DXVECTOR3
*texelsize
, void *data
)
1519 value
->x
= texcoord
->x
;
1520 value
->y
= texcoord
->y
;
1521 value
->z
= texcoord
->z
;
1522 value
->w
= texelsize
->x
;
1525 static void test_D3DXFillVolumeTexture(IDirect3DDevice9
*device
)
1527 IDirect3DVolumeTexture9
*tex
;
1529 D3DLOCKED_BOX lock_box
;
1532 DWORD value
, expected
, size
, row_pitch
, slice_pitch
;
1535 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, size
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1536 D3DPOOL_DEFAULT
, &tex
, NULL
);
1537 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
1538 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1539 ok(hr
== D3DERR_INVALIDCALL
, "Unexpected hr %#lx.\n", hr
);
1540 IDirect3DVolumeTexture9_Release(tex
);
1542 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, size
, size
, size
, 0, 0, D3DFMT_A8R8G8B8
,
1543 D3DPOOL_MANAGED
, &tex
, NULL
);
1546 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1547 ok(hr
== D3D_OK
, "D3DXFillVolumeTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1549 for (m
= 0; m
< 3; m
++)
1551 hr
= IDirect3DVolumeTexture9_LockBox(tex
, m
, &lock_box
, NULL
, D3DLOCK_READONLY
);
1552 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#lx\n", hr
);
1555 row_pitch
= lock_box
.RowPitch
/ sizeof(DWORD
);
1556 slice_pitch
= lock_box
.SlicePitch
/ sizeof(DWORD
);
1557 for (z
= 0; z
< size
; z
++)
1559 for (y
= 0; y
< size
; y
++)
1561 for (x
= 0; x
< size
; x
++)
1563 value
= ((DWORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1564 v
[0] = (value
>> 24) & 0xff;
1565 v
[1] = (value
>> 16) & 0xff;
1566 v
[2] = (value
>> 8) & 0xff;
1567 v
[3] = value
& 0xff;
1569 e
[0] = 255.0f
/ size
+ 0.5f
;
1570 e
[1] = (x
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1571 e
[2] = (y
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1572 e
[3] = (z
+ 0.5f
) / size
* 255.0f
+ 0.5f
;
1573 expected
= e
[0] << 24 | e
[1] << 16 | e
[2] << 8 | e
[3];
1575 ok(color_match(v
, e
),
1576 "Texel at (%lu, %lu, %lu) doesn't match: %#lx, expected %#lx\n",
1577 x
, y
, z
, value
, expected
);
1581 IDirect3DVolumeTexture9_UnlockBox(tex
, m
);
1586 IDirect3DVolumeTexture9_Release(tex
);
1589 skip("Failed to create texture\n");
1591 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5
,
1592 D3DPOOL_MANAGED
, &tex
, NULL
);
1596 hr
= D3DXFillVolumeTexture(tex
, fillfunc_volume
, NULL
);
1597 ok(hr
== D3D_OK
, "D3DXFillTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1598 hr
= IDirect3DVolumeTexture9_LockBox(tex
, 0, &lock_box
, NULL
, D3DLOCK_READONLY
);
1599 ok(hr
== D3D_OK
, "Couldn't lock the texture, error %#lx\n", hr
);
1602 row_pitch
= lock_box
.RowPitch
/ sizeof(WORD
);
1603 slice_pitch
= lock_box
.SlicePitch
/ sizeof(WORD
);
1604 for (z
= 0; z
< 4; z
++)
1606 for (y
= 0; y
< 4; y
++)
1608 for (x
= 0; x
< 4; x
++)
1610 value
= ((WORD
*)lock_box
.pBits
)[z
* slice_pitch
+ y
* row_pitch
+ x
];
1612 v
[1] = value
>> 10 & 0x1f;
1613 v
[2] = value
>> 5 & 0x1f;
1614 v
[3] = value
& 0x1f;
1617 e
[1] = (x
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1618 e
[2] = (y
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1619 e
[3] = (z
+ 0.5f
) / 4 * 31.0f
+ 0.5f
;
1620 expected
= e
[0] << 15 | e
[1] << 10 | e
[2] << 5 | e
[3];
1622 ok(color_match(v
, e
),
1623 "Texel at (%lu, %lu, %lu) doesn't match: %#lx, expected %#lx\n",
1624 x
, y
, z
, value
, expected
);
1628 IDirect3DVolumeTexture9_UnlockBox(tex
, 0);
1631 IDirect3DVolumeTexture9_Release(tex
);
1634 skip("Failed to create texture\n");
1637 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9
*device
)
1639 static const DWORD dds_dxt5_expected
[] =
1641 0xff7b207b, 0xff7b207b, 0xff84df7b, 0xff84df7b,
1642 0xff7b207b, 0xff7b207b, 0xff84df7b, 0xff84df7b,
1643 0xff7b207b, 0xff7b207b, 0xff84df7b, 0xff84df7b,
1644 0xff7b207b, 0xff7b207b, 0xff84df7b, 0xff84df7b,
1646 static const DWORD dds_dxt5_8_8_expected
[] =
1648 0x0000ff00, 0x0000ff00, 0x000000ff, 0x000000ff, 0x3f00ffff, 0x3f00ffff, 0x3fff0000, 0x3fff0000,
1649 0x0000ff00, 0x0000ff00, 0x000000ff, 0x000000ff, 0x3f00ffff, 0x3f00ffff, 0x3fff0000, 0x3fff0000,
1650 0x000000ff, 0x000000ff, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3f00ffff, 0x3f00ffff,
1651 0x000000ff, 0x000000ff, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3f00ffff, 0x3f00ffff,
1652 0x7fffff00, 0x7fffff00, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xffffffff, 0xffffffff,
1653 0x7fffff00, 0x7fffff00, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xffffffff, 0xffffffff,
1654 0x7fff00ff, 0x7fff00ff, 0x7fffff00, 0x7fffff00, 0xffffffff, 0xffffffff, 0xff000000, 0xff000000,
1655 0x7fff00ff, 0x7fff00ff, 0x7fffff00, 0x7fffff00, 0xffffffff, 0xffffffff, 0xff000000, 0xff000000,
1657 static const DWORD dds_dxt5_8_8_expected_misaligned_1
[] =
1659 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3fff0000, 0x3fff0000,
1660 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3fff0000, 0x3fff0000,
1661 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3fff0000, 0x3fff0000,
1662 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x3fff0000, 0x3fff0000,
1663 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1664 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1665 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1666 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0xff000000, 0xff000000,
1668 static const DWORD dds_dxt5_8_8_expected_misaligned_3
[] =
1670 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1671 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1672 0x00000000, 0x00000000, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x00000000, 0x00000000,
1673 0x00000000, 0x00000000, 0x0000ff00, 0x0000ff00, 0x3fff0000, 0x3fff0000, 0x00000000, 0x00000000,
1674 0x00000000, 0x00000000, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0x00000000, 0x00000000,
1675 0x00000000, 0x00000000, 0x7fff00ff, 0x7fff00ff, 0xff000000, 0xff000000, 0x00000000, 0x00000000,
1676 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1677 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1679 IDirect3DSurface9
*surface
, *uncompressed_surface
;
1680 IDirect3DTexture9
*texture
;
1681 D3DLOCKED_RECT lock_rect
;
1682 D3DRESOURCETYPE type
;
1683 D3DSURFACE_DESC desc
;
1684 unsigned int i
, x
, y
;
1689 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_16bit
, sizeof(dds_16bit
), &texture
);
1690 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1691 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1693 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
), &texture
);
1694 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1695 if (SUCCEEDED(hr
)) IDirect3DTexture9_Release(texture
);
1697 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_24bit
, sizeof(dds_24bit
) - 1, &texture
);
1698 ok(hr
== D3DXERR_INVALIDDATA
, "D3DXCreateTextureFromFileInMemory returned %#lx, expected %#x\n", hr
, D3DXERR_INVALIDDATA
);
1700 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1701 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &texture
);
1702 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1703 type
= IDirect3DTexture9_GetType(texture
);
1704 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type
, D3DRTYPE_TEXTURE
);
1705 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1706 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1707 ok(desc
.Width
== 4, "Width is %u, expected 4.\n", desc
.Width
);
1708 ok(desc
.Height
== 4, "Height is %u, expected 4.\n", desc
.Height
);
1711 ok(desc
.Format
== D3DFMT_DXT5
, "Unexpected texture format %#x.\n", desc
.Format
);
1712 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1713 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1716 for (i
= 0; i
< 16; i
++)
1717 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_cube_map
[128 + i
],
1718 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1719 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_cube_map
[128 + i
]);
1720 IDirect3DTexture9_UnlockRect(texture
, 0);
1725 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Unexpected texture format %#x.\n", desc
.Format
);
1726 skip("D3DFMT_DXT5 textures are not supported, skipping a test.\n");
1728 IDirect3DTexture9_Release(texture
);
1730 /* Test with a DXT5 texture smaller than the block size. */
1731 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_dxt5
, sizeof(dds_dxt5
), &texture
);
1732 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1733 if (SUCCEEDED(hr
) && has_2d_dxt5
)
1735 type
= IDirect3DTexture9_GetType(texture
);
1736 ok(type
== D3DRTYPE_TEXTURE
, "Got unexpected type %u.\n", type
);
1737 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1738 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1739 ok(desc
.Width
== 4, "Got unexpected width %u.\n", desc
.Width
);
1740 ok(desc
.Height
== 4, "Got unexpected height %u.\n", desc
.Height
);
1742 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1743 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 4, 4, D3DFMT_A8R8G8B8
,
1744 D3DPOOL_DEFAULT
, &uncompressed_surface
, NULL
);
1745 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1746 hr
= D3DXLoadSurfaceFromSurface(uncompressed_surface
, NULL
, NULL
, surface
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1747 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1748 hr
= IDirect3DSurface9_LockRect(uncompressed_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1749 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1750 for (y
= 0; y
< 4; ++y
)
1752 for (x
= 0; x
< 4; ++x
)
1754 /* Use a large tolerance, decompression + stretching +
1755 * compression + decompression again introduce quite a bit of
1756 * precision loss. */
1757 ok(compare_color(((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1758 dds_dxt5_expected
[y
* 4 + x
], 32),
1759 "Color at position %u, %u is 0x%08lx, expected 0x%08lx.\n",
1760 x
, y
, ((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1761 dds_dxt5_expected
[y
* 4 + x
]);
1764 hr
= IDirect3DSurface9_UnlockRect(uncompressed_surface
);
1765 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1767 IDirect3DSurface9_Release(uncompressed_surface
);
1768 IDirect3DSurface9_Release(surface
);
1771 IDirect3DTexture9_Release(texture
);
1773 /* Test with a larger DXT5 texture. */
1774 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_dxt5_8_8
, sizeof(dds_dxt5_8_8
), &texture
);
1775 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1776 type
= IDirect3DTexture9_GetType(texture
);
1777 ok(type
== D3DRTYPE_TEXTURE
, "Got unexpected type %u.\n", type
);
1778 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1779 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1780 ok(desc
.Width
== 8, "Got unexpected width %u.\n", desc
.Width
);
1781 ok(desc
.Height
== 8, "Got unexpected height %u.\n", desc
.Height
);
1782 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1784 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 8, 8, D3DFMT_A8R8G8B8
,
1785 D3DPOOL_DEFAULT
, &uncompressed_surface
, NULL
);
1786 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1787 hr
= D3DXLoadSurfaceFromSurface(uncompressed_surface
, NULL
, NULL
, surface
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1788 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1791 hr
= IDirect3DSurface9_LockRect(uncompressed_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1792 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1793 for (y
= 0; y
< 8; ++y
)
1795 for (x
= 0; x
< 8; ++x
)
1797 ok(compare_color(((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1798 dds_dxt5_8_8_expected
[y
* 8 + x
], 0),
1799 "Color at position %u, %u is 0x%08lx, expected 0x%08lx.\n",
1800 x
, y
, ((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1801 dds_dxt5_8_8_expected
[y
* 8 + x
]);
1804 hr
= IDirect3DSurface9_UnlockRect(uncompressed_surface
);
1805 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1808 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1809 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1810 for (y
= 0; y
< 2; ++y
)
1811 memset(&((BYTE
*)lock_rect
.pBits
)[y
* lock_rect
.Pitch
], 0, 16 * 2);
1812 hr
= IDirect3DSurface9_UnlockRect(surface
);
1813 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1815 SetRect(&rect
, 2, 2, 6, 6);
1816 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, NULL
, &dds_dxt5_8_8
[128],
1817 D3DFMT_DXT5
, 16 * 2, NULL
, &rect
, D3DX_FILTER_POINT
, 0);
1818 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1819 hr
= D3DXLoadSurfaceFromSurface(uncompressed_surface
, NULL
, NULL
, surface
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1820 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1822 hr
= IDirect3DSurface9_LockRect(uncompressed_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1823 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1824 for (y
= 0; y
< 8; ++y
)
1826 for (x
= 0; x
< 8; ++x
)
1828 ok(compare_color(((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1829 dds_dxt5_8_8_expected_misaligned_1
[y
* 8 + x
], 0),
1830 "Color at position %u, %u is 0x%08lx, expected 0x%08lx.\n",
1831 x
, y
, ((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1832 dds_dxt5_8_8_expected_misaligned_1
[y
* 8 + x
]);
1835 hr
= IDirect3DSurface9_UnlockRect(uncompressed_surface
);
1836 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1838 hr
= IDirect3DSurface9_LockRect(surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1839 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1840 for (y
= 0; y
< 2; ++y
)
1841 memset(&((BYTE
*)lock_rect
.pBits
)[y
* lock_rect
.Pitch
], 0, 16 * 2);
1842 hr
= IDirect3DSurface9_UnlockRect(surface
);
1843 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1845 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, &rect
, &dds_dxt5_8_8
[128],
1846 D3DFMT_DXT5
, 16 * 2, NULL
, NULL
, D3DX_FILTER_POINT
, 0);
1847 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#lx.\n", hr
);
1849 hr
= D3DXLoadSurfaceFromMemory(surface
, NULL
, &rect
, &dds_dxt5_8_8
[128],
1850 D3DFMT_DXT5
, 16 * 2, NULL
, &rect
, D3DX_FILTER_POINT
, 0);
1851 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1852 hr
= D3DXLoadSurfaceFromSurface(uncompressed_surface
, NULL
, NULL
, surface
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1853 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1855 hr
= IDirect3DSurface9_LockRect(uncompressed_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1856 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1857 for (y
= 0; y
< 8; ++y
)
1859 for (x
= 0; x
< 8; ++x
)
1861 ok(compare_color(((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1862 dds_dxt5_8_8_expected_misaligned_3
[y
* 8 + x
], 0),
1863 "Color at position %u, %u is 0x%08lx, expected 0x%08lx.\n",
1864 x
, y
, ((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1865 dds_dxt5_8_8_expected_misaligned_3
[y
* 8 + x
]);
1868 hr
= IDirect3DSurface9_UnlockRect(uncompressed_surface
);
1869 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1871 hr
= D3DXLoadSurfaceFromFileInMemory(surface
, NULL
, &rect
, dds_dxt5_8_8
,
1872 sizeof(dds_dxt5_8_8
), &rect
, D3DX_FILTER_POINT
, 0, NULL
);
1873 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1874 hr
= D3DXLoadSurfaceFromSurface(uncompressed_surface
, NULL
, NULL
, surface
, NULL
, NULL
, D3DX_FILTER_NONE
, 0);
1875 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1877 hr
= IDirect3DSurface9_LockRect(uncompressed_surface
, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1878 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1879 for (y
= 0; y
< 8; ++y
)
1881 for (x
= 0; x
< 8; ++x
)
1883 ok(compare_color(((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1884 dds_dxt5_8_8_expected_misaligned_3
[y
* 8 + x
], 0),
1885 "Color at position %u, %u is 0x%08lx, expected 0x%08lx.\n",
1886 x
, y
, ((DWORD
*)lock_rect
.pBits
)[lock_rect
.Pitch
/ 4 * y
+ x
],
1887 dds_dxt5_8_8_expected_misaligned_3
[y
* 8 + x
]);
1890 hr
= IDirect3DSurface9_UnlockRect(uncompressed_surface
);
1891 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
1893 IDirect3DSurface9_Release(uncompressed_surface
);
1894 IDirect3DSurface9_Release(surface
);
1895 IDirect3DTexture9_Release(texture
);
1897 /* Volume textures work too. */
1898 hr
= D3DXCreateTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &texture
);
1899 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemory returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1900 type
= IDirect3DTexture9_GetType(texture
);
1901 ok(type
== D3DRTYPE_TEXTURE
, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type
, D3DRTYPE_TEXTURE
);
1902 level_count
= IDirect3DBaseTexture9_GetLevelCount((IDirect3DBaseTexture9
*)texture
);
1903 todo_wine
ok(level_count
== 3, "Texture has %lu mip levels, 3 expected.\n", level_count
);
1904 hr
= IDirect3DTexture9_GetLevelDesc(texture
, 0, &desc
);
1905 ok(hr
== D3D_OK
, "IDirect3DTexture9_GetLevelDesc returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1906 ok(desc
.Width
== 4, "Width is %u, expected 4.\n", desc
.Width
);
1907 ok(desc
.Height
== 4, "Height is %u, expected 4.\n", desc
.Height
);
1911 ok(desc
.Format
== D3DFMT_DXT3
, "Unexpected texture format %#x.\n", desc
.Format
);
1912 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lock_rect
, NULL
, D3DLOCK_READONLY
);
1913 ok(hr
== D3D_OK
, "IDirect3DTexture9_LockRect returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1916 for (i
= 0; i
< 16; ++i
)
1917 ok(((BYTE
*)lock_rect
.pBits
)[i
] == dds_volume_map
[128 + i
],
1918 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1919 i
, ((BYTE
*)lock_rect
.pBits
)[i
], dds_volume_map
[128 + i
]);
1920 IDirect3DTexture9_UnlockRect(texture
, 0);
1925 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Unexpected texture format %#x.\n", desc
.Format
);
1926 skip("D3DFMT_DXT3 volume textures are not supported, skipping a test.\n");
1928 /* The lower texture levels are apparently generated by filtering the level 0 surface
1929 * I.e. following levels from the file are ignored. */
1930 IDirect3DTexture9_Release(texture
);
1933 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
1936 IDirect3DTexture9
*texture
;
1937 unsigned int miplevels
;
1938 IDirect3DSurface9
*surface
;
1939 D3DSURFACE_DESC desc
;
1941 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1942 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1943 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1944 IDirect3DTexture9_Release(texture
);
1946 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1947 D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1948 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1949 IDirect3DTexture9_Release(texture
);
1951 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
), D3DX_DEFAULT
,
1952 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DUSAGE_DYNAMIC
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1953 D3DX_DEFAULT
, D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_FILTER_POINT
), 0, NULL
, NULL
, &texture
);
1954 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1955 miplevels
= IDirect3DTexture9_GetLevelCount(texture
);
1956 ok(miplevels
== 1, "Got miplevels %u, expected %u.\n", miplevels
, 1);
1957 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1958 IDirect3DSurface9_GetDesc(surface
, &desc
);
1959 ok(desc
.Width
== 1 && desc
.Height
== 1,
1960 "Surface dimensions are %ux%u, expected 1x1.\n", desc
.Width
, desc
.Height
);
1961 IDirect3DSurface9_Release(surface
);
1962 IDirect3DTexture9_Release(texture
);
1964 if (!is_autogenmipmap_supported(device
, D3DRTYPE_TEXTURE
))
1966 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1970 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
), D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
,
1971 D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1972 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx\n", hr
, D3D_OK
);
1973 IDirect3DTexture9_Release(texture
);
1975 /* Checking for color key format overrides. */
1976 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1977 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1978 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
1979 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1980 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1981 IDirect3DSurface9_GetDesc(surface
, &desc
);
1982 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_X1R5G5B5
);
1983 IDirect3DSurface9_Release(surface
);
1984 IDirect3DTexture9_Release(texture
);
1985 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1986 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
1987 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1988 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1989 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1990 IDirect3DSurface9_GetDesc(surface
, &desc
);
1991 ok(desc
.Format
== D3DFMT_A1R5G5B5
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_A1R5G5B5
);
1992 IDirect3DSurface9_Release(surface
);
1993 IDirect3DTexture9_Release(texture
);
1994 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_16bit
, sizeof(dds_16bit
),
1995 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X1R5G5B5
, D3DPOOL_DEFAULT
,
1996 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
1997 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
1998 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
1999 IDirect3DSurface9_GetDesc(surface
, &desc
);
2000 ok(desc
.Format
== D3DFMT_X1R5G5B5
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_X1R5G5B5
);
2001 IDirect3DSurface9_Release(surface
);
2002 IDirect3DTexture9_Release(texture
);
2004 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
2005 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
2006 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
2007 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2008 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2009 IDirect3DSurface9_GetDesc(surface
, &desc
);
2010 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_X8R8G8B8
);
2011 IDirect3DSurface9_Release(surface
);
2012 IDirect3DTexture9_Release(texture
);
2013 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
2014 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
2015 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
2016 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2017 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2018 IDirect3DSurface9_GetDesc(surface
, &desc
);
2019 ok(desc
.Format
== D3DFMT_A8R8G8B8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_A8R8G8B8
);
2020 IDirect3DSurface9_Release(surface
);
2021 IDirect3DTexture9_Release(texture
);
2022 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, dds_24bit
, sizeof(dds_24bit
),
2023 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_X8R8G8B8
, D3DPOOL_DEFAULT
,
2024 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
2025 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2026 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2027 IDirect3DSurface9_GetDesc(surface
, &desc
);
2028 ok(desc
.Format
== D3DFMT_X8R8G8B8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_X8R8G8B8
);
2029 IDirect3DSurface9_Release(surface
);
2030 IDirect3DTexture9_Release(texture
);
2032 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
2033 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
2034 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &texture
);
2035 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2036 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2037 IDirect3DSurface9_GetDesc(surface
, &desc
);
2038 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_L8
);
2039 IDirect3DSurface9_Release(surface
);
2040 IDirect3DTexture9_Release(texture
);
2041 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
2042 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
2043 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
2044 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2045 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2046 IDirect3DSurface9_GetDesc(surface
, &desc
);
2047 ok(desc
.Format
== D3DFMT_A8L8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_A8L8
);
2048 IDirect3DSurface9_Release(surface
);
2049 IDirect3DTexture9_Release(texture
);
2050 hr
= D3DXCreateTextureFromFileInMemoryEx(device
, png_grayscale
, sizeof(png_grayscale
),
2051 D3DX_DEFAULT
, D3DX_DEFAULT
, D3DX_DEFAULT
, 0, D3DFMT_L8
, D3DPOOL_DEFAULT
,
2052 D3DX_DEFAULT
, D3DX_DEFAULT
, 0xff000000, NULL
, NULL
, &texture
);
2053 ok(hr
== D3D_OK
, "D3DXCreateTextureFromFileInMemoryEx returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2054 IDirect3DTexture9_GetSurfaceLevel(texture
, 0, &surface
);
2055 IDirect3DSurface9_GetDesc(surface
, &desc
);
2056 ok(desc
.Format
== D3DFMT_L8
, "Returned format %u, expected %u.\n", desc
.Format
, D3DFMT_L8
);
2057 IDirect3DSurface9_Release(surface
);
2058 IDirect3DTexture9_Release(texture
);
2061 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9
*device
)
2066 IDirect3DCubeTexture9
*cube_texture
;
2067 D3DSURFACE_DESC surface_desc
;
2069 hr
= D3DXCreateCubeTextureFromFileInMemory(NULL
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
2070 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2072 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, NULL
, sizeof(dds_cube_map
), &cube_texture
);
2073 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2075 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, 0, &cube_texture
);
2076 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2078 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), NULL
);
2079 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateCubeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2081 hr
= D3DXCreateCubeTextureFromFileInMemory(device
, dds_cube_map
, sizeof(dds_cube_map
), &cube_texture
);
2084 levelcount
= IDirect3DCubeTexture9_GetLevelCount(cube_texture
);
2085 ok(levelcount
== 3, "GetLevelCount returned %lu, expected 3\n", levelcount
);
2087 hr
= IDirect3DCubeTexture9_GetLevelDesc(cube_texture
, 0, &surface_desc
);
2088 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2089 ok(surface_desc
.Width
== 4, "Got width %u, expected 4\n", surface_desc
.Width
);
2090 ok(surface_desc
.Height
== 4, "Got height %u, expected 4\n", surface_desc
.Height
);
2092 ref
= IDirect3DCubeTexture9_Release(cube_texture
);
2093 ok(ref
== 0, "Invalid reference count. Got %lu, expected 0\n", ref
);
2094 } else skip("Couldn't create cube texture\n");
2097 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
2099 IDirect3DCubeTexture9
*cube_texture
;
2102 hr
= D3DXCreateCubeTextureFromFileInMemoryEx(device
, dds_cube_map
, sizeof(dds_cube_map
), D3DX_DEFAULT
,
2103 D3DX_DEFAULT
, D3DUSAGE_RENDERTARGET
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
,
2104 D3DX_DEFAULT
, 0, NULL
, NULL
, &cube_texture
);
2105 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
2106 IDirect3DCubeTexture9_Release(cube_texture
);
2108 if (!is_autogenmipmap_supported(device
, D3DRTYPE_CUBETEXTURE
))
2110 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
2114 hr
= D3DXCreateCubeTextureFromFileInMemoryEx(device
, dds_cube_map
, sizeof(dds_cube_map
), D3DX_DEFAULT
,
2115 D3DX_DEFAULT
, D3DUSAGE_DYNAMIC
| D3DUSAGE_AUTOGENMIPMAP
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
,
2116 D3DX_DEFAULT
, D3DX_DEFAULT
, 0, NULL
, NULL
, &cube_texture
);
2117 ok(hr
== D3D_OK
, "Got unexpected hr %#lx.\n", hr
);
2118 IDirect3DCubeTexture9_Release(cube_texture
);
2121 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9
*device
)
2126 IDirect3DVolumeTexture9
*volume_texture
;
2127 D3DVOLUME_DESC volume_desc
;
2129 hr
= D3DXCreateVolumeTextureFromFileInMemory(NULL
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
2130 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2132 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, NULL
, sizeof(dds_volume_map
), &volume_texture
);
2133 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2135 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, 0, &volume_texture
);
2136 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2138 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), NULL
);
2139 ok(hr
== D3DERR_INVALIDCALL
, "D3DXCreateVolumeTextureFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3DERR_INVALIDCALL
);
2141 hr
= D3DXCreateVolumeTextureFromFileInMemory(device
, dds_volume_map
, sizeof(dds_volume_map
), &volume_texture
);
2142 ok(hr
== D3D_OK
, "D3DXCreateVolumeTextureFromFileInMemory returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2143 levelcount
= IDirect3DVolumeTexture9_GetLevelCount(volume_texture
);
2144 ok(levelcount
== 3, "GetLevelCount returned %lu, expected 3.\n", levelcount
);
2146 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 0, &volume_desc
);
2147 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2148 ok(volume_desc
.Width
== 4, "Got width %u, expected 4.\n", volume_desc
.Width
);
2149 ok(volume_desc
.Height
== 4, "Got height %u, expected 4.\n", volume_desc
.Height
);
2150 ok(volume_desc
.Depth
== 2, "Got depth %u, expected 2.\n", volume_desc
.Depth
);
2151 ok(volume_desc
.Pool
== D3DPOOL_MANAGED
, "Got pool %u, expected D3DPOOL_MANAGED.\n", volume_desc
.Pool
);
2153 hr
= IDirect3DVolumeTexture9_GetLevelDesc(volume_texture
, 1, &volume_desc
);
2154 ok(hr
== D3D_OK
, "GetLevelDesc returned %#lx, expected %#lx.\n", hr
, D3D_OK
);
2155 ok(volume_desc
.Width
== 2, "Got width %u, expected 2.\n", volume_desc
.Width
);
2156 ok(volume_desc
.Height
== 2, "Got height %u, expected 2.\n", volume_desc
.Height
);
2157 ok(volume_desc
.Depth
== 1, "Got depth %u, expected 1.\n", volume_desc
.Depth
);
2159 ref
= IDirect3DVolumeTexture9_Release(volume_texture
);
2160 ok(ref
== 0, "Invalid reference count. Got %lu, expected 0.\n", ref
);
2163 static void test_D3DXCreateVolumeTextureFromFileInMemoryEx(IDirect3DDevice9
*device
)
2165 IDirect3DVolumeTexture9
*volume_texture
;
2168 hr
= D3DXCreateVolumeTextureFromFileInMemoryEx(device
, dds_volume_map
, sizeof(dds_volume_map
), D3DX_DEFAULT
,
2169 D3DX_DEFAULT
, D3DX_DEFAULT
, 1, D3DUSAGE_RENDERTARGET
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
,
2170 D3DX_DEFAULT
, 0, NULL
, NULL
, &volume_texture
);
2171 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#lx.\n", hr
);
2173 hr
= D3DXCreateVolumeTextureFromFileInMemoryEx(device
, dds_volume_map
, sizeof(dds_volume_map
), D3DX_DEFAULT
,
2174 D3DX_DEFAULT
, D3DX_DEFAULT
, 1, D3DUSAGE_DEPTHSTENCIL
, D3DFMT_UNKNOWN
, D3DPOOL_DEFAULT
, D3DX_DEFAULT
,
2175 D3DX_DEFAULT
, 0, NULL
, NULL
, &volume_texture
);
2176 ok(hr
== D3DERR_NOTAVAILABLE
, "Got unexpected hr %#lx.\n", hr
);
2179 /* fills positive x face with red color */
2180 static void WINAPI
fill_cube_positive_x(D3DXVECTOR4
*out
, const D3DXVECTOR3
*tex_coord
, const D3DXVECTOR3
*texel_size
, void *data
)
2182 memset(out
, 0, sizeof(*out
));
2183 if (tex_coord
->x
> 0 && fabs(tex_coord
->x
) > fabs(tex_coord
->y
) && fabs(tex_coord
->x
) > fabs(tex_coord
->z
))
2187 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9
*device
)
2190 IDirect3DTexture9
*texture
;
2191 IDirect3DCubeTexture9
*cube_texture
;
2192 IDirect3DVolumeTexture9
*volume_texture
;
2193 ID3DXBuffer
*buffer
;
2194 void *buffer_pointer
;
2196 D3DXIMAGE_INFO info
;
2197 D3DXIMAGE_FILEFORMAT file_format
;
2200 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &texture
, NULL
);
2203 skip("Failed to create texture\n");
2207 for (file_format
= D3DXIFF_BMP
; file_format
<= D3DXIFF_JPG
; file_format
++)
2209 hr
= D3DXSaveTextureToFileInMemory(&buffer
, file_format
, (IDirect3DBaseTexture9
*)texture
, NULL
);
2210 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2213 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2214 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2215 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2216 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2218 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2219 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2220 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
2221 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
2222 ok(info
.ImageFileFormat
== file_format
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, file_format
);
2223 ID3DXBuffer_Release(buffer
);
2228 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)texture
, NULL
);
2229 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2232 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2233 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2234 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2235 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2237 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2238 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2239 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
2240 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
2241 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
2242 ID3DXBuffer_Release(buffer
);
2246 IDirect3DTexture9_Release(texture
);
2249 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &cube_texture
, NULL
);
2252 skip("Failed to create cube texture\n");
2256 hr
= D3DXFillCubeTexture(cube_texture
, fill_cube_positive_x
, NULL
);
2257 ok(hr
== D3D_OK
, "D3DXFillCubeTexture returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2259 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
2260 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2263 IDirect3DSurface9
*surface
;
2265 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2266 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2267 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2268 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2270 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2271 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2272 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
2273 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
2274 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
2276 /* positive x face is saved */
2277 hr
= IDirect3DDevice9_CreateOffscreenPlainSurface(device
, 256, 256, D3DFMT_X8R8G8B8
, D3DPOOL_SYSTEMMEM
, &surface
, NULL
);
2280 D3DLOCKED_RECT locked_rect
;
2282 hr
= D3DXLoadSurfaceFromFileInMemory(surface
, NULL
, NULL
, buffer_pointer
, buffer_size
, NULL
, D3DX_FILTER_NONE
, 0, NULL
);
2283 ok(hr
== D3D_OK
, "D3DXLoadSurfaceFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2285 hr
= IDirect3DSurface9_LockRect(surface
, &locked_rect
, NULL
, D3DLOCK_READONLY
);
2288 DWORD
*color
= locked_rect
.pBits
;
2289 ok(*color
== 0x00ff0000, "Got color %#lx, expected %#x\n", *color
, 0x00ff0000);
2290 IDirect3DSurface9_UnlockRect(surface
);
2293 IDirect3DSurface9_Release(surface
);
2294 } else skip("Failed to create surface\n");
2296 ID3DXBuffer_Release(buffer
);
2300 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)cube_texture
, NULL
);
2301 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2304 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2305 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2306 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2307 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2309 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2310 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2311 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
2312 ok(info
.ResourceType
== D3DRTYPE_CUBETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_CUBETEXTURE
);
2313 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
2314 ID3DXBuffer_Release(buffer
);
2318 IDirect3DCubeTexture9_Release(cube_texture
);
2320 /* volume textures */
2321 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8
, D3DPOOL_MANAGED
, &volume_texture
, NULL
);
2324 skip("Failed to create volume texture\n");
2329 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_BMP
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
2330 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2333 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2334 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2335 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2336 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2338 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2339 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2340 ok(info
.Depth
== 1, "Got depth %u, expected %u\n", info
.Depth
, 1);
2341 ok(info
.MipLevels
== 1, "Got miplevels %u, expected %u\n", info
.MipLevels
, 1);
2342 ok(info
.ResourceType
== D3DRTYPE_TEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_TEXTURE
);
2343 ok(info
.ImageFileFormat
== D3DXIFF_BMP
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_BMP
);
2344 ID3DXBuffer_Release(buffer
);
2347 hr
= D3DXSaveTextureToFileInMemory(&buffer
, D3DXIFF_DDS
, (IDirect3DBaseTexture9
*)volume_texture
, NULL
);
2348 ok(hr
== D3D_OK
, "D3DXSaveTextureToFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2351 buffer_pointer
= ID3DXBuffer_GetBufferPointer(buffer
);
2352 buffer_size
= ID3DXBuffer_GetBufferSize(buffer
);
2353 hr
= D3DXGetImageInfoFromFileInMemory(buffer_pointer
, buffer_size
, &info
);
2354 ok(hr
== D3D_OK
, "D3DXGetImageInfoFromFileInMemory returned %#lx, expected %#lx\n", hr
, D3D_OK
);
2356 ok(info
.Width
== 256, "Got width %u, expected %u\n", info
.Width
, 256);
2357 ok(info
.Height
== 256, "Got height %u, expected %u\n", info
.Height
, 256);
2358 ok(info
.Depth
== 256, "Got depth %u, expected %u\n", info
.Depth
, 256);
2359 ok(info
.MipLevels
== 9, "Got miplevels %u, expected %u\n", info
.MipLevels
, 9);
2360 ok(info
.ResourceType
== D3DRTYPE_VOLUMETEXTURE
, "Got resource type %#x, expected %#x\n", info
.ResourceType
, D3DRTYPE_VOLUMETEXTURE
);
2361 ok(info
.ImageFileFormat
== D3DXIFF_DDS
, "Got file format %#x, expected %#x\n", info
.ImageFileFormat
, D3DXIFF_DDS
);
2362 ID3DXBuffer_Release(buffer
);
2366 IDirect3DVolumeTexture9_Release(volume_texture
);
2369 static void test_texture_shader(void)
2371 static const DWORD shader_zero
[] = {0x0};
2372 static const DWORD shader_invalid
[] = {0xeeee0100};
2373 static const DWORD shader_empty
[] = {0xfffe0200, 0x0000ffff};
2375 float4
main(float3 pos
: POSITION
, float3 size
: PSIZE
) : COLOR
2377 return float4(pos
, 1.0);
2380 static const DWORD shader_code
[] =
2382 0x54580100, 0x0015fffe, 0x42415443, 0x0000001c, 0x0000001f, 0x54580100, 0x00000000, 0x00000000,
2383 0x00000100, 0x0000001c, 0x4d007874, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820, 0x6853204c,
2384 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072, 0x392e3932, 0x332e3235, 0x00313131, 0x000afffe,
2385 0x54494c43, 0x00000004, 0x00000000, 0x3ff00000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2386 0x00000000, 0x00000000, 0x0014fffe, 0x434c5846, 0x00000002, 0x10000003, 0x00000001, 0x00000000,
2387 0x00000003, 0x00000000, 0x00000000, 0x00000004, 0x00000000, 0x10000001, 0x00000001, 0x00000000,
2388 0x00000001, 0x00000000, 0x00000000, 0x00000004, 0x00000003, 0xf0f0f0f0, 0x0f0f0f0f, 0x0000ffff,
2391 float f1
[2] = { 0.4f
, 0.1f
};
2407 float4
main(float3 pos
: POSITION
, float3 size
: PSIZE
) : COLOR
2409 float t
= b2
[0] * b2
[1] * f2
.x
+ s1
.i2
;
2410 return float4(pos
, f1
[0] + f1
[1] + b1
* 0.6f
+ t
);
2413 static const DWORD shader_code2
[] =
2415 0x54580100, 0x0074fffe, 0x42415443, 0x0000001c, 0x000001a3, 0x54580100, 0x00000005, 0x0000001c,
2416 0x00000100, 0x000001a0, 0x00000080, 0x00090002, 0x00000001, 0x00000084, 0x00000094, 0x000000a4,
2417 0x00070002, 0x00000002, 0x000000a8, 0x00000000, 0x000000b8, 0x00050002, 0x00000002, 0x000000bc,
2418 0x000000cc, 0x000000ec, 0x000a0002, 0x00000001, 0x000000f0, 0x00000000, 0x00000100, 0x00000002,
2419 0x00000005, 0x00000190, 0x00000000, 0xab003162, 0x00010000, 0x00010001, 0x00000001, 0x00000000,
2420 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xab003262, 0x00010000, 0x00010001, 0x00000002,
2421 0x00000000, 0xab003166, 0x00030000, 0x00010001, 0x00000002, 0x00000000, 0x3ecccccd, 0x00000000,
2422 0x00000000, 0x00000000, 0x3dcccccd, 0x00000000, 0x00000000, 0x00000000, 0xab003266, 0x00030001,
2423 0x00040001, 0x00000001, 0x00000000, 0x62003173, 0xabab0033, 0x00010000, 0x00010001, 0x00000001,
2424 0x00000000, 0xab003366, 0x00030000, 0x00010001, 0x00000001, 0x00000000, 0xab003466, 0x00030001,
2425 0x00040001, 0x00000001, 0x00000000, 0xab003169, 0x00020000, 0x00010001, 0x00000001, 0x00000000,
2426 0xab003269, 0x00020000, 0x00010001, 0x00000001, 0x00000000, 0x00000103, 0x00000108, 0x00000118,
2427 0x0000011c, 0x0000012c, 0x00000130, 0x00000140, 0x00000144, 0x00000154, 0x00000158, 0x00000005,
2428 0x00080001, 0x00050001, 0x00000168, 0x4d007874, 0x6f726369, 0x74666f73, 0x29522820, 0x534c4820,
2429 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x30312072, 0xab00312e, 0x0062fffe, 0x54494c43,
2430 0x00000030, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2431 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2432 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2433 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2434 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2435 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2436 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2437 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2438 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2439 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2440 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2441 0x00000000, 0x40000000, 0x3fe33333, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
2442 0x00000000, 0x0059fffe, 0x434c5846, 0x00000008, 0xa0500001, 0x00000002, 0x00000000, 0x00000002,
2443 0x0000001c, 0x00000000, 0x00000002, 0x00000020, 0x00000000, 0x00000007, 0x00000000, 0xa0500001,
2444 0x00000002, 0x00000000, 0x00000007, 0x00000000, 0x00000000, 0x00000002, 0x00000028, 0x00000000,
2445 0x00000007, 0x00000004, 0xa0400001, 0x00000002, 0x00000000, 0x00000007, 0x00000004, 0x00000000,
2446 0x00000002, 0x00000010, 0x00000000, 0x00000007, 0x00000000, 0xa0400001, 0x00000002, 0x00000000,
2447 0x00000002, 0x00000014, 0x00000000, 0x00000002, 0x00000018, 0x00000000, 0x00000007, 0x00000001,
2448 0xa0500001, 0x00000002, 0x00000000, 0x00000002, 0x00000024, 0x00000000, 0x00000001, 0x0000002c,
2449 0x00000000, 0x00000007, 0x00000002, 0xa0400001, 0x00000002, 0x00000000, 0x00000007, 0x00000002,
2450 0x00000000, 0x00000007, 0x00000001, 0x00000000, 0x00000007, 0x00000004, 0xa0400001, 0x00000002,
2451 0x00000000, 0x00000007, 0x00000000, 0x00000000, 0x00000007, 0x00000004, 0x00000000, 0x00000004,
2452 0x00000003, 0x10000003, 0x00000001, 0x00000000, 0x00000003, 0x00000000, 0x00000000, 0x00000004,
2453 0x00000000, 0xf0f0f0f0, 0x0f0f0f0f, 0x0000ffff,
2455 IDirect3DVolumeTexture9
*volume_texture
;
2456 IDirect3DCubeTexture9
*cube_texture
;
2457 D3DXCONSTANTTABLE_DESC ctab_desc
;
2458 ID3DXBuffer
*buffer
, *buffer2
;
2459 D3DXCONSTANT_DESC const_desc
;
2460 unsigned int x
, y
, z
, count
;
2461 D3DPRESENT_PARAMETERS d3dpp
;
2462 IDirect3DTexture9
*texture
;
2463 IDirect3DDevice9
*device
;
2464 ID3DXTextureShader
*tx
;
2475 hr
= D3DXCreateTextureShader(NULL
, NULL
);
2476 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#lx.\n", hr
);
2478 tx
= (void *)0xdeadbeef;
2479 hr
= D3DXCreateTextureShader(NULL
, &tx
);
2480 ok(hr
== D3DERR_INVALIDCALL
, "Got unexpected hr %#lx.\n", hr
);
2481 ok(tx
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", tx
);
2483 tx
= (void *)0xdeadbeef;
2484 hr
= D3DXCreateTextureShader(shader_invalid
, &tx
);
2485 ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#lx.\n", hr
);
2486 ok(tx
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", tx
);
2488 tx
= (void *)0xdeadbeef;
2489 hr
= D3DXCreateTextureShader(shader_zero
, &tx
);
2490 ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#lx.\n", hr
);
2491 ok(tx
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", tx
);
2493 tx
= (void *)0xdeadbeef;
2494 hr
= D3DXCreateTextureShader(shader_empty
, &tx
);
2495 ok(hr
== D3DXERR_INVALIDDATA
, "Got unexpected hr %#lx.\n", hr
);
2496 ok(tx
== (void *)0xdeadbeef, "Unexpected pointer %p.\n", tx
);
2498 hr
= D3DXCreateTextureShader(shader_code
, &tx
);
2499 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2501 hr
= tx
->lpVtbl
->GetFunction(tx
, &buffer
);
2502 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
2504 hr
= tx
->lpVtbl
->GetFunction(tx
, &buffer2
);
2505 ok(hr
== D3D_OK
, "Unexpected hr %#lx.\n", hr
);
2506 ok(buffer2
== buffer
, "Unexpected buffer object.\n");
2507 ID3DXBuffer_Release(buffer2
);
2509 size
= ID3DXBuffer_GetBufferSize(buffer
);
2510 ok(size
== 224, "Unexpected buffer size %lu.\n", size
);
2512 ID3DXBuffer_Release(buffer
);
2514 /* Constant buffer */
2515 hr
= tx
->lpVtbl
->GetConstantBuffer(tx
, &buffer
);
2517 ok(SUCCEEDED(hr
), "Failed to get texture shader constant buffer.\n");
2521 size
= ID3DXBuffer_GetBufferSize(buffer
);
2522 ok(!size
, "Unexpected buffer size %lu.\n", size
);
2524 ID3DXBuffer_Release(buffer
);
2527 hr
= tx
->lpVtbl
->GetDesc(tx
, &ctab_desc
);
2529 ok(hr
== S_OK
, "Failed to get constant description, hr %#lx.\n", hr
);
2531 ok(!ctab_desc
.Constants
, "Unexpected number of constants %u.\n", ctab_desc
.Constants
);
2533 /* Constant table access calls, without constant table. */
2534 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 0);
2535 ok(!h
, "Unexpected handle %p.\n", h
);
2537 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
2538 640, 480, NULL
, NULL
, NULL
, NULL
)))
2540 skip("Couldn't create application window.\n");
2541 IUnknown_Release(tx
);
2544 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2547 skip("Couldn't create IDirect3D9 object.\n");
2549 IUnknown_Release(tx
);
2553 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
2554 d3dpp
.Windowed
= TRUE
;
2555 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2556 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
,
2557 D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
2560 skip("Failed to create IDirect3DDevice9 object, hr %#lx.\n", hr
);
2561 IDirect3D9_Release(d3d
);
2563 IUnknown_Release(tx
);
2567 IDirect3DDevice9_GetDeviceCaps(device
, &caps
);
2569 hr
= IDirect3DDevice9_CreateTexture(device
, 256, 256, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
,
2571 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2573 hr
= D3DXFillTextureTX(texture
, tx
);
2574 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2576 hr
= IDirect3DTexture9_LockRect(texture
, 0, &lr
, NULL
, D3DLOCK_READONLY
);
2577 ok(SUCCEEDED(hr
), "Locking texture failed, hr %#lx.\n", hr
);
2579 for (y
= 0; y
< 256; ++y
)
2581 for (x
= 0; x
< 256; ++x
)
2583 unsigned int expected
= 0xff000000 | x
<< 16 | y
<< 8;
2584 /* The third position coordinate is apparently undefined for 2D textures. */
2585 unsigned int color
= data
[y
* lr
.Pitch
/ sizeof(*data
) + x
] & 0xffffff00;
2587 ok(compare_color(color
, expected
, 1), "Unexpected color %08x at (%u, %u).\n", color
, x
, y
);
2590 hr
= IDirect3DTexture9_UnlockRect(texture
, 0);
2591 ok(SUCCEEDED(hr
), "Unlocking texture failed, hr %#lx.\n", hr
);
2593 IDirect3DTexture9_Release(texture
);
2595 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_CUBEMAP
))
2597 skip("Cube textures not supported, skipping tests.\n");
2601 hr
= IDirect3DDevice9_CreateCubeTexture(device
, 256, 1, 0, D3DFMT_A8R8G8B8
, D3DPOOL_SYSTEMMEM
,
2602 &cube_texture
, NULL
);
2603 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2605 hr
= D3DXFillCubeTextureTX(cube_texture
, tx
);
2606 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2607 compare_cube_texture(cube_texture
, fillfunc_cube_coord
, 1);
2608 IDirect3DCubeTexture9_Release(cube_texture
);
2610 if (!(caps
.TextureCaps
& D3DPTEXTURECAPS_VOLUMEMAP
) || caps
.MaxVolumeExtent
< 64)
2612 skip("Volume textures not supported, skipping test.\n");
2615 hr
= IDirect3DDevice9_CreateVolumeTexture(device
, 64, 64, 64, 1, 0, D3DFMT_A8R8G8B8
,
2616 D3DPOOL_SYSTEMMEM
, &volume_texture
, NULL
);
2617 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2619 hr
= D3DXFillVolumeTextureTX(volume_texture
, tx
);
2621 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2623 hr
= IDirect3DVolumeTexture9_LockBox(volume_texture
, 0, &lb
, NULL
, D3DLOCK_READONLY
);
2624 ok(SUCCEEDED(hr
), "Locking texture failed, hr %#lx.\n", hr
);
2626 for (z
= 0; z
< 64; ++z
)
2628 for (y
= 0; y
< 64; ++y
)
2630 for (x
= 0; x
< 64; ++x
)
2632 unsigned int expected
= 0xff000000 | ((x
* 4 + 2) << 16) | ((y
* 4 + 2) << 8) | (z
* 4 + 2);
2633 unsigned int color
= data
[z
* lb
.SlicePitch
/ sizeof(*data
) + y
* lb
.RowPitch
/ sizeof(*data
) + x
];
2636 ok(compare_color(color
, expected
, 1), "Unexpected color %08x at (%u, %u, %u).\n",
2641 hr
= IDirect3DVolumeTexture9_UnlockBox(volume_texture
, 0);
2642 ok(SUCCEEDED(hr
), "Unlocking texture failed, hr %#lx.\n", hr
);
2644 IDirect3DVolumeTexture9_Release(volume_texture
);
2646 IUnknown_Release(tx
);
2648 /* With constant table */
2650 hr
= D3DXCreateTextureShader(shader_code2
, &tx
);
2652 ok(SUCCEEDED(hr
), "Got unexpected hr %#lx.\n", hr
);
2656 hr
= tx
->lpVtbl
->GetConstantBuffer(tx
, &buffer
);
2658 ok(SUCCEEDED(hr
), "Failed to get texture shader constant buffer.\n");
2661 skip("Texture shaders not supported, skipping further tests.\n");
2662 IUnknown_Release(tx
);
2666 size
= ID3DXBuffer_GetBufferSize(buffer
);
2667 ok(size
== 176, "Unexpected buffer size %lu.\n", size
);
2669 hr
= tx
->lpVtbl
->GetDesc(tx
, &ctab_desc
);
2670 ok(hr
== S_OK
, "Failed to get constant description, hr %#lx.\n", hr
);
2671 ok(ctab_desc
.Constants
== 5, "Unexpected number of constants %u.\n", ctab_desc
.Constants
);
2673 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 0);
2674 ok(!!h
, "Unexpected handle %p.\n", h
);
2675 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h
, &const_desc
, &count
);
2676 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2677 ok(!strcmp(const_desc
.Name
, "b1"), "Unexpected name %s.\n", const_desc
.Name
);
2678 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2679 ok(const_desc
.RegisterIndex
== 9, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2680 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2682 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 1);
2683 ok(!!h
, "Unexpected handle %p.\n", h
);
2684 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h
, &const_desc
, &count
);
2685 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2686 ok(!strcmp(const_desc
.Name
, "b2"), "Unexpected name %s.\n", const_desc
.Name
);
2687 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2688 ok(const_desc
.RegisterIndex
== 7, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2689 ok(const_desc
.RegisterCount
== 2, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2691 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 2);
2692 ok(!!h
, "Unexpected handle %p.\n", h
);
2693 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h
, &const_desc
, &count
);
2694 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2695 ok(!strcmp(const_desc
.Name
, "f1"), "Unexpected name %s.\n", const_desc
.Name
);
2696 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2697 ok(const_desc
.RegisterIndex
== 5, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2698 ok(const_desc
.RegisterCount
== 2, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2699 ok(const_desc
.Elements
== 2, "Unexpected elements count %u.\n", const_desc
.Elements
);
2702 h2
= tx
->lpVtbl
->GetConstantElement(tx
, h
, 0);
2703 ok(!!h2
, "Unexpected handle %p.\n", h
);
2704 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h2
, &const_desc
, &count
);
2705 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2706 ok(!strcmp(const_desc
.Name
, "f1"), "Unexpected name %s.\n", const_desc
.Name
);
2707 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2708 ok(const_desc
.RegisterIndex
== 5, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2709 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2710 ok(const_desc
.Elements
== 1, "Unexpected elements count %u.\n", const_desc
.Elements
);
2712 h2
= tx
->lpVtbl
->GetConstantElement(tx
, h
, 1);
2713 ok(!!h2
, "Unexpected handle %p.\n", h
);
2714 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h2
, &const_desc
, &count
);
2715 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2716 ok(!strcmp(const_desc
.Name
, "f1"), "Unexpected name %s.\n", const_desc
.Name
);
2717 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2718 ok(const_desc
.RegisterIndex
== 6, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2719 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2720 ok(const_desc
.Elements
== 1, "Unexpected elements count %u.\n", const_desc
.Elements
);
2722 h2
= tx
->lpVtbl
->GetConstantElement(tx
, h
, 2);
2723 ok(!h2
, "Unexpected handle %p.\n", h
);
2725 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 3);
2726 ok(!!h
, "Unexpected handle %p.\n", h
);
2727 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h
, &const_desc
, &count
);
2728 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2729 ok(!strcmp(const_desc
.Name
, "f2"), "Unexpected name %s.\n", const_desc
.Name
);
2730 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2731 ok(const_desc
.RegisterIndex
== 10, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2732 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2735 h
= tx
->lpVtbl
->GetConstant(tx
, NULL
, 4);
2736 ok(!!h
, "Unexpected handle %p.\n", h
);
2737 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h
, &const_desc
, &count
);
2738 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2739 ok(!strcmp(const_desc
.Name
, "s1"), "Unexpected name %s.\n", const_desc
.Name
);
2740 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2741 ok(const_desc
.RegisterIndex
== 0, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2742 ok(const_desc
.RegisterCount
== 5, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2743 ok(const_desc
.Class
== D3DXPC_STRUCT
, "Unexpected class %u.\n", const_desc
.Class
);
2744 ok(const_desc
.StructMembers
== 5, "Unexpected member count %u.\n", const_desc
.StructMembers
);
2746 h2
= tx
->lpVtbl
->GetConstant(tx
, h
, 0);
2747 ok(!!h2
, "Unexpected handle %p.\n", h
);
2748 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h2
, &const_desc
, &count
);
2749 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2750 ok(!strcmp(const_desc
.Name
, "b3"), "Unexpected name %s.\n", const_desc
.Name
);
2751 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2752 ok(const_desc
.RegisterIndex
== 0, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2753 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2754 ok(const_desc
.Elements
== 1, "Unexpected elements count %u.\n", const_desc
.Elements
);
2756 h2
= tx
->lpVtbl
->GetConstant(tx
, h
, 1);
2757 ok(!!h2
, "Unexpected handle %p.\n", h
);
2758 hr
= tx
->lpVtbl
->GetConstantDesc(tx
, h2
, &const_desc
, &count
);
2759 ok(hr
== S_OK
, "Unexpected hr %#lx.\n", hr
);
2760 ok(!strcmp(const_desc
.Name
, "f3"), "Unexpected name %s.\n", const_desc
.Name
);
2761 ok(const_desc
.RegisterSet
== D3DXRS_FLOAT4
, "Unexpected register set %u.\n", const_desc
.RegisterSet
);
2762 ok(const_desc
.RegisterIndex
== 1, "Unexpected register index %u.\n", const_desc
.RegisterIndex
);
2763 ok(const_desc
.RegisterCount
== 1, "Unexpected register count %u.\n", const_desc
.RegisterCount
);
2764 ok(const_desc
.Elements
== 1, "Unexpected elements count %u.\n", const_desc
.Elements
);
2766 h2
= tx
->lpVtbl
->GetConstant(tx
, h
, 10);
2767 ok(!h2
, "Unexpected handle %p.\n", h
);
2769 ID3DXBuffer_Release(buffer
);
2772 IDirect3DDevice9_Release(device
);
2773 IDirect3D9_Release(d3d
);
2776 IUnknown_Release(tx
);
2783 IDirect3DDevice9
*device
;
2784 D3DPRESENT_PARAMETERS d3dpp
;
2788 if (!(wnd
= CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW
, 0, 0,
2789 640, 480, NULL
, NULL
, NULL
, NULL
)))
2791 skip("Couldn't create application window\n");
2794 d3d
= Direct3DCreate9(D3D_SDK_VERSION
);
2796 skip("Couldn't create IDirect3D9 object\n");
2801 ZeroMemory(&d3dpp
, sizeof(d3dpp
));
2802 d3dpp
.Windowed
= TRUE
;
2803 d3dpp
.SwapEffect
= D3DSWAPEFFECT_DISCARD
;
2804 hr
= IDirect3D9_CreateDevice(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, wnd
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &d3dpp
, &device
);
2806 skip("Failed to create IDirect3DDevice9 object %#lx\n", hr
);
2807 IDirect3D9_Release(d3d
);
2812 /* Check whether DXTn textures are supported. */
2813 has_2d_dxt1
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2814 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT1
));
2815 has_2d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2816 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT3
));
2817 has_2d_dxt5
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2818 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_TEXTURE
, D3DFMT_DXT5
));
2819 has_cube_dxt5
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2820 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_CUBETEXTURE
, D3DFMT_DXT5
));
2821 has_3d_dxt3
= SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
,
2822 D3DFMT_X8R8G8B8
, 0, D3DRTYPE_VOLUMETEXTURE
, D3DFMT_DXT3
));
2823 trace("DXTn texture support: 2D DXT1 %#x, 2D DXT3 %#x, 2D DXT5 %#x, cube DXT5 %#x, 3D dxt3 %#x.\n",
2824 has_2d_dxt1
, has_2d_dxt3
, has_2d_dxt5
, has_cube_dxt5
, has_3d_dxt3
);
2826 test_D3DXCheckTextureRequirements(device
);
2827 test_D3DXCheckCubeTextureRequirements(device
);
2828 test_D3DXCheckVolumeTextureRequirements(device
);
2829 test_D3DXCreateTexture(device
);
2830 test_D3DXFilterTexture(device
);
2831 test_D3DXFillTexture(device
);
2832 test_D3DXFillCubeTexture(device
);
2833 test_D3DXFillVolumeTexture(device
);
2834 test_D3DXCreateTextureFromFileInMemory(device
);
2835 test_D3DXCreateTextureFromFileInMemoryEx(device
);
2836 test_D3DXCreateCubeTextureFromFileInMemory(device
);
2837 test_D3DXCreateCubeTextureFromFileInMemoryEx(device
);
2838 test_D3DXCreateVolumeTextureFromFileInMemory(device
);
2839 test_D3DXCreateVolumeTextureFromFileInMemoryEx(device
);
2840 test_D3DXSaveTextureToFileInMemory(device
);
2842 ref
= IDirect3DDevice9_Release(device
);
2843 ok(!ref
, "Device has %lu references left.\n", ref
);
2845 IDirect3D9_Release(d3d
);
2848 test_texture_shader();