utils.c 42.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
/*
 * DirectDraw helper functions
 *
 * Copyright (c) 1997-2000 Marcus Meissner
 * Copyright (c) 1998 Lionel Ulmer
 * Copyright (c) 2000 TransGaming Technologies Inc.
 * Copyright (c) 2006 Stefan Dsinger
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "config.h"

#define NONAMELESSUNION

#include "ddraw_private.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(ddraw);


/*****************************************************************************
 * PixelFormat_WineD3DtoDD
 *
 * Converts an WINED3DFORMAT value into a DDPIXELFORMAT structure
 *
 * Params:
 *  DDPixelFormat: Address of the structure to write the pixel format to
 *  WineD3DFormat: Source format
 *
 *****************************************************************************/
void
PixelFormat_WineD3DtoDD(DDPIXELFORMAT *DDPixelFormat,
                        WINED3DFORMAT WineD3DFormat)
{
    DWORD Size = DDPixelFormat->dwSize;
    TRACE("Converting WINED3DFORMAT %d to DDRAW\n", WineD3DFormat);

    if(Size==0) return;

    memset(DDPixelFormat, 0x00, Size);
    DDPixelFormat->dwSize = Size;
    switch(WineD3DFormat)
    {
        case WINED3DFMT_R8G8B8:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 24;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_A8R8G8B8:
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xff000000;
            break;

        case WINED3DFMT_X8R8G8B8:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x00ff0000;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x000000ff;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_X8B8G8R8:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 32;
            DDPixelFormat->u2.dwRBitMask = 0x000000ff;
            DDPixelFormat->u3.dwGBitMask = 0x0000ff00;
            DDPixelFormat->u4.dwBBitMask = 0x00ff0000;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_R5G6B5:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0xF800;
            DDPixelFormat->u3.dwGBitMask = 0x07E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_X1R5G5B5:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x7C00;
            DDPixelFormat->u3.dwGBitMask = 0x03E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_A1R5G5B5:
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x7C00;
            DDPixelFormat->u3.dwGBitMask = 0x03E0;
            DDPixelFormat->u4.dwBBitMask = 0x001F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x8000;
            break;

        case WINED3DFMT_A4R4G4B4:
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x0F00;
            DDPixelFormat->u3.dwGBitMask = 0x00F0;
            DDPixelFormat->u4.dwBBitMask = 0x000F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
            break;

        case WINED3DFMT_R3G3B2:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 8;
            DDPixelFormat->u2.dwRBitMask = 0xE0;
            DDPixelFormat->u3.dwGBitMask = 0x1C;
            DDPixelFormat->u4.dwBBitMask = 0x03;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_P8:
            DDPixelFormat->dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 8;
            DDPixelFormat->u2.dwRBitMask = 0x00;
            DDPixelFormat->u3.dwGBitMask = 0x00;
            DDPixelFormat->u4.dwBBitMask = 0x00;
            break;

        case WINED3DFMT_A8:
            DDPixelFormat->dwFlags = DDPF_ALPHA;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwAlphaBitDepth = 8;
            DDPixelFormat->u2.dwRBitMask = 0x0;
            DDPixelFormat->u3.dwZBitMask = 0x0;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_A8R3G3B2:
            DDPixelFormat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x00E0;
            DDPixelFormat->u3.dwGBitMask = 0x001C;
            DDPixelFormat->u4.dwBBitMask = 0x0003;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0xF000;
            break;

        case WINED3DFMT_X4R4G4B4:
            DDPixelFormat->dwFlags = DDPF_RGB;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwRGBBitCount = 16;
            DDPixelFormat->u2.dwRBitMask = 0x0F00;
            DDPixelFormat->u3.dwGBitMask = 0x00F0;
            DDPixelFormat->u4.dwBBitMask = 0x000F;
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            return;

        /* How are Z buffer bit depth and Stencil buffer bit depth related?
         */
        case WINED3DFMT_D16:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwZBufferBitDepth = 16;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
            DDPixelFormat->u3.dwZBitMask = 0x0000FFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
195
            DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
196 197 198 199 200 201 202 203 204
            break;

        case WINED3DFMT_D32:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
            DDPixelFormat->u3.dwZBitMask = 0xFFFFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0;
205
            DDPixelFormat->u5.dwRGBZBitMask = 0x00000000;
206 207 208 209 210 211
            break;

        case WINED3DFMT_D24X4S4:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
            /* Should I set dwZBufferBitDepth to 32 here? */
212
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
213
            DDPixelFormat->u2.dwStencilBitDepth = 4;
214 215
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x0F000000;
216 217 218 219 220 221 222
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_D24S8:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
            /* Should I set dwZBufferBitDepth to 32 here? */
223
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
224
            DDPixelFormat->u2.dwStencilBitDepth = 8;
225 226
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0xFF000000;
227 228 229 230 231 232
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_D24X8:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER;
            DDPixelFormat->dwFourCC = 0;
233 234 235 236
            DDPixelFormat->u1.dwZBufferBitDepth = 32;
            DDPixelFormat->u2.dwStencilBitDepth = 0;
            DDPixelFormat->u3.dwZBitMask = 0x00FFFFFFFF;
            DDPixelFormat->u4.dwStencilBitMask = 0x00000000;
237 238 239 240 241 242
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;

            break;
        case WINED3DFMT_D15S1:
            DDPixelFormat->dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
            DDPixelFormat->dwFourCC = 0;
243
            DDPixelFormat->u1.dwZBufferBitDepth = 16;
244
            DDPixelFormat->u2.dwStencilBitDepth = 1;
245 246
            DDPixelFormat->u3.dwZBitMask = 0x7fff;
            DDPixelFormat->u4.dwStencilBitMask = 0x8000;
247 248 249 250 251
            DDPixelFormat->u5.dwRGBAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_UYVY:
        case WINED3DFMT_YUY2:
252
        case WINED3DFMT_YV12:
253 254 255 256 257
        case WINED3DFMT_DXT1:
        case WINED3DFMT_DXT2:
        case WINED3DFMT_DXT3:
        case WINED3DFMT_DXT4:
        case WINED3DFMT_DXT5:
258
        case WINED3DFMT_MULTI2_ARGB8:
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        case WINED3DFMT_G8R8_G8B8:
        case WINED3DFMT_R8G8_B8G8:
            DDPixelFormat->dwFlags = DDPF_FOURCC;
            DDPixelFormat->dwFourCC = WineD3DFormat;
            break;

        /* Luminance */
        case WINED3DFMT_L8:
            DDPixelFormat->dwFlags = DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 8;
            DDPixelFormat->u2.dwLuminanceBitMask = 0xff;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x0;
            break;

        case WINED3DFMT_A4L4:
            DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 4;
            DDPixelFormat->u2.dwLuminanceBitMask = 0x0f;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xf0;
            break;

        case WINED3DFMT_A8L8:
            DDPixelFormat->dwFlags = DDPF_ALPHAPIXELS | DDPF_LUMINANCE;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwLuminanceBitCount = 16;
            DDPixelFormat->u2.dwLuminanceBitMask = 0x00ff;
            DDPixelFormat->u3.dwBumpDvBitMask = 0x0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask = 0x0;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0xff00;
            break;

        /* Bump mapping */
        case WINED3DFMT_V8U8:
            DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwBumpBitCount = 16;
            DDPixelFormat->u2.dwBumpDuBitMask =         0x000000ff;
            DDPixelFormat->u3.dwBumpDvBitMask =         0x0000ff00;
            DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x00000000;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
            break;

        case WINED3DFMT_L6V5U5:
            DDPixelFormat->dwFlags = DDPF_BUMPDUDV;
            DDPixelFormat->dwFourCC = 0;
            DDPixelFormat->u1.dwBumpBitCount = 16;
            DDPixelFormat->u2.dwBumpDuBitMask =         0x0000001f;
            DDPixelFormat->u3.dwBumpDvBitMask =         0x000003e0;
            DDPixelFormat->u4.dwBumpLuminanceBitMask =  0x0000fc00;
            DDPixelFormat->u5.dwLuminanceAlphaBitMask = 0x00000000;
            break;

        default:
            ERR("Can't translate this Pixelformat %d\n", WineD3DFormat);
    }

    if(TRACE_ON(ddraw)) {
        TRACE("Returning: ");
        DDRAW_dump_pixelformat(DDPixelFormat);
    }
}
/*****************************************************************************
 * PixelFormat_DD2WineD3D
 *
 * Reads a DDPIXELFORMAT structure and returns the equal WINED3DFORMAT
 *
 * Params:
 *  DDPixelFormat: The source format
 *
 * Returns:
 *  The WINED3DFORMAT equal to the DDraw format
 *  WINED3DFMT_UNKNOWN if a matching format wasn't found
 *****************************************************************************/
