d3dx9: Correctly handle D3DUSAGE_AUTOGENMIPMAP in D3DXCheckVolumeTextureRequirements.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob79e4023507cb5a21127cbc112be60a57a7bf5db1
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 else
770 skip("Failed to create texture\n");
772 IDirect3DTexture9_Release(tex);
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 /* Cube texture test */
801 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
803 if (SUCCEEDED(hr))
805 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
806 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
808 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
809 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
811 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
812 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
813 IDirect3DCubeTexture9_Release(cubetex);
815 else
816 skip("Failed to create texture\n");
819 static BOOL color_match(const DWORD *value, const DWORD *expected)
821 int i;
823 for (i = 0; i < 4; i++)
825 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
826 if (diff > 1) return FALSE;
828 return TRUE;
831 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
832 const D3DXVECTOR2 *texelsize, void *data)
834 value->x = texcoord->x;
835 value->y = texcoord->y;
836 value->z = texelsize->x;
837 value->w = 1.0f;
840 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
842 IDirect3DTexture9 *tex;
843 HRESULT hr;
844 D3DLOCKED_RECT lock_rect;
845 DWORD x, y, m;
846 DWORD v[4], e[4];
847 DWORD value, expected, size, pitch;
849 size = 4;
850 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
851 D3DPOOL_MANAGED, &tex, NULL);
853 if (SUCCEEDED(hr))
855 hr = D3DXFillTexture(tex, fillfunc, NULL);
856 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
858 for (m = 0; m < 3; m++)
860 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
861 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
862 if (SUCCEEDED(hr))
864 pitch = lock_rect.Pitch / sizeof(DWORD);
865 for (y = 0; y < size; y++)
867 for (x = 0; x < size; x++)
869 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
870 v[0] = (value >> 24) & 0xff;
871 v[1] = (value >> 16) & 0xff;
872 v[2] = (value >> 8) & 0xff;
873 v[3] = value & 0xff;
875 e[0] = 0xff;
876 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
877 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
878 e[3] = 255.0f / size + 0.5f;
879 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
881 ok(color_match(v, e),
882 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
883 x, y, value, expected);
886 IDirect3DTexture9_UnlockRect(tex, m);
888 size >>= 1;
891 else
892 skip("Failed to create texture\n");
894 IDirect3DTexture9_Release(tex);
896 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
897 D3DPOOL_MANAGED, &tex, NULL);
899 if (SUCCEEDED(hr))
901 hr = D3DXFillTexture(tex, fillfunc, NULL);
902 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
904 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
905 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
906 if (SUCCEEDED(hr))
908 pitch = lock_rect.Pitch / sizeof(WORD);
909 for (y = 0; y < 4; y++)
911 for (x = 0; x < 4; x++)
913 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
914 v[0] = value >> 15;
915 v[1] = value >> 10 & 0x1f;
916 v[2] = value >> 5 & 0x1f;
917 v[3] = value & 0x1f;
919 e[0] = 1;
920 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
921 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
922 e[3] = 8;
923 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
925 ok(color_match(v, e),
926 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
927 x, y, value, expected);
930 IDirect3DTexture9_UnlockRect(tex, 0);
933 else
934 skip("Failed to create texture\n");
936 IDirect3DTexture9_Release(tex);
939 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
940 const D3DXVECTOR3 *texelsize, void *data)
942 value->x = (texcoord->x + 1.0f) / 2.0f;
943 value->y = (texcoord->y + 1.0f) / 2.0f;
944 value->z = (texcoord->z + 1.0f) / 2.0f;
945 value->w = texelsize->x;
948 enum cube_coord
950 XCOORD = 0,
951 XCOORDINV = 1,
952 YCOORD = 2,
953 YCOORDINV = 3,
954 ZERO = 4,
955 ONE = 5
958 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
960 switch (coord)
962 case XCOORD:
963 return x + 0.5f;
964 case XCOORDINV:
965 return size - x - 0.5f;
966 case YCOORD:
967 return y + 0.5f;
968 case YCOORDINV:
969 return size - y - 0.5f;
970 case ZERO:
971 return 0.0f;
972 case ONE:
973 return size;
974 default:
975 trace("Unexpected coordinate value\n");
976 return 0.0f;
980 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
982 IDirect3DCubeTexture9 *tex;
983 HRESULT hr;
984 D3DLOCKED_RECT lock_rect;
985 DWORD x, y, f, m;
986 DWORD v[4], e[4];
987 DWORD value, expected, size, pitch;
988 enum cube_coord coordmap[6][3] =
990 {ONE, YCOORDINV, XCOORDINV},
991 {ZERO, YCOORDINV, XCOORD},
992 {XCOORD, ONE, YCOORD},
993 {XCOORD, ZERO, YCOORDINV},
994 {XCOORD, YCOORDINV, ONE},
995 {XCOORDINV, YCOORDINV, ZERO}
998 size = 4;
999 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
1000 D3DPOOL_MANAGED, &tex, NULL);
1002 if (SUCCEEDED(hr))
1004 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1005 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1007 for (m = 0; m < 3; m++)
1009 for (f = 0; f < 6; f++)
1011 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
1012 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1013 if (SUCCEEDED(hr))
1015 pitch = lock_rect.Pitch / sizeof(DWORD);
1016 for (y = 0; y < size; y++)
1018 for (x = 0; x < size; x++)
1020 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
1021 v[0] = (value >> 24) & 0xff;
1022 v[1] = (value >> 16) & 0xff;
1023 v[2] = (value >> 8) & 0xff;
1024 v[3] = value & 0xff;
1026 e[0] = (f == 0) || (f == 1) ?
1027 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
1028 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
1029 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
1030 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
1031 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1033 ok(color_match(v, e),
1034 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1035 f, x, y, value, expected);
1038 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
1041 size >>= 1;
1044 else
1045 skip("Failed to create texture\n");
1047 IDirect3DCubeTexture9_Release(tex);
1049 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
1050 D3DPOOL_MANAGED, &tex, NULL);
1052 if (SUCCEEDED(hr))
1054 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
1055 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1056 for (f = 0; f < 6; f++)
1058 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &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(WORD);
1063 for (y = 0; y < 4; y++)
1065 for (x = 0; x < 4; x++)
1067 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
1068 v[0] = value >> 15;
1069 v[1] = value >> 10 & 0x1f;
1070 v[2] = value >> 5 & 0x1f;
1071 v[3] = value & 0x1f;
1073 e[0] = (f == 0) || (f == 1) ?
1074 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
1075 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1076 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1077 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1078 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | 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, 0);
1089 else
1090 skip("Failed to create texture\n");
1092 IDirect3DCubeTexture9_Release(tex);
1095 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1096 const D3DXVECTOR3 *texelsize, void *data)
1098 value->x = texcoord->x;
1099 value->y = texcoord->y;
1100 value->z = texcoord->z;
1101 value->w = texelsize->x;
1104 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1106 IDirect3DVolumeTexture9 *tex;
1107 HRESULT hr;
1108 D3DLOCKED_BOX lock_box;
1109 DWORD x, y, z, m;
1110 DWORD v[4], e[4];
1111 DWORD value, expected, size, row_pitch, slice_pitch;
1113 size = 4;
1114 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1115 D3DPOOL_MANAGED, &tex, NULL);
1117 if (SUCCEEDED(hr))
1119 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1120 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1122 for (m = 0; m < 3; m++)
1124 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1125 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1126 if (SUCCEEDED(hr))
1128 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1129 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1130 for (z = 0; z < size; z++)
1132 for (y = 0; y < size; y++)
1134 for (x = 0; x < size; x++)
1136 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1137 v[0] = (value >> 24) & 0xff;
1138 v[1] = (value >> 16) & 0xff;
1139 v[2] = (value >> 8) & 0xff;
1140 v[3] = value & 0xff;
1142 e[0] = 255.0f / size + 0.5f;
1143 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1144 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1145 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1146 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1148 ok(color_match(v, e),
1149 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1150 x, y, z, value, expected);
1154 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1156 size >>= 1;
1159 else
1160 skip("Failed to create texture\n");
1162 IDirect3DVolumeTexture9_Release(tex);
1164 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1165 D3DPOOL_MANAGED, &tex, NULL);
1167 if (SUCCEEDED(hr))
1169 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1170 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1171 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &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(WORD);
1176 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1177 for (z = 0; z < 4; z++)
1179 for (y = 0; y < 4; y++)
1181 for (x = 0; x < 4; x++)
1183 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1184 v[0] = value >> 15;
1185 v[1] = value >> 10 & 0x1f;
1186 v[2] = value >> 5 & 0x1f;
1187 v[3] = value & 0x1f;
1189 e[0] = 1;
1190 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1191 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1192 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1193 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | 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, 0);
1204 else
1205 skip("Failed to create texture\n");
1207 IDirect3DVolumeTexture9_Release(tex);
1210 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1212 HRESULT hr;
1213 IDirect3DTexture9 *texture;
1215 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1216 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1217 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1219 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1220 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1221 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1223 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1224 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1227 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1229 HRESULT hr;
1230 IDirect3DTexture9 *texture;
1232 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1233 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1234 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1235 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1237 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1238 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1239 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1240 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1243 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1245 HRESULT hr;
1246 ULONG ref;
1247 DWORD levelcount;
1248 IDirect3DCubeTexture9 *cube_texture;
1249 D3DSURFACE_DESC surface_desc;
1251 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1252 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1254 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1255 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1257 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1258 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1260 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1261 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1263 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1264 if (SUCCEEDED(hr))
1266 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1267 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1269 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1270 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1271 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1272 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1274 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 3, &surface_desc);
1275 todo_wine ok(hr == D3DERR_INVALIDCALL, "GetLevelDesc returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1277 ref = IDirect3DCubeTexture9_Release(cube_texture);
1278 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1279 } else skip("Couldn't create cube texture\n");
1282 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1284 HRESULT hr;
1285 ULONG ref;
1286 DWORD levelcount;
1287 IDirect3DVolumeTexture9 *volume_texture;
1288 D3DVOLUME_DESC volume_desc;
1290 todo_wine {
1291 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1292 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1294 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1295 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1297 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1298 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1300 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1301 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1303 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1304 if (SUCCEEDED(hr))
1306 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1307 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1309 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1310 ok(hr == D3D_OK, "GetLevelDesc returend %#x, expected %#x\n", hr, D3D_OK);
1311 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1312 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1313 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1315 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1316 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1317 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1318 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1319 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1321 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1322 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1327 START_TEST(texture)
1329 HWND wnd;
1330 IDirect3D9 *d3d;
1331 IDirect3DDevice9 *device;
1332 D3DPRESENT_PARAMETERS d3dpp;
1333 HRESULT hr;
1335 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1336 if (!wnd) {
1337 skip("Couldn't create application window\n");
1338 return;
1340 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1341 if (!d3d) {
1342 skip("Couldn't create IDirect3D9 object\n");
1343 DestroyWindow(wnd);
1344 return;
1347 ZeroMemory(&d3dpp, sizeof(d3dpp));
1348 d3dpp.Windowed = TRUE;
1349 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1350 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1351 if (FAILED(hr)) {
1352 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1353 IDirect3D9_Release(d3d);
1354 DestroyWindow(wnd);
1355 return;
1358 test_D3DXCheckTextureRequirements(device);
1359 test_D3DXCheckCubeTextureRequirements(device);
1360 test_D3DXCheckVolumeTextureRequirements(device);
1361 test_D3DXCreateTexture(device);
1362 test_D3DXFilterTexture(device);
1363 test_D3DXFillTexture(device);
1364 test_D3DXFillCubeTexture(device);
1365 test_D3DXFillVolumeTexture(device);
1366 test_D3DXCreateTextureFromFileInMemory(device);
1367 test_D3DXCreateTextureFromFileInMemoryEx(device);
1368 test_D3DXCreateCubeTextureFromFileInMemory(device);
1369 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1371 IDirect3DDevice9_Release(device);
1372 IDirect3D9_Release(d3d);
1373 DestroyWindow(wnd);