d3dx9/tests: Do not release a cube texture if it wasn't created.
[wine/multimedia.git] / dlls / d3dx9_36 / tests / texture.c
blob143d45b36bb5978b2cb96ac2e33dc208ad38d166
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 void test_D3DXCheckTextureRequirements(IDirect3DDevice9 *device)
90 UINT width, height, mipmaps;
91 D3DFORMAT format, expected;
92 D3DCAPS9 caps;
93 HRESULT hr;
94 IDirect3D9 *d3d;
95 D3DDEVICE_CREATION_PARAMETERS params;
96 D3DDISPLAYMODE mode;
98 IDirect3DDevice9_GetDeviceCaps(device, &caps);
100 /* general tests */
101 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
102 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
104 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
105 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
107 hr = D3DXCheckTextureRequirements(NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
108 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
110 /* width & height */
111 width = height = D3DX_DEFAULT;
112 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
113 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
114 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
115 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
117 width = D3DX_DEFAULT;
118 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
119 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
120 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
122 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
123 skip("Hardware only supports pow2 textures\n");
124 else
126 width = 62;
127 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
128 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
129 ok(width == 62, "Returned width %d, expected %d\n", width, 62);
131 width = D3DX_DEFAULT; height = 63;
132 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
133 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
134 ok(width == height, "Returned width %d, expected %d\n", width, height);
135 ok(height == 63, "Returned height %d, expected %d\n", height, 63);
138 width = D3DX_DEFAULT; height = 0;
139 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
140 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
141 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
142 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
144 width = 0; height = 0;
145 hr = D3DXCheckTextureRequirements(device, &width, &height, NULL, 0, NULL, D3DPOOL_DEFAULT);
146 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
147 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
148 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
150 width = 0;
151 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
152 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
153 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
155 width = 0xFFFFFFFE;
156 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
157 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
158 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
160 width = caps.MaxTextureWidth-1;
161 hr = D3DXCheckTextureRequirements(device, &width, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
162 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
163 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
164 ok(width == caps.MaxTextureWidth, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth);
165 else
166 ok(width == caps.MaxTextureWidth-1, "Returned width %d, expected %d\n", width, caps.MaxTextureWidth-1);
168 /* mipmaps */
169 width = 64; height = 63;
170 mipmaps = 9;
171 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
172 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
173 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
175 if (!(caps.TextureCaps & D3DPTEXTURECAPS_POW2))
177 width = 284; height = 137;
178 mipmaps = 20;
179 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
180 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
181 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
183 width = height = 63;
184 mipmaps = 9;
185 hr = D3DXCheckTextureRequirements(device, &width, &height, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
186 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
187 ok(mipmaps == 6, "Returned mipmaps %d, expected %d\n", mipmaps, 6);
189 else
190 skip("Skipping some tests, npot2 textures unsupported\n");
192 mipmaps = 20;
193 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
194 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
195 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
197 mipmaps = 0;
198 hr = D3DXCheckTextureRequirements(device, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
199 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
200 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
202 /* usage */
203 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
204 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
205 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
206 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
207 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
208 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
209 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
210 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
211 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
212 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckTextureRequirements succeeded, but should've failed.\n");
214 /* format */
215 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
216 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
218 format = D3DFMT_UNKNOWN;
219 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
220 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
221 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
223 format = D3DX_DEFAULT;
224 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
225 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
226 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
228 format = D3DFMT_R8G8B8;
229 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
230 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
231 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
233 IDirect3DDevice9_GetDirect3D(device, &d3d);
234 IDirect3DDevice9_GetCreationParameters(device, &params);
235 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
237 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
238 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_R3G3B2)))
239 expected = D3DFMT_R3G3B2;
240 else
242 if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
243 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_X4R4G4B4)))
244 expected = D3DFMT_X4R4G4B4;
245 else
246 expected = D3DFMT_X1R5G5B5;
249 format = D3DFMT_R3G3B2;
250 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
251 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
252 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
254 if(SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3d, params.AdapterOrdinal, params.DeviceType,
255 mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R3G3B2)))
256 expected = D3DFMT_A8R3G3B2;
257 else
258 expected = D3DFMT_A8R8G8B8;
260 format = D3DFMT_A8R3G3B2;
261 hr = D3DXCheckTextureRequirements(device, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
262 ok(hr == D3D_OK, "D3DXCheckTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
263 ok(format == expected, "Returned format %u, expected %u\n", format, expected);
265 IDirect3D9_Release(d3d);
268 static void test_D3DXCheckCubeTextureRequirements(IDirect3DDevice9 *device)
270 UINT size, mipmaps, expected;
271 D3DFORMAT format;
272 D3DCAPS9 caps;
273 HRESULT hr;
275 IDirect3DDevice9_GetDeviceCaps(device, &caps);
277 if (!(caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP))
279 skip("No cube textures support\n");
280 return;
283 /* general tests */
284 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
285 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
287 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
288 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
290 hr = D3DXCheckCubeTextureRequirements(NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
291 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
293 /* size */
294 size = D3DX_DEFAULT;
295 hr = D3DXCheckCubeTextureRequirements(device, &size, NULL, 0, NULL, D3DPOOL_DEFAULT);
296 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
297 ok(size == 256, "Returned size %d, expected %d\n", size, 256);
299 /* mipmaps */
300 size = 64;
301 mipmaps = 9;
302 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
303 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
304 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
306 size = 284;
307 mipmaps = 20;
308 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 10 : 9;
309 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
310 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
311 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
313 size = 63;
314 mipmaps = 9;
315 expected = caps.TextureCaps & D3DPTEXTURECAPS_CUBEMAP_POW2 ? 7 : 6;
316 hr = D3DXCheckCubeTextureRequirements(device, &size, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
317 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
318 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
320 mipmaps = 0;
321 hr = D3DXCheckCubeTextureRequirements(device, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
322 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
323 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
325 /* usage */
326 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_WRITEONLY, NULL, D3DPOOL_DEFAULT);
327 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
328 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_DONOTCLIP, NULL, D3DPOOL_DEFAULT);
329 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
330 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_POINTS, NULL, D3DPOOL_DEFAULT);
331 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
332 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_RTPATCHES, NULL, D3DPOOL_DEFAULT);
333 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
334 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, D3DUSAGE_NPATCHES, NULL, D3DPOOL_DEFAULT);
335 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckCubeTextureRequirements succeeded, but should've failed.\n");
337 /* format */
338 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
339 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
341 format = D3DFMT_UNKNOWN;
342 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
343 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
344 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
346 format = D3DX_DEFAULT;
347 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
348 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
349 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
351 format = D3DFMT_R8G8B8;
352 hr = D3DXCheckCubeTextureRequirements(device, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
353 ok(hr == D3D_OK, "D3DXCheckCubeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
354 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
357 static void test_D3DXCheckVolumeTextureRequirements(IDirect3DDevice9 *device)
359 UINT width, height, depth, mipmaps, expected;
360 D3DFORMAT format;
361 D3DCAPS9 caps;
362 HRESULT hr;
364 IDirect3DDevice9_GetDeviceCaps(device, &caps);
366 if (!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP))
368 skip("No volume textures support\n");
369 return;
372 /* general tests */
373 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
374 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
376 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
377 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
379 hr = D3DXCheckVolumeTextureRequirements(NULL, NULL, NULL, NULL, NULL, D3DX_DEFAULT, NULL, D3DPOOL_DEFAULT);
380 ok(hr == D3DERR_INVALIDCALL, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
382 /* width, height, depth */
383 width = height = depth = D3DX_DEFAULT;
384 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
385 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
386 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
387 ok(height == 256, "Returned height %d, expected %d\n", height, 256);
388 ok(depth == 1, "Returned depth %d, expected %d\n", depth, 1);
390 width = D3DX_DEFAULT;
391 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
392 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
393 ok(width == 256, "Returned width %d, expected %d\n", width, 256);
395 width = D3DX_DEFAULT; height = 0; depth = 0;
396 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
397 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
398 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
399 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
400 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
402 width = 0; height = 0; depth = 0;
403 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, NULL, 0, NULL, D3DPOOL_DEFAULT);
404 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
405 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
406 ok(height == 1, "Returned height %d, expected %d\n", height, 1);
407 ok(depth == 1, "Returned height %d, expected %d\n", depth, 1);
409 width = 0;
410 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
411 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
412 ok(width == 1, "Returned width %d, expected %d\n", width, 1);
414 width = 0xFFFFFFFE;
415 hr = D3DXCheckVolumeTextureRequirements(device, &width, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
416 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
417 ok(width == caps.MaxVolumeExtent, "Returned width %d, expected %d\n", width, caps.MaxVolumeExtent);
419 /* format */
420 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, NULL, D3DPOOL_DEFAULT);
421 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
423 format = D3DFMT_UNKNOWN;
424 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
425 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
426 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
428 format = D3DX_DEFAULT;
429 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
430 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
431 ok(format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_A8R8G8B8);
433 format = D3DFMT_R8G8B8;
434 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, NULL, 0, &format, D3DPOOL_DEFAULT);
435 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
436 ok(format == D3DFMT_X8R8G8B8, "Returned format %u, expected %u\n", format, D3DFMT_X8R8G8B8);
438 /* mipmaps */
439 if (!(caps.TextureCaps & D3DPTEXTURECAPS_MIPVOLUMEMAP))
441 skip("No volume textures mipmapping support\n");
442 return;
445 width = height = depth = 64;
446 mipmaps = 9;
447 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
448 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
449 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
451 width = 284;
452 height = 143;
453 depth = 55;
454 mipmaps = 20;
455 expected = caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP_POW2 ? 10 : 9;
456 hr = D3DXCheckVolumeTextureRequirements(device, &width, &height, &depth, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
457 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
458 ok(mipmaps == expected, "Returned mipmaps %d, expected %d\n", mipmaps, expected);
460 mipmaps = 0;
461 hr = D3DXCheckVolumeTextureRequirements(device, NULL, NULL, NULL, &mipmaps, 0, NULL, D3DPOOL_DEFAULT);
462 ok(hr == D3D_OK, "D3DXCheckVolumeTextureRequirements returned %#x, expected %#x\n", hr, D3D_OK);
463 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
466 static void test_D3DXCreateTexture(IDirect3DDevice9 *device)
468 IDirect3DTexture9 *texture;
469 D3DSURFACE_DESC desc;
470 D3DCAPS9 caps;
471 UINT mipmaps;
472 HRESULT hr;
474 IDirect3DDevice9_GetDeviceCaps(device, &caps);
476 hr = D3DXCreateTexture(NULL, 0, 0, 0, 0, D3DX_DEFAULT, 0, D3DPOOL_DEFAULT);
477 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
479 /* width and height tests */
481 hr = D3DXCreateTexture(device, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, 0, D3DPOOL_DEFAULT, &texture);
482 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
484 if (texture)
486 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
487 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
488 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
490 ok(desc.Width == 256, "Returned width %d, expected %d\n", desc.Width, 256);
491 ok(desc.Height == 256, "Returned height %d, expected %d\n", desc.Height, 256);
493 IDirect3DTexture9_Release(texture);
497 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
498 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
500 if (texture)
502 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
503 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
504 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
506 ok(desc.Width == 1, "Returned width %d, expected %d\n", desc.Width, 1);
507 ok(desc.Height == 1, "Returned height %d, expected %d\n", desc.Height, 1);
509 IDirect3DTexture9_Release(texture);
513 if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
514 skip("Hardware only supports pow2 textures\n");
515 else
517 hr = D3DXCreateTexture(device, D3DX_DEFAULT, 63, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
518 ok((hr == D3D_OK) ||
519 /* may not work with conditional NPOT */
520 ((hr != D3D_OK) && (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)),
521 "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
523 if (texture)
525 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
526 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
527 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
529 /* Conditional NPOT may create a texture with different dimensions, so allow those
530 situations instead of returning a fail */
532 ok(desc.Width == 63 ||
533 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
534 "Returned width %d, expected %d\n", desc.Width, 63);
536 ok(desc.Height == 63 ||
537 (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL),
538 "Returned height %d, expected %d\n", desc.Height, 63);
540 IDirect3DTexture9_Release(texture);
544 /* mipmaps */
546 hr = D3DXCreateTexture(device, 64, 63, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
547 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
549 if (texture)
551 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
552 ok(mipmaps == 7, "Returned mipmaps %d, expected %d\n", mipmaps, 7);
554 IDirect3DTexture9_Release(texture);
558 hr = D3DXCreateTexture(device, 284, 137, 9, 0, 0, D3DPOOL_DEFAULT, &texture);
559 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
561 if (texture)
563 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
564 ok(mipmaps == 9, "Returned mipmaps %d, expected %d\n", mipmaps, 9);
566 IDirect3DTexture9_Release(texture);
570 hr = D3DXCreateTexture(device, 0, 0, 20, 0, 0, D3DPOOL_DEFAULT, &texture);
571 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
573 if (texture)
575 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
576 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
578 IDirect3DTexture9_Release(texture);
582 hr = D3DXCreateTexture(device, 64, 64, 1, 0, 0, D3DPOOL_DEFAULT, &texture);
583 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
585 if (texture)
587 mipmaps = IDirect3DTexture9_GetLevelCount(texture);
588 ok(mipmaps == 1, "Returned mipmaps %d, expected %d\n", mipmaps, 1);
590 IDirect3DTexture9_Release(texture);
593 /* usage */
595 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &texture);
596 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
597 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_DONOTCLIP, 0, D3DPOOL_DEFAULT, &texture);
598 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
599 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_POINTS, 0, D3DPOOL_DEFAULT, &texture);
600 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
601 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_RTPATCHES, 0, D3DPOOL_DEFAULT, &texture);
602 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
603 hr = D3DXCreateTexture(device, 0, 0, 0, D3DUSAGE_NPATCHES, 0, D3DPOOL_DEFAULT, &texture);
604 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTexture succeeded, but should have failed.\n");
606 /* format */
608 hr = D3DXCreateTexture(device, 0, 0, 0, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, &texture);
609 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
611 if (texture)
613 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
614 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
615 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
617 IDirect3DTexture9_Release(texture);
621 hr = D3DXCreateTexture(device, 0, 0, 0, 0, 0, D3DPOOL_DEFAULT, &texture);
622 ok(hr == D3D_OK, "D3DXCreateTexture returned %#x, expected %#x\n", hr, D3D_OK);
624 if (texture)
626 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &desc);
627 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
628 ok(desc.Format == D3DFMT_A8R8G8B8, "Returned format %u, expected %u\n", desc.Format, D3DFMT_A8R8G8B8);
630 IDirect3DTexture9_Release(texture);
633 /* D3DXCreateTextureFromResource */
634 todo_wine {
635 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDB_BITMAP_1x1), &texture);
636 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
637 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
639 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
640 ok(hr == D3D_OK, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3D_OK);
641 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
643 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDS_STRING), &texture);
644 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
646 hr = D3DXCreateTextureFromResourceA(NULL, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), &texture);
647 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
649 hr = D3DXCreateTextureFromResourceA(device, NULL, NULL, &texture);
650 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
652 hr = D3DXCreateTextureFromResourceA(device, NULL, MAKEINTRESOURCEA(IDD_BITMAPDATA_1x1), NULL);
653 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResource returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
656 /* D3DXCreateTextureFromResourceEx */
657 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);
658 ok(hr == D3D_OK, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3D_OK);
659 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
661 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);
662 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
664 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);
665 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
667 hr = D3DXCreateTextureFromResourceExA(device, NULL, NULL, D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
668 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
670 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);
671 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateTextureFromResourceEx returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
674 static void test_D3DXFilterTexture(IDirect3DDevice9 *device)
676 IDirect3DTexture9 *tex;
677 IDirect3DCubeTexture9 *cubetex;
678 HRESULT hr;
680 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &tex, NULL);
682 if (SUCCEEDED(hr))
684 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
685 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
687 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
688 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
690 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
691 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
693 else
694 skip("Failed to create texture\n");
696 IDirect3DTexture9_Release(tex);
698 hr = D3DXFilterTexture(NULL, NULL, 0, D3DX_FILTER_NONE);
699 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
701 /* Test different pools */
702 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &tex, NULL);
704 if (SUCCEEDED(hr))
706 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
707 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
708 IDirect3DTexture9_Release(tex);
710 else
711 skip("Failed to create texture\n");
713 hr = IDirect3DDevice9_CreateTexture(device, 256, 256, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &tex, NULL);
715 if (SUCCEEDED(hr))
717 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) tex, NULL, 0, D3DX_FILTER_NONE);
718 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
719 IDirect3DTexture9_Release(tex);
721 else
722 skip("Failed to create texture\n");
724 /* Cube texture test */
725 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 5, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &cubetex, NULL);
727 if (SUCCEEDED(hr))
729 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_NONE);
730 ok(hr == D3D_OK, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3D_OK);
732 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 0, D3DX_FILTER_BOX + 1); /* Invalid filter */
733 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
735 hr = D3DXFilterTexture((IDirect3DBaseTexture9*) cubetex, NULL, 5, D3DX_FILTER_NONE); /* Invalid miplevel */
736 ok(hr == D3DERR_INVALIDCALL, "D3DXFilterTexture returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
737 IDirect3DCubeTexture9_Release(cubetex);
739 else
740 skip("Failed to create texture\n");
743 static BOOL color_match(const DWORD *value, const DWORD *expected)
745 int i;
747 for (i = 0; i < 4; i++)
749 DWORD diff = value[i] > expected[i] ? value[i] - expected[i] : expected[i] - value[i];
750 if (diff > 1) return FALSE;
752 return TRUE;
755 static void WINAPI fillfunc(D3DXVECTOR4 *value, const D3DXVECTOR2 *texcoord,
756 const D3DXVECTOR2 *texelsize, void *data)
758 value->x = texcoord->x;
759 value->y = texcoord->y;
760 value->z = texelsize->x;
761 value->w = 1.0f;
764 static void test_D3DXFillTexture(IDirect3DDevice9 *device)
766 IDirect3DTexture9 *tex;
767 HRESULT hr;
768 D3DLOCKED_RECT lock_rect;
769 DWORD x, y, m;
770 DWORD v[4], e[4];
771 DWORD value, expected, size, pitch;
773 size = 4;
774 hr = IDirect3DDevice9_CreateTexture(device, size, size, 0, 0, D3DFMT_A8R8G8B8,
775 D3DPOOL_MANAGED, &tex, NULL);
777 if (SUCCEEDED(hr))
779 hr = D3DXFillTexture(tex, fillfunc, NULL);
780 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
782 for (m = 0; m < 3; m++)
784 hr = IDirect3DTexture9_LockRect(tex, m, &lock_rect, NULL, D3DLOCK_READONLY);
785 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
786 if (SUCCEEDED(hr))
788 pitch = lock_rect.Pitch / sizeof(DWORD);
789 for (y = 0; y < size; y++)
791 for (x = 0; x < size; x++)
793 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
794 v[0] = (value >> 24) & 0xff;
795 v[1] = (value >> 16) & 0xff;
796 v[2] = (value >> 8) & 0xff;
797 v[3] = value & 0xff;
799 e[0] = 0xff;
800 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
801 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
802 e[3] = 255.0f / size + 0.5f;
803 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
805 ok(color_match(v, e),
806 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
807 x, y, value, expected);
810 IDirect3DTexture9_UnlockRect(tex, m);
812 size >>= 1;
815 else
816 skip("Failed to create texture\n");
818 IDirect3DTexture9_Release(tex);
820 hr = IDirect3DDevice9_CreateTexture(device, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
821 D3DPOOL_MANAGED, &tex, NULL);
823 if (SUCCEEDED(hr))
825 hr = D3DXFillTexture(tex, fillfunc, NULL);
826 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
828 hr = IDirect3DTexture9_LockRect(tex, 0, &lock_rect, NULL, D3DLOCK_READONLY);
829 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
830 if (SUCCEEDED(hr))
832 pitch = lock_rect.Pitch / sizeof(WORD);
833 for (y = 0; y < 4; y++)
835 for (x = 0; x < 4; x++)
837 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
838 v[0] = value >> 15;
839 v[1] = value >> 10 & 0x1f;
840 v[2] = value >> 5 & 0x1f;
841 v[3] = value & 0x1f;
843 e[0] = 1;
844 e[1] = (x + 0.5f) / 4.0f * 31.0f + 0.5f;
845 e[2] = (y + 0.5f) / 4.0f * 31.0f + 0.5f;
846 e[3] = 8;
847 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
849 ok(color_match(v, e),
850 "Texel at (%u, %u) doesn't match: %#x, expected %#x\n",
851 x, y, value, expected);
854 IDirect3DTexture9_UnlockRect(tex, 0);
857 else
858 skip("Failed to create texture\n");
860 IDirect3DTexture9_Release(tex);
863 static void WINAPI fillfunc_cube(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
864 const D3DXVECTOR3 *texelsize, void *data)
866 value->x = (texcoord->x + 1.0f) / 2.0f;
867 value->y = (texcoord->y + 1.0f) / 2.0f;
868 value->z = (texcoord->z + 1.0f) / 2.0f;
869 value->w = texelsize->x;
872 enum cube_coord
874 XCOORD = 0,
875 XCOORDINV = 1,
876 YCOORD = 2,
877 YCOORDINV = 3,
878 ZERO = 4,
879 ONE = 5
882 static float get_cube_coord(enum cube_coord coord, unsigned int x, unsigned int y, unsigned int size)
884 switch (coord)
886 case XCOORD:
887 return x + 0.5f;
888 case XCOORDINV:
889 return size - x - 0.5f;
890 case YCOORD:
891 return y + 0.5f;
892 case YCOORDINV:
893 return size - y - 0.5f;
894 case ZERO:
895 return 0.0f;
896 case ONE:
897 return size;
898 default:
899 trace("Unexpected coordinate value\n");
900 return 0.0f;
904 static void test_D3DXFillCubeTexture(IDirect3DDevice9 *device)
906 IDirect3DCubeTexture9 *tex;
907 HRESULT hr;
908 D3DLOCKED_RECT lock_rect;
909 DWORD x, y, f, m;
910 DWORD v[4], e[4];
911 DWORD value, expected, size, pitch;
912 enum cube_coord coordmap[6][3] =
914 {ONE, YCOORDINV, XCOORDINV},
915 {ZERO, YCOORDINV, XCOORD},
916 {XCOORD, ONE, YCOORD},
917 {XCOORD, ZERO, YCOORDINV},
918 {XCOORD, YCOORDINV, ONE},
919 {XCOORDINV, YCOORDINV, ZERO}
922 size = 4;
923 hr = IDirect3DDevice9_CreateCubeTexture(device, size, 0, 0, D3DFMT_A8R8G8B8,
924 D3DPOOL_MANAGED, &tex, NULL);
926 if (SUCCEEDED(hr))
928 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
929 ok(hr == D3D_OK, "D3DXFillCubeTexture returned %#x, expected %#x\n", hr, D3D_OK);
931 for (m = 0; m < 3; m++)
933 for (f = 0; f < 6; f++)
935 hr = IDirect3DCubeTexture9_LockRect(tex, f, m, &lock_rect, NULL, D3DLOCK_READONLY);
936 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
937 if (SUCCEEDED(hr))
939 pitch = lock_rect.Pitch / sizeof(DWORD);
940 for (y = 0; y < size; y++)
942 for (x = 0; x < size; x++)
944 value = ((DWORD *)lock_rect.pBits)[y * pitch + x];
945 v[0] = (value >> 24) & 0xff;
946 v[1] = (value >> 16) & 0xff;
947 v[2] = (value >> 8) & 0xff;
948 v[3] = value & 0xff;
950 e[0] = (f == 0) || (f == 1) ?
951 0 : (BYTE)(255.0f / size * 2.0f + 0.5f);
952 e[1] = get_cube_coord(coordmap[f][0], x, y, size) / size * 255.0f + 0.5f;
953 e[2] = get_cube_coord(coordmap[f][1], x, y, size) / size * 255.0f + 0.5f;
954 e[3] = get_cube_coord(coordmap[f][2], x, y, size) / size * 255.0f + 0.5f;
955 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
957 ok(color_match(v, e),
958 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
959 f, x, y, value, expected);
962 IDirect3DCubeTexture9_UnlockRect(tex, f, m);
965 size >>= 1;
968 else
969 skip("Failed to create texture\n");
971 IDirect3DCubeTexture9_Release(tex);
973 hr = IDirect3DDevice9_CreateCubeTexture(device, 4, 1, 0, D3DFMT_A1R5G5B5,
974 D3DPOOL_MANAGED, &tex, NULL);
976 if (SUCCEEDED(hr))
978 hr = D3DXFillCubeTexture(tex, fillfunc_cube, NULL);
979 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
980 for (f = 0; f < 6; f++)
982 hr = IDirect3DCubeTexture9_LockRect(tex, f, 0, &lock_rect, NULL, D3DLOCK_READONLY);
983 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
984 if (SUCCEEDED(hr))
986 pitch = lock_rect.Pitch / sizeof(WORD);
987 for (y = 0; y < 4; y++)
989 for (x = 0; x < 4; x++)
991 value = ((WORD *)lock_rect.pBits)[y * pitch + x];
992 v[0] = value >> 15;
993 v[1] = value >> 10 & 0x1f;
994 v[2] = value >> 5 & 0x1f;
995 v[3] = value & 0x1f;
997 e[0] = (f == 0) || (f == 1) ?
998 0 : (BYTE)(1.0f / size * 2.0f + 0.5f);
999 e[1] = get_cube_coord(coordmap[f][0], x, y, 4) / 4 * 31.0f + 0.5f;
1000 e[2] = get_cube_coord(coordmap[f][1], x, y, 4) / 4 * 31.0f + 0.5f;
1001 e[3] = get_cube_coord(coordmap[f][2], x, y, 4) / 4 * 31.0f + 0.5f;
1002 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1004 ok(color_match(v, e),
1005 "Texel at face %u (%u, %u) doesn't match: %#x, expected %#x\n",
1006 f, x, y, value, expected);
1009 IDirect3DCubeTexture9_UnlockRect(tex, f, 0);
1013 else
1014 skip("Failed to create texture\n");
1016 IDirect3DCubeTexture9_Release(tex);
1019 static void WINAPI fillfunc_volume(D3DXVECTOR4 *value, const D3DXVECTOR3 *texcoord,
1020 const D3DXVECTOR3 *texelsize, void *data)
1022 value->x = texcoord->x;
1023 value->y = texcoord->y;
1024 value->z = texcoord->z;
1025 value->w = texelsize->x;
1028 static void test_D3DXFillVolumeTexture(IDirect3DDevice9 *device)
1030 IDirect3DVolumeTexture9 *tex;
1031 HRESULT hr;
1032 D3DLOCKED_BOX lock_box;
1033 DWORD x, y, z, m;
1034 DWORD v[4], e[4];
1035 DWORD value, expected, size, row_pitch, slice_pitch;
1037 size = 4;
1038 hr = IDirect3DDevice9_CreateVolumeTexture(device, size, size, size, 0, 0, D3DFMT_A8R8G8B8,
1039 D3DPOOL_MANAGED, &tex, NULL);
1041 if (SUCCEEDED(hr))
1043 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1044 ok(hr == D3D_OK, "D3DXFillVolumeTexture returned %#x, expected %#x\n", hr, D3D_OK);
1046 for (m = 0; m < 3; m++)
1048 hr = IDirect3DVolumeTexture9_LockBox(tex, m, &lock_box, NULL, D3DLOCK_READONLY);
1049 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1050 if (SUCCEEDED(hr))
1052 row_pitch = lock_box.RowPitch / sizeof(DWORD);
1053 slice_pitch = lock_box.SlicePitch / sizeof(DWORD);
1054 for (z = 0; z < size; z++)
1056 for (y = 0; y < size; y++)
1058 for (x = 0; x < size; x++)
1060 value = ((DWORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1061 v[0] = (value >> 24) & 0xff;
1062 v[1] = (value >> 16) & 0xff;
1063 v[2] = (value >> 8) & 0xff;
1064 v[3] = value & 0xff;
1066 e[0] = 255.0f / size + 0.5f;
1067 e[1] = (x + 0.5f) / size * 255.0f + 0.5f;
1068 e[2] = (y + 0.5f) / size * 255.0f + 0.5f;
1069 e[3] = (z + 0.5f) / size * 255.0f + 0.5f;
1070 expected = e[0] << 24 | e[1] << 16 | e[2] << 8 | e[3];
1072 ok(color_match(v, e),
1073 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1074 x, y, z, value, expected);
1078 IDirect3DVolumeTexture9_UnlockBox(tex, m);
1080 size >>= 1;
1083 else
1084 skip("Failed to create texture\n");
1086 IDirect3DVolumeTexture9_Release(tex);
1088 hr = IDirect3DDevice9_CreateVolumeTexture(device, 4, 4, 4, 1, 0, D3DFMT_A1R5G5B5,
1089 D3DPOOL_MANAGED, &tex, NULL);
1091 if (SUCCEEDED(hr))
1093 hr = D3DXFillVolumeTexture(tex, fillfunc_volume, NULL);
1094 ok(hr == D3D_OK, "D3DXFillTexture returned %#x, expected %#x\n", hr, D3D_OK);
1095 hr = IDirect3DVolumeTexture9_LockBox(tex, 0, &lock_box, NULL, D3DLOCK_READONLY);
1096 ok(hr == D3D_OK, "Couldn't lock the texture, error %#x\n", hr);
1097 if (SUCCEEDED(hr))
1099 row_pitch = lock_box.RowPitch / sizeof(WORD);
1100 slice_pitch = lock_box.SlicePitch / sizeof(WORD);
1101 for (z = 0; z < 4; z++)
1103 for (y = 0; y < 4; y++)
1105 for (x = 0; x < 4; x++)
1107 value = ((WORD *)lock_box.pBits)[z * slice_pitch + y * row_pitch + x];
1108 v[0] = value >> 15;
1109 v[1] = value >> 10 & 0x1f;
1110 v[2] = value >> 5 & 0x1f;
1111 v[3] = value & 0x1f;
1113 e[0] = 1;
1114 e[1] = (x + 0.5f) / 4 * 31.0f + 0.5f;
1115 e[2] = (y + 0.5f) / 4 * 31.0f + 0.5f;
1116 e[3] = (z + 0.5f) / 4 * 31.0f + 0.5f;
1117 expected = e[0] << 15 | e[1] << 10 | e[2] << 5 | e[3];
1119 ok(color_match(v, e),
1120 "Texel at (%u, %u, %u) doesn't match: %#x, expected %#x\n",
1121 x, y, z, value, expected);
1125 IDirect3DVolumeTexture9_UnlockBox(tex, 0);
1128 else
1129 skip("Failed to create texture\n");
1131 IDirect3DVolumeTexture9_Release(tex);
1134 static void test_D3DXCreateTextureFromFileInMemory(IDirect3DDevice9 *device)
1136 HRESULT hr;
1137 IDirect3DTexture9 *texture;
1139 hr = D3DXCreateTextureFromFileInMemory(device, dds_16bit, sizeof(dds_16bit), &texture);
1140 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1141 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1143 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit), &texture);
1144 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3D_OK);
1145 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1147 hr = D3DXCreateTextureFromFileInMemory(device, dds_24bit, sizeof(dds_24bit) - 1, &texture);
1148 ok(hr == D3DXERR_INVALIDDATA, "D3DXCreateTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DXERR_INVALIDDATA);
1151 static void test_D3DXCreateTextureFromFileInMemoryEx(IDirect3DDevice9 *device)
1153 HRESULT hr;
1154 IDirect3DTexture9 *texture;
1156 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1157 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1158 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1159 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1161 hr = D3DXCreateTextureFromFileInMemoryEx(device, dds_16bit, sizeof(dds_16bit), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT,
1162 D3DUSAGE_DYNAMIC, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &texture);
1163 ok(hr == D3D_OK, "D3DXCreateTextureFromFileInMemoryEx returned %#x, expected %#x\n", hr, D3D_OK);
1164 if (SUCCEEDED(hr)) IDirect3DTexture9_Release(texture);
1167 static void test_D3DXCreateCubeTextureFromFileInMemory(IDirect3DDevice9 *device)
1169 HRESULT hr;
1170 ULONG ref;
1171 DWORD levelcount;
1172 IDirect3DCubeTexture9 *cube_texture;
1173 D3DSURFACE_DESC surface_desc;
1175 hr = D3DXCreateCubeTextureFromFileInMemory(NULL, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1176 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1178 hr = D3DXCreateCubeTextureFromFileInMemory(device, NULL, sizeof(dds_cube_map), &cube_texture);
1179 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1181 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, 0, &cube_texture);
1182 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1184 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), NULL);
1185 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateCubeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1187 hr = D3DXCreateCubeTextureFromFileInMemory(device, dds_cube_map, sizeof(dds_cube_map), &cube_texture);
1188 if (SUCCEEDED(hr))
1190 levelcount = IDirect3DCubeTexture9_GetLevelCount(cube_texture);
1191 todo_wine ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1193 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 0, &surface_desc);
1194 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1195 ok(surface_desc.Width == 4, "Got width %u, expected 4\n", surface_desc.Width);
1196 ok(surface_desc.Height == 4, "Got height %u, expected 4\n", surface_desc.Height);
1198 hr = IDirect3DCubeTexture9_GetLevelDesc(cube_texture, 3, &surface_desc);
1199 todo_wine ok(hr == D3DERR_INVALIDCALL, "GetLevelDesc returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1201 ref = IDirect3DCubeTexture9_Release(cube_texture);
1202 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1203 } else skip("Couldn't create cube texture\n");
1206 static void test_D3DXCreateVolumeTextureFromFileInMemory(IDirect3DDevice9 *device)
1208 HRESULT hr;
1209 ULONG ref;
1210 DWORD levelcount;
1211 IDirect3DVolumeTexture9 *volume_texture;
1212 D3DVOLUME_DESC volume_desc;
1214 todo_wine {
1215 hr = D3DXCreateVolumeTextureFromFileInMemory(NULL, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1216 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1218 hr = D3DXCreateVolumeTextureFromFileInMemory(device, NULL, sizeof(dds_volume_map), &volume_texture);
1219 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1221 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, 0, &volume_texture);
1222 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1224 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), NULL);
1225 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateVolumeTextureFromFileInMemory returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1227 hr = D3DXCreateVolumeTextureFromFileInMemory(device, dds_volume_map, sizeof(dds_volume_map), &volume_texture);
1228 if (SUCCEEDED(hr))
1230 levelcount = IDirect3DVolumeTexture9_GetLevelCount(volume_texture);
1231 ok(levelcount == 3, "GetLevelCount returned %u, expected 3\n", levelcount);
1233 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 0, &volume_desc);
1234 ok(hr == D3D_OK, "GetLevelDesc returend %#x, expected %#x\n", hr, D3D_OK);
1235 ok(volume_desc.Width == 4, "Got width %u, expected 4\n", volume_desc.Width);
1236 ok(volume_desc.Height == 4, "Got height %u, expected 4\n", volume_desc.Height);
1237 ok(volume_desc.Depth == 2, "Got depth %u, expected 2\n", volume_desc.Depth);
1239 hr = IDirect3DVolumeTexture9_GetLevelDesc(volume_texture, 1, &volume_desc);
1240 ok(hr == D3D_OK, "GetLevelDesc returned %#x, expected %#x\n", hr, D3D_OK);
1241 ok(volume_desc.Width == 2, "Got width %u, expected 2\n", volume_desc.Width);
1242 ok(volume_desc.Height == 2, "Got height %u, expected 2\n", volume_desc.Height);
1243 ok(volume_desc.Depth == 1, "Got depth %u, expected 1\n", volume_desc.Depth);
1245 ref = IDirect3DVolumeTexture9_Release(volume_texture);
1246 ok(ref == 0, "Invalid reference count. Got %u, expected 0\n", ref);
1251 START_TEST(texture)
1253 HWND wnd;
1254 IDirect3D9 *d3d;
1255 IDirect3DDevice9 *device;
1256 D3DPRESENT_PARAMETERS d3dpp;
1257 HRESULT hr;
1259 wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
1260 if (!wnd) {
1261 skip("Couldn't create application window\n");
1262 return;
1264 d3d = Direct3DCreate9(D3D_SDK_VERSION);
1265 if (!d3d) {
1266 skip("Couldn't create IDirect3D9 object\n");
1267 DestroyWindow(wnd);
1268 return;
1271 ZeroMemory(&d3dpp, sizeof(d3dpp));
1272 d3dpp.Windowed = TRUE;
1273 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1274 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device);
1275 if (FAILED(hr)) {
1276 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1277 IDirect3D9_Release(d3d);
1278 DestroyWindow(wnd);
1279 return;
1282 test_D3DXCheckTextureRequirements(device);
1283 test_D3DXCheckCubeTextureRequirements(device);
1284 test_D3DXCheckVolumeTextureRequirements(device);
1285 test_D3DXCreateTexture(device);
1286 test_D3DXFilterTexture(device);
1287 test_D3DXFillTexture(device);
1288 test_D3DXFillCubeTexture(device);
1289 test_D3DXFillVolumeTexture(device);
1290 test_D3DXCreateTextureFromFileInMemory(device);
1291 test_D3DXCreateTextureFromFileInMemoryEx(device);
1292 test_D3DXCreateCubeTextureFromFileInMemory(device);
1293 test_D3DXCreateVolumeTextureFromFileInMemory(device);
1295 IDirect3DDevice9_Release(device);
1296 IDirect3D9_Release(d3d);
1297 DestroyWindow(wnd);