WINED3DFORMAT
339
PixelFormat_DD2WineD3D(const DDPIXELFORMAT *DDPixelFormat)
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
{
    TRACE("Convert a DirectDraw Pixelformat to a WineD3D Pixelformat\n");    
    if(TRACE_ON(ddraw))
    {
        DDRAW_dump_pixelformat(DDPixelFormat);
    }

    if(DDPixelFormat->dwFlags & DDPF_PALETTEINDEXED8)
    {
        return WINED3DFMT_P8;
    }
    else if(DDPixelFormat->dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4) )
    {
        FIXME("DDPF_PALETTEINDEXED1 to DDPF_PALETTEINDEXED4 are not supported by WineD3D (yet). Returning WINED3DFMT_P8\n");
        return WINED3DFMT_P8;
    }
    else if(DDPixelFormat->dwFlags & DDPF_RGB)
    {
        switch(DDPixelFormat->u1.dwRGBBitCount)
        {
            case 8:
                /* This is the only format that can match here */
                return WINED3DFMT_R3G3B2;

            case 16:
                /* Read the Color masks */
                if( (DDPixelFormat->u2.dwRBitMask == 0xF800) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x07E0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x001F) )
                {
                    return WINED3DFMT_R5G6B5;
                }

                if( (DDPixelFormat->u2.dwRBitMask == 0x7C00) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x03E0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x001F) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0x8000))
                        return WINED3DFMT_A1R5G5B5;
                    else
                        return WINED3DFMT_X1R5G5B5;
                }

                if( (DDPixelFormat->u2.dwRBitMask == 0x0F00) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x00F0) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x000F) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xF000))
                        return WINED3DFMT_A4R4G4B4;
                    else
                        return WINED3DFMT_X4R4G4B4;
                }

                if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                    (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF00) &&
                    (DDPixelFormat->u2.dwRBitMask == 0x00E0) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x001C) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x0003) )
                {
                    return WINED3DFMT_A8R3G3B2;
                }
                ERR("16 bit RGB Pixel format does not match\n");
                return WINED3DFMT_UNKNOWN;

            case 24:
                return WINED3DFMT_R8G8B8;

            case 32:
                /* Read the Color masks */
                if( (DDPixelFormat->u2.dwRBitMask == 0x00FF0000) &&
                    (DDPixelFormat->u3.dwGBitMask == 0x0000FF00) &&
                    (DDPixelFormat->u4.dwBBitMask == 0x000000FF) )
                {
                    if( (DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS) &&
                        (DDPixelFormat->u5.dwRGBAlphaBitMask == 0xFF000000))
                        return WINED3DFMT_A8R8G8B8;
                    else
                        return WINED3DFMT_X8R8G8B8;

                }
                ERR("32 bit RGB pixel format does not match\n");

            default:
                ERR("Invalid dwRGBBitCount in Pixelformat structure\n");
                return WINED3DFMT_UNKNOWN;
        }
    }
    else if( (DDPixelFormat->dwFlags & DDPF_ALPHA) )
    {
        /* Alpha only Pixelformat */
        switch(DDPixelFormat->u1.dwAlphaBitDepth)
        {
            case 1:
            case 2:
            case 4:
437
                ERR("Unsupported Alpha-Only bit depth 0x%x\n", DDPixelFormat->u1.dwAlphaBitDepth);
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
            case 8:
                return WINED3DFMT_A8;

            default:
                ERR("Invalid AlphaBitDepth in Alpha-Only Pixelformat\n");
                return WINED3DFMT_UNKNOWN;
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_LUMINANCE)
    {
        /* Luminance-only or luminance-alpha */
        if(DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS)
        {
            /* Luminance with Alpha */
            switch(DDPixelFormat->u1.dwLuminanceBitCount)
            {
                case 4:
                    if(DDPixelFormat->u1.dwAlphaBitDepth == 4)
                        return WINED3DFMT_A4L4;
                    ERR("Unknown Alpha / Luminance bit depth combination\n");
                    return WINED3DFMT_UNKNOWN;

                case 6:
                    ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n");
                    return WINED3DFMT_L6V5U5;

                case 8:
                    if(DDPixelFormat->u1.dwAlphaBitDepth == 8)
                        return WINED3DFMT_A8L8;
467
                    ERR("Unknown Alpha / Lumincase bit depth combination\n");
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
                    return WINED3DFMT_UNKNOWN;
            }
        }
        else
        {
            /* Luminance-only */
            switch(DDPixelFormat->u1.dwLuminanceBitCount)
            {
                case 6:
                    ERR("A luminance Pixelformat shouldn't have 6 luminance bits. Returning D3DFMT_L6V5U5 for now!!\n");
                    return WINED3DFMT_L6V5U5;

                case 8:
                    return WINED3DFMT_L8;

                default:
484
                    ERR("Unknown luminance-only bit depth 0x%x\n", DDPixelFormat->u1.dwLuminanceBitCount);
485 486 487 488 489 490 491 492 493 494 495 496
                    return WINED3DFMT_UNKNOWN;
             }
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_ZBUFFER)
    {
        /* Z buffer */
        if(DDPixelFormat->dwFlags & DDPF_STENCILBUFFER)
        {
            switch(DDPixelFormat->u1.dwZBufferBitDepth)
            {
                case 8:
497
                    FIXME("8 Bits Z+Stencil buffer pixelformat is not supported. Returning WINED3DFMT_UNKNOWN\n");
498 499 500
                    return WINED3DFMT_UNKNOWN;

                case 15:
501
                    FIXME("15 bit depth buffer not handled yet, assuming 16 bit\n");
502 503 504 505
                case 16:
                    if(DDPixelFormat->u2.dwStencilBitDepth == 1)
                        return WINED3DFMT_D15S1;

506
                    FIXME("Don't know how to handle a 16 bit Z buffer with %d bit stencil buffer pixelformat\n", DDPixelFormat->u2.dwStencilBitDepth);
507 508 509
                    return WINED3DFMT_UNKNOWN;

                case 24:
510
                    FIXME("Don't know how to handle a 24 bit depth buffer with stencil bits\n");
511 512 513 514 515 516 517 518 519
                    return WINED3DFMT_D24S8;

                case 32:
                    if(DDPixelFormat->u2.dwStencilBitDepth == 8)
                        return WINED3DFMT_D24S8;
                    else
                        return WINED3DFMT_D24X4S4;

                default:
520
                    ERR("Unknown Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth);
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
                    return WINED3DFMT_UNKNOWN;
            }
        }
        else
        {
            switch(DDPixelFormat->u1.dwZBufferBitDepth)
            {
                case 8:
                    ERR("8 Bit Z buffers are not supported. Trying a 16 Bit one\n");
                    return WINED3DFMT_D16;

                case 16:
                    return WINED3DFMT_D16;

                case 24:
536
                    FIXME("24 Bit depth buffer, treating like a 32 bit one\n");
537
                case 32:
538 539 540 541 542 543 544
                    if(DDPixelFormat->u3.dwZBitMask == 0x00FFFFFF) {
                        return WINED3DFMT_D24X8;
                    } else if(DDPixelFormat->u3.dwZBitMask == 0xFFFFFFFF) {
                        return WINED3DFMT_D32;
                    }
                    FIXME("Unhandled 32 bit depth buffer bitmasks, returning WINED3DFMT_D24X8\n");
                    return WINED3DFMT_D24X8; /* That's most likely to make games happy */
545 546

                default:
547
                    ERR("Unsupported Z buffer depth %d\n", DDPixelFormat->u1.dwZBufferBitDepth);
548 549 550 551 552 553 554 555 556 557 558 559 560 561
                    return WINED3DFMT_UNKNOWN;
            }
        }
    }
    else if(DDPixelFormat->dwFlags & DDPF_FOURCC)
    {
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('U', 'Y', 'V', 'Y'))
        {
            return WINED3DFMT_UYVY;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('Y', 'U', 'Y', '2'))
        {
            return WINED3DFMT_YUY2;
        }
562 563 564 565
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('Y', 'V', '1', '2'))
        {
            return WINED3DFMT_YV12;
        }
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('D', 'X', 'T', '1'))
        {
            return WINED3DFMT_DXT1;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('D', 'X', 'T', '2'))
        {
            return WINED3DFMT_DXT2;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('D', 'X', 'T', '3'))
        {
           return WINED3DFMT_DXT3;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('D', 'X', 'T', '4'))
        {
            return WINED3DFMT_DXT4;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('D', 'X', 'T', '5'))
        {
	    return WINED3DFMT_DXT5;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('G', 'R', 'G', 'B'))
        {
            return WINED3DFMT_G8R8_G8B8;
        }
        if(DDPixelFormat->dwFourCC == MAKEFOURCC('R', 'G', 'B', 'G'))
        {
            return WINED3DFMT_R8G8_B8G8;
        }
594
        return WINED3DFMT_UNKNOWN;  /* Abuse this as an error value */
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
    }
    else if(DDPixelFormat->dwFlags & DDPF_BUMPDUDV)
    {
        if( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
            (DDPixelFormat->u2.dwBumpDuBitMask        == 0x000000ff) &&
            (DDPixelFormat->u3.dwBumpDvBitMask        == 0x0000ff00) &&
            (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x00000000) )
        {
            return WINED3DFMT_V8U8;
        }
        else if ( (DDPixelFormat->u1.dwBumpBitCount         == 16        ) &&
                  (DDPixelFormat->u2.dwBumpDuBitMask        == 0x0000001f) &&
                  (DDPixelFormat->u3.dwBumpDvBitMask        == 0x000003e0) &&
                  (DDPixelFormat->u4.dwBumpLuminanceBitMask == 0x0000fc00) )
        {
            return WINED3DFMT_L6V5U5;
        }
    }

    ERR("Unknown Pixelformat!\n");
    return WINED3DFMT_UNKNOWN;
}

