riched20: Rewrite the picture destination parser to handle embedded groups.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob095650f11d38f9d344fa6e7b3ee56a9166fea029
1 /*
2 * Tests for the D3DX9 texture functions
4 * Copyright 2009 Tony Wasserka
5 * Copyright 2010 Owen Rudge for CodeWeavers
6 * Copyright 2010 Matteo Bruni for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define COBJMACROS
24 #include "wine/test.h"
25 #include "d3dx9tex.h"
26 #include "resources.h"
28 static int has_2d_dxt3, has_2d_dxt5, has_cube_dxt5, has_3d_dxt3;
30 /* 2x2 16-bit dds, no mipmaps */
31 static const unsigned char dds_16bit[] = {
32 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
33 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
35 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
37 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
38 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
39 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
43 /* 2x2 24-bit dds, 2 mipmaps */
44 static const unsigned char dds_24bit[] = {
45 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
46 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
47 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
48 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
49 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
50 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
51 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
52 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
53 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
56 /* 4x4 cube map dds */
57 static const unsigned char dds_cube_map[] = {
58 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
59 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
60 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
61 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
63 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
64 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
65 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
66 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
67 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x51,
68 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x52,
69 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x53,
70 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x54,
71 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x55
74 /* 4x4x2 volume map dds, 2 mipmaps */
75 static const unsigned char dds_volume_map[] = {
76 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
77 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
78 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
81 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
83 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
84 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
85 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
86 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
87 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
90 static const unsigned char png_grayscale[] =
92 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
93 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00,
94 0x00, 0x00, 0x00, 0x3a, 0x7e, 0x9b, 0x55, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44,
95 0x41, 0x54, 0x08, 0xd7, 0x63, 0xf8, 0x0f, 0x00, 0x01, 0x01, 0x01, 0x00, 0x1b,
96 0xb6, 0xee, 0x56, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42,
97 0x60, 0x82
100 #define ADMITTED_ERROR 0.0001f
102 static inline float relative_error(float expected, float got)
104 return expected == 0.0f ? fabs(expected - got) : fabs(1.0f - got / expected);
107 #define expect_vec4(expected, got) expect_vec4_(__LINE__, expected, got)
108 static inline void expect_vec4_(unsigned int line, const D3DXVECTOR4 *expected, const D3DXVECTOR4 *got)
110 ok_(__FILE__, line)(relative_error(expected->x, got->x) < ADMITTED_ERROR
111 && relative_error(expected->y, got->y) < ADMITTED_ERROR
112 && relative_error(expected->z, got->z) < ADMITTED_ERROR
113 && relative_error(expected->w, got->w) < ADMITTED_ERROR,
114 "Expected (%f, %f, %f, %f), got (%f, %f, %f, %f)\n",
115 expected->x, expected->y, expected->z, expected->w,
116 got->x, got->y, got->z, got->w);
119 static BOOL is_autogenmipmap_supported(IDirect3DDevice9 *device, D3DRESOURCETYPE resource_type)
121 HRESULT hr;
122 D3DCAPS9 caps;
123 IDirect3D9 *d3d9;
124 D3DDISPLAYMODE mode;
125 D3DDEVICE_CREATION_PARAMETERS params;
127 IDirect3DDevice9_GetDeviceCaps(device, &caps);
128 IDirect3DDevice9_GetDirect3D(device, &d3d9);
129 IDirect3DDevice9_GetCreationParameters(device, &params);
130 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
132 if (!(caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP))
133 return FALSE;
135 hr = IDirect3D9_CheckDeviceFormat(d3d9, params.AdapterOrdinal, params.DeviceType,
136 mode.Format, D3DUSAGE_AUTOGENMIPMAP, resource_type, D3DFMT_A8R8G8B8);
138 IDirect3D9_Release(d3d9);
139 return SUCCEEDED(hr);
142 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
144 UINT width, height, mipmaps;
145 D3DFORMAT format, expected;
146 D3DCAPS9 caps;
147 HRESULT hr;
148 IDirect3D9 *d3d;
149 D3DDEVICE_CREATION_PARAMETERS params;
150 D3DDISPLAYMODE mode;
152 IDirect3DDevice9_GetDeviceCaps(device, &caps);
154 /* general tests */
155 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
156 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
158 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
159 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
161 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
162 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
164 /* width & height */
165 width = height = D3DX_DEFAULT;
166 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
167 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
168 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
169 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
171 width = D3DX_DEFAULT;
172 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
173 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
174 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
176 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
177 skip("Hardware only supports pow2 textures\n");
178 else
180 width = 62;
181 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
182 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
183 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
185 width = D3DX_DEFAULT; height = 63;
186 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
187 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
188 ok(width == height, "Returned width %d, expected %d\n", width, height);
189 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
192 width = D3DX_DEFAULT; height = 0;
193 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
194 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
195 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
196 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
198 width = 0; height = 0;
199 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
200 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
201 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
202 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
204 width = 0;
205 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
206 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
207 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
209 width = 0xFFFFFFFE;
210 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
211 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
212 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
214 width = caps.MaxTextureWidth-1;
215 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
216 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
217 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
218 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
219 else
220 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
222 /* mipmaps */
223 width = 64; height = 63;
224 mipmaps = 9;
225 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
226 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
227 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
229 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
231 width = 284; height = 137;
232 mipmaps = 20;
233 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
234 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
235 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
237 width = height = 63;
238 mipmaps = 9;
239 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
240 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
241 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
243 else
244 skip("Skipping some tests, npot2 textures unsupported\n");
246 mipmaps = 20;
247 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
248 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
249 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
251 mipmaps = 0;
252 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
253 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
254 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
256 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
257 if (is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
259 mipmaps = 0;
260 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
261 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
262 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
263 mipmaps = 1;
264 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
265 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
266 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
267 mipmaps = 2;
268 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
269 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
270 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
271 mipmaps = 6;
272 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
273 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
274 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
276 else
277 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
279 /* usage */
280 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
281 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
282 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
283 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
284 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
285 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
286 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
287 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
288 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
289 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
291 /* format */
292 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
293 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
295 format = D3DFMT_UNKNOWN;
296 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
297 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
298 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
300 format = D3DX_DEFAULT;
301 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
302 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
303 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
305 format = D3DFMT_R8G8B8;
306 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
307 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
308 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
310 IDirect3DDevice9_GetDirect3D(device, &d3d);
311 IDirect3DDevice9_GetCreationParameters(device, &params);
312 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
314 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
315 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
316 expected = D3DFMT_R3G3B2;
317 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
318 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
319 expected = D3DFMT_X4R4G4B4;
320 else if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
321 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X1R5G5B5)))
322 expected = D3DFMT_X1R5G5B5;
323 else
324 expected = D3DFMT_R5G6B5;
326 format = D3DFMT_R3G3B2;
327 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
328 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
329 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
331 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
332 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
333 expected = D3DFMT_A8R3G3B2;
334 else
335 expected = D3DFMT_A8R8G8B8;
337 format = D3DFMT_A8R3G3B2;
338 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
339 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
340 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
342 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
343 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_P8)))
344 expected = D3DFMT_P8;
345 else
346 expected = D3DFMT_A8R8G8B8;
348 format = D3DFMT_P8;
349 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
350 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
351 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
353 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
354 mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L8)))
355 expected = D3DFMT_L8;
356 else
357 expected = D3DFMT_X8R8G8B8;
359 format = D3DFMT_L8;
360 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
361 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
362 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
364 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
365 mode.Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_L16)))
366 expected = D3DFMT_L16;
367 else
368 expected = D3DFMT_A16B16G16R16;
370 format = D3DFMT_L16;
371 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RENDERTARGET, &format, D3DPOOL_DEFAULT);
372 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
373 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
375 /* Block-based texture formats and size < block size. */
376 if (has_2d_dxt5)
378 format = D3DFMT_DXT5;
379 width = 2; height = 2;
380 mipmaps = 1;
381 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, &format, D3DPOOL_DEFAULT);
382 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
383 ok(width == 4, "Returned width %d, expected %d\n", width, 4);
384 ok(height == 4, "Returned height %d, expected %d\n", height, 4);
385 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
386 ok(format == D3DFMT_DXT5, "Returned format %u, expected %u\n", format, D3DFMT_DXT5);
388 else
390 skip("D3DFMT_DXT5 textures are not supported, skipping a test.\n");
393 IDirect3D9_Release(d3d);
396 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
398 UINT size, mipmaps, expected;
399 D3DFORMAT format;
400 D3DCAPS9 caps;
401 HRESULT hr;
403 IDirect3DDevice9_GetDeviceCaps(device, &caps);
405 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
407 skip("No cube textures support\n");
408 return;
411 /* general tests */
412 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
413 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
415 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
416 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
418 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
419 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
421 /* size */
422 size = D3DX_DEFAULT;
423 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
424 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
425 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
427 /* mipmaps */
428 size = 64;
429 mipmaps = 9;
430 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
431 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
432 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
434 size = 284;
435 mipmaps = 20;
436 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
437 expected = caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP ? expected : 1;
438 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
439 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
440 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
442 size = 63;
443 mipmaps = 9;
444 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
445 expected = caps.TextureCaps & D3DPTEXTURECAPS_MIPCUBEMAP ? expected : 1;
446 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
447 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
448 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
450 mipmaps = 0;
451 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
452 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
453 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
455 if (is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
457 mipmaps = 3;
458 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
459 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
460 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
462 else
463 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
465 /* usage */
466 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
467 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
468 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
469 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
470 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
471 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
472 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
473 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
474 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
475 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
477 /* format */
478 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
479 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
481 format = D3DFMT_UNKNOWN;
482 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
483 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
484 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
486 format = D3DX_DEFAULT;
487 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
488 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
489 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
491 format = D3DFMT_R8G8B8;
492 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
493 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
494 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
497 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
499 UINT width, height, depth, mipmaps, expected;
500 D3DFORMAT format;
501 D3DCAPS9 caps;
502 HRESULT hr;
504 IDirect3DDevice9_GetDeviceCaps(device, &caps);
506 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP) || (caps.MaxVolumeExtent < 256))
508 skip("Limited or no volume textures support.\n");
509 return;
512 /* general tests */
513 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
514 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
516 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
517 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
519 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
520 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
522 /* width, height, depth */
523 width = height = depth = D3DX_DEFAULT;
524 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
525 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
526 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
527 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
528 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
530 width = D3DX_DEFAULT;
531 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
532 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
533 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
535 width = D3DX_DEFAULT; height = 0; depth = 0;
536 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
537 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
538 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
539 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
540 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
542 width = 0; height = 0; depth = 0;
543 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
544 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
545 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
546 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
547 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
549 width = 0;
550 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
551 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
552 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
554 width = 0xFFFFFFFE;
555 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
556 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
557 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
559 /* format */
560 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
561 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
563 format = D3DFMT_UNKNOWN;
564 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
565 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
566 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
568 format = D3DX_DEFAULT;
569 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
570 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
571 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
573 format = D3DFMT_R8G8B8;
574 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
575 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
576 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
578 format = D3DFMT_DXT3;
579 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
580 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
581 if (has_3d_dxt3)
582 ok(format == D3DFMT_DXT3, "Returned format %u, expected %u\n", format, D3DFMT_DXT3);
583 else
584 todo_wine ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
586 /* mipmaps */
587 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
589 skip("No volume textures mipmapping support\n");
590 return;
593 width = height = depth = 64;
594 mipmaps = 9;
595 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
596 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
597 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
599 width = 284;
600 height = 143;
601 depth = 55;
602 mipmaps = 20;
603 expected = (caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 && caps.MaxVolumeExtent >= 512) ? 10 : 9;
604 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
605 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
606 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
608 mipmaps = 0;
609 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
610 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
611 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
613 if (!is_autogenmipmap_supported(device, D3DRTYPE_VOLUMETEXTURE))
615 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
616 return;
619 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
620 mipmaps = 0;
621 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
622 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
623 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
624 mipmaps = 1;
625 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
626 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
627 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
628 mipmaps = 3;
629 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
630 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
631 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
634 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
636 IDirect3DTexture9 *texture;
637 D3DSURFACE_DESC desc;
638 D3DCAPS9 caps;
639 UINT mipmaps;
640 HRESULT hr;
642 IDirect3DDevice9_GetDeviceCaps(device, &caps);
644 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, D3DPOOL_DEFAULT, NULL);
645 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
647 /* width and height tests */
649 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
650 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
652 if (texture)
654 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
655 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
656 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
658 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
659 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
661 IDirect3DTexture9_Release(texture);
665 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
666 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
668 if (texture)
670 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
671 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
672 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
674 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
675 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
677 IDirect3DTexture9_Release(texture);
681 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
682 skip("Hardware only supports pow2 textures\n");
683 else
685 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
686 ok((hr == D3D_OK) ||
687 /* may not work with conditional NPOT */
688 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
689 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
691 if (texture)
693 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
694 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
695 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
697 /* Conditional NPOT may create a texture with different dimensions, so allow those
698 situations instead of returning a fail */
700 ok(desc.Width == 63 ||
701 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
702 "Returned width %d, expected %d\n", desc.Width, 63);
704 ok(desc.Height == 63 ||
705 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
706 "Returned height %d, expected %d\n", desc.Height, 63);
708 IDirect3DTexture9_Release(texture);
712 /* mipmaps */
714 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
715 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
717 if (texture)
719 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
720 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
722 IDirect3DTexture9_Release(texture);
726 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
727 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
729 if (texture)
731 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
732 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
734 IDirect3DTexture9_Release(texture);
738 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
739 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
741 if (texture)
743 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
744 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
746 IDirect3DTexture9_Release(texture);
750 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
751 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
753 if (texture)
755 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
756 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
758 IDirect3DTexture9_Release(texture);
761 /* usage */
763 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
764 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
765 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
766 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
767 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
768 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
769 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
770 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
771 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
772 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
774 /* format */
776 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
777 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
779 if (texture)
781 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
782 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
783 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
785 IDirect3DTexture9_Release(texture);
789 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
790 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
792 if (texture)
794 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
795 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
796 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
798 IDirect3DTexture9_Release(texture);
801 /* D3DXCreateTextureFromResource */
802 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
803 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
804 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
806 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
807 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
808 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
810 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
811 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
813 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
814 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
816 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
817 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
819 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
820 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
823 /* D3DXCreateTextureFromResourceEx */
824 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
825 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
826 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
828 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
829 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
831 hr = D3DXCreateTextureFromResourceExA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
832 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
834 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
835 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
837 hr = D3DXCreateTextureFromResourceExA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, NULL);
838 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
841 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
843 IDirect3DTexture9 *tex;
844 IDirect3DCubeTexture9 *cubetex;
845 IDirect3DVolumeTexture9 *voltex;
846 HRESULT hr;
848 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
850 if (SUCCEEDED(hr))
852 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, D3DX_DEFAULT, D3DX_FILTER_NONE);
853 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
855 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
856 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
858 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
859 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
861 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
862 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
864 IDirect3DTexture9_Release(tex);
866 else
867 skip("Failed to create texture\n");
869 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
870 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
872 /* Test different pools */
873 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
875 if (SUCCEEDED(hr))
877 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
878 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
879 IDirect3DTexture9_Release(tex);
881 else
882 skip("Failed to create texture\n");
884 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
886 if (SUCCEEDED(hr))
888 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
889 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
890 IDirect3DTexture9_Release(tex);
892 else
893 skip("Failed to create texture\n");
895 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
896 if (SUCCEEDED(hr))
898 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
899 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
900 IDirect3DTexture9_Release(tex);
902 else
903 skip("Failed to create texture\n");
905 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
906 if (SUCCEEDED(hr))
908 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
909 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
910 IDirect3DTexture9_Release(tex);
912 else
913 skip("Failed to create texture\n");
915 /* Cube texture test */
916 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
918 if (SUCCEEDED(hr))
920 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
921 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
923 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
924 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
926 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
927 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
928 IDirect3DCubeTexture9_Release(cubetex);
930 else
931 skip("Failed to create texture\n");
933 /* Volume texture test */
934 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 4, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &voltex, NULL);
935 if (SUCCEEDED(hr))
937 DWORD level_count = IDirect3DVolumeTexture9_GetLevelCount(voltex);
939 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_NONE);
940 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
942 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_DEFAULT);
943 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
945 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, 0, D3DX_FILTER_BOX);
946 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
948 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count - 1, D3DX_DEFAULT);
949 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
951 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) voltex, NULL, level_count, D3DX_DEFAULT);
952 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
954 IDirect3DVolumeTexture9_Release(voltex);
956 else
957 skip("Failed to create volume texture\n");
959 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
960 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
962 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
963 return;
966 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
967 if (SUCCEEDED(hr))
969 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
970 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
971 IDirect3DTexture9_Release(tex);
973 else
974 skip("Failed to create texture\n");
976 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
977 if (SUCCEEDED(hr))
979 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
980 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
981 IDirect3DTexture9_Release(tex);
983 else
984 skip("Failed to create texture\n");
987 static BOOL color_match(const DWORD *value, const DWORD *expected)
989 int i;
991 for (i = 0; i < 4; i++)
993 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
994 if (diff > 1) return FALSE;
996 return TRUE;
999 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
1000 const D3DXVECTOR2 *texelsize, void *data)
1002 value->x = texcoord->x;
1003 value->y = texcoord->y;
1004 value->z = texelsize->x;
1005 value->w = 1.0f;
1008 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
1010 IDirect3DTexture9 *tex;
1011 HRESULT hr;
1012 D3DLOCKED_RECT lock_rect;
1013 DWORD x, y, m;
1014 DWORD v[4], e[4];
1015 DWORD value, expected, size, pitch;
1017 size = 4;
1018 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
1019 D3DPOOL_MANAGED, &tex, NULL);
1021 if (SUCCEEDED(hr))
1023 hr = D3DXFillTexture(tex, fillfunc, NULL);
1024 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1026 for (m = 0; m < 3; m++)
1028 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
1029 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1030 if (SUCCEEDED(hr))
1032 pitch = lock_rect.Pitch / sizeof(DWORD);
1033 for (y = 0; y < size; y++)
1035 for (x = 0; x < size; x++)
1037 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1038 v[0] = (value >> 24) & 0xff;
1039 v[1] = (value >> 16) & 0xff;
1040 v[2] = (value >> 8) & 0xff;
1041 v[3] = value & 0xff;
1043 e[0] = 0xff;
1044 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1045 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1046 e[3] = 255.0f / size + 0.5f;
1047 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1049 ok(color_match(v, e),
1050 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1051 x, y, value, expected);
1054 IDirect3DTexture9_UnlockRect(tex, m);
1056 size >>= 1;
1059 IDirect3DTexture9_Release(tex);
1061 else
1062 skip("Failed to create texture\n");
1064 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1065 D3DPOOL_MANAGED, &tex, NULL);
1067 if (SUCCEEDED(hr))
1069 hr = D3DXFillTexture(tex, fillfunc, NULL);
1070 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1072 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1073 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1074 if (SUCCEEDED(hr))
1076 pitch = lock_rect.Pitch / sizeof(WORD);
1077 for (y = 0; y < 4; y++)
1079 for (x = 0; x < 4; x++)
1081 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1082 v[0] = value >> 15;
1083 v[1] = value >> 10 & 0x1f;
1084 v[2] = value >> 5 & 0x1f;
1085 v[3] = value & 0x1f;
1087 e[0] = 1;
1088 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
1089 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
1090 e[3] = 8;
1091 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1093 ok(color_match(v, e),
1094 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
1095 x, y, value, expected);
1098 IDirect3DTexture9_UnlockRect(tex, 0);
1101 IDirect3DTexture9_Release(tex);
1103 else
1104 skip("Failed to create texture\n");
1106 /* test floating-point textures */
1107 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A16B16G16R16F,
1108 D3DPOOL_MANAGED, &tex, NULL);
1110 if (SUCCEEDED(hr))
1112 hr = D3DXFillTexture(tex, fillfunc, NULL);
1113 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1115 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1116 if (SUCCEEDED(hr))
1118 pitch = lock_rect.Pitch / sizeof(WORD);
1119 for (y = 0; y < 4; y++)
1121 WORD *ptr = (WORD *)lock_rect.pBits + y * pitch;
1122 for (x = 0; x < 4; x++)
1124 D3DXVECTOR4 got, expected;
1126 D3DXFloat16To32Array((FLOAT *)&got, (D3DXFLOAT16 *)ptr, 4);
1127 ptr += 4;
1129 expected.x = (x + 0.5f) / 4.0f;
1130 expected.y = (y + 0.5f) / 4.0f;
1131 expected.z = 1.0f / 4.0f;
1132 expected.w = 1.0f;
1134 expect_vec4(&expected, &got);
1138 IDirect3DTexture9_UnlockRect(tex, 0);
1140 else
1141 skip("Failed to lock texture\n");
1143 IDirect3DTexture9_Release(tex);
1145 else
1146 skip("Failed to create D3DFMT_A16B16G16R16F texture\n");
1148 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A32B32G32R32F,
1149 D3DPOOL_MANAGED, &tex, NULL);
1151 if (SUCCEEDED(hr))
1153 hr = D3DXFillTexture(tex, fillfunc, NULL);
1154 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1156 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1157 if (SUCCEEDED(hr))
1159 pitch = lock_rect.Pitch / sizeof(float);
1160 for (y = 0; y < 4; y++)
1162 float *ptr = (float *)lock_rect.pBits + y * pitch;
1163 for (x = 0; x < 4; x++)
1165 D3DXVECTOR4 got, expected;
1167 got.x = *ptr++;
1168 got.y = *ptr++;
1169 got.z = *ptr++;
1170 got.w = *ptr++;
1172 expected.x = (x + 0.5f) / 4.0f;
1173 expected.y = (y + 0.5f) / 4.0f;
1174 expected.z = 1.0f / 4.0f;
1175 expected.w = 1.0f;
1177 expect_vec4(&expected, &got);
1181 IDirect3DTexture9_UnlockRect(tex, 0);
1183 else
1184 skip("Failed to lock texture\n");
1186 IDirect3DTexture9_Release(tex);
1188 else
1189 skip("Failed to create D3DFMT_A32B32G32R32F texture\n");
1191 /* test a compressed texture */
1192 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_DXT1,
1193 D3DPOOL_MANAGED, &tex, NULL);
1195 if (SUCCEEDED(hr))
1197 hr = D3DXFillTexture(tex, fillfunc, NULL);
1198 todo_wine ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1200 IDirect3DTexture9_Release(tex);
1202 else
1203 skip("Failed to create D3DFMT_DXT1 texture\n");
1206 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1207 const D3DXVECTOR3 *texelsize, void *data)
1209 value->x = (texcoord->x + 1.0f) / 2.0f;
1210 value->y = (texcoord->y + 1.0f) / 2.0f;
1211 value->z = (texcoord->z + 1.0f) / 2.0f;
1212 value->w = texelsize->x;
1215 enum cube_coord
1217 XCOORD = 0,
1218 XCOORDINV = 1,
1219 YCOORD = 2,
1220 YCOORDINV = 3,
1221 ZERO = 4,
1222 ONE = 5
1225 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1227 switch (coord)
1229 case XCOORD:
1230 return x + 0.5f;
1231 case XCOORDINV:
1232 return size - x - 0.5f;
1233 case YCOORD:
1234 return y + 0.5f;
1235 case YCOORDINV:
1236 return size - y - 0.5f;
1237 case ZERO:
1238 return 0.0f;
1239 case ONE:
1240 return size;
1241 default:
1242 trace("Unexpected coordinate value\n");
1243 return 0.0f;
1247 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
1249 IDirect3DCubeTexture9 *tex;
1250 HRESULT hr;
1251 D3DLOCKED_RECT lock_rect;
1252 DWORD x, y, f, m;
1253 DWORD v[4], e[4];
1254 DWORD value, expected, size, pitch;
1255 enum cube_coord coordmap[6][3] =
1257 {ONE, YCOORDINV, XCOORDINV},
1258 {ZERO, YCOORDINV, XCOORD},
1259 {XCOORD, ONE, YCOORD},
1260 {XCOORD, ZERO, YCOORDINV},
1261 {XCOORD, YCOORDINV, ONE},
1262 {XCOORDINV, YCOORDINV, ZERO}
1265 size = 4;
1266 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1267 D3DPOOL_MANAGED, &tex, NULL);
1269 if (SUCCEEDED(hr))
1271 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1272 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1274 for (m = 0; m < 3; m++)
1276 for (f = 0; f < 6; f++)
1278 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1279 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1280 if (SUCCEEDED(hr))
1282 pitch = lock_rect.Pitch / sizeof(DWORD);
1283 for (y = 0; y < size; y++)
1285 for (x = 0; x < size; x++)
1287 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1288 v[0] = (value >> 24) & 0xff;
1289 v[1] = (value >> 16) & 0xff;
1290 v[2] = (value >> 8) & 0xff;
1291 v[3] = value & 0xff;
1293 e[0] = (f == 0) || (f == 1) ?
1294 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1295 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1296 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1297 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1298 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1300 ok(color_match(v, e),
1301 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1302 f, x, y, value, expected);
1305 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1308 size >>= 1;
1311 IDirect3DCubeTexture9_Release(tex);
1313 else
1314 skip("Failed to create texture\n");
1316 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1317 D3DPOOL_MANAGED, &tex, NULL);
1319 if (SUCCEEDED(hr))
1321 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1322 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1323 for (f = 0; f < 6; f++)
1325 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1326 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1327 if (SUCCEEDED(hr))
1329 pitch = lock_rect.Pitch / sizeof(WORD);
1330 for (y = 0; y < 4; y++)
1332 for (x = 0; x < 4; x++)
1334 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1335 v[0] = value >> 15;
1336 v[1] = value >> 10 & 0x1f;
1337 v[2] = value >> 5 & 0x1f;
1338 v[3] = value & 0x1f;
1340 e[0] = (f == 0) || (f == 1) ?
1341 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1342 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1343 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1344 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1345 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1347 ok(color_match(v, e),
1348 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1349 f, x, y, value, expected);
1352 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1356 IDirect3DCubeTexture9_Release(tex);
1358 else
1359 skip("Failed to create texture\n");
1362 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1363 const D3DXVECTOR3 *texelsize, void *data)
1365 value->x = texcoord->x;
1366 value->y = texcoord->y;
1367 value->z = texcoord->z;
1368 value->w = texelsize->x;
1371 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1373 IDirect3DVolumeTexture9 *tex;
1374 HRESULT hr;
1375 D3DLOCKED_BOX lock_box;
1376 DWORD x, y, z, m;
1377 DWORD v[4], e[4];
1378 DWORD value, expected, size, row_pitch, slice_pitch;
1380 size = 4;
1381 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1382 D3DPOOL_MANAGED, &tex, NULL);
1384 if (SUCCEEDED(hr))
1386 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1387 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1389 for (m = 0; m < 3; m++)
1391 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1392 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1393 if (SUCCEEDED(hr))
1395 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1396 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1397 for (z = 0; z < size; z++)
1399 for (y = 0; y < size; y++)
1401 for (x = 0; x < size; x++)
1403 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1404 v[0] = (value >> 24) & 0xff;
1405 v[1] = (value >> 16) & 0xff;
1406 v[2] = (value >> 8) & 0xff;
1407 v[3] = value & 0xff;
1409 e[0] = 255.0f / size + 0.5f;
1410 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1411 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1412 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1413 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1415 ok(color_match(v, e),
1416 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1417 x, y, z, value, expected);
1421 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1423 size >>= 1;
1426 IDirect3DVolumeTexture9_Release(tex);
1428 else
1429 skip("Failed to create texture\n");
1431 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1432 D3DPOOL_MANAGED, &tex, NULL);
1434 if (SUCCEEDED(hr))
1436 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1437 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1438 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1439 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1440 if (SUCCEEDED(hr))
1442 row_pitch = lock_box.RowPitch / sizeof(WORD);
1443 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1444 for (z = 0; z < 4; z++)
1446 for (y = 0; y < 4; y++)
1448 for (x = 0; x < 4; x++)
1450 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1451 v[0] = value >> 15;
1452 v[1] = value >> 10 & 0x1f;
1453 v[2] = value >> 5 & 0x1f;
1454 v[3] = value & 0x1f;
1456 e[0] = 1;
1457 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1458 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1459 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1460 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1462 ok(color_match(v, e),
1463 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1464 x, y, z, value, expected);
1468 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1471 IDirect3DVolumeTexture9_Release(tex);
1473 else
1474 skip("Failed to create texture\n");
1477 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1479 HRESULT hr;
1480 IDirect3DTexture9 *texture;
1481 D3DRESOURCETYPE type;
1482 D3DSURFACE_DESC desc;
1483 D3DLOCKED_RECT lock_rect;
1484 int i;
1485 DWORD level_count;
1487 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1488 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1489 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1491 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1492 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1493 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1495 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1496 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1498 /* Check that D3DXCreateTextureFromFileInMemory accepts cube texture dds file (only first face texture is loaded) */
1499 hr = D3DXCreateTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &texture);
1500 if (has_2d_dxt5)
1501 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1502 else
1503 todo_wine ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1504 if (SUCCEEDED(hr))
1506 type = IDirect3DTexture9_GetType(texture);
1507 ok(type == D3DRTYPE_TEXTURE, "IDirect3DTexture9_GetType returned %u, expected %u\n", type, D3DRTYPE_TEXTURE);
1508 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
1509 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1510 ok(desc.Width == 4, "Width is %u, expected 4\n", desc.Width);
1511 ok(desc.Height == 4, "Height is %u, expected 4\n", desc.Height);
1512 hr = IDirect3DTexture9_LockRect(texture, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1513 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %#x, expected %#x\n", hr, D3D_OK);
1514 if (SUCCEEDED(hr))
1516 for (i = 0; i < 16; i++)
1517 ok(((BYTE *)lock_rect.pBits)[i] == dds_cube_map[128 + i],
1518 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1519 i, ((BYTE *)lock_rect.pBits)[i], dds_cube_map[128 + i]);
1520 IDirect3DTexture9_UnlockRect(texture, 0);
1522 IDirect3DTexture9_Release(texture);
1526 /* Volume textures work too. */
1527 hr = D3DXCreateTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &texture);
1528 if (has_2d_dxt3)
1529 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1530 else
1531 todo_wine ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x.\n", hr, D3D_OK);
1532 if (SUCCEEDED(hr))
1534 type = IDirect3DTexture9_GetType(texture);
1535 ok(type == D3DRTYPE_TEXTURE, "IDirect3DTexture9_GetType returned %u, expected %u.\n", type, D3DRTYPE_TEXTURE);
1536 level_count = IDirect3DBaseTexture9_GetLevelCount((IDirect3DBaseTexture9 *)texture);
1537 todo_wine ok(level_count == 3, "Texture has %u mip levels, 3 expected.\n", level_count);
1538 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
1539 ok(hr == D3D_OK, "IDirect3DTexture9_GetLevelDesc returned %#x, expected %#x.\n", hr, D3D_OK);
1540 ok(desc.Width == 4, "Width is %u, expected 4.\n", desc.Width);
1541 ok(desc.Height == 4, "Height is %u, expected 4.\n", desc.Height);
1543 hr = IDirect3DTexture9_LockRect(texture, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1544 ok(hr == D3D_OK, "IDirect3DTexture9_LockRect returned %#x, expected %#x.\n", hr, D3D_OK);
1545 if (SUCCEEDED(hr))
1547 for (i = 0; i < 16; ++i)
1548 ok(((BYTE *)lock_rect.pBits)[i] == dds_volume_map[128 + i],
1549 "Byte at index %u is 0x%02x, expected 0x%02x.\n",
1550 i, ((BYTE *)lock_rect.pBits)[i], dds_volume_map[128 + i]);
1551 IDirect3DTexture9_UnlockRect(texture, 0);
1553 /* The lower texture levels are apparently generated by filtering the level 0 surface
1554 * I.e. following levels from the file are ignored. */
1555 IDirect3DTexture9_Release(texture);
1559 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1561 HRESULT hr;
1562 IDirect3DTexture9 *texture;
1563 unsigned int miplevels;
1564 IDirect3DSurface9 *surface;
1565 D3DSURFACE_DESC desc;
1567 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1568 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1569 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1570 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1572 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1573 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1574 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1575 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1577 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit), D3DX_DEFAULT,
1578 D3DX_DEFAULT, D3DX_DEFAULT, D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1579 D3DX_DEFAULT, D3DX_SKIP_DDS_MIP_LEVELS(1, D3DX_FILTER_POINT), 0, NULL, NULL, &texture);
1580 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1581 if (SUCCEEDED(hr))
1583 miplevels = IDirect3DTexture9_GetLevelCount(texture);
1584 ok(miplevels == 1, "Got miplevels %u, expected %u\n", miplevels, 1);
1585 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1586 IDirect3DSurface9_GetDesc(surface, &desc);
1587 ok(desc.Width == 1 && desc.Height == 1,
1588 "Surface dimensions are %ux%u, expected 1x1.\n", desc.Width, desc.Height);
1589 IDirect3DSurface9_Release(surface);
1590 IDirect3DTexture9_Release(texture);
1593 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
1595 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1596 return;
1599 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1600 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1601 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1602 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1604 /* Checking for color key format overrides. */
1605 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit),
1606 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1607 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1608 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1609 if (SUCCEEDED(hr))
1611 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1612 IDirect3DSurface9_GetDesc(surface, &desc);
1613 ok(desc.Format == D3DFMT_X1R5G5B5, "Returned format %u, expected %u\n", desc.Format, D3DFMT_X1R5G5B5);
1614 IDirect3DTexture9_Release(texture);
1616 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit),
1617 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1618 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1619 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1620 if (SUCCEEDED(hr))
1622 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1623 IDirect3DSurface9_GetDesc(surface, &desc);
1624 ok(desc.Format == D3DFMT_A1R5G5B5, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A1R5G5B5);
1625 IDirect3DTexture9_Release(texture);
1627 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit),
1628 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_X1R5G5B5, D3DPOOL_DEFAULT,
1629 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1630 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1631 if (SUCCEEDED(hr))
1633 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1634 IDirect3DSurface9_GetDesc(surface, &desc);
1635 ok(desc.Format == D3DFMT_X1R5G5B5, "Returned format %u, expected %u\n", desc.Format, D3DFMT_X1R5G5B5);
1636 IDirect3DTexture9_Release(texture);
1639 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit),
1640 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1641 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1642 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1643 if (SUCCEEDED(hr))
1645 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1646 IDirect3DSurface9_GetDesc(surface, &desc);
1647 ok(desc.Format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_X8R8G8B8);
1648 IDirect3DTexture9_Release(texture);
1650 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit),
1651 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1652 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1653 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1654 if (SUCCEEDED(hr))
1656 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1657 IDirect3DSurface9_GetDesc(surface, &desc);
1658 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
1659 IDirect3DTexture9_Release(texture);
1661 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_24bit, sizeof(dds_24bit),
1662 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT,
1663 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1664 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1665 if (SUCCEEDED(hr))
1667 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1668 IDirect3DSurface9_GetDesc(surface, &desc);
1669 ok(desc.Format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_X8R8G8B8);
1670 IDirect3DTexture9_Release(texture);
1673 hr = D3DXCreateTextureFromFileInMemoryEx(device, png_grayscale, sizeof(png_grayscale),
1674 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1675 D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1676 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1677 if (SUCCEEDED(hr))
1679 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1680 IDirect3DSurface9_GetDesc(surface, &desc);
1681 ok(desc.Format == D3DFMT_L8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_L8);
1682 IDirect3DTexture9_Release(texture);
1684 hr = D3DXCreateTextureFromFileInMemoryEx(device, png_grayscale, sizeof(png_grayscale),
1685 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT,
1686 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1687 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1688 if (SUCCEEDED(hr))
1690 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1691 IDirect3DSurface9_GetDesc(surface, &desc);
1692 ok(desc.Format == D3DFMT_A8L8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8L8);
1693 IDirect3DTexture9_Release(texture);
1695 hr = D3DXCreateTextureFromFileInMemoryEx(device, png_grayscale, sizeof(png_grayscale),
1696 D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
1697 D3DX_DEFAULT, D3DX_DEFAULT, 0xff000000, NULL, NULL, &texture);
1698 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1699 if (SUCCEEDED(hr))
1701 IDirect3DTexture9_GetSurfaceLevel(texture, 0, &surface);
1702 IDirect3DSurface9_GetDesc(surface, &desc);
1703 ok(desc.Format == D3DFMT_L8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_L8);
1704 IDirect3DTexture9_Release(texture);
1708 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1710 HRESULT hr;
1711 ULONG ref;
1712 DWORD levelcount;
1713 IDirect3DCubeTexture9 *cube_texture;
1714 D3DSURFACE_DESC surface_desc;
1716 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1717 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1719 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1720 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1722 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1723 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1725 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1726 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1728 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1729 if (SUCCEEDED(hr))
1731 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1732 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1734 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1735 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1736 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1737 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1739 ref = IDirect3DCubeTexture9_Release(cube_texture);
1740 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1741 } else skip("Couldn't create cube texture\n");
1744 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1746 HRESULT hr;
1747 IDirect3DCubeTexture9 *cube_texture;
1749 if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
1751 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1752 return;
1755 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT,
1756 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
1757 if (has_cube_dxt5)
1758 ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1759 else
1760 todo_wine ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x.\n", hr, D3D_OK);
1761 if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture);
1764 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1766 HRESULT hr;
1767 ULONG ref;
1768 DWORD levelcount;
1769 IDirect3DVolumeTexture9 *volume_texture;
1770 D3DVOLUME_DESC volume_desc;
1772 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1773 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1775 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1776 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1778 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1779 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1781 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1782 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1784 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1785 if (has_3d_dxt3)
1786 ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1787 else
1788 todo_wine ok(hr == D3D_OK, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1789 if (SUCCEEDED(hr))
1791 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1792 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1794 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1795 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1796 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1797 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1798 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1799 ok(volume_desc.Pool == D3DPOOL_MANAGED, "Got pool %u, expected D3DPOOL_MANAGED\n", volume_desc.Pool);
1801 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1802 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1803 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1804 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1805 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1807 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1808 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1812 /* fills positive x face with red color */
1813 static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data)
1815 memset(out, 0, sizeof(*out));
1816 if (tex_coord->x > 0 && fabs(tex_coord->x) > fabs(tex_coord->y) && fabs(tex_coord->x) > fabs(tex_coord->z))
1817 out->x = 1;
1820 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device)
1822 HRESULT hr;
1823 IDirect3DTexture9 *texture;
1824 IDirect3DCubeTexture9 *cube_texture;
1825 IDirect3DVolumeTexture9 *volume_texture;
1826 ID3DXBuffer *buffer;
1827 void *buffer_pointer;
1828 DWORD buffer_size;
1829 D3DXIMAGE_INFO info;
1830 D3DXIMAGE_FILEFORMAT file_format;
1832 /* textures */
1833 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
1834 if (FAILED(hr))
1836 skip("Failed to create texture\n");
1837 return;
1840 for (file_format = D3DXIFF_BMP; file_format <= D3DXIFF_JPG; file_format++)
1842 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, (IDirect3DBaseTexture9 *)texture, NULL);
1843 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1844 if (SUCCEEDED(hr))
1846 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1847 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1848 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1849 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1851 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1852 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1853 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1854 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1855 ok(info.ImageFileFormat == file_format, "Got file format %#x, expected %#x\n", info.ImageFileFormat, file_format);
1856 ID3DXBuffer_Release(buffer);
1860 todo_wine {
1861 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)texture, NULL);
1862 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1863 if (SUCCEEDED(hr))
1865 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1866 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1867 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1868 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1870 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1871 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1872 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1873 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1874 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1875 ID3DXBuffer_Release(buffer);
1879 IDirect3DTexture9_Release(texture);
1881 /* cube textures */
1882 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &cube_texture, NULL);
1883 if (FAILED(hr))
1885 skip("Failed to create cube texture\n");
1886 return;
1889 hr = D3DXFillCubeTexture(cube_texture, fill_cube_positive_x, NULL);
1890 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1892 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1893 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1894 if (SUCCEEDED(hr))
1896 IDirect3DSurface9 *surface;
1898 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1899 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1900 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1901 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1903 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1904 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1905 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1906 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1907 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1909 /* positive x face is saved */
1910 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1911 if (SUCCEEDED(hr))
1913 D3DLOCKED_RECT locked_rect;
1915 hr = D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, buffer_pointer, buffer_size, NULL, D3DX_FILTER_NONE, 0, NULL);
1916 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1918 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1919 if (SUCCEEDED(hr))
1921 DWORD *color = locked_rect.pBits;
1922 ok(*color == 0x00ff0000, "Got color %#x, expected %#x\n", *color, 0x00ff0000);
1923 IDirect3DSurface9_UnlockRect(surface);
1926 IDirect3DSurface9_Release(surface);
1927 } else skip("Failed to create surface\n");
1929 ID3DXBuffer_Release(buffer);
1932 todo_wine {
1933 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1934 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1935 if (SUCCEEDED(hr))
1937 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1938 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1939 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1940 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1942 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1943 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1944 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1945 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
1946 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1947 ID3DXBuffer_Release(buffer);
1951 IDirect3DCubeTexture9_Release(cube_texture);
1953 /* volume textures */
1954 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &volume_texture, NULL);
1955 if (FAILED(hr))
1957 skip("Failed to create volume texture\n");
1958 return;
1961 todo_wine {
1962 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1963 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1964 if (SUCCEEDED(hr))
1966 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1967 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1968 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1969 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1971 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1972 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1973 ok(info.Depth == 1, "Got depth %u, expected %u\n", info.Depth, 1);
1974 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1975 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1976 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1977 ID3DXBuffer_Release(buffer);
1980 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1981 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1982 if (SUCCEEDED(hr))
1984 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1985 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1986 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1987 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1989 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1990 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1991 ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256);
1992 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1993 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
1994 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1995 ID3DXBuffer_Release(buffer);
1999 IDirect3DVolumeTexture9_Release(volume_texture);
2002 START_TEST(texture)
2004 HWND wnd;
2005 IDirect3D9 *d3d;
2006 IDirect3DDevice9 *device;
2007 D3DPRESENT_PARAMETERS d3dpp;
2008 HRESULT hr;
2010 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
2011 640, 480, NULL, NULL, NULL, NULL)))
2013 skip("Couldn't create application window\n");
2014 return;
2016 d3d = Direct3DCreate9(D3D_SDK_VERSION);
2017 if (!d3d) {
2018 skip("Couldn't create IDirect3D9 object\n");
2019 DestroyWindow(wnd);
2020 return;
2023 ZeroMemory(&d3dpp, sizeof(d3dpp));
2024 d3dpp.Windowed = TRUE;
2025 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
2026 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
2027 if (FAILED(hr)) {
2028 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
2029 IDirect3D9_Release(d3d);
2030 DestroyWindow(wnd);
2031 return;
2034 /* Check whether DXTn textures are supported. */
2035 has_2d_dxt3 = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
2036 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT3));
2037 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
2038 D3DFMT_X8R8G8B8, 0, D3DRTYPE_TEXTURE, D3DFMT_DXT5);
2039 has_2d_dxt5 = SUCCEEDED(hr);
2040 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
2041 D3DFMT_X8R8G8B8, 0, D3DRTYPE_CUBETEXTURE, D3DFMT_DXT5);
2042 has_cube_dxt5 = SUCCEEDED(hr);
2043 has_3d_dxt3 = SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
2044 D3DFMT_X8R8G8B8, 0, D3DRTYPE_VOLUMETEXTURE, D3DFMT_DXT3));
2046 test_D3DXCheckTextureRequirements(device);
2047 test_D3DXCheckCubeTextureRequirements(device);
2048 test_D3DXCheckVolumeTextureRequirements(device);
2049 test_D3DXCreateTexture(device);
2050 test_D3DXFilterTexture(device);
2051 test_D3DXFillTexture(device);
2052 test_D3DXFillCubeTexture(device);
2053 test_D3DXFillVolumeTexture(device);
2054 test_D3DXCreateTextureFromFileInMemory(device);
2055 test_D3DXCreateTextureFromFileInMemoryEx(device);
2056 test_D3DXCreateCubeTextureFromFileInMemory(device);
2057 test_D3DXCreateCubeTextureFromFileInMemoryEx(device);
2058 test_D3DXCreateVolumeTextureFromFileInMemory(device);
2059 test_D3DXSaveTextureToFileInMemory(device);
2061 IDirect3DDevice9_Release(device);
2062 IDirect3D9_Release(d3d);
2063 DestroyWindow(wnd);