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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 339 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 437 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 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 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 594 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 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 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 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 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 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 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 954 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 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 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 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966
|
/*
* Copyright (c) 1998-2004 Lionel Ulmer
* Copyright (c) 2002-2005 Christian Costa
* Copyright (c) 2006-2009, 2011-2013 Stefan Dösinger
* Copyright (c) 2008 Alexander Dorofeyev
*
* 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
*
* IDirect3DDevice implementation, version 1, 2, 3 and 7. Rendering is relayed
* to WineD3D, some minimal DirectDraw specific management is handled here.
* The Direct3DDevice is NOT the parent of the WineD3DDevice, because d3d
* is initialized when DirectDraw creates the primary surface.
* Some type management is necessary, because some D3D types changed between
* D3D7 and D3D9.
*
*/
#include "config.h"
#include "wine/port.h"
#include "ddraw_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
WINE_DECLARE_DEBUG_CHANNEL(winediag);
/* The device ID */
const GUID IID_D3DDEVICE_WineD3D = {
0xaef72d43,
0xb09a,
0x4b7b,
{ 0xb7,0x98,0xc6,0x8a,0x77,0x2d,0x72,0x2a }
};
static inline void set_fpu_control_word(WORD fpucw)
{
#if defined(__i386__) && defined(__GNUC__)
__asm__ volatile ("fldcw %0" : : "m" (fpucw));
#elif defined(__i386__) && defined(_MSC_VER)
__asm fldcw fpucw;
#endif
}
static inline WORD d3d_fpu_setup(void)
{
WORD oldcw;
#if defined(__i386__) && defined(__GNUC__)
__asm__ volatile ("fnstcw %0" : "=m" (oldcw));
#elif defined(__i386__) && defined(_MSC_VER)
__asm fnstcw oldcw;
#else
static BOOL warned = FALSE;
if(!warned)
{
FIXME("FPUPRESERVE not implemented for this platform / compiler\n");
warned = TRUE;
}
return 0;
#endif
set_fpu_control_word(0x37f);
return oldcw;
}
static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
{
return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
}
static HRESULT WINAPI d3d_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
{
struct d3d_device *device = impl_from_IUnknown(iface);
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
if (!riid)
{
*out = NULL;
return DDERR_INVALIDPARAMS;
}
if (IsEqualGUID(&IID_IUnknown, riid))
{
IDirect3DDevice7_AddRef(&device->IDirect3DDevice7_iface);
*out = &device->IDirect3DDevice7_iface;
return S_OK;
}
if (device->version == 7)
{
if (IsEqualGUID(&IID_IDirect3DDevice7, riid))
{
IDirect3DDevice7_AddRef(&device->IDirect3DDevice7_iface);
*out = &device->IDirect3DDevice7_iface;
return S_OK;
}
}
else
{
if (IsEqualGUID(&IID_IDirect3DDevice3, riid) && device->version == 3)
{
IDirect3DDevice3_AddRef(&device->IDirect3DDevice3_iface);
*out = &device->IDirect3DDevice3_iface;
return S_OK;
}
if (IsEqualGUID(&IID_IDirect3DDevice2, riid) && device->version >= 2)
{
IDirect3DDevice2_AddRef(&device->IDirect3DDevice2_iface);
*out = &device->IDirect3DDevice2_iface;
return S_OK;
}
if (IsEqualGUID(&IID_IDirect3DDevice, riid))
{
IDirect3DDevice_AddRef(&device->IDirect3DDevice_iface);
*out = &device->IDirect3DDevice_iface;
return S_OK;
}
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
*out = NULL;
return E_NOINTERFACE;
}
static HRESULT WINAPI d3d_device7_QueryInterface(IDirect3DDevice7 *iface, REFIID riid, void **out)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
return IUnknown_QueryInterface(device->outer_unknown, riid, out);
}
static HRESULT WINAPI d3d_device3_QueryInterface(IDirect3DDevice3 *iface, REFIID riid, void **out)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
return IUnknown_QueryInterface(device->outer_unknown, riid, out);
}
static HRESULT WINAPI d3d_device2_QueryInterface(IDirect3DDevice2 *iface, REFIID riid, void **out)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
return IUnknown_QueryInterface(device->outer_unknown, riid, out);
}
static HRESULT WINAPI d3d_device1_QueryInterface(IDirect3DDevice *iface, REFIID riid, void **out)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
return IUnknown_QueryInterface(device->outer_unknown, riid, out);
}
static ULONG WINAPI d3d_device_inner_AddRef(IUnknown *iface)
{
struct d3d_device *device = impl_from_IUnknown(iface);
ULONG ref = InterlockedIncrement(&device->ref);
TRACE("%p increasing refcount to %u.\n", device, ref);
return ref;
}
static ULONG WINAPI d3d_device7_AddRef(IDirect3DDevice7 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p.\n", iface);
return IUnknown_AddRef(device->outer_unknown);
}
static ULONG WINAPI d3d_device3_AddRef(IDirect3DDevice3 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p.\n", iface);
return IUnknown_AddRef(device->outer_unknown);
}
static ULONG WINAPI d3d_device2_AddRef(IDirect3DDevice2 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p.\n", iface);
return IUnknown_AddRef(device->outer_unknown);
}
static ULONG WINAPI d3d_device1_AddRef(IDirect3DDevice *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p.\n", iface);
return IUnknown_AddRef(device->outer_unknown);
}
static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
{
struct d3d_device *This = impl_from_IUnknown(iface);
ULONG ref = InterlockedDecrement(&This->ref);
IUnknown *rt_iface;
TRACE("%p decreasing refcount to %u.\n", This, ref);
/* This method doesn't destroy the wined3d device, because it's still in
* use for 2D rendering. IDirectDrawSurface7::Release will destroy the
* wined3d device when the render target is released. */
if (!ref)
{
DWORD i;
struct list *vp_entry, *vp_entry2;
wined3d_mutex_lock();
/* There is no need to unset any resources here, wined3d will take
* care of that on uninit_3d(). */
if (This->index_buffer)
wined3d_buffer_decref(This->index_buffer);
if (This->vertex_buffer)
wined3d_buffer_decref(This->vertex_buffer);
wined3d_device_set_rendertarget_view(This->wined3d_device, 0, NULL, FALSE);
/* Release the wined3d device. This won't destroy it. */
if (!wined3d_device_decref(This->wined3d_device))
ERR("The wined3d device (%p) was destroyed unexpectedly.\n", This->wined3d_device);
/* The texture handles should be unset by now, but there might be some bits
* missing in our reference counting(needs test). Do a sanity check. */
for (i = 0; i < This->handle_table.entry_count; ++i)
{
struct ddraw_handle_entry *entry = &This->handle_table.entries[i];
switch (entry->type)
{
case DDRAW_HANDLE_FREE:
break;
case DDRAW_HANDLE_MATERIAL:
{
struct d3d_material *m = entry->object;
FIXME("Material handle %#x (%p) not unset properly.\n", i + 1, m);
m->Handle = 0;
break;
}
case DDRAW_HANDLE_MATRIX:
{
/* No FIXME here because this might happen because of sloppy applications. */
WARN("Leftover matrix handle %#x (%p), deleting.\n", i + 1, entry->object);
IDirect3DDevice_DeleteMatrix(&This->IDirect3DDevice_iface, i + 1);
break;
}
case DDRAW_HANDLE_STATEBLOCK:
{
/* No FIXME here because this might happen because of sloppy applications. */
WARN("Leftover stateblock handle %#x (%p), deleting.\n", i + 1, entry->object);
IDirect3DDevice7_DeleteStateBlock(&This->IDirect3DDevice7_iface, i + 1);
break;
}
case DDRAW_HANDLE_SURFACE:
{
struct ddraw_surface *surf = entry->object;
FIXME("Texture handle %#x (%p) not unset properly.\n", i + 1, surf);
surf->Handle = 0;
break;
}
default:
FIXME("Handle %#x (%p) has unknown type %#x.\n", i + 1, entry->object, entry->type);
break;
}
}
ddraw_handle_table_destroy(&This->handle_table);
LIST_FOR_EACH_SAFE(vp_entry, vp_entry2, &This->viewport_list)
{
struct d3d_viewport *vp = LIST_ENTRY(vp_entry, struct d3d_viewport, entry);
IDirect3DDevice3_DeleteViewport(&This->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface);
}
TRACE("Releasing render target %p.\n", This->rt_iface);
rt_iface = This->rt_iface;
This->rt_iface = NULL;
if (This->version != 1)
IUnknown_Release(rt_iface);
TRACE("Render target release done.\n");
/* Releasing the render target above may have released the last
* reference to the ddraw object. */
if (This->ddraw)
This->ddraw->d3ddevice = NULL;
/* Now free the structure */
HeapFree(GetProcessHeap(), 0, This);
wined3d_mutex_unlock();
}
TRACE("Done\n");
return ref;
}
static ULONG WINAPI d3d_device7_Release(IDirect3DDevice7 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p.\n", iface);
return IUnknown_Release(device->outer_unknown);
}
static ULONG WINAPI d3d_device3_Release(IDirect3DDevice3 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p.\n", iface);
return IUnknown_Release(device->outer_unknown);
}
static ULONG WINAPI d3d_device2_Release(IDirect3DDevice2 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p.\n", iface);
return IUnknown_Release(device->outer_unknown);
}
static ULONG WINAPI d3d_device1_Release(IDirect3DDevice *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p.\n", iface);
return IUnknown_Release(device->outer_unknown);
}
/*****************************************************************************
* IDirect3DDevice Methods
*****************************************************************************/
/*****************************************************************************
* IDirect3DDevice::Initialize
*
* Initializes a Direct3DDevice. This implementation is a no-op, as all
* initialization is done at create time.
*
* Exists in Version 1
*
* Parameters:
* No idea what they mean, as the MSDN page is gone
*
* Returns: DD_OK
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_Initialize(IDirect3DDevice *iface,
IDirect3D *d3d, GUID *guid, D3DDEVICEDESC *device_desc)
{
/* It shouldn't be crucial, but print a FIXME, I'm interested if
* any game calls it and when. */
FIXME("iface %p, d3d %p, guid %s, device_desc %p nop!\n",
iface, d3d, debugstr_guid(guid), device_desc);
return D3D_OK;
}
static HRESULT d3d_device7_GetCaps(IDirect3DDevice7 *iface, D3DDEVICEDESC7 *device_desc)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, device_desc %p.\n", iface, device_desc);
if (!device_desc)
{
WARN("device_desc is NULL, returning DDERR_INVALIDPARAMS.\n");
return DDERR_INVALIDPARAMS;
}
/* Call the same function used by IDirect3D, this saves code */
return ddraw_get_d3dcaps(device->ddraw, device_desc);
}
static HRESULT WINAPI d3d_device7_GetCaps_FPUSetup(IDirect3DDevice7 *iface, D3DDEVICEDESC7 *desc)
{
return d3d_device7_GetCaps(iface, desc);
}
static HRESULT WINAPI d3d_device7_GetCaps_FPUPreserve(IDirect3DDevice7 *iface, D3DDEVICEDESC7 *desc)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetCaps(iface, desc);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice3::GetCaps
*
* Retrieves the capabilities of the hardware device and the emulation
* device. For Wine, hardware and emulation are the same (it's all HW).
*
* This implementation is used for Version 1, 2, and 3. Version 7 has its own
*
* Parameters:
* HWDesc: Structure to fill with the HW caps
* HelDesc: Structure to fill with the hardware emulation caps
*
* Returns:
* D3D_OK on success
* D3DERR_* if a problem occurs. See WineD3D
*
*****************************************************************************/
/* There are 3 versions of D3DDEVICEDESC. All 3 share the same name because
* Microsoft just expanded the existing structure without naming them
* D3DDEVICEDESC2 and D3DDEVICEDESC3. Which version is used have depends
* on the version of the DirectX SDK. DirectX 6+ and Wine use the latest
* one with 252 bytes.
*
* All 3 versions are allowed as parameters and only the specified amount of
* bytes is written.
*
* Note that Direct3D7 and earlier are not available in native Win64
* ddraw.dll builds, so possible size differences between 32 bit and
* 64 bit are a non-issue.
*/
static inline BOOL check_d3ddevicedesc_size(DWORD size)
{
if (size == FIELD_OFFSET(D3DDEVICEDESC, dwMinTextureWidth) /* 172 */
|| size == FIELD_OFFSET(D3DDEVICEDESC, dwMaxTextureRepeat) /* 204 */
|| size == sizeof(D3DDEVICEDESC) /* 252 */) return TRUE;
return FALSE;
}
static HRESULT WINAPI d3d_device3_GetCaps(IDirect3DDevice3 *iface,
D3DDEVICEDESC *HWDesc, D3DDEVICEDESC *HelDesc)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
D3DDEVICEDESC7 desc7;
D3DDEVICEDESC desc1;
HRESULT hr;
TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, HWDesc, HelDesc);
if (!HWDesc)
{
WARN("HWDesc is NULL, returning DDERR_INVALIDPARAMS.\n");
return DDERR_INVALIDPARAMS;
}
if (!check_d3ddevicedesc_size(HWDesc->dwSize))
{
WARN("HWDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HWDesc->dwSize);
return DDERR_INVALIDPARAMS;
}
if (!HelDesc)
{
WARN("HelDesc is NULL, returning DDERR_INVALIDPARAMS.\n");
return DDERR_INVALIDPARAMS;
}
if (!check_d3ddevicedesc_size(HelDesc->dwSize))
{
WARN("HelDesc->dwSize is %u, returning DDERR_INVALIDPARAMS.\n", HelDesc->dwSize);
return DDERR_INVALIDPARAMS;
}
if (FAILED(hr = ddraw_get_d3dcaps(device->ddraw, &desc7)))
return hr;
ddraw_d3dcaps1_from_7(&desc1, &desc7);
DD_STRUCT_COPY_BYSIZE(HWDesc, &desc1);
DD_STRUCT_COPY_BYSIZE(HelDesc, &desc1);
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetCaps(IDirect3DDevice2 *iface,
D3DDEVICEDESC *hw_desc, D3DDEVICEDESC *hel_desc)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, hw_desc, hel_desc);
return d3d_device3_GetCaps(&device->IDirect3DDevice3_iface, hw_desc, hel_desc);
}
static HRESULT WINAPI d3d_device1_GetCaps(IDirect3DDevice *iface,
D3DDEVICEDESC *hw_desc, D3DDEVICEDESC *hel_desc)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p, hw_desc %p, hel_desc %p.\n", iface, hw_desc, hel_desc);
return d3d_device3_GetCaps(&device->IDirect3DDevice3_iface, hw_desc, hel_desc);
}
/*****************************************************************************
* IDirect3DDevice2::SwapTextureHandles
*
* Swaps the texture handles of 2 Texture interfaces. Version 1 and 2
*
* Parameters:
* Tex1, Tex2: The 2 Textures to swap
*
* Returns:
* D3D_OK
*
*****************************************************************************/
static HRESULT WINAPI d3d_device2_SwapTextureHandles(IDirect3DDevice2 *iface,
IDirect3DTexture2 *tex1, IDirect3DTexture2 *tex2)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct ddraw_surface *surf1 = unsafe_impl_from_IDirect3DTexture2(tex1);
struct ddraw_surface *surf2 = unsafe_impl_from_IDirect3DTexture2(tex2);
DWORD h1, h2;
TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, tex1, tex2);
wined3d_mutex_lock();
h1 = surf1->Handle - 1;
h2 = surf2->Handle - 1;
device->handle_table.entries[h1].object = surf2;
device->handle_table.entries[h2].object = surf1;
surf2->Handle = h1 + 1;
surf1->Handle = h2 + 1;
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device1_SwapTextureHandles(IDirect3DDevice *iface,
IDirect3DTexture *tex1, IDirect3DTexture *tex2)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct ddraw_surface *surf1 = unsafe_impl_from_IDirect3DTexture(tex1);
struct ddraw_surface *surf2 = unsafe_impl_from_IDirect3DTexture(tex2);
IDirect3DTexture2 *t1 = surf1 ? &surf1->IDirect3DTexture2_iface : NULL;
IDirect3DTexture2 *t2 = surf2 ? &surf2->IDirect3DTexture2_iface : NULL;
TRACE("iface %p, tex1 %p, tex2 %p.\n", iface, tex1, tex2);
return d3d_device2_SwapTextureHandles(&device->IDirect3DDevice2_iface, t1, t2);
}
/*****************************************************************************
* IDirect3DDevice3::GetStats
*
* This method seems to retrieve some stats from the device.
* The MSDN documentation doesn't exist any more, but the D3DSTATS
* structure suggests that the amount of drawn primitives and processed
* vertices is returned.
*
* Exists in Version 1, 2 and 3
*
* Parameters:
* Stats: Pointer to a D3DSTATS structure to be filled
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Stats == NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_GetStats(IDirect3DDevice3 *iface, D3DSTATS *Stats)
{
FIXME("iface %p, stats %p stub!\n", iface, Stats);
if(!Stats)
return DDERR_INVALIDPARAMS;
/* Fill the Stats with 0 */
Stats->dwTrianglesDrawn = 0;
Stats->dwLinesDrawn = 0;
Stats->dwPointsDrawn = 0;
Stats->dwSpansDrawn = 0;
Stats->dwVerticesProcessed = 0;
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetStats(IDirect3DDevice2 *iface, D3DSTATS *stats)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, stats %p.\n", iface, stats);
return d3d_device3_GetStats(&device->IDirect3DDevice3_iface, stats);
}
static HRESULT WINAPI d3d_device1_GetStats(IDirect3DDevice *iface, D3DSTATS *stats)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p, stats %p.\n", iface, stats);
return d3d_device3_GetStats(&device->IDirect3DDevice3_iface, stats);
}
/*****************************************************************************
* IDirect3DDevice::CreateExecuteBuffer
*
* Creates an IDirect3DExecuteBuffer, used for rendering with a
* Direct3DDevice.
*
* Version 1 only.
*
* Params:
* Desc: Buffer description
* ExecuteBuffer: Address to return the Interface pointer at
* UnkOuter: Must be NULL. Basically for aggregation, which ddraw doesn't
* support
*
* Returns:
* CLASS_E_NOAGGREGATION if UnkOuter != NULL
* DDERR_OUTOFMEMORY if we ran out of memory
* D3D_OK on success
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_CreateExecuteBuffer(IDirect3DDevice *iface,
D3DEXECUTEBUFFERDESC *buffer_desc, IDirect3DExecuteBuffer **ExecuteBuffer, IUnknown *outer_unknown)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct d3d_execute_buffer *object;
HRESULT hr;
TRACE("iface %p, buffer_desc %p, buffer %p, outer_unknown %p.\n",
iface, buffer_desc, ExecuteBuffer, outer_unknown);
if (outer_unknown)
return CLASS_E_NOAGGREGATION;
/* Allocate the new Execute Buffer */
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if(!object)
{
ERR("Failed to allocate execute buffer memory.\n");
return DDERR_OUTOFMEMORY;
}
hr = d3d_execute_buffer_init(object, device, buffer_desc);
if (FAILED(hr))
{
WARN("Failed to initialize execute buffer, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
*ExecuteBuffer = &object->IDirect3DExecuteBuffer_iface;
TRACE(" Returning IDirect3DExecuteBuffer at %p, implementation is at %p\n", *ExecuteBuffer, object);
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice::Execute
*
* Executes all the stuff in an execute buffer.
*
* Params:
* ExecuteBuffer: The buffer to execute
* Viewport: The viewport used for rendering
* Flags: Some flags
*
* Returns:
* DDERR_INVALIDPARAMS if ExecuteBuffer == NULL
* D3D_OK on success
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_Execute(IDirect3DDevice *iface,
IDirect3DExecuteBuffer *ExecuteBuffer, IDirect3DViewport *viewport, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct d3d_execute_buffer *buffer = unsafe_impl_from_IDirect3DExecuteBuffer(ExecuteBuffer);
struct d3d_viewport *viewport_impl = unsafe_impl_from_IDirect3DViewport(viewport);
HRESULT hr;
TRACE("iface %p, buffer %p, viewport %p, flags %#x.\n", iface, ExecuteBuffer, viewport, flags);
if(!buffer)
return DDERR_INVALIDPARAMS;
/* Execute... */
wined3d_mutex_lock();
hr = d3d_execute_buffer_execute(buffer, device, viewport_impl);
wined3d_mutex_unlock();
return hr;
}
/*****************************************************************************
* IDirect3DDevice3::AddViewport
*
* Add a Direct3DViewport to the device's viewport list. These viewports
* are wrapped to IDirect3DDevice7 viewports in viewport.c
*
* Exists in Version 1, 2 and 3. Note that IDirect3DViewport 1, 2 and 3
* are the same interfaces.
*
* Params:
* Viewport: The viewport to add
*
* Returns:
* DDERR_INVALIDPARAMS if Viewport == NULL
* D3D_OK on success
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_AddViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
/* Sanity check */
if(!vp)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
IDirect3DViewport3_AddRef(viewport);
list_add_head(&device->viewport_list, &vp->entry);
/* Viewport must be usable for Clear() after AddViewport, so set active_device here. */
vp->active_device = device;
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_AddViewport(IDirect3DDevice2 *iface,
IDirect3DViewport2 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport2(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_AddViewport(&device->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface);
}
static HRESULT WINAPI d3d_device1_AddViewport(IDirect3DDevice *iface, IDirect3DViewport *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_AddViewport(&device->IDirect3DDevice3_iface, &vp->IDirect3DViewport3_iface);
}
/*****************************************************************************
* IDirect3DDevice3::DeleteViewport
*
* Deletes a Direct3DViewport from the device's viewport list.
*
* Exists in Version 1, 2 and 3. Note that all Viewport interface versions
* are equal.
*
* Params:
* Viewport: The viewport to delete
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if the viewport wasn't found in the list
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_DeleteViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
if (!vp)
{
WARN("NULL viewport, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
if (vp->active_device != device)
{
WARN("Viewport %p active device is %p.\n", vp, vp->active_device);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if (device->current_viewport == vp)
{
TRACE("Deleting current viewport, unsetting and releasing\n");
IDirect3DViewport3_Release(viewport);
device->current_viewport = NULL;
}
vp->active_device = NULL;
list_remove(&vp->entry);
IDirect3DViewport3_Release(viewport);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_DeleteViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport2(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_DeleteViewport(&device->IDirect3DDevice3_iface,
vp ? &vp->IDirect3DViewport3_iface : NULL);
}
static HRESULT WINAPI d3d_device1_DeleteViewport(IDirect3DDevice *iface, IDirect3DViewport *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_DeleteViewport(&device->IDirect3DDevice3_iface,
vp ? &vp->IDirect3DViewport3_iface : NULL);
}
/*****************************************************************************
* IDirect3DDevice3::NextViewport
*
* Returns a viewport from the viewport list, depending on the
* passed viewport and the flags.
*
* Exists in Version 1, 2 and 3. Note that all Viewport interface versions
* are equal.
*
* Params:
* Viewport: Viewport to use for beginning the search
* Flags: D3DNEXT_NEXT, D3DNEXT_HEAD or D3DNEXT_TAIL
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if the flags were wrong, or Viewport was NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_NextViewport(IDirect3DDevice3 *iface,
IDirect3DViewport3 *Viewport3, IDirect3DViewport3 **lplpDirect3DViewport3, DWORD flags)
{
struct d3d_device *This = impl_from_IDirect3DDevice3(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(Viewport3);
struct d3d_viewport *next;
struct list *entry;
TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
iface, Viewport3, lplpDirect3DViewport3, flags);
if(!vp)
{
*lplpDirect3DViewport3 = NULL;
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
switch (flags)
{
case D3DNEXT_NEXT:
entry = list_next(&This->viewport_list, &vp->entry);
break;
case D3DNEXT_HEAD:
entry = list_head(&This->viewport_list);
break;
case D3DNEXT_TAIL:
entry = list_tail(&This->viewport_list);
break;
default:
WARN("Invalid flags %#x.\n", flags);
*lplpDirect3DViewport3 = NULL;
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if (entry)
{
next = LIST_ENTRY(entry, struct d3d_viewport, entry);
*lplpDirect3DViewport3 = &next->IDirect3DViewport3_iface;
}
else
*lplpDirect3DViewport3 = NULL;
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_NextViewport(IDirect3DDevice2 *iface,
IDirect3DViewport2 *viewport, IDirect3DViewport2 **next, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport2(viewport);
IDirect3DViewport3 *res;
HRESULT hr;
TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
iface, viewport, next, flags);
hr = d3d_device3_NextViewport(&device->IDirect3DDevice3_iface,
&vp->IDirect3DViewport3_iface, &res, flags);
*next = (IDirect3DViewport2 *)res;
return hr;
}
static HRESULT WINAPI d3d_device1_NextViewport(IDirect3DDevice *iface,
IDirect3DViewport *viewport, IDirect3DViewport **next, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport(viewport);
IDirect3DViewport3 *res;
HRESULT hr;
TRACE("iface %p, viewport %p, next %p, flags %#x.\n",
iface, viewport, next, flags);
hr = d3d_device3_NextViewport(&device->IDirect3DDevice3_iface,
&vp->IDirect3DViewport3_iface, &res, flags);
*next = (IDirect3DViewport *)res;
return hr;
}
/*****************************************************************************
* IDirect3DDevice::Pick
*
* Executes an execute buffer without performing rendering. Instead, a
* list of primitives that intersect with (x1,y1) of the passed rectangle
* is created. IDirect3DDevice::GetPickRecords can be used to retrieve
* this list.
*
* Version 1 only
*
* Params:
* ExecuteBuffer: Buffer to execute
* Viewport: Viewport to use for execution
* Flags: None are defined, according to the SDK
* Rect: Specifies the coordinates to be picked. Only x1 and y2 are used,
* x2 and y2 are ignored.
*
* Returns:
* D3D_OK because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_Pick(IDirect3DDevice *iface, IDirect3DExecuteBuffer *buffer,
IDirect3DViewport *viewport, DWORD flags, D3DRECT *rect)
{
FIXME("iface %p, buffer %p, viewport %p, flags %#x, rect %s stub!\n",
iface, buffer, viewport, flags, wine_dbgstr_rect((RECT *)rect));
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice::GetPickRecords
*
* Retrieves the pick records generated by IDirect3DDevice::GetPickRecords
*
* Version 1 only
*
* Params:
* Count: Pointer to a DWORD containing the numbers of pick records to
* retrieve
* D3DPickRec: Address to store the resulting D3DPICKRECORD array.
*
* Returns:
* D3D_OK, because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_GetPickRecords(IDirect3DDevice *iface,
DWORD *count, D3DPICKRECORD *records)
{
FIXME("iface %p, count %p, records %p stub!\n", iface, count, records);
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice7::EnumTextureformats
*
* Enumerates the supported texture formats. It has a list of all possible
* formats and calls IWineD3D::CheckDeviceFormat for each format to see if
* WineD3D supports it. If so, then it is passed to the app.
*
* This is for Version 7 and 3, older versions have a different
* callback function and their own implementation
*
* Params:
* Callback: Callback to call for each enumerated format
* Arg: Argument to pass to the callback
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Callback == NULL
*
*****************************************************************************/
static HRESULT d3d_device7_EnumTextureFormats(IDirect3DDevice7 *iface,
LPD3DENUMPIXELFORMATSCALLBACK callback, void *context)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_display_mode mode;
HRESULT hr;
unsigned int i;
static const enum wined3d_format_id FormatList[] =
{
/* 16 bit */
WINED3DFMT_B5G5R5X1_UNORM,
WINED3DFMT_B5G5R5A1_UNORM,
WINED3DFMT_B4G4R4A4_UNORM,
WINED3DFMT_B5G6R5_UNORM,
/* 32 bit */
WINED3DFMT_B8G8R8X8_UNORM,
WINED3DFMT_B8G8R8A8_UNORM,
/* 8 bit */
WINED3DFMT_B2G3R3_UNORM,
WINED3DFMT_P8_UINT,
/* FOURCC codes */
WINED3DFMT_DXT1,
WINED3DFMT_DXT2,
WINED3DFMT_DXT3,
WINED3DFMT_DXT4,
WINED3DFMT_DXT5,
};
static const enum wined3d_format_id BumpFormatList[] =
{
WINED3DFMT_R8G8_SNORM,
WINED3DFMT_R5G5_SNORM_L6_UNORM,
WINED3DFMT_R8G8_SNORM_L8X8_UNORM,
WINED3DFMT_R10G11B11_SNORM,
WINED3DFMT_R10G10B10_SNORM_A2_UNORM
};
TRACE("iface %p, callback %p, context %p.\n", iface, callback, context);
if (!callback)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
memset(&mode, 0, sizeof(mode));
if (FAILED(hr = wined3d_get_adapter_display_mode(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode, NULL)))
{
wined3d_mutex_unlock();
WARN("Cannot get the current adapter format\n");
return hr;
}
for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT, WINED3D_DEVICE_TYPE_HAL,
mode.format_id, WINED3DUSAGE_TEXTURE, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
{
DDPIXELFORMAT pformat;
memset(&pformat, 0, sizeof(pformat));
pformat.dwSize = sizeof(pformat);
ddrawformat_from_wined3dformat(&pformat, FormatList[i]);
TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
hr = callback(&pformat, context);
if(hr != DDENUMRET_OK)
{
TRACE("Format enumeration cancelled by application\n");
wined3d_mutex_unlock();
return D3D_OK;
}
}
}
for (i = 0; i < sizeof(BumpFormatList) / sizeof(*BumpFormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT,
WINED3D_DEVICE_TYPE_HAL, mode.format_id, WINED3DUSAGE_TEXTURE | WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
WINED3D_RTYPE_TEXTURE_2D, BumpFormatList[i]) == D3D_OK)
{
DDPIXELFORMAT pformat;
memset(&pformat, 0, sizeof(pformat));
pformat.dwSize = sizeof(pformat);
ddrawformat_from_wined3dformat(&pformat, BumpFormatList[i]);
TRACE("Enumerating WineD3DFormat %d\n", BumpFormatList[i]);
hr = callback(&pformat, context);
if(hr != DDENUMRET_OK)
{
TRACE("Format enumeration cancelled by application\n");
wined3d_mutex_unlock();
return D3D_OK;
}
}
}
TRACE("End of enumeration\n");
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_EnumTextureFormats_FPUSetup(IDirect3DDevice7 *iface,
LPD3DENUMPIXELFORMATSCALLBACK callback, void *context)
{
return d3d_device7_EnumTextureFormats(iface, callback, context);
}
static HRESULT WINAPI d3d_device7_EnumTextureFormats_FPUPreserve(IDirect3DDevice7 *iface,
LPD3DENUMPIXELFORMATSCALLBACK callback, void *context)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_EnumTextureFormats(iface, callback, context);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_EnumTextureFormats(IDirect3DDevice3 *iface,
LPD3DENUMPIXELFORMATSCALLBACK callback, void *context)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, callback %p, context %p.\n", iface, callback, context);
return IDirect3DDevice7_EnumTextureFormats(&device->IDirect3DDevice7_iface, callback, context);
}
/*****************************************************************************
* IDirect3DDevice2::EnumTextureformats
*
* EnumTextureFormats for Version 1 and 2, see
* IDirect3DDevice7::EnumTexureFormats for a more detailed description.
*
* This version has a different callback and does not enumerate FourCC
* formats
*
*****************************************************************************/
static HRESULT WINAPI d3d_device2_EnumTextureFormats(IDirect3DDevice2 *iface,
LPD3DENUMTEXTUREFORMATSCALLBACK callback, void *context)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct wined3d_display_mode mode;
HRESULT hr;
unsigned int i;
static const enum wined3d_format_id FormatList[] =
{
/* 16 bit */
WINED3DFMT_B5G5R5X1_UNORM,
WINED3DFMT_B5G5R5A1_UNORM,
WINED3DFMT_B4G4R4A4_UNORM,
WINED3DFMT_B5G6R5_UNORM,
/* 32 bit */
WINED3DFMT_B8G8R8X8_UNORM,
WINED3DFMT_B8G8R8A8_UNORM,
/* 8 bit */
WINED3DFMT_B2G3R3_UNORM,
WINED3DFMT_P8_UINT,
/* FOURCC codes - Not in this version*/
};
TRACE("iface %p, callback %p, context %p.\n", iface, callback, context);
if (!callback)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
memset(&mode, 0, sizeof(mode));
if (FAILED(hr = wined3d_get_adapter_display_mode(device->ddraw->wined3d, WINED3DADAPTER_DEFAULT, &mode, NULL)))
{
wined3d_mutex_unlock();
WARN("Cannot get the current adapter format\n");
return hr;
}
for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
{
if (wined3d_check_device_format(device->ddraw->wined3d, 0, WINED3D_DEVICE_TYPE_HAL,
mode.format_id, WINED3DUSAGE_TEXTURE, WINED3D_RTYPE_TEXTURE_2D, FormatList[i]) == D3D_OK)
{
DDSURFACEDESC sdesc;
memset(&sdesc, 0, sizeof(sdesc));
sdesc.dwSize = sizeof(sdesc);
sdesc.dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
sdesc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
sdesc.ddpfPixelFormat.dwSize = sizeof(sdesc.ddpfPixelFormat);
ddrawformat_from_wined3dformat(&sdesc.ddpfPixelFormat, FormatList[i]);
TRACE("Enumerating WineD3DFormat %d\n", FormatList[i]);
hr = callback(&sdesc, context);
if(hr != DDENUMRET_OK)
{
TRACE("Format enumeration cancelled by application\n");
wined3d_mutex_unlock();
return D3D_OK;
}
}
}
TRACE("End of enumeration\n");
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device1_EnumTextureFormats(IDirect3DDevice *iface,
LPD3DENUMTEXTUREFORMATSCALLBACK callback, void *context)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p, callback %p, context %p.\n", iface, callback, context);
return d3d_device2_EnumTextureFormats(&device->IDirect3DDevice2_iface, callback, context);
}
/*****************************************************************************
* IDirect3DDevice::CreateMatrix
*
* Creates a matrix handle. A handle is created and memory for a D3DMATRIX is
* allocated for the handle.
*
* Version 1 only
*
* Params
* D3DMatHandle: Address to return the handle at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if D3DMatHandle = NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_CreateMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE *D3DMatHandle)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
D3DMATRIX *Matrix;
DWORD h;
TRACE("iface %p, matrix_handle %p.\n", iface, D3DMatHandle);
if(!D3DMatHandle)
return DDERR_INVALIDPARAMS;
Matrix = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(D3DMATRIX));
if(!Matrix)
{
ERR("Out of memory when allocating a D3DMATRIX\n");
return DDERR_OUTOFMEMORY;
}
wined3d_mutex_lock();
h = ddraw_allocate_handle(&device->handle_table, Matrix, DDRAW_HANDLE_MATRIX);
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate a matrix handle.\n");
HeapFree(GetProcessHeap(), 0, Matrix);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
*D3DMatHandle = h + 1;
TRACE(" returning matrix handle %d\n", *D3DMatHandle);
wined3d_mutex_unlock();
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice::SetMatrix
*
* Sets a matrix for a matrix handle. The matrix is copied into the memory
* allocated for the handle
*
* Version 1 only
*
* Params:
* D3DMatHandle: Handle to set the matrix to
* D3DMatrix: Matrix to set
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if the handle of the matrix is invalid or the matrix
* to set is NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_SetMatrix(IDirect3DDevice *iface,
D3DMATRIXHANDLE D3DMatHandle, D3DMATRIX *D3DMatrix)
{
struct d3d_device *This = impl_from_IDirect3DDevice(iface);
D3DMATRIX *m;
TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix);
if (!D3DMatrix) return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
m = ddraw_get_object(&This->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
if (!m)
{
WARN("Invalid matrix handle.\n");
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if (TRACE_ON(ddraw))
dump_D3DMATRIX(D3DMatrix);
*m = *D3DMatrix;
if (D3DMatHandle == This->world)
wined3d_device_set_transform(This->wined3d_device,
WINED3D_TS_WORLD_MATRIX(0), (struct wined3d_matrix *)D3DMatrix);
if (D3DMatHandle == This->view)
wined3d_device_set_transform(This->wined3d_device,
WINED3D_TS_VIEW, (struct wined3d_matrix *)D3DMatrix);
if (D3DMatHandle == This->proj)
wined3d_device_set_transform(This->wined3d_device,
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)D3DMatrix);
wined3d_mutex_unlock();
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice::GetMatrix
*
* Returns the content of a D3DMATRIX handle
*
* Version 1 only
*
* Params:
* D3DMatHandle: Matrix handle to read the content from
* D3DMatrix: Address to store the content at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if D3DMatHandle is invalid or D3DMatrix is NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_GetMatrix(IDirect3DDevice *iface,
D3DMATRIXHANDLE D3DMatHandle, D3DMATRIX *D3DMatrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
D3DMATRIX *m;
TRACE("iface %p, matrix_handle %#x, matrix %p.\n", iface, D3DMatHandle, D3DMatrix);
if (!D3DMatrix) return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
m = ddraw_get_object(&device->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
if (!m)
{
WARN("Invalid matrix handle.\n");
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
*D3DMatrix = *m;
wined3d_mutex_unlock();
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice::DeleteMatrix
*
* Destroys a Matrix handle. Frees the memory and unsets the handle data
*
* Version 1 only
*
* Params:
* D3DMatHandle: Handle to destroy
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if D3DMatHandle is invalid
*
*****************************************************************************/
static HRESULT WINAPI d3d_device1_DeleteMatrix(IDirect3DDevice *iface, D3DMATRIXHANDLE D3DMatHandle)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
D3DMATRIX *m;
TRACE("iface %p, matrix_handle %#x.\n", iface, D3DMatHandle);
wined3d_mutex_lock();
m = ddraw_free_handle(&device->handle_table, D3DMatHandle - 1, DDRAW_HANDLE_MATRIX);
if (!m)
{
WARN("Invalid matrix handle.\n");
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_unlock();
HeapFree(GetProcessHeap(), 0, m);
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice7::BeginScene
*
* This method must be called before any rendering is performed.
* IDirect3DDevice::EndScene has to be called after the scene is complete
*
* Version 1, 2, 3 and 7
*
* Returns:
* D3D_OK on success, for details see IWineD3DDevice::BeginScene
* D3DERR_SCENE_IN_SCENE if WineD3D returns an error(Only in case of an already
* started scene).
*
*****************************************************************************/
static HRESULT d3d_device7_BeginScene(IDirect3DDevice7 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
hr = wined3d_device_begin_scene(device->wined3d_device);
wined3d_mutex_unlock();
if(hr == WINED3D_OK) return D3D_OK;
else return D3DERR_SCENE_IN_SCENE; /* TODO: Other possible causes of failure */
}
static HRESULT WINAPI d3d_device7_BeginScene_FPUSetup(IDirect3DDevice7 *iface)
{
return d3d_device7_BeginScene(iface);
}
static HRESULT WINAPI d3d_device7_BeginScene_FPUPreserve(IDirect3DDevice7 *iface)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_BeginScene(iface);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_BeginScene(IDirect3DDevice3 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_BeginScene(&device->IDirect3DDevice7_iface);
}
static HRESULT WINAPI d3d_device2_BeginScene(IDirect3DDevice2 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_BeginScene(&device->IDirect3DDevice7_iface);
}
static HRESULT WINAPI d3d_device1_BeginScene(IDirect3DDevice *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_BeginScene(&device->IDirect3DDevice7_iface);
}
/*****************************************************************************
* IDirect3DDevice7::EndScene
*
* Ends a scene that has been begun with IDirect3DDevice7::BeginScene.
* This method must be called after rendering is finished.
*
* Version 1, 2, 3 and 7
*
* Returns:
* D3D_OK on success, for details see IWineD3DDevice::EndScene
* D3DERR_SCENE_NOT_IN_SCENE is returned if WineD3D returns an error. It does
* that only if the scene was already ended.
*
*****************************************************************************/
static HRESULT d3d_device7_EndScene(IDirect3DDevice7 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
hr = wined3d_device_end_scene(device->wined3d_device);
wined3d_mutex_unlock();
if(hr == WINED3D_OK) return D3D_OK;
else return D3DERR_SCENE_NOT_IN_SCENE;
}
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d_device7_EndScene_FPUSetup(IDirect3DDevice7 *iface)
{
return d3d_device7_EndScene(iface);
}
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d_device7_EndScene_FPUPreserve(IDirect3DDevice7 *iface)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_EndScene(iface);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d_device3_EndScene(IDirect3DDevice3 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_EndScene(&device->IDirect3DDevice7_iface);
}
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d_device2_EndScene(IDirect3DDevice2 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_EndScene(&device->IDirect3DDevice7_iface);
}
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d_device1_EndScene(IDirect3DDevice *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p.\n", iface);
return IDirect3DDevice7_EndScene(&device->IDirect3DDevice7_iface);
}
/*****************************************************************************
* IDirect3DDevice7::GetDirect3D
*
* Returns the IDirect3D(= interface to the DirectDraw object) used to create
* this device.
*
* Params:
* Direct3D7: Address to store the interface pointer at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Direct3D7 == NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device7_GetDirect3D(IDirect3DDevice7 *iface, IDirect3D7 **d3d)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, d3d %p.\n", iface, d3d);
if (!d3d)
return DDERR_INVALIDPARAMS;
*d3d = &device->ddraw->IDirect3D7_iface;
IDirect3D7_AddRef(*d3d);
TRACE("Returning interface %p.\n", *d3d);
return D3D_OK;
}
static HRESULT WINAPI d3d_device3_GetDirect3D(IDirect3DDevice3 *iface, IDirect3D3 **d3d)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, d3d %p.\n", iface, d3d);
if (!d3d)
return DDERR_INVALIDPARAMS;
*d3d = &device->ddraw->IDirect3D3_iface;
IDirect3D3_AddRef(*d3d);
TRACE("Returning interface %p.\n", *d3d);
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetDirect3D(IDirect3DDevice2 *iface, IDirect3D2 **d3d)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, d3d %p.\n", iface, d3d);
if (!d3d)
return DDERR_INVALIDPARAMS;
*d3d = &device->ddraw->IDirect3D2_iface;
IDirect3D2_AddRef(*d3d);
TRACE("Returning interface %p.\n", *d3d);
return D3D_OK;
}
static HRESULT WINAPI d3d_device1_GetDirect3D(IDirect3DDevice *iface, IDirect3D **d3d)
{
struct d3d_device *device = impl_from_IDirect3DDevice(iface);
TRACE("iface %p, d3d %p.\n", iface, d3d);
if (!d3d)
return DDERR_INVALIDPARAMS;
*d3d = &device->ddraw->IDirect3D_iface;
IDirect3D_AddRef(*d3d);
TRACE("Returning interface %p.\n", *d3d);
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice3::SetCurrentViewport
*
* Sets a Direct3DViewport as the current viewport.
* For the thunks note that all viewport interface versions are equal
*
* Params:
* Direct3DViewport3: The viewport to set
*
* Version 2 and 3
*
* Returns:
* D3D_OK on success
* (Is a NULL viewport valid?)
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_SetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 *Direct3DViewport3)
{
struct d3d_device *This = impl_from_IDirect3DDevice3(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport3(Direct3DViewport3);
TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport3);
if (!vp)
{
WARN("Direct3DViewport3 is NULL, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
/* Do nothing if the specified viewport is the same as the current one */
if (This->current_viewport == vp)
{
wined3d_mutex_unlock();
return D3D_OK;
}
if (vp->active_device != This)
{
WARN("Viewport %p active device is %p.\n", vp, vp->active_device);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
/* Release previous viewport and AddRef the new one */
if (This->current_viewport)
{
TRACE("ViewportImpl is at %p, interface is at %p\n", This->current_viewport,
&This->current_viewport->IDirect3DViewport3_iface);
IDirect3DViewport3_Release(&This->current_viewport->IDirect3DViewport3_iface);
}
IDirect3DViewport3_AddRef(Direct3DViewport3);
/* Set this viewport as the current viewport */
This->current_viewport = vp;
/* Activate this viewport */
viewport_activate(This->current_viewport, FALSE);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_SetCurrentViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
struct d3d_viewport *vp = unsafe_impl_from_IDirect3DViewport2(viewport);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_SetCurrentViewport(&device->IDirect3DDevice3_iface,
vp ? &vp->IDirect3DViewport3_iface : NULL);
}
/*****************************************************************************
* IDirect3DDevice3::GetCurrentViewport
*
* Returns the currently active viewport.
*
* Version 2 and 3
*
* Params:
* Direct3DViewport3: Address to return the interface pointer at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Direct3DViewport == NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_GetCurrentViewport(IDirect3DDevice3 *iface, IDirect3DViewport3 **viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, viewport %p.\n", iface, viewport);
wined3d_mutex_lock();
if (!device->current_viewport)
{
wined3d_mutex_unlock();
WARN("No current viewport, returning D3DERR_NOCURRENTVIEWPORT\n");
return D3DERR_NOCURRENTVIEWPORT;
}
*viewport = &device->current_viewport->IDirect3DViewport3_iface;
IDirect3DViewport3_AddRef(*viewport);
TRACE("Returning interface %p.\n", *viewport);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetCurrentViewport(IDirect3DDevice2 *iface, IDirect3DViewport2 **viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, viewport %p.\n", iface, viewport);
return d3d_device3_GetCurrentViewport(&device->IDirect3DDevice3_iface,
(IDirect3DViewport3 **)viewport);
}
static BOOL validate_surface_palette(struct ddraw_surface *surface)
{
return !format_is_paletteindexed(&surface->surface_desc.u4.ddpfPixelFormat)
|| surface->palette;
}
static HRESULT d3d_device_set_render_target(struct d3d_device *device,
struct ddraw_surface *target, IUnknown *rt_iface)
{
HRESULT hr;
if (device->rt_iface == rt_iface)
{
TRACE("No-op SetRenderTarget operation, not doing anything\n");
return D3D_OK;
}
if (!target)
{
WARN("Trying to set render target to NULL.\n");
return DDERR_INVALIDPARAMS;
}
if (FAILED(hr = wined3d_device_set_rendertarget_view(device->wined3d_device,
0, ddraw_surface_get_rendertarget_view(target), FALSE)))
return hr;
IUnknown_AddRef(rt_iface);
IUnknown_Release(device->rt_iface);
device->rt_iface = rt_iface;
d3d_device_update_depth_stencil(device);
return D3D_OK;
}
static HRESULT d3d_device7_SetRenderTarget(IDirect3DDevice7 *iface,
IDirectDrawSurface7 *target, DWORD flags)
{
struct ddraw_surface *target_impl = unsafe_impl_from_IDirectDrawSurface7(target);
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, target %p, flags %#x.\n", iface, target, flags);
wined3d_mutex_lock();
if (!validate_surface_palette(target_impl))
{
WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE))
{
WARN("Surface %p is not a render target.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IDirectDrawSurface7_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
hr = d3d_device_set_render_target(device, target_impl, (IUnknown *)target);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_SetRenderTarget_FPUSetup(IDirect3DDevice7 *iface,
IDirectDrawSurface7 *NewTarget, DWORD flags)
{
return d3d_device7_SetRenderTarget(iface, NewTarget, flags);
}
static HRESULT WINAPI d3d_device7_SetRenderTarget_FPUPreserve(IDirect3DDevice7 *iface,
IDirectDrawSurface7 *NewTarget, DWORD flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetRenderTarget(iface, NewTarget, flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_SetRenderTarget(IDirect3DDevice3 *iface,
IDirectDrawSurface4 *target, DWORD flags)
{
struct ddraw_surface *target_impl = unsafe_impl_from_IDirectDrawSurface4(target);
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
HRESULT hr;
TRACE("iface %p, target %p, flags %#x.\n", iface, target, flags);
wined3d_mutex_lock();
if (!validate_surface_palette(target_impl))
{
WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE))
{
WARN("Surface %p is not a render target.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IDirectDrawSurface4_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
IDirectDrawSurface4_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return D3D_OK;
}
hr = d3d_device_set_render_target(device, target_impl, (IUnknown *)target);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device2_SetRenderTarget(IDirect3DDevice2 *iface,
IDirectDrawSurface *target, DWORD flags)
{
struct ddraw_surface *target_impl = unsafe_impl_from_IDirectDrawSurface(target);
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
HRESULT hr;
TRACE("iface %p, target %p, flags %#x.\n", iface, target, flags);
wined3d_mutex_lock();
if (!validate_surface_palette(target_impl))
{
WARN("Surface %p has an indexed pixel format, but no palette.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE))
{
WARN("Surface %p is not a render target.\n", target_impl);
wined3d_mutex_unlock();
return DDERR_INVALIDCAPS;
}
if (target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
{
WARN("Surface %p is a depth buffer.\n", target_impl);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return DDERR_INVALIDPIXELFORMAT;
}
if (!(target_impl->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target_impl);
IDirectDrawSurface_AddRef(target);
IUnknown_Release(device->rt_iface);
device->rt_iface = (IUnknown *)target;
wined3d_mutex_unlock();
return D3D_OK;
}
hr = d3d_device_set_render_target(device, target_impl, (IUnknown *)target);
wined3d_mutex_unlock();
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetRenderTarget
*
* Returns the current render target.
* This is handled locally, because the WineD3D render target's parent
* is an IParent
*
* Version 2, 3 and 7
*
* Params:
* RenderTarget: Address to store the surface interface pointer
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if RenderTarget == NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device7_GetRenderTarget(IDirect3DDevice7 *iface, IDirectDrawSurface7 **RenderTarget)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, target %p.\n", iface, RenderTarget);
if(!RenderTarget)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
hr = IUnknown_QueryInterface(device->rt_iface, &IID_IDirectDrawSurface7, (void **)RenderTarget);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device3_GetRenderTarget(IDirect3DDevice3 *iface, IDirectDrawSurface4 **RenderTarget)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
IDirectDrawSurface7 *RenderTarget7;
struct ddraw_surface *RenderTargetImpl;
HRESULT hr;
TRACE("iface %p, target %p.\n", iface, RenderTarget);
if(!RenderTarget)
return DDERR_INVALIDPARAMS;
hr = d3d_device7_GetRenderTarget(&device->IDirect3DDevice7_iface, &RenderTarget7);
if(hr != D3D_OK) return hr;
RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7);
*RenderTarget = &RenderTargetImpl->IDirectDrawSurface4_iface;
IDirectDrawSurface4_AddRef(*RenderTarget);
IDirectDrawSurface7_Release(RenderTarget7);
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetRenderTarget(IDirect3DDevice2 *iface, IDirectDrawSurface **RenderTarget)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
IDirectDrawSurface7 *RenderTarget7;
struct ddraw_surface *RenderTargetImpl;
HRESULT hr;
TRACE("iface %p, target %p.\n", iface, RenderTarget);
if(!RenderTarget)
return DDERR_INVALIDPARAMS;
hr = d3d_device7_GetRenderTarget(&device->IDirect3DDevice7_iface, &RenderTarget7);
if(hr != D3D_OK) return hr;
RenderTargetImpl = impl_from_IDirectDrawSurface7(RenderTarget7);
*RenderTarget = &RenderTargetImpl->IDirectDrawSurface_iface;
IDirectDrawSurface_AddRef(*RenderTarget);
IDirectDrawSurface7_Release(RenderTarget7);
return D3D_OK;
}
/*****************************************************************************
* IDirect3DDevice3::Begin
*
* Begins a description block of vertices. This is similar to glBegin()
* and glEnd(). After a call to IDirect3DDevice3::End, the vertices
* described with IDirect3DDevice::Vertex are drawn.
*
* Version 2 and 3
*
* Params:
* PrimitiveType: The type of primitives to draw
* VertexTypeDesc: A flexible vertex format description of the vertices
* Flags: Some flags..
*
* Returns:
* D3D_OK on success
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_Begin(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, primitive_type %#x, fvf %#x, flags %#x.\n",
iface, primitive_type, fvf, flags);
wined3d_mutex_lock();
device->primitive_type = primitive_type;
device->vertex_type = fvf;
device->render_flags = flags;
device->vertex_size = get_flexible_vertex_size(device->vertex_type);
device->nb_vertices = 0;
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_Begin(IDirect3DDevice2 *iface,
D3DPRIMITIVETYPE primitive_type, D3DVERTEXTYPE vertex_type, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
DWORD fvf;
TRACE("iface %p, primitive_type %#x, vertex_type %#x, flags %#x.\n",
iface, primitive_type, vertex_type, flags);
switch (vertex_type)
{
case D3DVT_VERTEX: fvf = D3DFVF_VERTEX; break;
case D3DVT_LVERTEX: fvf = D3DFVF_LVERTEX; break;
case D3DVT_TLVERTEX: fvf = D3DFVF_TLVERTEX; break;
default:
ERR("Unexpected vertex type %#x.\n", vertex_type);
return DDERR_INVALIDPARAMS; /* Should never happen */
};
return d3d_device3_Begin(&device->IDirect3DDevice3_iface, primitive_type, fvf, flags);
}
/*****************************************************************************
* IDirect3DDevice3::BeginIndexed
*
* Draws primitives based on vertices in a vertex array which are specified
* by indices.
*
* Version 2 and 3
*
* Params:
* PrimitiveType: Primitive type to draw
* VertexType: A FVF description of the vertex format
* Vertices: pointer to an array containing the vertices
* NumVertices: The number of vertices in the vertex array
* Flags: Some flags ...
*
* Returns:
* D3D_OK, because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_BeginIndexed(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf,
void *vertices, DWORD vertex_count, DWORD flags)
{
FIXME("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
iface, primitive_type, fvf, vertices, vertex_count, flags);
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_BeginIndexed(IDirect3DDevice2 *iface,
D3DPRIMITIVETYPE primitive_type, D3DVERTEXTYPE vertex_type,
void *vertices, DWORD vertex_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
DWORD fvf;
TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x stub!\n",
iface, primitive_type, vertex_type, vertices, vertex_count, flags);
switch (vertex_type)
{
case D3DVT_VERTEX: fvf = D3DFVF_VERTEX; break;
case D3DVT_LVERTEX: fvf = D3DFVF_LVERTEX; break;
case D3DVT_TLVERTEX: fvf = D3DFVF_TLVERTEX; break;
default:
ERR("Unexpected vertex type %#x.\n", vertex_type);
return DDERR_INVALIDPARAMS; /* Should never happen */
};
return d3d_device3_BeginIndexed(&device->IDirect3DDevice3_iface,
primitive_type, fvf, vertices, vertex_count, flags);
}
/*****************************************************************************
* IDirect3DDevice3::Vertex
*
* Draws a vertex as described by IDirect3DDevice3::Begin. It places all
* drawn vertices in a vertex buffer. If the buffer is too small, its
* size is increased.
*
* Version 2 and 3
*
* Params:
* Vertex: Pointer to the vertex
*
* Returns:
* D3D_OK, on success
* DDERR_INVALIDPARAMS if Vertex is NULL
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_Vertex(IDirect3DDevice3 *iface, void *vertex)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, vertex %p.\n", iface, vertex);
if (!vertex)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if ((device->nb_vertices + 1) * device->vertex_size > device->buffer_size)
{
BYTE *old_buffer;
device->buffer_size = device->buffer_size ? device->buffer_size * 2 : device->vertex_size * 3;
old_buffer = device->sysmem_vertex_buffer;
device->sysmem_vertex_buffer = HeapAlloc(GetProcessHeap(), 0, device->buffer_size);
if (old_buffer)
{
memcpy(device->sysmem_vertex_buffer, old_buffer, device->nb_vertices * device->vertex_size);
HeapFree(GetProcessHeap(), 0, old_buffer);
}
}
memcpy(device->sysmem_vertex_buffer + device->nb_vertices++ * device->vertex_size, vertex, device->vertex_size);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_Vertex(IDirect3DDevice2 *iface, void *vertex)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, vertex %p.\n", iface, vertex);
return d3d_device3_Vertex(&device->IDirect3DDevice3_iface, vertex);
}
/*****************************************************************************
* IDirect3DDevice3::Index
*
* Specifies an index to a vertex to be drawn. The vertex array has to
* be specified with BeginIndexed first.
*
* Parameters:
* VertexIndex: The index of the vertex to draw
*
* Returns:
* D3D_OK because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_Index(IDirect3DDevice3 *iface, WORD index)
{
FIXME("iface %p, index %#x stub!\n", iface, index);
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_Index(IDirect3DDevice2 *iface, WORD index)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, index %#x.\n", iface, index);
return d3d_device3_Index(&device->IDirect3DDevice3_iface, index);
}
/*****************************************************************************
* IDirect3DDevice7::GetRenderState
*
* Returns the value of a render state. The possible render states are
* defined in include/d3dtypes.h
*
* Version 2, 3 and 7
*
* Params:
* RenderStateType: Render state to return the current setting of
* Value: Address to store the value at
*
* Returns:
* D3D_OK on success, for details see IWineD3DDevice::GetRenderState
* DDERR_INVALIDPARAMS if Value == NULL
*
*****************************************************************************/
static HRESULT d3d_device7_GetRenderState(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr = D3D_OK;
TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
if (!value)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
switch (state)
{
case D3DRENDERSTATE_TEXTUREMAG:
{
enum wined3d_texture_filter_type tex_mag;
tex_mag = wined3d_device_get_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_MAG_FILTER);
switch (tex_mag)
{
case WINED3D_TEXF_POINT:
*value = D3DFILTER_NEAREST;
break;
case WINED3D_TEXF_LINEAR:
*value = D3DFILTER_LINEAR;
break;
default:
ERR("Unhandled texture mag %d !\n",tex_mag);
*value = 0;
}
break;
}
case D3DRENDERSTATE_TEXTUREMIN:
{
enum wined3d_texture_filter_type tex_min;
enum wined3d_texture_filter_type tex_mip;
tex_min = wined3d_device_get_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_MIN_FILTER);
tex_mip = wined3d_device_get_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_MIP_FILTER);
switch (tex_min)
{
case WINED3D_TEXF_POINT:
switch (tex_mip)
{
case WINED3D_TEXF_NONE:
*value = D3DFILTER_NEAREST;
break;
case WINED3D_TEXF_POINT:
*value = D3DFILTER_MIPNEAREST;
break;
case WINED3D_TEXF_LINEAR:
*value = D3DFILTER_LINEARMIPNEAREST;
break;
default:
ERR("Unhandled mip filter %#x.\n", tex_mip);
*value = D3DFILTER_NEAREST;
break;
}
break;
case WINED3D_TEXF_LINEAR:
switch (tex_mip)
{
case WINED3D_TEXF_NONE:
*value = D3DFILTER_LINEAR;
break;
case WINED3D_TEXF_POINT:
*value = D3DFILTER_MIPLINEAR;
break;
case WINED3D_TEXF_LINEAR:
*value = D3DFILTER_LINEARMIPLINEAR;
break;
default:
ERR("Unhandled mip filter %#x.\n", tex_mip);
*value = D3DFILTER_LINEAR;
break;
}
break;
default:
ERR("Unhandled texture min filter %#x.\n",tex_min);
*value = D3DFILTER_NEAREST;
break;
}
break;
}
case D3DRENDERSTATE_TEXTUREADDRESS:
case D3DRENDERSTATE_TEXTUREADDRESSU:
*value = wined3d_device_get_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_ADDRESS_U);
break;
case D3DRENDERSTATE_TEXTUREADDRESSV:
*value = wined3d_device_get_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_ADDRESS_V);
break;
case D3DRENDERSTATE_BORDERCOLOR:
FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
hr = E_NOTIMPL;
break;
case D3DRENDERSTATE_TEXTUREHANDLE:
case D3DRENDERSTATE_TEXTUREMAPBLEND:
WARN("Render state %#x is invalid in d3d7.\n", state);
hr = DDERR_INVALIDPARAMS;
break;
case D3DRENDERSTATE_ZBIAS:
*value = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS);
break;
default:
if (state >= D3DRENDERSTATE_STIPPLEPATTERN00
&& state <= D3DRENDERSTATE_STIPPLEPATTERN31)
{
FIXME("Unhandled stipple pattern render state (%#x).\n", state);
hr = E_NOTIMPL;
break;
}
*value = wined3d_device_get_render_state(device->wined3d_device, state);
}
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_GetRenderState_FPUSetup(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD *value)
{
return d3d_device7_GetRenderState(iface, state, value);
}
static HRESULT WINAPI d3d_device7_GetRenderState_FPUPreserve(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD *value)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetRenderState(iface, state, value);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_GetRenderState(IDirect3DDevice3 *iface,
D3DRENDERSTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
switch (state)
{
case D3DRENDERSTATE_TEXTUREHANDLE:
{
/* This state is wrapped to SetTexture in SetRenderState, so
* it has to be wrapped to GetTexture here. */
struct wined3d_texture *tex = NULL;
*value = 0;
wined3d_mutex_lock();
if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
{
/* The parent of the texture is the IDirectDrawSurface7
* interface of the ddraw surface. */
struct ddraw_texture *parent = wined3d_texture_get_parent(tex);
if (parent)
*value = parent->root->Handle;
}
wined3d_mutex_unlock();
return D3D_OK;
}
case D3DRENDERSTATE_TEXTUREMAPBLEND:
{
/* D3DRENDERSTATE_TEXTUREMAPBLEND is mapped to texture state stages in SetRenderState; reverse
the mapping to get the value. */
DWORD colorop, colorarg1, colorarg2;
DWORD alphaop, alphaarg1, alphaarg2;
wined3d_mutex_lock();
device->legacyTextureBlending = TRUE;
colorop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_OP);
colorarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG1);
colorarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_COLOR_ARG2);
alphaop = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_OP);
alphaarg1 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG1);
alphaarg2 = wined3d_device_get_texture_stage_state(device->wined3d_device, 0, WINED3D_TSS_ALPHA_ARG2);
if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
&& alphaop == WINED3D_TOP_SELECT_ARG1 && alphaarg1 == WINED3DTA_TEXTURE)
*value = D3DTBLEND_DECAL;
else if (colorop == WINED3D_TOP_SELECT_ARG1 && colorarg1 == WINED3DTA_TEXTURE
&& alphaop == WINED3D_TOP_MODULATE
&& alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
*value = D3DTBLEND_DECALALPHA;
else if (colorop == WINED3D_TOP_MODULATE
&& colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
&& alphaop == WINED3D_TOP_MODULATE
&& alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT)
*value = D3DTBLEND_MODULATEALPHA;
else
{
struct wined3d_texture *tex = NULL;
BOOL tex_alpha = FALSE;
DDPIXELFORMAT ddfmt;
if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
{
struct wined3d_resource_desc desc;
wined3d_resource_get_desc(wined3d_texture_get_resource(tex), &desc);
ddfmt.dwSize = sizeof(ddfmt);
ddrawformat_from_wined3dformat(&ddfmt, desc.format);
if (ddfmt.u5.dwRGBAlphaBitMask)
tex_alpha = TRUE;
}
if (!(colorop == WINED3D_TOP_MODULATE
&& colorarg1 == WINED3DTA_TEXTURE && colorarg2 == WINED3DTA_CURRENT
&& alphaop == (tex_alpha ? WINED3D_TOP_SELECT_ARG1 : WINED3D_TOP_SELECT_ARG2)
&& alphaarg1 == WINED3DTA_TEXTURE && alphaarg2 == WINED3DTA_CURRENT))
ERR("Unexpected texture stage state setup, returning D3DTBLEND_MODULATE - likely erroneous.\n");
*value = D3DTBLEND_MODULATE;
}
wined3d_mutex_unlock();
return D3D_OK;
}
case D3DRENDERSTATE_LIGHTING:
case D3DRENDERSTATE_NORMALIZENORMALS:
case D3DRENDERSTATE_LOCALVIEWER:
*value = 0xffffffff;
return D3D_OK;
default:
return IDirect3DDevice7_GetRenderState(&device->IDirect3DDevice7_iface, state, value);
}
}
static HRESULT WINAPI d3d_device2_GetRenderState(IDirect3DDevice2 *iface,
D3DRENDERSTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
return IDirect3DDevice3_GetRenderState(&device->IDirect3DDevice3_iface, state, value);
}
/*****************************************************************************
* IDirect3DDevice7::SetRenderState
*
* Sets a render state. The possible render states are defined in
* include/d3dtypes.h
*
* Version 2, 3 and 7
*
* Params:
* RenderStateType: State to set
* Value: Value to assign to that state
*
* Returns:
* D3D_OK on success,
* for details see IWineD3DDevice::SetRenderState
*
*****************************************************************************/
static HRESULT d3d_device7_SetRenderState(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr = D3D_OK;
TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
wined3d_mutex_lock();
/* Some render states need special care */
switch (state)
{
/*
* The ddraw texture filter mapping works like this:
* D3DFILTER_NEAREST Point min/mag, no mip
* D3DFILTER_MIPNEAREST Point min/mag, point mip
* D3DFILTER_LINEARMIPNEAREST: Point min/mag, linear mip
*
* D3DFILTER_LINEAR Linear min/mag, no mip
* D3DFILTER_MIPLINEAR Linear min/mag, point mip
* D3DFILTER_LINEARMIPLINEAR Linear min/mag, linear mip
*
* This is the opposite of the GL naming convention,
* D3DFILTER_LINEARMIPNEAREST corresponds to GL_NEAREST_MIPMAP_LINEAR.
*/
case D3DRENDERSTATE_TEXTUREMAG:
{
enum wined3d_texture_filter_type tex_mag;
switch (value)
{
case D3DFILTER_NEAREST:
case D3DFILTER_MIPNEAREST:
case D3DFILTER_LINEARMIPNEAREST:
tex_mag = WINED3D_TEXF_POINT;
break;
case D3DFILTER_LINEAR:
case D3DFILTER_MIPLINEAR:
case D3DFILTER_LINEARMIPLINEAR:
tex_mag = WINED3D_TEXF_LINEAR;
break;
default:
tex_mag = WINED3D_TEXF_POINT;
FIXME("Unhandled texture mag %#x.\n", value);
break;
}
wined3d_device_set_sampler_state(device->wined3d_device, 0, WINED3D_SAMP_MAG_FILTER, tex_mag);
break;
}
case D3DRENDERSTATE_TEXTUREMIN:
{
enum wined3d_texture_filter_type tex_min;
enum wined3d_texture_filter_type tex_mip;
switch (value)
{
case D3DFILTER_NEAREST:
tex_min = WINED3D_TEXF_POINT;
tex_mip = WINED3D_TEXF_NONE;
break;
case D3DFILTER_LINEAR:
tex_min = WINED3D_TEXF_LINEAR;
tex_mip = WINED3D_TEXF_NONE;
break;
case D3DFILTER_MIPNEAREST:
tex_min = WINED3D_TEXF_POINT;
tex_mip = WINED3D_TEXF_POINT;
break;
case D3DFILTER_MIPLINEAR:
tex_min = WINED3D_TEXF_LINEAR;
tex_mip = WINED3D_TEXF_POINT;
break;
case D3DFILTER_LINEARMIPNEAREST:
tex_min = WINED3D_TEXF_POINT;
tex_mip = WINED3D_TEXF_LINEAR;
break;
case D3DFILTER_LINEARMIPLINEAR:
tex_min = WINED3D_TEXF_LINEAR;
tex_mip = WINED3D_TEXF_LINEAR;
break;
default:
FIXME("Unhandled texture min %#x.\n",value);
tex_min = WINED3D_TEXF_POINT;
tex_mip = WINED3D_TEXF_NONE;
break;
}
wined3d_device_set_sampler_state(device->wined3d_device,
0, WINED3D_SAMP_MIP_FILTER, tex_mip);
wined3d_device_set_sampler_state(device->wined3d_device,
0, WINED3D_SAMP_MIN_FILTER, tex_min);
break;
}
case D3DRENDERSTATE_TEXTUREADDRESS:
wined3d_device_set_sampler_state(device->wined3d_device,
0, WINED3D_SAMP_ADDRESS_V, value);
/* Drop through */
case D3DRENDERSTATE_TEXTUREADDRESSU:
wined3d_device_set_sampler_state(device->wined3d_device,
0, WINED3D_SAMP_ADDRESS_U, value);
break;
case D3DRENDERSTATE_TEXTUREADDRESSV:
wined3d_device_set_sampler_state(device->wined3d_device,
0, WINED3D_SAMP_ADDRESS_V, value);
break;
case D3DRENDERSTATE_BORDERCOLOR:
/* This should probably just forward to the corresponding sampler
* state. Needs tests. */
FIXME("Unhandled render state D3DRENDERSTATE_BORDERCOLOR.\n");
hr = E_NOTIMPL;
break;
case D3DRENDERSTATE_TEXTUREHANDLE:
case D3DRENDERSTATE_TEXTUREMAPBLEND:
WARN("Render state %#x is invalid in d3d7.\n", state);
hr = DDERR_INVALIDPARAMS;
break;
case D3DRENDERSTATE_ZBIAS:
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DEPTHBIAS, value);
break;
default:
if (state >= D3DRENDERSTATE_STIPPLEPATTERN00
&& state <= D3DRENDERSTATE_STIPPLEPATTERN31)
{
FIXME("Unhandled stipple pattern render state (%#x).\n", state);
hr = E_NOTIMPL;
break;
}
wined3d_device_set_render_state(device->wined3d_device, state, value);
break;
}
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_SetRenderState_FPUSetup(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD value)
{
return d3d_device7_SetRenderState(iface, state, value);
}
static HRESULT WINAPI d3d_device7_SetRenderState_FPUPreserve(IDirect3DDevice7 *iface,
D3DRENDERSTATETYPE state, DWORD value)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetRenderState(iface, state, value);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_SetRenderState(IDirect3DDevice3 *iface,
D3DRENDERSTATETYPE state, DWORD value)
{
/* Note about D3DRENDERSTATE_TEXTUREMAPBLEND implementation: most of values
for this state can be directly mapped to texture stage colorop and alphaop, but
D3DTBLEND_MODULATE is tricky: it uses alpha from texture when available and alpha
from diffuse otherwise. So changing the texture must be monitored in SetTexture to modify
alphaarg when needed.
Aliens vs Predator 1 depends on accurate D3DTBLEND_MODULATE emulation
Legacy texture blending (TEXTUREMAPBLEND) and texture stage states: directx6 docs state that
TEXTUREMAPBLEND is deprecated, yet can still be used. Games must not use both or results
are undefined. D3DTBLEND_MODULATE mode in particular is dependent on texture pixel format and
requires fixup of stage 0 texture states when texture changes, but this fixup can interfere
with games not using this deprecated state. So a flag 'legacyTextureBlending' has to be kept
in device - TRUE if the app is using TEXTUREMAPBLEND.
Tests show that setting TEXTUREMAPBLEND on native doesn't seem to change values returned by
GetTextureStageState and vice versa. Not so on Wine, but it is 'undefined' anyway so, probably, ok,
unless some broken game will be found that cares. */
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
HRESULT hr;
TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
if (state >= D3DSTATE_OVERRIDE_BIAS)
{
WARN("Unhandled state %#x.\n", state);
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
switch (state)
{
case D3DRENDERSTATE_TEXTUREHANDLE:
{
struct ddraw_surface *surf;
if (value == 0)
{
hr = wined3d_device_set_texture(device->wined3d_device, 0, NULL);
break;
}
surf = ddraw_get_object(&device->handle_table, value - 1, DDRAW_HANDLE_SURFACE);
if (!surf)
{
WARN("Invalid texture handle.\n");
hr = DDERR_INVALIDPARAMS;
break;
}
hr = IDirect3DDevice3_SetTexture(iface, 0, &surf->IDirect3DTexture2_iface);
break;
}
case D3DRENDERSTATE_TEXTUREMAPBLEND:
{
device->legacyTextureBlending = TRUE;
switch (value)
{
case D3DTBLEND_MODULATE:
{
struct wined3d_texture *tex = NULL;
BOOL tex_alpha = FALSE;
DDPIXELFORMAT ddfmt;
if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
{
struct wined3d_resource_desc desc;
wined3d_resource_get_desc(wined3d_texture_get_resource(tex), &desc);
ddfmt.dwSize = sizeof(ddfmt);
ddrawformat_from_wined3dformat(&ddfmt, desc.format);
if (ddfmt.u5.dwRGBAlphaBitMask)
tex_alpha = TRUE;
}
if (tex_alpha)
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1);
else
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_MODULATE);
break;
}
case D3DTBLEND_ADD:
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_ADD);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT);
break;
case D3DTBLEND_MODULATEALPHA:
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_MODULATE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_MODULATE);
break;
case D3DTBLEND_COPY:
case D3DTBLEND_DECAL:
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_SELECT_ARG1);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1);
break;
case D3DTBLEND_DECALALPHA:
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_OP, WINED3D_TOP_BLEND_TEXTURE_ALPHA);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG1, WINED3DTA_TEXTURE);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_COLOR_ARG2, WINED3DTA_CURRENT);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2);
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_ARG2, WINED3DTA_CURRENT);
break;
default:
FIXME("Unhandled texture environment %#x.\n", value);
}
hr = D3D_OK;
break;
}
case D3DRENDERSTATE_LIGHTING:
case D3DRENDERSTATE_NORMALIZENORMALS:
case D3DRENDERSTATE_LOCALVIEWER:
hr = D3D_OK;
break;
default:
hr = IDirect3DDevice7_SetRenderState(&device->IDirect3DDevice7_iface, state, value);
break;
}
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device2_SetRenderState(IDirect3DDevice2 *iface,
D3DRENDERSTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
return IDirect3DDevice3_SetRenderState(&device->IDirect3DDevice3_iface, state, value);
}
/*****************************************************************************
* Direct3DDevice3::SetLightState
*
* Sets a light state for Direct3DDevice3 and Direct3DDevice2. The
* light states are forwarded to Direct3DDevice7 render states
*
* Version 2 and 3
*
* Params:
* LightStateType: The light state to change
* Value: The value to assign to that light state
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if the parameters were incorrect
* Also check IDirect3DDevice7::SetRenderState
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_SetLightState(IDirect3DDevice3 *iface,
D3DLIGHTSTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
HRESULT hr;
TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
if (!state || (state > D3DLIGHTSTATE_COLORVERTEX))
{
TRACE("Unexpected Light State Type\n");
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
if (state == D3DLIGHTSTATE_MATERIAL)
{
if (value)
{
struct d3d_material *m;
if (!(m = ddraw_get_object(&device->handle_table, value - 1, DDRAW_HANDLE_MATERIAL)))
{
WARN("Invalid material handle.\n");
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
material_activate(m);
}
device->material = value;
}
else if (state == D3DLIGHTSTATE_COLORMODEL)
{
switch (value)
{
case D3DCOLOR_MONO:
ERR("DDCOLOR_MONO should not happen!\n");
break;
case D3DCOLOR_RGB:
/* We are already in this mode */
TRACE("Setting color model to RGB (no-op).\n");
break;
default:
ERR("Unknown color model!\n");
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
else
{
D3DRENDERSTATETYPE rs;
switch (state)
{
case D3DLIGHTSTATE_AMBIENT: /* 2 */
rs = D3DRENDERSTATE_AMBIENT;
break;
case D3DLIGHTSTATE_FOGMODE: /* 4 */
rs = D3DRENDERSTATE_FOGVERTEXMODE;
break;
case D3DLIGHTSTATE_FOGSTART: /* 5 */
rs = D3DRENDERSTATE_FOGSTART;
break;
case D3DLIGHTSTATE_FOGEND: /* 6 */
rs = D3DRENDERSTATE_FOGEND;
break;
case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
rs = D3DRENDERSTATE_FOGDENSITY;
break;
case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
rs = D3DRENDERSTATE_COLORVERTEX;
break;
default:
FIXME("Unhandled D3DLIGHTSTATETYPE %#x.\n", state);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
hr = IDirect3DDevice7_SetRenderState(&device->IDirect3DDevice7_iface, rs, value);
wined3d_mutex_unlock();
return hr;
}
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_SetLightState(IDirect3DDevice2 *iface,
D3DLIGHTSTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
return d3d_device3_SetLightState(&device->IDirect3DDevice3_iface, state, value);
}
/*****************************************************************************
* IDirect3DDevice3::GetLightState
*
* Returns the current setting of a light state. The state is read from
* the Direct3DDevice7 render state.
*
* Version 2 and 3
*
* Params:
* LightStateType: The light state to return
* Value: The address to store the light state setting at
*
* Returns:
* D3D_OK on success
* DDDERR_INVALIDPARAMS if the parameters were incorrect
* Also see IDirect3DDevice7::GetRenderState
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_GetLightState(IDirect3DDevice3 *iface,
D3DLIGHTSTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
HRESULT hr;
TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
if (!state || (state > D3DLIGHTSTATE_COLORVERTEX))
{
TRACE("Unexpected Light State Type\n");
return DDERR_INVALIDPARAMS;
}
if (!value)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if (state == D3DLIGHTSTATE_MATERIAL)
{
*value = device->material;
}
else if (state == D3DLIGHTSTATE_COLORMODEL)
{
*value = D3DCOLOR_RGB;
}
else
{
D3DRENDERSTATETYPE rs;
switch (state)
{
case D3DLIGHTSTATE_AMBIENT: /* 2 */
rs = D3DRENDERSTATE_AMBIENT;
break;
case D3DLIGHTSTATE_FOGMODE: /* 4 */
rs = D3DRENDERSTATE_FOGVERTEXMODE;
break;
case D3DLIGHTSTATE_FOGSTART: /* 5 */
rs = D3DRENDERSTATE_FOGSTART;
break;
case D3DLIGHTSTATE_FOGEND: /* 6 */
rs = D3DRENDERSTATE_FOGEND;
break;
case D3DLIGHTSTATE_FOGDENSITY: /* 7 */
rs = D3DRENDERSTATE_FOGDENSITY;
break;
case D3DLIGHTSTATE_COLORVERTEX: /* 8 */
rs = D3DRENDERSTATE_COLORVERTEX;
break;
default:
FIXME("Unhandled D3DLIGHTSTATETYPE %#x.\n", state);
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
hr = IDirect3DDevice7_GetRenderState(&device->IDirect3DDevice7_iface, rs, value);
wined3d_mutex_unlock();
return hr;
}
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device2_GetLightState(IDirect3DDevice2 *iface,
D3DLIGHTSTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
return d3d_device3_GetLightState(&device->IDirect3DDevice3_iface, state, value);
}
/*****************************************************************************
* IDirect3DDevice7::SetTransform
*
* Assigns a D3DMATRIX to a transform type. The transform types are defined
* in include/d3dtypes.h.
* The D3DTRANSFORMSTATE_WORLD (=1) is translated to D3DTS_WORLDMATRIX(0)
* (=255) for wined3d, because the 1 transform state was removed in d3d8
* and WineD3D already understands the replacement D3DTS_WORLDMATRIX(0)
*
* Version 2, 3 and 7
*
* Params:
* TransformStateType: transform state to set
* Matrix: Matrix to assign to the state
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Matrix == NULL
* For details see IWineD3DDevice::SetTransform
*
*****************************************************************************/
static HRESULT d3d_device7_SetTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
switch (state)
{
case D3DTRANSFORMSTATE_WORLD:
wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
break;
case D3DTRANSFORMSTATE_WORLD1:
wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
break;
case D3DTRANSFORMSTATE_WORLD2:
wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
break;
case D3DTRANSFORMSTATE_WORLD3:
wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
break;
default:
wined3d_state = state;
}
if (!matrix)
return DDERR_INVALIDPARAMS;
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
wined3d_device_set_transform(device->wined3d_device, wined3d_state, (struct wined3d_matrix *)matrix);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_SetTransform_FPUSetup(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
return d3d_device7_SetTransform(iface, state, matrix);
}
static HRESULT WINAPI d3d_device7_SetTransform_FPUPreserve(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetTransform(iface, state, matrix);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_SetTransform(IDirect3DDevice3 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
if (!matrix)
return DDERR_INVALIDPARAMS;
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
D3DMATRIX projection;
wined3d_mutex_lock();
multiply_matrix(&projection, &device->legacy_clipspace, matrix);
wined3d_device_set_transform(device->wined3d_device,
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
device->legacy_projection = *matrix;
wined3d_mutex_unlock();
return D3D_OK;
}
return IDirect3DDevice7_SetTransform(&device->IDirect3DDevice7_iface, state, matrix);
}
static HRESULT WINAPI d3d_device2_SetTransform(IDirect3DDevice2 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
return IDirect3DDevice3_SetTransform(&device->IDirect3DDevice3_iface, state, matrix);
}
/*****************************************************************************
* IDirect3DDevice7::GetTransform
*
* Returns the matrix assigned to a transform state
* D3DTRANSFORMSTATE_WORLD is translated to D3DTS_WORLDMATRIX(0), see
* SetTransform
*
* Params:
* TransformStateType: State to read the matrix from
* Matrix: Address to store the matrix at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Matrix == NULL
* For details, see IWineD3DDevice::GetTransform
*
*****************************************************************************/
static HRESULT d3d_device7_GetTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
switch (state)
{
case D3DTRANSFORMSTATE_WORLD:
wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
break;
case D3DTRANSFORMSTATE_WORLD1:
wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
break;
case D3DTRANSFORMSTATE_WORLD2:
wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
break;
case D3DTRANSFORMSTATE_WORLD3:
wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
break;
default:
wined3d_state = state;
}
if (!matrix)
return DDERR_INVALIDPARAMS;
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
wined3d_device_get_transform(device->wined3d_device, wined3d_state, (struct wined3d_matrix *)matrix);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_GetTransform_FPUSetup(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
return d3d_device7_GetTransform(iface, state, matrix);
}
static HRESULT WINAPI d3d_device7_GetTransform_FPUPreserve(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetTransform(iface, state, matrix);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_GetTransform(IDirect3DDevice3 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
if (!matrix)
return DDERR_INVALIDPARAMS;
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
wined3d_mutex_lock();
*matrix = device->legacy_projection;
wined3d_mutex_unlock();
return DD_OK;
}
return IDirect3DDevice7_GetTransform(&device->IDirect3DDevice7_iface, state, matrix);
}
static HRESULT WINAPI d3d_device2_GetTransform(IDirect3DDevice2 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
return IDirect3DDevice3_GetTransform(&device->IDirect3DDevice3_iface, state, matrix);
}
/*****************************************************************************
* IDirect3DDevice7::MultiplyTransform
*
* Multiplies the already-set transform matrix of a transform state
* with another matrix. For the world matrix, see SetTransform
*
* Version 2, 3 and 7
*
* Params:
* TransformStateType: Transform state to multiply
* D3DMatrix Matrix to multiply with.
*
* Returns
* D3D_OK on success
* DDERR_INVALIDPARAMS if D3DMatrix is NULL
* For details, see IWineD3DDevice::MultiplyTransform
*
*****************************************************************************/
static HRESULT d3d_device7_MultiplyTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
switch (state)
{
case D3DTRANSFORMSTATE_WORLD:
wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
break;
case D3DTRANSFORMSTATE_WORLD1:
wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
break;
case D3DTRANSFORMSTATE_WORLD2:
wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
break;
case D3DTRANSFORMSTATE_WORLD3:
wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
break;
default:
wined3d_state = state;
}
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
wined3d_device_multiply_transform(device->wined3d_device,
wined3d_state, (struct wined3d_matrix *)matrix);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_MultiplyTransform_FPUSetup(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
return d3d_device7_MultiplyTransform(iface, state, matrix);
}
static HRESULT WINAPI d3d_device7_MultiplyTransform_FPUPreserve(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_MultiplyTransform(iface, state, matrix);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_MultiplyTransform(IDirect3DDevice3 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
if (state == D3DTRANSFORMSTATE_PROJECTION)
{
D3DMATRIX projection, tmp;
wined3d_mutex_lock();
multiply_matrix(&tmp, &device->legacy_projection, matrix);
multiply_matrix(&projection, &device->legacy_clipspace, &tmp);
wined3d_device_set_transform(device->wined3d_device,
WINED3D_TS_PROJECTION, (struct wined3d_matrix *)&projection);
device->legacy_projection = tmp;
wined3d_mutex_unlock();
return D3D_OK;
}
return IDirect3DDevice7_MultiplyTransform(&device->IDirect3DDevice7_iface, state, matrix);
}
static HRESULT WINAPI d3d_device2_MultiplyTransform(IDirect3DDevice2 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
return IDirect3DDevice3_MultiplyTransform(&device->IDirect3DDevice3_iface, state, matrix);
}
/*****************************************************************************
* IDirect3DDevice7::DrawPrimitive
*
* Draws primitives based on vertices in an application-provided pointer
*
* Version 2, 3 and 7. The IDirect3DDevice2 thunk converts the fixed vertex type into
* an FVF format for D3D7
*
* Params:
* PrimitiveType: The type of the primitives to draw
* Vertex type: Flexible vertex format vertex description
* Vertices: Pointer to the vertex array
* VertexCount: The number of vertices to draw
* Flags: As usual a few flags
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Vertices is NULL
* For details, see IWineD3DDevice::DrawPrimitiveUP
*
*****************************************************************************/
/* The caller is responsible for wined3d locking */
static HRESULT d3d_device_prepare_vertex_buffer(struct d3d_device *device, UINT min_size)
{
HRESULT hr;
if (device->vertex_buffer_size < min_size || !device->vertex_buffer)
{
UINT size = max(device->vertex_buffer_size * 2, min_size);
struct wined3d_buffer *buffer;
TRACE("Growing vertex buffer to %u bytes\n", size);
hr = wined3d_buffer_create_vb(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer);
if (FAILED(hr))
{
ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device, hr);
return hr;
}
if (device->vertex_buffer)
wined3d_buffer_decref(device->vertex_buffer);
device->vertex_buffer = buffer;
device->vertex_buffer_size = size;
device->vertex_buffer_pos = 0;
}
return D3D_OK;
}
static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices,
DWORD vertex_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
UINT stride, vb_pos, size, align;
struct wined3d_resource *vb;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x.\n",
iface, primitive_type, fvf, vertices, vertex_count, flags);
if (!vertex_count)
{
WARN("0 vertex count.\n");
return D3D_OK;
}
/* Get the stride */
stride = get_flexible_vertex_size(fvf);
size = vertex_count * stride;
wined3d_mutex_lock();
hr = d3d_device_prepare_vertex_buffer(device, size);
if (FAILED(hr))
goto done;
vb_pos = device->vertex_buffer_pos;
align = vb_pos % stride;
if (align) align = stride - align;
if (vb_pos + size + align > device->vertex_buffer_size)
vb_pos = 0;
else
vb_pos += align;
wined3d_box.left = vb_pos;
wined3d_box.right = vb_pos + size;
vb = wined3d_buffer_get_resource(device->vertex_buffer);
if (FAILED(hr = wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
memcpy(wined3d_map_desc.data, vertices, size);
wined3d_resource_unmap(vb, 0);
device->vertex_buffer_pos = vb_pos + size;
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
if (FAILED(hr))
goto done;
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vertex_count);
done:
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawPrimitive_FPUSetup(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices,
DWORD vertex_count, DWORD flags)
{
return d3d_device7_DrawPrimitive(iface, primitive_type, fvf, vertices, vertex_count, flags);
}
static HRESULT WINAPI d3d_device7_DrawPrimitive_FPUPreserve(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices,
DWORD vertex_count, DWORD flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawPrimitive(iface, primitive_type, fvf, vertices, vertex_count, flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static void setup_lighting(const struct d3d_device *device, DWORD fvf, DWORD flags)
{
BOOL enable = TRUE;
/* Ignore the D3DFVF_XYZRHW case here, wined3d takes care of that */
if (!device->material || !(fvf & D3DFVF_NORMAL) || (flags & D3DDP_DONOTLIGHT))
enable = FALSE;
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_LIGHTING, enable);
}
static HRESULT WINAPI d3d_device3_DrawPrimitive(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count,
DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, flags %#x.\n",
iface, primitive_type, fvf, vertices, vertex_count, flags);
setup_lighting(device, fvf, flags);
return IDirect3DDevice7_DrawPrimitive(&device->IDirect3DDevice7_iface,
primitive_type, fvf, vertices, vertex_count, flags);
}
static HRESULT WINAPI d3d_device2_DrawPrimitive(IDirect3DDevice2 *iface,
D3DPRIMITIVETYPE primitive_type, D3DVERTEXTYPE vertex_type, void *vertices,
DWORD vertex_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
DWORD fvf;
TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, flags %#x.\n",
iface, primitive_type, vertex_type, vertices, vertex_count, flags);
switch (vertex_type)
{
case D3DVT_VERTEX: fvf = D3DFVF_VERTEX; break;
case D3DVT_LVERTEX: fvf = D3DFVF_LVERTEX; break;
case D3DVT_TLVERTEX: fvf = D3DFVF_TLVERTEX; break;
default:
FIXME("Unhandled vertex type %#x.\n", vertex_type);
return DDERR_INVALIDPARAMS; /* Should never happen */
}
return d3d_device3_DrawPrimitive(&device->IDirect3DDevice3_iface,
primitive_type, fvf, vertices, vertex_count, flags);
}
/*****************************************************************************
* IDirect3DDevice7::DrawIndexedPrimitive
*
* Draws vertices from an application-provided pointer, based on the index
* numbers in a WORD array.
*
* Version 2, 3 and 7. The version 7 thunk translates the vertex type into
* an FVF format for D3D7
*
* Params:
* PrimitiveType: The primitive type to draw
* VertexType: The FVF vertex description
* Vertices: Pointer to the vertex array
* VertexCount: ?
* Indices: Pointer to the index array
* IndexCount: Number of indices = Number of vertices to draw
* Flags: As usual, some flags
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Vertices or Indices is NULL
* For details, see IWineD3DDevice::DrawIndexedPrimitiveUP
*
*****************************************************************************/
/* The caller is responsible for wined3d locking */
static HRESULT d3d_device_prepare_index_buffer(struct d3d_device *device, UINT min_size)
{
HRESULT hr;
if (device->index_buffer_size < min_size || !device->index_buffer)
{
UINT size = max(device->index_buffer_size * 2, min_size);
struct wined3d_buffer *buffer;
TRACE("Growing index buffer to %u bytes\n", size);
hr = wined3d_buffer_create_ib(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer);
if (FAILED(hr))
{
ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device, hr);
return hr;
}
if (device->index_buffer)
wined3d_buffer_decref(device->index_buffer);
device->index_buffer = buffer;
device->index_buffer_size = size;
device->index_buffer_pos = 0;
}
return D3D_OK;
}
static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count,
WORD *indices, DWORD index_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
UINT stride = get_flexible_vertex_size(fvf);
UINT vtx_size = stride * vertex_count, idx_size = index_count * sizeof(*indices);
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
struct wined3d_resource *ib, *vb;
UINT vb_pos, ib_pos, align;
TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, "
"indices %p, index_count %u, flags %#x.\n",
iface, primitive_type, fvf, vertices, vertex_count, indices, index_count, flags);
if (!vertex_count || !index_count)
{
WARN("0 vertex or index count.\n");
return D3D_OK;
}
/* Set the D3DDevice's FVF */
wined3d_mutex_lock();
hr = d3d_device_prepare_vertex_buffer(device, vtx_size);
if (FAILED(hr))
goto done;
vb_pos = device->vertex_buffer_pos;
align = vb_pos % stride;
if (align) align = stride - align;
if (vb_pos + vtx_size + align > device->vertex_buffer_size)
vb_pos = 0;
else
vb_pos += align;
wined3d_box.left = vb_pos;
wined3d_box.right = vb_pos + vtx_size;
vb = wined3d_buffer_get_resource(device->vertex_buffer);
if (FAILED(hr = wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
memcpy(wined3d_map_desc.data, vertices, vtx_size);
wined3d_resource_unmap(vb, 0);
device->vertex_buffer_pos = vb_pos + vtx_size;
hr = d3d_device_prepare_index_buffer(device, idx_size);
if (FAILED(hr))
goto done;
ib_pos = device->index_buffer_pos;
if (device->index_buffer_size - idx_size < ib_pos)
ib_pos = 0;
wined3d_box.left = ib_pos;
wined3d_box.right = ib_pos + idx_size;
ib = wined3d_buffer_get_resource(device->index_buffer);
if (FAILED(hr = wined3d_resource_map(ib, 0, &wined3d_map_desc, &wined3d_box,
ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
memcpy(wined3d_map_desc.data, indices, idx_size);
wined3d_resource_unmap(ib, 0);
device->index_buffer_pos = ib_pos + idx_size;
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
if (FAILED(hr))
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / stride);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(*indices), index_count);
done:
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitive_FPUSetup(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count,
WORD *indices, DWORD index_count, DWORD flags)
{
return d3d_device7_DrawIndexedPrimitive(iface, primitive_type, fvf,
vertices, vertex_count, indices, index_count, flags);
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitive_FPUPreserve(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count,
WORD *indices, DWORD index_count, DWORD flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawIndexedPrimitive(iface, primitive_type, fvf,
vertices, vertex_count, indices, index_count, flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_DrawIndexedPrimitive(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, void *vertices, DWORD vertex_count,
WORD *indices, DWORD index_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, primitive_type %#x, fvf %#x, vertices %p, vertex_count %u, "
"indices %p, index_count %u, flags %#x.\n",
iface, primitive_type, fvf, vertices, vertex_count, indices, index_count, flags);
setup_lighting(device, fvf, flags);
return IDirect3DDevice7_DrawIndexedPrimitive(&device->IDirect3DDevice7_iface,
primitive_type, fvf, vertices, vertex_count, indices, index_count, flags);
}
static HRESULT WINAPI d3d_device2_DrawIndexedPrimitive(IDirect3DDevice2 *iface,
D3DPRIMITIVETYPE primitive_type, D3DVERTEXTYPE vertex_type, void *vertices,
DWORD vertex_count, WORD *indices, DWORD index_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
DWORD fvf;
TRACE("iface %p, primitive_type %#x, vertex_type %#x, vertices %p, vertex_count %u, "
"indices %p, index_count %u, flags %#x.\n",
iface, primitive_type, vertex_type, vertices, vertex_count, indices, index_count, flags);
switch (vertex_type)
{
case D3DVT_VERTEX: fvf = D3DFVF_VERTEX; break;
case D3DVT_LVERTEX: fvf = D3DFVF_LVERTEX; break;
case D3DVT_TLVERTEX: fvf = D3DFVF_TLVERTEX; break;
default:
ERR("Unhandled vertex type %#x.\n", vertex_type);
return DDERR_INVALIDPARAMS; /* Should never happen */
}
return d3d_device3_DrawIndexedPrimitive(&device->IDirect3DDevice3_iface,
primitive_type, fvf, vertices, vertex_count, indices, index_count, flags);
}
/*****************************************************************************
* IDirect3DDevice3::End
*
* Ends a draw begun with IDirect3DDevice3::Begin or
* IDirect3DDevice::BeginIndexed. The vertices specified with
* IDirect3DDevice::Vertex or IDirect3DDevice::Index are drawn using
* the IDirect3DDevice3::DrawPrimitive method. So far only
* non-indexed mode is supported
*
* Version 2 and 3
*
* Params:
* Flags: Some flags, as usual. Don't know which are defined
*
* Returns:
* The return value of IDirect3DDevice3::DrawPrimitive
*
*****************************************************************************/
static HRESULT WINAPI d3d_device3_End(IDirect3DDevice3 *iface, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, flags %#x.\n", iface, flags);
return d3d_device3_DrawPrimitive(&device->IDirect3DDevice3_iface, device->primitive_type,
device->vertex_type, device->sysmem_vertex_buffer, device->nb_vertices, device->render_flags);
}
static HRESULT WINAPI d3d_device2_End(IDirect3DDevice2 *iface, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, flags %#x.\n", iface, flags);
return d3d_device3_End(&device->IDirect3DDevice3_iface, flags);
}
/*****************************************************************************
* IDirect3DDevice7::SetClipStatus
*
* Sets the clip status. This defines things as clipping conditions and
* the extents of the clipping region.
*
* Version 2, 3 and 7
*
* Params:
* ClipStatus:
*
* Returns:
* D3D_OK because it's a stub
* (DDERR_INVALIDPARAMS if ClipStatus == NULL)
*
*****************************************************************************/
static HRESULT WINAPI d3d_device7_SetClipStatus(IDirect3DDevice7 *iface, D3DCLIPSTATUS *clip_status)
{
FIXME("iface %p, clip_status %p stub!\n", iface, clip_status);
/* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them
* Perhaps this needs a new data type and an additional IWineD3DDevice method
*/
/* return IWineD3DDevice_SetClipStatus(This->wineD3DDevice, ClipStatus);*/
return D3D_OK;
}
static HRESULT WINAPI d3d_device3_SetClipStatus(IDirect3DDevice3 *iface, D3DCLIPSTATUS *clip_status)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, clip_status %p.\n", iface, clip_status);
return IDirect3DDevice7_SetClipStatus(&device->IDirect3DDevice7_iface, clip_status);
}
static HRESULT WINAPI d3d_device2_SetClipStatus(IDirect3DDevice2 *iface, D3DCLIPSTATUS *clip_status)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, clip_status %p.\n", iface, clip_status);
return IDirect3DDevice7_SetClipStatus(&device->IDirect3DDevice7_iface, clip_status);
}
/*****************************************************************************
* IDirect3DDevice7::GetClipStatus
*
* Returns the clip status
*
* Params:
* ClipStatus: Address to write the clip status to
*
* Returns:
* D3D_OK because it's a stub
*
*****************************************************************************/
static HRESULT WINAPI d3d_device7_GetClipStatus(IDirect3DDevice7 *iface, D3DCLIPSTATUS *clip_status)
{
FIXME("iface %p, clip_status %p stub!\n", iface, clip_status);
/* D3DCLIPSTATUS and WINED3DCLIPSTATUS are different. I don't know how to convert them */
/* return IWineD3DDevice_GetClipStatus(This->wineD3DDevice, ClipStatus);*/
return D3D_OK;
}
static HRESULT WINAPI d3d_device3_GetClipStatus(IDirect3DDevice3 *iface, D3DCLIPSTATUS *clip_status)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, clip_status %p.\n", iface, clip_status);
return IDirect3DDevice7_GetClipStatus(&device->IDirect3DDevice7_iface, clip_status);
}
static HRESULT WINAPI d3d_device2_GetClipStatus(IDirect3DDevice2 *iface, D3DCLIPSTATUS *clip_status)
{
struct d3d_device *device = impl_from_IDirect3DDevice2(iface);
TRACE("iface %p, clip_status %p.\n", iface, clip_status);
return IDirect3DDevice7_GetClipStatus(&device->IDirect3DDevice7_iface, clip_status);
}
/*****************************************************************************
* IDirect3DDevice::DrawPrimitiveStrided
*
* Draws vertices described by a D3DDRAWPRIMITIVESTRIDEDDATA structure.
*
* Version 3 and 7
*
* Params:
* PrimitiveType: The primitive type to draw
* VertexType: The FVF description of the vertices to draw (for the stride??)
* D3DDrawPrimStrideData: A D3DDRAWPRIMITIVESTRIDEDDATA structure describing
* the vertex data locations
* VertexCount: The number of vertices to draw
* Flags: Some flags
*
* Returns:
* D3D_OK, because it's a stub
* (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
* (For details, see IWineD3DDevice::DrawPrimitiveStrided)
*
*****************************************************************************/
static void pack_strided_data(BYTE *dst, DWORD count, const D3DDRAWPRIMITIVESTRIDEDDATA *src, DWORD fvf)
{
DWORD i, tex, offset;
for (i = 0; i < count; i++)
{
/* The contents of the strided data are determined by the fvf,
* not by the members set in src. So it's valid
* to have diffuse.lpvData set to 0xdeadbeef if the diffuse flag is
* not set in the fvf. */
if (fvf & D3DFVF_POSITION_MASK)
{
offset = i * src->position.dwStride;
if (fvf & D3DFVF_XYZRHW)
{
memcpy(dst, ((BYTE *)src->position.lpvData) + offset, 4 * sizeof(float));
dst += 4 * sizeof(float);
}
else
{
memcpy(dst, ((BYTE *)src->position.lpvData) + offset, 3 * sizeof(float));
dst += 3 * sizeof(float);
}
}
if (fvf & D3DFVF_NORMAL)
{
offset = i * src->normal.dwStride;
memcpy(dst, ((BYTE *)src->normal.lpvData) + offset, 3 * sizeof(float));
dst += 3 * sizeof(float);
}
if (fvf & D3DFVF_DIFFUSE)
{
offset = i * src->diffuse.dwStride;
memcpy(dst, ((BYTE *)src->diffuse.lpvData) + offset, sizeof(DWORD));
dst += sizeof(DWORD);
}
if (fvf & D3DFVF_SPECULAR)
{
offset = i * src->specular.dwStride;
memcpy(dst, ((BYTE *)src->specular.lpvData) + offset, sizeof(DWORD));
dst += sizeof(DWORD);
}
for (tex = 0; tex < GET_TEXCOUNT_FROM_FVF(fvf); ++tex)
{
DWORD attrib_count = GET_TEXCOORD_SIZE_FROM_FVF(fvf, tex);
offset = i * src->textureCoords[tex].dwStride;
memcpy(dst, ((BYTE *)src->textureCoords[tex].lpvData) + offset, attrib_count * sizeof(float));
dst += attrib_count * sizeof(float);
}
}
}
static HRESULT d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, D3DPRIMITIVETYPE primitive_type,
DWORD fvf, D3DDRAWPRIMITIVESTRIDEDDATA *strided_data, DWORD vertex_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
UINT dst_stride = get_flexible_vertex_size(fvf);
UINT dst_size = dst_stride * vertex_count;
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
struct wined3d_resource *vb;
UINT vb_pos, align;
TRACE("iface %p, primitive_type %#x, fvf %#x, strided_data %p, vertex_count %u, flags %#x.\n",
iface, primitive_type, fvf, strided_data, vertex_count, flags);
if (!vertex_count)
{
WARN("0 vertex count.\n");
return D3D_OK;
}
wined3d_mutex_lock();
hr = d3d_device_prepare_vertex_buffer(device, dst_size);
if (FAILED(hr))
goto done;
vb_pos = device->vertex_buffer_pos;
align = vb_pos % dst_stride;
if (align) align = dst_stride - align;
if (vb_pos + dst_size + align > device->vertex_buffer_size)
vb_pos = 0;
else
vb_pos += align;
wined3d_box.left = vb_pos;
wined3d_box.right = vb_pos + dst_size;
vb = wined3d_buffer_get_resource(device->vertex_buffer);
if (FAILED(hr = wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
pack_strided_data(wined3d_map_desc.data, vertex_count, strided_data, fvf);
wined3d_resource_unmap(vb, 0);
device->vertex_buffer_pos = vb_pos + dst_size;
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, dst_stride);
if (FAILED(hr))
goto done;
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / dst_stride, vertex_count);
done:
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawPrimitiveStrided_FPUSetup(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, DWORD Flags)
{
return d3d_device7_DrawPrimitiveStrided(iface, PrimitiveType,
VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
}
static HRESULT WINAPI d3d_device7_DrawPrimitiveStrided_FPUPreserve(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, DWORD Flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawPrimitiveStrided(iface, PrimitiveType,
VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_DrawPrimitiveStrided(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, DWORD Flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, flags %#x.\n",
iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
setup_lighting(device, VertexType, Flags);
return IDirect3DDevice7_DrawPrimitiveStrided(&device->IDirect3DDevice7_iface,
PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Flags);
}
/*****************************************************************************
* IDirect3DDevice7::DrawIndexedPrimitiveStrided
*
* Draws primitives specified by strided data locations based on indices
*
* Version 3 and 7
*
* Params:
* PrimitiveType:
*
* Returns:
* D3D_OK, because it's a stub
* (DDERR_INVALIDPARAMS if D3DDrawPrimStrideData is NULL)
* (DDERR_INVALIDPARAMS if Indices is NULL)
* (For more details, see IWineD3DDevice::DrawIndexedPrimitiveStrided)
*
*****************************************************************************/
static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, DWORD fvf, D3DDRAWPRIMITIVESTRIDEDDATA *strided_data,
DWORD vertex_count, WORD *indices, DWORD index_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
UINT vtx_dst_stride = get_flexible_vertex_size(fvf);
UINT vtx_dst_size = vertex_count * vtx_dst_stride;
UINT idx_size = index_count * sizeof(WORD);
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
struct wined3d_resource *ib, *vb;
UINT vb_pos, align;
UINT ib_pos;
HRESULT hr;
TRACE("iface %p, primitive_type %#x, fvf %#x, strided_data %p, "
"vertex_count %u, indices %p, index_count %u, flags %#x.\n",
iface, primitive_type, fvf, strided_data, vertex_count, indices, index_count, flags);
if (!vertex_count || !index_count)
{
WARN("0 vertex or index count.\n");
return D3D_OK;
}
wined3d_mutex_lock();
hr = d3d_device_prepare_vertex_buffer(device, vtx_dst_size);
if (FAILED(hr))
goto done;
vb_pos = device->vertex_buffer_pos;
align = vb_pos % vtx_dst_stride;
if (align) align = vtx_dst_stride - align;
if (vb_pos + vtx_dst_size + align > device->vertex_buffer_size)
vb_pos = 0;
else
vb_pos += align;
wined3d_box.left = vb_pos;
wined3d_box.right = vb_pos + vtx_dst_size;
vb = wined3d_buffer_get_resource(device->vertex_buffer);
if (FAILED(hr = wined3d_resource_map(vb, 0, &wined3d_map_desc, &wined3d_box,
vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
pack_strided_data(wined3d_map_desc.data, vertex_count, strided_data, fvf);
wined3d_resource_unmap(vb, 0);
device->vertex_buffer_pos = vb_pos + vtx_dst_size;
hr = d3d_device_prepare_index_buffer(device, idx_size);
if (FAILED(hr))
goto done;
ib_pos = device->index_buffer_pos;
if (device->index_buffer_size - idx_size < ib_pos)
ib_pos = 0;
wined3d_box.left = ib_pos;
wined3d_box.right = ib_pos + idx_size;
ib = wined3d_buffer_get_resource(device->index_buffer);
if (FAILED(hr = wined3d_resource_map(ib, 0, &wined3d_map_desc, &wined3d_box,
ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
goto done;
memcpy(wined3d_map_desc.data, indices, idx_size);
wined3d_resource_unmap(ib, 0);
device->index_buffer_pos = ib_pos + idx_size;
hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, vtx_dst_stride);
if (FAILED(hr))
goto done;
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vtx_dst_stride);
wined3d_device_set_vertex_declaration(device->wined3d_device, ddraw_find_decl(device->ddraw, fvf));
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
done:
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitiveStrided_FPUSetup(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount,
WORD *Indices, DWORD IndexCount, DWORD Flags)
{
return d3d_device7_DrawIndexedPrimitiveStrided(iface, PrimitiveType, VertexType,
D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitiveStrided_FPUPreserve(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount,
WORD *Indices, DWORD IndexCount, DWORD Flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawIndexedPrimitiveStrided(iface, PrimitiveType, VertexType,
D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_DrawIndexedPrimitiveStrided(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE PrimitiveType, DWORD VertexType,
D3DDRAWPRIMITIVESTRIDEDDATA *D3DDrawPrimStrideData, DWORD VertexCount, WORD *Indices,
DWORD IndexCount, DWORD Flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, primitive_type %#x, FVF %#x, strided_data %p, vertex_count %u, indices %p, index_count %u, flags %#x.\n",
iface, PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
setup_lighting(device, VertexType, Flags);
return IDirect3DDevice7_DrawIndexedPrimitiveStrided(&device->IDirect3DDevice7_iface,
PrimitiveType, VertexType, D3DDrawPrimStrideData, VertexCount, Indices, IndexCount, Flags);
}
/*****************************************************************************
* IDirect3DDevice7::DrawPrimitiveVB
*
* Draws primitives from a vertex buffer to the screen.
*
* Version 3 and 7
*
* Params:
* PrimitiveType: Type of primitive to be rendered.
* D3DVertexBuf: Source Vertex Buffer
* StartVertex: Index of the first vertex from the buffer to be rendered
* NumVertices: Number of vertices to be rendered
* Flags: Can be D3DDP_WAIT to wait until rendering has finished
*
* Return values
* D3D_OK on success
* DDERR_INVALIDPARAMS if D3DVertexBuf is NULL
*
*****************************************************************************/
static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVETYPE primitive_type,
IDirect3DVertexBuffer7 *vb, DWORD start_vertex, DWORD vertex_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb_impl = unsafe_impl_from_IDirect3DVertexBuffer7(vb);
HRESULT hr;
DWORD stride;
TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
iface, primitive_type, vb, start_vertex, vertex_count, flags);
if (!vertex_count)
{
WARN("0 vertex count.\n");
return D3D_OK;
}
stride = get_flexible_vertex_size(vb_impl->fvf);
wined3d_mutex_lock();
wined3d_device_set_vertex_declaration(device->wined3d_device, vb_impl->wined3d_declaration);
if (FAILED(hr = wined3d_device_set_stream_source(device->wined3d_device,
0, vb_impl->wined3d_buffer, 0, stride)))
{
WARN("Failed to set stream source, hr %#x.\n", hr);
wined3d_mutex_unlock();
return hr;
}
/* Now draw the primitives */
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawPrimitiveVB_FPUSetup(IDirect3DDevice7 *iface, D3DPRIMITIVETYPE PrimitiveType,
IDirect3DVertexBuffer7 *D3DVertexBuf, DWORD StartVertex, DWORD NumVertices, DWORD Flags)
{
return d3d_device7_DrawPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
}
static HRESULT WINAPI d3d_device7_DrawPrimitiveVB_FPUPreserve(IDirect3DDevice7 *iface, D3DPRIMITIVETYPE PrimitiveType,
IDirect3DVertexBuffer7 *D3DVertexBuf, DWORD StartVertex, DWORD NumVertices, DWORD Flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawPrimitiveVB(iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_DrawPrimitiveVB(IDirect3DDevice3 *iface, D3DPRIMITIVETYPE PrimitiveType,
IDirect3DVertexBuffer *D3DVertexBuf, DWORD StartVertex, DWORD NumVertices, DWORD Flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct d3d_vertex_buffer *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf);
TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, vertex_count %u, flags %#x.\n",
iface, PrimitiveType, D3DVertexBuf, StartVertex, NumVertices, Flags);
setup_lighting(device, vb->fvf, Flags);
return IDirect3DDevice7_DrawPrimitiveVB(&device->IDirect3DDevice7_iface,
PrimitiveType, &vb->IDirect3DVertexBuffer7_iface, StartVertex, NumVertices, Flags);
}
/*****************************************************************************
* IDirect3DDevice7::DrawIndexedPrimitiveVB
*
* Draws primitives from a vertex buffer to the screen
*
* Params:
* PrimitiveType: Type of primitive to be rendered.
* D3DVertexBuf: Source Vertex Buffer
* StartVertex: Index of the first vertex from the buffer to be rendered
* NumVertices: Number of vertices to be rendered
* Indices: Array of DWORDs used to index into the Vertices
* IndexCount: Number of indices in Indices
* Flags: Can be D3DDP_WAIT to wait until rendering has finished
*
* Return values
*
*****************************************************************************/
static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE primitive_type, IDirect3DVertexBuffer7 *vb,
DWORD start_vertex, DWORD vertex_count, WORD *indices, DWORD index_count, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb_impl = unsafe_impl_from_IDirect3DVertexBuffer7(vb);
DWORD stride = get_flexible_vertex_size(vb_impl->fvf);
struct wined3d_map_desc wined3d_map_desc;
struct wined3d_box wined3d_box = {0};
struct wined3d_resource *ib;
HRESULT hr;
UINT ib_pos;
TRACE("iface %p, primitive_type %#x, vb %p, start_vertex %u, "
"vertex_count %u, indices %p, index_count %u, flags %#x.\n",
iface, primitive_type, vb, start_vertex, vertex_count, indices, index_count, flags);
if (!vertex_count || !index_count)
{
WARN("0 vertex or index count.\n");
return D3D_OK;
}
/* Steps:
* 1) Upload the indices to the index buffer
* 2) Set the index source
* 3) Set the Vertex Buffer as the Stream source
* 4) Call IWineD3DDevice::DrawIndexedPrimitive
*/
wined3d_mutex_lock();
wined3d_device_set_vertex_declaration(device->wined3d_device, vb_impl->wined3d_declaration);
hr = d3d_device_prepare_index_buffer(device, index_count * sizeof(WORD));
if (FAILED(hr))
{
wined3d_mutex_unlock();
return hr;
}
ib_pos = device->index_buffer_pos;
if (device->index_buffer_size - index_count * sizeof(WORD) < ib_pos)
ib_pos = 0;
/* Copy the index stream into the index buffer. A new IWineD3DDevice
* method could be created which takes an user pointer containing the
* indices or a SetData-Method for the index buffer, which overrides the
* index buffer data with our pointer. */
wined3d_box.left = ib_pos;
wined3d_box.right = ib_pos + index_count * sizeof(WORD);
ib = wined3d_buffer_get_resource(device->index_buffer);
if (FAILED(hr = wined3d_resource_map(ib, 0, &wined3d_map_desc, &wined3d_box,
ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD)))
{
ERR("Failed to map buffer, hr %#x.\n", hr);
wined3d_mutex_unlock();
return hr;
}
memcpy(wined3d_map_desc.data, indices, index_count * sizeof(WORD));
wined3d_resource_unmap(ib, 0);
device->index_buffer_pos = ib_pos + index_count * sizeof(WORD);
/* Set the index stream */
wined3d_device_set_base_vertex_index(device->wined3d_device, start_vertex);
wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer, WINED3DFMT_R16_UINT, 0);
/* Set the vertex stream source */
if (FAILED(hr = wined3d_device_set_stream_source(device->wined3d_device,
0, vb_impl->wined3d_buffer, 0, stride)))
{
ERR("(%p) IDirect3DDevice::SetStreamSource failed with hr = %08x\n", device, hr);
wined3d_mutex_unlock();
return hr;
}
wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitiveVB_FPUSetup(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer7 *D3DVertexBuf,
DWORD StartVertex, DWORD NumVertices, WORD *Indices, DWORD IndexCount, DWORD Flags)
{
return d3d_device7_DrawIndexedPrimitiveVB(iface, PrimitiveType,
D3DVertexBuf, StartVertex, NumVertices, Indices, IndexCount, Flags);
}
static HRESULT WINAPI d3d_device7_DrawIndexedPrimitiveVB_FPUPreserve(IDirect3DDevice7 *iface,
D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer7 *D3DVertexBuf,
DWORD StartVertex, DWORD NumVertices, WORD *Indices, DWORD IndexCount, DWORD Flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DrawIndexedPrimitiveVB(iface, PrimitiveType,
D3DVertexBuf, StartVertex, NumVertices, Indices, IndexCount, Flags);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_DrawIndexedPrimitiveVB(IDirect3DDevice3 *iface,
D3DPRIMITIVETYPE PrimitiveType, IDirect3DVertexBuffer *D3DVertexBuf, WORD *Indices,
DWORD IndexCount, DWORD Flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct d3d_vertex_buffer *vb = unsafe_impl_from_IDirect3DVertexBuffer(D3DVertexBuf);
TRACE("iface %p, primitive_type %#x, vb %p, indices %p, index_count %u, flags %#x.\n",
iface, PrimitiveType, D3DVertexBuf, Indices, IndexCount, Flags);
setup_lighting(device, vb->fvf, Flags);
return IDirect3DDevice7_DrawIndexedPrimitiveVB(&device->IDirect3DDevice7_iface, PrimitiveType,
&vb->IDirect3DVertexBuffer7_iface, 0, IndexCount, Indices, IndexCount, Flags);
}
/*****************************************************************************
* IDirect3DDevice7::ComputeSphereVisibility
*
* Calculates the visibility of spheres in the current viewport. The spheres
* are passed in the Centers and Radii arrays, the results are passed back
* in the ReturnValues array. Return values are either completely visible,
* partially visible or completely invisible.
* The return value consists of a combination of D3DCLIP_* flags, or is
* 0 if the sphere is completely visible (according to the SDK, not checked)
*
* Version 3 and 7
*
* Params:
* Centers: Array containing the sphere centers
* Radii: Array containing the sphere radii
* NumSpheres: The number of centers and radii in the arrays
* Flags: Some flags
* ReturnValues: Array to write the results to
*
* Returns:
* D3D_OK
* (DDERR_INVALIDPARAMS if Centers, Radii or ReturnValues are NULL)
* (D3DERR_INVALIDMATRIX if the combined world, view and proj matrix
* is singular)
*
*****************************************************************************/
static DWORD in_plane(UINT plane, D3DVECTOR normal, D3DVALUE origin_plane, D3DVECTOR center, D3DVALUE radius)
{
float distance, norm;
norm = sqrtf(normal.u1.x * normal.u1.x + normal.u2.y * normal.u2.y + normal.u3.z * normal.u3.z);
distance = ( origin_plane + normal.u1.x * center.u1.x + normal.u2.y * center.u2.y + normal.u3.z * center.u3.z ) / norm;
if ( fabs( distance ) < radius ) return D3DSTATUS_CLIPUNIONLEFT << plane;
if ( distance < -radius ) return (D3DSTATUS_CLIPUNIONLEFT | D3DSTATUS_CLIPINTERSECTIONLEFT) << plane;
return 0;
}
static HRESULT WINAPI d3d_device7_ComputeSphereVisibility(IDirect3DDevice7 *iface,
D3DVECTOR *centers, D3DVALUE *radii, DWORD sphere_count, DWORD flags, DWORD *return_values)
{
D3DMATRIX m, temp;
D3DVALUE origin_plane[6];
D3DVECTOR vec[6];
HRESULT hr;
UINT i, j;
TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
iface, centers, radii, sphere_count, flags, return_values);
hr = d3d_device7_GetTransform(iface, D3DTRANSFORMSTATE_WORLD, &m);
if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
hr = d3d_device7_GetTransform(iface, D3DTRANSFORMSTATE_VIEW, &temp);
if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
multiply_matrix(&m, &temp, &m);
hr = d3d_device7_GetTransform(iface, D3DTRANSFORMSTATE_PROJECTION, &temp);
if ( hr != DD_OK ) return DDERR_INVALIDPARAMS;
multiply_matrix(&m, &temp, &m);
/* Left plane */
vec[0].u1.x = m._14 + m._11;
vec[0].u2.y = m._24 + m._21;
vec[0].u3.z = m._34 + m._31;
origin_plane[0] = m._44 + m._41;
/* Right plane */
vec[1].u1.x = m._14 - m._11;
vec[1].u2.y = m._24 - m._21;
vec[1].u3.z = m._34 - m._31;
origin_plane[1] = m._44 - m._41;
/* Top plane */
vec[2].u1.x = m._14 - m._12;
vec[2].u2.y = m._24 - m._22;
vec[2].u3.z = m._34 - m._32;
origin_plane[2] = m._44 - m._42;
/* Bottom plane */
vec[3].u1.x = m._14 + m._12;
vec[3].u2.y = m._24 + m._22;
vec[3].u3.z = m._34 + m._32;
origin_plane[3] = m._44 + m._42;
/* Front plane */
vec[4].u1.x = m._13;
vec[4].u2.y = m._23;
vec[4].u3.z = m._33;
origin_plane[4] = m._43;
/* Back plane*/
vec[5].u1.x = m._14 - m._13;
vec[5].u2.y = m._24 - m._23;
vec[5].u3.z = m._34 - m._33;
origin_plane[5] = m._44 - m._43;
for (i = 0; i < sphere_count; ++i)
{
return_values[i] = 0;
for (j = 0; j < 6; ++j)
return_values[i] |= in_plane(j, vec[j], origin_plane[j], centers[i], radii[i]);
}
return D3D_OK;
}
static HRESULT WINAPI d3d_device3_ComputeSphereVisibility(IDirect3DDevice3 *iface,
D3DVECTOR *centers, D3DVALUE *radii, DWORD sphere_count, DWORD flags, DWORD *return_values)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, centers %p, radii %p, sphere_count %u, flags %#x, return_values %p.\n",
iface, centers, radii, sphere_count, flags, return_values);
return IDirect3DDevice7_ComputeSphereVisibility(&device->IDirect3DDevice7_iface,
centers, radii, sphere_count, flags, return_values);
}
/*****************************************************************************
* IDirect3DDevice7::GetTexture
*
* Returns the texture interface handle assigned to a texture stage.
* The returned texture is AddRefed. This is taken from old ddraw,
* not checked in Windows.
*
* Version 3 and 7
*
* Params:
* Stage: Texture stage to read the texture from
* Texture: Address to store the interface pointer at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Texture is NULL
* For details, see IWineD3DDevice::GetTexture
*
*****************************************************************************/
static HRESULT d3d_device7_GetTexture(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 **texture)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_texture *wined3d_texture;
struct ddraw_texture *ddraw_texture;
TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
if (!texture)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if (!(wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
{
*texture = NULL;
wined3d_mutex_unlock();
return D3D_OK;
}
ddraw_texture = wined3d_texture_get_parent(wined3d_texture);
*texture = &ddraw_texture->root->IDirectDrawSurface7_iface;
IDirectDrawSurface7_AddRef(*texture);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_GetTexture_FPUSetup(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 **Texture)
{
return d3d_device7_GetTexture(iface, stage, Texture);
}
static HRESULT WINAPI d3d_device7_GetTexture_FPUPreserve(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 **Texture)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetTexture(iface, stage, Texture);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_GetTexture(IDirect3DDevice3 *iface, DWORD stage, IDirect3DTexture2 **Texture2)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct ddraw_surface *ret_val_impl;
HRESULT ret;
IDirectDrawSurface7 *ret_val;
TRACE("iface %p, stage %u, texture %p.\n", iface, stage, Texture2);
ret = IDirect3DDevice7_GetTexture(&device->IDirect3DDevice7_iface, stage, &ret_val);
ret_val_impl = unsafe_impl_from_IDirectDrawSurface7(ret_val);
*Texture2 = ret_val_impl ? &ret_val_impl->IDirect3DTexture2_iface : NULL;
TRACE("Returning texture %p.\n", *Texture2);
return ret;
}
/*****************************************************************************
* IDirect3DDevice7::SetTexture
*
* Assigns a texture to a texture stage. Is the texture AddRef-ed?
*
* Version 3 and 7
*
* Params:
* Stage: The stage to assign the texture to
* Texture: Interface pointer to the texture surface
*
* Returns
* D3D_OK on success
* For details, see IWineD3DDevice::SetTexture
*
*****************************************************************************/
static HRESULT d3d_device7_SetTexture(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 *texture)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct ddraw_surface *surf = unsafe_impl_from_IDirectDrawSurface7(texture);
struct wined3d_texture *wined3d_texture = NULL;
HRESULT hr;
TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
if (surf && (surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE))
wined3d_texture = surf->wined3d_texture;
wined3d_mutex_lock();
hr = wined3d_device_set_texture(device->wined3d_device, stage, wined3d_texture);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_SetTexture_FPUSetup(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 *texture)
{
return d3d_device7_SetTexture(iface, stage, texture);
}
static HRESULT WINAPI d3d_device7_SetTexture_FPUPreserve(IDirect3DDevice7 *iface,
DWORD stage, IDirectDrawSurface7 *texture)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetTexture(iface, stage, texture);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_SetTexture(IDirect3DDevice3 *iface,
DWORD stage, IDirect3DTexture2 *texture)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
struct ddraw_surface *tex = unsafe_impl_from_IDirect3DTexture2(texture);
DWORD texmapblend;
HRESULT hr;
TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
wined3d_mutex_lock();
if (device->legacyTextureBlending)
IDirect3DDevice3_GetRenderState(iface, D3DRENDERSTATE_TEXTUREMAPBLEND, &texmapblend);
hr = IDirect3DDevice7_SetTexture(&device->IDirect3DDevice7_iface, stage, &tex->IDirectDrawSurface7_iface);
if (device->legacyTextureBlending && texmapblend == D3DTBLEND_MODULATE)
{
/* This fixup is required by the way D3DTBLEND_MODULATE maps to texture stage states.
See d3d_device3_SetRenderState() for details. */
struct wined3d_texture *tex = NULL;
BOOL tex_alpha = FALSE;
DDPIXELFORMAT ddfmt;
if ((tex = wined3d_device_get_texture(device->wined3d_device, 0)))
{
struct wined3d_resource_desc desc;
wined3d_resource_get_desc(wined3d_texture_get_resource(tex), &desc);
ddfmt.dwSize = sizeof(ddfmt);
ddrawformat_from_wined3dformat(&ddfmt, desc.format);
if (ddfmt.u5.dwRGBAlphaBitMask)
tex_alpha = TRUE;
}
/* Args 1 and 2 are already set to WINED3DTA_TEXTURE/WINED3DTA_CURRENT in case of D3DTBLEND_MODULATE */
if (tex_alpha)
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG1);
else
wined3d_device_set_texture_stage_state(device->wined3d_device,
0, WINED3D_TSS_ALPHA_OP, WINED3D_TOP_SELECT_ARG2);
}
wined3d_mutex_unlock();
return hr;
}
static const struct tss_lookup
{
BOOL sampler_state;
union
{
enum wined3d_texture_stage_state texture_state;
enum wined3d_sampler_state sampler_state;
} u;
}
tss_lookup[] =
{
{FALSE, {WINED3D_TSS_INVALID}}, /* 0, unused */
{FALSE, {WINED3D_TSS_COLOR_OP}}, /* 1, D3DTSS_COLOROP */
{FALSE, {WINED3D_TSS_COLOR_ARG1}}, /* 2, D3DTSS_COLORARG1 */
{FALSE, {WINED3D_TSS_COLOR_ARG2}}, /* 3, D3DTSS_COLORARG2 */
{FALSE, {WINED3D_TSS_ALPHA_OP}}, /* 4, D3DTSS_ALPHAOP */
{FALSE, {WINED3D_TSS_ALPHA_ARG1}}, /* 5, D3DTSS_ALPHAARG1 */
{FALSE, {WINED3D_TSS_ALPHA_ARG2}}, /* 6, D3DTSS_ALPHAARG2 */
{FALSE, {WINED3D_TSS_BUMPENV_MAT00}}, /* 7, D3DTSS_BUMPENVMAT00 */
{FALSE, {WINED3D_TSS_BUMPENV_MAT01}}, /* 8, D3DTSS_BUMPENVMAT01 */
{FALSE, {WINED3D_TSS_BUMPENV_MAT10}}, /* 9, D3DTSS_BUMPENVMAT10 */
{FALSE, {WINED3D_TSS_BUMPENV_MAT11}}, /* 10, D3DTSS_BUMPENVMAT11 */
{FALSE, {WINED3D_TSS_TEXCOORD_INDEX}}, /* 11, D3DTSS_TEXCOORDINDEX */
{TRUE, {WINED3D_SAMP_ADDRESS_U}}, /* 12, D3DTSS_ADDRESS */
{TRUE, {WINED3D_SAMP_ADDRESS_U}}, /* 13, D3DTSS_ADDRESSU */
{TRUE, {WINED3D_SAMP_ADDRESS_V}}, /* 14, D3DTSS_ADDRESSV */
{TRUE, {WINED3D_SAMP_BORDER_COLOR}}, /* 15, D3DTSS_BORDERCOLOR */
{TRUE, {WINED3D_SAMP_MAG_FILTER}}, /* 16, D3DTSS_MAGFILTER */
{TRUE, {WINED3D_SAMP_MIN_FILTER}}, /* 17, D3DTSS_MINFILTER */
{TRUE, {WINED3D_SAMP_MIP_FILTER}}, /* 18, D3DTSS_MIPFILTER */
{TRUE, {WINED3D_SAMP_MIPMAP_LOD_BIAS}}, /* 19, D3DTSS_MIPMAPLODBIAS */
{TRUE, {WINED3D_SAMP_MAX_MIP_LEVEL}}, /* 20, D3DTSS_MAXMIPLEVEL */
{TRUE, {WINED3D_SAMP_MAX_ANISOTROPY}}, /* 21, D3DTSS_MAXANISOTROPY */
{FALSE, {WINED3D_TSS_BUMPENV_LSCALE}}, /* 22, D3DTSS_BUMPENVLSCALE */
{FALSE, {WINED3D_TSS_BUMPENV_LOFFSET}}, /* 23, D3DTSS_BUMPENVLOFFSET */
{FALSE, {WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS}}, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
};
/*****************************************************************************
* IDirect3DDevice7::GetTextureStageState
*
* Retrieves a state from a texture stage.
*
* Version 3 and 7
*
* Params:
* Stage: The stage to retrieve the state from
* TexStageStateType: The state type to retrieve
* State: Address to store the state's value at
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if State is NULL
* For details, see IWineD3DDevice::GetTextureStageState
*
*****************************************************************************/
static HRESULT d3d_device7_GetTextureStageState(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
const struct tss_lookup *l;
TRACE("iface %p, stage %u, state %#x, value %p.\n",
iface, stage, state, value);
if (!value)
return DDERR_INVALIDPARAMS;
if (state > D3DTSS_TEXTURETRANSFORMFLAGS)
{
WARN("Invalid state %#x passed.\n", state);
return DD_OK;
}
l = &tss_lookup[state];
wined3d_mutex_lock();
if (l->sampler_state)
{
*value = wined3d_device_get_sampler_state(device->wined3d_device, stage, l->u.sampler_state);
switch (state)
{
/* Mipfilter is a sampler state with different values */
case D3DTSS_MIPFILTER:
{
switch (*value)
{
case WINED3D_TEXF_NONE:
*value = D3DTFP_NONE;
break;
case WINED3D_TEXF_POINT:
*value = D3DTFP_POINT;
break;
case WINED3D_TEXF_LINEAR:
*value = D3DTFP_LINEAR;
break;
default:
ERR("Unexpected mipfilter value %#x.\n", *value);
*value = D3DTFP_NONE;
break;
}
break;
}
/* Magfilter has slightly different values */
case D3DTSS_MAGFILTER:
{
switch (*value)
{
case WINED3D_TEXF_POINT:
*value = D3DTFG_POINT;
break;
case WINED3D_TEXF_LINEAR:
*value = D3DTFG_LINEAR;
break;
case WINED3D_TEXF_ANISOTROPIC:
*value = D3DTFG_ANISOTROPIC;
break;
case WINED3D_TEXF_FLAT_CUBIC:
*value = D3DTFG_FLATCUBIC;
break;
case WINED3D_TEXF_GAUSSIAN_CUBIC:
*value = D3DTFG_GAUSSIANCUBIC;
break;
default:
ERR("Unexpected wined3d mag filter value %#x.\n", *value);
*value = D3DTFG_POINT;
break;
}
break;
}
default:
break;
}
}
else
{
*value = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, l->u.texture_state);
}
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_GetTextureStageState_FPUSetup(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
{
return d3d_device7_GetTextureStageState(iface, stage, state, value);
}
static HRESULT WINAPI d3d_device7_GetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetTextureStageState(iface, stage, state, value);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_GetTextureStageState(IDirect3DDevice3 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, stage %u, state %#x, value %p.\n",
iface, stage, state, value);
return IDirect3DDevice7_GetTextureStageState(&device->IDirect3DDevice7_iface, stage, state, value);
}
/*****************************************************************************
* IDirect3DDevice7::SetTextureStageState
*
* Sets a texture stage state. Some stage types need to be handled specially,
* because they do not exist in WineD3D and were moved to another place
*
* Version 3 and 7
*
* Params:
* Stage: The stage to modify
* TexStageStateType: The state to change
* State: The new value for the state
*
* Returns:
* D3D_OK on success
* For details, see IWineD3DDevice::SetTextureStageState
*
*****************************************************************************/
static HRESULT d3d_device7_SetTextureStageState(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
const struct tss_lookup *l;
TRACE("iface %p, stage %u, state %#x, value %#x.\n",
iface, stage, state, value);
if (state > D3DTSS_TEXTURETRANSFORMFLAGS)
{
WARN("Invalid state %#x passed.\n", state);
return DD_OK;
}
l = &tss_lookup[state];
wined3d_mutex_lock();
if (l->sampler_state)
{
switch (state)
{
/* Mipfilter is a sampler state with different values */
case D3DTSS_MIPFILTER:
{
switch (value)
{
case D3DTFP_NONE:
value = WINED3D_TEXF_NONE;
break;
case D3DTFP_POINT:
value = WINED3D_TEXF_POINT;
break;
case 0: /* Unchecked */
case D3DTFP_LINEAR:
value = WINED3D_TEXF_LINEAR;
break;
default:
ERR("Unexpected mipfilter value %#x.\n", value);
value = WINED3D_TEXF_NONE;
break;
}
break;
}
/* Magfilter has slightly different values */
case D3DTSS_MAGFILTER:
{
switch (value)
{
case D3DTFG_POINT:
value = WINED3D_TEXF_POINT;
break;
case D3DTFG_LINEAR:
value = WINED3D_TEXF_LINEAR;
break;
case D3DTFG_FLATCUBIC:
value = WINED3D_TEXF_FLAT_CUBIC;
break;
case D3DTFG_GAUSSIANCUBIC:
value = WINED3D_TEXF_GAUSSIAN_CUBIC;
break;
case D3DTFG_ANISOTROPIC:
value = WINED3D_TEXF_ANISOTROPIC;
break;
default:
ERR("Unexpected d3d7 mag filter value %#x.\n", value);
value = WINED3D_TEXF_POINT;
break;
}
break;
}
case D3DTSS_ADDRESS:
wined3d_device_set_sampler_state(device->wined3d_device, stage, WINED3D_SAMP_ADDRESS_V, value);
break;
default:
break;
}
wined3d_device_set_sampler_state(device->wined3d_device, stage, l->u.sampler_state, value);
}
else
{
wined3d_device_set_texture_stage_state(device->wined3d_device, stage, l->u.texture_state, value);
}
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_SetTextureStageState_FPUSetup(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
{
return d3d_device7_SetTextureStageState(iface, stage, state, value);
}
static HRESULT WINAPI d3d_device7_SetTextureStageState_FPUPreserve(IDirect3DDevice7 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetTextureStageState(iface, stage, state, value);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_SetTextureStageState(IDirect3DDevice3 *iface,
DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, stage %u, state %#x, value %#x.\n",
iface, stage, state, value);
return IDirect3DDevice7_SetTextureStageState(&device->IDirect3DDevice7_iface, stage, state, value);
}
/*****************************************************************************
* IDirect3DDevice7::ValidateDevice
*
* SDK: "Reports the device's ability to render the currently set
* texture-blending operations in a single pass". Whatever that means
* exactly...
*
* Version 3 and 7
*
* Params:
* NumPasses: Address to write the number of necessary passes for the
* desired effect to.
*
* Returns:
* D3D_OK on success
* See IWineD3DDevice::ValidateDevice for more details
*
*****************************************************************************/
static HRESULT d3d_device7_ValidateDevice(IDirect3DDevice7 *iface, DWORD *pass_count)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, pass_count %p.\n", iface, pass_count);
wined3d_mutex_lock();
hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_ValidateDevice_FPUSetup(IDirect3DDevice7 *iface, DWORD *pass_count)
{
return d3d_device7_ValidateDevice(iface, pass_count);
}
static HRESULT WINAPI d3d_device7_ValidateDevice_FPUPreserve(IDirect3DDevice7 *iface, DWORD *pass_count)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_ValidateDevice(iface, pass_count);
set_fpu_control_word(old_fpucw);
return hr;
}
static HRESULT WINAPI d3d_device3_ValidateDevice(IDirect3DDevice3 *iface, DWORD *pass_count)
{
struct d3d_device *device = impl_from_IDirect3DDevice3(iface);
TRACE("iface %p, pass_count %p.\n", iface, pass_count);
return IDirect3DDevice7_ValidateDevice(&device->IDirect3DDevice7_iface, pass_count);
}
/*****************************************************************************
* IDirect3DDevice7::Clear
*
* Fills the render target, the z buffer and the stencil buffer with a
* clear color / value
*
* Version 7 only
*
* Params:
* Count: Number of rectangles in Rects must be 0 if Rects is NULL
* Rects: Rectangles to clear. If NULL, the whole surface is cleared
* Flags: Some flags, as usual
* Color: Clear color for the render target
* Z: Clear value for the Z buffer
* Stencil: Clear value to store in each stencil buffer entry
*
* Returns:
* D3D_OK on success
* For details, see IWineD3DDevice::Clear
*
*****************************************************************************/
static HRESULT d3d_device7_Clear(IDirect3DDevice7 *iface, DWORD count,
D3DRECT *rects, DWORD flags, D3DCOLOR color, D3DVALUE z, DWORD stencil)
{
const struct wined3d_color c =
{
((color >> 16) & 0xff) / 255.0f,
((color >> 8) & 0xff) / 255.0f,
(color & 0xff) / 255.0f,
((color >> 24) & 0xff) / 255.0f,
};
struct d3d_device *This = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %#x.\n",
iface, count, rects, flags, color, z, stencil);
if (count && !rects)
{
WARN("count %u with NULL rects.\n", count);
count = 0;
}
wined3d_mutex_lock();
hr = wined3d_device_clear(This->wined3d_device, count, (RECT *)rects, flags, &c, z, stencil);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_Clear_FPUSetup(IDirect3DDevice7 *iface, DWORD count,
D3DRECT *rects, DWORD flags, D3DCOLOR color, D3DVALUE z, DWORD stencil)
{
return d3d_device7_Clear(iface, count, rects, flags, color, z, stencil);
}
static HRESULT WINAPI d3d_device7_Clear_FPUPreserve(IDirect3DDevice7 *iface, DWORD count,
D3DRECT *rects, DWORD flags, D3DCOLOR color, D3DVALUE z, DWORD stencil)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_Clear(iface, count, rects, flags, color, z, stencil);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::SetViewport
*
* Sets the current viewport.
*
* Version 7 only, but IDirect3DViewport uses this call for older
* versions
*
* Params:
* Data: The new viewport to set
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Data is NULL
* For more details, see IWineDDDevice::SetViewport
*
*****************************************************************************/
static HRESULT d3d_device7_SetViewport(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, viewport %p.\n", iface, viewport);
if (!viewport)
return DDERR_INVALIDPARAMS;
/* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */
wined3d_mutex_lock();
wined3d_device_set_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_SetViewport_FPUSetup(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
return d3d_device7_SetViewport(iface, viewport);
}
static HRESULT WINAPI d3d_device7_SetViewport_FPUPreserve(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetViewport(iface, viewport);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice::GetViewport
*
* Returns the current viewport
*
* Version 7
*
* Params:
* Data: D3D7Viewport structure to write the viewport information to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Data is NULL
* For more details, see IWineD3DDevice::GetViewport
*
*****************************************************************************/
static HRESULT d3d_device7_GetViewport(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, viewport %p.\n", iface, viewport);
if (!viewport)
return DDERR_INVALIDPARAMS;
/* Note: D3DVIEWPORT7 is compatible with struct wined3d_viewport. */
wined3d_mutex_lock();
wined3d_device_get_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_GetViewport_FPUSetup(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
return d3d_device7_GetViewport(iface, viewport);
}
static HRESULT WINAPI d3d_device7_GetViewport_FPUPreserve(IDirect3DDevice7 *iface, D3DVIEWPORT7 *viewport)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetViewport(iface, viewport);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::SetMaterial
*
* Sets the Material
*
* Version 7
*
* Params:
* Mat: The material to set
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Mat is NULL.
* For more details, see IWineD3DDevice::SetMaterial
*
*****************************************************************************/
static HRESULT d3d_device7_SetMaterial(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, material %p.\n", iface, material);
if (!material)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
/* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */
wined3d_device_set_material(device->wined3d_device, (struct wined3d_material *)material);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_SetMaterial_FPUSetup(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
return d3d_device7_SetMaterial(iface, material);
}
static HRESULT WINAPI d3d_device7_SetMaterial_FPUPreserve(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetMaterial(iface, material);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetMaterial
*
* Returns the current material
*
* Version 7
*
* Params:
* Mat: D3DMATERIAL7 structure to write the material parameters to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Mat is NULL
* For more details, see IWineD3DDevice::GetMaterial
*
*****************************************************************************/
static HRESULT d3d_device7_GetMaterial(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
TRACE("iface %p, material %p.\n", iface, material);
wined3d_mutex_lock();
/* Note: D3DMATERIAL7 is compatible with struct wined3d_material. */
wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_GetMaterial_FPUSetup(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
return d3d_device7_GetMaterial(iface, material);
}
static HRESULT WINAPI d3d_device7_GetMaterial_FPUPreserve(IDirect3DDevice7 *iface, D3DMATERIAL7 *material)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetMaterial(iface, material);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::SetLight
*
* Assigns a light to a light index, but doesn't activate it yet.
*
* Version 7, IDirect3DLight uses this method for older versions
*
* Params:
* LightIndex: The index of the new light
* Light: A D3DLIGHT7 structure describing the light
*
* Returns:
* D3D_OK on success
* For more details, see IWineD3DDevice::SetLight
*
*****************************************************************************/
static HRESULT d3d_device7_SetLight(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, light_idx %u, light %p.\n", iface, light_idx, light);
wined3d_mutex_lock();
/* Note: D3DLIGHT7 is compatible with struct wined3d_light. */
hr = wined3d_device_set_light(device->wined3d_device, light_idx, (struct wined3d_light *)light);
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_SetLight_FPUSetup(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
return d3d_device7_SetLight(iface, light_idx, light);
}
static HRESULT WINAPI d3d_device7_SetLight_FPUPreserve(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetLight(iface, light_idx, light);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetLight
*
* Returns the light assigned to a light index
*
* Params:
* Light: Structure to write the light information to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Light is NULL
* For details, see IWineD3DDevice::GetLight
*
*****************************************************************************/
static HRESULT d3d_device7_GetLight(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT rc;
TRACE("iface %p, light_idx %u, light %p.\n", iface, light_idx, light);
wined3d_mutex_lock();
/* Note: D3DLIGHT7 is compatible with struct wined3d_light. */
rc = wined3d_device_get_light(device->wined3d_device, light_idx, (struct wined3d_light *)light);
wined3d_mutex_unlock();
/* Translate the result. WineD3D returns other values than D3D7 */
return hr_ddraw_from_wined3d(rc);
}
static HRESULT WINAPI d3d_device7_GetLight_FPUSetup(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
return d3d_device7_GetLight(iface, light_idx, light);
}
static HRESULT WINAPI d3d_device7_GetLight_FPUPreserve(IDirect3DDevice7 *iface, DWORD light_idx, D3DLIGHT7 *light)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetLight(iface, light_idx, light);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::BeginStateBlock
*
* Begins recording to a stateblock
*
* Version 7
*
* Returns:
* D3D_OK on success
* For details see IWineD3DDevice::BeginStateBlock
*
*****************************************************************************/
static HRESULT d3d_device7_BeginStateBlock(IDirect3DDevice7 *iface)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p.\n", iface);
wined3d_mutex_lock();
hr = wined3d_device_begin_stateblock(device->wined3d_device);
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_BeginStateBlock_FPUSetup(IDirect3DDevice7 *iface)
{
return d3d_device7_BeginStateBlock(iface);
}
static HRESULT WINAPI d3d_device7_BeginStateBlock_FPUPreserve(IDirect3DDevice7 *iface)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_BeginStateBlock(iface);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::EndStateBlock
*
* Stops recording to a state block and returns the created stateblock
* handle.
*
* Version 7
*
* Params:
* BlockHandle: Address to store the stateblock's handle to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if BlockHandle is NULL
* See IWineD3DDevice::EndStateBlock for more details
*
*****************************************************************************/
static HRESULT d3d_device7_EndStateBlock(IDirect3DDevice7 *iface, DWORD *stateblock)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_stateblock *wined3d_sb;
HRESULT hr;
DWORD h;
TRACE("iface %p, stateblock %p.\n", iface, stateblock);
if (!stateblock)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
hr = wined3d_device_end_stateblock(device->wined3d_device, &wined3d_sb);
if (FAILED(hr))
{
WARN("Failed to end stateblock, hr %#x.\n", hr);
wined3d_mutex_unlock();
*stateblock = 0;
return hr_ddraw_from_wined3d(hr);
}
h = ddraw_allocate_handle(&device->handle_table, wined3d_sb, DDRAW_HANDLE_STATEBLOCK);
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate a stateblock handle.\n");
wined3d_stateblock_decref(wined3d_sb);
wined3d_mutex_unlock();
*stateblock = 0;
return DDERR_OUTOFMEMORY;
}
wined3d_mutex_unlock();
*stateblock = h + 1;
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_EndStateBlock_FPUSetup(IDirect3DDevice7 *iface, DWORD *stateblock)
{
return d3d_device7_EndStateBlock(iface, stateblock);
}
static HRESULT WINAPI d3d_device7_EndStateBlock_FPUPreserve(IDirect3DDevice7 *iface, DWORD *stateblock)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_EndStateBlock(iface, stateblock);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::PreLoad
*
* Allows the app to signal that a texture will be used soon, to allow
* the Direct3DDevice to load it to the video card in the meantime.
*
* Version 7
*
* Params:
* Texture: The texture to preload
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Texture is NULL
* See IWineD3DSurface::PreLoad for details
*
*****************************************************************************/
static HRESULT d3d_device7_PreLoad(IDirect3DDevice7 *iface, IDirectDrawSurface7 *texture)
{
struct ddraw_surface *surface = unsafe_impl_from_IDirectDrawSurface7(texture);
TRACE("iface %p, texture %p.\n", iface, texture);
if (!texture)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
wined3d_resource_preload(wined3d_texture_get_resource(surface->wined3d_texture));
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_PreLoad_FPUSetup(IDirect3DDevice7 *iface, IDirectDrawSurface7 *texture)
{
return d3d_device7_PreLoad(iface, texture);
}
static HRESULT WINAPI d3d_device7_PreLoad_FPUPreserve(IDirect3DDevice7 *iface, IDirectDrawSurface7 *texture)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_PreLoad(iface, texture);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::ApplyStateBlock
*
* Activates the state stored in a state block handle.
*
* Params:
* BlockHandle: The stateblock handle to activate
*
* Returns:
* D3D_OK on success
* D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
*
*****************************************************************************/
static HRESULT d3d_device7_ApplyStateBlock(IDirect3DDevice7 *iface, DWORD stateblock)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_stateblock *wined3d_sb;
TRACE("iface %p, stateblock %#x.\n", iface, stateblock);
wined3d_mutex_lock();
wined3d_sb = ddraw_get_object(&device->handle_table, stateblock - 1, DDRAW_HANDLE_STATEBLOCK);
if (!wined3d_sb)
{
WARN("Invalid stateblock handle.\n");
wined3d_mutex_unlock();
return D3DERR_INVALIDSTATEBLOCK;
}
wined3d_stateblock_apply(wined3d_sb);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_ApplyStateBlock_FPUSetup(IDirect3DDevice7 *iface, DWORD stateblock)
{
return d3d_device7_ApplyStateBlock(iface, stateblock);
}
static HRESULT WINAPI d3d_device7_ApplyStateBlock_FPUPreserve(IDirect3DDevice7 *iface, DWORD stateblock)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_ApplyStateBlock(iface, stateblock);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::CaptureStateBlock
*
* Updates a stateblock's values to the values currently set for the device
*
* Version 7
*
* Params:
* BlockHandle: Stateblock to update
*
* Returns:
* D3D_OK on success
* D3DERR_INVALIDSTATEBLOCK if BlockHandle is NULL
* See IWineD3DDevice::CaptureStateBlock for more details
*
*****************************************************************************/
static HRESULT d3d_device7_CaptureStateBlock(IDirect3DDevice7 *iface, DWORD stateblock)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_stateblock *wined3d_sb;
TRACE("iface %p, stateblock %#x.\n", iface, stateblock);
wined3d_mutex_lock();
wined3d_sb = ddraw_get_object(&device->handle_table, stateblock - 1, DDRAW_HANDLE_STATEBLOCK);
if (!wined3d_sb)
{
WARN("Invalid stateblock handle.\n");
wined3d_mutex_unlock();
return D3DERR_INVALIDSTATEBLOCK;
}
wined3d_stateblock_capture(wined3d_sb);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_CaptureStateBlock_FPUSetup(IDirect3DDevice7 *iface, DWORD stateblock)
{
return d3d_device7_CaptureStateBlock(iface, stateblock);
}
static HRESULT WINAPI d3d_device7_CaptureStateBlock_FPUPreserve(IDirect3DDevice7 *iface, DWORD stateblock)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_CaptureStateBlock(iface, stateblock);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::DeleteStateBlock
*
* Deletes a stateblock handle. This means releasing the WineD3DStateBlock
*
* Version 7
*
* Params:
* BlockHandle: Stateblock handle to delete
*
* Returns:
* D3D_OK on success
* D3DERR_INVALIDSTATEBLOCK if BlockHandle is 0
*
*****************************************************************************/
static HRESULT d3d_device7_DeleteStateBlock(IDirect3DDevice7 *iface, DWORD stateblock)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_stateblock *wined3d_sb;
ULONG ref;
TRACE("iface %p, stateblock %#x.\n", iface, stateblock);
wined3d_mutex_lock();
wined3d_sb = ddraw_free_handle(&device->handle_table, stateblock - 1, DDRAW_HANDLE_STATEBLOCK);
if (!wined3d_sb)
{
WARN("Invalid stateblock handle.\n");
wined3d_mutex_unlock();
return D3DERR_INVALIDSTATEBLOCK;
}
if ((ref = wined3d_stateblock_decref(wined3d_sb)))
{
ERR("Something is still holding stateblock %p (refcount %u).\n", wined3d_sb, ref);
}
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_DeleteStateBlock_FPUSetup(IDirect3DDevice7 *iface, DWORD stateblock)
{
return d3d_device7_DeleteStateBlock(iface, stateblock);
}
static HRESULT WINAPI d3d_device7_DeleteStateBlock_FPUPreserve(IDirect3DDevice7 *iface, DWORD stateblock)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_DeleteStateBlock(iface, stateblock);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::CreateStateBlock
*
* Creates a new state block handle.
*
* Version 7
*
* Params:
* Type: The state block type
* BlockHandle: Address to write the created handle to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if BlockHandle is NULL
*
*****************************************************************************/
static HRESULT d3d_device7_CreateStateBlock(IDirect3DDevice7 *iface,
D3DSTATEBLOCKTYPE type, DWORD *stateblock)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct wined3d_stateblock *wined3d_sb;
HRESULT hr;
DWORD h;
TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
if (!stateblock)
return DDERR_INVALIDPARAMS;
if (type != D3DSBT_ALL
&& type != D3DSBT_PIXELSTATE
&& type != D3DSBT_VERTEXSTATE)
{
WARN("Unexpected stateblock type, returning DDERR_INVALIDPARAMS\n");
return DDERR_INVALIDPARAMS;
}
wined3d_mutex_lock();
/* The D3DSTATEBLOCKTYPE enum is fine here. */
hr = wined3d_stateblock_create(device->wined3d_device, type, &wined3d_sb);
if (FAILED(hr))
{
WARN("Failed to create stateblock, hr %#x.\n", hr);
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
h = ddraw_allocate_handle(&device->handle_table, wined3d_sb, DDRAW_HANDLE_STATEBLOCK);
if (h == DDRAW_INVALID_HANDLE)
{
ERR("Failed to allocate stateblock handle.\n");
wined3d_stateblock_decref(wined3d_sb);
wined3d_mutex_unlock();
return DDERR_OUTOFMEMORY;
}
*stateblock = h + 1;
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_CreateStateBlock_FPUSetup(IDirect3DDevice7 *iface,
D3DSTATEBLOCKTYPE type, DWORD *stateblock)
{
return d3d_device7_CreateStateBlock(iface, type, stateblock);
}
static HRESULT WINAPI d3d_device7_CreateStateBlock_FPUPreserve(IDirect3DDevice7 *iface,
D3DSTATEBLOCKTYPE type, DWORD *stateblock)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_CreateStateBlock(iface, type, stateblock);
set_fpu_control_word(old_fpucw);
return hr;
}
static BOOL is_mip_level_subset(struct ddraw_surface *dest, struct ddraw_surface *src)
{
struct ddraw_surface *src_level, *dest_level;
IDirectDrawSurface7 *temp;
DDSURFACEDESC2 ddsd;
BOOL levelFound; /* at least one suitable sublevel in dest found */
/* To satisfy "destination is mip level subset of source" criteria (regular texture counts as 1 level),
* 1) there must be at least one mip level in destination that matched dimensions of some mip level in source and
* 2) there must be no destination levels that don't match any levels in source. Otherwise it's INVALIDPARAMS.
*/
levelFound = FALSE;
src_level = src;
dest_level = dest;
for (;src_level && dest_level;)
{
if (src_level->surface_desc.dwWidth == dest_level->surface_desc.dwWidth &&
src_level->surface_desc.dwHeight == dest_level->surface_desc.dwHeight)
{
levelFound = TRUE;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
IDirectDrawSurface7_GetAttachedSurface(&dest_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
dest_level = unsafe_impl_from_IDirectDrawSurface7(temp);
}
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
src_level = unsafe_impl_from_IDirectDrawSurface7(temp);
}
if (src_level && src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
if (dest_level && dest_level != dest) IDirectDrawSurface7_Release(&dest_level->IDirectDrawSurface7_iface);
return !dest_level && levelFound;
}
static void copy_mipmap_chain(struct d3d_device *device, struct ddraw_surface *dst,
struct ddraw_surface *src, const POINT *DestPoint, const RECT *SrcRect)
{
struct ddraw_surface *dst_level, *src_level;
IDirectDrawSurface7 *temp;
DDSURFACEDESC2 ddsd;
POINT point;
RECT src_rect;
HRESULT hr;
IDirectDrawPalette *pal = NULL, *pal_src = NULL;
DWORD ckeyflag;
DDCOLORKEY ddckey;
/* Copy palette, if possible. */
IDirectDrawSurface7_GetPalette(&src->IDirectDrawSurface7_iface, &pal_src);
IDirectDrawSurface7_GetPalette(&dst->IDirectDrawSurface7_iface, &pal);
if (pal_src != NULL && pal != NULL)
{
PALETTEENTRY palent[256];
IDirectDrawPalette_GetEntries(pal_src, 0, 0, 256, palent);
IDirectDrawPalette_SetEntries(pal, 0, 0, 256, palent);
}
if (pal) IDirectDrawPalette_Release(pal);
if (pal_src) IDirectDrawPalette_Release(pal_src);
/* Copy colorkeys, if present. */
for (ckeyflag = DDCKEY_DESTBLT; ckeyflag <= DDCKEY_SRCOVERLAY; ckeyflag <<= 1)
{
hr = IDirectDrawSurface7_GetColorKey(&src->IDirectDrawSurface7_iface, ckeyflag, &ddckey);
if (SUCCEEDED(hr))
{
IDirectDrawSurface7_SetColorKey(&dst->IDirectDrawSurface7_iface, ckeyflag, &ddckey);
}
}
src_level = src;
dst_level = dst;
point = *DestPoint;
src_rect = *SrcRect;
for (;src_level && dst_level;)
{
if (src_level->surface_desc.dwWidth == dst_level->surface_desc.dwWidth
&& src_level->surface_desc.dwHeight == dst_level->surface_desc.dwHeight)
{
UINT src_w = src_rect.right - src_rect.left;
UINT src_h = src_rect.bottom - src_rect.top;
RECT dst_rect = {point.x, point.y, point.x + src_w, point.y + src_h};
if (FAILED(hr = wined3d_texture_blt(dst_level->wined3d_texture, dst_level->sub_resource_idx, &dst_rect,
src_level->wined3d_texture, src_level->sub_resource_idx, &src_rect, 0, NULL, WINED3D_TEXF_POINT)))
ERR("Blit failed, hr %#x.\n", hr);
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
IDirectDrawSurface7_GetAttachedSurface(&dst_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (dst_level != dst)
IDirectDrawSurface7_Release(&dst_level->IDirectDrawSurface7_iface);
dst_level = unsafe_impl_from_IDirectDrawSurface7(temp);
}
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_MIPMAPSUBLEVEL;
IDirectDrawSurface7_GetAttachedSurface(&src_level->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (src_level != src) IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
src_level = unsafe_impl_from_IDirectDrawSurface7(temp);
point.x /= 2;
point.y /= 2;
src_rect.top /= 2;
src_rect.left /= 2;
src_rect.right = (src_rect.right + 1) / 2;
src_rect.bottom = (src_rect.bottom + 1) / 2;
}
if (src_level && src_level != src)
IDirectDrawSurface7_Release(&src_level->IDirectDrawSurface7_iface);
if (dst_level && dst_level != dst)
IDirectDrawSurface7_Release(&dst_level->IDirectDrawSurface7_iface);
}
/*****************************************************************************
* IDirect3DDevice7::Load
*
* Loads a rectangular area from the source into the destination texture.
* It can also copy the source to the faces of a cubic environment map
*
* Version 7
*
* Params:
* DestTex: Destination texture
* DestPoint: Point in the destination where the source image should be
* written to
* SrcTex: Source texture
* SrcRect: Source rectangle
* Flags: Cubemap faces to load (DDSCAPS2_CUBEMAP_ALLFACES, DDSCAPS2_CUBEMAP_POSITIVEX,
* DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, DDSCAPS2_CUBEMAP_NEGATIVEY,
* DDSCAPS2_CUBEMAP_POSITIVEZ, DDSCAPS2_CUBEMAP_NEGATIVEZ)
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if dst_texture or src_texture is NULL, broken coordinates or anything unexpected.
*
*
*****************************************************************************/
static HRESULT d3d_device7_Load(IDirect3DDevice7 *iface, IDirectDrawSurface7 *dst_texture, POINT *dst_pos,
IDirectDrawSurface7 *src_texture, RECT *src_rect, DWORD flags)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
struct ddraw_surface *dest = unsafe_impl_from_IDirectDrawSurface7(dst_texture);
struct ddraw_surface *src = unsafe_impl_from_IDirectDrawSurface7(src_texture);
POINT destpoint;
RECT srcrect;
TRACE("iface %p, dst_texture %p, dst_pos %s, src_texture %p, src_rect %s, flags %#x.\n",
iface, dst_texture, wine_dbgstr_point(dst_pos), src_texture, wine_dbgstr_rect(src_rect), flags);
if( (!src) || (!dest) )
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
if (!src_rect)
SetRect(&srcrect, 0, 0, src->surface_desc.dwWidth, src->surface_desc.dwHeight);
else
srcrect = *src_rect;
if (!dst_pos)
destpoint.x = destpoint.y = 0;
else
destpoint = *dst_pos;
/* Check bad dimensions. dst_pos is validated against src, not dest, because
* destination can be a subset of mip levels, in which case actual coordinates used
* for it may be divided. If any dimension of dest is larger than source, it can't be
* mip level subset, so an error can be returned early.
*/
if (IsRectEmpty(&srcrect) || srcrect.right > src->surface_desc.dwWidth ||
srcrect.bottom > src->surface_desc.dwHeight ||
destpoint.x + srcrect.right - srcrect.left > src->surface_desc.dwWidth ||
destpoint.y + srcrect.bottom - srcrect.top > src->surface_desc.dwHeight ||
dest->surface_desc.dwWidth > src->surface_desc.dwWidth ||
dest->surface_desc.dwHeight > src->surface_desc.dwHeight)
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
/* Must be top level surfaces. */
if (src->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL ||
dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_MIPMAPSUBLEVEL)
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
if (src->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
{
struct ddraw_surface *src_face, *dest_face;
DWORD src_face_flag, dest_face_flag;
IDirectDrawSurface7 *temp;
DDSURFACEDESC2 ddsd;
int i;
if (!(dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP))
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
/* Iterate through cube faces 2 times. First time is just to check INVALIDPARAMS conditions, second
* time it's actual surface loading. */
for (i = 0; i < 2; i++)
{
dest_face = dest;
src_face = src;
for (;dest_face && src_face;)
{
src_face_flag = src_face->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES;
dest_face_flag = dest_face->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP_ALLFACES;
if (src_face_flag == dest_face_flag)
{
if (i == 0)
{
/* Destination mip levels must be subset of source mip levels. */
if (!is_mip_level_subset(dest_face, src_face))
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
else if (flags & dest_face_flag)
{
copy_mipmap_chain(device, dest_face, src_face, &destpoint, &srcrect);
}
if (src_face_flag < DDSCAPS2_CUBEMAP_NEGATIVEZ)
{
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (src_face_flag << 1);
IDirectDrawSurface7_GetAttachedSurface(&src->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface);
src_face = unsafe_impl_from_IDirectDrawSurface7(temp);
}
else
{
if (src_face != src) IDirectDrawSurface7_Release(&src_face->IDirectDrawSurface7_iface);
src_face = NULL;
}
}
if (dest_face_flag < DDSCAPS2_CUBEMAP_NEGATIVEZ)
{
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_CUBEMAP | (dest_face_flag << 1);
IDirectDrawSurface7_GetAttachedSurface(&dest->IDirectDrawSurface7_iface, &ddsd.ddsCaps, &temp);
if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface);
dest_face = unsafe_impl_from_IDirectDrawSurface7(temp);
}
else
{
if (dest_face != dest) IDirectDrawSurface7_Release(&dest_face->IDirectDrawSurface7_iface);
dest_face = NULL;
}
}
if (i == 0)
{
/* Native returns error if src faces are not subset of dest faces. */
if (src_face)
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
}
}
wined3d_mutex_unlock();
return D3D_OK;
}
else if (dest->surface_desc.ddsCaps.dwCaps2 & DDSCAPS2_CUBEMAP)
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
/* Handle non cube map textures. */
/* Destination mip levels must be subset of source mip levels. */
if (!is_mip_level_subset(dest, src))
{
wined3d_mutex_unlock();
return DDERR_INVALIDPARAMS;
}
copy_mipmap_chain(device, dest, src, &destpoint, &srcrect);
wined3d_mutex_unlock();
return D3D_OK;
}
static HRESULT WINAPI d3d_device7_Load_FPUSetup(IDirect3DDevice7 *iface, IDirectDrawSurface7 *dst_texture,
POINT *dst_pos, IDirectDrawSurface7 *src_texture, RECT *src_rect, DWORD flags)
{
return d3d_device7_Load(iface, dst_texture, dst_pos, src_texture, src_rect, flags);
}
static HRESULT WINAPI d3d_device7_Load_FPUPreserve(IDirect3DDevice7 *iface, IDirectDrawSurface7 *dst_texture,
POINT *dst_pos, IDirectDrawSurface7 *src_texture, RECT *src_rect, DWORD flags)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_Load(iface, dst_texture, dst_pos, src_texture, src_rect, flags);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::LightEnable
*
* Enables or disables a light
*
* Version 7, IDirect3DLight uses this method too.
*
* Params:
* LightIndex: The index of the light to enable / disable
* Enable: Enable or disable the light
*
* Returns:
* D3D_OK on success
* For more details, see IWineD3DDevice::SetLightEnable
*
*****************************************************************************/
static HRESULT d3d_device7_LightEnable(IDirect3DDevice7 *iface, DWORD light_idx, BOOL enabled)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, light_idx %u, enabled %#x.\n", iface, light_idx, enabled);
wined3d_mutex_lock();
hr = wined3d_device_set_light_enable(device->wined3d_device, light_idx, enabled);
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_LightEnable_FPUSetup(IDirect3DDevice7 *iface, DWORD light_idx, BOOL enabled)
{
return d3d_device7_LightEnable(iface, light_idx, enabled);
}
static HRESULT WINAPI d3d_device7_LightEnable_FPUPreserve(IDirect3DDevice7 *iface, DWORD light_idx, BOOL enabled)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_LightEnable(iface, light_idx, enabled);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetLightEnable
*
* Retrieves if the light with the given index is enabled or not
*
* Version 7
*
* Params:
* LightIndex: Index of desired light
* Enable: Pointer to a BOOL which contains the result
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if Enable is NULL
* See IWineD3DDevice::GetLightEnable for more details
*
*****************************************************************************/
static HRESULT d3d_device7_GetLightEnable(IDirect3DDevice7 *iface, DWORD light_idx, BOOL *enabled)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, light_idx %u, enabled %p.\n", iface, light_idx, enabled);
if (!enabled)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
hr = wined3d_device_get_light_enable(device->wined3d_device, light_idx, enabled);
wined3d_mutex_unlock();
return hr_ddraw_from_wined3d(hr);
}
static HRESULT WINAPI d3d_device7_GetLightEnable_FPUSetup(IDirect3DDevice7 *iface, DWORD light_idx, BOOL *enabled)
{
return d3d_device7_GetLightEnable(iface, light_idx, enabled);
}
static HRESULT WINAPI d3d_device7_GetLightEnable_FPUPreserve(IDirect3DDevice7 *iface, DWORD light_idx, BOOL *enabled)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetLightEnable(iface, light_idx, enabled);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::SetClipPlane
*
* Sets custom clipping plane
*
* Version 7
*
* Params:
* Index: The index of the clipping plane
* PlaneEquation: An equation defining the clipping plane
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if PlaneEquation is NULL
* See IWineD3DDevice::SetClipPlane for more details
*
*****************************************************************************/
static HRESULT d3d_device7_SetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, idx %u, plane %p.\n", iface, idx, plane);
if (!plane)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
hr = wined3d_device_set_clip_plane(device->wined3d_device, idx, (struct wined3d_vec4 *)plane);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_SetClipPlane_FPUSetup(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
return d3d_device7_SetClipPlane(iface, idx, plane);
}
static HRESULT WINAPI d3d_device7_SetClipPlane_FPUPreserve(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_SetClipPlane(iface, idx, plane);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetClipPlane
*
* Returns the clipping plane with a specific index
*
* Params:
* Index: The index of the desired plane
* PlaneEquation: Address to store the plane equation to
*
* Returns:
* D3D_OK on success
* DDERR_INVALIDPARAMS if PlaneEquation is NULL
* See IWineD3DDevice::GetClipPlane for more details
*
*****************************************************************************/
static HRESULT d3d_device7_GetClipPlane(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
HRESULT hr;
TRACE("iface %p, idx %u, plane %p.\n", iface, idx, plane);
if (!plane)
return DDERR_INVALIDPARAMS;
wined3d_mutex_lock();
hr = wined3d_device_get_clip_plane(device->wined3d_device, idx, (struct wined3d_vec4 *)plane);
wined3d_mutex_unlock();
return hr;
}
static HRESULT WINAPI d3d_device7_GetClipPlane_FPUSetup(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
return d3d_device7_GetClipPlane(iface, idx, plane);
}
static HRESULT WINAPI d3d_device7_GetClipPlane_FPUPreserve(IDirect3DDevice7 *iface, DWORD idx, D3DVALUE *plane)
{
HRESULT hr;
WORD old_fpucw;
old_fpucw = d3d_fpu_setup();
hr = d3d_device7_GetClipPlane(iface, idx, plane);
set_fpu_control_word(old_fpucw);
return hr;
}
/*****************************************************************************
* IDirect3DDevice7::GetInfo
*
* Retrieves some information about the device. The DirectX sdk says that
* this version returns S_FALSE for all retail builds of DirectX, that's what
* this implementation does.
*
* Params:
* DevInfoID: Information type requested
* DevInfoStruct: Pointer to a structure to store the info to
* Size: Size of the structure
*
* Returns:
* S_FALSE, because it's a non-debug driver
*
*****************************************************************************/
static HRESULT WINAPI d3d_device7_GetInfo(IDirect3DDevice7 *iface, DWORD info_id, void *info, DWORD info_size)
{
TRACE("iface %p, info_id %#x, info %p, info_size %u.\n",
iface, info_id, info, info_size);
if (TRACE_ON(ddraw))
{
TRACE(" info requested : ");
switch (info_id)
{
case D3DDEVINFOID_TEXTUREMANAGER: TRACE("D3DDEVINFOID_TEXTUREMANAGER\n"); break;
case D3DDEVINFOID_D3DTEXTUREMANAGER: TRACE("D3DDEVINFOID_D3DTEXTUREMANAGER\n"); break;
case D3DDEVINFOID_TEXTURING: TRACE("D3DDEVINFOID_TEXTURING\n"); break;
default: ERR(" invalid flag !!!\n"); return DDERR_INVALIDPARAMS;
}
}
return S_FALSE; /* According to MSDN, this is valid for a non-debug driver */
}
/* For performance optimization, devices created in FPUSETUP and FPUPRESERVE modes
* have separate vtables. Simple functions where this doesn't matter like GetDirect3D
* are not duplicated.
* Device created with DDSCL_FPUSETUP (d3d7 default) - device methods assume that FPU
* has already been setup for optimal d3d operation.
* Device created with DDSCL_FPUPRESERVE - resets and restores FPU mode when necessary in
* d3d calls (FPU may be in a mode non-suitable for d3d when the app calls d3d). Required
* by Sacrifice (game). */
static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_setup_vtbl =
{
/*** IUnknown Methods ***/
d3d_device7_QueryInterface,
d3d_device7_AddRef,
d3d_device7_Release,
/*** IDirect3DDevice7 ***/
d3d_device7_GetCaps_FPUSetup,
d3d_device7_EnumTextureFormats_FPUSetup,
d3d_device7_BeginScene_FPUSetup,
d3d_device7_EndScene_FPUSetup,
d3d_device7_GetDirect3D,
d3d_device7_SetRenderTarget_FPUSetup,
d3d_device7_GetRenderTarget,
d3d_device7_Clear_FPUSetup,
d3d_device7_SetTransform_FPUSetup,
d3d_device7_GetTransform_FPUSetup,
d3d_device7_SetViewport_FPUSetup,
d3d_device7_MultiplyTransform_FPUSetup,
d3d_device7_GetViewport_FPUSetup,
d3d_device7_SetMaterial_FPUSetup,
d3d_device7_GetMaterial_FPUSetup,
d3d_device7_SetLight_FPUSetup,
d3d_device7_GetLight_FPUSetup,
d3d_device7_SetRenderState_FPUSetup,
d3d_device7_GetRenderState_FPUSetup,
d3d_device7_BeginStateBlock_FPUSetup,
d3d_device7_EndStateBlock_FPUSetup,
d3d_device7_PreLoad_FPUSetup,
d3d_device7_DrawPrimitive_FPUSetup,
d3d_device7_DrawIndexedPrimitive_FPUSetup,
d3d_device7_SetClipStatus,
d3d_device7_GetClipStatus,
d3d_device7_DrawPrimitiveStrided_FPUSetup,
d3d_device7_DrawIndexedPrimitiveStrided_FPUSetup,
d3d_device7_DrawPrimitiveVB_FPUSetup,
d3d_device7_DrawIndexedPrimitiveVB_FPUSetup,
d3d_device7_ComputeSphereVisibility,
d3d_device7_GetTexture_FPUSetup,
d3d_device7_SetTexture_FPUSetup,
d3d_device7_GetTextureStageState_FPUSetup,
d3d_device7_SetTextureStageState_FPUSetup,
d3d_device7_ValidateDevice_FPUSetup,
d3d_device7_ApplyStateBlock_FPUSetup,
d3d_device7_CaptureStateBlock_FPUSetup,
d3d_device7_DeleteStateBlock_FPUSetup,
d3d_device7_CreateStateBlock_FPUSetup,
d3d_device7_Load_FPUSetup,
d3d_device7_LightEnable_FPUSetup,
d3d_device7_GetLightEnable_FPUSetup,
d3d_device7_SetClipPlane_FPUSetup,
d3d_device7_GetClipPlane_FPUSetup,
d3d_device7_GetInfo
};
static const struct IDirect3DDevice7Vtbl d3d_device7_fpu_preserve_vtbl =
{
/*** IUnknown Methods ***/
d3d_device7_QueryInterface,
d3d_device7_AddRef,
d3d_device7_Release,
/*** IDirect3DDevice7 ***/
d3d_device7_GetCaps_FPUPreserve,
d3d_device7_EnumTextureFormats_FPUPreserve,
d3d_device7_BeginScene_FPUPreserve,
d3d_device7_EndScene_FPUPreserve,
d3d_device7_GetDirect3D,
d3d_device7_SetRenderTarget_FPUPreserve,
d3d_device7_GetRenderTarget,
d3d_device7_Clear_FPUPreserve,
d3d_device7_SetTransform_FPUPreserve,
d3d_device7_GetTransform_FPUPreserve,
d3d_device7_SetViewport_FPUPreserve,
d3d_device7_MultiplyTransform_FPUPreserve,
d3d_device7_GetViewport_FPUPreserve,
d3d_device7_SetMaterial_FPUPreserve,
d3d_device7_GetMaterial_FPUPreserve,
d3d_device7_SetLight_FPUPreserve,
d3d_device7_GetLight_FPUPreserve,
d3d_device7_SetRenderState_FPUPreserve,
d3d_device7_GetRenderState_FPUPreserve,
d3d_device7_BeginStateBlock_FPUPreserve,
d3d_device7_EndStateBlock_FPUPreserve,
d3d_device7_PreLoad_FPUPreserve,
d3d_device7_DrawPrimitive_FPUPreserve,
d3d_device7_DrawIndexedPrimitive_FPUPreserve,
d3d_device7_SetClipStatus,
d3d_device7_GetClipStatus,
d3d_device7_DrawPrimitiveStrided_FPUPreserve,
d3d_device7_DrawIndexedPrimitiveStrided_FPUPreserve,
d3d_device7_DrawPrimitiveVB_FPUPreserve,
d3d_device7_DrawIndexedPrimitiveVB_FPUPreserve,
d3d_device7_ComputeSphereVisibility,
d3d_device7_GetTexture_FPUPreserve,
d3d_device7_SetTexture_FPUPreserve,
d3d_device7_GetTextureStageState_FPUPreserve,
d3d_device7_SetTextureStageState_FPUPreserve,
d3d_device7_ValidateDevice_FPUPreserve,
d3d_device7_ApplyStateBlock_FPUPreserve,
d3d_device7_CaptureStateBlock_FPUPreserve,
d3d_device7_DeleteStateBlock_FPUPreserve,
d3d_device7_CreateStateBlock_FPUPreserve,
d3d_device7_Load_FPUPreserve,
d3d_device7_LightEnable_FPUPreserve,
d3d_device7_GetLightEnable_FPUPreserve,
d3d_device7_SetClipPlane_FPUPreserve,
d3d_device7_GetClipPlane_FPUPreserve,
d3d_device7_GetInfo
};
static const struct IDirect3DDevice3Vtbl d3d_device3_vtbl =
{
/*** IUnknown Methods ***/
d3d_device3_QueryInterface,
d3d_device3_AddRef,
d3d_device3_Release,
/*** IDirect3DDevice3 ***/
d3d_device3_GetCaps,
d3d_device3_GetStats,
d3d_device3_AddViewport,
d3d_device3_DeleteViewport,
d3d_device3_NextViewport,
d3d_device3_EnumTextureFormats,
d3d_device3_BeginScene,
d3d_device3_EndScene,
d3d_device3_GetDirect3D,
d3d_device3_SetCurrentViewport,
d3d_device3_GetCurrentViewport,
d3d_device3_SetRenderTarget,
d3d_device3_GetRenderTarget,
d3d_device3_Begin,
d3d_device3_BeginIndexed,
d3d_device3_Vertex,
d3d_device3_Index,
d3d_device3_End,
d3d_device3_GetRenderState,
d3d_device3_SetRenderState,
d3d_device3_GetLightState,
d3d_device3_SetLightState,
d3d_device3_SetTransform,
d3d_device3_GetTransform,
d3d_device3_MultiplyTransform,
d3d_device3_DrawPrimitive,
d3d_device3_DrawIndexedPrimitive,
d3d_device3_SetClipStatus,
d3d_device3_GetClipStatus,
d3d_device3_DrawPrimitiveStrided,
d3d_device3_DrawIndexedPrimitiveStrided,
d3d_device3_DrawPrimitiveVB,
d3d_device3_DrawIndexedPrimitiveVB,
d3d_device3_ComputeSphereVisibility,
d3d_device3_GetTexture,
d3d_device3_SetTexture,
d3d_device3_GetTextureStageState,
d3d_device3_SetTextureStageState,
d3d_device3_ValidateDevice
};
static const struct IDirect3DDevice2Vtbl d3d_device2_vtbl =
{
/*** IUnknown Methods ***/
d3d_device2_QueryInterface,
d3d_device2_AddRef,
d3d_device2_Release,
/*** IDirect3DDevice2 ***/
d3d_device2_GetCaps,
d3d_device2_SwapTextureHandles,
d3d_device2_GetStats,
d3d_device2_AddViewport,
d3d_device2_DeleteViewport,
d3d_device2_NextViewport,
d3d_device2_EnumTextureFormats,
d3d_device2_BeginScene,
d3d_device2_EndScene,
d3d_device2_GetDirect3D,
d3d_device2_SetCurrentViewport,
d3d_device2_GetCurrentViewport,
d3d_device2_SetRenderTarget,
d3d_device2_GetRenderTarget,
d3d_device2_Begin,
d3d_device2_BeginIndexed,
d3d_device2_Vertex,
d3d_device2_Index,
d3d_device2_End,
d3d_device2_GetRenderState,
d3d_device2_SetRenderState,
d3d_device2_GetLightState,
d3d_device2_SetLightState,
d3d_device2_SetTransform,
d3d_device2_GetTransform,
d3d_device2_MultiplyTransform,
d3d_device2_DrawPrimitive,
d3d_device2_DrawIndexedPrimitive,
d3d_device2_SetClipStatus,
d3d_device2_GetClipStatus
};
static const struct IDirect3DDeviceVtbl d3d_device1_vtbl =
{
/*** IUnknown Methods ***/
d3d_device1_QueryInterface,
d3d_device1_AddRef,
d3d_device1_Release,
/*** IDirect3DDevice1 ***/
d3d_device1_Initialize,
d3d_device1_GetCaps,
d3d_device1_SwapTextureHandles,
d3d_device1_CreateExecuteBuffer,
d3d_device1_GetStats,
d3d_device1_Execute,
d3d_device1_AddViewport,
d3d_device1_DeleteViewport,
d3d_device1_NextViewport,
d3d_device1_Pick,
d3d_device1_GetPickRecords,
d3d_device1_EnumTextureFormats,
d3d_device1_CreateMatrix,
d3d_device1_SetMatrix,
d3d_device1_GetMatrix,
d3d_device1_DeleteMatrix,
d3d_device1_BeginScene,
d3d_device1_EndScene,
d3d_device1_GetDirect3D
};
static const struct IUnknownVtbl d3d_device_inner_vtbl =
{
d3d_device_inner_QueryInterface,
d3d_device_inner_AddRef,
d3d_device_inner_Release,
};
struct d3d_device *unsafe_impl_from_IDirect3DDevice7(IDirect3DDevice7 *iface)
{
if (!iface) return NULL;
assert((iface->lpVtbl == &d3d_device7_fpu_preserve_vtbl) || (iface->lpVtbl == &d3d_device7_fpu_setup_vtbl));
return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice7_iface);
}
struct d3d_device *unsafe_impl_from_IDirect3DDevice3(IDirect3DDevice3 *iface)
{
if (!iface) return NULL;
assert(iface->lpVtbl == &d3d_device3_vtbl);
return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice3_iface);
}
struct d3d_device *unsafe_impl_from_IDirect3DDevice2(IDirect3DDevice2 *iface)
{
if (!iface) return NULL;
assert(iface->lpVtbl == &d3d_device2_vtbl);
return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice2_iface);
}
struct d3d_device *unsafe_impl_from_IDirect3DDevice(IDirect3DDevice *iface)
{
if (!iface) return NULL;
assert(iface->lpVtbl == &d3d_device1_vtbl);
return CONTAINING_RECORD(iface, struct d3d_device, IDirect3DDevice_iface);
}
enum wined3d_depth_buffer_type d3d_device_update_depth_stencil(struct d3d_device *device)
{
IDirectDrawSurface7 *depthStencil = NULL;
IDirectDrawSurface7 *render_target;
static DDSCAPS2 depthcaps = { DDSCAPS_ZBUFFER, 0, 0, {0} };
struct ddraw_surface *dsi;
if (device->rt_iface && SUCCEEDED(IUnknown_QueryInterface(device->rt_iface,
&IID_IDirectDrawSurface7, (void **)&render_target)))
{
IDirectDrawSurface7_GetAttachedSurface(render_target, &depthcaps, &depthStencil);
IDirectDrawSurface7_Release(render_target);
}
if (!depthStencil)
{
TRACE("Setting wined3d depth stencil to NULL\n");
wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
return WINED3D_ZB_FALSE;
}
dsi = impl_from_IDirectDrawSurface7(depthStencil);
wined3d_device_set_depth_stencil_view(device->wined3d_device,
ddraw_surface_get_rendertarget_view(dsi));
IDirectDrawSurface7_Release(depthStencil);
return WINED3D_ZB_TRUE;
}
static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
struct ddraw_surface *target, IUnknown *rt_iface, UINT version, IUnknown *outer_unknown)
{
static const D3DMATRIX ident =
{
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
HRESULT hr;
if (ddraw->cooperative_level & DDSCL_FPUPRESERVE)
device->IDirect3DDevice7_iface.lpVtbl = &d3d_device7_fpu_preserve_vtbl;
else
device->IDirect3DDevice7_iface.lpVtbl = &d3d_device7_fpu_setup_vtbl;
device->IDirect3DDevice3_iface.lpVtbl = &d3d_device3_vtbl;
device->IDirect3DDevice2_iface.lpVtbl = &d3d_device2_vtbl;
device->IDirect3DDevice_iface.lpVtbl = &d3d_device1_vtbl;
device->IUnknown_inner.lpVtbl = &d3d_device_inner_vtbl;
device->ref = 1;
device->version = version;
if (outer_unknown)
device->outer_unknown = outer_unknown;
else
device->outer_unknown = &device->IUnknown_inner;
device->ddraw = ddraw;
list_init(&device->viewport_list);
if (!ddraw_handle_table_init(&device->handle_table, 64))
{
ERR("Failed to initialize handle table.\n");
return DDERR_OUTOFMEMORY;
}
device->legacyTextureBlending = FALSE;
device->legacy_projection = ident;
device->legacy_clipspace = ident;
/* This is for convenience. */
device->wined3d_device = ddraw->wined3d_device;
wined3d_device_incref(ddraw->wined3d_device);
/* Render to the back buffer */
if (FAILED(hr = wined3d_device_set_rendertarget_view(ddraw->wined3d_device,
0, ddraw_surface_get_rendertarget_view(target), TRUE)))
{
ERR("Failed to set render target, hr %#x.\n", hr);
ddraw_handle_table_destroy(&device->handle_table);
return hr;
}
device->rt_iface = rt_iface;
if (version != 1)
IUnknown_AddRef(device->rt_iface);
ddraw->d3ddevice = device;
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_ZENABLE,
d3d_device_update_depth_stencil(device));
if (version == 1) /* Color keying is initially enabled for version 1 devices. */
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_COLORKEYENABLE, TRUE);
else if (version == 2)
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_SPECULARENABLE, TRUE);
if (version < 7)
wined3d_device_set_render_state(ddraw->wined3d_device, WINED3D_RS_NORMALIZENORMALS, TRUE);
return D3D_OK;
}
HRESULT d3d_device_create(struct ddraw *ddraw, struct ddraw_surface *target, IUnknown *rt_iface,
UINT version, struct d3d_device **device, IUnknown *outer_unknown)
{
struct d3d_device *object;
HRESULT hr;
TRACE("ddraw %p, target %p, version %u, device %p, outer_unknown %p.\n",
ddraw, target, version, device, outer_unknown);
if (!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_3DDEVICE)
|| (target->surface_desc.ddsCaps.dwCaps & DDSCAPS_ZBUFFER))
{
WARN("Surface %p is not a render target.\n", target);
return DDERR_INVALIDCAPS;
}
if (!validate_surface_palette(target))
{
WARN("Surface %p has an indexed pixel format, but no palette.\n", target);
return DDERR_NOPALETTEATTACHED;
}
if (!(target->surface_desc.ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY))
{
WARN("Surface %p is not in video memory.\n", target);
return D3DERR_SURFACENOTINVIDMEM;
}
if (ddraw->flags & DDRAW_NO3D)
{
ERR_(winediag)("The application wants to create a Direct3D device, "
"but the current DirectDrawRenderer does not support this.\n");
return DDERR_NO3D;
}
if (ddraw->d3ddevice)
{
FIXME("Only one Direct3D device per DirectDraw object supported.\n");
return DDERR_INVALIDPARAMS;
}
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (!object)
{
ERR("Failed to allocate device memory.\n");
return DDERR_OUTOFMEMORY;
}
if (FAILED(hr = d3d_device_init(object, ddraw, target, rt_iface, version, outer_unknown)))
{
WARN("Failed to initialize device, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
TRACE("Created device %p.\n", object);
*device = object;
return D3D_OK;
}
|