/*****************************************************************************
 * Various dumping functions.
 *
Andrew Riedi's avatar
Andrew Riedi committed
621
 * They write the contents of a specific function to a TRACE.
622 623 624 625 626
 *
 *****************************************************************************/
static void
DDRAW_dump_DWORD(const void *in)
{
627
    TRACE("%d\n", *((const DWORD *) in));
628 629 630 631
}
static void
DDRAW_dump_PTR(const void *in)
{
632
    TRACE("%p\n", *((const void * const*) in));
633
}
634
static void
635 636
DDRAW_dump_DDCOLORKEY(const DDCOLORKEY *ddck)
{
637
    TRACE("Low : %d  - High : %d\n", ddck->dwColorSpaceLowValue, ddck->dwColorSpaceHighValue);
638
}
639

640 641
static void DDRAW_dump_flags_nolf(DWORD flags, const flag_info* names,
                                  size_t num_names)
642 643 644 645 646 647
{
    unsigned int	i;

    for (i=0; i < num_names; i++)
        if ((flags & names[i].val) ||      /* standard flag value */
            ((!flags) && (!names[i].val))) /* zero value only */
648
            TRACE("%s ", names[i].name);
649
}
650

651
static void DDRAW_dump_flags(DWORD flags, const flag_info* names, size_t num_names)
652 653 654
{
    DDRAW_dump_flags_nolf(flags, names, num_names);
    TRACE("\n");
655 656
}

