wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / ddraw / utils.c
blobefc1dddd18990c4831d088782cdde565e1b04dc5
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 "ddraw_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
28 static void DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf);
30 void ddrawformat_from_wined3dformat(DDPIXELFORMAT *DDPixelFormat, enum wined3d_format_id wined3d_format)
32 DWORD Size = DDPixelFormat->dwSize;
34 if(Size==0) return;
36 memset(DDPixelFormat, 0x00, Size);
37 DDPixelFormat->dwSize = Size;
38 switch (wined3d_format)
40 case WINED3DFMT_B8G8R8_UNORM:
41 DDPixelFormat->dwFlags = DDPF_RGB;
42 DDPixelFormat->dwFourCC = 0;
43 DDPixelFormat->u1.dwRGBBitCount = 24;
44 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
45 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
46 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
47 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
48 break;
50 case WINED3DFMT_B8G8R8A8_UNORM:
51 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
52 DDPixelFormat->dwFourCC = 0;
53 DDPixelFormat->u1.dwRGBBitCount = 32;
54 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
55 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
56 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
57 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
58 break;
60 case WINED3DFMT_B8G8R8X8_UNORM:
61 DDPixelFormat->dwFlags = DDPF_RGB;
62 DDPixelFormat->dwFourCC = 0;
63 DDPixelFormat->u1.dwRGBBitCount = 32;
64 DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
65 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
66 DDPixelFormat->u4.dwBBitMask = 0x000000ff;
67 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
68 break;
70 case WINED3DFMT_R8G8B8X8_UNORM:
71 DDPixelFormat->dwFlags = DDPF_RGB;
72 DDPixelFormat->dwFourCC = 0;
73 DDPixelFormat->u1.dwRGBBitCount = 32;
74 DDPixelFormat->u2.dwRBitMask = 0x000000ff;
75 DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
76 DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
77 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
78 break;
80 case WINED3DFMT_B5G6R5_UNORM:
81 DDPixelFormat->dwFlags = DDPF_RGB;
82 DDPixelFormat->dwFourCC = 0;
83 DDPixelFormat->u1.dwRGBBitCount = 16;
84 DDPixelFormat->u2.dwRBitMask = 0xF800;
85 DDPixelFormat->u3.dwGBitMask = 0x07E0;
86 DDPixelFormat->u4.dwBBitMask = 0x001F;
87 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
88 break;
90 case WINED3DFMT_B5G5R5X1_UNORM:
91 DDPixelFormat->dwFlags = DDPF_RGB;
92 DDPixelFormat->dwFourCC = 0;
93 DDPixelFormat->u1.dwRGBBitCount = 16;
94 DDPixelFormat->u2.dwRBitMask = 0x7C00;
95 DDPixelFormat->u3.dwGBitMask = 0x03E0;
96 DDPixelFormat->u4.dwBBitMask = 0x001F;
97 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
98 break;
100 case WINED3DFMT_B5G5R5A1_UNORM:
101 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
102 DDPixelFormat->dwFourCC = 0;
103 DDPixelFormat->u1.dwRGBBitCount = 16;
104 DDPixelFormat->u2.dwRBitMask = 0x7C00;
105 DDPixelFormat->u3.dwGBitMask = 0x03E0;
106 DDPixelFormat->u4.dwBBitMask = 0x001F;
107 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
108 break;
110 case WINED3DFMT_B4G4R4A4_UNORM:
111 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
112 DDPixelFormat->dwFourCC = 0;
113 DDPixelFormat->u1.dwRGBBitCount = 16;
114 DDPixelFormat->u2.dwRBitMask = 0x0F00;
115 DDPixelFormat->u3.dwGBitMask = 0x00F0;
116 DDPixelFormat->u4.dwBBitMask = 0x000F;
117 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
118 break;
120 case WINED3DFMT_B2G3R3_UNORM:
121 DDPixelFormat->dwFlags = DDPF_RGB;
122 DDPixelFormat->dwFourCC = 0;
123 DDPixelFormat->u1.dwRGBBitCount = 8;
124 DDPixelFormat->u2.dwRBitMask = 0xE0;
125 DDPixelFormat->u3.dwGBitMask = 0x1C;
126 DDPixelFormat->u4.dwBBitMask = 0x03;
127 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
128 break;
130 case WINED3DFMT_P8_UINT:
131 DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
132 DDPixelFormat->dwFourCC = 0;
133 DDPixelFormat->u1.dwRGBBitCount = 8;
134 DDPixelFormat->u2.dwRBitMask = 0x00;
135 DDPixelFormat->u3.dwGBitMask = 0x00;
136 DDPixelFormat->u4.dwBBitMask = 0x00;
137 break;
139 case WINED3DFMT_A8_UNORM:
140 DDPixelFormat->dwFlags = DDPF_ALPHA;
141 DDPixelFormat->dwFourCC = 0;
142 DDPixelFormat->u1.dwAlphaBitDepth = 8;
143 DDPixelFormat->u2.dwRBitMask = 0x0;
144 DDPixelFormat->u3.dwZBitMask = 0x0;
145 DDPixelFormat->u4.dwStencilBitMask = 0x0;
146 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
147 break;
149 case WINED3DFMT_B2G3R3A8_UNORM:
150 DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
151 DDPixelFormat->dwFourCC = 0;
152 DDPixelFormat->u1.dwRGBBitCount = 16;
153 DDPixelFormat->u2.dwRBitMask = 0x00E0;
154 DDPixelFormat->u3.dwGBitMask = 0x001C;
155 DDPixelFormat->u4.dwBBitMask = 0x0003;
156 DDPixelFormat->u5.dwRGBAlphaBitMask = 0xFF00;
157 break;
159 case WINED3DFMT_B4G4R4X4_UNORM:
160 DDPixelFormat->dwFlags = DDPF_RGB;
161 DDPixelFormat->dwFourCC = 0;
162 DDPixelFormat->u1.dwRGBBitCount = 16;
163 DDPixelFormat->u2.dwRBitMask = 0x0F00;
164 DDPixelFormat->u3.dwGBitMask = 0x00F0;
165 DDPixelFormat->u4.dwBBitMask = 0x000F;
166 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
167 break;
169 /* How are Z buffer bit depth and Stencil buffer bit depth related?
171 case WINED3DFMT_D16_UNORM:
172 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
173 DDPixelFormat->dwFourCC = 0;
174 DDPixelFormat->u1.dwZBufferBitDepth = 16;
175 DDPixelFormat->u2.dwStencilBitDepth = 0;
176 DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
177 DDPixelFormat->u4.dwStencilBitMask = 0x0;
178 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
179 break;
181 case WINED3DFMT_D32_UNORM:
182 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
183 DDPixelFormat->dwFourCC = 0;
184 DDPixelFormat->u1.dwZBufferBitDepth = 32;
185 DDPixelFormat->u2.dwStencilBitDepth = 0;
186 DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
187 DDPixelFormat->u4.dwStencilBitMask = 0x0;
188 DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
189 break;
191 case WINED3DFMT_S4X4_UINT_D24_UNORM:
192 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
193 DDPixelFormat->dwFourCC = 0;
194 /* Should I set dwZBufferBitDepth to 32 here? */
195 DDPixelFormat->u1.dwZBufferBitDepth = 32;
196 DDPixelFormat->u2.dwStencilBitDepth = 4;
197 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
198 DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
199 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
200 break;
202 case WINED3DFMT_D24_UNORM_S8_UINT:
203 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
204 DDPixelFormat->dwFourCC = 0;
205 DDPixelFormat->u1.dwZBufferBitDepth = 32;
206 DDPixelFormat->u2.dwStencilBitDepth = 8;
207 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
208 DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
209 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
210 break;
212 case WINED3DFMT_X8D24_UNORM:
213 DDPixelFormat->dwFlags = DDPF_ZBUFFER;
214 DDPixelFormat->dwFourCC = 0;
215 DDPixelFormat->u1.dwZBufferBitDepth = 32;
216 DDPixelFormat->u2.dwStencilBitDepth = 0;
217 DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
218 DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
219 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
220 break;
222 case WINED3DFMT_S1_UINT_D15_UNORM:
223 DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
224 DDPixelFormat->dwFourCC = 0;
225 DDPixelFormat->u1.dwZBufferBitDepth = 16;
226 DDPixelFormat->u2.dwStencilBitDepth = 1;
227 DDPixelFormat->u3.dwZBitMask = 0x7fff;
228 DDPixelFormat->u4.dwStencilBitMask = 0x8000;
229 DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
230 break;
232 case WINED3DFMT_UYVY:
233 case WINED3DFMT_YUY2:
234 DDPixelFormat->u1.dwYUVBitCount = 16;
235 DDPixelFormat->dwFlags = DDPF_FOURCC;
236 DDPixelFormat->dwFourCC = wined3d_format;
237 break;
239 case WINED3DFMT_YV12:
240 DDPixelFormat->u1.dwYUVBitCount = 12;
241 DDPixelFormat->dwFlags = DDPF_FOURCC;
242 DDPixelFormat->dwFourCC = wined3d_format;
243 break;
245 case WINED3DFMT_DXT1:
246 case WINED3DFMT_DXT2:
247 case WINED3DFMT_DXT3:
248 case WINED3DFMT_DXT4:
249 case WINED3DFMT_DXT5:
250 case WINED3DFMT_MULTI2_ARGB8:
251 case WINED3DFMT_G8R8_G8B8:
252 case WINED3DFMT_R8G8_B8G8:
253 DDPixelFormat->dwFlags = DDPF_FOURCC;
254 DDPixelFormat->dwFourCC = wined3d_format;
255 break;
257 /* Luminance */
258 case WINED3DFMT_L8_UNORM:
259 DDPixelFormat->dwFlags = DDPF_LUMINANCE;
260 DDPixelFormat->dwFourCC = 0;
261 DDPixelFormat->u1.dwLuminanceBitCount = 8;
262 DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
263 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
264 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
265 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
266 break;
268 case WINED3DFMT_L4A4_UNORM:
269 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
270 DDPixelFormat->dwFourCC = 0;
271 DDPixelFormat->u1.dwLuminanceBitCount = 4;
272 DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
273 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
274 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
275 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
276 break;
278 case WINED3DFMT_L8A8_UNORM:
279 DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
280 DDPixelFormat->dwFourCC = 0;
281 DDPixelFormat->u1.dwLuminanceBitCount = 16;
282 DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
283 DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
284 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
285 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
286 break;
288 /* Bump mapping */
289 case WINED3DFMT_R8G8_SNORM:
290 DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
291 DDPixelFormat->dwFourCC = 0;
292 DDPixelFormat->u1.dwBumpBitCount = 16;
293 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
294 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
295 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00000000;
296 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
297 break;
299 case WINED3DFMT_R5G5_SNORM_L6_UNORM:
300 DDPixelFormat->dwFlags = DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE;
301 DDPixelFormat->dwFourCC = 0;
302 DDPixelFormat->u1.dwBumpBitCount = 16;
303 DDPixelFormat->u2.dwBumpDuBitMask = 0x0000001f;
304 DDPixelFormat->u3.dwBumpDvBitMask = 0x000003e0;
305 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0000fc00;
306 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
307 break;
309 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
310 DDPixelFormat->dwFlags = DDPF_BUMPDUDV | DDPF_BUMPLUMINANCE;
311 DDPixelFormat->dwFourCC = 0;
312 DDPixelFormat->u1.dwBumpBitCount = 32;
313 DDPixelFormat->u2.dwBumpDuBitMask = 0x000000ff;
314 DDPixelFormat->u3.dwBumpDvBitMask = 0x0000ff00;
315 DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x00ff0000;
316 DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
317 break;
319 default:
320 FIXME("Unhandled wined3d format %#x.\n", wined3d_format);
321 break;
324 if(TRACE_ON(ddraw)) {
325 TRACE("Returning: ");
326 DDRAW_dump_pixelformat(DDPixelFormat);
330 enum wined3d_format_id wined3dformat_from_ddrawformat(const DDPIXELFORMAT *DDPixelFormat)
332 TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");
333 if(TRACE_ON(ddraw))
335 DDRAW_dump_pixelformat(DDPixelFormat);
338 if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
340 return WINED3DFMT_P8_UINT;
342 else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
344 FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
345 return WINED3DFMT_P8_UINT;
347 else if(DDPixelFormat->dwFlags & DDPF_RGB)
349 switch(DDPixelFormat->u1.dwRGBBitCount)
351 case 8:
352 /* This is the only format that can match here */
353 return WINED3DFMT_B2G3R3_UNORM;
355 case 16:
356 /* Read the Color masks */
357 if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
358 (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
359 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
361 return WINED3DFMT_B5G6R5_UNORM;
364 if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
365 (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
366 (DDPixelFormat->u4.dwBBitMask == 0x001F) )
368 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
369 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
370 return WINED3DFMT_B5G5R5A1_UNORM;
371 else
372 return WINED3DFMT_B5G5R5X1_UNORM;
375 if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
376 (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
377 (DDPixelFormat->u4.dwBBitMask == 0x000F) )
379 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
380 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
381 return WINED3DFMT_B4G4R4A4_UNORM;
382 else
383 return WINED3DFMT_B4G4R4X4_UNORM;
386 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
387 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
388 (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
389 (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
390 (DDPixelFormat->u4.dwBBitMask == 0x0003) )
392 return WINED3DFMT_B2G3R3A8_UNORM;
394 WARN("16 bit RGB Pixel format does not match.\n");
395 return WINED3DFMT_UNKNOWN;
397 case 24:
398 return WINED3DFMT_B8G8R8_UNORM;
400 case 32:
401 /* Read the Color masks */
402 if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
403 (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
404 (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
406 if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
407 (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
408 return WINED3DFMT_B8G8R8A8_UNORM;
409 else
410 return WINED3DFMT_B8G8R8X8_UNORM;
413 WARN("32 bit RGB pixel format does not match.\n");
414 return WINED3DFMT_UNKNOWN;
416 default:
417 WARN("Invalid dwRGBBitCount in Pixelformat structure.\n");
418 return WINED3DFMT_UNKNOWN;
421 else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
423 /* Alpha only Pixelformat */
424 switch(DDPixelFormat->u1.dwAlphaBitDepth)
426 case 8:
427 return WINED3DFMT_A8_UNORM;
429 default:
430 WARN("Invalid AlphaBitDepth in Alpha-Only Pixelformat.\n");
431 return WINED3DFMT_UNKNOWN;
434 else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
436 /* Luminance-only or luminance-alpha */
437 if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
439 /* Luminance with Alpha */
440 switch(DDPixelFormat->u1.dwLuminanceBitCount)
442 case 4:
443 if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
444 return WINED3DFMT_L4A4_UNORM;
445 WARN("Unknown Alpha / Luminance bit depth combination.\n");
446 return WINED3DFMT_UNKNOWN;
448 case 6:
449 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
450 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
452 case 8:
453 if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
454 return WINED3DFMT_L8A8_UNORM;
455 WARN("Unknown Alpha / Lumincase bit depth combination.\n");
456 return WINED3DFMT_UNKNOWN;
459 else
461 /* Luminance-only */
462 switch(DDPixelFormat->u1.dwLuminanceBitCount)
464 case 6:
465 FIXME("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now.\n");
466 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
468 case 8:
469 return WINED3DFMT_L8_UNORM;
471 default:
472 WARN("Unknown luminance-only bit depth 0x%x.\n", DDPixelFormat->u1.dwLuminanceBitCount);
473 return WINED3DFMT_UNKNOWN;
477 else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
479 /* Z buffer */
480 if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
482 switch(DDPixelFormat->u1.dwZBufferBitDepth)
484 case 16:
485 if (DDPixelFormat->u2.dwStencilBitDepth == 1) return WINED3DFMT_S1_UINT_D15_UNORM;
486 WARN("Unknown depth stencil format: 16 z bits, %u stencil bits.\n",
487 DDPixelFormat->u2.dwStencilBitDepth);
488 return WINED3DFMT_UNKNOWN;
490 case 32:
491 if (DDPixelFormat->u2.dwStencilBitDepth == 8) return WINED3DFMT_D24_UNORM_S8_UINT;
492 else if (DDPixelFormat->u2.dwStencilBitDepth == 4) return WINED3DFMT_S4X4_UINT_D24_UNORM;
493 WARN("Unknown depth stencil format: 32 z bits, %u stencil bits.\n",
494 DDPixelFormat->u2.dwStencilBitDepth);
495 return WINED3DFMT_UNKNOWN;
497 default:
498 WARN("Unknown depth stencil format: %u z bits, %u stencil bits.\n",
499 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u2.dwStencilBitDepth);
500 return WINED3DFMT_UNKNOWN;
503 else
505 switch(DDPixelFormat->u1.dwZBufferBitDepth)
507 case 16:
508 return WINED3DFMT_D16_UNORM;
510 case 24:
511 return WINED3DFMT_X8D24_UNORM;
513 case 32:
514 if (DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) return WINED3DFMT_X8D24_UNORM;
515 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFF00) return WINED3DFMT_X8D24_UNORM;
516 else if (DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) return WINED3DFMT_D32_UNORM;
517 WARN("Unknown depth-only format: 32 z bits, mask 0x%08x\n",
518 DDPixelFormat->u3.dwZBitMask);
519 return WINED3DFMT_UNKNOWN;
521 default:
522 WARN("Unknown depth-only format: %u z bits, mask 0x%08x\n",
523 DDPixelFormat->u1.dwZBufferBitDepth, DDPixelFormat->u3.dwZBitMask);
524 return WINED3DFMT_UNKNOWN;
528 else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
530 return DDPixelFormat->dwFourCC;
532 else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
534 if( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
535 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
536 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
537 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
539 return WINED3DFMT_R8G8_SNORM;
541 else if ( (DDPixelFormat->u1.dwBumpBitCount == 16 ) &&
542 (DDPixelFormat->u2.dwBumpDuBitMask == 0x0000001f) &&
543 (DDPixelFormat->u3.dwBumpDvBitMask == 0x000003e0) &&
544 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
546 return WINED3DFMT_R5G5_SNORM_L6_UNORM;
548 else if ( (DDPixelFormat->u1.dwBumpBitCount == 32 ) &&
549 (DDPixelFormat->u2.dwBumpDuBitMask == 0x000000ff) &&
550 (DDPixelFormat->u3.dwBumpDvBitMask == 0x0000ff00) &&
551 (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00ff0000) )
553 return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
557 WARN("Unknown Pixelformat.\n");
558 return WINED3DFMT_UNKNOWN;
561 unsigned int wined3dmapflags_from_ddrawmapflags(unsigned int flags)
563 static const unsigned int handled = DDLOCK_NOSYSLOCK
564 | DDLOCK_NOOVERWRITE
565 | DDLOCK_DISCARDCONTENTS
566 | DDLOCK_DONOTWAIT;
567 unsigned int wined3d_flags;
569 wined3d_flags = flags & handled;
570 if (!(flags & (DDLOCK_NOOVERWRITE | DDLOCK_DISCARDCONTENTS | DDLOCK_WRITEONLY)))
571 wined3d_flags |= WINED3D_MAP_READ;
572 if (!(flags & DDLOCK_READONLY))
573 wined3d_flags |= WINED3D_MAP_WRITE;
574 if (!(wined3d_flags & (WINED3D_MAP_READ | WINED3D_MAP_WRITE)))
575 wined3d_flags |= WINED3D_MAP_READ | WINED3D_MAP_WRITE;
576 if (flags & DDLOCK_NODIRTYUPDATE)
577 wined3d_flags |= WINED3D_MAP_NO_DIRTY_UPDATE;
578 flags &= ~(handled | DDLOCK_WAIT | DDLOCK_READONLY | DDLOCK_WRITEONLY | DDLOCK_NODIRTYUPDATE);
580 if (flags)
581 FIXME("Unhandled flags %#x.\n", flags);
583 return wined3d_flags;
586 static float colour_to_float(DWORD colour, DWORD mask)
588 if (!mask)
589 return 0.0f;
590 return (float)(colour & mask) / (float)mask;
593 BOOL wined3d_colour_from_ddraw_colour(const DDPIXELFORMAT *pf, const struct ddraw_palette *palette,
594 DWORD colour, struct wined3d_color *wined3d_colour)
596 if (pf->dwFlags & DDPF_ALPHA)
598 DWORD size, mask;
600 size = pf->u1.dwAlphaBitDepth;
601 mask = size < 32 ? (1u << size) - 1 : ~0u;
602 wined3d_colour->r = 0.0f;
603 wined3d_colour->g = 0.0f;
604 wined3d_colour->b = 0.0f;
605 wined3d_colour->a = colour_to_float(colour, mask);
606 return TRUE;
609 if (pf->dwFlags & DDPF_FOURCC)
611 WARN("FourCC formats not supported.\n");
612 goto fail;
615 if (pf->dwFlags & DDPF_PALETTEINDEXED8)
617 PALETTEENTRY entry;
619 colour &= 0xff;
620 if (!palette || FAILED(wined3d_palette_get_entries(palette->wined3d_palette, 0, colour, 1, &entry)))
622 wined3d_colour->r = 0.0f;
623 wined3d_colour->g = 0.0f;
624 wined3d_colour->b = 0.0f;
626 else
628 wined3d_colour->r = entry.peRed / 255.0f;
629 wined3d_colour->g = entry.peGreen / 255.0f;
630 wined3d_colour->b = entry.peBlue / 255.0f;
632 wined3d_colour->a = colour / 255.0f;
633 return TRUE;
636 if (pf->dwFlags & DDPF_RGB)
638 wined3d_colour->r = colour_to_float(colour, pf->u2.dwRBitMask);
639 wined3d_colour->g = colour_to_float(colour, pf->u3.dwGBitMask);
640 wined3d_colour->b = colour_to_float(colour, pf->u4.dwBBitMask);
641 if (pf->dwFlags & DDPF_ALPHAPIXELS)
642 wined3d_colour->a = colour_to_float(colour, pf->u5.dwRGBAlphaBitMask);
643 else
644 wined3d_colour->a = 0.0f;
645 return TRUE;
648 if (pf->dwFlags & DDPF_ZBUFFER)
650 wined3d_colour->r = colour_to_float(colour, pf->u3.dwZBitMask);
651 if (pf->dwFlags & DDPF_STENCILBUFFER)
652 wined3d_colour->g = colour_to_float(colour, pf->u4.dwStencilBitMask);
653 else
654 wined3d_colour->g = 0.0f;
655 wined3d_colour->b = 0.0f;
656 wined3d_colour->a = 0.0f;
657 return TRUE;
660 FIXME("Unhandled pixel format.\n");
661 DDRAW_dump_pixelformat(pf);
663 fail:
664 wined3d_colour->r = 0.0f;
665 wined3d_colour->g = 0.0f;
666 wined3d_colour->b = 0.0f;
667 wined3d_colour->a = 0.0f;
669 return FALSE;
672 /*****************************************************************************
673 * Various dumping functions.
675 * They write the contents of a specific function to a TRACE.
677 *****************************************************************************/
678 static void
679 DDRAW_dump_DWORD(const void *in)
681 TRACE("%d\n", *((const DWORD *) in));
683 static void
684 DDRAW_dump_PTR(const void *in)
686 TRACE("%p\n", *((const void * const*) in));
688 static void
689 DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
691 TRACE("Low : 0x%08x - High : 0x%08x\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
694 static void DDRAW_dump_flags_nolf(DWORD flags, const struct flag_info *names, size_t num_names)
696 unsigned int i;
698 for (i=0; i < num_names; i++)
699 if ((flags & names[i].val) || /* standard flag value */
700 ((!flags) && (!names[i].val))) /* zero value only */
701 TRACE("%s ", names[i].name);
704 static void DDRAW_dump_flags(DWORD flags, const struct flag_info *names, size_t num_names)
706 DDRAW_dump_flags_nolf(flags, names, num_names);
707 TRACE("\n");
710 void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
712 static const struct flag_info flags[] =
714 FE(DDSCAPS_RESERVED1),
715 FE(DDSCAPS_ALPHA),
716 FE(DDSCAPS_BACKBUFFER),
717 FE(DDSCAPS_COMPLEX),
718 FE(DDSCAPS_FLIP),
719 FE(DDSCAPS_FRONTBUFFER),
720 FE(DDSCAPS_OFFSCREENPLAIN),
721 FE(DDSCAPS_OVERLAY),
722 FE(DDSCAPS_PALETTE),
723 FE(DDSCAPS_PRIMARYSURFACE),
724 FE(DDSCAPS_PRIMARYSURFACELEFT),
725 FE(DDSCAPS_SYSTEMMEMORY),
726 FE(DDSCAPS_TEXTURE),
727 FE(DDSCAPS_3DDEVICE),
728 FE(DDSCAPS_VIDEOMEMORY),
729 FE(DDSCAPS_VISIBLE),
730 FE(DDSCAPS_WRITEONLY),
731 FE(DDSCAPS_ZBUFFER),
732 FE(DDSCAPS_OWNDC),
733 FE(DDSCAPS_LIVEVIDEO),
734 FE(DDSCAPS_HWCODEC),
735 FE(DDSCAPS_MODEX),
736 FE(DDSCAPS_MIPMAP),
737 FE(DDSCAPS_RESERVED2),
738 FE(DDSCAPS_ALLOCONLOAD),
739 FE(DDSCAPS_VIDEOPORT),
740 FE(DDSCAPS_LOCALVIDMEM),
741 FE(DDSCAPS_NONLOCALVIDMEM),
742 FE(DDSCAPS_STANDARDVGAMODE),
743 FE(DDSCAPS_OPTIMIZED)
745 static const struct flag_info flags2[] =
747 FE(DDSCAPS2_HARDWAREDEINTERLACE),
748 FE(DDSCAPS2_HINTDYNAMIC),
749 FE(DDSCAPS2_HINTSTATIC),
750 FE(DDSCAPS2_TEXTUREMANAGE),
751 FE(DDSCAPS2_RESERVED1),
752 FE(DDSCAPS2_RESERVED2),
753 FE(DDSCAPS2_OPAQUE),
754 FE(DDSCAPS2_HINTANTIALIASING),
755 FE(DDSCAPS2_CUBEMAP),
756 FE(DDSCAPS2_CUBEMAP_POSITIVEX),
757 FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
758 FE(DDSCAPS2_CUBEMAP_POSITIVEY),
759 FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
760 FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
761 FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
762 FE(DDSCAPS2_MIPMAPSUBLEVEL),
763 FE(DDSCAPS2_D3DTEXTUREMANAGE),
764 FE(DDSCAPS2_DONOTPERSIST),
765 FE(DDSCAPS2_STEREOSURFACELEFT)
768 DDRAW_dump_flags_nolf(in->dwCaps, flags, ARRAY_SIZE(flags));
769 DDRAW_dump_flags(in->dwCaps2, flags2, ARRAY_SIZE(flags2));
772 static void
773 DDRAW_dump_DDSCAPS(const DDSCAPS *in)
775 DDSCAPS2 in_bis;
777 in_bis.dwCaps = in->dwCaps;
778 in_bis.dwCaps2 = 0;
779 in_bis.dwCaps3 = 0;
780 in_bis.u1.dwCaps4 = 0;
782 DDRAW_dump_DDSCAPS2(&in_bis);
785 static void
786 DDRAW_dump_pixelformat_flag(DWORD flagmask)
788 static const struct flag_info flags[] =
790 FE(DDPF_ALPHAPIXELS),
791 FE(DDPF_ALPHA),
792 FE(DDPF_FOURCC),
793 FE(DDPF_PALETTEINDEXED4),
794 FE(DDPF_PALETTEINDEXEDTO8),
795 FE(DDPF_PALETTEINDEXED8),
796 FE(DDPF_RGB),
797 FE(DDPF_COMPRESSED),
798 FE(DDPF_RGBTOYUV),
799 FE(DDPF_YUV),
800 FE(DDPF_ZBUFFER),
801 FE(DDPF_PALETTEINDEXED1),
802 FE(DDPF_PALETTEINDEXED2),
803 FE(DDPF_ZPIXELS)
806 DDRAW_dump_flags_nolf(flagmask, flags, ARRAY_SIZE(flags));
809 static void DDRAW_dump_members(DWORD flags, const void *data, const struct member_info *mems, size_t num_mems)
811 unsigned int i;
813 for (i=0; i < num_mems; i++)
815 if (mems[i].val & flags)
817 TRACE(" - %s : ", mems[i].name);
818 mems[i].func((const char *)data + mems[i].offset);
823 static void
824 DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
826 TRACE("( ");
827 DDRAW_dump_pixelformat_flag(pf->dwFlags);
828 if (pf->dwFlags & DDPF_FOURCC)
829 TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %u bits per pixel",
830 (unsigned char)( pf->dwFourCC &0xff),
831 (unsigned char)((pf->dwFourCC>> 8)&0xff),
832 (unsigned char)((pf->dwFourCC>>16)&0xff),
833 (unsigned char)((pf->dwFourCC>>24)&0xff),
834 pf->dwFourCC,
835 pf->u1.dwYUVBitCount);
836 if (pf->dwFlags & DDPF_RGB)
838 TRACE(", RGB bits: %u, R 0x%08x G 0x%08x B 0x%08x",
839 pf->u1.dwRGBBitCount,
840 pf->u2.dwRBitMask,
841 pf->u3.dwGBitMask,
842 pf->u4.dwBBitMask);
843 if (pf->dwFlags & DDPF_ALPHAPIXELS)
844 TRACE(" A 0x%08x", pf->u5.dwRGBAlphaBitMask);
845 if (pf->dwFlags & DDPF_ZPIXELS)
846 TRACE(" Z 0x%08x", pf->u5.dwRGBZBitMask);
848 if (pf->dwFlags & DDPF_ZBUFFER)
849 TRACE(", Z bits: %u", pf->u1.dwZBufferBitDepth);
850 if (pf->dwFlags & DDPF_ALPHA)
851 TRACE(", Alpha bits: %u", pf->u1.dwAlphaBitDepth);
852 if (pf->dwFlags & DDPF_BUMPDUDV)
853 TRACE(", Bump bits: %u, U 0x%08x V 0x%08x L 0x%08x",
854 pf->u1.dwBumpBitCount,
855 pf->u2.dwBumpDuBitMask,
856 pf->u3.dwBumpDvBitMask,
857 pf->u4.dwBumpLuminanceBitMask);
858 TRACE(")\n");
861 void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
863 #define STRUCT DDSURFACEDESC2
864 static const struct member_info members[] =
866 ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
867 ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
868 ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
869 ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
870 ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, u5.dwBackBufferCount),
871 ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
872 ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
873 ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
874 ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
875 ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
876 ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
877 ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
878 ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
879 ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
880 ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
882 static const struct member_info members_caps[] =
884 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
886 static const struct member_info members_caps2[] =
888 ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
890 #undef STRUCT
892 if (NULL == lpddsd)
894 TRACE("(null)\n");
896 else
898 if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
900 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
902 else
904 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
906 DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members, ARRAY_SIZE(members));
910 void
911 dump_D3DMATRIX(const D3DMATRIX *mat)
913 TRACE(" %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
914 TRACE(" %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
915 TRACE(" %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
916 TRACE(" %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
919 DWORD
920 get_flexible_vertex_size(DWORD d3dvtVertexType)
922 DWORD size = 0;
923 DWORD i;
925 if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
926 if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
927 if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
928 if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
929 switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
931 case D3DFVF_XYZ: size += 3 * sizeof(D3DVALUE); break;
932 case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
933 case D3DFVF_XYZB1: size += 4 * sizeof(D3DVALUE); break;
934 case D3DFVF_XYZB2: size += 5 * sizeof(D3DVALUE); break;
935 case D3DFVF_XYZB3: size += 6 * sizeof(D3DVALUE); break;
936 case D3DFVF_XYZB4: size += 7 * sizeof(D3DVALUE); break;
937 case D3DFVF_XYZB5: size += 8 * sizeof(D3DVALUE); break;
938 default: ERR("Unexpected position mask\n");
940 for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
942 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
945 return size;
948 void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
950 /* 2 adds three additional caps fields to the end. Both versions
951 * are unversioned. */
952 pOut->dwCaps = pIn->dwCaps;
953 pOut->dwCaps2 = 0;
954 pOut->dwCaps3 = 0;
955 pOut->u1.dwCaps4 = 0;
958 void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
960 /* 2 adds a dwWHQLLevel field to the end. Both structures are
961 * unversioned. */
962 memcpy(pOut, pIn, sizeof(*pOut));
965 void DDRAW_dump_cooperativelevel(DWORD cooplevel)
967 static const struct flag_info flags[] =
969 FE(DDSCL_FULLSCREEN),
970 FE(DDSCL_ALLOWREBOOT),
971 FE(DDSCL_NOWINDOWCHANGES),
972 FE(DDSCL_NORMAL),
973 FE(DDSCL_ALLOWMODEX),
974 FE(DDSCL_EXCLUSIVE),
975 FE(DDSCL_SETFOCUSWINDOW),
976 FE(DDSCL_SETDEVICEWINDOW),
977 FE(DDSCL_CREATEDEVICEWINDOW)
980 if (TRACE_ON(ddraw))
982 TRACE(" - ");
983 DDRAW_dump_flags(cooplevel, flags, ARRAY_SIZE(flags));
987 void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
989 static const struct flag_info flags1[] =
991 FE(DDCAPS_3D),
992 FE(DDCAPS_ALIGNBOUNDARYDEST),
993 FE(DDCAPS_ALIGNSIZEDEST),
994 FE(DDCAPS_ALIGNBOUNDARYSRC),
995 FE(DDCAPS_ALIGNSIZESRC),
996 FE(DDCAPS_ALIGNSTRIDE),
997 FE(DDCAPS_BLT),
998 FE(DDCAPS_BLTQUEUE),
999 FE(DDCAPS_BLTFOURCC),
1000 FE(DDCAPS_BLTSTRETCH),
1001 FE(DDCAPS_GDI),
1002 FE(DDCAPS_OVERLAY),
1003 FE(DDCAPS_OVERLAYCANTCLIP),
1004 FE(DDCAPS_OVERLAYFOURCC),
1005 FE(DDCAPS_OVERLAYSTRETCH),
1006 FE(DDCAPS_PALETTE),
1007 FE(DDCAPS_PALETTEVSYNC),
1008 FE(DDCAPS_READSCANLINE),
1009 FE(DDCAPS_STEREOVIEW),
1010 FE(DDCAPS_VBI),
1011 FE(DDCAPS_ZBLTS),
1012 FE(DDCAPS_ZOVERLAYS),
1013 FE(DDCAPS_COLORKEY),
1014 FE(DDCAPS_ALPHA),
1015 FE(DDCAPS_COLORKEYHWASSIST),
1016 FE(DDCAPS_NOHARDWARE),
1017 FE(DDCAPS_BLTCOLORFILL),
1018 FE(DDCAPS_BANKSWITCHED),
1019 FE(DDCAPS_BLTDEPTHFILL),
1020 FE(DDCAPS_CANCLIP),
1021 FE(DDCAPS_CANCLIPSTRETCHED),
1022 FE(DDCAPS_CANBLTSYSMEM)
1024 static const struct flag_info flags2[] =
1026 FE(DDCAPS2_CERTIFIED),
1027 FE(DDCAPS2_NO2DDURING3DSCENE),
1028 FE(DDCAPS2_VIDEOPORT),
1029 FE(DDCAPS2_AUTOFLIPOVERLAY),
1030 FE(DDCAPS2_CANBOBINTERLEAVED),
1031 FE(DDCAPS2_CANBOBNONINTERLEAVED),
1032 FE(DDCAPS2_COLORCONTROLOVERLAY),
1033 FE(DDCAPS2_COLORCONTROLPRIMARY),
1034 FE(DDCAPS2_CANDROPZ16BIT),
1035 FE(DDCAPS2_NONLOCALVIDMEM),
1036 FE(DDCAPS2_NONLOCALVIDMEMCAPS),
1037 FE(DDCAPS2_NOPAGELOCKREQUIRED),
1038 FE(DDCAPS2_WIDESURFACES),
1039 FE(DDCAPS2_CANFLIPODDEVEN),
1040 FE(DDCAPS2_CANBOBHARDWARE),
1041 FE(DDCAPS2_COPYFOURCC),
1042 FE(DDCAPS2_PRIMARYGAMMA),
1043 FE(DDCAPS2_CANRENDERWINDOWED),
1044 FE(DDCAPS2_CANCALIBRATEGAMMA),
1045 FE(DDCAPS2_FLIPINTERVAL),
1046 FE(DDCAPS2_FLIPNOVSYNC),
1047 FE(DDCAPS2_CANMANAGETEXTURE),
1048 FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
1049 FE(DDCAPS2_STEREO),
1050 FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
1052 static const struct flag_info flags3[] =
1054 FE(DDCKEYCAPS_DESTBLT),
1055 FE(DDCKEYCAPS_DESTBLTCLRSPACE),
1056 FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
1057 FE(DDCKEYCAPS_DESTBLTYUV),
1058 FE(DDCKEYCAPS_DESTOVERLAY),
1059 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
1060 FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
1061 FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
1062 FE(DDCKEYCAPS_DESTOVERLAYYUV),
1063 FE(DDCKEYCAPS_SRCBLT),
1064 FE(DDCKEYCAPS_SRCBLTCLRSPACE),
1065 FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
1066 FE(DDCKEYCAPS_SRCBLTYUV),
1067 FE(DDCKEYCAPS_SRCOVERLAY),
1068 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
1069 FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
1070 FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
1071 FE(DDCKEYCAPS_SRCOVERLAYYUV),
1072 FE(DDCKEYCAPS_NOCOSTOVERLAY)
1074 static const struct flag_info flags4[] =
1076 FE(DDFXCAPS_BLTALPHA),
1077 FE(DDFXCAPS_OVERLAYALPHA),
1078 FE(DDFXCAPS_BLTARITHSTRETCHYN),
1079 FE(DDFXCAPS_BLTARITHSTRETCHY),
1080 FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
1081 FE(DDFXCAPS_BLTMIRRORUPDOWN),
1082 FE(DDFXCAPS_BLTROTATION),
1083 FE(DDFXCAPS_BLTROTATION90),
1084 FE(DDFXCAPS_BLTSHRINKX),
1085 FE(DDFXCAPS_BLTSHRINKXN),
1086 FE(DDFXCAPS_BLTSHRINKY),
1087 FE(DDFXCAPS_BLTSHRINKYN),
1088 FE(DDFXCAPS_BLTSTRETCHX),
1089 FE(DDFXCAPS_BLTSTRETCHXN),
1090 FE(DDFXCAPS_BLTSTRETCHY),
1091 FE(DDFXCAPS_BLTSTRETCHYN),
1092 FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
1093 FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
1094 FE(DDFXCAPS_OVERLAYSHRINKX),
1095 FE(DDFXCAPS_OVERLAYSHRINKXN),
1096 FE(DDFXCAPS_OVERLAYSHRINKY),
1097 FE(DDFXCAPS_OVERLAYSHRINKYN),
1098 FE(DDFXCAPS_OVERLAYSTRETCHX),
1099 FE(DDFXCAPS_OVERLAYSTRETCHXN),
1100 FE(DDFXCAPS_OVERLAYSTRETCHY),
1101 FE(DDFXCAPS_OVERLAYSTRETCHYN),
1102 FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
1103 FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
1105 static const struct flag_info flags5[] =
1107 FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
1108 FE(DDFXALPHACAPS_BLTALPHAPIXELS),
1109 FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
1110 FE(DDFXALPHACAPS_BLTALPHASURFACES),
1111 FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
1112 FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
1113 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
1114 FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
1115 FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
1116 FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
1118 static const struct flag_info flags6[] =
1120 FE(DDPCAPS_4BIT),
1121 FE(DDPCAPS_8BITENTRIES),
1122 FE(DDPCAPS_8BIT),
1123 FE(DDPCAPS_INITIALIZE),
1124 FE(DDPCAPS_PRIMARYSURFACE),
1125 FE(DDPCAPS_PRIMARYSURFACELEFT),
1126 FE(DDPCAPS_ALLOW256),
1127 FE(DDPCAPS_VSYNC),
1128 FE(DDPCAPS_1BIT),
1129 FE(DDPCAPS_2BIT),
1130 FE(DDPCAPS_ALPHA),
1132 static const struct flag_info flags7[] =
1134 FE(DDSVCAPS_RESERVED1),
1135 FE(DDSVCAPS_RESERVED2),
1136 FE(DDSVCAPS_RESERVED3),
1137 FE(DDSVCAPS_RESERVED4),
1138 FE(DDSVCAPS_STEREOSEQUENTIAL),
1141 TRACE(" - dwSize : %d\n", lpcaps->dwSize);
1142 TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, ARRAY_SIZE(flags1));
1143 TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, ARRAY_SIZE(flags2));
1144 TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, ARRAY_SIZE(flags3));
1145 TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, ARRAY_SIZE(flags4));
1146 TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, ARRAY_SIZE(flags5));
1147 TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, ARRAY_SIZE(flags6));
1148 TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, ARRAY_SIZE(flags7));
1149 TRACE("...\n");
1150 TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
1151 TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
1152 TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
1153 TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
1154 TRACE("...\n");
1155 TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1158 void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2)
1160 struct wined3d_matrix temp;
1162 /* Now do the multiplication 'by hand'.
1163 I know that all this could be optimised, but this will be done later :-) */
1164 temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
1165 temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
1166 temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
1167 temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
1169 temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
1170 temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
1171 temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
1172 temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
1174 temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
1175 temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
1176 temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
1177 temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
1179 temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
1180 temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
1181 temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
1182 temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
1184 *dst = temp;
1187 HRESULT
1188 hr_ddraw_from_wined3d(HRESULT hr)
1190 switch(hr)
1192 case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
1193 case WINED3DERR_NOTAVAILABLE: return DDERR_UNSUPPORTED;
1194 case WINEDDERR_NOTAOVERLAYSURFACE: return DDERR_NOTAOVERLAYSURFACE;
1195 case WINEDDERR_OVERLAYNOTVISIBLE: return DDERR_OVERLAYNOTVISIBLE;
1196 default: return hr;
1200 /* Note that this function writes the full sizeof(DDSURFACEDESC2) size, don't use it
1201 * for writing into application-provided DDSURFACEDESC2 structures if the size may
1202 * be different */
1203 void DDSD_to_DDSD2(const DDSURFACEDESC *in, DDSURFACEDESC2 *out)
1205 /* The output of this function is never passed to the application directly, so
1206 * the memset is not strictly needed. CreateSurface still has problems with this
1207 * though. Don't forget to set ddsCaps.dwCaps2/3/4 to 0 when removing this */
1208 memset(out, 0x00, sizeof(*out));
1209 out->dwSize = sizeof(*out);
1210 out->dwFlags = in->dwFlags & ~DDSD_ZBUFFERBITDEPTH;
1211 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1212 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1213 if (in->dwFlags & DDSD_PIXELFORMAT) out->u4.ddpfPixelFormat = in->ddpfPixelFormat;
1214 else if(in->dwFlags & DDSD_ZBUFFERBITDEPTH)
1216 out->dwFlags |= DDSD_PIXELFORMAT;
1217 memset(&out->u4.ddpfPixelFormat, 0, sizeof(out->u4.ddpfPixelFormat));
1218 out->u4.ddpfPixelFormat.dwSize = sizeof(out->u4.ddpfPixelFormat);
1219 out->u4.ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
1220 out->u4.ddpfPixelFormat.u1.dwZBufferBitDepth = in->u2.dwZBufferBitDepth;
1221 /* 0 is not a valid DDSURFACEDESC / DDPIXELFORMAT on either side of the
1222 * conversion */
1223 out->u4.ddpfPixelFormat.u3.dwZBitMask = ~0U >> (32 - in->u2.dwZBufferBitDepth);
1225 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1226 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1227 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1228 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->u5.dwBackBufferCount = in->dwBackBufferCount;
1229 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1230 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1231 out->lpSurface = in->lpSurface;
1232 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->u3.ddckCKDestOverlay = in->ddckCKDestOverlay;
1233 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1234 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1235 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1236 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1237 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1238 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1239 /* Does not exist in DDSURFACEDESC:
1240 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1244 /* Note that this function writes the full sizeof(DDSURFACEDESC) size, don't use it
1245 * for writing into application-provided DDSURFACEDESC structures if the size may
1246 * be different */
1247 void DDSD2_to_DDSD(const DDSURFACEDESC2 *in, DDSURFACEDESC *out)
1249 memset(out, 0, sizeof(*out));
1250 out->dwSize = sizeof(*out);
1251 out->dwFlags = in->dwFlags;
1252 if (in->dwFlags & DDSD_WIDTH) out->dwWidth = in->dwWidth;
1253 if (in->dwFlags & DDSD_HEIGHT) out->dwHeight = in->dwHeight;
1254 if (in->dwFlags & DDSD_PIXELFORMAT)
1256 out->ddpfPixelFormat = in->u4.ddpfPixelFormat;
1257 if ((in->dwFlags & DDSD_CAPS) && (in->ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
1259 /* Z buffers have DDSD_ZBUFFERBITDEPTH set, but not DDSD_PIXELFORMAT. They do
1260 * have valid data in ddpfPixelFormat though */
1261 out->dwFlags &= ~DDSD_PIXELFORMAT;
1262 out->dwFlags |= DDSD_ZBUFFERBITDEPTH;
1263 out->u2.dwZBufferBitDepth = in->u4.ddpfPixelFormat.u1.dwZBufferBitDepth;
1266 /* ddsCaps is read even without DDSD_CAPS set. See dsurface:no_ddsd_caps_test */
1267 out->ddsCaps.dwCaps = in->ddsCaps.dwCaps;
1268 if (in->dwFlags & DDSD_PITCH) out->u1.lPitch = in->u1.lPitch;
1269 if (in->dwFlags & DDSD_BACKBUFFERCOUNT) out->dwBackBufferCount = in->u5.dwBackBufferCount;
1270 if (in->dwFlags & DDSD_ZBUFFERBITDEPTH) out->u2.dwZBufferBitDepth = in->u2.dwMipMapCount; /* same union */
1271 if (in->dwFlags & DDSD_ALPHABITDEPTH) out->dwAlphaBitDepth = in->dwAlphaBitDepth;
1272 /* DDraw(native, and wine) does not set the DDSD_LPSURFACE, so always copy */
1273 out->lpSurface = in->lpSurface;
1274 if (in->dwFlags & DDSD_CKDESTOVERLAY) out->ddckCKDestOverlay = in->u3.ddckCKDestOverlay;
1275 if (in->dwFlags & DDSD_CKDESTBLT) out->ddckCKDestBlt = in->ddckCKDestBlt;
1276 if (in->dwFlags & DDSD_CKSRCOVERLAY) out->ddckCKSrcOverlay = in->ddckCKSrcOverlay;
1277 if (in->dwFlags & DDSD_CKSRCBLT) out->ddckCKSrcBlt = in->ddckCKSrcBlt;
1278 if (in->dwFlags & DDSD_MIPMAPCOUNT) out->u2.dwMipMapCount = in->u2.dwMipMapCount;
1279 if (in->dwFlags & DDSD_REFRESHRATE) out->u2.dwRefreshRate = in->u2.dwRefreshRate;
1280 if (in->dwFlags & DDSD_LINEARSIZE) out->u1.dwLinearSize = in->u1.dwLinearSize;
1281 /* Does not exist in DDSURFACEDESC:
1282 * DDSD_TEXTURESTAGE, DDSD_FVF, DDSD_SRCVBHANDLE,
1284 if (in->dwFlags & DDSD_TEXTURESTAGE) WARN("Does not exist in DDSURFACEDESC: DDSD_TEXTURESTAGE\n");
1285 if (in->dwFlags & DDSD_FVF) WARN("Does not exist in DDSURFACEDESC: DDSD_FVF\n");
1286 if (in->dwFlags & DDSD_SRCVBHANDLE) WARN("Does not exist in DDSURFACEDESC: DDSD_SRCVBHANDLE\n");
1287 out->dwFlags &= ~(DDSD_TEXTURESTAGE | DDSD_FVF | DDSD_SRCVBHANDLE);