ddraw: Rename PixelFormat_DD2WineD3D() to wined3dformat_from_ddrawformat().
[wine/multimedia.git] / dlls / ddraw / utils.c
blobc605c743ec3a10b29180d3a9e45c10521a106936
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 /*****************************************************************************
34 * PixelFormat_WineD3DtoDD
36 * Converts an wined3d format ID into a DDPIXELFORMAT structure
38 * Params:
39 * DDPixelFormat: Address of the structure to write the pixel format to
40 * WineD3DFormat: Source format
42 *****************************************************************************/
43 void PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_id WineD3DFormat)
45 DWORD Size = DDPixelFormat->dwSize;
46 TRACE("Converting wined3d format %#x to DDRAW.\n", WineD3DFormat);
48 if(Size==0) return;
50 memset(DDPixelFormat, 0x00, Size);
51 DDPixelFormat->dwSize = Size;
52 switch(WineD3DFormat)
54 case WINED3DFMT_B8G8R8_UNORM:
55 DDPixelFormat->dwFlags = DDPF_RGB;
56 DDPixelFormat->dwFourCC = 0;
57 DDPixelFormat->u1.dwRGBBitCount = 24;
58 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
59 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
60 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
61 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
62 break;
64 case WINED3DFMT_B8G8R8A8_UNORM:
65 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
66 DDPixelFormat->dwFourCC = 0;
67 DDPixelFormat->u1.dwRGBBitCount = 32;
68 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
69 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
70 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
71 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
72 break;
74 case WINED3DFMT_B8G8R8X8_UNORM:
75 DDPixelFormat->dwFlags = DDPF_RGB;
76 DDPixelFormat->dwFourCC = 0;
77 DDPixelFormat->u1.dwRGBBitCount = 32;
78 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
79 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
80 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
81 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
82 break;
84 case WINED3DFMT_R8G8B8X8_UNORM:
85 DDPixelFormat->dwFlags = DDPF_RGB;
86 DDPixelFormat->dwFourCC = 0;
87 DDPixelFormat->u1.dwRGBBitCount = 32;
88 DDPixelFormat->u2.dwRBitMask = 0x000000ff;
89 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
90 DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
91 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
92 break;
94 case WINED3DFMT_B5G6R5_UNORM:
95 DDPixelFormat->dwFlags = DDPF_RGB;
96 DDPixelFormat->dwFourCC = 0;
97 DDPixelFormat->u1.dwRGBBitCount = 16;
98 DDPixelFormat->u2.dwRBitMask = 0xF800;
99 DDPixelFormat->u3.dwGBitMask = 0x07E0;
100 DDPixelFormat->u4.dwBBitMask = 0x001F;
101 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
102 break;
104 case WINED3DFMT_B5G5R5X1_UNORM:
105 DDPixelFormat->dwFlags = DDPF_RGB;
106 DDPixelFormat->dwFourCC = 0;
107 DDPixelFormat->u1.dwRGBBitCount = 16;
108 DDPixelFormat->u2.dwRBitMask = 0x7C00;
109 DDPixelFormat->u3.dwGBitMask = 0x03E0;
110 DDPixelFormat->u4.dwBBitMask = 0x001F;
111 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
112 break;
114 case WINED3DFMT_B5G5R5A1_UNORM:
115 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
116 DDPixelFormat->dwFourCC = 0;
117 DDPixelFormat->u1.dwRGBBitCount = 16;
118 DDPixelFormat->u2.dwRBitMask = 0x7C00;
119 DDPixelFormat->u3.dwGBitMask = 0x03E0;
120 DDPixelFormat->u4.dwBBitMask = 0x001F;
121 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
122 break;
124 case WINED3DFMT_B4G4R4A4_UNORM:
125 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
126 DDPixelFormat->dwFourCC = 0;
127 DDPixelFormat->u1.dwRGBBitCount = 16;
128 DDPixelFormat->u2.dwRBitMask = 0x0F00;
129 DDPixelFormat->u3.dwGBitMask = 0x00F0;
130 DDPixelFormat->u4.dwBBitMask = 0x000F;
131 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
132 break;
134 case WINED3DFMT_B2G3R3_UNORM:
135 DDPixelFormat->dwFlags = DDPF_RGB;
136 DDPixelFormat->dwFourCC = 0;
137 DDPixelFormat->u1.dwRGBBitCount = 8;
138 DDPixelFormat->u2.dwRBitMask = 0xE0;
139 DDPixelFormat->u3.dwGBitMask = 0x1C;
140 DDPixelFormat->u4.dwBBitMask = 0x03;
141 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
142 break;
144 case WINED3DFMT_P8_UINT:
145 DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
146 DDPixelFormat->dwFourCC = 0;
147 DDPixelFormat->u1.dwRGBBitCount = 8;
148 DDPixelFormat->u2.dwRBitMask = 0x00;
149 DDPixelFormat->u3.dwGBitMask = 0x00;
150 DDPixelFormat->u4.dwBBitMask = 0x00;
151 break;
153 case WINED3DFMT_A8_UNORM:
154 DDPixelFormat->dwFlags = DDPF_ALPHA;
155 DDPixelFormat->dwFourCC = 0;
156 DDPixelFormat->u1.dwAlphaBitDepth = 8;
157 DDPixelFormat->u2.dwRBitMask = 0x0;
158 DDPixelFormat->u3.dwZBitMask = 0x0;
159 DDPixelFormat->u4.dwStencilBitMask = 0x0;
160 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
161 break;
163 case WINED3DFMT_B2G3R3A8_UNORM:
164 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
165 DDPixelFormat->dwFourCC = 0;
166 DDPixelFormat->u1.dwRGBBitCount = 16;
167 DDPixelFormat->u2.dwRBitMask = 0x00E0;
168 DDPixelFormat->u3.dwGBitMask = 0x001C;
169 DDPixelFormat->u4.dwBBitMask = 0x0003;
170 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xFF00;
171 break;
173 case WINED3DFMT_B4G4R4X4_UNORM:
174 DDPixelFormat->dwFlags = DDPF_RGB;
175 DDPixelFormat->dwFourCC = 0;
176 DDPixelFormat->u1.dwRGBBitCount = 16;
177 DDPixelFormat->u2.dwRBitMask = 0x0F00;
178 DDPixelFormat->u3.dwGBitMask = 0x00F0;
179 DDPixelFormat->u4.dwBBitMask = 0x000F;
180 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
181 break;
183 /* How are Z buffer bit depth and Stencil buffer bit depth related?
185 case WINED3DFMT_D16_UNORM:
186 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
187 DDPixelFormat->dwFourCC = 0;
188 DDPixelFormat->u1.dwZBufferBitDepth = 16;
189 DDPixelFormat->u2.dwStencilBitDepth = 0;
190 DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
191 DDPixelFormat->u4.dwStencilBitMask = 0x0;
192 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
193 break;
195 case WINED3DFMT_D32_UNORM:
196 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
197 DDPixelFormat->dwFourCC = 0;
198 DDPixelFormat->u1.dwZBufferBitDepth = 32;
199 DDPixelFormat->u2.dwStencilBitDepth = 0;
200 DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
201 DDPixelFormat->u4.dwStencilBitMask = 0x0;
202 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
203 break;
205 case WINED3DFMT_S4X4_UINT_D24_UNORM:
206 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
207 DDPixelFormat->dwFourCC = 0;
208 /* Should I set dwZBufferBitDepth to 32 here? */
209 DDPixelFormat->u1.dwZBufferBitDepth = 32;
210 DDPixelFormat->u2.dwStencilBitDepth = 4;
211 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
212 DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
213 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
214 break;
216 case WINED3DFMT_D24_UNORM_S8_UINT:
217 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
218 DDPixelFormat->dwFourCC = 0;
219 DDPixelFormat->u1.dwZBufferBitDepth = 32;
220 DDPixelFormat->u2.dwStencilBitDepth = 8;
221 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
222 DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
223 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
224 break;
226 case WINED3DFMT_X8D24_UNORM:
227 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
228 DDPixelFormat->dwFourCC = 0;
229 DDPixelFormat->u1.dwZBufferBitDepth = 32;
230 DDPixelFormat->u2.dwStencilBitDepth = 0;
231 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
232 DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
233 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
234 break;
236 case WINED3DFMT_S1_UINT_D15_UNORM:
237 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
238 DDPixelFormat->dwFourCC = 0;
239 DDPixelFormat->u1.dwZBufferBitDepth = 16;
240 DDPixelFormat->u2.dwStencilBitDepth = 1;
241 DDPixelFormat->u3.dwZBitMask = 0x7fff;
242 DDPixelFormat->u4.dwStencilBitMask = 0x8000;
243 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
244 break;
246 case WINED3DFMT_UYVY:
247 case WINED3DFMT_YUY2:
248 DDPixelFormat->u1.dwYUVBitCount = 16;
249 DDPixelFormat->dwFlags = DDPF_FOURCC;
250 DDPixelFormat->dwFourCC = WineD3DFormat;
251 break;
253 case WINED3DFMT_YV12:
254 DDPixelFormat->u1.dwYUVBitCount = 12;
255 DDPixelFormat->dwFlags = DDPF_FOURCC;
256 DDPixelFormat->dwFourCC = WineD3DFormat;
257 break;
259 case WINED3DFMT_DXT1:
260 case WINED3DFMT_DXT2:
261 case WINED3DFMT_DXT3:
262 case WINED3DFMT_DXT4:
263 case WINED3DFMT_DXT5:
264 case WINED3DFMT_MULTI2_ARGB8:
265 case WINED3DFMT_G8R8_G8B8:
266 case WINED3DFMT_R8G8_B8G8:
267 DDPixelFormat->dwFlags = DDPF_FOURCC;
268 DDPixelFormat->dwFourCC = WineD3DFormat;
269 break;
271 /* Luminance */
272 case WINED3DFMT_L8_UNORM:
273 DDPixelFormat->dwFlags = DDPF_LUMINANCE;
274 DDPixelFormat->dwFourCC = 0;
275 DDPixelFormat->u1.dwLuminanceBitCount = 8;
276 DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
277 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
278 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
279 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
280 break;
282 case WINED3DFMT_L4A4_UNORM:
283 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
284 DDPixelFormat->dwFourCC = 0;
285 DDPixelFormat->u1.dwLuminanceBitCount = 4;
286 DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
287 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
288 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
289 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
290 break;
292 case WINED3DFMT_L8A8_UNORM:
293 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
294 DDPixelFormat->dwFourCC = 0;
295 DDPixelFormat->u1.dwLuminanceBitCount = 16;
296 DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
297 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
298 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
299 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
300 break;
302 /* Bump mapping */
303 case WINED3DFMT_R8G8_SNORM:
304 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
305 DDPixelFormat->dwFourCC = 0;
306 DDPixelFormat->u1.dwBumpBitCount = 16;
307 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
308 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
309 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00000000;
310 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
311 break;
313 case WINED3DFMT_R16G16_SNORM:
314 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
315 DDPixelFormat->dwFourCC = 0;
316 DDPixelFormat->u1.dwBumpBitCount = 32;
317 DDPixelFormat->u2.dwBumpDuBitMask = 0x0000ffff;
318 DDPixelFormat->u3.dwBumpDvBitMask = 0xffff0000;
319 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00000000;
320 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
321 break;
323 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
324 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
325 DDPixelFormat->dwFourCC = 0;
326 DDPixelFormat->u1.dwBumpBitCount = 16;
327 DDPixelFormat->u2.dwBumpDuBitMask = 0x0000001f;
328 DDPixelFormat->u3.dwBumpDvBitMask = 0x000003e0;
329 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0000fc00;
330 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
331 break;
333 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
334 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
335 DDPixelFormat->dwFourCC = 0;
336 DDPixelFormat->u1.dwBumpBitCount = 32;
337 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
338 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
339 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00ff0000;
340 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
341 break;
343 default:
344 ERR("Can't translate this Pixelformat %d\n", WineD3DFormat);
347 if(TRACE_ON(ddraw)) {
348 TRACE("Returning: ");
349 DDRAW_dump_pixelformat(DDPixelFormat);
353 enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *DDPixelFormat)
355 TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");
356 if(TRACE_ON(ddraw))
358 DDRAW_dump_pixelformat(DDPixelFormat);
361 if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
363 return WINED3DFMT_P8_UINT;
365 else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
367 FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
368 return WINED3DFMT_P8_UINT;
370 else if(DDPixelFormat->dwFlags & DDPF_RGB)
372 switch(DDPixelFormat->u1.dwRGBBitCount)
374 case 8:
375 /* This is the only format that can match here */
376 return WINED3DFMT_B2G3R3_UNORM;
378 case 16:
379 /* Read the Color masks */
380 if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
381 (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
382 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
384 return WINED3DFMT_B5G6R5_UNORM;
387 if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
388 (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
389 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
391 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
392 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
393 return WINED3DFMT_B5G5R5A1_UNORM;
394 else
395 return WINED3DFMT_B5G5R5X1_UNORM;
398 if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
399 (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
400 (DDPixelFormat->u4.dwBBitMask == 0x000F) )
402 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
403 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
404 return WINED3DFMT_B4G4R4A4_UNORM;
405 else
406 return WINED3DFMT_B4G4R4X4_UNORM;
409 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
410 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
411 (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
412 (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
413 (DDPixelFormat->u4.dwBBitMask == 0x0003) )
415 return WINED3DFMT_B2G3R3A8_UNORM;
417 WARN("16 bit RGB Pixel format does not match.\n");
418 return WINED3DFMT_UNKNOWN;
420 case 24:
421 return WINED3DFMT_B8G8R8_UNORM;
423 case 32:
424 /* Read the Color masks */
425 if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
426 (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
427 (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
429 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
430 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
431 return WINED3DFMT_B8G8R8A8_UNORM;
432 else
433 return WINED3DFMT_B8G8R8X8_UNORM;
436 WARN("32 bit RGB pixel format does not match.\n");
437 return WINED3DFMT_UNKNOWN;
439 default:
440 WARN("Invalid dwRGBBitCount in Pixelformat structure.\n");
441 return WINED3DFMT_UNKNOWN;
444 else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
446 /* Alpha only Pixelformat */
447 switch(DDPixelFormat->u1.dwAlphaBitDepth)
449 case 8:
450 return WINED3DFMT_A8_UNORM;
452 default:
453 WARN("Invalid AlphaBitDepth in Alpha-Only Pixelformat.\n");
454 return WINED3DFMT_UNKNOWN;
457 else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
459 /* Luminance-only or luminance-alpha */
460 if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
462 /* Luminance with Alpha */
463 switch(DDPixelFormat->u1.dwLuminanceBitCount)
465 case 4:
466 if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
467 return WINED3DFMT_L4A4_UNORM;
468 WARN("Unknown Alpha / Luminance bit depth combination.\n");
469 return WINED3DFMT_UNKNOWN;
471 case 6:
472 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
473 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
475 case 8:
476 if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
477 return WINED3DFMT_L8A8_UNORM;
478 WARN("Unknown Alpha / Lumincase bit depth combination.\n");
479 return WINED3DFMT_UNKNOWN;
482 else
484 /* Luminance-only */
485 switch(DDPixelFormat->u1.dwLuminanceBitCount)
487 case 6:
488 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
489 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
491 case 8:
492 return WINED3DFMT_L8_UNORM;
494 default:
495 WARN("Unknown luminance-only bit depth 0x%x.\n", DDPixelFormat->u1.dwLuminanceBitCount);
496 return WINED3DFMT_UNKNOWN;
500 else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
502 /* Z buffer */
503 if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
505 switch(DDPixelFormat->u1.dwZBufferBitDepth)
507 case 16:
508 if (DDPixelFormat->u2.dwStencilBitDepth == 1) return WINED3DFMT_S1_UINT_D15_UNORM;
509 WARN("Unknown depth stenil format: 16 z bits, %u stencil bits\n",
510 DDPixelFormat->u2.dwStencilBitDepth);
511 return WINED3DFMT_UNKNOWN;
513 case 32:
514 if (DDPixelFormat->u2.dwStencilBitDepth == 8) return WINED3DFMT_D24_UNORM_S8_UINT;
515 else if (DDPixelFormat->u2.dwStencilBitDepth == 4) return WINED3DFMT_S4X4_UINT_D24_UNORM;
516 WARN("Unknown depth stenil format: 32 z bits, %u stencil bits\n",
517 DDPixelFormat->u2.dwStencilBitDepth);
518 return WINED3DFMT_UNKNOWN;
520 default:
521 WARN("Unknown depth stenil format: %u z bits, %u stencil bits\n",
522 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u2.dwStencilBitDepth);
523 return WINED3DFMT_UNKNOWN;
526 else
528 switch(DDPixelFormat->u1.dwZBufferBitDepth)
530 case 16:
531 return WINED3DFMT_D16_UNORM;
533 case 24:
534 return WINED3DFMT_X8D24_UNORM;
536 case 32:
537 if (DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) return WINED3DFMT_X8D24_UNORM;
538 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFF00) return WINED3DFMT_X8D24_UNORM;
539 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) return WINED3DFMT_D32_UNORM;
540 WARN("Unknown depth-only format: 32 z bits, mask 0x%08x\n",
541 DDPixelFormat->u3.dwZBitMask);
542 return WINED3DFMT_UNKNOWN;
544 default:
545 WARN("Unknown depth-only format: %u z bits, mask 0x%08x\n",
546 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u3.dwZBitMask);
547 return WINED3DFMT_UNKNOWN;
551 else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
553 return DDPixelFormat->dwFourCC;
555 else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
557 if( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
558 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
559 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
560 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
562 return WINED3DFMT_R8G8_SNORM;
564 else if ( (DDPixelFormat->u1.dwBumpBitCount == 32 ) &&
565 (DDPixelFormat->u2.dwBumpDuBitMask == 0x0000ffff) &&
566 (DDPixelFormat->u3.dwBumpDvBitMask == 0xffff0000) &&
567 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
569 return WINED3DFMT_R16G16_SNORM;
571 else if ( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
572 (DDPixelFormat->u2.dwBumpDuBitMask == 0x0000001f) &&
573 (DDPixelFormat->u3.dwBumpDvBitMask == 0x000003e0) &&
574 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
576 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
578 else if ( (DDPixelFormat->u1.dwBumpBitCount == 32 ) &&
579 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
580 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
581 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00ff0000) )
583 return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
587 WARN("Unknown Pixelformat.\n");
588 return WINED3DFMT_UNKNOWN;
591 /*****************************************************************************
592 * Various dumping functions.
594 * They write the contents of a specific function to a TRACE.
596 *****************************************************************************/
597 static void
598 DDRAW_dump_DWORD(const void *in)
600 TRACE("%d\n", *((const DWORD *) in));
602 static void
603 DDRAW_dump_PTR(const void *in)
605 TRACE("%p\n", *((const void * const*) in));
607 static void
608 DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
610 TRACE("Low : 0x%08x - High : 0x%08x\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
613 static void DDRAW_dump_flags_nolf(DWORD flags, const struct flag_info *names, size_t num_names)
615 unsigned int i;
617 for (i=0; i < num_names; i++)
618 if ((flags & names[i].val) || /* standard flag value */
619 ((!flags) && (!names[i].val))) /* zero value only */
620 TRACE("%s ", names[i].name);
623 static void DDRAW_dump_flags(DWORD flags, const struct flag_info *names, size_t num_names)
625 DDRAW_dump_flags_nolf(flags, names, num_names);
626 TRACE("\n");
629 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
631 static const struct flag_info flags[] =
633 FE(DDSCAPS_RESERVED1),
634 FE(DDSCAPS_ALPHA),
635 FE(DDSCAPS_BACKBUFFER),
636 FE(DDSCAPS_COMPLEX),
637 FE(DDSCAPS_FLIP),
638 FE(DDSCAPS_FRONTBUFFER),
639 FE(DDSCAPS_OFFSCREENPLAIN),
640 FE(DDSCAPS_OVERLAY),
641 FE(DDSCAPS_PALETTE),
642 FE(DDSCAPS_PRIMARYSURFACE),
643 FE(DDSCAPS_PRIMARYSURFACELEFT),
644 FE(DDSCAPS_SYSTEMMEMORY),
645 FE(DDSCAPS_TEXTURE),
646 FE(DDSCAPS_3DDEVICE),
647 FE(DDSCAPS_VIDEOMEMORY),
648 FE(DDSCAPS_VISIBLE),
649 FE(DDSCAPS_WRITEONLY),
650 FE(DDSCAPS_ZBUFFER),
651 FE(DDSCAPS_OWNDC),
652 FE(DDSCAPS_LIVEVIDEO),
653 FE(DDSCAPS_HWCODEC),
654 FE(DDSCAPS_MODEX),
655 FE(DDSCAPS_MIPMAP),
656 FE(DDSCAPS_RESERVED2),
657 FE(DDSCAPS_ALLOCONLOAD),
658 FE(DDSCAPS_VIDEOPORT),
659 FE(DDSCAPS_LOCALVIDMEM),
660 FE(DDSCAPS_NONLOCALVIDMEM),
661 FE(DDSCAPS_STANDARDVGAMODE),
662 FE(DDSCAPS_OPTIMIZED)
664 static const struct flag_info flags2[] =
666 FE(DDSCAPS2_HARDWAREDEINTERLACE),
667 FE(DDSCAPS2_HINTDYNAMIC),
668 FE(DDSCAPS2_HINTSTATIC),
669 FE(DDSCAPS2_TEXTUREMANAGE),
670 FE(DDSCAPS2_RESERVED1),
671 FE(DDSCAPS2_RESERVED2),
672 FE(DDSCAPS2_OPAQUE),
673 FE(DDSCAPS2_HINTANTIALIASING),
674 FE(DDSCAPS2_CUBEMAP),
675 FE(DDSCAPS2_CUBEMAP_POSITIVEX),
676 FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
677 FE(DDSCAPS2_CUBEMAP_POSITIVEY),
678 FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
679 FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
680 FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
681 FE(DDSCAPS2_MIPMAPSUBLEVEL),
682 FE(DDSCAPS2_D3DTEXTUREMANAGE),
683 FE(DDSCAPS2_DONOTPERSIST),
684 FE(DDSCAPS2_STEREOSURFACELEFT)
687 DDRAW_dump_flags_nolf(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
688 DDRAW_dump_flags(in->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
691 static void
692 DDRAW_dump_DDSCAPS(const DDSCAPS *in)
694 DDSCAPS2 in_bis;
696 in_bis.dwCaps = in->dwCaps;
697 in_bis.dwCaps2 = 0;
698 in_bis.dwCaps3 = 0;
699 in_bis.dwCaps4 = 0;
701 DDRAW_dump_DDSCAPS2(&in_bis);
704 static void
705 DDRAW_dump_pixelformat_flag(DWORD flagmask)
707 static const struct flag_info flags[] =
709 FE(DDPF_ALPHAPIXELS),
710 FE(DDPF_ALPHA),
711 FE(DDPF_FOURCC),
712 FE(DDPF_PALETTEINDEXED4),
713 FE(DDPF_PALETTEINDEXEDTO8),
714 FE(DDPF_PALETTEINDEXED8),
715 FE(DDPF_RGB),
716 FE(DDPF_COMPRESSED),
717 FE(DDPF_RGBTOYUV),
718 FE(DDPF_YUV),
719 FE(DDPF_ZBUFFER),
720 FE(DDPF_PALETTEINDEXED1),
721 FE(DDPF_PALETTEINDEXED2),
722 FE(DDPF_ZPIXELS)
725 DDRAW_dump_flags_nolf(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
728 static void DDRAW_dump_members(DWORD flags, const void *data, const struct member_info *mems, size_t num_mems)
730 unsigned int i;
732 for (i=0; i < num_mems; i++)
734 if (mems[i].val & flags)
736 TRACE(" - %s : ", mems[i].name);
737 mems[i].func((const char *)data + mems[i].offset);
742 static void
743 DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
745 TRACE("( ");
746 DDRAW_dump_pixelformat_flag(pf->dwFlags);
747 if (pf->dwFlags & DDPF_FOURCC)
749 TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %d bits per pixel",
750 (unsigned char)( pf->dwFourCC &0xff),
751 (unsigned char)((pf->dwFourCC>> 8)&0xff),
752 (unsigned char)((pf->dwFourCC>>16)&0xff),
753 (unsigned char)((pf->dwFourCC>>24)&0xff),
754 pf->dwFourCC,
755 pf->u1.dwYUVBitCount
758 if (pf->dwFlags & DDPF_RGB)
760 const char *cmd;
761 TRACE(", RGB bits: %d, ", pf->u1.dwRGBBitCount);
762 switch (pf->u1.dwRGBBitCount)
764 case 4: cmd = "%1lx"; break;
765 case 8: cmd = "%02lx"; break;
766 case 16: cmd = "%04lx"; break;
767 case 24: cmd = "%06lx"; break;
768 case 32: cmd = "%08lx"; break;
769 default: ERR("Unexpected bit depth !\n"); cmd = "%d"; break;
771 TRACE(" R "); TRACE(cmd, pf->u2.dwRBitMask);
772 TRACE(" G "); TRACE(cmd, pf->u3.dwGBitMask);
773 TRACE(" B "); TRACE(cmd, pf->u4.dwBBitMask);
774 if (pf->dwFlags & DDPF_ALPHAPIXELS)
776 TRACE(" A "); TRACE(cmd, pf->u5.dwRGBAlphaBitMask);
778 if (pf->dwFlags & DDPF_ZPIXELS)
780 TRACE(" Z "); TRACE(cmd, pf->u5.dwRGBZBitMask);
783 if (pf->dwFlags & DDPF_ZBUFFER)
785 TRACE(", Z bits : %d", pf->u1.dwZBufferBitDepth);
787 if (pf->dwFlags & DDPF_ALPHA)
789 TRACE(", Alpha bits : %d", pf->u1.dwAlphaBitDepth);
791 if (pf->dwFlags & DDPF_BUMPDUDV)
793 const char *cmd = "%08lx";
794 TRACE(", Bump bits: %d, ", pf->u1.dwBumpBitCount);
795 TRACE(" U "); TRACE(cmd, pf->u2.dwBumpDuBitMask);
796 TRACE(" V "); TRACE(cmd, pf->u3.dwBumpDvBitMask);
797 TRACE(" L "); TRACE(cmd, pf->u4.dwBumpLuminanceBitMask);
799 TRACE(")\n");
802 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
804 #define STRUCT DDSURFACEDESC2
805 static const struct member_info members[] =
807 ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
808 ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
809 ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
810 ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
811 ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
812 ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
813 ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
814 ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
815 ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
816 ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
817 ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
818 ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
819 ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
820 ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
821 ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
823 static const struct member_info members_caps[] =
825 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
827 static const struct member_info members_caps2[] =
829 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
831 #undef STRUCT
833 if (NULL == lpddsd)
835 TRACE("(null)\n");
837 else
839 if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
841 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
843 else
845 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
847 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
848 sizeof(members)/sizeof(members[0]));
852 void
853 dump_D3DMATRIX(const D3DMATRIX *mat)
855 TRACE(" %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
856 TRACE(" %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
857 TRACE(" %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
858 TRACE(" %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
861 DWORD
862 get_flexible_vertex_size(DWORD d3dvtVertexType)
864 DWORD size = 0;
865 DWORD i;
867 if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
868 if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
869 if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
870 if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
871 switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
873 case D3DFVF_XYZ: size += 3 * sizeof(D3DVALUE); break;
874 case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
875 case D3DFVF_XYZB1: size += 4 * sizeof(D3DVALUE); break;
876 case D3DFVF_XYZB2: size += 5 * sizeof(D3DVALUE); break;
877 case D3DFVF_XYZB3: size += 6 * sizeof(D3DVALUE); break;
878 case D3DFVF_XYZB4: size += 7 * sizeof(D3DVALUE); break;
879 case D3DFVF_XYZB5: size += 8 * sizeof(D3DVALUE); break;
880 default: ERR("Unexpected position mask\n");
882 for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
884 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
887 return size;
890 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
892 /* 2 adds three additional caps fields to the end. Both versions
893 * are unversioned. */
894 pOut->dwCaps = pIn->dwCaps;
895 pOut->dwCaps2 = 0;
896 pOut->dwCaps3 = 0;
897 pOut->dwCaps4 = 0;
900 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
902 /* 2 adds a dwWHQLLevel field to the end. Both structures are
903 * unversioned. */
904 memcpy(pOut, pIn, sizeof(*pOut));
907 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
909 static const struct flag_info flags[] =
911 FE(DDSCL_FULLSCREEN),
912 FE(DDSCL_ALLOWREBOOT),
913 FE(DDSCL_NOWINDOWCHANGES),
914 FE(DDSCL_NORMAL),
915 FE(DDSCL_ALLOWMODEX),
916 FE(DDSCL_EXCLUSIVE),
917 FE(DDSCL_SETFOCUSWINDOW),
918 FE(DDSCL_SETDEVICEWINDOW),
919 FE(DDSCL_CREATEDEVICEWINDOW)
922 if (TRACE_ON(ddraw))
924 TRACE(" - ");
925 DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));
929 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
931 static const struct flag_info flags1[] =
933 FE(DDCAPS_3D),
934 FE(DDCAPS_ALIGNBOUNDARYDEST),
935 FE(DDCAPS_ALIGNSIZEDEST),
936 FE(DDCAPS_ALIGNBOUNDARYSRC),
937 FE(DDCAPS_ALIGNSIZESRC),
938 FE(DDCAPS_ALIGNSTRIDE),
939 FE(DDCAPS_BLT),
940 FE(DDCAPS_BLTQUEUE),
941 FE(DDCAPS_BLTFOURCC),
942 FE(DDCAPS_BLTSTRETCH),
943 FE(DDCAPS_GDI),
944 FE(DDCAPS_OVERLAY),
945 FE(DDCAPS_OVERLAYCANTCLIP),
946 FE(DDCAPS_OVERLAYFOURCC),
947 FE(DDCAPS_OVERLAYSTRETCH),
948 FE(DDCAPS_PALETTE),
949 FE(DDCAPS_PALETTEVSYNC),
950 FE(DDCAPS_READSCANLINE),
951 FE(DDCAPS_STEREOVIEW),
952 FE(DDCAPS_VBI),
953 FE(DDCAPS_ZBLTS),
954 FE(DDCAPS_ZOVERLAYS),
955 FE(DDCAPS_COLORKEY),
956 FE(DDCAPS_ALPHA),
957 FE(DDCAPS_COLORKEYHWASSIST),
958 FE(DDCAPS_NOHARDWARE),
959 FE(DDCAPS_BLTCOLORFILL),
960 FE(DDCAPS_BANKSWITCHED),
961 FE(DDCAPS_BLTDEPTHFILL),
962 FE(DDCAPS_CANCLIP),
963 FE(DDCAPS_CANCLIPSTRETCHED),
964 FE(DDCAPS_CANBLTSYSMEM)
966 static const struct flag_info flags2[] =
968 FE(DDCAPS2_CERTIFIED),
969 FE(DDCAPS2_NO2DDURING3DSCENE),
970 FE(DDCAPS2_VIDEOPORT),
971 FE(DDCAPS2_AUTOFLIPOVERLAY),
972 FE(DDCAPS2_CANBOBINTERLEAVED),
973 FE(DDCAPS2_CANBOBNONINTERLEAVED),
974 FE(DDCAPS2_COLORCONTROLOVERLAY),
975 FE(DDCAPS2_COLORCONTROLPRIMARY),
976 FE(DDCAPS2_CANDROPZ16BIT),
977 FE(DDCAPS2_NONLOCALVIDMEM),
978 FE(DDCAPS2_NONLOCALVIDMEMCAPS),
979 FE(DDCAPS2_NOPAGELOCKREQUIRED),
980 FE(DDCAPS2_WIDESURFACES),
981 FE(DDCAPS2_CANFLIPODDEVEN),
982 FE(DDCAPS2_CANBOBHARDWARE),
983 FE(DDCAPS2_COPYFOURCC),
984 FE(DDCAPS2_PRIMARYGAMMA),
985 FE(DDCAPS2_CANRENDERWINDOWED),
986 FE(DDCAPS2_CANCALIBRATEGAMMA),
987 FE(DDCAPS2_FLIPINTERVAL),
988 FE(DDCAPS2_FLIPNOVSYNC),
989 FE(DDCAPS2_CANMANAGETEXTURE),
990 FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
991 FE(DDCAPS2_STEREO),
992 FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
994 static const struct flag_info flags3[] =
996 FE(DDCKEYCAPS_DESTBLT),
997 FE(DDCKEYCAPS_DESTBLTCLRSPACE),
998 FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
999 FE(DDCKEYCAPS_DESTBLTYUV),
1000 FE(DDCKEYCAPS_DESTOVERLAY),
1001 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
1002 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
1003 FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
1004 FE(DDCKEYCAPS_DESTOVERLAYYUV),
1005 FE(DDCKEYCAPS_SRCBLT),
1006 FE(DDCKEYCAPS_SRCBLTCLRSPACE),
1007 FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
1008 FE(DDCKEYCAPS_SRCBLTYUV),
1009 FE(DDCKEYCAPS_SRCOVERLAY),
1010 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
1011 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
1012 FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
1013 FE(DDCKEYCAPS_SRCOVERLAYYUV),
1014 FE(DDCKEYCAPS_NOCOSTOVERLAY)
1016 static const struct flag_info flags4[] =
1018 FE(DDFXCAPS_BLTALPHA),
1019 FE(DDFXCAPS_OVERLAYALPHA),
1020 FE(DDFXCAPS_BLTARITHSTRETCHYN),
1021 FE(DDFXCAPS_BLTARITHSTRETCHY),
1022 FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
1023 FE(DDFXCAPS_BLTMIRRORUPDOWN),
1024 FE(DDFXCAPS_BLTROTATION),
1025 FE(DDFXCAPS_BLTROTATION90),
1026 FE(DDFXCAPS_BLTSHRINKX),
1027 FE(DDFXCAPS_BLTSHRINKXN),
1028 FE(DDFXCAPS_BLTSHRINKY),
1029 FE(DDFXCAPS_BLTSHRINKYN),
1030 FE(DDFXCAPS_BLTSTRETCHX),
1031 FE(DDFXCAPS_BLTSTRETCHXN),
1032 FE(DDFXCAPS_BLTSTRETCHY),
1033 FE(DDFXCAPS_BLTSTRETCHYN),
1034 FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
1035 FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
1036 FE(DDFXCAPS_OVERLAYSHRINKX),
1037 FE(DDFXCAPS_OVERLAYSHRINKXN),
1038 FE(DDFXCAPS_OVERLAYSHRINKY),
1039 FE(DDFXCAPS_OVERLAYSHRINKYN),
1040 FE(DDFXCAPS_OVERLAYSTRETCHX),
1041 FE(DDFXCAPS_OVERLAYSTRETCHXN),
1042 FE(DDFXCAPS_OVERLAYSTRETCHY),
1043 FE(DDFXCAPS_OVERLAYSTRETCHYN),
1044 FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
1045 FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
1047 static const struct flag_info flags5[] =
1049 FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
1050 FE(DDFXALPHACAPS_BLTALPHAPIXELS),
1051 FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
1052 FE(DDFXALPHACAPS_BLTALPHASURFACES),
1053 FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
1054 FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
1055 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
1056 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
1057 FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
1058 FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
1060 static const struct flag_info flags6[] =
1062 FE(DDPCAPS_4BIT),
1063 FE(DDPCAPS_8BITENTRIES),
1064 FE(DDPCAPS_8BIT),
1065 FE(DDPCAPS_INITIALIZE),
1066 FE(DDPCAPS_PRIMARYSURFACE),
1067 FE(DDPCAPS_PRIMARYSURFACELEFT),
1068 FE(DDPCAPS_ALLOW256),
1069 FE(DDPCAPS_VSYNC),
1070 FE(DDPCAPS_1BIT),
1071 FE(DDPCAPS_2BIT),
1072 FE(DDPCAPS_ALPHA),
1074 static const struct flag_info flags7[] =
1076 FE(DDSVCAPS_RESERVED1),
1077 FE(DDSVCAPS_RESERVED2),
1078 FE(DDSVCAPS_RESERVED3),
1079 FE(DDSVCAPS_RESERVED4),
1080 FE(DDSVCAPS_STEREOSEQUENTIAL),
1083 TRACE(" - dwSize : %d\n", lpcaps->dwSize);
1084 TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, sizeof(flags1)/sizeof(flags1[0]));
1085 TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
1086 TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, sizeof(flags3)/sizeof(flags3[0]));
1087 TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, sizeof(flags4)/sizeof(flags4[0]));
1088 TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, sizeof(flags5)/sizeof(flags5[0]));
1089 TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, sizeof(flags6)/sizeof(flags6[0]));
1090 TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, sizeof(flags7)/sizeof(flags7[0]));
1091 TRACE("...\n");
1092 TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
1093 TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
1094 TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
1095 TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
1096 TRACE("...\n");
1097 TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1100 /*****************************************************************************
1101 * multiply_matrix
1103 * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
1105 * Params:
1106 * dest: Pointer to the destination matrix
1107 * src1: Pointer to the first source matrix
1108 * src2: Pointer to the second source matrix
1110 *****************************************************************************/
1111 void
1112 multiply_matrix(D3DMATRIX *dest,
1113 const D3DMATRIX *src1,
1114 const D3DMATRIX *src2)
1116 D3DMATRIX temp;
1118 /* Now do the multiplication 'by hand'.
1119 I know that all this could be optimised, but this will be done later :-) */
1120 temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
1121 temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
1122 temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
1123 temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
1125 temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
1126 temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
1127 temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
1128 temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
1130 temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
1131 temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
1132 temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
1133 temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
1135 temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
1136 temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
1137 temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
1138 temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
1140 /* And copy the new matrix in the good storage.. */
1141 memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
1144 HRESULT
1145 hr_ddraw_from_wined3d(HRESULT hr)
1147 switch(hr)
1149 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1150 default: return hr;
1154 /* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it
1155 * for writing into application-provided DDSURFACEDESC2 structures if the size may
1156 * be different */
1157 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
1159 /* The output of this function is never passed to the application directly, so
1160 * the memset is not strictly needed. CreateSurface still has problems with this
1161 * though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */
1162 memset(out, 0x00, sizeof(*out));
1163 out->dwSize = sizeof(*out);
1164 out->dwFlags = in->dwFlags & ~DDSD_ZBUFFERBITDEPTH;
1165 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1166 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1167 if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
1168 else if(in->dwFlags & DDSD_ZBUFFERBITDEPTH)
1170 out->dwFlags |= DDSD_PIXELFORMAT;
1171 memset(&out->u4.ddpfPixelFormat, 0, sizeof(out->u4.ddpfPixelFormat));
1172 out->u4.ddpfPixelFormat.dwSize = sizeof(out->u4.ddpfPixelFormat);
1173 out->u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
1174 out->u4.ddpfPixelFormat.u1.dwZBufferBitDepth = in->u2.dwZBufferBitDepth;
1175 /* 0 is not a valid DDSURFACEDESC / DDPIXELFORMAT on either side of the
1176 * conversion */
1177 out->u4.ddpfPixelFormat.u3.dwZBitMask = ~0U >> (32 - in->u2.dwZBufferBitDepth);
1179 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1180 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1181 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1182 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
1183 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1184 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1185 out->lpSurface = in->lpSurface;
1186 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
1187 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1188 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1189 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1190 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1191 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1192 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1193 /* Does not exist in DDSURFACEDESC:
1194 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1198 /* Note that this function writes the full sizeof(DDSURFACEDESC) size, don't use it
1199 * for writing into application-provided DDSURFACEDESC structures if the size may
1200 * be different */
1201 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
1203 memset(out, 0, sizeof(*out));
1204 out->dwSize = sizeof(*out);
1205 out->dwFlags = in->dwFlags;
1206 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1207 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1208 if (in->dwFlags & DDSD_PIXELFORMAT)
1210 out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
1211 if ((in->dwFlags & DDSD_CAPS) && (in->ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
1213 /* Z buffers have DDSD_ZBUFFERBITDEPTH set, but not DDSD_PIXELFORMAT. They do
1214 * have valid data in ddpfPixelFormat though */
1215 out->dwFlags &= ~DDSD_PIXELFORMAT;
1216 out->dwFlags |= DDSD_ZBUFFERBITDEPTH;
1217 out->u2.dwZBufferBitDepth = in->u4.ddpfPixelFormat.u1.dwZBufferBitDepth;
1220 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1221 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1222 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1223 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->dwBackBufferCount;
1224 if (in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
1225 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1226 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1227 out->lpSurface = in->lpSurface;
1228 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
1229 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1230 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1231 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1232 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1233 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1234 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1235 /* Does not exist in DDSURFACEDESC:
1236 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1238 if (in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
1239 if (in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
1240 if (in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
1241 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);