657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
void DDRAW_dump_DDSCAPS2(const DDSCAPS2 *in)
{
    static const flag_info flags[] = {
        FE(DDSCAPS_RESERVED1),
        FE(DDSCAPS_ALPHA),
        FE(DDSCAPS_BACKBUFFER),
        FE(DDSCAPS_COMPLEX),
        FE(DDSCAPS_FLIP),
        FE(DDSCAPS_FRONTBUFFER),
        FE(DDSCAPS_OFFSCREENPLAIN),
        FE(DDSCAPS_OVERLAY),
        FE(DDSCAPS_PALETTE),
        FE(DDSCAPS_PRIMARYSURFACE),
        FE(DDSCAPS_PRIMARYSURFACELEFT),
        FE(DDSCAPS_SYSTEMMEMORY),
        FE(DDSCAPS_TEXTURE),
        FE(DDSCAPS_3DDEVICE),
        FE(DDSCAPS_VIDEOMEMORY),
        FE(DDSCAPS_VISIBLE),
        FE(DDSCAPS_WRITEONLY),
        FE(DDSCAPS_ZBUFFER),
        FE(DDSCAPS_OWNDC),
        FE(DDSCAPS_LIVEVIDEO),
        FE(DDSCAPS_HWCODEC),
        FE(DDSCAPS_MODEX),
        FE(DDSCAPS_MIPMAP),
        FE(DDSCAPS_RESERVED2),
        FE(DDSCAPS_ALLOCONLOAD),
        FE(DDSCAPS_VIDEOPORT),
        FE(DDSCAPS_LOCALVIDMEM),
        FE(DDSCAPS_NONLOCALVIDMEM),
        FE(DDSCAPS_STANDARDVGAMODE),
        FE(DDSCAPS_OPTIMIZED)
    };
    static const flag_info flags2[] = {
        FE(DDSCAPS2_HARDWAREDEINTERLACE),
        FE(DDSCAPS2_HINTDYNAMIC),
        FE(DDSCAPS2_HINTSTATIC),
        FE(DDSCAPS2_TEXTUREMANAGE),
        FE(DDSCAPS2_RESERVED1),
        FE(DDSCAPS2_RESERVED2),
        FE(DDSCAPS2_OPAQUE),
        FE(DDSCAPS2_HINTANTIALIASING),
        FE(DDSCAPS2_CUBEMAP),
        FE(DDSCAPS2_CUBEMAP_POSITIVEX),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEX),
        FE(DDSCAPS2_CUBEMAP_POSITIVEY),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEY),
        FE(DDSCAPS2_CUBEMAP_POSITIVEZ),
        FE(DDSCAPS2_CUBEMAP_NEGATIVEZ),
        FE(DDSCAPS2_MIPMAPSUBLEVEL),
        FE(DDSCAPS2_D3DTEXTUREMANAGE),
        FE(DDSCAPS2_DONOTPERSIST),
        FE(DDSCAPS2_STEREOSURFACELEFT)
    };

713
    DDRAW_dump_flags_nolf(in->dwCaps, flags, sizeof(flags)/sizeof(flags[0]));
714
    DDRAW_dump_flags(in->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729
}

void
DDRAW_dump_DDSCAPS(const DDSCAPS *in)
{
    DDSCAPS2 in_bis;

    in_bis.dwCaps = in->dwCaps;
    in_bis.dwCaps2 = 0;
    in_bis.dwCaps3 = 0;
    in_bis.dwCaps4 = 0;

    DDRAW_dump_DDSCAPS2(&in_bis);
}

