d3dx9/tests: Add tests for D3DXSaveTextureToFileInMemory.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob6cee06507e473026540b9745f2d4d8f4261256cb
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 /* 2x2 16-bit dds, no mipmaps */
29 static const unsigned char dds_16bit[] = {
30 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x02,0x00,0x00,0x00,
31 0x02,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
34 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
35 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,
36 0xe0,0x03,0x00,0x00,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,
37 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
38 0xff,0x7f,0xff,0x7f,0xff,0x7f,0xff,0x7f
41 /* 2x2 24-bit dds, 2 mipmaps */
42 static const unsigned char dds_24bit[] = {
43 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x0a,0x00,0x02,0x00,0x00,0x00,
44 0x02,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,
45 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
46 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
47 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
48 0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0xff,0x00,
49 0x00,0xff,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
50 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
51 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
54 /* 4x4 cube map dds */
55 static const unsigned char dds_cube_map[] = {
56 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x08,0x00,0x04,0x00,0x00,0x00,
57 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
59 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
60 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
61 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
62 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x00,0x00,
63 0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
64 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
65 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
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,0x50,
68 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
69 0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50
72 /* 4x4x2 volume map dds, 2 mipmaps */
73 static const unsigned char dds_volume_map[] = {
74 0x44,0x44,0x53,0x20,0x7c,0x00,0x00,0x00,0x07,0x10,0x8a,0x00,0x04,0x00,0x00,0x00,
75 0x04,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x03,0x00,0x00,0x00,
76 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
78 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
79 0x04,0x00,0x00,0x00,0x44,0x58,0x54,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x40,0x00,
81 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
82 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
83 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xef,0x87,0x0f,0x78,0x05,0x05,0x50,0x50,
84 0xff,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x2f,0x7e,0xcf,0x79,0x01,0x54,0x5c,0x5c,
85 0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x84,0xef,0x7b,0xaa,0xab,0xab,0xab
88 static BOOL is_autogenmipmap_supported(IDirect3DDevice9 *device, D3DRESOURCETYPE resource_type)
90 HRESULT hr;
91 D3DCAPS9 caps;
92 IDirect3D9 *d3d9;
93 D3DDISPLAYMODE mode;
94 D3DDEVICE_CREATION_PARAMETERS params;
96 IDirect3DDevice9_GetDeviceCaps(device, &caps);
97 IDirect3DDevice9_GetDirect3D(device, &d3d9);
98 IDirect3DDevice9_GetCreationParameters(device, &params);
99 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
101 if (!(caps.Caps2 & D3DCAPS2_CANAUTOGENMIPMAP))
102 return FALSE;
104 hr = IDirect3D9_CheckDeviceFormat(d3d9, params.AdapterOrdinal, params.DeviceType,
105 mode.Format, D3DUSAGE_AUTOGENMIPMAP, resource_type, D3DFMT_A8R8G8B8);
107 IDirect3D9_Release(d3d9);
108 return SUCCEEDED(hr);
111 static void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
113 UINT width, height, mipmaps;
114 D3DFORMAT format, expected;
115 D3DCAPS9 caps;
116 HRESULT hr;
117 IDirect3D9 *d3d;
118 D3DDEVICE_CREATION_PARAMETERS params;
119 D3DDISPLAYMODE mode;
121 IDirect3DDevice9_GetDeviceCaps(device, &caps);
123 /* general tests */
124 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
125 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
127 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
128 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
130 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
131 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
133 /* width & height */
134 width = height = D3DX_DEFAULT;
135 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
136 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
137 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
138 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
140 width = D3DX_DEFAULT;
141 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
142 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
143 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
145 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
146 skip("Hardware only supports pow2 textures\n");
147 else
149 width = 62;
150 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
151 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
152 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
154 width = D3DX_DEFAULT; height = 63;
155 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
156 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
157 ok(width == height, "Returned width %d, expected %d\n", width, height);
158 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
161 width = D3DX_DEFAULT; height = 0;
162 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
163 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
164 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
165 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
167 width = 0; height = 0;
168 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
169 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
170 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
171 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
173 width = 0;
174 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
175 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
176 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
178 width = 0xFFFFFFFE;
179 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
180 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
181 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
183 width = caps.MaxTextureWidth-1;
184 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
185 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
186 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
187 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
188 else
189 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
191 /* mipmaps */
192 width = 64; height = 63;
193 mipmaps = 9;
194 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
195 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
196 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
198 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
200 width = 284; height = 137;
201 mipmaps = 20;
202 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
203 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
204 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
206 width = height = 63;
207 mipmaps = 9;
208 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
209 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
210 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
212 else
213 skip("Skipping some tests, npot2 textures unsupported\n");
215 mipmaps = 20;
216 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
217 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
218 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
220 mipmaps = 0;
221 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
222 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
223 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
225 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
226 if (is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
228 mipmaps = 0;
229 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
230 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
231 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
232 mipmaps = 1;
233 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
234 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
235 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
236 mipmaps = 2;
237 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
238 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
239 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
240 mipmaps = 6;
241 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
242 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
243 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
245 else
246 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
248 /* usage */
249 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
250 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
251 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
252 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
253 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
254 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
255 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
256 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
257 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
258 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
260 /* format */
261 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
262 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
264 format = D3DFMT_UNKNOWN;
265 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
266 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
267 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
269 format = D3DX_DEFAULT;
270 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
271 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
272 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
274 format = D3DFMT_R8G8B8;
275 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
276 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
277 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
279 IDirect3DDevice9_GetDirect3D(device, &d3d);
280 IDirect3DDevice9_GetCreationParameters(device, &params);
281 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
283 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
284 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
285 expected = D3DFMT_R3G3B2;
286 else
288 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
289 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
290 expected = D3DFMT_X4R4G4B4;
291 else
292 expected = D3DFMT_X1R5G5B5;
295 format = D3DFMT_R3G3B2;
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 == expected, "Returned format %u, expected %u\n", format, expected);
300 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
301 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
302 expected = D3DFMT_A8R3G3B2;
303 else
304 expected = D3DFMT_A8R8G8B8;
306 format = D3DFMT_A8R3G3B2;
307 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
308 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
309 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
311 IDirect3D9_Release(d3d);
314 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
316 UINT size, mipmaps, expected;
317 D3DFORMAT format;
318 D3DCAPS9 caps;
319 HRESULT hr;
321 IDirect3DDevice9_GetDeviceCaps(device, &caps);
323 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
325 skip("No cube textures support\n");
326 return;
329 /* general tests */
330 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
331 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
333 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
334 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
336 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
337 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
339 /* size */
340 size = D3DX_DEFAULT;
341 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
342 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
343 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
345 /* mipmaps */
346 size = 64;
347 mipmaps = 9;
348 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
349 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
350 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
352 size = 284;
353 mipmaps = 20;
354 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
355 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
356 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
357 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
359 size = 63;
360 mipmaps = 9;
361 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
362 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
363 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
364 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
366 mipmaps = 0;
367 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
368 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
369 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
371 if (is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
373 mipmaps = 3;
374 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
375 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
376 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
378 else
379 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
381 /* usage */
382 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
383 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
384 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
385 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
386 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
387 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
388 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
389 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
390 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
391 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
393 /* format */
394 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
395 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
397 format = D3DFMT_UNKNOWN;
398 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
399 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
400 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
402 format = D3DX_DEFAULT;
403 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
404 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
405 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
407 format = D3DFMT_R8G8B8;
408 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
409 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
410 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
413 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
415 UINT width, height, depth, mipmaps, expected;
416 D3DFORMAT format;
417 D3DCAPS9 caps;
418 HRESULT hr;
420 IDirect3DDevice9_GetDeviceCaps(device, &caps);
422 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
424 skip("No volume textures support\n");
425 return;
428 /* general tests */
429 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
430 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
432 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
433 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
435 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
436 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
438 /* width, height, depth */
439 width = height = depth = D3DX_DEFAULT;
440 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
441 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
442 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
443 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
444 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
446 width = D3DX_DEFAULT;
447 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
448 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
449 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
451 width = D3DX_DEFAULT; height = 0; depth = 0;
452 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
453 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
454 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
455 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
456 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
458 width = 0; height = 0; depth = 0;
459 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
460 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
461 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
462 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
463 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
465 width = 0;
466 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
467 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
468 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
470 width = 0xFFFFFFFE;
471 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
472 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
473 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
475 /* format */
476 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
477 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
479 format = D3DFMT_UNKNOWN;
480 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
481 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
482 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
484 format = D3DX_DEFAULT;
485 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
486 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
487 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
489 format = D3DFMT_R8G8B8;
490 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
491 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
492 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
494 /* mipmaps */
495 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
497 skip("No volume textures mipmapping support\n");
498 return;
501 width = height = depth = 64;
502 mipmaps = 9;
503 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
504 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
505 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
507 width = 284;
508 height = 143;
509 depth = 55;
510 mipmaps = 20;
511 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
512 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
513 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
514 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
516 mipmaps = 0;
517 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
518 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
519 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
521 if (!is_autogenmipmap_supported(device, D3DRTYPE_VOLUMETEXTURE))
523 skip("No D3DUSAGE_AUTOGENMIPMAP support for volume textures\n");
524 return;
527 /* mipmaps when D3DUSAGE_AUTOGENMIPMAP is set */
528 mipmaps = 0;
529 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
530 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
531 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
532 mipmaps = 1;
533 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
534 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
535 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
536 mipmaps = 3;
537 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL,NULL, &mipmaps, D3DUSAGE_AUTOGENMIPMAP, NULL, D3DPOOL_DEFAULT);
538 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
539 ok(mipmaps == 0, "Returned mipmaps %d, expected %d\n", mipmaps, 0);
542 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
544 IDirect3DTexture9 *texture;
545 D3DSURFACE_DESC desc;
546 D3DCAPS9 caps;
547 UINT mipmaps;
548 HRESULT hr;
550 IDirect3DDevice9_GetDeviceCaps(device, &caps);
552 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, D3DPOOL_DEFAULT, NULL);
553 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
555 /* width and height tests */
557 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
558 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
560 if (texture)
562 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
563 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
564 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
566 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
567 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
569 IDirect3DTexture9_Release(texture);
573 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
574 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
576 if (texture)
578 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
579 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
580 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
582 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
583 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
585 IDirect3DTexture9_Release(texture);
589 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
590 skip("Hardware only supports pow2 textures\n");
591 else
593 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
594 ok((hr == D3D_OK) ||
595 /* may not work with conditional NPOT */
596 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
597 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
599 if (texture)
601 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
602 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
603 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
605 /* Conditional NPOT may create a texture with different dimensions, so allow those
606 situations instead of returning a fail */
608 ok(desc.Width == 63 ||
609 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
610 "Returned width %d, expected %d\n", desc.Width, 63);
612 ok(desc.Height == 63 ||
613 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
614 "Returned height %d, expected %d\n", desc.Height, 63);
616 IDirect3DTexture9_Release(texture);
620 /* mipmaps */
622 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
623 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
625 if (texture)
627 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
628 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
630 IDirect3DTexture9_Release(texture);
634 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
635 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
637 if (texture)
639 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
640 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
642 IDirect3DTexture9_Release(texture);
646 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
647 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
649 if (texture)
651 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
652 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
654 IDirect3DTexture9_Release(texture);
658 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
659 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
661 if (texture)
663 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
664 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
666 IDirect3DTexture9_Release(texture);
669 /* usage */
671 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
672 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
673 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
674 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
675 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
676 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
677 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
678 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
679 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
680 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
682 /* format */
684 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
685 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
687 if (texture)
689 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
690 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
691 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
693 IDirect3DTexture9_Release(texture);
697 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
698 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
700 if (texture)
702 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
703 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
704 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
706 IDirect3DTexture9_Release(texture);
709 /* D3DXCreateTextureFromResource */
710 todo_wine {
711 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
712 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
713 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
715 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
716 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
717 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
719 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
720 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
722 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
723 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
725 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
726 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
728 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
729 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
732 /* D3DXCreateTextureFromResourceEx */
733 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);
734 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
735 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
737 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);
738 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
740 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);
741 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
743 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
744 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
746 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);
747 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
750 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
752 IDirect3DTexture9 *tex;
753 IDirect3DCubeTexture9 *cubetex;
754 HRESULT hr;
756 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
758 if (SUCCEEDED(hr))
760 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
761 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
763 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
764 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
766 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
767 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
769 IDirect3DTexture9_Release(tex);
771 else
772 skip("Failed to create texture\n");
774 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
775 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
777 /* Test different pools */
778 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
780 if (SUCCEEDED(hr))
782 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
783 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
784 IDirect3DTexture9_Release(tex);
786 else
787 skip("Failed to create texture\n");
789 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
791 if (SUCCEEDED(hr))
793 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
794 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
795 IDirect3DTexture9_Release(tex);
797 else
798 skip("Failed to create texture\n");
800 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
801 if (SUCCEEDED(hr))
803 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
804 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
805 IDirect3DTexture9_Release(tex);
807 else
808 skip("Failed to create texture\n");
810 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
811 if (SUCCEEDED(hr))
813 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_POINT);
814 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
815 IDirect3DTexture9_Release(tex);
817 else
818 skip("Failed to create texture\n");
820 /* Cube texture test */
821 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
823 if (SUCCEEDED(hr))
825 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
826 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
828 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
829 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
831 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
832 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
833 IDirect3DCubeTexture9_Release(cubetex);
835 else
836 skip("Failed to create texture\n");
838 /* Test textures with D3DUSAGE_AUTOGENMIPMAP usage */
839 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
841 skip("No D3DUSAGE_AUTOGENMIPMAP supported for textures\n");
842 return;
845 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
846 if (SUCCEEDED(hr))
848 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
849 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
850 IDirect3DTexture9_Release(tex);
852 else
853 skip("Failed to create texture\n");
855 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 1, D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex, NULL);
856 if (SUCCEEDED(hr))
858 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
859 ok(hr == D3D_OK, "D3dXFilteTexture returned %#x, expected %#x\n", hr, D3D_OK);
860 IDirect3DTexture9_Release(tex);
862 else
863 skip("Failed to create texture\n");
866 static BOOL color_match(const DWORD *value, const DWORD *expected)
868 int i;
870 for (i = 0; i < 4; i++)
872 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
873 if (diff > 1) return FALSE;
875 return TRUE;
878 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
879 const D3DXVECTOR2 *texelsize, void *data)
881 value->x = texcoord->x;
882 value->y = texcoord->y;
883 value->z = texelsize->x;
884 value->w = 1.0f;
887 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
889 IDirect3DTexture9 *tex;
890 HRESULT hr;
891 D3DLOCKED_RECT lock_rect;
892 DWORD x, y, m;
893 DWORD v[4], e[4];
894 DWORD value, expected, size, pitch;
896 size = 4;
897 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
898 D3DPOOL_MANAGED, &tex, NULL);
900 if (SUCCEEDED(hr))
902 hr = D3DXFillTexture(tex, fillfunc, NULL);
903 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
905 for (m = 0; m < 3; m++)
907 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
908 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
909 if (SUCCEEDED(hr))
911 pitch = lock_rect.Pitch / sizeof(DWORD);
912 for (y = 0; y < size; y++)
914 for (x = 0; x < size; x++)
916 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
917 v[0] = (value >> 24) & 0xff;
918 v[1] = (value >> 16) & 0xff;
919 v[2] = (value >> 8) & 0xff;
920 v[3] = value & 0xff;
922 e[0] = 0xff;
923 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
924 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
925 e[3] = 255.0f / size + 0.5f;
926 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
928 ok(color_match(v, e),
929 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
930 x, y, value, expected);
933 IDirect3DTexture9_UnlockRect(tex, m);
935 size >>= 1;
938 else
939 skip("Failed to create texture\n");
941 IDirect3DTexture9_Release(tex);
943 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
944 D3DPOOL_MANAGED, &tex, NULL);
946 if (SUCCEEDED(hr))
948 hr = D3DXFillTexture(tex, fillfunc, NULL);
949 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
951 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
952 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
953 if (SUCCEEDED(hr))
955 pitch = lock_rect.Pitch / sizeof(WORD);
956 for (y = 0; y < 4; y++)
958 for (x = 0; x < 4; x++)
960 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
961 v[0] = value >> 15;
962 v[1] = value >> 10 & 0x1f;
963 v[2] = value >> 5 & 0x1f;
964 v[3] = value & 0x1f;
966 e[0] = 1;
967 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
968 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
969 e[3] = 8;
970 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
972 ok(color_match(v, e),
973 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
974 x, y, value, expected);
977 IDirect3DTexture9_UnlockRect(tex, 0);
980 else
981 skip("Failed to create texture\n");
983 IDirect3DTexture9_Release(tex);
986 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
987 const D3DXVECTOR3 *texelsize, void *data)
989 value->x = (texcoord->x + 1.0f) / 2.0f;
990 value->y = (texcoord->y + 1.0f) / 2.0f;
991 value->z = (texcoord->z + 1.0f) / 2.0f;
992 value->w = texelsize->x;
995 enum cube_coord
997 XCOORD = 0,
998 XCOORDINV = 1,
999 YCOORD = 2,
1000 YCOORDINV = 3,
1001 ZERO = 4,
1002 ONE = 5
1005 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
1007 switch (coord)
1009 case XCOORD:
1010 return x + 0.5f;
1011 case XCOORDINV:
1012 return size - x - 0.5f;
1013 case YCOORD:
1014 return y + 0.5f;
1015 case YCOORDINV:
1016 return size - y - 0.5f;
1017 case ZERO:
1018 return 0.0f;
1019 case ONE:
1020 return size;
1021 default:
1022 trace("Unexpected coordinate value\n");
1023 return 0.0f;
1027 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
1029 IDirect3DCubeTexture9 *tex;
1030 HRESULT hr;
1031 D3DLOCKED_RECT lock_rect;
1032 DWORD x, y, f, m;
1033 DWORD v[4], e[4];
1034 DWORD value, expected, size, pitch;
1035 enum cube_coord coordmap[6][3] =
1037 {ONE, YCOORDINV, XCOORDINV},
1038 {ZERO, YCOORDINV, XCOORD},
1039 {XCOORD, ONE, YCOORD},
1040 {XCOORD, ZERO, YCOORDINV},
1041 {XCOORD, YCOORDINV, ONE},
1042 {XCOORDINV, YCOORDINV, ZERO}
1045 size = 4;
1046 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1047 D3DPOOL_MANAGED, &tex, NULL);
1049 if (SUCCEEDED(hr))
1051 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1052 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1054 for (m = 0; m < 3; m++)
1056 for (f = 0; f < 6; f++)
1058 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1059 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1060 if (SUCCEEDED(hr))
1062 pitch = lock_rect.Pitch / sizeof(DWORD);
1063 for (y = 0; y < size; y++)
1065 for (x = 0; x < size; x++)
1067 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1068 v[0] = (value >> 24) & 0xff;
1069 v[1] = (value >> 16) & 0xff;
1070 v[2] = (value >> 8) & 0xff;
1071 v[3] = value & 0xff;
1073 e[0] = (f == 0) || (f == 1) ?
1074 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1075 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1076 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1077 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1078 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1080 ok(color_match(v, e),
1081 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1082 f, x, y, value, expected);
1085 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1088 size >>= 1;
1091 else
1092 skip("Failed to create texture\n");
1094 IDirect3DCubeTexture9_Release(tex);
1096 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1097 D3DPOOL_MANAGED, &tex, NULL);
1099 if (SUCCEEDED(hr))
1101 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1102 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1103 for (f = 0; f < 6; f++)
1105 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
1106 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1107 if (SUCCEEDED(hr))
1109 pitch = lock_rect.Pitch / sizeof(WORD);
1110 for (y = 0; y < 4; y++)
1112 for (x = 0; x < 4; x++)
1114 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1115 v[0] = value >> 15;
1116 v[1] = value >> 10 & 0x1f;
1117 v[2] = value >> 5 & 0x1f;
1118 v[3] = value & 0x1f;
1120 e[0] = (f == 0) || (f == 1) ?
1121 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1122 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1123 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1124 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1125 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1127 ok(color_match(v, e),
1128 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1129 f, x, y, value, expected);
1132 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1136 else
1137 skip("Failed to create texture\n");
1139 IDirect3DCubeTexture9_Release(tex);
1142 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1143 const D3DXVECTOR3 *texelsize, void *data)
1145 value->x = texcoord->x;
1146 value->y = texcoord->y;
1147 value->z = texcoord->z;
1148 value->w = texelsize->x;
1151 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1153 IDirect3DVolumeTexture9 *tex;
1154 HRESULT hr;
1155 D3DLOCKED_BOX lock_box;
1156 DWORD x, y, z, m;
1157 DWORD v[4], e[4];
1158 DWORD value, expected, size, row_pitch, slice_pitch;
1160 size = 4;
1161 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1162 D3DPOOL_MANAGED, &tex, NULL);
1164 if (SUCCEEDED(hr))
1166 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1167 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1169 for (m = 0; m < 3; m++)
1171 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1172 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1173 if (SUCCEEDED(hr))
1175 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1176 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1177 for (z = 0; z < size; z++)
1179 for (y = 0; y < size; y++)
1181 for (x = 0; x < size; x++)
1183 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1184 v[0] = (value >> 24) & 0xff;
1185 v[1] = (value >> 16) & 0xff;
1186 v[2] = (value >> 8) & 0xff;
1187 v[3] = value & 0xff;
1189 e[0] = 255.0f / size + 0.5f;
1190 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1191 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1192 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1193 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1195 ok(color_match(v, e),
1196 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1197 x, y, z, value, expected);
1201 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1203 size >>= 1;
1206 else
1207 skip("Failed to create texture\n");
1209 IDirect3DVolumeTexture9_Release(tex);
1211 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1212 D3DPOOL_MANAGED, &tex, NULL);
1214 if (SUCCEEDED(hr))
1216 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1217 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1218 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1219 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1220 if (SUCCEEDED(hr))
1222 row_pitch = lock_box.RowPitch / sizeof(WORD);
1223 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1224 for (z = 0; z < 4; z++)
1226 for (y = 0; y < 4; y++)
1228 for (x = 0; x < 4; x++)
1230 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1231 v[0] = value >> 15;
1232 v[1] = value >> 10 & 0x1f;
1233 v[2] = value >> 5 & 0x1f;
1234 v[3] = value & 0x1f;
1236 e[0] = 1;
1237 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1238 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1239 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1240 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1242 ok(color_match(v, e),
1243 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1244 x, y, z, value, expected);
1248 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1251 else
1252 skip("Failed to create texture\n");
1254 IDirect3DVolumeTexture9_Release(tex);
1257 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1259 HRESULT hr;
1260 IDirect3DTexture9 *texture;
1262 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1263 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1264 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1266 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1267 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1268 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1270 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1271 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1274 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1276 HRESULT hr;
1277 IDirect3DTexture9 *texture;
1279 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1280 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1281 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1282 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1284 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1285 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1286 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1287 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1289 if (!is_autogenmipmap_supported(device, D3DRTYPE_TEXTURE))
1291 skip("No D3DUSAGE_AUTOGENMIPMAP support for textures\n");
1292 return;
1295 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1296 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1297 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1298 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1301 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1303 HRESULT hr;
1304 ULONG ref;
1305 DWORD levelcount;
1306 IDirect3DCubeTexture9 *cube_texture;
1307 D3DSURFACE_DESC surface_desc;
1309 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1310 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1312 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1313 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1315 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1316 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1318 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1319 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1321 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1322 if (SUCCEEDED(hr))
1324 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1325 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1327 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1328 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1329 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1330 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1332 ref = IDirect3DCubeTexture9_Release(cube_texture);
1333 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1334 } else skip("Couldn't create cube texture\n");
1337 static void test_D3DXCreateCubeTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1339 HRESULT hr;
1340 IDirect3DCubeTexture9 *cube_texture;
1342 if (!is_autogenmipmap_supported(device, D3DRTYPE_CUBETEXTURE))
1344 skip("No D3DUSAGE_AUTOGENMIPMAP support for cube textures\n");
1345 return;
1348 hr = D3DXCreateCubeTextureFromFileInMemoryEx(device, dds_cube_map, sizeof(dds_cube_map), D3DX_DEFAULT, D3DX_DEFAULT,
1349 D3DUSAGE_DYNAMIC | D3DUSAGE_AUTOGENMIPMAP, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &cube_texture);
1350 ok(hr == D3D_OK, "D3DXCreateCubeTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1351 if (SUCCEEDED(hr)) IDirect3DCubeTexture9_Release(cube_texture);
1354 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1356 HRESULT hr;
1357 ULONG ref;
1358 DWORD levelcount;
1359 IDirect3DVolumeTexture9 *volume_texture;
1360 D3DVOLUME_DESC volume_desc;
1362 todo_wine {
1363 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1364 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1366 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1367 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1369 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1370 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1372 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1373 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1375 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1376 if (SUCCEEDED(hr))
1378 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1379 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1381 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1382 ok(hr == D3D_OK, "GetLevelDesc returend %#x, expected %#x\n", hr, D3D_OK);
1383 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1384 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1385 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1387 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1388 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1389 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1390 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1391 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1393 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1394 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1399 /* fills positive x face with red color */
1400 static void WINAPI fill_cube_positive_x(D3DXVECTOR4 *out, const D3DXVECTOR3 *tex_coord, const D3DXVECTOR3 *texel_size, void *data)
1402 memset(out, 0, sizeof(*out));
1403 if (tex_coord->x > 0 && fabs(tex_coord->x) > fabs(tex_coord->y) && fabs(tex_coord->x) > fabs(tex_coord->z))
1404 out->x = 1;
1407 static void test_D3DXSaveTextureToFileInMemory(IDirect3DDevice9 *device)
1409 HRESULT hr;
1410 IDirect3DTexture9 *texture;
1411 IDirect3DCubeTexture9 *cube_texture;
1412 IDirect3DVolumeTexture9 *volume_texture;
1413 ID3DXBuffer *buffer;
1414 void *buffer_pointer;
1415 DWORD buffer_size;
1416 D3DXIMAGE_INFO info;
1417 D3DXIMAGE_FILEFORMAT file_format;
1419 /* textures */
1420 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &texture, NULL);
1421 if (FAILED(hr))
1423 skip("Failed to create texture\n");
1424 return;
1427 for (file_format = D3DXIFF_BMP; file_format <= D3DXIFF_JPG; file_format++)
1429 hr = D3DXSaveTextureToFileInMemory(&buffer, file_format, (IDirect3DBaseTexture9 *)texture, NULL);
1430 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1431 if (SUCCEEDED(hr))
1433 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1434 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1435 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1436 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1438 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1439 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1440 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1441 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1442 ok(info.ImageFileFormat == file_format, "Got file format %#x, expected %#x\n", info.ImageFileFormat, file_format);
1443 ID3DXBuffer_Release(buffer);
1447 todo_wine {
1448 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)texture, NULL);
1449 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1450 if (SUCCEEDED(hr))
1452 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1453 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1454 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1455 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1457 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1458 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1459 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1460 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1461 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1462 ID3DXBuffer_Release(buffer);
1466 IDirect3DTexture9_Release(texture);
1468 /* cube textures */
1469 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &cube_texture, NULL);
1470 if (FAILED(hr))
1472 skip("Failed to create cube texture\n");
1473 return;
1476 hr = D3DXFillCubeTexture(cube_texture, fill_cube_positive_x, NULL);
1477 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1479 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1480 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1481 if (SUCCEEDED(hr))
1483 IDirect3DSurface9 *surface;
1485 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1486 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1487 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1488 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1490 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1491 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1492 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1493 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1494 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1496 /* positive x face is saved */
1497 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_X8R8G8B8, D3DPOOL_SYSTEMMEM, &surface, NULL);
1498 if (SUCCEEDED(hr))
1500 D3DLOCKED_RECT locked_rect;
1502 hr = D3DXLoadSurfaceFromFileInMemory(surface, NULL, NULL, buffer_pointer, buffer_size, NULL, D3DX_FILTER_NONE, 0, NULL);
1503 ok(hr == D3D_OK, "D3DXLoadSurfaceFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1505 hr = IDirect3DSurface9_LockRect(surface, &locked_rect, NULL, D3DLOCK_READONLY);
1506 if (SUCCEEDED(hr))
1508 DWORD *color = locked_rect.pBits;
1509 ok(*color == 0x00ff0000, "Got color %#x, expected %#x\n", *color, 0x00ff0000);
1510 IDirect3DSurface9_UnlockRect(surface);
1513 IDirect3DSurface9_Release(surface);
1514 } else skip("Failed to create surface\n");
1516 ID3DXBuffer_Release(buffer);
1519 todo_wine {
1520 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)cube_texture, NULL);
1521 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1522 if (SUCCEEDED(hr))
1524 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1525 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1526 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1527 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1529 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1530 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1531 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1532 ok(info.ResourceType == D3DRTYPE_CUBETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_CUBETEXTURE);
1533 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1534 ID3DXBuffer_Release(buffer);
1538 IDirect3DCubeTexture9_Release(cube_texture);
1540 /* volume textures */
1541 hr = IDirect3DDevice9_CreateVolumeTexture(device, 256, 256, 256, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &volume_texture, NULL);
1542 if (FAILED(hr))
1544 skip("Failed to create volume texture\n");
1545 return;
1548 todo_wine {
1549 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_BMP, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1550 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1551 if (SUCCEEDED(hr))
1553 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1554 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1555 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1556 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1558 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1559 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1560 ok(info.Depth == 1, "Got depth %u, expected %u\n", info.Depth, 1);
1561 ok(info.MipLevels == 1, "Got miplevels %u, expected %u\n", info.MipLevels, 1);
1562 ok(info.ResourceType == D3DRTYPE_TEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_TEXTURE);
1563 ok(info.ImageFileFormat == D3DXIFF_BMP, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_BMP);
1564 ID3DXBuffer_Release(buffer);
1567 hr = D3DXSaveTextureToFileInMemory(&buffer, D3DXIFF_DDS, (IDirect3DBaseTexture9 *)volume_texture, NULL);
1568 ok(hr == D3D_OK, "D3DXSaveTextureToFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1569 if (SUCCEEDED(hr))
1571 buffer_pointer = ID3DXBuffer_GetBufferPointer(buffer);
1572 buffer_size = ID3DXBuffer_GetBufferSize(buffer);
1573 hr = D3DXGetImageInfoFromFileInMemory(buffer_pointer, buffer_size, &info);
1574 ok(hr == D3D_OK, "D3DXGetImageInfoFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1576 ok(info.Width == 256, "Got width %u, expected %u\n", info.Width, 256);
1577 ok(info.Height == 256, "Got height %u, expected %u\n", info.Height, 256);
1578 ok(info.Depth == 256, "Got depth %u, expected %u\n", info.Depth, 256);
1579 ok(info.MipLevels == 9, "Got miplevels %u, expected %u\n", info.MipLevels, 9);
1580 ok(info.ResourceType == D3DRTYPE_VOLUMETEXTURE, "Got resource type %#x, expected %#x\n", info.ResourceType, D3DRTYPE_VOLUMETEXTURE);
1581 ok(info.ImageFileFormat == D3DXIFF_DDS, "Got file format %#x, expected %#x\n", info.ImageFileFormat, D3DXIFF_DDS);
1582 ID3DXBuffer_Release(buffer);
1586 IDirect3DVolumeTexture9_Release(volume_texture);
1589 START_TEST(texture)
1591 HWND wnd;
1592 IDirect3D9 *d3d;
1593 IDirect3DDevice9 *device;
1594 D3DPRESENT_PARAMETERS d3dpp;
1595 HRESULT hr;
1597 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1598 if (!wnd) {
1599 skip("Couldn't create application window\n");
1600 return;
1602 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1603 if (!d3d) {
1604 skip("Couldn't create IDirect3D9 object\n");
1605 DestroyWindow(wnd);
1606 return;
1609 ZeroMemory(&d3dpp, sizeof(d3dpp));
1610 d3dpp.Windowed = TRUE;
1611 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1612 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1613 if (FAILED(hr)) {
1614 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1615 IDirect3D9_Release(d3d);
1616 DestroyWindow(wnd);
1617 return;
1620 test_D3DXCheckTextureRequirements(device);
1621 test_D3DXCheckCubeTextureRequirements(device);
1622 test_D3DXCheckVolumeTextureRequirements(device);
1623 test_D3DXCreateTexture(device);
1624 test_D3DXFilterTexture(device);
1625 test_D3DXFillTexture(device);
1626 test_D3DXFillCubeTexture(device);
1627 test_D3DXFillVolumeTexture(device);
1628 test_D3DXCreateTextureFromFileInMemory(device);
1629 test_D3DXCreateTextureFromFileInMemoryEx(device);
1630 test_D3DXCreateCubeTextureFromFileInMemory(device);
1631 test_D3DXCreateCubeTextureFromFileInMemoryEx(device);
1632 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1633 test_D3DXSaveTextureToFileInMemory(device);
1635 IDirect3DDevice9_Release(device);
1636 IDirect3D9_Release(d3d);
1637 DestroyWindow(wnd);