vbscript: Added support for title and type arguments of MsgBox.
[wine.git] / dlls / ddraw / utils.c
blobebd355bc2edb757b2228bf60cfb72441cc0ba30f
1 /*
2 * DirectDraw helper functions
4 * Copyright (c) 1997-2000 Marcus Meissner
5 * Copyright (c) 1998 Lionel Ulmer
6 * Copyright (c) 2000 TransGaming Technologies Inc.
7 * Copyright (c) 2006 Stefan Dösinger
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
25 #include "wine/port.h"
27 #include "ddraw_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
31 static void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf);
33 void ddrawformat_from_wined3dformat(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_id wined3d_format)
35 DWORD Size = DDPixelFormat->dwSize;
37 if(Size==0) return;
39 memset(DDPixelFormat, 0x00, Size);
40 DDPixelFormat->dwSize = Size;
41 switch (wined3d_format)
43 case WINED3DFMT_B8G8R8_UNORM:
44 DDPixelFormat->dwFlags = DDPF_RGB;
45 DDPixelFormat->dwFourCC = 0;
46 DDPixelFormat->u1.dwRGBBitCount = 24;
47 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
48 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
49 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
50 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
51 break;
53 case WINED3DFMT_B8G8R8A8_UNORM:
54 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
55 DDPixelFormat->dwFourCC = 0;
56 DDPixelFormat->u1.dwRGBBitCount = 32;
57 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
58 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
59 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
60 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
61 break;
63 case WINED3DFMT_B8G8R8X8_UNORM:
64 DDPixelFormat->dwFlags = DDPF_RGB;
65 DDPixelFormat->dwFourCC = 0;
66 DDPixelFormat->u1.dwRGBBitCount = 32;
67 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
68 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
69 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
70 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
71 break;
73 case WINED3DFMT_R8G8B8X8_UNORM:
74 DDPixelFormat->dwFlags = DDPF_RGB;
75 DDPixelFormat->dwFourCC = 0;
76 DDPixelFormat->u1.dwRGBBitCount = 32;
77 DDPixelFormat->u2.dwRBitMask = 0x000000ff;
78 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
79 DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
80 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
81 break;
83 case WINED3DFMT_B5G6R5_UNORM:
84 DDPixelFormat->dwFlags = DDPF_RGB;
85 DDPixelFormat->dwFourCC = 0;
86 DDPixelFormat->u1.dwRGBBitCount = 16;
87 DDPixelFormat->u2.dwRBitMask = 0xF800;
88 DDPixelFormat->u3.dwGBitMask = 0x07E0;
89 DDPixelFormat->u4.dwBBitMask = 0x001F;
90 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
91 break;
93 case WINED3DFMT_B5G5R5X1_UNORM:
94 DDPixelFormat->dwFlags = DDPF_RGB;
95 DDPixelFormat->dwFourCC = 0;
96 DDPixelFormat->u1.dwRGBBitCount = 16;
97 DDPixelFormat->u2.dwRBitMask = 0x7C00;
98 DDPixelFormat->u3.dwGBitMask = 0x03E0;
99 DDPixelFormat->u4.dwBBitMask = 0x001F;
100 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
101 break;
103 case WINED3DFMT_B5G5R5A1_UNORM:
104 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
105 DDPixelFormat->dwFourCC = 0;
106 DDPixelFormat->u1.dwRGBBitCount = 16;
107 DDPixelFormat->u2.dwRBitMask = 0x7C00;
108 DDPixelFormat->u3.dwGBitMask = 0x03E0;
109 DDPixelFormat->u4.dwBBitMask = 0x001F;
110 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
111 break;
113 case WINED3DFMT_B4G4R4A4_UNORM:
114 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
115 DDPixelFormat->dwFourCC = 0;
116 DDPixelFormat->u1.dwRGBBitCount = 16;
117 DDPixelFormat->u2.dwRBitMask = 0x0F00;
118 DDPixelFormat->u3.dwGBitMask = 0x00F0;
119 DDPixelFormat->u4.dwBBitMask = 0x000F;
120 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
121 break;
123 case WINED3DFMT_B2G3R3_UNORM:
124 DDPixelFormat->dwFlags = DDPF_RGB;
125 DDPixelFormat->dwFourCC = 0;
126 DDPixelFormat->u1.dwRGBBitCount = 8;
127 DDPixelFormat->u2.dwRBitMask = 0xE0;
128 DDPixelFormat->u3.dwGBitMask = 0x1C;
129 DDPixelFormat->u4.dwBBitMask = 0x03;
130 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
131 break;
133 case WINED3DFMT_P8_UINT:
134 DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
135 DDPixelFormat->dwFourCC = 0;
136 DDPixelFormat->u1.dwRGBBitCount = 8;
137 DDPixelFormat->u2.dwRBitMask = 0x00;
138 DDPixelFormat->u3.dwGBitMask = 0x00;
139 DDPixelFormat->u4.dwBBitMask = 0x00;
140 break;
142 case WINED3DFMT_A8_UNORM:
143 DDPixelFormat->dwFlags = DDPF_ALPHA;
144 DDPixelFormat->dwFourCC = 0;
145 DDPixelFormat->u1.dwAlphaBitDepth = 8;
146 DDPixelFormat->u2.dwRBitMask = 0x0;
147 DDPixelFormat->u3.dwZBitMask = 0x0;
148 DDPixelFormat->u4.dwStencilBitMask = 0x0;
149 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
150 break;
152 case WINED3DFMT_B2G3R3A8_UNORM:
153 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
154 DDPixelFormat->dwFourCC = 0;
155 DDPixelFormat->u1.dwRGBBitCount = 16;
156 DDPixelFormat->u2.dwRBitMask = 0x00E0;
157 DDPixelFormat->u3.dwGBitMask = 0x001C;
158 DDPixelFormat->u4.dwBBitMask = 0x0003;
159 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xFF00;
160 break;
162 case WINED3DFMT_B4G4R4X4_UNORM:
163 DDPixelFormat->dwFlags = DDPF_RGB;
164 DDPixelFormat->dwFourCC = 0;
165 DDPixelFormat->u1.dwRGBBitCount = 16;
166 DDPixelFormat->u2.dwRBitMask = 0x0F00;
167 DDPixelFormat->u3.dwGBitMask = 0x00F0;
168 DDPixelFormat->u4.dwBBitMask = 0x000F;
169 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
170 break;
172 /* How are Z buffer bit depth and Stencil buffer bit depth related?
174 case WINED3DFMT_D16_UNORM:
175 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
176 DDPixelFormat->dwFourCC = 0;
177 DDPixelFormat->u1.dwZBufferBitDepth = 16;
178 DDPixelFormat->u2.dwStencilBitDepth = 0;
179 DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
180 DDPixelFormat->u4.dwStencilBitMask = 0x0;
181 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
182 break;
184 case WINED3DFMT_D32_UNORM:
185 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
186 DDPixelFormat->dwFourCC = 0;
187 DDPixelFormat->u1.dwZBufferBitDepth = 32;
188 DDPixelFormat->u2.dwStencilBitDepth = 0;
189 DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
190 DDPixelFormat->u4.dwStencilBitMask = 0x0;
191 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
192 break;
194 case WINED3DFMT_S4X4_UINT_D24_UNORM:
195 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
196 DDPixelFormat->dwFourCC = 0;
197 /* Should I set dwZBufferBitDepth to 32 here? */
198 DDPixelFormat->u1.dwZBufferBitDepth = 32;
199 DDPixelFormat->u2.dwStencilBitDepth = 4;
200 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
201 DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
202 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
203 break;
205 case WINED3DFMT_D24_UNORM_S8_UINT:
206 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
207 DDPixelFormat->dwFourCC = 0;
208 DDPixelFormat->u1.dwZBufferBitDepth = 32;
209 DDPixelFormat->u2.dwStencilBitDepth = 8;
210 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
211 DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
212 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
213 break;
215 case WINED3DFMT_X8D24_UNORM:
216 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
217 DDPixelFormat->dwFourCC = 0;
218 DDPixelFormat->u1.dwZBufferBitDepth = 32;
219 DDPixelFormat->u2.dwStencilBitDepth = 0;
220 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
221 DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
222 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
223 break;
225 case WINED3DFMT_S1_UINT_D15_UNORM:
226 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
227 DDPixelFormat->dwFourCC = 0;
228 DDPixelFormat->u1.dwZBufferBitDepth = 16;
229 DDPixelFormat->u2.dwStencilBitDepth = 1;
230 DDPixelFormat->u3.dwZBitMask = 0x7fff;
231 DDPixelFormat->u4.dwStencilBitMask = 0x8000;
232 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
233 break;
235 case WINED3DFMT_UYVY:
236 case WINED3DFMT_YUY2:
237 DDPixelFormat->u1.dwYUVBitCount = 16;
238 DDPixelFormat->dwFlags = DDPF_FOURCC;
239 DDPixelFormat->dwFourCC = wined3d_format;
240 break;
242 case WINED3DFMT_YV12:
243 DDPixelFormat->u1.dwYUVBitCount = 12;
244 DDPixelFormat->dwFlags = DDPF_FOURCC;
245 DDPixelFormat->dwFourCC = wined3d_format;
246 break;
248 case WINED3DFMT_DXT1:
249 case WINED3DFMT_DXT2:
250 case WINED3DFMT_DXT3:
251 case WINED3DFMT_DXT4:
252 case WINED3DFMT_DXT5:
253 case WINED3DFMT_MULTI2_ARGB8:
254 case WINED3DFMT_G8R8_G8B8:
255 case WINED3DFMT_R8G8_B8G8:
256 DDPixelFormat->dwFlags = DDPF_FOURCC;
257 DDPixelFormat->dwFourCC = wined3d_format;
258 break;
260 /* Luminance */
261 case WINED3DFMT_L8_UNORM:
262 DDPixelFormat->dwFlags = DDPF_LUMINANCE;
263 DDPixelFormat->dwFourCC = 0;
264 DDPixelFormat->u1.dwLuminanceBitCount = 8;
265 DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
266 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
267 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
268 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
269 break;
271 case WINED3DFMT_L4A4_UNORM:
272 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
273 DDPixelFormat->dwFourCC = 0;
274 DDPixelFormat->u1.dwLuminanceBitCount = 4;
275 DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
276 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
277 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
278 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
279 break;
281 case WINED3DFMT_L8A8_UNORM:
282 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
283 DDPixelFormat->dwFourCC = 0;
284 DDPixelFormat->u1.dwLuminanceBitCount = 16;
285 DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
286 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
287 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
288 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
289 break;
291 /* Bump mapping */
292 case WINED3DFMT_R8G8_SNORM:
293 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
294 DDPixelFormat->dwFourCC = 0;
295 DDPixelFormat->u1.dwBumpBitCount = 16;
296 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
297 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
298 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00000000;
299 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
300 break;
302 case WINED3DFMT_R16G16_SNORM:
303 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
304 DDPixelFormat->dwFourCC = 0;
305 DDPixelFormat->u1.dwBumpBitCount = 32;
306 DDPixelFormat->u2.dwBumpDuBitMask = 0x0000ffff;
307 DDPixelFormat->u3.dwBumpDvBitMask = 0xffff0000;
308 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00000000;
309 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
310 break;
312 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
313 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
314 DDPixelFormat->dwFourCC = 0;
315 DDPixelFormat->u1.dwBumpBitCount = 16;
316 DDPixelFormat->u2.dwBumpDuBitMask = 0x0000001f;
317 DDPixelFormat->u3.dwBumpDvBitMask = 0x000003e0;
318 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0000fc00;
319 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
320 break;
322 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
323 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
324 DDPixelFormat->dwFourCC = 0;
325 DDPixelFormat->u1.dwBumpBitCount = 32;
326 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
327 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
328 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00ff0000;
329 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
330 break;
332 default:
333 FIXME("Unhandled wined3d format %#x.\n", wined3d_format);
334 break;
337 if(TRACE_ON(ddraw)) {
338 TRACE("Returning: ");
339 DDRAW_dump_pixelformat(DDPixelFormat);
343 enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *DDPixelFormat)
345 TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");
346 if(TRACE_ON(ddraw))
348 DDRAW_dump_pixelformat(DDPixelFormat);
351 if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
353 return WINED3DFMT_P8_UINT;
355 else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
357 FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
358 return WINED3DFMT_P8_UINT;
360 else if(DDPixelFormat->dwFlags & DDPF_RGB)
362 switch(DDPixelFormat->u1.dwRGBBitCount)
364 case 8:
365 /* This is the only format that can match here */
366 return WINED3DFMT_B2G3R3_UNORM;
368 case 16:
369 /* Read the Color masks */
370 if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
371 (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
372 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
374 return WINED3DFMT_B5G6R5_UNORM;
377 if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
378 (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
379 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
381 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
382 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
383 return WINED3DFMT_B5G5R5A1_UNORM;
384 else
385 return WINED3DFMT_B5G5R5X1_UNORM;
388 if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
389 (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
390 (DDPixelFormat->u4.dwBBitMask == 0x000F) )
392 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
393 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
394 return WINED3DFMT_B4G4R4A4_UNORM;
395 else
396 return WINED3DFMT_B4G4R4X4_UNORM;
399 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
400 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
401 (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
402 (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
403 (DDPixelFormat->u4.dwBBitMask == 0x0003) )
405 return WINED3DFMT_B2G3R3A8_UNORM;
407 WARN("16 bit RGB Pixel format does not match.\n");
408 return WINED3DFMT_UNKNOWN;
410 case 24:
411 return WINED3DFMT_B8G8R8_UNORM;
413 case 32:
414 /* Read the Color masks */
415 if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
416 (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
417 (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
419 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
420 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
421 return WINED3DFMT_B8G8R8A8_UNORM;
422 else
423 return WINED3DFMT_B8G8R8X8_UNORM;
426 WARN("32 bit RGB pixel format does not match.\n");
427 return WINED3DFMT_UNKNOWN;
429 default:
430 WARN("Invalid dwRGBBitCount in Pixelformat structure.\n");
431 return WINED3DFMT_UNKNOWN;
434 else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
436 /* Alpha only Pixelformat */
437 switch(DDPixelFormat->u1.dwAlphaBitDepth)
439 case 8:
440 return WINED3DFMT_A8_UNORM;
442 default:
443 WARN("Invalid AlphaBitDepth in Alpha-Only Pixelformat.\n");
444 return WINED3DFMT_UNKNOWN;
447 else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
449 /* Luminance-only or luminance-alpha */
450 if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
452 /* Luminance with Alpha */
453 switch(DDPixelFormat->u1.dwLuminanceBitCount)
455 case 4:
456 if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
457 return WINED3DFMT_L4A4_UNORM;
458 WARN("Unknown Alpha / Luminance bit depth combination.\n");
459 return WINED3DFMT_UNKNOWN;
461 case 6:
462 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
463 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
465 case 8:
466 if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
467 return WINED3DFMT_L8A8_UNORM;
468 WARN("Unknown Alpha / Lumincase bit depth combination.\n");
469 return WINED3DFMT_UNKNOWN;
472 else
474 /* Luminance-only */
475 switch(DDPixelFormat->u1.dwLuminanceBitCount)
477 case 6:
478 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
479 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
481 case 8:
482 return WINED3DFMT_L8_UNORM;
484 default:
485 WARN("Unknown luminance-only bit depth 0x%x.\n", DDPixelFormat->u1.dwLuminanceBitCount);
486 return WINED3DFMT_UNKNOWN;
490 else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
492 /* Z buffer */
493 if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
495 switch(DDPixelFormat->u1.dwZBufferBitDepth)
497 case 16:
498 if (DDPixelFormat->u2.dwStencilBitDepth == 1) return WINED3DFMT_S1_UINT_D15_UNORM;
499 WARN("Unknown depth stenil format: 16 z bits, %u stencil bits\n",
500 DDPixelFormat->u2.dwStencilBitDepth);
501 return WINED3DFMT_UNKNOWN;
503 case 32:
504 if (DDPixelFormat->u2.dwStencilBitDepth == 8) return WINED3DFMT_D24_UNORM_S8_UINT;
505 else if (DDPixelFormat->u2.dwStencilBitDepth == 4) return WINED3DFMT_S4X4_UINT_D24_UNORM;
506 WARN("Unknown depth stenil format: 32 z bits, %u stencil bits\n",
507 DDPixelFormat->u2.dwStencilBitDepth);
508 return WINED3DFMT_UNKNOWN;
510 default:
511 WARN("Unknown depth stenil format: %u z bits, %u stencil bits\n",
512 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u2.dwStencilBitDepth);
513 return WINED3DFMT_UNKNOWN;
516 else
518 switch(DDPixelFormat->u1.dwZBufferBitDepth)
520 case 16:
521 return WINED3DFMT_D16_UNORM;
523 case 24:
524 return WINED3DFMT_X8D24_UNORM;
526 case 32:
527 if (DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) return WINED3DFMT_X8D24_UNORM;
528 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFF00) return WINED3DFMT_X8D24_UNORM;
529 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) return WINED3DFMT_D32_UNORM;
530 WARN("Unknown depth-only format: 32 z bits, mask 0x%08x\n",
531 DDPixelFormat->u3.dwZBitMask);
532 return WINED3DFMT_UNKNOWN;
534 default:
535 WARN("Unknown depth-only format: %u z bits, mask 0x%08x\n",
536 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u3.dwZBitMask);
537 return WINED3DFMT_UNKNOWN;
541 else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
543 return DDPixelFormat->dwFourCC;
545 else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
547 if( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
548 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
549 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
550 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
552 return WINED3DFMT_R8G8_SNORM;
554 else if ( (DDPixelFormat->u1.dwBumpBitCount == 32 ) &&
555 (DDPixelFormat->u2.dwBumpDuBitMask == 0x0000ffff) &&
556 (DDPixelFormat->u3.dwBumpDvBitMask == 0xffff0000) &&
557 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
559 return WINED3DFMT_R16G16_SNORM;
561 else if ( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
562 (DDPixelFormat->u2.dwBumpDuBitMask == 0x0000001f) &&
563 (DDPixelFormat->u3.dwBumpDvBitMask == 0x000003e0) &&
564 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
566 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
568 else if ( (DDPixelFormat->u1.dwBumpBitCount == 32 ) &&
569 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
570 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
571 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00ff0000) )
573 return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
577 WARN("Unknown Pixelformat.\n");
578 return WINED3DFMT_UNKNOWN;
581 /*****************************************************************************
582 * Various dumping functions.
584 * They write the contents of a specific function to a TRACE.
586 *****************************************************************************/
587 static void
588 DDRAW_dump_DWORD(const void *in)
590 TRACE("%d\n", *((const DWORD *) in));
592 static void
593 DDRAW_dump_PTR(const void *in)
595 TRACE("%p\n", *((const void * const*) in));
597 static void
598 DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
600 TRACE("Low : 0x%08x - High : 0x%08x\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
603 static void DDRAW_dump_flags_nolf(DWORD flags, const struct flag_info *names, size_t num_names)
605 unsigned int i;
607 for (i=0; i < num_names; i++)
608 if ((flags & names[i].val) || /* standard flag value */
609 ((!flags) && (!names[i].val))) /* zero value only */
610 TRACE("%s ", names[i].name);
613 static void DDRAW_dump_flags(DWORD flags, const struct flag_info *names, size_t num_names)
615 DDRAW_dump_flags_nolf(flags, names, num_names);
616 TRACE("\n");
619 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
621 static const struct flag_info flags[] =
623 FE(DDSCAPS_RESERVED1),
624 FE(DDSCAPS_ALPHA),
625 FE(DDSCAPS_BACKBUFFER),
626 FE(DDSCAPS_COMPLEX),
627 FE(DDSCAPS_FLIP),
628 FE(DDSCAPS_FRONTBUFFER),
629 FE(DDSCAPS_OFFSCREENPLAIN),
630 FE(DDSCAPS_OVERLAY),
631 FE(DDSCAPS_PALETTE),
632 FE(DDSCAPS_PRIMARYSURFACE),
633 FE(DDSCAPS_PRIMARYSURFACELEFT),
634 FE(DDSCAPS_SYSTEMMEMORY),
635 FE(DDSCAPS_TEXTURE),
636 FE(DDSCAPS_3DDEVICE),
637 FE(DDSCAPS_VIDEOMEMORY),
638 FE(DDSCAPS_VISIBLE),
639 FE(DDSCAPS_WRITEONLY),
640 FE(DDSCAPS_ZBUFFER),
641 FE(DDSCAPS_OWNDC),
642 FE(DDSCAPS_LIVEVIDEO),
643 FE(DDSCAPS_HWCODEC),
644 FE(DDSCAPS_MODEX),
645 FE(DDSCAPS_MIPMAP),
646 FE(DDSCAPS_RESERVED2),
647 FE(DDSCAPS_ALLOCONLOAD),
648 FE(DDSCAPS_VIDEOPORT),
649 FE(DDSCAPS_LOCALVIDMEM),
650 FE(DDSCAPS_NONLOCALVIDMEM),
651 FE(DDSCAPS_STANDARDVGAMODE),
652 FE(DDSCAPS_OPTIMIZED)
654 static const struct flag_info flags2[] =
656 FE(DDSCAPS2_HARDWAREDEINTERLACE),
657 FE(DDSCAPS2_HINTDYNAMIC),
658 FE(DDSCAPS2_HINTSTATIC),
659 FE(DDSCAPS2_TEXTUREMANAGE),
660 FE(DDSCAPS2_RESERVED1),
661 FE(DDSCAPS2_RESERVED2),
662 FE(DDSCAPS2_OPAQUE),
663 FE(DDSCAPS2_HINTANTIALIASING),
664 FE(DDSCAPS2_CUBEMAP),
665 FE(DDSCAPS2_CUBEMAP_POSITIVEX),
666 FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
667 FE(DDSCAPS2_CUBEMAP_POSITIVEY),
668 FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
669 FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
670 FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
671 FE(DDSCAPS2_MIPMAPSUBLEVEL),
672 FE(DDSCAPS2_D3DTEXTUREMANAGE),
673 FE(DDSCAPS2_DONOTPERSIST),
674 FE(DDSCAPS2_STEREOSURFACELEFT)
677 DDRAW_dump_flags_nolf(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
678 DDRAW_dump_flags(in->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
681 static void
682 DDRAW_dump_DDSCAPS(const DDSCAPS *in)
684 DDSCAPS2 in_bis;
686 in_bis.dwCaps = in->dwCaps;
687 in_bis.dwCaps2 = 0;
688 in_bis.dwCaps3 = 0;
689 in_bis.dwCaps4 = 0;
691 DDRAW_dump_DDSCAPS2(&in_bis);
694 static void
695 DDRAW_dump_pixelformat_flag(DWORD flagmask)
697 static const struct flag_info flags[] =
699 FE(DDPF_ALPHAPIXELS),
700 FE(DDPF_ALPHA),
701 FE(DDPF_FOURCC),
702 FE(DDPF_PALETTEINDEXED4),
703 FE(DDPF_PALETTEINDEXEDTO8),
704 FE(DDPF_PALETTEINDEXED8),
705 FE(DDPF_RGB),
706 FE(DDPF_COMPRESSED),
707 FE(DDPF_RGBTOYUV),
708 FE(DDPF_YUV),
709 FE(DDPF_ZBUFFER),
710 FE(DDPF_PALETTEINDEXED1),
711 FE(DDPF_PALETTEINDEXED2),
712 FE(DDPF_ZPIXELS)
715 DDRAW_dump_flags_nolf(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
718 static void DDRAW_dump_members(DWORD flags, const void *data, const struct member_info *mems, size_t num_mems)
720 unsigned int i;
722 for (i=0; i < num_mems; i++)
724 if (mems[i].val & flags)
726 TRACE(" - %s : ", mems[i].name);
727 mems[i].func((const char *)data + mems[i].offset);
732 static void
733 DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
735 TRACE("( ");
736 DDRAW_dump_pixelformat_flag(pf->dwFlags);
737 if (pf->dwFlags & DDPF_FOURCC)
738 TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %u bits per pixel",
739 (unsigned char)( pf->dwFourCC &0xff),
740 (unsigned char)((pf->dwFourCC>> 8)&0xff),
741 (unsigned char)((pf->dwFourCC>>16)&0xff),
742 (unsigned char)((pf->dwFourCC>>24)&0xff),
743 pf->dwFourCC,
744 pf->u1.dwYUVBitCount);
745 if (pf->dwFlags & DDPF_RGB)
747 TRACE(", RGB bits: %u, R 0x%08x G 0x%08x B 0x%08x",
748 pf->u1.dwRGBBitCount,
749 pf->u2.dwRBitMask,
750 pf->u3.dwGBitMask,
751 pf->u4.dwBBitMask);
752 if (pf->dwFlags & DDPF_ALPHAPIXELS)
753 TRACE(" A 0x%08x", pf->u5.dwRGBAlphaBitMask);
754 if (pf->dwFlags & DDPF_ZPIXELS)
755 TRACE(" Z 0x%08x", pf->u5.dwRGBZBitMask);
757 if (pf->dwFlags & DDPF_ZBUFFER)
758 TRACE(", Z bits: %u", pf->u1.dwZBufferBitDepth);
759 if (pf->dwFlags & DDPF_ALPHA)
760 TRACE(", Alpha bits: %u", pf->u1.dwAlphaBitDepth);
761 if (pf->dwFlags & DDPF_BUMPDUDV)
762 TRACE(", Bump bits: %u, U 0x%08x V 0x%08x L 0x%08x",
763 pf->u1.dwBumpBitCount,
764 pf->u2.dwBumpDuBitMask,
765 pf->u3.dwBumpDvBitMask,
766 pf->u4.dwBumpLuminanceBitMask);
767 TRACE(")\n");
770 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
772 #define STRUCT DDSURFACEDESC2
773 static const struct member_info members[] =
775 ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
776 ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
777 ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
778 ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
779 ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
780 ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
781 ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
782 ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
783 ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
784 ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
785 ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
786 ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
787 ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
788 ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
789 ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
791 static const struct member_info members_caps[] =
793 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
795 static const struct member_info members_caps2[] =
797 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
799 #undef STRUCT
801 if (NULL == lpddsd)
803 TRACE("(null)\n");
805 else
807 if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
809 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
811 else
813 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
815 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
816 sizeof(members)/sizeof(members[0]));
820 void
821 dump_D3DMATRIX(const D3DMATRIX *mat)
823 TRACE(" %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
824 TRACE(" %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
825 TRACE(" %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
826 TRACE(" %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
829 DWORD
830 get_flexible_vertex_size(DWORD d3dvtVertexType)
832 DWORD size = 0;
833 DWORD i;
835 if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
836 if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
837 if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
838 if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
839 switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
841 case D3DFVF_XYZ: size += 3 * sizeof(D3DVALUE); break;
842 case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
843 case D3DFVF_XYZB1: size += 4 * sizeof(D3DVALUE); break;
844 case D3DFVF_XYZB2: size += 5 * sizeof(D3DVALUE); break;
845 case D3DFVF_XYZB3: size += 6 * sizeof(D3DVALUE); break;
846 case D3DFVF_XYZB4: size += 7 * sizeof(D3DVALUE); break;
847 case D3DFVF_XYZB5: size += 8 * sizeof(D3DVALUE); break;
848 default: ERR("Unexpected position mask\n");
850 for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
852 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
855 return size;
858 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
860 /* 2 adds three additional caps fields to the end. Both versions
861 * are unversioned. */
862 pOut->dwCaps = pIn->dwCaps;
863 pOut->dwCaps2 = 0;
864 pOut->dwCaps3 = 0;
865 pOut->dwCaps4 = 0;
868 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
870 /* 2 adds a dwWHQLLevel field to the end. Both structures are
871 * unversioned. */
872 memcpy(pOut, pIn, sizeof(*pOut));
875 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
877 static const struct flag_info flags[] =
879 FE(DDSCL_FULLSCREEN),
880 FE(DDSCL_ALLOWREBOOT),
881 FE(DDSCL_NOWINDOWCHANGES),
882 FE(DDSCL_NORMAL),
883 FE(DDSCL_ALLOWMODEX),
884 FE(DDSCL_EXCLUSIVE),
885 FE(DDSCL_SETFOCUSWINDOW),
886 FE(DDSCL_SETDEVICEWINDOW),
887 FE(DDSCL_CREATEDEVICEWINDOW)
890 if (TRACE_ON(ddraw))
892 TRACE(" - ");
893 DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));
897 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
899 static const struct flag_info flags1[] =
901 FE(DDCAPS_3D),
902 FE(DDCAPS_ALIGNBOUNDARYDEST),
903 FE(DDCAPS_ALIGNSIZEDEST),
904 FE(DDCAPS_ALIGNBOUNDARYSRC),
905 FE(DDCAPS_ALIGNSIZESRC),
906 FE(DDCAPS_ALIGNSTRIDE),
907 FE(DDCAPS_BLT),
908 FE(DDCAPS_BLTQUEUE),
909 FE(DDCAPS_BLTFOURCC),
910 FE(DDCAPS_BLTSTRETCH),
911 FE(DDCAPS_GDI),
912 FE(DDCAPS_OVERLAY),
913 FE(DDCAPS_OVERLAYCANTCLIP),
914 FE(DDCAPS_OVERLAYFOURCC),
915 FE(DDCAPS_OVERLAYSTRETCH),
916 FE(DDCAPS_PALETTE),
917 FE(DDCAPS_PALETTEVSYNC),
918 FE(DDCAPS_READSCANLINE),
919 FE(DDCAPS_STEREOVIEW),
920 FE(DDCAPS_VBI),
921 FE(DDCAPS_ZBLTS),
922 FE(DDCAPS_ZOVERLAYS),
923 FE(DDCAPS_COLORKEY),
924 FE(DDCAPS_ALPHA),
925 FE(DDCAPS_COLORKEYHWASSIST),
926 FE(DDCAPS_NOHARDWARE),
927 FE(DDCAPS_BLTCOLORFILL),
928 FE(DDCAPS_BANKSWITCHED),
929 FE(DDCAPS_BLTDEPTHFILL),
930 FE(DDCAPS_CANCLIP),
931 FE(DDCAPS_CANCLIPSTRETCHED),
932 FE(DDCAPS_CANBLTSYSMEM)
934 static const struct flag_info flags2[] =
936 FE(DDCAPS2_CERTIFIED),
937 FE(DDCAPS2_NO2DDURING3DSCENE),
938 FE(DDCAPS2_VIDEOPORT),
939 FE(DDCAPS2_AUTOFLIPOVERLAY),
940 FE(DDCAPS2_CANBOBINTERLEAVED),
941 FE(DDCAPS2_CANBOBNONINTERLEAVED),
942 FE(DDCAPS2_COLORCONTROLOVERLAY),
943 FE(DDCAPS2_COLORCONTROLPRIMARY),
944 FE(DDCAPS2_CANDROPZ16BIT),
945 FE(DDCAPS2_NONLOCALVIDMEM),
946 FE(DDCAPS2_NONLOCALVIDMEMCAPS),
947 FE(DDCAPS2_NOPAGELOCKREQUIRED),
948 FE(DDCAPS2_WIDESURFACES),
949 FE(DDCAPS2_CANFLIPODDEVEN),
950 FE(DDCAPS2_CANBOBHARDWARE),
951 FE(DDCAPS2_COPYFOURCC),
952 FE(DDCAPS2_PRIMARYGAMMA),
953 FE(DDCAPS2_CANRENDERWINDOWED),
954 FE(DDCAPS2_CANCALIBRATEGAMMA),
955 FE(DDCAPS2_FLIPINTERVAL),
956 FE(DDCAPS2_FLIPNOVSYNC),
957 FE(DDCAPS2_CANMANAGETEXTURE),
958 FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
959 FE(DDCAPS2_STEREO),
960 FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
962 static const struct flag_info flags3[] =
964 FE(DDCKEYCAPS_DESTBLT),
965 FE(DDCKEYCAPS_DESTBLTCLRSPACE),
966 FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
967 FE(DDCKEYCAPS_DESTBLTYUV),
968 FE(DDCKEYCAPS_DESTOVERLAY),
969 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
970 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
971 FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
972 FE(DDCKEYCAPS_DESTOVERLAYYUV),
973 FE(DDCKEYCAPS_SRCBLT),
974 FE(DDCKEYCAPS_SRCBLTCLRSPACE),
975 FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
976 FE(DDCKEYCAPS_SRCBLTYUV),
977 FE(DDCKEYCAPS_SRCOVERLAY),
978 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
979 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
980 FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
981 FE(DDCKEYCAPS_SRCOVERLAYYUV),
982 FE(DDCKEYCAPS_NOCOSTOVERLAY)
984 static const struct flag_info flags4[] =
986 FE(DDFXCAPS_BLTALPHA),
987 FE(DDFXCAPS_OVERLAYALPHA),
988 FE(DDFXCAPS_BLTARITHSTRETCHYN),
989 FE(DDFXCAPS_BLTARITHSTRETCHY),
990 FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
991 FE(DDFXCAPS_BLTMIRRORUPDOWN),
992 FE(DDFXCAPS_BLTROTATION),
993 FE(DDFXCAPS_BLTROTATION90),
994 FE(DDFXCAPS_BLTSHRINKX),
995 FE(DDFXCAPS_BLTSHRINKXN),
996 FE(DDFXCAPS_BLTSHRINKY),
997 FE(DDFXCAPS_BLTSHRINKYN),
998 FE(DDFXCAPS_BLTSTRETCHX),
999 FE(DDFXCAPS_BLTSTRETCHXN),
1000 FE(DDFXCAPS_BLTSTRETCHY),
1001 FE(DDFXCAPS_BLTSTRETCHYN),
1002 FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
1003 FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
1004 FE(DDFXCAPS_OVERLAYSHRINKX),
1005 FE(DDFXCAPS_OVERLAYSHRINKXN),
1006 FE(DDFXCAPS_OVERLAYSHRINKY),
1007 FE(DDFXCAPS_OVERLAYSHRINKYN),
1008 FE(DDFXCAPS_OVERLAYSTRETCHX),
1009 FE(DDFXCAPS_OVERLAYSTRETCHXN),
1010 FE(DDFXCAPS_OVERLAYSTRETCHY),
1011 FE(DDFXCAPS_OVERLAYSTRETCHYN),
1012 FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
1013 FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
1015 static const struct flag_info flags5[] =
1017 FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
1018 FE(DDFXALPHACAPS_BLTALPHAPIXELS),
1019 FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
1020 FE(DDFXALPHACAPS_BLTALPHASURFACES),
1021 FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
1022 FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
1023 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
1024 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
1025 FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
1026 FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
1028 static const struct flag_info flags6[] =
1030 FE(DDPCAPS_4BIT),
1031 FE(DDPCAPS_8BITENTRIES),
1032 FE(DDPCAPS_8BIT),
1033 FE(DDPCAPS_INITIALIZE),
1034 FE(DDPCAPS_PRIMARYSURFACE),
1035 FE(DDPCAPS_PRIMARYSURFACELEFT),
1036 FE(DDPCAPS_ALLOW256),
1037 FE(DDPCAPS_VSYNC),
1038 FE(DDPCAPS_1BIT),
1039 FE(DDPCAPS_2BIT),
1040 FE(DDPCAPS_ALPHA),
1042 static const struct flag_info flags7[] =
1044 FE(DDSVCAPS_RESERVED1),
1045 FE(DDSVCAPS_RESERVED2),
1046 FE(DDSVCAPS_RESERVED3),
1047 FE(DDSVCAPS_RESERVED4),
1048 FE(DDSVCAPS_STEREOSEQUENTIAL),
1051 TRACE(" - dwSize : %d\n", lpcaps->dwSize);
1052 TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, sizeof(flags1)/sizeof(flags1[0]));
1053 TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
1054 TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, sizeof(flags3)/sizeof(flags3[0]));
1055 TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, sizeof(flags4)/sizeof(flags4[0]));
1056 TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, sizeof(flags5)/sizeof(flags5[0]));
1057 TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, sizeof(flags6)/sizeof(flags6[0]));
1058 TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, sizeof(flags7)/sizeof(flags7[0]));
1059 TRACE("...\n");
1060 TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
1061 TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
1062 TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
1063 TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
1064 TRACE("...\n");
1065 TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1068 /*****************************************************************************
1069 * multiply_matrix
1071 * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
1073 * Params:
1074 * dest: Pointer to the destination matrix
1075 * src1: Pointer to the first source matrix
1076 * src2: Pointer to the second source matrix
1078 *****************************************************************************/
1079 void
1080 multiply_matrix(D3DMATRIX *dest,
1081 const D3DMATRIX *src1,
1082 const D3DMATRIX *src2)
1084 D3DMATRIX temp;
1086 /* Now do the multiplication 'by hand'.
1087 I know that all this could be optimised, but this will be done later :-) */
1088 temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
1089 temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
1090 temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
1091 temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
1093 temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
1094 temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
1095 temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
1096 temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
1098 temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
1099 temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
1100 temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
1101 temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
1103 temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
1104 temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
1105 temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
1106 temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
1108 /* And copy the new matrix in the good storage.. */
1109 memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
1112 HRESULT
1113 hr_ddraw_from_wined3d(HRESULT hr)
1115 switch(hr)
1117 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1118 default: return hr;
1122 /* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it
1123 * for writing into application-provided DDSURFACEDESC2 structures if the size may
1124 * be different */
1125 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
1127 /* The output of this function is never passed to the application directly, so
1128 * the memset is not strictly needed. CreateSurface still has problems with this
1129 * though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */
1130 memset(out, 0x00, sizeof(*out));
1131 out->dwSize = sizeof(*out);
1132 out->dwFlags = in->dwFlags & ~DDSD_ZBUFFERBITDEPTH;
1133 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1134 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1135 if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
1136 else if(in->dwFlags & DDSD_ZBUFFERBITDEPTH)
1138 out->dwFlags |= DDSD_PIXELFORMAT;
1139 memset(&out->u4.ddpfPixelFormat, 0, sizeof(out->u4.ddpfPixelFormat));
1140 out->u4.ddpfPixelFormat.dwSize = sizeof(out->u4.ddpfPixelFormat);
1141 out->u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
1142 out->u4.ddpfPixelFormat.u1.dwZBufferBitDepth = in->u2.dwZBufferBitDepth;
1143 /* 0 is not a valid DDSURFACEDESC / DDPIXELFORMAT on either side of the
1144 * conversion */
1145 out->u4.ddpfPixelFormat.u3.dwZBitMask = ~0U >> (32 - in->u2.dwZBufferBitDepth);
1147 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1148 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1149 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1150 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
1151 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1152 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1153 out->lpSurface = in->lpSurface;
1154 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
1155 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1156 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1157 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1158 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1159 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1160 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1161 /* Does not exist in DDSURFACEDESC:
1162 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1166 /* Note that this function writes the full sizeof(DDSURFACEDESC) size, don't use it
1167 * for writing into application-provided DDSURFACEDESC structures if the size may
1168 * be different */
1169 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
1171 memset(out, 0, sizeof(*out));
1172 out->dwSize = sizeof(*out);
1173 out->dwFlags = in->dwFlags;
1174 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1175 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1176 if (in->dwFlags & DDSD_PIXELFORMAT)
1178 out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
1179 if ((in->dwFlags & DDSD_CAPS) && (in->ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
1181 /* Z buffers have DDSD_ZBUFFERBITDEPTH set, but not DDSD_PIXELFORMAT. They do
1182 * have valid data in ddpfPixelFormat though */
1183 out->dwFlags &= ~DDSD_PIXELFORMAT;
1184 out->dwFlags |= DDSD_ZBUFFERBITDEPTH;
1185 out->u2.dwZBufferBitDepth = in->u4.ddpfPixelFormat.u1.dwZBufferBitDepth;
1188 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1189 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1190 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1191 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
1192 if (in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
1193 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1194 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1195 out->lpSurface = in->lpSurface;
1196 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
1197 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1198 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1199 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1200 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1201 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1202 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1203 /* Does not exist in DDSURFACEDESC:
1204 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1206 if (in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
1207 if (in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
1208 if (in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
1209 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);