730
static void
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
DDRAW_dump_pixelformat_flag(DWORD flagmask)
{
    static const flag_info flags[] =
        {
            FE(DDPF_ALPHAPIXELS),
            FE(DDPF_ALPHA),
            FE(DDPF_FOURCC),
            FE(DDPF_PALETTEINDEXED4),
            FE(DDPF_PALETTEINDEXEDTO8),
            FE(DDPF_PALETTEINDEXED8),
            FE(DDPF_RGB),
            FE(DDPF_COMPRESSED),
            FE(DDPF_RGBTOYUV),
            FE(DDPF_YUV),
            FE(DDPF_ZBUFFER),
            FE(DDPF_PALETTEINDEXED1),
            FE(DDPF_PALETTEINDEXED2),
            FE(DDPF_ZPIXELS)
    };

751
    DDRAW_dump_flags_nolf(flagmask, flags, sizeof(flags)/sizeof(flags[0]));
752 753
}

754
static void
755 756 757 758 759 760 761 762 763 764 765
DDRAW_dump_members(DWORD flags,
                   const void* data,
                   const member_info* mems,
                   size_t num_mems)
{
    unsigned int i;

    for (i=0; i < num_mems; i++)
    {
        if (mems[i].val & flags)
        {
Andrew Riedi's avatar
Andrew Riedi committed
766
            TRACE(" - %s : ", mems[i].name);
767 768 769 770 771 772 773 774
            mems[i].func((const char *)data + mems[i].offset);
        }
    }
}

void
DDRAW_dump_pixelformat(const DDPIXELFORMAT *pf)
{
Andrew Riedi's avatar
Andrew Riedi committed
775
    TRACE("( ");
776 777 778
    DDRAW_dump_pixelformat_flag(pf->dwFlags);
    if (pf->dwFlags & DDPF_FOURCC)
    {
Andrew Riedi's avatar
Andrew Riedi committed
779
        TRACE(", dwFourCC code '%c%c%c%c' (0x%08x) - %d bits per pixel",
780 781 782 783 784 785 786 787 788 789 790
                (unsigned char)( pf->dwFourCC     &0xff),
                (unsigned char)((pf->dwFourCC>> 8)&0xff),
                (unsigned char)((pf->dwFourCC>>16)&0xff),
                (unsigned char)((pf->dwFourCC>>24)&0xff),
                pf->dwFourCC,
                pf->u1.dwYUVBitCount
        );
    }
    if (pf->dwFlags & DDPF_RGB)
    {
        const char *cmd;
Andrew Riedi's avatar
Andrew Riedi committed
791
        TRACE(", RGB bits: %d, ", pf->u1.dwRGBBitCount);
792 793 794 795 796 797 798 799 800
        switch (pf->u1.dwRGBBitCount)
        {
        case 4: cmd = "%1lx"; break;
        case 8: cmd = "%02lx"; break;
        case 16: cmd = "%04lx"; break;
        case 24: cmd = "%06lx"; break;
        case 32: cmd = "%08lx"; break;
        default: ERR("Unexpected bit depth !\n"); cmd = "%d"; break;
        }
Andrew Riedi's avatar
Andrew Riedi committed
801 802 803
        TRACE(" R "); TRACE(cmd, pf->u2.dwRBitMask);
        TRACE(" G "); TRACE(cmd, pf->u3.dwGBitMask);
        TRACE(" B "); TRACE(cmd, pf->u4.dwBBitMask);
804 805
        if (pf->dwFlags & DDPF_ALPHAPIXELS)
        {
Andrew Riedi's avatar
Andrew Riedi committed
806
            TRACE(" A "); TRACE(cmd, pf->u5.dwRGBAlphaBitMask);
807 808 809
        }
        if (pf->dwFlags & DDPF_ZPIXELS)
        {
Andrew Riedi's avatar
Andrew Riedi committed
810
            TRACE(" Z "); TRACE(cmd, pf->u5.dwRGBZBitMask);
811 812 813 814
        }
    }
    if (pf->dwFlags & DDPF_ZBUFFER)
    {
Andrew Riedi's avatar
Andrew Riedi committed
815
        TRACE(", Z bits : %d", pf->u1.dwZBufferBitDepth);
816 817 818
    }
    if (pf->dwFlags & DDPF_ALPHA)
    {
Andrew Riedi's avatar
Andrew Riedi committed
819
        TRACE(", Alpha bits : %d", pf->u1.dwAlphaBitDepth);
820 821 822 823
    }
    if (pf->dwFlags & DDPF_BUMPDUDV)
    {
        const char *cmd = "%08lx";
Andrew Riedi's avatar
Andrew Riedi committed
824 825 826 827
        TRACE(", Bump bits: %d, ", pf->u1.dwBumpBitCount);
        TRACE(" U "); TRACE(cmd, pf->u2.dwBumpDuBitMask);
        TRACE(" V "); TRACE(cmd, pf->u3.dwBumpDvBitMask);
        TRACE(" L "); TRACE(cmd, pf->u4.dwBumpLuminanceBitMask);
828
    }
829
    TRACE(")\n");
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
}

void DDRAW_dump_surface_desc(const DDSURFACEDESC2 *lpddsd)
{
#define STRUCT DDSURFACEDESC2
    static const member_info members[] =
        {
            ME(DDSD_HEIGHT, DDRAW_dump_DWORD, dwHeight),
            ME(DDSD_WIDTH, DDRAW_dump_DWORD, dwWidth),
            ME(DDSD_PITCH, DDRAW_dump_DWORD, u1 /* lPitch */),
            ME(DDSD_LINEARSIZE, DDRAW_dump_DWORD, u1 /* dwLinearSize */),
            ME(DDSD_BACKBUFFERCOUNT, DDRAW_dump_DWORD, dwBackBufferCount),
            ME(DDSD_MIPMAPCOUNT, DDRAW_dump_DWORD, u2 /* dwMipMapCount */),
            ME(DDSD_ZBUFFERBITDEPTH, DDRAW_dump_DWORD, u2 /* dwZBufferBitDepth */), /* This is for 'old-style' D3D */
            ME(DDSD_REFRESHRATE, DDRAW_dump_DWORD, u2 /* dwRefreshRate */),
            ME(DDSD_ALPHABITDEPTH, DDRAW_dump_DWORD, dwAlphaBitDepth),
            ME(DDSD_LPSURFACE, DDRAW_dump_PTR, lpSurface),
            ME(DDSD_CKDESTOVERLAY, DDRAW_dump_DDCOLORKEY, u3 /* ddckCKDestOverlay */),
            ME(DDSD_CKDESTBLT, DDRAW_dump_DDCOLORKEY, ddckCKDestBlt),
            ME(DDSD_CKSRCOVERLAY, DDRAW_dump_DDCOLORKEY, ddckCKSrcOverlay),
            ME(DDSD_CKSRCBLT, DDRAW_dump_DDCOLORKEY, ddckCKSrcBlt),
            ME(DDSD_PIXELFORMAT, DDRAW_dump_pixelformat, u4 /* ddpfPixelFormat */)
        };
    static const member_info members_caps[] =
        {
            ME(DDSD_CAPS, DDRAW_dump_DDSCAPS, ddsCaps)
        };
    static const member_info members_caps2[] =
        {
            ME(DDSD_CAPS, DDRAW_dump_DDSCAPS2, ddsCaps)
        };
#undef STRUCT

    if (NULL == lpddsd)
    {
Andrew Riedi's avatar
Andrew Riedi committed
865
        TRACE("(null)\n");
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
    }
    else
    {
      if (lpddsd->dwSize >= sizeof(DDSURFACEDESC2))
      {
          DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps2, 1);
      }
      else
      {
          DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members_caps, 1);
      }
      DDRAW_dump_members(lpddsd->dwFlags, lpddsd, members,
                          sizeof(members)/sizeof(members[0]));
    }
}

void
883
dump_D3DMATRIX(const D3DMATRIX *mat)
884
{
Andrew Riedi's avatar
Andrew Riedi committed
885 886 887 888
    TRACE("  %f %f %f %f\n", mat->_11, mat->_12, mat->_13, mat->_14);
    TRACE("  %f %f %f %f\n", mat->_21, mat->_22, mat->_23, mat->_24);
    TRACE("  %f %f %f %f\n", mat->_31, mat->_32, mat->_33, mat->_34);
    TRACE("  %f %f %f %f\n", mat->_41, mat->_42, mat->_43, mat->_44);
889 890 891 892 893 894 895 896 897 898 899 900 901 902
}

DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType)
{
    DWORD size = 0;
    int i;

    if (d3dvtVertexType & D3DFVF_NORMAL) size += 3 * sizeof(D3DVALUE);
    if (d3dvtVertexType & D3DFVF_DIFFUSE) size += sizeof(DWORD);
    if (d3dvtVertexType & D3DFVF_SPECULAR) size += sizeof(DWORD);
    if (d3dvtVertexType & D3DFVF_RESERVED1) size += sizeof(DWORD);
    switch (d3dvtVertexType & D3DFVF_POSITION_MASK)
    {
903
        case D3DFVF_XYZ:    size += 3 * sizeof(D3DVALUE); break;
904
        case D3DFVF_XYZRHW: size += 4 * sizeof(D3DVALUE); break;
905 906 907 908 909 910
        case D3DFVF_XYZB1:  size += 4 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB2:  size += 5 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB3:  size += 6 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB4:  size += 7 * sizeof(D3DVALUE); break;
        case D3DFVF_XYZB5:  size += 8 * sizeof(D3DVALUE); break;
        default: ERR("Unexpected position mask\n");
911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953
    }
    for (i = 0; i < GET_TEXCOUNT_FROM_FVF(d3dvtVertexType); i++)
    {
        size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(D3DVALUE);
    }

    return size;
}

void DDRAW_Convert_DDSCAPS_1_To_2(const DDSCAPS* pIn, DDSCAPS2* pOut)
{
    /* 2 adds three additional caps fields to the end. Both versions
     * are unversioned. */
    pOut->dwCaps = pIn->dwCaps;
    pOut->dwCaps2 = 0;
    pOut->dwCaps3 = 0;
    pOut->dwCaps4 = 0;
}

void DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(const DDDEVICEIDENTIFIER2* pIn, DDDEVICEIDENTIFIER* pOut)
{
    /* 2 adds a dwWHQLLevel field to the end. Both structures are
     * unversioned. */
    memcpy(pOut, pIn, sizeof(*pOut));
}

void DDRAW_dump_cooperativelevel(DWORD cooplevel)
{
    static const flag_info flags[] =
        {
            FE(DDSCL_FULLSCREEN),
            FE(DDSCL_ALLOWREBOOT),
            FE(DDSCL_NOWINDOWCHANGES),
            FE(DDSCL_NORMAL),
            FE(DDSCL_ALLOWMODEX),
            FE(DDSCL_EXCLUSIVE),
            FE(DDSCL_SETFOCUSWINDOW),
            FE(DDSCL_SETDEVICEWINDOW),
            FE(DDSCL_CREATEDEVICEWINDOW)
    };

    if (TRACE_ON(ddraw))
    {
Andrew Riedi's avatar
Andrew Riedi committed
954
        TRACE(" - ");
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
        DDRAW_dump_flags(cooplevel, flags, sizeof(flags)/sizeof(flags[0]));
    }
}

void DDRAW_dump_DDCAPS(const DDCAPS *lpcaps)
{
    static const flag_info flags1[] =
    {
      FE(DDCAPS_3D),
      FE(DDCAPS_ALIGNBOUNDARYDEST),
      FE(DDCAPS_ALIGNSIZEDEST),
      FE(DDCAPS_ALIGNBOUNDARYSRC),
      FE(DDCAPS_ALIGNSIZESRC),
      FE(DDCAPS_ALIGNSTRIDE),
      FE(DDCAPS_BLT),
      FE(DDCAPS_BLTQUEUE),
      FE(DDCAPS_BLTFOURCC),
      FE(DDCAPS_BLTSTRETCH),
      FE(DDCAPS_GDI),
      FE(DDCAPS_OVERLAY),
      FE(DDCAPS_OVERLAYCANTCLIP),
      FE(DDCAPS_OVERLAYFOURCC),
      FE(DDCAPS_OVERLAYSTRETCH),
      FE(DDCAPS_PALETTE),
      FE(DDCAPS_PALETTEVSYNC),
      FE(DDCAPS_READSCANLINE),
      FE(DDCAPS_STEREOVIEW),
      FE(DDCAPS_VBI),
      FE(DDCAPS_ZBLTS),
      FE(DDCAPS_ZOVERLAYS),
      FE(DDCAPS_COLORKEY),
      FE(DDCAPS_ALPHA),
      FE(DDCAPS_COLORKEYHWASSIST),
      FE(DDCAPS_NOHARDWARE),
      FE(DDCAPS_BLTCOLORFILL),
      FE(DDCAPS_BANKSWITCHED),
      FE(DDCAPS_BLTDEPTHFILL),
      FE(DDCAPS_CANCLIP),
      FE(DDCAPS_CANCLIPSTRETCHED),
      FE(DDCAPS_CANBLTSYSMEM)
    };
    static const flag_info flags2[] =
    {
      FE(DDCAPS2_CERTIFIED),
      FE(DDCAPS2_NO2DDURING3DSCENE),
      FE(DDCAPS2_VIDEOPORT),
      FE(DDCAPS2_AUTOFLIPOVERLAY),
      FE(DDCAPS2_CANBOBINTERLEAVED),
      FE(DDCAPS2_CANBOBNONINTERLEAVED),
      FE(DDCAPS2_COLORCONTROLOVERLAY),
      FE(DDCAPS2_COLORCONTROLPRIMARY),
      FE(DDCAPS2_CANDROPZ16BIT),
      FE(DDCAPS2_NONLOCALVIDMEM),
      FE(DDCAPS2_NONLOCALVIDMEMCAPS),
      FE(DDCAPS2_NOPAGELOCKREQUIRED),
      FE(DDCAPS2_WIDESURFACES),
      FE(DDCAPS2_CANFLIPODDEVEN),
      FE(DDCAPS2_CANBOBHARDWARE),
      FE(DDCAPS2_COPYFOURCC),
      FE(DDCAPS2_PRIMARYGAMMA),
      FE(DDCAPS2_CANRENDERWINDOWED),
      FE(DDCAPS2_CANCALIBRATEGAMMA),
      FE(DDCAPS2_FLIPINTERVAL),
      FE(DDCAPS2_FLIPNOVSYNC),
      FE(DDCAPS2_CANMANAGETEXTURE),
      FE(DDCAPS2_TEXMANINNONLOCALVIDMEM),
      FE(DDCAPS2_STEREO),
      FE(DDCAPS2_SYSTONONLOCAL_AS_SYSTOLOCAL)
    };
    static const flag_info flags3[] =
    {
      FE(DDCKEYCAPS_DESTBLT),
      FE(DDCKEYCAPS_DESTBLTCLRSPACE),
      FE(DDCKEYCAPS_DESTBLTCLRSPACEYUV),
      FE(DDCKEYCAPS_DESTBLTYUV),
      FE(DDCKEYCAPS_DESTOVERLAY),
      FE(DDCKEYCAPS_DESTOVERLAYCLRSPACE),
      FE(DDCKEYCAPS_DESTOVERLAYCLRSPACEYUV),
      FE(DDCKEYCAPS_DESTOVERLAYONEACTIVE),
      FE(DDCKEYCAPS_DESTOVERLAYYUV),
      FE(DDCKEYCAPS_SRCBLT),
      FE(DDCKEYCAPS_SRCBLTCLRSPACE),
      FE(DDCKEYCAPS_SRCBLTCLRSPACEYUV),
      FE(DDCKEYCAPS_SRCBLTYUV),
      FE(DDCKEYCAPS_SRCOVERLAY),
      FE(DDCKEYCAPS_SRCOVERLAYCLRSPACE),
      FE(DDCKEYCAPS_SRCOVERLAYCLRSPACEYUV),
      FE(DDCKEYCAPS_SRCOVERLAYONEACTIVE),
      FE(DDCKEYCAPS_SRCOVERLAYYUV),
      FE(DDCKEYCAPS_NOCOSTOVERLAY)
    };
    static const flag_info flags4[] =
    {
      FE(DDFXCAPS_BLTALPHA),
      FE(DDFXCAPS_OVERLAYALPHA),
      FE(DDFXCAPS_BLTARITHSTRETCHYN),
      FE(DDFXCAPS_BLTARITHSTRETCHY),
      FE(DDFXCAPS_BLTMIRRORLEFTRIGHT),
      FE(DDFXCAPS_BLTMIRRORUPDOWN),
      FE(DDFXCAPS_BLTROTATION),
      FE(DDFXCAPS_BLTROTATION90),
      FE(DDFXCAPS_BLTSHRINKX),
      FE(DDFXCAPS_BLTSHRINKXN),
      FE(DDFXCAPS_BLTSHRINKY),
      FE(DDFXCAPS_BLTSHRINKYN),
      FE(DDFXCAPS_BLTSTRETCHX),
      FE(DDFXCAPS_BLTSTRETCHXN),
      FE(DDFXCAPS_BLTSTRETCHY),
      FE(DDFXCAPS_BLTSTRETCHYN),
      FE(DDFXCAPS_OVERLAYARITHSTRETCHY),
      FE(DDFXCAPS_OVERLAYARITHSTRETCHYN),
      FE(DDFXCAPS_OVERLAYSHRINKX),
      FE(DDFXCAPS_OVERLAYSHRINKXN),
      FE(DDFXCAPS_OVERLAYSHRINKY),
      FE(DDFXCAPS_OVERLAYSHRINKYN),
      FE(DDFXCAPS_OVERLAYSTRETCHX),
      FE(DDFXCAPS_OVERLAYSTRETCHXN),
      FE(DDFXCAPS_OVERLAYSTRETCHY),
      FE(DDFXCAPS_OVERLAYSTRETCHYN),
      FE(DDFXCAPS_OVERLAYMIRRORLEFTRIGHT),
      FE(DDFXCAPS_OVERLAYMIRRORUPDOWN)
    };
    static const flag_info flags5[] =
    {
      FE(DDFXALPHACAPS_BLTALPHAEDGEBLEND),
      FE(DDFXALPHACAPS_BLTALPHAPIXELS),
      FE(DDFXALPHACAPS_BLTALPHAPIXELSNEG),
      FE(DDFXALPHACAPS_BLTALPHASURFACES),
      FE(DDFXALPHACAPS_BLTALPHASURFACESNEG),
      FE(DDFXALPHACAPS_OVERLAYALPHAEDGEBLEND),
      FE(DDFXALPHACAPS_OVERLAYALPHAPIXELS),
      FE(DDFXALPHACAPS_OVERLAYALPHAPIXELSNEG),
      FE(DDFXALPHACAPS_OVERLAYALPHASURFACES),
      FE(DDFXALPHACAPS_OVERLAYALPHASURFACESNEG)
    };
    static const flag_info flags6[] =
    {
      FE(DDPCAPS_4BIT),
      FE(DDPCAPS_8BITENTRIES),
      FE(DDPCAPS_8BIT),
      FE(DDPCAPS_INITIALIZE),
      FE(DDPCAPS_PRIMARYSURFACE),
      FE(DDPCAPS_PRIMARYSURFACELEFT),
      FE(DDPCAPS_ALLOW256),
      FE(DDPCAPS_VSYNC),
      FE(DDPCAPS_1BIT),
      FE(DDPCAPS_2BIT),
      FE(DDPCAPS_ALPHA),
    };
    static const flag_info flags7[] =
    {
      FE(DDSVCAPS_RESERVED1),
      FE(DDSVCAPS_RESERVED2),
      FE(DDSVCAPS_RESERVED3),
      FE(DDSVCAPS_RESERVED4),
      FE(DDSVCAPS_STEREOSEQUENTIAL),
    };

Andrew Riedi's avatar
Andrew Riedi committed
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
    TRACE(" - dwSize : %d\n", lpcaps->dwSize);
    TRACE(" - dwCaps : "); DDRAW_dump_flags(lpcaps->dwCaps, flags1, sizeof(flags1)/sizeof(flags1[0]));
    TRACE(" - dwCaps2 : "); DDRAW_dump_flags(lpcaps->dwCaps2, flags2, sizeof(flags2)/sizeof(flags2[0]));
    TRACE(" - dwCKeyCaps : "); DDRAW_dump_flags(lpcaps->dwCKeyCaps, flags3, sizeof(flags3)/sizeof(flags3[0]));
    TRACE(" - dwFXCaps : "); DDRAW_dump_flags(lpcaps->dwFXCaps, flags4, sizeof(flags4)/sizeof(flags4[0]));
    TRACE(" - dwFXAlphaCaps : "); DDRAW_dump_flags(lpcaps->dwFXAlphaCaps, flags5, sizeof(flags5)/sizeof(flags5[0]));
    TRACE(" - dwPalCaps : "); DDRAW_dump_flags(lpcaps->dwPalCaps, flags6, sizeof(flags6)/sizeof(flags6[0]));
    TRACE(" - dwSVCaps : "); DDRAW_dump_flags(lpcaps->dwSVCaps, flags7, sizeof(flags7)/sizeof(flags7[0]));
    TRACE("...\n");
    TRACE(" - dwNumFourCCCodes : %d\n", lpcaps->dwNumFourCCCodes);
    TRACE(" - dwCurrVisibleOverlays : %d\n", lpcaps->dwCurrVisibleOverlays);
    TRACE(" - dwMinOverlayStretch : %d\n", lpcaps->dwMinOverlayStretch);
    TRACE(" - dwMaxOverlayStretch : %d\n", lpcaps->dwMaxOverlayStretch);
    TRACE("...\n");
1127
    TRACE(" - ddsCaps : "); DDRAW_dump_DDSCAPS2(&lpcaps->ddsCaps);
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
}

/*****************************************************************************
 * multiply_matrix
 *
 * Multiplies 2 4x4 matrices src1 and src2, and stores the result in dest.
 *
 * Params:
 *  dest: Pointer to the destination matrix
 *  src1: Pointer to the first source matrix
1138
 *  src2: Pointer to the second source matrix
1139 1140 1141 1142
 *
 *****************************************************************************/
void
multiply_matrix(D3DMATRIX *dest,
1143 1144
                const D3DMATRIX *src1,
                const D3DMATRIX *src2)
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
{
    D3DMATRIX temp;

    /* Now do the multiplication 'by hand'.
       I know that all this could be optimised, but this will be done later :-) */
    temp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
    temp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
    temp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
    temp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);

    temp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
    temp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
    temp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
    temp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);

    temp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
    temp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
    temp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
    temp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);

    temp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
    temp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
    temp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
    temp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);

    /* And copy the new matrix in the good storage.. */
    memcpy(dest, &temp, 16 * sizeof(D3DVALUE));
}


HRESULT
hr_ddraw_from_wined3d(HRESULT hr)
{
    switch(hr)
    {
        case WINED3DERR_INVALIDCALL: return DDERR_INVALIDPARAMS;
        default: return hr;
    }
}