aboutsummaryrefslogblamecommitdiffstats
path: root/Game/Code/lib/DSPack/DirectX9/Direct3D.pas
blob: 629a03fe904f2e3da8b7c65e4530f6e9104ae8e6 (plain) (tree)
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








































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                      
{******************************************************************************}
{*                                                                            *}
{*  Copyright (C) Microsoft Corporation.  All Rights Reserved.                *}
{*                                                                            *}
{*  Files:      d3dtypes.h d3dcaps.h d3d.h                                    *}
{*  Content:    Direct3D8 include files                                       *}
{*                                                                            *}
{*  DirectX 9.0 Delphi adaptation by Alexey Barkovoy                          *}
{*  E-Mail: clootie@reactor.ru                                                *}
{*                                                                            *}
{*  Modified: 26-Jan-2003                                                     *}
{*                                                                            *}
{*  Partly based upon :                                                       *}
{*    DirectX 7.0 Object Pascal adaptation by                                 *}
{*      Erik Unger, e-Mail: DelphiDirectX@next-reality.com                    *}
{*                                                                            *}
{*  Latest version can be downloaded from:                                    *}
{*     http://clootie.narod.ru/delphi/                                        *}
{*                                                                            *}
{******************************************************************************}
{                                                                              }
{ Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI)        }
{                                                                              }
{ The contents of this file are used with permission, subject to the Mozilla   }
{ Public License Version 1.1 (the "License"); you may not use this file except }
{ in compliance with the License. You may obtain a copy of the License at      }
{ http://www.mozilla.org/MPL/MPL-1.1.html                                      }
{                                                                              }
{ Software distributed under the License is distributed on an "AS IS" basis,   }
{ WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
{ the specific language governing rights and limitations under the License.    }
{                                                                              }
{ Alternatively, the contents of this file may be used under the terms of the  }
{ GNU Lesser General Public License (the  "LGPL License"), in which case the   }
{ provisions of the LGPL License are applicable instead of those above.        }
{ If you wish to allow use of your version of this file only under the terms   }
{ of the LGPL License and not to allow others to use your version of this file }
{ under the MPL, indicate your decision by deleting  the provisions above and  }
{ replace  them with the notice and other provisions required by the LGPL      }
{ License.  If you do not delete the provisions above, a recipient may use     }
{ your version of this file under either the MPL or the LGPL License.          }
{                                                                              }
{ For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
{                                                                              }
{******************************************************************************}

///////////////////////////////////////////////////////////////////////////////
// Notes:
//----------------------------------------------------------------------------
// Possible input defines for this file, mapped to original C values:
//   DIRECT3D_VERSION_8 : DIRECT3D_VERSION = 0x0800,
//   DIRECT3D_VERSION_7 : DIRECT3D_VERSION = 0x0700,
//   DIRECT3D_VERSION_6 : DIRECT3D_VERSION = 0x0600,
//   DIRECT3D_VERSION_5 : DIRECT3D_VERSION = 0x0500,
//   DIRECT3D_VERSION_LESS_5 : DIRECT3D_VERSION < 0x0500,
//
// By default DIRECT3D_VERSION_7 (DIRECT3D_VERSION = 0x0700) is assumed
///////////////////////////////////////////////////////////////////////////////

unit Direct3D;

{$I DirectX.inc}

// Remove "dots" below to exclude DXFile interfaces - these interfaces
// are included for compatibility with original Erik Unger translation
{$DEFINE EXCLUDE_DXFILE_FROM_DIRECT3D}

// Assume for what Direct3D version we will compile headers
{$IFNDEF DIRECT3D_VERSION_8}
  {$IFNDEF DIRECT3D_VERSION_7}
    {$IFNDEF DIRECT3D_VERSION_6}
      {$IFNDEF DIRECT3D_VERSION_5}
        {$IFNDEF DIRECT3D_VERSION_LESS_5}
          {$DEFINE DIRECT3D_VERSION_7} // Compiling for Direct3D7 by default
        {$ENDIF}
      {$ENDIF}
    {$ENDIF}
  {$ENDIF}
{$ENDIF}

// Emit conditionals to C++Builder compiler
{$IFDEF DIRECT3D_VERSION_8}
  {$HPPEMIT '#define DIRECT3D_VERSION         0x0800'}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_7}
  {$HPPEMIT '#define DIRECT3D_VERSION         0x0700'}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT '#define DIRECT3D_VERSION         0x0600'}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT '#define DIRECT3D_VERSION         0x0500'}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_LESS_5}
  {$HPPEMIT '#define DIRECT3D_VERSION         0x0300'}
{$ENDIF}

// Define symbols for '>=' comparision
{$IFDEF DIRECT3D_VERSION_8}
  {$DEFINE DIRECT3D_VERSION_7}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_7}
  {$DEFINE DIRECT3D_VERSION_6}
{$ENDIF}
{$IFDEF DIRECT3D_VERSION_6}
  {$DEFINE DIRECT3D_VERSION_5}
{$ENDIF}

// Define symbols for '<' comparision
{$IFNDEF DIRECT3D_VERSION_8}
  {$DEFINE DIRECT3D_VERSION_LESS_8}
{$ENDIF}
{$IFNDEF DIRECT3D_VERSION_7}
  {$DEFINE DIRECT3D_VERSION_LESS_7}
{$ENDIF}
{$IFNDEF DIRECT3D_VERSION_6}
  {$DEFINE DIRECT3D_VERSION_LESS_6}
{$ENDIF}
{$IFNDEF DIRECT3D_VERSION_5}
  {$DEFINE DIRECT3D_VERSION_LESS_5}
{$ENDIF}

interface

uses
  Windows, DXTypes, DirectDraw{$IFDEF DIRECT3D_VERSION_8}, Direct3D8{$ENDIF};

{$NOINCLUDE Windows}
{$NOINCLUDE DXTypes}
{$NOINCLUDE DirectDraw}
{$IFDEF DIRECT3D_VERSION_8}
  {$NOINCLUDE Direct3D8}
{$ENDIF}

{$HPPEMIT '#include "d3d.h"'}
{$HPPEMIT '#include "d3dtypes.h"'}
{$HPPEMIT '#include "d3dcaps.h"'}

(* TD3DValue is the fundamental Direct3D fractional data type *)

type
  TRefClsID = TGUID;

type
  D3DVALUE = DXTypes.D3DVALUE;
  {$EXTERNALSYM D3DVALUE}
  TD3DValue = DXTypes.TD3DValue;
  {$NODEFINE TD3DValue}
  PD3DValue = DXTypes.PD3DValue;
  {$NODEFINE PD3DValue}

  D3DFIXED = Longint;
  {$EXTERNALSYM D3DFIXED}
  TD3DFixed = D3DFIXED;

  float = TD3DValue;
  {$EXTERNALSYM float}

  D3DCOLOR = DXTypes.D3DCOLOR;
  {$EXTERNALSYM D3DCOLOR}
  TD3DColor = DXTypes.TD3DColor;
  {$NODEFINE TD3DColor}
  PD3DColor = DXTypes.PD3DColor;
  {$NODEFINE PD3DColor}

function D3DVal(val: Variant): Single;
{$EXTERNALSYM D3DVal}
function D3DDivide(a, b: Double): Single;
{$EXTERNALSYM D3DDivide}
function D3DMultiply(a, b: Double): Single;
{$EXTERNALSYM D3DMultiply}

(*
 * Format of CI colors is
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  |    alpha      |         color index           |   fraction    |
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *)

// #define CI_GETALPHA(ci)    ((ci) >> 24)
function CI_GETALPHA(ci: DWORD): DWORD;
{$EXTERNALSYM CI_GETALPHA}

// #define CI_GETINDEX(ci)    (((ci) >> 8) & 0xffff)
function CI_GETINDEX(ci: DWORD): DWORD;
{$EXTERNALSYM CI_GETINDEX}

// #define CI_GETFRACTION(ci) ((ci) & 0xff)
function CI_GETFRACTION(ci: DWORD): DWORD;
{$EXTERNALSYM CI_GETFRACTION}

// #define CI_ROUNDINDEX(ci)  CI_GETINDEX((ci) + 0x80)
function CI_ROUNDINDEX(ci: DWORD): DWORD;
{$EXTERNALSYM CI_ROUNDINDEX}

// #define CI_MASKALPHA(ci)   ((ci) & 0xffffff)
function CI_MASKALPHA(ci: DWORD): DWORD;
{$EXTERNALSYM CI_MASKALPHA}

// #define CI_MAKE(a, i, f)    (((a) << 24) | ((i) << 8) | (f))
function CI_MAKE(a,i,f: DWORD): DWORD;
{$EXTERNALSYM CI_MAKE}

(*
 * Format of RGBA colors is
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  |    alpha      |      red      |     green     |     blue      |
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *)

// #define RGBA_GETALPHA(rgb)      ((rgb) >> 24)
function RGBA_GETALPHA(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGBA_GETALPHA}

// #define RGBA_GETRED(rgb)        (((rgb) >> 16) & 0xff)
function RGBA_GETRED(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGBA_GETRED}

// #define RGBA_GETGREEN(rgb)      (((rgb) >> 8) & 0xff)
function RGBA_GETGREEN(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGBA_GETGREEN}

// #define RGBA_GETBLUE(rgb)       ((rgb) & 0xff)
function RGBA_GETBLUE(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGBA_GETBLUE}

// #define RGBA_MAKE(r, g, b, a)   ((TD3DColor) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
function RGBA_MAKE(r, g, b, a: DWORD): TD3DColor;
{$EXTERNALSYM RGBA_MAKE}

(* D3DRGB and D3DRGBA may be used as initialisers for D3DCOLORs
 * The float values must be in the range 0..1
 *)

// #define D3DRGB(r, g, b) \
//     (0xff000000L | (((long)((r) * 255)) << 16) | (((long)((g) * 255)) << 8) | (long)((b) * 255))
function D3DRGB(r, g, b: Single): TD3DColor;
{$EXTERNALSYM D3DRGB}

// #define D3DRGBA(r, g, b, a) \
//     (  (((long)((a) * 255)) << 24) | (((long)((r) * 255)) << 16) \
//     |   (((long)((g) * 255)) << 8) | (long)((b) * 255) \
//    )
function D3DRGBA(r, g, b, a: Single): TD3DColor;
{$EXTERNALSYM D3DRGBA}

(*
 * Format of RGB colors is
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *  |    ignored    |      red      |     green     |     blue      |
 *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 *)

// #define RGB_GETRED(rgb)         (((rgb) >> 16) & 0xff)
function RGB_GETRED(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGB_GETRED}

// #define RGB_GETGREEN(rgb)       (((rgb) >> 8) & 0xff)
function RGB_GETGREEN(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGB_GETGREEN}

// #define RGB_GETBLUE(rgb)        ((rgb) & 0xff)
function RGB_GETBLUE(rgb: TD3DColor): DWORD;
{$EXTERNALSYM RGB_GETBLUE}

// #define RGBA_SETALPHA(rgba, x) (((x) << 24) | ((rgba) & 0x00ffffff))
function RGBA_SETALPHA(rgba: TD3DColor; x: DWORD): TD3DColor;
{$EXTERNALSYM RGBA_SETALPHA}

// #define RGB_MAKE(r, g, b)       ((TD3DColor) (((r) << 16) | ((g) << 8) | (b)))
function RGB_MAKE(r, g, b: DWORD): TD3DColor;
{$EXTERNALSYM RGB_MAKE}

// #define RGBA_TORGB(rgba)       ((TD3DColor) ((rgba) & 0xffffff))
function RGBA_TORGB(rgba: TD3DColor): TD3DColor;
{$EXTERNALSYM RGBA_TORGB}

// #define RGB_TORGBA(rgb)        ((TD3DColor) ((rgb) | 0xff000000))
function RGB_TORGBA(rgb: TD3DColor): TD3DColor;
{$EXTERNALSYM RGB_TORGBA}

(*
 * Flags for Enumerate functions
 *)
const

(*
 * Stop the enumeration
 *)

  D3DENUMRET_CANCEL                        = DDENUMRET_CANCEL;
  {$EXTERNALSYM D3DENUMRET_CANCEL}

(*
 * Continue the enumeration
 *)

  D3DENUMRET_OK                            = DDENUMRET_OK;
  {$EXTERNALSYM D3DENUMRET_OK}

type
  TD3DValidateCallback = function (lpUserArg: Pointer;
      dwOffset: DWORD): HResult; stdcall;
  {$NODEFINE TD3DValidateCallback}
  {$HPPEMIT 'typedef LPD3DVALIDATECALLBACK TD3DValidateCallback;'}

  TD3DEnumTextureFormatsCallback = function (var lpDdsd: TDDSurfaceDesc;
      lpContext: Pointer): HResult; stdcall;
  {$NODEFINE TD3DEnumTextureFormatsCallback}
  {$HPPEMIT 'typedef LPD3DENUMTEXTUREFORMATSCALLBACK TD3DEnumTextureFormatsCallback;'}

  TD3DEnumPixelFormatsCallback = function (var lpDDPixFmt: TDDPixelFormat;
      lpContext: Pointer): HResult; stdcall;
  {$NODEFINE TD3DEnumPixelFormatsCallback}
  {$HPPEMIT 'typedef LPD3DENUMPIXELFORMATSCALLBACK TD3DEnumPixelFormatsCallback;'}

  PD3DMaterialHandle = ^TD3DMaterialHandle;
  TD3DMaterialHandle = DWORD;

  PD3DTextureHandle = ^TD3DTextureHandle;
  TD3DTextureHandle = DWORD;

  PD3DMatrixHandle = ^TD3DMatrixHandle;
  TD3DMatrixHandle = DWORD;


  PD3DColorValue = ^TD3DColorValue;
  _D3DCOLORVALUE = packed record
    case Integer of
    0: (
      r: TD3DValue;
      g: TD3DValue;
      b: TD3DValue;
      a: TD3DValue;
     );
    1: (
      dvR: TD3DValue;
      dvG: TD3DValue;
      dvB: TD3DValue;
      dvA: TD3DValue;
     );
  end {_D3DCOLORVALUE};
  {$EXTERNALSYM _D3DCOLORVALUE}
  D3DCOLORVALUE = _D3DCOLORVALUE;
  {$EXTERNALSYM D3DCOLORVALUE}
  TD3DColorValue = _D3DCOLORVALUE;


  PD3DRect = ^TD3DRect;
  _D3DRECT = packed record
    case Integer of
    0: (
      x1: LongInt;
      y1: LongInt;
      x2: LongInt;
      y2: LongInt;
     );
    1: (
      lX1: LongInt;
      lY1: LongInt;
      lX2: LongInt;
      lY2: LongInt;
     );
     2: (
       a: array[0..3] of LongInt;
     );
  end {_D3DRECT};
  {$EXTERNALSYM _D3DRECT}
  D3DRECT = _D3DRECT;
  {$EXTERNALSYM D3DRECT}
  TD3DRect = _D3DRECT;


  PD3DVector = ^TD3DVector;
  _D3DVECTOR = packed record
    case Integer of
    0: (
      x: TD3DValue;
      y: TD3DValue;
      z: TD3DValue;
     );
    1: (
      dvX: TD3DValue;
      dvY: TD3DValue;
      dvZ: TD3DValue;
     );
  end {_D3DVECTOR};
  {$EXTERNALSYM _D3DVECTOR}
  D3DVECTOR = _D3DVECTOR;
  {$EXTERNALSYM D3DVECTOR}
  TD3DVector = _D3DVECTOR;

{$HPPEMIT ''}
{$HPPEMIT '#ifndef DX_SHARED_DEFINES_BCB'}
{$HPPEMIT ''}
{$HPPEMIT 'typedef D3DVALUE TD3DValue;'}
{$HPPEMIT 'typedef D3DVALUE *PD3DValue;'}
{$HPPEMIT ''}
{$HPPEMIT '#ifndef D3DCOLOR_DEFINED_BCB'}
{$HPPEMIT 'typedef D3DCOLOR TD3DColor;'}
{$HPPEMIT 'typedef D3DCOLOR *PD3DColor;'}
{$HPPEMIT '#define D3DCOLOR_DEFINED_BCB'}
{$HPPEMIT '#endif'}
{$HPPEMIT ''}
{$HPPEMIT '#define D3DVECTOR_DEFINED_BCB'}
{$HPPEMIT ''}
{$HPPEMIT '#define DX_SHARED_DEFINES_BCB'}
{$HPPEMIT '#endif // DX_SHARED_DEFINES_BCB'}
{$HPPEMIT ''}


(******************************************************************
 *                                                                *
 *   D3DVec.inl                                                   *
 *                                                                *
 *   float-valued 3D vector class for Direct3D.                   *
 *                                                                *
 *   Copyright (c) 1996-1998 Microsoft Corp. All rights reserved. *
 *                                                                *
 ******************************************************************)

    // Addition and subtraction
  function VectorAdd(const v1, v2: TD3DVector): TD3DVector;
  function VectorSub(const v1, v2: TD3DVector): TD3DVector;
    // Scalar multiplication and division
  function VectorMulS(const v: TD3DVector; s: TD3DValue): TD3DVector;
  function VectorDivS(const v: TD3DVector; s: TD3DValue): TD3DVector;
    // Memberwise multiplication and division
  function VectorMul(const v1, v2: TD3DVector): TD3DVector;
  function VectorDiv(const v1, v2: TD3DVector): TD3DVector;
    // Vector dominance
  function VectorSmaller(v1, v2: TD3DVector): Boolean;
  function VectorSmallerEqual(v1, v2: TD3DVector): Boolean;
    // Bitwise equality
  function VectorEqual(v1, v2: TD3DVector): Boolean;
    // Length-related functions
  function VectorSquareMagnitude(v: TD3DVector): TD3DValue;
  function VectorMagnitude(v: TD3DVector): TD3DValue;
    // Returns vector with same direction and unit length
  function VectorNormalize(const v: TD3DVector): TD3DVector;
    // Return min/max component of the input vector
  function VectorMin(v: TD3DVector): TD3DValue;
  function VectorMax(v: TD3DVector): TD3DValue;
    // Return memberwise min/max of input vectors
  function VectorMinimize(const v1, v2: TD3DVector): TD3DVector;
  function VectorMaximize(const v1, v2: TD3DVector): TD3DVector;
    // Dot and cross product
  function VectorDotProduct(v1, v2: TD3DVector): TD3DValue;
  function VectorCrossProduct(const v1, v2: TD3DVector): TD3DVector;

type
(*
 * Vertex data types supported in an ExecuteBuffer.
 *)

(*
 * Homogeneous vertices
 *)

  PD3DHVertex = ^TD3DHVertex;
  _D3DHVERTEX = packed record
    dwFlags: DWORD;        (* Homogeneous clipping flags *)
    case Integer of
    0: (
      hx: TD3DValue;
      hy: TD3DValue;
      hz: TD3DValue;
     );
    1: (
      dvHX: TD3DValue;
      dvHY: TD3DValue;
      dvHZ: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DHVERTEX}
  D3DHVERTEX = _D3DHVERTEX;
  {$EXTERNALSYM D3DHVERTEX}
  TD3DHVertex = _D3DHVERTEX;


(*
 * Transformed/lit vertices
 *)

  PD3DTLVertex = ^TD3DTLVertex;
  _D3DTLVERTEX = packed record
    case Integer of
    0: (
      sx: TD3DValue;             (* Screen coordinates *)
      sy: TD3DValue;
      sz: TD3DValue;
      rhw: TD3DValue;            (* Reciprocal of homogeneous w *)
      color: TD3DColor;          (* Vertex color *)
      specular: TD3DColor;       (* Specular component of vertex *)
      tu: TD3DValue;             (* Texture coordinates *)
      tv: TD3DValue;
     );
    1: (
      dvSX: TD3DValue;
      dvSY: TD3DValue;
      dvSZ: TD3DValue;
      dvRHW: TD3DValue;
      dcColor: TD3DColor;
      dcSpecular: TD3DColor;
      dvTU: TD3DValue;
      dvTV: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DTLVERTEX}
  D3DTLVERTEX = _D3DTLVERTEX;
  {$EXTERNALSYM D3DTLVERTEX}
  TD3DTLVertex = _D3DTLVERTEX;

(*
 * Untransformed/lit vertices
 *)

  PD3DLVertex = ^TD3DLVertex;
  _D3DLVERTEX = packed record
    case Integer of
    0: (
      x: TD3DValue;             (* Homogeneous coordinates *)
      y: TD3DValue;
      z: TD3DValue;
      dwReserved: DWORD;
      color: TD3DColor;         (* Vertex color *)
      specular: TD3DColor;      (* Specular component of vertex *)
      tu: TD3DValue;            (* Texture coordinates *)
      tv: TD3DValue;
     );
    1: (
      dvX: TD3DValue;
      dvY: TD3DValue;
      dvZ: TD3DValue;
      UNIONFILLER1d: DWORD;
      dcColor: TD3DColor;
      dcSpecular: TD3DColor;
      dvTU: TD3DValue;
      dvTV: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DLVERTEX}
  D3DLVERTEX = _D3DLVERTEX;
  {$EXTERNALSYM D3DLVERTEX}
  TD3DLVertex = _D3DLVERTEX;


(*
 * Untransformed/unlit vertices
 *)

  PD3DVertex = ^TD3DVertex;
  _D3DVERTEX = packed record
    case Integer of
    0: (
      x: TD3DValue;             (* Homogeneous coordinates *)
      y: TD3DValue;
      z: TD3DValue;
      nx: TD3DValue;            (* Normal *)
      ny: TD3DValue;
      nz: TD3DValue;
      tu: TD3DValue;            (* Texture coordinates *)
      tv: TD3DValue;
     );
    1: (
      dvX: TD3DValue;
      dvY: TD3DValue;
      dvZ: TD3DValue;
      dvNX: TD3DValue;
      dvNY: TD3DValue;
      dvNZ: TD3DValue;
      dvTU: TD3DValue;
      dvTV: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DVERTEX}
  D3DVERTEX = _D3DVERTEX;
  {$EXTERNALSYM D3DVERTEX}
  TD3DVertex = _D3DVERTEX;

(*
 * Matrix, viewport, and tranformation structures and definitions.
 *)

  PD3DMatrix = ^TD3DMatrix;
  _D3DMATRIX = packed record
    case integer of
      0 : (_11, _12, _13, _14: TD3DValue;
           _21, _22, _23, _24: TD3DValue;
           _31, _32, _33, _34: TD3DValue;
           _41, _42, _43, _44: TD3DValue);
      1 : (m : array [0..3, 0..3] of TD3DValue);
  end {_D3DMATRIX};
  {$EXTERNALSYM _D3DMATRIX}
  D3DMATRIX = _D3DMATRIX;
  {$EXTERNALSYM D3DMATRIX}
  TD3DMatrix = _D3DMATRIX;

  PD3DViewport = ^TD3DViewport;
  _D3DVIEWPORT = packed record
    dwSize: DWORD;
    dwX: DWORD;
    dwY: DWORD;                (* Top left *)
    dwWidth: DWORD;
    dwHeight: DWORD;           (* Dimensions *)
    dvScaleX: TD3DValue;       (* Scale homogeneous to screen *)
    dvScaleY: TD3DValue;       (* Scale homogeneous to screen *)
    dvMaxX: TD3DValue;         (* Min/max homogeneous x coord *)
    dvMaxY: TD3DValue;         (* Min/max homogeneous y coord *)
    dvMinZ: TD3DValue;
    dvMaxZ: TD3DValue;         (* Min/max homogeneous z coord *)
  end {_D3DVIEWPORT};
  {$EXTERNALSYM _D3DVIEWPORT}
  D3DVIEWPORT = _D3DVIEWPORT;
  {$EXTERNALSYM D3DVIEWPORT}
  TD3DViewport = _D3DVIEWPORT;


{$IFDEF DIRECT3D_VERSION_5}
  PD3DViewport2 = ^TD3DViewport2;
  _D3DVIEWPORT2 = packed record
    dwSize: DWORD;
    dwX: DWORD;
    dwY: DWORD;                (* Viewport Top left *)
    dwWidth: DWORD;
    dwHeight: DWORD;           (* Viewport Dimensions *)
    dvClipX: TD3DValue;	       (* Top left of clip volume *)
    dvClipY: TD3DValue;
    dvClipWidth: TD3DValue;    (* Clip Volume Dimensions *)
    dvClipHeight: TD3DValue;
    dvMinZ: TD3DValue;         (* Min/max of clip Volume *)
    dvMaxZ: TD3DValue;
  end;
  {$EXTERNALSYM _D3DVIEWPORT2}
  D3DVIEWPORT2 = _D3DVIEWPORT2;
  {$EXTERNALSYM D3DVIEWPORT2}
  TD3DViewport2 = _D3DVIEWPORT2;
{$ENDIF} // DIRECT3D_VERSION_5


{$IFDEF DIRECT3D_VERSION_7}
  PD3DViewport7 = ^TD3DViewport7;
  _D3DVIEWPORT7 = packed record
    dwX: DWORD;
    dwY: DWORD;                (* Viewport Top left *)
    dwWidth: DWORD;
    dwHeight: DWORD;           (* Viewport Dimensions *)
    dvMinZ: TD3DValue;         (* Min/max of clip Volume *)
    dvMaxZ: TD3DValue;
  end;
  {$EXTERNALSYM _D3DVIEWPORT7}
  D3DVIEWPORT7 = _D3DVIEWPORT7;
  {$EXTERNALSYM D3DVIEWPORT7}
  TD3DViewport7 = _D3DVIEWPORT7;
{$ENDIF} // DIRECT3D_VERSION_7

(*
 * Values for clip fields.
 *)

{$IFDEF DIRECT3D_VERSION_7}

const
// Max number of user clipping planes, supported in D3D.
  D3DMAXUSERCLIPPLANES  = 32;
  {$EXTERNALSYM D3DMAXUSERCLIPPLANES}

// These bits could be ORed together to use with D3DRENDERSTATE_CLIPPLANEENABLE
//
  D3DCLIPPLANE0 = (1 shl 0);
  {$EXTERNALSYM D3DCLIPPLANE0}
  D3DCLIPPLANE1 = (1 shl 1);
  {$EXTERNALSYM D3DCLIPPLANE1}
  D3DCLIPPLANE2 = (1 shl 2);
  {$EXTERNALSYM D3DCLIPPLANE2}
  D3DCLIPPLANE3 = (1 shl 3);
  {$EXTERNALSYM D3DCLIPPLANE3}
  D3DCLIPPLANE4 = (1 shl 4);
  {$EXTERNALSYM D3DCLIPPLANE4}
  D3DCLIPPLANE5 = (1 shl 5);
  {$EXTERNALSYM D3DCLIPPLANE5}

{$ENDIF} // DIRECT3D_VERSION_7

const
  D3DCLIP_LEFT                            = $00000001;
  {$EXTERNALSYM D3DCLIP_LEFT}
  D3DCLIP_RIGHT                           = $00000002;
  {$EXTERNALSYM D3DCLIP_RIGHT}
  D3DCLIP_TOP                             = $00000004;
  {$EXTERNALSYM D3DCLIP_TOP}
  D3DCLIP_BOTTOM                          = $00000008;
  {$EXTERNALSYM D3DCLIP_BOTTOM}
  D3DCLIP_FRONT                           = $00000010;
  {$EXTERNALSYM D3DCLIP_FRONT}
  D3DCLIP_BACK                            = $00000020;
  {$EXTERNALSYM D3DCLIP_BACK}
  D3DCLIP_GEN0                            = $00000040;
  {$EXTERNALSYM D3DCLIP_GEN0}
  D3DCLIP_GEN1                            = $00000080;
  {$EXTERNALSYM D3DCLIP_GEN1}
  D3DCLIP_GEN2                            = $00000100;
  {$EXTERNALSYM D3DCLIP_GEN2}
  D3DCLIP_GEN3                            = $00000200;
  {$EXTERNALSYM D3DCLIP_GEN3}
  D3DCLIP_GEN4                            = $00000400;
  {$EXTERNALSYM D3DCLIP_GEN4}
  D3DCLIP_GEN5                            = $00000800;
  {$EXTERNALSYM D3DCLIP_GEN5}

(*
 * Values for d3d status.
 *)

  D3DSTATUS_CLIPUNIONLEFT                 = D3DCLIP_LEFT;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONLEFT}
  D3DSTATUS_CLIPUNIONRIGHT                = D3DCLIP_RIGHT;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONRIGHT}
  D3DSTATUS_CLIPUNIONTOP                  = D3DCLIP_TOP;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONTOP}
  D3DSTATUS_CLIPUNIONBOTTOM               = D3DCLIP_BOTTOM;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONBOTTOM}
  D3DSTATUS_CLIPUNIONFRONT                = D3DCLIP_FRONT;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONFRONT}
  D3DSTATUS_CLIPUNIONBACK                 = D3DCLIP_BACK;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONBACK}
  D3DSTATUS_CLIPUNIONGEN0                 = D3DCLIP_GEN0;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN0}
  D3DSTATUS_CLIPUNIONGEN1                 = D3DCLIP_GEN1;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN1}
  D3DSTATUS_CLIPUNIONGEN2                 = D3DCLIP_GEN2;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN2}
  D3DSTATUS_CLIPUNIONGEN3                 = D3DCLIP_GEN3;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN3}
  D3DSTATUS_CLIPUNIONGEN4                 = D3DCLIP_GEN4;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN4}
  D3DSTATUS_CLIPUNIONGEN5                 = D3DCLIP_GEN5;
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONGEN5}

  D3DSTATUS_CLIPINTERSECTIONLEFT          = $00001000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONLEFT}
  D3DSTATUS_CLIPINTERSECTIONRIGHT         = $00002000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONRIGHT}
  D3DSTATUS_CLIPINTERSECTIONTOP           = $00004000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONTOP}
  D3DSTATUS_CLIPINTERSECTIONBOTTOM        = $00008000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONBOTTOM}
  D3DSTATUS_CLIPINTERSECTIONFRONT         = $00010000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONFRONT}
  D3DSTATUS_CLIPINTERSECTIONBACK          = $00020000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONBACK}
  D3DSTATUS_CLIPINTERSECTIONGEN0          = $00040000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN0}
  D3DSTATUS_CLIPINTERSECTIONGEN1          = $00080000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN1}
  D3DSTATUS_CLIPINTERSECTIONGEN2          = $00100000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN2}
  D3DSTATUS_CLIPINTERSECTIONGEN3          = $00200000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN3}
  D3DSTATUS_CLIPINTERSECTIONGEN4          = $00400000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN4}
  D3DSTATUS_CLIPINTERSECTIONGEN5          = $00800000;
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONGEN5}
  D3DSTATUS_ZNOTVISIBLE                   = $01000000;
  {$EXTERNALSYM D3DSTATUS_ZNOTVISIBLE}
(* Do not use 0x80000000 for any status flags in future as it is reserved *)

  D3DSTATUS_CLIPUNIONALL = (
            D3DSTATUS_CLIPUNIONLEFT or
            D3DSTATUS_CLIPUNIONRIGHT or
            D3DSTATUS_CLIPUNIONTOP or
            D3DSTATUS_CLIPUNIONBOTTOM or
            D3DSTATUS_CLIPUNIONFRONT or
            D3DSTATUS_CLIPUNIONBACK or
            D3DSTATUS_CLIPUNIONGEN0 or
            D3DSTATUS_CLIPUNIONGEN1 or
            D3DSTATUS_CLIPUNIONGEN2 or
            D3DSTATUS_CLIPUNIONGEN3 or
            D3DSTATUS_CLIPUNIONGEN4 or
            D3DSTATUS_CLIPUNIONGEN5);
  {$EXTERNALSYM D3DSTATUS_CLIPUNIONALL}

  D3DSTATUS_CLIPINTERSECTIONALL = (
            D3DSTATUS_CLIPINTERSECTIONLEFT or
            D3DSTATUS_CLIPINTERSECTIONRIGHT or
            D3DSTATUS_CLIPINTERSECTIONTOP or
            D3DSTATUS_CLIPINTERSECTIONBOTTOM or
            D3DSTATUS_CLIPINTERSECTIONFRONT or
            D3DSTATUS_CLIPINTERSECTIONBACK or
            D3DSTATUS_CLIPINTERSECTIONGEN0 or
            D3DSTATUS_CLIPINTERSECTIONGEN1 or
            D3DSTATUS_CLIPINTERSECTIONGEN2 or
            D3DSTATUS_CLIPINTERSECTIONGEN3 or
            D3DSTATUS_CLIPINTERSECTIONGEN4 or
            D3DSTATUS_CLIPINTERSECTIONGEN5);
  {$EXTERNALSYM D3DSTATUS_CLIPINTERSECTIONALL}

  D3DSTATUS_DEFAULT = (
            D3DSTATUS_CLIPINTERSECTIONALL or
            D3DSTATUS_ZNOTVISIBLE);
  {$EXTERNALSYM D3DSTATUS_DEFAULT}

(*
 * Options for direct transform calls
 *)

  D3DTRANSFORM_CLIPPED       = $00000001;
  {$EXTERNALSYM D3DTRANSFORM_CLIPPED}
  D3DTRANSFORM_UNCLIPPED     = $00000002;
  {$EXTERNALSYM D3DTRANSFORM_UNCLIPPED}

type
  PD3DTransformData = ^TD3DTransformData;
  _D3DTRANSFORMDATA = packed record
    dwSize: DWORD;
    lpIn: Pointer;             (* Input vertices *)
    dwInSize: DWORD;           (* Stride of input vertices *)
    lpOut: Pointer;            (* Output vertices *)
    dwOutSize: DWORD;          (* Stride of output vertices *)
    lpHOut: ^TD3DHVertex;      (* Output homogeneous vertices *)
    dwClip: DWORD;             (* Clipping hint *)
    dwClipIntersection: DWORD;
    dwClipUnion: DWORD;        (* Union of all clip flags *)
    drExtent: TD3DRect;        (* Extent of transformed vertices *)
  end;
  {$EXTERNALSYM _D3DTRANSFORMDATA}
  D3DTRANSFORMDATA = _D3DTRANSFORMDATA;
  {$EXTERNALSYM D3DTRANSFORMDATA}
  TD3DTransformData = _D3DTRANSFORMDATA;

(*
 * Structure defining position and direction properties for lighting.
 *)

  PD3DLightingElement = ^TD3DLightingElement;
  _D3DLIGHTINGELEMENT = packed record
    dvPosition: TD3DVector;           (* Lightable point in model space *)
    dvNormal: TD3DVector;             (* Normalised unit vector *)
  end;
  {$EXTERNALSYM _D3DLIGHTINGELEMENT}
  D3DLIGHTINGELEMENT = _D3DLIGHTINGELEMENT;
  {$EXTERNALSYM D3DLIGHTINGELEMENT}
  TD3DLightingElement = _D3DLIGHTINGELEMENT;

(*
 * Structure defining material properties for lighting.
 *)

  PD3DMaterial = ^TD3DMaterial;
  _D3DMATERIAL = packed record
    dwSize: DWORD;
    case Integer of
    0: (
      diffuse: TD3DColorValue;        (* Diffuse color RGBA *)
      ambient: TD3DColorValue;        (* Ambient color RGB *)
      specular: TD3DColorValue;       (* Specular 'shininess' *)
      emissive: TD3DColorValue;       (* Emissive color RGB *)
      power: TD3DValue;               (* Sharpness if specular highlight *)
      hTexture: TD3DTextureHandle;    (* Handle to texture map *)
      dwRampSize: DWORD;
     );
    1: (
      dcvDiffuse: TD3DColorValue;
      dcvAmbient: TD3DColorValue;
      dcvSpecular: TD3DColorValue;
      dcvEmissive: TD3DColorValue;
      dvPower: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DMATERIAL}
  D3DMATERIAL = _D3DMATERIAL;
  {$EXTERNALSYM D3DMATERIAL}
  TD3DMaterial = _D3DMATERIAL;

{$IFDEF DIRECT3D_VERSION_7}

  PD3DMaterial7 = ^TD3DMaterial7;
  _D3DMATERIAL7 = packed record
    case Integer of
    0: (
      diffuse: TD3DColorValue;        (* Diffuse color RGBA *)
      ambient: TD3DColorValue;        (* Ambient color RGB *)
      specular: TD3DColorValue;       (* Specular 'shininess' *)
      emissive: TD3DColorValue;       (* Emissive color RGB *)
      power: TD3DValue;               (* Sharpness if specular highlight *)
     );
    1: (
      dcvDiffuse: TD3DColorValue;
      dcvAmbient: TD3DColorValue;
      dcvSpecular: TD3DColorValue;
      dcvEmissive: TD3DColorValue;
      dvPower: TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DMATERIAL7}
  D3DMATERIAL7 = _D3DMATERIAL7;
  {$EXTERNALSYM D3DMATERIAL7}
  TD3DMaterial7 = _D3DMATERIAL7;

{$ENDIF} // DIRECT3D_VERSION_7

{$IFDEF DIRECT3D_VERSION_LESS_8}

  PD3DLightType = ^TD3DLightType;
  _D3DLIGHTTYPE = (
    D3DLIGHT_INVALID_0,
    D3DLIGHT_POINT,
    D3DLIGHT_SPOT,
    D3DLIGHT_DIRECTIONAL,
// Note: The following light type (D3DLIGHT_PARALLELPOINT)
// is no longer supported from D3D for DX7 onwards.
    D3DLIGHT_PARALLELPOINT
{$IFDEF DIRECT3D_VERSION_LESS_5}, // For backward compatible headers
    D3DLIGHT_GLSPOT
{$ENDIF} // DIRECT3D_VERSION_LESS_5
  );
  {$EXTERNALSYM _D3DLIGHTTYPE}
  D3DLIGHTTYPE = _D3DLIGHTTYPE;
  {$EXTERNALSYM D3DLIGHTTYPE}
  TD3DLightType = _D3DLIGHTTYPE;

{$ELSE}
const
  D3DLIGHT_PARALLELPOINT  = TD3DLightType(4);
  {$EXTERNALSYM D3DLIGHT_PARALLELPOINT}
  D3DLIGHT_GLSPOT         = TD3DLightType(5);
  {$EXTERNALSYM D3DLIGHT_GLSPOT}

type
{$ENDIF} //(DIRECT3D_VERSION < 0x0800)

(*
 * Structure defining a light source and its properties.
 *)

  PD3DLight = ^TD3DLight;
  _D3DLIGHT = packed record
    dwSize: DWORD;
    dltType: TD3DLightType;     (* Type of light source *)
    dcvColor: TD3DColorValue;   (* Color of light *)
    dvPosition: TD3DVector;     (* Position in world space *)
    dvDirection: TD3DVector;    (* Direction in world space *)
    dvRange: TD3DValue;         (* Cutoff range *)
    dvFalloff: TD3DValue;       (* Falloff *)
    dvAttenuation0: TD3DValue;  (* Constant attenuation *)
    dvAttenuation1: TD3DValue;  (* Linear attenuation *)
    dvAttenuation2: TD3DValue;  (* Quadratic attenuation *)
    dvTheta: TD3DValue;         (* Inner angle of spotlight cone *)
    dvPhi: TD3DValue;           (* Outer angle of spotlight cone *)
  end;
  {$EXTERNALSYM _D3DLIGHT}
  D3DLIGHT = _D3DLIGHT;
  {$EXTERNALSYM D3DLIGHT}
  TD3DLight = _D3DLIGHT;

{$IFDEF DIRECT3D_VERSION_7}

  PD3DLight7 = ^TD3DLight7;
  _D3DLIGHT7 = packed record
    dltType: TD3DLightType;     (* Type of light source *)
    dcvDiffuse: TD3DColorValue; (* Diffuse color of light *)
    dcvSpecular: TD3DColorValue;(* Specular color of light *)
    dcvAmbient: TD3DColorValue; (* Ambient color of light *)
    dvPosition: TD3DVector;     (* Position in world space *)
    dvDirection: TD3DVector;    (* Direction in world space *)
    dvRange: TD3DValue;         (* Cutoff range *)
    dvFalloff: TD3DValue;       (* Falloff *)
    dvAttenuation0: TD3DValue;  (* Constant attenuation *)
    dvAttenuation1: TD3DValue;  (* Linear attenuation *)
    dvAttenuation2: TD3DValue;  (* Quadratic attenuation *)
    dvTheta: TD3DValue;         (* Inner angle of spotlight cone *)
    dvPhi: TD3DValue;           (* Outer angle of spotlight cone *)
  end;
  {$EXTERNALSYM _D3DLIGHT7}
  D3DLIGHT7 = _D3DLIGHT7;
  {$EXTERNALSYM D3DLIGHT7}
  TD3DLight7 = _D3DLIGHT7;

{$ENDIF} // DIRECT3D_VERSION_7

{$IFDEF DIRECT3D_VERSION_5}

(*
 * Structure defining a light source and its properties.
 *)

(* flags bits *)
const
  D3DLIGHT_ACTIVE       = $00000001;
  {$EXTERNALSYM D3DLIGHT_ACTIVE}
  D3DLIGHT_NO_SPECULAR  = $00000002;
  {$EXTERNALSYM D3DLIGHT_NO_SPECULAR}
  D3DLIGHT_ALL = D3DLIGHT_ACTIVE or D3DLIGHT_ACTIVE;
  {$EXTERNALSYM D3DLIGHT_ALL}

(* maximum valid light range *)
  D3DLIGHT_RANGE_MAX		= 1.8439088915e+18; //sqrt(FLT_MAX);
  {$EXTERNALSYM D3DLIGHT_RANGE_MAX}

type
  PD3DLight2 = ^TD3DLight2;
  _D3DLIGHT2 = packed record
    dwSize: DWORD;
    dltType: TD3DLightType;     (* Type of light source *)
    dcvColor: TD3DColorValue;   (* Color of light *)
    dvPosition: TD3DVector;     (* Position in world space *)
    dvDirection: TD3DVector;    (* Direction in world space *)
    dvRange: TD3DValue;         (* Cutoff range *)
    dvFalloff: TD3DValue;       (* Falloff *)
    dvAttenuation0: TD3DValue;  (* Constant attenuation *)
    dvAttenuation1: TD3DValue;  (* Linear attenuation *)
    dvAttenuation2: TD3DValue;  (* Quadratic attenuation *)
    dvTheta: TD3DValue;         (* Inner angle of spotlight cone *)
    dvPhi: TD3DValue;           (* Outer angle of spotlight cone *)
    dwFlags: DWORD;
  end;
  {$EXTERNALSYM _D3DLIGHT2}
  D3DLIGHT2 = _D3DLIGHT2;
  {$EXTERNALSYM D3DLIGHT2}
  TD3DLight2 = _D3DLIGHT2;

{$ELSE}
  PD3DLight2 = PD3DLight;
  TD3DLight2 = TD3DLight;

{$ENDIF} // DIRECT3D_VERSION_5
  PD3DLightData = ^TD3DLightData;
  _D3DLIGHTDATA = packed record
    dwSize: DWORD;
    lpIn: ^TD3DLightingElement; (* Input positions and normals *)
    dwInSize: DWORD;            (* Stride of input elements *)
    lpOut: ^TD3DTLVertex;       (* Output colors *)
    dwOutSize: DWORD;           (* Stride of output colors *)
  end;
  {$EXTERNALSYM _D3DLIGHTDATA}
  D3DLIGHTDATA = _D3DLIGHTDATA;
  {$EXTERNALSYM D3DLIGHTDATA}
  TD3DLightData = _D3DLIGHTDATA;

(*
 * Before DX5, these values were in an enum called
 * TD3DColorModel. This was not correct, since they are
 * bit flags. A driver can surface either or both flags
 * in the dcmColorModel member of D3DDEVICEDESC.
 *)

type
  TD3DColorModel = DWORD;

const
  D3DCOLOR_MONO = 1;
  {$EXTERNALSYM D3DCOLOR_MONO}
  D3DCOLOR_RGB  = 2;
  {$EXTERNALSYM D3DCOLOR_RGB}

(*
 * Options for clearing
 *)

const
  D3DCLEAR_TARGET            = $00000001; (* Clear target surface *)
  {$EXTERNALSYM D3DCLEAR_TARGET}
  D3DCLEAR_ZBUFFER           = $00000002; (* Clear target z buffer *)
  {$EXTERNALSYM D3DCLEAR_ZBUFFER}
{$IFDEF DIRECT3D_VERSION_6}
  D3DCLEAR_STENCIL           = $00000004; (* Clear stencil planes *)
  {$EXTERNALSYM D3DCLEAR_STENCIL}
{$ENDIF} // DIRECT3D_VERSION_6

(*
 * Execute buffers are allocated via Direct3D.  These buffers may then
 * be filled by the application with instructions to execute along with
 * vertex data.
 *)

(*
 * Supported op codes for execute instructions.
 *)

type
  PD3DOpcode = ^TD3DOpcode;
  _D3DOPCODE = (
    D3DOP_INVALID_0,
    D3DOP_POINT,
    D3DOP_LINE,
    D3DOP_TRIANGLE,
    D3DOP_MATRIXLOAD,
    D3DOP_MATRIXMULTIPLY,
    D3DOP_STATETRANSFORM,
    D3DOP_STATELIGHT,
    D3DOP_STATERENDER,
    D3DOP_PROCESSVERTICES,
    D3DOP_TEXTURELOAD,
    D3DOP_EXIT,
    D3DOP_BRANCHFORWARD,
    D3DOP_SPAN,
    D3DOP_SETSTATUS);
  {$EXTERNALSYM _D3DOPCODE}
  D3DOPCODE = _D3DOPCODE;
  {$EXTERNALSYM D3DOPCODE}
  TD3DOpcode = _D3DOPCODE;

  PD3DInstruction = ^TD3DInstruction;
  _D3DINSTRUCTION = packed record
    bOpcode: Byte;   (* Instruction opcode *)
    bSize: Byte;     (* Size of each instruction data unit *)
    wCount: Word;    (* Count of instruction data units to follow *)
  end;
  {$EXTERNALSYM _D3DINSTRUCTION}
  D3DINSTRUCTION = _D3DINSTRUCTION;
  {$EXTERNALSYM D3DINSTRUCTION}
  TD3DInstruction = _D3DINSTRUCTION;

(*
 * Structure for texture loads
 *)

  PD3DTextureLoad = ^TD3DTextureLoad;
  _D3DTEXTURELOAD = packed record
    hDestTexture: TD3DTextureHandle;
    hSrcTexture: TD3DTextureHandle;
  end;
  {$EXTERNALSYM _D3DTEXTURELOAD}
  D3DTEXTURELOAD = _D3DTEXTURELOAD;
  {$EXTERNALSYM D3DTEXTURELOAD}
  TD3DTextureLoad = _D3DTEXTURELOAD;

(*
 * Structure for picking
 *)

  PD3DPickRecord = ^TD3DPickRecord;
  _D3DPICKRECORD = packed record
    bOpcode: Byte;
    bPad: Byte;
    dwOffset: DWORD;
    dvZ: TD3DValue;
  end;
  {$EXTERNALSYM _D3DPICKRECORD}
  D3DPICKRECORD = _D3DPICKRECORD;
  {$EXTERNALSYM D3DPICKRECORD}
  TD3DPickRecord = _D3DPICKRECORD;

(*
 * The following defines the rendering states which can be set in the
 * execute buffer.
 *)

{$IFDEF DIRECT3D_VERSION_LESS_8}

  PD3DShadeMode = ^TD3DShadeMode;
  _D3DSHADEMODE = (
    D3DSHADE_INVALID_0,
    D3DSHADE_FLAT,
    D3DSHADE_GOURAUD,
    D3DSHADE_PHONG);
  {$EXTERNALSYM _D3DSHADEMODE}
  D3DSHADEMODE = _D3DSHADEMODE;
  {$EXTERNALSYM D3DSHADEMODE}
  TD3DShadeMode = _D3DSHADEMODE;

  PD3DFillMode = ^TD3DFillMode;
  _D3DFILLMODE = (
    D3DFILL_INVALID_0,
    D3DFILL_POINT,
    D3DFILL_WIREFRAME,
    D3DFILL_SOLID);
  {$EXTERNALSYM _D3DFILLMODE}
  D3DFILLMODE = _D3DFILLMODE;
  {$EXTERNALSYM D3DFILLMODE}
  TD3DFillMode = _D3DFILLMODE;

  PD3DLinePattern = ^TD3DLinePattern;
  _D3DLINEPATTERN = packed record
    wRepeatFactor: WORD;
    wLinePattern: WORD;
  end;
  {$EXTERNALSYM _D3DLINEPATTERN}
  D3DLINEPATTERN = _D3DLINEPATTERN;
  {$EXTERNALSYM D3DLINEPATTERN}
  TD3DLinePattern = _D3DLINEPATTERN;

{$ENDIF} // DIRECT3D_VERSION_LESS_8

  PD3DTextureFilter = ^TD3DTextureFilter;
  _D3DTEXTUREFILTER = (
    D3DFILTER_INVALID_0,
    D3DFILTER_NEAREST,
    D3DFILTER_LINEAR,
    D3DFILTER_MIPNEAREST,
    D3DFILTER_MIPLINEAR,
    D3DFILTER_LINEARMIPNEAREST,
    D3DFILTER_LINEARMIPLINEAR);
  {$EXTERNALSYM _D3DTEXTUREFILTER}
  D3DTEXTUREFILTER = _D3DTEXTUREFILTER;
  {$EXTERNALSYM D3DTEXTUREFILTER}
  TD3DTextureFilter = _D3DTEXTUREFILTER;

{$IFDEF DIRECT3D_VERSION_LESS_8}

  PD3DBlend = ^TD3DBlend;
  _D3DBLEND = (
    D3DBLEND_INVALID_0,
    D3DBLEND_ZERO,
    D3DBLEND_ONE,
    D3DBLEND_SRCCOLOR,
    D3DBLEND_INVSRCCOLOR,
    D3DBLEND_SRCALPHA,
    D3DBLEND_INVSRCALPHA,
    D3DBLEND_DESTALPHA,
    D3DBLEND_INVDESTALPHA,
    D3DBLEND_DESTCOLOR,
    D3DBLEND_INVDESTCOLOR,
    D3DBLEND_SRCALPHASAT,
    D3DBLEND_BOTHSRCALPHA,
    D3DBLEND_BOTHINVSRCALPHA);
  {$EXTERNALSYM _D3DBLEND}
  D3DBLEND = _D3DBLEND;
  {$EXTERNALSYM D3DBLEND}
  TD3DBlend = _D3DBLEND;

{$ENDIF} // DIRECT3D_VERSION_LESS_8

  PD3DTextureBlend = ^TD3DTextureBlend;
  _D3DTEXTUREBLEND = (
    D3DTBLEND_INVALID_0,
    D3DTBLEND_DECAL,
    D3DTBLEND_MODULATE,
    D3DTBLEND_DECALALPHA,
    D3DTBLEND_MODULATEALPHA,
    D3DTBLEND_DECALMASK,
    D3DTBLEND_MODULATEMASK,
    D3DTBLEND_COPY
{$IFDEF DIRECT3D_VERSION_5},
    D3DTBLEND_ADD
{$ENDIF} // DIRECT3D_VERSION_5
  );
  {$EXTERNALSYM _D3DTEXTUREBLEND}
  D3DTEXTUREBLEND = _D3DTEXTUREBLEND;
  {$EXTERNALSYM D3DTEXTUREBLEND}
  TD3DTextureBlend = _D3DTEXTUREBLEND;

{$IFDEF DIRECT3D_VERSION_LESS_8}

  PD3DTextureAddress = ^TD3DTextureAddress;
  _D3DTEXTUREADDRESS = (
    D3DTADDRESS_INVALID_0,
    D3DTADDRESS_WRAP,
    D3DTADDRESS_MIRROR,
    D3DTADDRESS_CLAMP
{$IFDEF DIRECT3D_VERSION_5},
    D3DTADDRESS_BORDER
{$ENDIF} // DIRECT3D_VERSION_5
  );
  {$EXTERNALSYM _D3DTEXTUREADDRESS}
  D3DTEXTUREADDRESS = _D3DTEXTUREADDRESS;
  {$EXTERNALSYM D3DTEXTUREADDRESS}
  TD3DTextureAddress = _D3DTEXTUREADDRESS;

  PD3DCull = ^TD3DCull;
  _D3DCULL = (
    D3DCULL_INVALID_0,
    D3DCULL_NONE,
    D3DCULL_CW,
    D3DCULL_CCW);
  {$EXTERNALSYM _D3DCULL}
  D3DCULL = _D3DCULL;
  {$EXTERNALSYM D3DCULL}
  TD3DCull = _D3DCULL;

  PD3DCmpFunc = ^TD3DCmpFunc;
  _D3DCMPFUNC = (
    D3DCMP_INVALID_0,
    D3DCMP_NEVER,
    D3DCMP_LESS,
    D3DCMP_EQUAL,
    D3DCMP_LESSEQUAL,
    D3DCMP_GREATER,
    D3DCMP_NOTEQUAL,
    D3DCMP_GREATEREQUAL,
    D3DCMP_ALWAYS);
  {$EXTERNALSYM _D3DCMPFUNC}
  D3DCMPFUNC = _D3DCMPFUNC;
  {$EXTERNALSYM D3DCMPFUNC}
  TD3DCmpFunc = _D3DCMPFUNC;

{$IFDEF DIRECT3D_VERSION_6}
  PD3DStencilOp = ^TD3DStencilOp;
  _D3DSTENCILOP = (
    D3DSTENCILOP_INVALID_0,
    D3DSTENCILOP_KEEP,
    D3DSTENCILOP_ZERO,
    D3DSTENCILOP_REPLACE,
    D3DSTENCILOP_INCRSAT,
    D3DSTENCILOP_DECRSAT,
    D3DSTENCILOP_INVERT,
    D3DSTENCILOP_INCR,
    D3DSTENCILOP_DECR);
  {$EXTERNALSYM _D3DSTENCILOP}
  D3DSTENCILOP = _D3DSTENCILOP;
  {$EXTERNALSYM D3DSTENCILOP}
  TD3DStencilOp = _D3DSTENCILOP;
{$ENDIF} // DIRECT3D_VERSION_6

  PD3DFogMode = ^TD3DFogMode;
  _D3DFOGMODE = (
    D3DFOG_NONE,
    D3DFOG_EXP,
    D3DFOG_EXP2
{$IFDEF DIRECT3D_VERSION_5},
    D3DFOG_LINEAR
{$ENDIF} // DIRECT3D_VERSION_5
  );
  {$EXTERNALSYM _D3DFOGMODE}
  D3DFOGMODE = _D3DFOGMODE;
  {$EXTERNALSYM D3DFOGMODE}
  TD3DFogMode = _D3DFOGMODE;

{$IFDEF DIRECT3D_VERSION_6}
  PD3DZBufferType = ^TD3DZBufferType;
  _D3DZBUFFERTYPE = (
    D3DZB_FALSE,
    D3DZB_TRUE,   // Z buffering
    D3DZB_USEW);  // W buffering
  {$EXTERNALSYM _D3DZBUFFERTYPE}
  D3DZBUFFERTYPE = _D3DZBUFFERTYPE;
  {$EXTERNALSYM D3DZBUFFERTYPE}
  TD3DZBufferType = _D3DZBUFFERTYPE;
{$ENDIF} // DIRECT3D_VERSION_6

{$ENDIF} // DIRECT3D_VERSION_LESS_8

{$IFDEF DIRECT3D_VERSION_5}
  PD3DAntialiasMode = ^TD3DAntialiasMode;
  _D3DANTIALIASMODE = (
    D3DANTIALIAS_NONE,
    D3DANTIALIAS_SORTDEPENDENT,
    D3DANTIALIAS_SORTINDEPENDENT);
  {$EXTERNALSYM _D3DANTIALIASMODE}
  D3DANTIALIASMODE = _D3DANTIALIASMODE;
  {$EXTERNALSYM D3DANTIALIASMODE}
  TD3DAntialiasMode = _D3DANTIALIASMODE;

// Vertex types supported by Direct3D
  PD3DVertexType = ^TD3DVertexType;
  _D3DVERTEXTYPE = (
    D3DVT_INVALID_0,
    D3DVT_VERTEX,
    D3DVT_LVERTEX,
    D3DVT_TLVERTEX);
  {$EXTERNALSYM _D3DVERTEXTYPE}
  D3DVERTEXTYPE = _D3DVERTEXTYPE;
  {$EXTERNALSYM D3DVERTEXTYPE}
  TD3DVertexType = _D3DVERTEXTYPE;

{$IFDEF DIRECT3D_VERSION_LESS_8}

// Primitives supported by draw-primitive API
  PD3DPrimitiveType = ^TD3DPrimitiveType;
  _D3DPRIMITIVETYPE = (
    D3DPT_INVALID_0,
    D3DPT_POINTLIST,
    D3DPT_LINELIST,
    D3DPT_LINESTRIP,
    D3DPT_TRIANGLELIST,
    D3DPT_TRIANGLESTRIP,
    D3DPT_TRIANGLEFAN);
  {$EXTERNALSYM _D3DPRIMITIVETYPE}
  D3DPRIMITIVETYPE = _D3DPRIMITIVETYPE;
  {$EXTERNALSYM D3DPRIMITIVETYPE}
  TD3DPrimitiveType = _D3DPRIMITIVETYPE;

{$ENDIF} // DIRECT3D_VERSION_LESS_8

{$ENDIF} // DIRECT3D_VERSION_5

(*
 * Amount to add to a state to generate the override for that state.
 *)

const
  D3DSTATE_OVERRIDE_BIAS          = 256;
  {$EXTERNALSYM D3DSTATE_OVERRIDE_BIAS}

(*
 * A state which sets the override flag for the specified state type.
 *)

function D3DSTATE_OVERRIDE(StateType: DWORD): DWORD;
{$EXTERNALSYM D3DSTATE_OVERRIDE}

{$IFDEF DIRECT3D_VERSION_8}
//
// legacy transform state names
//
{$ENDIF} // DIRECT3D_VERSION_8
type
  PD3DTransformStateType = ^TD3DTransformStateType;
  TD3DTransformStateType = DWORD;
const
  D3DTRANSFORMSTATE_WORLD         = TD3DTransformStateType(1);
  {$EXTERNALSYM D3DTRANSFORMSTATE_WORLD}
  D3DTRANSFORMSTATE_VIEW          = TD3DTransformStateType(2);
  {$EXTERNALSYM D3DTRANSFORMSTATE_VIEW}
  D3DTRANSFORMSTATE_PROJECTION    = TD3DTransformStateType(3);
  {$EXTERNALSYM D3DTRANSFORMSTATE_PROJECTION}
{$IFDEF DIRECT3D_VERSION_7}
  D3DTRANSFORMSTATE_WORLD1        = TD3DTransformStateType(4);  // 2nd matrix to blend
  {$EXTERNALSYM D3DTRANSFORMSTATE_WORLD1}
  D3DTRANSFORMSTATE_WORLD2        = TD3DTransformStateType(5);  // 3rd matrix to blend
  {$EXTERNALSYM D3DTRANSFORMSTATE_WORLD2}
  D3DTRANSFORMSTATE_WORLD3        = TD3DTransformStateType(6);  // 4th matrix to blend
  {$EXTERNALSYM D3DTRANSFORMSTATE_WORLD3}
  D3DTRANSFORMSTATE_TEXTURE0      = TD3DTransformStateType(16);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE0}
  D3DTRANSFORMSTATE_TEXTURE1      = TD3DTransformStateType(17);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE1}
  D3DTRANSFORMSTATE_TEXTURE2      = TD3DTransformStateType(18);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE2}
  D3DTRANSFORMSTATE_TEXTURE3      = TD3DTransformStateType(19);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE3}
  D3DTRANSFORMSTATE_TEXTURE4      = TD3DTransformStateType(20);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE4}
  D3DTRANSFORMSTATE_TEXTURE5      = TD3DTransformStateType(21);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE5}
  D3DTRANSFORMSTATE_TEXTURE6      = TD3DTransformStateType(22);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE6}
  D3DTRANSFORMSTATE_TEXTURE7      = TD3DTransformStateType(23);
  {$EXTERNALSYM D3DTRANSFORMSTATE_TEXTURE7}
{$ENDIF} // DIRECT3D_VERSION_7


type
  PD3DLightStateType = ^TD3DLightStateType;
  _D3DLIGHTSTATETYPE = (
    D3DLIGHTSTATE_INVALID_0,
    D3DLIGHTSTATE_MATERIAL,
    D3DLIGHTSTATE_AMBIENT,
    D3DLIGHTSTATE_COLORMODEL,
    D3DLIGHTSTATE_FOGMODE,
    D3DLIGHTSTATE_FOGSTART,
    D3DLIGHTSTATE_FOGEND,
    D3DLIGHTSTATE_FOGDENSITY
{$IFDEF DIRECT3D_VERSION_6},
    D3DLIGHTSTATE_COLORVERTEX
  {$EXTERNALSYM _D3DLIGHTSTATETYPE}
{$ENDIF} // DIRECT3D_VERSION_6
  );
  D3DLIGHTSTATETYPE = _D3DLIGHTSTATETYPE;
  {$EXTERNALSYM D3DLIGHTSTATETYPE}
  TD3DLightStateType = _D3DLIGHTSTATETYPE;

type  
  PD3DRenderStateType = ^TD3DRenderStateType;
  TD3DRenderStateType = DWORD;

const
  D3DRENDERSTATE_ANTIALIAS          = 2;    (* D3DANTIALIASMODE *)
  {$EXTERNALSYM D3DRENDERSTATE_ANTIALIAS}
  D3DRENDERSTATE_TEXTUREPERSPECTIVE = 4;    (* TRUE for perspective correction *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREPERSPECTIVE}
  D3DRENDERSTATE_ZENABLE            = 7;    (* D3DZBUFFERTYPE (or TRUE/FALSE for legacy) *)
  {$EXTERNALSYM D3DRENDERSTATE_ZENABLE}
  D3DRENDERSTATE_FILLMODE           = 8;    (* D3DFILL_MODE        *)
  {$EXTERNALSYM D3DRENDERSTATE_FILLMODE}
  D3DRENDERSTATE_SHADEMODE          = 9;    (* D3DSHADEMODE *)
  {$EXTERNALSYM D3DRENDERSTATE_SHADEMODE}
  D3DRENDERSTATE_LINEPATTERN        = 10;   (* D3DLINEPATTERN *)
  {$EXTERNALSYM D3DRENDERSTATE_LINEPATTERN}
  D3DRENDERSTATE_ZWRITEENABLE       = 14;   (* TRUE to enable z writes *)
  {$EXTERNALSYM D3DRENDERSTATE_ZWRITEENABLE}
  D3DRENDERSTATE_ALPHATESTENABLE    = 15;   (* TRUE to enable alpha tests *)
  {$EXTERNALSYM D3DRENDERSTATE_ALPHATESTENABLE}
  D3DRENDERSTATE_LASTPIXEL          = 16;   (* TRUE for last-pixel on lines *)
  {$EXTERNALSYM D3DRENDERSTATE_LASTPIXEL}
  D3DRENDERSTATE_SRCBLEND           = 19;   (* D3DBLEND *)
  {$EXTERNALSYM D3DRENDERSTATE_SRCBLEND}
  D3DRENDERSTATE_DESTBLEND          = 20;   (* D3DBLEND *)
  {$EXTERNALSYM D3DRENDERSTATE_DESTBLEND}
  D3DRENDERSTATE_CULLMODE           = 22;   (* D3DCULL *)
  {$EXTERNALSYM D3DRENDERSTATE_CULLMODE}
  D3DRENDERSTATE_ZFUNC              = 23;   (* D3DCMPFUNC *)
  {$EXTERNALSYM D3DRENDERSTATE_ZFUNC}
  D3DRENDERSTATE_ALPHAREF           = 24;   (* D3DFIXED *)
  {$EXTERNALSYM D3DRENDERSTATE_ALPHAREF}
  D3DRENDERSTATE_ALPHAFUNC          = 25;   (* D3DCMPFUNC *)
  {$EXTERNALSYM D3DRENDERSTATE_ALPHAFUNC}
  D3DRENDERSTATE_DITHERENABLE       = 26;   (* TRUE to enable dithering *)
  {$EXTERNALSYM D3DRENDERSTATE_DITHERENABLE}
{$IFDEF DIRECT3D_VERSION_5}
  D3DRENDERSTATE_ALPHABLENDENABLE   = 27;   (* TRUE to enable alpha blending *)
  {$EXTERNALSYM D3DRENDERSTATE_ALPHABLENDENABLE}
{$ENDIF} // DIRECT3D_VERSION_5
  D3DRENDERSTATE_FOGENABLE          = 28;   (* TRUE to enable fog blending *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGENABLE}
  D3DRENDERSTATE_SPECULARENABLE     = 29;   (* TRUE to enable specular *)
  {$EXTERNALSYM D3DRENDERSTATE_SPECULARENABLE}
  D3DRENDERSTATE_ZVISIBLE           = 30;   (* TRUE to enable z checking *)
  {$EXTERNALSYM D3DRENDERSTATE_ZVISIBLE}
  D3DRENDERSTATE_STIPPLEDALPHA      = 33;   (* TRUE to enable stippled alpha (RGB device only) *)
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEDALPHA}
  D3DRENDERSTATE_FOGCOLOR           = 34;   (* D3DCOLOR *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGCOLOR}
  D3DRENDERSTATE_FOGTABLEMODE       = 35;   (* D3DFOGMODE *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGTABLEMODE}
{$IFDEF DIRECT3D_VERSION_7}
  D3DRENDERSTATE_FOGSTART           = 36;   (* Fog start (for both vertex and pixel fog) *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGSTART}
  D3DRENDERSTATE_FOGEND             = 37;   (* Fog end      *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGEND}
  D3DRENDERSTATE_FOGDENSITY         = 38;   (* Fog density  *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGDENSITY}
{$ENDIF} // DIRECT3D_VERSION_7
{$IFDEF DIRECT3D_VERSION_5}
  D3DRENDERSTATE_EDGEANTIALIAS      = 40;   (* TRUE to enable edge antialiasing *)
  {$EXTERNALSYM D3DRENDERSTATE_EDGEANTIALIAS}
  D3DRENDERSTATE_COLORKEYENABLE     = 41;   (* TRUE to enable source colorkeyed textures *)
  {$EXTERNALSYM D3DRENDERSTATE_COLORKEYENABLE}
  D3DRENDERSTATE_ZBIAS              = 47;   (* LONG Z bias *)
  {$EXTERNALSYM D3DRENDERSTATE_ZBIAS}
  D3DRENDERSTATE_RANGEFOGENABLE     = 48;   (* Enables range-based fog *)
  {$EXTERNALSYM D3DRENDERSTATE_RANGEFOGENABLE}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  D3DRENDERSTATE_STENCILENABLE      = 52;   (* BOOL enable/disable stenciling *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILENABLE}
  D3DRENDERSTATE_STENCILFAIL        = 53;   (* D3DSTENCILOP to do if stencil test fails *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILFAIL}
  D3DRENDERSTATE_STENCILZFAIL       = 54;   (* D3DSTENCILOP to do if stencil test passes and Z test fails *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILZFAIL}
  D3DRENDERSTATE_STENCILPASS        = 55;   (* D3DSTENCILOP to do if both stencil and Z tests pass *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILPASS}
  D3DRENDERSTATE_STENCILFUNC        = 56;   (* D3DCMPFUNC fn.  Stencil Test passes if ((ref & mask) stencilfn (stencil & mask)) is true *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILFUNC}
  D3DRENDERSTATE_STENCILREF         = 57;   (* Reference value used in stencil test *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILREF}
  D3DRENDERSTATE_STENCILMASK        = 58;   (* Mask value used in stencil test *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILMASK}
  D3DRENDERSTATE_STENCILWRITEMASK   = 59;   (* Write mask applied to values written to stencil buffer *)
  {$EXTERNALSYM D3DRENDERSTATE_STENCILWRITEMASK}
  D3DRENDERSTATE_TEXTUREFACTOR      = 60;   (* D3DCOLOR used for multi-texture blend *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREFACTOR}
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_6}

  (*
   * 128 values [128; 255] are reserved for texture coordinate wrap flags.
   * These are constructed with the D3DWRAP_U and D3DWRAP_V macros. Using
   * a flags word preserves forward compatibility with texture coordinates
   * that are >2D.
   *)
  D3DRENDERSTATE_WRAP0              = 128;  (* wrap for 1st texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP0}
  D3DRENDERSTATE_WRAP1              = 129;  (* wrap for 2nd texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP1}
  D3DRENDERSTATE_WRAP2              = 130;  (* wrap for 3rd texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP2}
  D3DRENDERSTATE_WRAP3              = 131;  (* wrap for 4th texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP3}
  D3DRENDERSTATE_WRAP4              = 132;  (* wrap for 5th texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP4}
  D3DRENDERSTATE_WRAP5              = 133;  (* wrap for 6th texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP5}
  D3DRENDERSTATE_WRAP6              = 134;  (* wrap for 7th texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP6}
  D3DRENDERSTATE_WRAP7              = 135;  (* wrap for 8th texture coord. set *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAP7}
{$ENDIF} // DIRECT3D_VERSION_6
{$IFDEF DIRECT3D_VERSION_7}
  D3DRENDERSTATE_CLIPPING            = 136;
  {$EXTERNALSYM D3DRENDERSTATE_CLIPPING}
  D3DRENDERSTATE_LIGHTING            = 137;
  {$EXTERNALSYM D3DRENDERSTATE_LIGHTING}
  D3DRENDERSTATE_EXTENTS             = 138;
  {$EXTERNALSYM D3DRENDERSTATE_EXTENTS}
  D3DRENDERSTATE_AMBIENT             = 139;
  {$EXTERNALSYM D3DRENDERSTATE_AMBIENT}
  D3DRENDERSTATE_FOGVERTEXMODE       = 140;
  {$EXTERNALSYM D3DRENDERSTATE_FOGVERTEXMODE}
  D3DRENDERSTATE_COLORVERTEX         = 141;
  {$EXTERNALSYM D3DRENDERSTATE_COLORVERTEX}
  D3DRENDERSTATE_LOCALVIEWER         = 142;
  {$EXTERNALSYM D3DRENDERSTATE_LOCALVIEWER}
  D3DRENDERSTATE_NORMALIZENORMALS    = 143;
  {$EXTERNALSYM D3DRENDERSTATE_NORMALIZENORMALS}
  D3DRENDERSTATE_COLORKEYBLENDENABLE = 144;
  {$EXTERNALSYM D3DRENDERSTATE_COLORKEYBLENDENABLE}
  D3DRENDERSTATE_DIFFUSEMATERIALSOURCE    = 145;
  {$EXTERNALSYM D3DRENDERSTATE_DIFFUSEMATERIALSOURCE}
  D3DRENDERSTATE_SPECULARMATERIALSOURCE   = 146;
  {$EXTERNALSYM D3DRENDERSTATE_SPECULARMATERIALSOURCE}
  D3DRENDERSTATE_AMBIENTMATERIALSOURCE    = 147;
  {$EXTERNALSYM D3DRENDERSTATE_AMBIENTMATERIALSOURCE}
  D3DRENDERSTATE_EMISSIVEMATERIALSOURCE   = 148;
  {$EXTERNALSYM D3DRENDERSTATE_EMISSIVEMATERIALSOURCE}
  D3DRENDERSTATE_VERTEXBLEND              = 151;
  {$EXTERNALSYM D3DRENDERSTATE_VERTEXBLEND}
  D3DRENDERSTATE_CLIPPLANEENABLE          = 152;
  {$EXTERNALSYM D3DRENDERSTATE_CLIPPLANEENABLE}

{$ENDIF} // DIRECT3D_VERSION_7

//
// retired renderstates - not supported for DX7 interfaces
//
  D3DRENDERSTATE_TEXTUREHANDLE      = 1;    (* Texture handle for legacy interfaces (Texture;Texture2) *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREHANDLE}
  D3DRENDERSTATE_TEXTUREADDRESS     = 3;    (* D3DTEXTUREADDRESS  *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREADDRESS}
  D3DRENDERSTATE_WRAPU              = 5;    (* TRUE for wrapping in u *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAPU}
  D3DRENDERSTATE_WRAPV              = 6;    (* TRUE for wrapping in v *)
  {$EXTERNALSYM D3DRENDERSTATE_WRAPV}
  D3DRENDERSTATE_MONOENABLE         = 11;   (* TRUE to enable mono rasterization *)
  {$EXTERNALSYM D3DRENDERSTATE_MONOENABLE}
  D3DRENDERSTATE_ROP2               = 12;   (* ROP2 *)
  {$EXTERNALSYM D3DRENDERSTATE_ROP2}
  D3DRENDERSTATE_PLANEMASK          = 13;   (* DWORD physical plane mask *)
  {$EXTERNALSYM D3DRENDERSTATE_PLANEMASK}
  D3DRENDERSTATE_TEXTUREMAG         = 17;   (* D3DTEXTUREFILTER *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREMAG}
  D3DRENDERSTATE_TEXTUREMIN         = 18;   (* D3DTEXTUREFILTER *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREMIN}
  D3DRENDERSTATE_TEXTUREMAPBLEND    = 21;   (* D3DTEXTUREBLEND *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREMAPBLEND}
  D3DRENDERSTATE_SUBPIXEL           = 31;   (* TRUE to enable subpixel correction *)
  {$EXTERNALSYM D3DRENDERSTATE_SUBPIXEL}
  D3DRENDERSTATE_SUBPIXELX          = 32;   (* TRUE to enable correction in X only *)
  {$EXTERNALSYM D3DRENDERSTATE_SUBPIXELX}
  D3DRENDERSTATE_STIPPLEENABLE      = 39;   (* TRUE to enable stippling *)
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEENABLE}
{$IFDEF DIRECT3D_VERSION_5}
  D3DRENDERSTATE_BORDERCOLOR        = 43;   (* Border color for texturing w/border *)
  {$EXTERNALSYM D3DRENDERSTATE_BORDERCOLOR}
  D3DRENDERSTATE_TEXTUREADDRESSU    = 44;   (* Texture addressing mode for U coordinate *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREADDRESSU}
  D3DRENDERSTATE_TEXTUREADDRESSV    = 45;   (* Texture addressing mode for V coordinate *)
  {$EXTERNALSYM D3DRENDERSTATE_TEXTUREADDRESSV}
  D3DRENDERSTATE_MIPMAPLODBIAS      = 46;   (* D3DVALUE Mipmap LOD bias *)
  {$EXTERNALSYM D3DRENDERSTATE_MIPMAPLODBIAS}
  D3DRENDERSTATE_ANISOTROPY         = 49;   (* Max. anisotropy. 1 = no anisotropy *)
  {$EXTERNALSYM D3DRENDERSTATE_ANISOTROPY}
{$ENDIF} // DIRECT3D_VERSION_5
  D3DRENDERSTATE_FLUSHBATCH         = 50;   (* Explicit flush for DP batching (DX5 Only) *)
  {$EXTERNALSYM D3DRENDERSTATE_FLUSHBATCH}
{$IFDEF DIRECT3D_VERSION_6}
  D3DRENDERSTATE_TRANSLUCENTSORTINDEPENDENT=51; (* BOOL enable sort-independent transparency *)
  {$EXTERNALSYM D3DRENDERSTATE_TRANSLUCENTSORTINDEPENDENT}
{$ENDIF} // DIRECT3D_VERSION_6
  D3DRENDERSTATE_STIPPLEPATTERN00   = 64;   (* Stipple pattern 01...  *)
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN00}
  D3DRENDERSTATE_STIPPLEPATTERN01   = 65;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN01}
  D3DRENDERSTATE_STIPPLEPATTERN02   = 66;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN02}
  D3DRENDERSTATE_STIPPLEPATTERN03   = 67;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN03}
  D3DRENDERSTATE_STIPPLEPATTERN04   = 68;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN04}
  D3DRENDERSTATE_STIPPLEPATTERN05   = 69;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN05}
  D3DRENDERSTATE_STIPPLEPATTERN06   = 70;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN06}
  D3DRENDERSTATE_STIPPLEPATTERN07   = 71;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN07}
  D3DRENDERSTATE_STIPPLEPATTERN08   = 72;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN08}
  D3DRENDERSTATE_STIPPLEPATTERN09   = 73;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN09}
  D3DRENDERSTATE_STIPPLEPATTERN10   = 74;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN10}
  D3DRENDERSTATE_STIPPLEPATTERN11   = 75;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN11}
  D3DRENDERSTATE_STIPPLEPATTERN12   = 76;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN12}
  D3DRENDERSTATE_STIPPLEPATTERN13   = 77;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN13}
  D3DRENDERSTATE_STIPPLEPATTERN14   = 78;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN14}
  D3DRENDERSTATE_STIPPLEPATTERN15   = 79;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN15}
  D3DRENDERSTATE_STIPPLEPATTERN16   = 80;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN16}
  D3DRENDERSTATE_STIPPLEPATTERN17   = 81;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN17}
  D3DRENDERSTATE_STIPPLEPATTERN18   = 82;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN18}
  D3DRENDERSTATE_STIPPLEPATTERN19   = 83;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN19}
  D3DRENDERSTATE_STIPPLEPATTERN20   = 84;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN20}
  D3DRENDERSTATE_STIPPLEPATTERN21   = 85;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN21}
  D3DRENDERSTATE_STIPPLEPATTERN22   = 86;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN22}
  D3DRENDERSTATE_STIPPLEPATTERN23   = 87;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN23}
  D3DRENDERSTATE_STIPPLEPATTERN24   = 88;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN24}
  D3DRENDERSTATE_STIPPLEPATTERN25   = 89;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN25}
  D3DRENDERSTATE_STIPPLEPATTERN26   = 90;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN26}
  D3DRENDERSTATE_STIPPLEPATTERN27   = 91;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN27}
  D3DRENDERSTATE_STIPPLEPATTERN28   = 92;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN28}
  D3DRENDERSTATE_STIPPLEPATTERN29   = 93;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN29}
  D3DRENDERSTATE_STIPPLEPATTERN30   = 94;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN30}
  D3DRENDERSTATE_STIPPLEPATTERN31   = 95;
  {$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN31}

//
// retired renderstate names - the values are still used under new naming conventions
//
  D3DRENDERSTATE_FOGTABLESTART      = 36;   (* Fog table start    *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGTABLESTART}
  D3DRENDERSTATE_FOGTABLEEND        = 37;   (* Fog table end      *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGTABLEEND}
  D3DRENDERSTATE_FOGTABLEDENSITY    = 38;   (* Fog table density  *)
  {$EXTERNALSYM D3DRENDERSTATE_FOGTABLEDENSITY}


{$IFDEF DIRECT3D_VERSION_LESS_8}

type
// Values for material source
  PD3DMateralColorSource = ^TD3DMateralColorSource;
  _D3DMATERIALCOLORSOURCE = (
    D3DMCS_MATERIAL,              // Color from material is used
    D3DMCS_COLOR1,                // Diffuse vertex color is used
    D3DMCS_COLOR2                 // Specular vertex color is used
  );
  {$EXTERNALSYM _D3DMATERIALCOLORSOURCE}
  D3DMATERIALCOLORSOURCE = _D3DMATERIALCOLORSOURCE;
  {$EXTERNALSYM D3DMATERIALCOLORSOURCE}
  TD3DMateralColorSource = _D3DMATERIALCOLORSOURCE;

{$IFDEF DIRECT3D_VERSION_5}
const
  // For back-compatibility with legacy compilations
  D3DRENDERSTATE_BLENDENABLE = D3DRENDERSTATE_ALPHABLENDENABLE;
  {$EXTERNALSYM D3DRENDERSTATE_BLENDENABLE}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}

// Bias to apply to the texture coordinate set to apply a wrap to.
   D3DRENDERSTATE_WRAPBIAS                = 128;
   {$EXTERNALSYM D3DRENDERSTATE_WRAPBIAS}

(* Flags to construct the WRAP render states *)
  D3DWRAP_U   = $00000001;
  {$EXTERNALSYM D3DWRAP_U}
  D3DWRAP_V   = $00000002;
  {$EXTERNALSYM D3DWRAP_V}

{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}

(* Flags to construct the WRAP render states for 1D thru 4D texture coordinates *)
  D3DWRAPCOORD_0   = $00000001;    // same as D3DWRAP_U
  {$EXTERNALSYM D3DWRAPCOORD_0}
  D3DWRAPCOORD_1   = $00000002;    // same as D3DWRAP_V
  {$EXTERNALSYM D3DWRAPCOORD_1}
  D3DWRAPCOORD_2   = $00000004;
  {$EXTERNALSYM D3DWRAPCOORD_2}
  D3DWRAPCOORD_3   = $00000008;
  {$EXTERNALSYM D3DWRAPCOORD_3}

{$ENDIF} // DIRECT3D_VERSION_7

{$ENDIF} // DIRECT3D_VERSION_LESS_8

function D3DRENDERSTATE_STIPPLEPATTERN(y: Integer): TD3DRenderStateType;
{$EXTERNALSYM D3DRENDERSTATE_STIPPLEPATTERN}

type
  PD3DState = ^TD3DState;
  _D3DSTATE = packed record
    case Integer of
    {$IFDEF DIRECT3D_VERSION_LESS_8}
    0: (
      dtstTransformStateType: TD3DTransformStateType;
     );
    {$ENDIF} // DIRECT3D_VERSION_LESS_8
    1: (
      dlstLightStateType: TD3DLightStateType;
      dwArg: array [0..0] of DWORD;
     );
    2: (
      drstRenderStateType: TD3DRenderStateType;
      dvArg: array [0..0] of TD3DValue;
     );
  end;
  {$EXTERNALSYM _D3DSTATE}
  D3DSTATE = _D3DSTATE;
  {$EXTERNALSYM D3DSTATE}
  TD3DState = _D3DSTATE;

(*
 * Operation used to load matrices
 * hDstMat = hSrcMat
 *)
  PD3DMatrixLoad = ^TD3DMatrixLoad;
  _D3DMATRIXLOAD = packed record
    hDestMatrix: TD3DMatrixHandle;   (* Destination matrix *)
    hSrcMatrix: TD3DMatrixHandle;    (* Source matrix *)
  end;
  {$EXTERNALSYM _D3DMATRIXLOAD}
  D3DMATRIXLOAD = _D3DMATRIXLOAD;
  {$EXTERNALSYM D3DMATRIXLOAD}
  TD3DMatrixLoad = _D3DMATRIXLOAD;

(*
 * Operation used to multiply matrices
 * hDstMat = hSrcMat1 * hSrcMat2
 *)
  PD3DMatrixMultiply = ^TD3DMatrixMultiply;
  _D3DMATRIXMULTIPLY = packed record
    hDestMatrix: TD3DMatrixHandle;   (* Destination matrix *)
    hSrcMatrix1: TD3DMatrixHandle;   (* First source matrix *)
    hSrcMatrix2: TD3DMatrixHandle;   (* Second source matrix *)
  end;
  {$EXTERNALSYM _D3DMATRIXMULTIPLY}
  D3DMATRIXMULTIPLY = _D3DMATRIXMULTIPLY;
  {$EXTERNALSYM D3DMATRIXMULTIPLY}
  TD3DMatrixMultiply = _D3DMATRIXMULTIPLY;

(*
 * Operation used to transform and light vertices.
 *)
  PD3DProcessVertices = ^TD3DProcessVertices;
  _D3DPROCESSVERTICES = packed record
    dwFlags: DWORD;           (* Do we transform or light or just copy? *)
    wStart: WORD;             (* Index to first vertex in source *)
    wDest: WORD;              (* Index to first vertex in local buffer *)
    dwCount: DWORD;           (* Number of vertices to be processed *)
    dwReserved: DWORD;        (* Must be zero *)
  end;
  {$EXTERNALSYM _D3DPROCESSVERTICES}
  D3DPROCESSVERTICES = _D3DPROCESSVERTICES;
  {$EXTERNALSYM D3DPROCESSVERTICES}
  TD3DProcessVertices = _D3DPROCESSVERTICES;

const
  D3DPROCESSVERTICES_TRANSFORMLIGHT       = $00000000;
  {$EXTERNALSYM D3DPROCESSVERTICES_TRANSFORMLIGHT}
  D3DPROCESSVERTICES_TRANSFORM            = $00000001;
  {$EXTERNALSYM D3DPROCESSVERTICES_TRANSFORM}
  D3DPROCESSVERTICES_COPY                 = $00000002;
  {$EXTERNALSYM D3DPROCESSVERTICES_COPY}
  D3DPROCESSVERTICES_OPMASK               = $00000007;
  {$EXTERNALSYM D3DPROCESSVERTICES_OPMASK}

  D3DPROCESSVERTICES_UPDATEEXTENTS        = $00000008;
  {$EXTERNALSYM D3DPROCESSVERTICES_UPDATEEXTENTS}
  D3DPROCESSVERTICES_NOCOLOR              = $00000010;
  {$EXTERNALSYM D3DPROCESSVERTICES_NOCOLOR}

{$IFDEF DIRECT3D_VERSION_6}
{$IFDEF DIRECT3D_VERSION_LESS_8}

(*
 * State enumerants for per-stage texture processing.
 *)
type
  PD3DTextureStageStateType = ^TD3DTextureStageStateType;
  TD3DTextureStageStateType = DWORD;
const
  D3DTSS_COLOROP        =  1; (* D3DTEXTUREOP - per-stage blending controls for color channels *)
  {$EXTERNALSYM D3DTSS_COLOROP}
  D3DTSS_COLORARG1      =  2; (* D3DTA_* (texture arg) *)
  {$EXTERNALSYM D3DTSS_COLORARG1}
  D3DTSS_COLORARG2      =  3; (* D3DTA_* (texture arg) *)
  {$EXTERNALSYM D3DTSS_COLORARG2}
  D3DTSS_ALPHAOP        =  4; (* D3DTEXTUREOP - per-stage blending controls for alpha channel *)
  {$EXTERNALSYM D3DTSS_ALPHAOP}
  D3DTSS_ALPHAARG1      =  5; (* D3DTA_* (texture arg) *)
  {$EXTERNALSYM D3DTSS_ALPHAARG1}
  D3DTSS_ALPHAARG2      =  6; (* D3DTA_* (texture arg) *)
  {$EXTERNALSYM D3DTSS_ALPHAARG2}
  D3DTSS_BUMPENVMAT00   =  7; (* D3DVALUE (bump mapping matrix) *)
  {$EXTERNALSYM D3DTSS_BUMPENVMAT00}
  D3DTSS_BUMPENVMAT01   =  8; (* D3DVALUE (bump mapping matrix) *)
  {$EXTERNALSYM D3DTSS_BUMPENVMAT01}
  D3DTSS_BUMPENVMAT10   =  9; (* D3DVALUE (bump mapping matrix) *)
  {$EXTERNALSYM D3DTSS_BUMPENVMAT10}
  D3DTSS_BUMPENVMAT11   = 10; (* D3DVALUE (bump mapping matrix) *)
  {$EXTERNALSYM D3DTSS_BUMPENVMAT11}
  D3DTSS_TEXCOORDINDEX  = 11; (* identifies which set of texture coordinates index this texture *)
  {$EXTERNALSYM D3DTSS_TEXCOORDINDEX}
  D3DTSS_ADDRESS        = 12; (* D3DTEXTUREADDRESS for both coordinates *)
  {$EXTERNALSYM D3DTSS_ADDRESS}
  D3DTSS_ADDRESSU       = 13; (* D3DTEXTUREADDRESS for U coordinate *)
  {$EXTERNALSYM D3DTSS_ADDRESSU}
  D3DTSS_ADDRESSV       = 14; (* D3DTEXTUREADDRESS for V coordinate *)
  {$EXTERNALSYM D3DTSS_ADDRESSV}
  D3DTSS_BORDERCOLOR    = 15; (* D3DCOLOR *)
  {$EXTERNALSYM D3DTSS_BORDERCOLOR}
  D3DTSS_MAGFILTER      = 16; (* D3DTEXTUREMAGFILTER filter to use for magnification *)
  {$EXTERNALSYM D3DTSS_MAGFILTER}
  D3DTSS_MINFILTER      = 17; (* D3DTEXTUREMINFILTER filter to use for minification *)
  {$EXTERNALSYM D3DTSS_MINFILTER}
  D3DTSS_MIPFILTER      = 18; (* D3DTEXTUREMIPFILTER filter to use between mipmaps during minification *)
  {$EXTERNALSYM D3DTSS_MIPFILTER}
  D3DTSS_MIPMAPLODBIAS  = 19; (* D3DVALUE Mipmap LOD bias *)
  {$EXTERNALSYM D3DTSS_MIPMAPLODBIAS}
  D3DTSS_MAXMIPLEVEL    = 20; (* DWORD 0..(n-1) LOD index of largest map to use (0 == largest) *)
  {$EXTERNALSYM D3DTSS_MAXMIPLEVEL}
  D3DTSS_MAXANISOTROPY  = 21; (* DWORD maximum anisotropy *)
  {$EXTERNALSYM D3DTSS_MAXANISOTROPY}
  D3DTSS_BUMPENVLSCALE  = 22; (* D3DVALUE scale for bump map luminance *)
  {$EXTERNALSYM D3DTSS_BUMPENVLSCALE}
  D3DTSS_BUMPENVLOFFSET = 23; (* D3DVALUE offset for bump map luminance *)
  {$EXTERNALSYM D3DTSS_BUMPENVLOFFSET}
{$IFDEF DIRECT3D_VERSION_7}
  D3DTSS_TEXTURETRANSFORMFLAGS = 24; (* D3DTEXTURETRANSFORMFLAGS controls texture transform *)
  {$EXTERNALSYM D3DTSS_TEXTURETRANSFORMFLAGS}
{$ENDIF}

{$IFDEF DIRECT3D_VERSION_7}
// Values, used with D3DTSS_TEXCOORDINDEX, to specify that the vertex data(position
// and normal in the camera space) should be taken as texture coordinates
// Low 16 bits are used to specify texture coordinate index, to take the WRAP mode from
//
  D3DTSS_TCI_PASSTHRU                             = $00000000;
  {$EXTERNALSYM D3DTSS_TCI_PASSTHRU}
  D3DTSS_TCI_CAMERASPACENORMAL                    = $00010000;
  {$EXTERNALSYM D3DTSS_TCI_CAMERASPACENORMAL}
  D3DTSS_TCI_CAMERASPACEPOSITION                  = $00020000;
  {$EXTERNALSYM D3DTSS_TCI_CAMERASPACEPOSITION}
  D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR          = $00030000;
  {$EXTERNALSYM D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR}
{$ENDIF}

type
(*
 * Enumerations for COLOROP and ALPHAOP texture blending operations set in
 * texture processing stage controls in D3DRENDERSTATE.
 *)
  PD3DTextureOp = ^TD3DTextureOp;
  _D3DTEXTUREOP = (
    D3DTOP_INVALID_0,
// Control
    D3DTOP_DISABLE   ,      // disables stage
    D3DTOP_SELECTARG1,      // the default
    D3DTOP_SELECTARG2,

// Modulate
    D3DTOP_MODULATE  ,      // multiply args together
    D3DTOP_MODULATE2X,      // multiply and  1 bit
    D3DTOP_MODULATE4X,      // multiply and  2 bits

// Add
    D3DTOP_ADD        ,   // add arguments together
    D3DTOP_ADDSIGNED  ,   // add with -0.5 bias
    D3DTOP_ADDSIGNED2X,   // as above but left  1 bit
    D3DTOP_SUBTRACT   ,   // Arg1 - Arg2, with no saturation
    D3DTOP_ADDSMOOTH  ,   // add 2 args, subtract product
                          // Arg1 + Arg2 - Arg1*Arg2
                          // = Arg1 + (1-Arg1)*Arg2

// Linear alpha blend: Arg1*(Alpha) + Arg2*(1-Alpha)
    D3DTOP_BLENDDIFFUSEALPHA  , // iterated alpha
    D3DTOP_BLENDTEXTUREALPHA  , // texture alpha
    D3DTOP_BLENDFACTORALPHA   , // alpha from D3DRENDERSTATE_TEXTUREFACTOR
    // Linear alpha blend with pre-multiplied arg1 input: Arg1 + Arg2*(1-Alpha)
    D3DTOP_BLENDTEXTUREALPHAPM, // texture alpha
    D3DTOP_BLENDCURRENTALPHA  , // by alpha of current color

// Specular mapping
    D3DTOP_PREMODULATE           ,     // modulate with next texture before use
    D3DTOP_MODULATEALPHA_ADDCOLOR,     // Arg1.RGB + Arg1.A*Arg2.RGB
                                       // COLOROP only
    D3DTOP_MODULATECOLOR_ADDALPHA,     // Arg1.RGB*Arg2.RGB + Arg1.A
                                            // COLOROP only
    D3DTOP_MODULATEINVALPHA_ADDCOLOR,  // (1-Arg1.A)*Arg2.RGB + Arg1.RGB
                                       // COLOROP only
    D3DTOP_MODULATEINVCOLOR_ADDALPHA,  // (1-Arg1.RGB)*Arg2.RGB + Arg1.A
                                            // COLOROP only

// Bump mapping
    D3DTOP_BUMPENVMAP         , // per pixel env map perturbation
    D3DTOP_BUMPENVMAPLUMINANCE, // with luminance channel
    // This can do either diffuse or specular bump mapping with correct input.
    // Performs the function (Arg1.R*Arg2.R + Arg1.G*Arg2.G + Arg1.B*Arg2.B)
    // where each component has been scaled and offset to make it signed.
    // The result is replicated into all four (including alpha) channels.
    // This is a valid COLOROP only.
    D3DTOP_DOTPRODUCT3
  );
  {$EXTERNALSYM _D3DTEXTUREOP}
  D3DTEXTUREOP = _D3DTEXTUREOP;
  {$EXTERNALSYM D3DTEXTUREOP}
  TD3DTextureOp = _D3DTEXTUREOP;

(*
 * Values for COLORARG1,2 and ALPHAARG1,2 texture blending operations
 * set in texture processing stage controls in D3DRENDERSTATE.
 *)
const
  D3DTA_SELECTMASK        = $0000000f;  // mask for arg selector
  {$EXTERNALSYM D3DTA_SELECTMASK}
  D3DTA_DIFFUSE           = $00000000;  // select diffuse color
  {$EXTERNALSYM D3DTA_DIFFUSE}
  D3DTA_CURRENT           = $00000001;  // select result of previous stage
  {$EXTERNALSYM D3DTA_CURRENT}
  D3DTA_TEXTURE           = $00000002;  // select texture color
  {$EXTERNALSYM D3DTA_TEXTURE}
  D3DTA_TFACTOR           = $00000003;  // select RENDERSTATE_TEXTUREFACTOR
  {$EXTERNALSYM D3DTA_TFACTOR}
{$IFDEF DIRECT3D_VERSION_7}
  D3DTA_SPECULAR          = $00000004;  // select specular color
  {$EXTERNALSYM D3DTA_SPECULAR}
{$ENDIF}
  D3DTA_COMPLEMENT        = $00000010;  // take 1.0 - x
  {$EXTERNALSYM D3DTA_COMPLEMENT}
  D3DTA_ALPHAREPLICATE    = $00000020;  // replicate alpha to color components
  {$EXTERNALSYM D3DTA_ALPHAREPLICATE}

{$ENDIF} // DIRECT3D_VERSION_LESS_8

(*
 *  IDirect3DTexture2 State Filter Types
 *)
type
  PD3DTextureMagFilter = ^TD3DTextureMagFilter;
  _D3DTEXTUREMAGFILTER = (
    D3DTFG_INVALID_0,
    D3DTFG_POINT        ,    // nearest
    D3DTFG_LINEAR       ,    // linear interpolation
    D3DTFG_FLATCUBIC    ,    // cubic
    D3DTFG_GAUSSIANCUBIC,    // different cubic kernel
    D3DTFG_ANISOTROPIC
  );
  {$EXTERNALSYM _D3DTEXTUREMAGFILTER}
  D3DTEXTUREMAGFILTER = _D3DTEXTUREMAGFILTER;
  {$EXTERNALSYM D3DTEXTUREMAGFILTER}
  TD3DTextureMagFilter = _D3DTEXTUREMAGFILTER;

  PD3DTextureMinFilter = ^TD3DTextureMinFilter;
  _D3DTEXTUREMINFILTER = (
    D3DTFN_INVALID_0,
    D3DTFN_POINT      ,    // nearest
    D3DTFN_LINEAR     ,    // linear interpolation
    D3DTFN_ANISOTROPIC
  );
  {$EXTERNALSYM _D3DTEXTUREMINFILTER}
  D3DTEXTUREMINFILTER = _D3DTEXTUREMINFILTER;
  {$EXTERNALSYM D3DTEXTUREMINFILTER}
  TD3DTextureMinFilter = _D3DTEXTUREMINFILTER;

  PD3DTextureMipFilter = ^TD3DTextureMipFilter;
  _D3DTEXTUREMIPFILTER = (
    D3DTFP_INVALID_0,
    D3DTFP_NONE   ,    // mipmapping disabled (use MAG filter)
    D3DTFP_POINT  ,    // nearest
    D3DTFP_LINEAR      // linear interpolation
  );
  {$EXTERNALSYM _D3DTEXTUREMIPFILTER}
  D3DTEXTUREMIPFILTER = _D3DTEXTUREMIPFILTER;
  {$EXTERNALSYM D3DTEXTUREMIPFILTER}
  TD3DTextureMipFilter = _D3DTEXTUREMIPFILTER;

{$ENDIF} // DIRECT3D_VERSION_6


(*
 * Triangle flags
 *)

(*
 * Tri strip and fan flags.
 * START loads all three vertices
 * EVEN and ODD load just v3 with even or odd culling
 * START_FLAT contains a count from 0 to 29 that allows the
 * whole strip or fan to be culled in one hit.
 * e.g. for a quad len = 1
 *)
const
  D3DTRIFLAG_START                        = $00000000;
  {$EXTERNALSYM D3DTRIFLAG_START}
// #define D3DTRIFLAG_STARTFLAT(len) (len)         (* 0 < len < 30 *)
function D3DTRIFLAG_STARTFLAT(len: DWORD): DWORD;
{$EXTERNALSYM D3DTRIFLAG_STARTFLAT}

const
  D3DTRIFLAG_ODD                          = $0000001e;
  {$EXTERNALSYM D3DTRIFLAG_ODD}
  D3DTRIFLAG_EVEN                         = $0000001f;
  {$EXTERNALSYM D3DTRIFLAG_EVEN}

(*
 * Triangle edge flags
 * enable edges for wireframe or antialiasing
 *)
  D3DTRIFLAG_EDGEENABLE1                  = $00000100; (* v0-v1 edge *)
  {$EXTERNALSYM D3DTRIFLAG_EDGEENABLE1}
  D3DTRIFLAG_EDGEENABLE2                  = $00000200; (* v1-v2 edge *)
  {$EXTERNALSYM D3DTRIFLAG_EDGEENABLE2}
  D3DTRIFLAG_EDGEENABLE3                  = $00000400; (* v2-v0 edge *)
  {$EXTERNALSYM D3DTRIFLAG_EDGEENABLE3}
  D3DTRIFLAG_EDGEENABLETRIANGLE = (
      D3DTRIFLAG_EDGEENABLE1 or D3DTRIFLAG_EDGEENABLE2 or D3DTRIFLAG_EDGEENABLE3);
  {$EXTERNALSYM D3DTRIFLAG_EDGEENABLETRIANGLE}

(*
 * Primitive structures and related defines.  Vertex offsets are to types
 * TD3DVertex, TD3DLVertex, or TD3DTLVertex.
 *)

(*
 * Triangle list primitive structure
 *)
type
  PD3DTriangle = ^TD3DTriangle;
  _D3DTRIANGLE = packed record
    case Integer of
    0: (
      v1: WORD;            (* Vertex indices *)
      v2: WORD;
      v3: WORD;
      wFlags: WORD;        (* Edge (and other) flags *)
     );
    1: (
      wV1: WORD;
      wV2: WORD;
      wV3: WORD;
     );
  end;
  {$EXTERNALSYM _D3DTRIANGLE}
  D3DTRIANGLE = _D3DTRIANGLE;
  {$EXTERNALSYM D3DTRIANGLE}
  TD3DTriangle = _D3DTRIANGLE;

(*
 * Line strip structure.
 * The instruction count - 1 defines the number of line segments.
 *)
  PD3DLine = ^TD3DLine;
  _D3DLINE = packed record
    case Integer of
    0: (
      v1: WORD;            (* Vertex indices *)
      v2: WORD;
     );
    1: (
      wV1: WORD;
      wV2: WORD;
     );
  end;
  {$EXTERNALSYM _D3DLINE}
  D3DLINE = _D3DLINE;
  {$EXTERNALSYM D3DLINE}
  TD3DLine = _D3DLINE;

(*
 * Span structure
 * Spans join a list of points with the same y value.
 * If the y value changes, a new span is started.
 *)
  PD3DSpan = ^TD3DSpan;
  _D3DSPAN = packed record
    wCount: WORD;        (* Number of spans *)
    wFirst: WORD;        (* Index to first vertex *)
  end;
  {$EXTERNALSYM _D3DSPAN}
  D3DSPAN = _D3DSPAN;
  {$EXTERNALSYM D3DSPAN}
  TD3DSpan = _D3DSPAN;

(*
 * Point structure
 *)
  PD3DPoint = ^TD3DPoint;
  _D3DPOINT = packed record
    wCount: WORD;        (* number of points         *)
    wFirst: WORD;        (* index to first vertex    *)
  end;
  {$EXTERNALSYM _D3DPOINT}
  D3DPOINT = _D3DPOINT;
  {$EXTERNALSYM D3DPOINT}
  TD3DPoint = _D3DPOINT;

(*
 * Forward branch structure.
 * Mask is logically anded with the driver status mask
 * if the result equals 'value', the branch is taken.
 *)
  PD3DBranch = ^TD3DBranch;
  _D3DBRANCH = packed record
    dwMask: DWORD;         (* Bitmask against D3D status *)
    dwValue: DWORD;
    bNegate: BOOL;         (* TRUE to negate comparison *)
    dwOffset: DWORD;       (* How far to branch forward (0 for exit)*)
  end;
  {$EXTERNALSYM _D3DBRANCH}
  D3DBRANCH = _D3DBRANCH;
  {$EXTERNALSYM D3DBRANCH}
  TD3DBranch = _D3DBRANCH;

(*
 * Status used for set status instruction.
 * The D3D status is initialised on device creation
 * and is modified by all execute calls.
 *)
  PD3DStatus = ^TD3DStatus;
  _D3DSTATUS = packed record
    dwFlags: DWORD;        (* Do we set extents or status *)
    dwStatus: DWORD;       (* D3D status *)
    drExtent: TD3DRect;
  end;
  {$EXTERNALSYM _D3DSTATUS}
  D3DSTATUS = _D3DSTATUS;
  {$EXTERNALSYM D3DSTATUS}
  TD3DStatus = _D3DSTATUS;

const
  D3DSETSTATUS_STATUS    = $00000001;
  {$EXTERNALSYM D3DSETSTATUS_STATUS}
  D3DSETSTATUS_EXTENTS   = $00000002;
  {$EXTERNALSYM D3DSETSTATUS_EXTENTS}
  D3DSETSTATUS_ALL      = (D3DSETSTATUS_STATUS or D3DSETSTATUS_EXTENTS);
  {$EXTERNALSYM D3DSETSTATUS_ALL}

{$IFDEF DIRECT3D_VERSION_5}
type
  PD3DClipStatus = ^TD3DClipStatus;
  _D3DCLIPSTATUS = packed record
    dwFlags : DWORD; (* Do we set 2d extents, 3D extents or status *)
    dwStatus : DWORD; (* Clip status *)
    minx, maxx : Single; (* X extents *)
    miny, maxy : Single; (* Y extents *)
    minz, maxz : Single; (* Z extents *)
  end;
  {$EXTERNALSYM _D3DCLIPSTATUS}
  D3DCLIPSTATUS = _D3DCLIPSTATUS;
  {$EXTERNALSYM D3DCLIPSTATUS}
  TD3DClipStatus = _D3DCLIPSTATUS;

const
  D3DCLIPSTATUS_STATUS        = $00000001;
  {$EXTERNALSYM D3DCLIPSTATUS_STATUS}
  D3DCLIPSTATUS_EXTENTS2      = $00000002;
  {$EXTERNALSYM D3DCLIPSTATUS_EXTENTS2}
  D3DCLIPSTATUS_EXTENTS3      = $00000004;
  {$EXTERNALSYM D3DCLIPSTATUS_EXTENTS3}
{$ENDIF} // DIRECT3D_VERSION_5

(*
 * Statistics structure
 *)
type
  PD3DStats = ^TD3DStats;
  _D3DSTATS = packed record
    dwSize: DWORD;
    dwTrianglesDrawn: DWORD;
    dwLinesDrawn: DWORD;
    dwPointsDrawn: DWORD;
    dwSpansDrawn: DWORD;
    dwVerticesProcessed: DWORD;
  end;
  {$EXTERNALSYM _D3DSTATS}
  D3DSTATS = _D3DSTATS;
  {$EXTERNALSYM D3DSTATS}
  TD3DStats = _D3DSTATS;

(*
 * Execute options.
 * When calling using D3DEXECUTE_UNCLIPPED all the primitives
 * inside the buffer must be contained within the viewport.
 *)
const
  D3DEXECUTE_CLIPPED       = $00000001;
  {$EXTERNALSYM D3DEXECUTE_CLIPPED}
  D3DEXECUTE_UNCLIPPED     = $00000002;
  {$EXTERNALSYM D3DEXECUTE_UNCLIPPED}

type
  PD3DExecuteData = ^TD3DExecuteData;
  _D3DEXECUTEDATA = packed record
    dwSize: DWORD;
    dwVertexOffset: DWORD;
    dwVertexCount: DWORD;
    dwInstructionOffset: DWORD;
    dwInstructionLength: DWORD;
    dwHVertexOffset: DWORD;
    dsStatus: TD3DStatus;       (* Status after execute *)
  end;
  {$EXTERNALSYM _D3DEXECUTEDATA}
  D3DEXECUTEDATA = _D3DEXECUTEDATA;
  {$EXTERNALSYM D3DEXECUTEDATA}
  TD3DExecuteData = _D3DEXECUTEDATA;

(*
 * Palette flags.
 * This are or'ed with the peFlags in the PALETTEENTRYs passed to DirectDraw.
 *)

const
  D3DPAL_FREE     = $00;    (* Renderer may use this entry freely *)
  {$EXTERNALSYM D3DPAL_FREE}
  D3DPAL_READONLY = $40;    (* Renderer may not set this entry *)
  {$EXTERNALSYM D3DPAL_READONLY}
  D3DPAL_RESERVED = $80;    (* Renderer may not use this entry *)
  {$EXTERNALSYM D3DPAL_RESERVED}

{$IFDEF DIRECT3D_VERSION_6}

type
  PD3DVertexBufferDesc = ^TD3DVertexBufferDesc;
  _D3DVERTEXBUFFERDESC = packed record
    dwSize : DWORD;
    dwCaps : DWORD;
    dwFVF : DWORD;
    dwNumVertices : DWORD;
  end;
  {$EXTERNALSYM _D3DVERTEXBUFFERDESC}
  D3DVERTEXBUFFERDESC = _D3DVERTEXBUFFERDESC;
  {$EXTERNALSYM D3DVERTEXBUFFERDESC}
  TD3DVertexBufferDesc = _D3DVERTEXBUFFERDESC;

const
(* These correspond to DDSCAPS_* flags *)
  D3DVBCAPS_SYSTEMMEMORY      = $00000800;
  {$EXTERNALSYM D3DVBCAPS_SYSTEMMEMORY}
  D3DVBCAPS_WRITEONLY         = $00010000;
  {$EXTERNALSYM D3DVBCAPS_WRITEONLY}
  D3DVBCAPS_OPTIMIZED         = $80000000;
  {$EXTERNALSYM D3DVBCAPS_OPTIMIZED}
  D3DVBCAPS_DONOTCLIP         = $00000001;
  {$EXTERNALSYM D3DVBCAPS_DONOTCLIP}

(* Vertex Operations for ProcessVertices *)
  D3DVOP_LIGHT      = (1 shl 10);
  {$EXTERNALSYM D3DVOP_LIGHT}
  D3DVOP_TRANSFORM  = (1 shl 0);
  {$EXTERNALSYM D3DVOP_TRANSFORM}
  D3DVOP_CLIP       = (1 shl 2);
  {$EXTERNALSYM D3DVOP_CLIP}
  D3DVOP_EXTENTS    = (1 shl 3);
  {$EXTERNALSYM D3DVOP_EXTENTS}

{$IFDEF DIRECT3D_VERSION_LESS_8}

(* The maximum number of vertices user can pass to any d3d
   drawing function or to create vertex buffer with
*)
  D3DMAXNUMVERTICES  =  ((1 shl 16) - 1);
  {$EXTERNALSYM D3DMAXNUMVERTICES}
(* The maximum number of primitives user can pass to any d3d
   drawing function.
*)
  D3DMAXNUMPRIMITIVES = ((1 shl 16) - 1);
  {$EXTERNALSYM D3DMAXNUMPRIMITIVES}

{$IFDEF DIRECT3D_VERSION_7}

(* Bits for dwFlags in ProcessVertices call *)
  D3DPV_DONOTCOPYDATA = (1 shl 0);
  {$EXTERNALSYM D3DPV_DONOTCOPYDATA}

{$ENDIF} // DIRECT3D_VERSION_7
{$ENDIF} // DIRECT3D_VERSION_LESS_8

//-------------------------------------------------------------------

{$IFDEF DIRECT3D_VERSION_LESS_8}

// Flexible vertex format bits
//
  D3DFVF_RESERVED0        = $001;
  {$EXTERNALSYM D3DFVF_RESERVED0}
  D3DFVF_POSITION_MASK    = $00E;
  {$EXTERNALSYM D3DFVF_POSITION_MASK}
  D3DFVF_XYZ              = $002;
  {$EXTERNALSYM D3DFVF_XYZ}
  D3DFVF_XYZRHW           = $004;
  {$EXTERNALSYM D3DFVF_XYZRHW}
{$IFDEF DIRECT3D_VERSION_7}
  D3DFVF_XYZB1            = $006;
  {$EXTERNALSYM D3DFVF_XYZB1}
  D3DFVF_XYZB2            = $008;
  {$EXTERNALSYM D3DFVF_XYZB2}
  D3DFVF_XYZB3            = $00a;
  {$EXTERNALSYM D3DFVF_XYZB3}
  D3DFVF_XYZB4            = $00c;
  {$EXTERNALSYM D3DFVF_XYZB4}
  D3DFVF_XYZB5            = $00e;
  {$EXTERNALSYM D3DFVF_XYZB5}

{$ENDIF} // DIRECT3D_VERSION_7
  D3DFVF_NORMAL           = $010;
  {$EXTERNALSYM D3DFVF_NORMAL}
  D3DFVF_RESERVED1        = $020;
  {$EXTERNALSYM D3DFVF_RESERVED1}
  D3DFVF_DIFFUSE          = $040;
  {$EXTERNALSYM D3DFVF_DIFFUSE}
  D3DFVF_SPECULAR         = $080;
  {$EXTERNALSYM D3DFVF_SPECULAR}

  D3DFVF_TEXCOUNT_MASK    = $f00;
  {$EXTERNALSYM D3DFVF_TEXCOUNT_MASK}
  D3DFVF_TEXCOUNT_SHIFT   = 8;
  {$EXTERNALSYM D3DFVF_TEXCOUNT_SHIFT}
  D3DFVF_TEX0             = $000;
  {$EXTERNALSYM D3DFVF_TEX0}
  D3DFVF_TEX1             = $100;
  {$EXTERNALSYM D3DFVF_TEX1}
  D3DFVF_TEX2             = $200;
  {$EXTERNALSYM D3DFVF_TEX2}
  D3DFVF_TEX3             = $300;
  {$EXTERNALSYM D3DFVF_TEX3}
  D3DFVF_TEX4             = $400;
  {$EXTERNALSYM D3DFVF_TEX4}
  D3DFVF_TEX5             = $500;
  {$EXTERNALSYM D3DFVF_TEX5}
  D3DFVF_TEX6             = $600;
  {$EXTERNALSYM D3DFVF_TEX6}
  D3DFVF_TEX7             = $700;
  {$EXTERNALSYM D3DFVF_TEX7}
  D3DFVF_TEX8             = $800;
  {$EXTERNALSYM D3DFVF_TEX8}

  D3DFVF_RESERVED2        = $f000;  // 4 reserved bits
  {$EXTERNALSYM D3DFVF_RESERVED2}

{$ELSE}
  D3DFVF_RESERVED1        = $020;
  {$EXTERNALSYM D3DFVF_RESERVED1}
{$ENDIF} // DIRECT3D_VERSION_LESS_8

  D3DFVF_VERTEX = ( D3DFVF_XYZ or D3DFVF_NORMAL or D3DFVF_TEX1 );
  {$EXTERNALSYM D3DFVF_VERTEX}
  D3DFVF_LVERTEX = ( D3DFVF_XYZ or D3DFVF_RESERVED1 or D3DFVF_DIFFUSE or
                         D3DFVF_SPECULAR or D3DFVF_TEX1 );
  {$EXTERNALSYM D3DFVF_LVERTEX}
  D3DFVF_TLVERTEX = ( D3DFVF_XYZRHW or D3DFVF_DIFFUSE or D3DFVF_SPECULAR or
                          D3DFVF_TEX1 );
  {$EXTERNALSYM D3DFVF_TLVERTEX}

type
  PD3DDP_PtrStride = ^TD3DDP_PtrStride;
  _D3DDP_PTRSTRIDE = packed record
    lpvData : pointer;
    dwStride : DWORD;
  end;
  {$EXTERNALSYM _D3DDP_PTRSTRIDE}
  D3DDP_PTRSTRIDE = _D3DDP_PTRSTRIDE;
  {$EXTERNALSYM D3DDP_PTRSTRIDE}
  TD3DDP_PtrStride = _D3DDP_PTRSTRIDE;
  TD3DDPPtrStride = _D3DDP_PTRSTRIDE;
  PD3DDPPtrStride = ^TD3DDPPtrStride;

const
  D3DDP_MAXTEXCOORD = 8;
  {$EXTERNALSYM D3DDP_MAXTEXCOORD}

type
  PD3DDrawPrimitiveStridedData = ^TD3DDrawPrimitiveStridedData;
  _D3DDRAWPRIMITIVESTRIDEDDATA = packed record
    position : TD3DDP_PtrStride;
    normal : TD3DDP_PtrStride;
    diffuse : TD3DDP_PtrStride;
    specular : TD3DDP_PtrStride;
    textureCoords : array [0..D3DDP_MAXTEXCOORD-1] of TD3DDP_PtrStride;
  end;
  {$EXTERNALSYM _D3DDRAWPRIMITIVESTRIDEDDATA}
  D3DDRAWPRIMITIVESTRIDEDDATA = _D3DDRAWPRIMITIVESTRIDEDDATA;
  {$EXTERNALSYM D3DDRAWPRIMITIVESTRIDEDDATA}
  TD3DDrawPrimitiveStridedData = _D3DDRAWPRIMITIVESTRIDEDDATA;

//---------------------------------------------------------------------
// ComputeSphereVisibility return values
//
const
  D3DVIS_INSIDE_FRUSTUM      = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_FRUSTUM}
  D3DVIS_INTERSECT_FRUSTUM   = 1;
  {$EXTERNALSYM D3DVIS_INTERSECT_FRUSTUM}
  D3DVIS_OUTSIDE_FRUSTUM     = 2;
  {$EXTERNALSYM D3DVIS_OUTSIDE_FRUSTUM}
  D3DVIS_INSIDE_LEFT         = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_LEFT}
  D3DVIS_INTERSECT_LEFT      = (1 shl 2);
  {$EXTERNALSYM D3DVIS_INTERSECT_LEFT}
  D3DVIS_OUTSIDE_LEFT        = (2 shl 2);
  {$EXTERNALSYM D3DVIS_OUTSIDE_LEFT}
  D3DVIS_INSIDE_RIGHT        = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_RIGHT}
  D3DVIS_INTERSECT_RIGHT     = (1 shl 4);
  {$EXTERNALSYM D3DVIS_INTERSECT_RIGHT}
  D3DVIS_OUTSIDE_RIGHT       = (2 shl 4);
  {$EXTERNALSYM D3DVIS_OUTSIDE_RIGHT}
  D3DVIS_INSIDE_TOP          = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_TOP}
  D3DVIS_INTERSECT_TOP       = (1 shl 6);
  {$EXTERNALSYM D3DVIS_INTERSECT_TOP}
  D3DVIS_OUTSIDE_TOP         = (2 shl 6);
  {$EXTERNALSYM D3DVIS_OUTSIDE_TOP}
  D3DVIS_INSIDE_BOTTOM       = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_BOTTOM}
  D3DVIS_INTERSECT_BOTTOM    = (1 shl 8);
  {$EXTERNALSYM D3DVIS_INTERSECT_BOTTOM}
  D3DVIS_OUTSIDE_BOTTOM      = (2 shl 8);
  {$EXTERNALSYM D3DVIS_OUTSIDE_BOTTOM}
  D3DVIS_INSIDE_NEAR         = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_NEAR}
  D3DVIS_INTERSECT_NEAR      = (1 shl 10);
  {$EXTERNALSYM D3DVIS_INTERSECT_NEAR}
  D3DVIS_OUTSIDE_NEAR        = (2 shl 10);
  {$EXTERNALSYM D3DVIS_OUTSIDE_NEAR}
  D3DVIS_INSIDE_FAR          = 0;
  {$EXTERNALSYM D3DVIS_INSIDE_FAR}
  D3DVIS_INTERSECT_FAR       = (1 shl 12);
  {$EXTERNALSYM D3DVIS_INTERSECT_FAR}
  D3DVIS_OUTSIDE_FAR         = (2 shl 12);
  {$EXTERNALSYM D3DVIS_OUTSIDE_FAR}

  D3DVIS_MASK_FRUSTUM        = (3 shl 0);
  {$EXTERNALSYM D3DVIS_MASK_FRUSTUM}
  D3DVIS_MASK_LEFT           = (3 shl 2);
  {$EXTERNALSYM D3DVIS_MASK_LEFT}
  D3DVIS_MASK_RIGHT          = (3 shl 4);
  {$EXTERNALSYM D3DVIS_MASK_RIGHT}
  D3DVIS_MASK_TOP            = (3 shl 6);
  {$EXTERNALSYM D3DVIS_MASK_TOP}
  D3DVIS_MASK_BOTTOM         = (3 shl 8);
  {$EXTERNALSYM D3DVIS_MASK_BOTTOM}
  D3DVIS_MASK_NEAR           = (3 shl 10);
  {$EXTERNALSYM D3DVIS_MASK_NEAR}
  D3DVIS_MASK_FAR            = (3 shl 12);
  {$EXTERNALSYM D3DVIS_MASK_FAR}

{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_LESS_8}
{$IFDEF DIRECT3D_VERSION_7}

// To be used with GetInfo()
  D3DDEVINFOID_TEXTUREMANAGER    = 1;
  {$EXTERNALSYM D3DDEVINFOID_TEXTUREMANAGER}
  D3DDEVINFOID_D3DTEXTUREMANAGER = 2;
  {$EXTERNALSYM D3DDEVINFOID_D3DTEXTUREMANAGER}
  D3DDEVINFOID_TEXTURING         = 3;
  {$EXTERNALSYM D3DDEVINFOID_TEXTURING}

type
  PD3DStateBlockType = ^TD3DStateBlockType;
  _D3DSTATEBLOCKTYPE = (
    D3DSBT_INVALID_0   ,
    D3DSBT_ALL         , // capture all state
    D3DSBT_PIXELSTATE  , // capture pixel state
    D3DSBT_VERTEXSTATE   // capture vertex state
  );
  {$EXTERNALSYM _D3DSTATEBLOCKTYPE}
  D3DSTATEBLOCKTYPE = _D3DSTATEBLOCKTYPE;
  {$EXTERNALSYM D3DSTATEBLOCKTYPE}
  TD3DStateBlockType = _D3DSTATEBLOCKTYPE;

// The D3DVERTEXBLENDFLAGS type is used with D3DRENDERSTATE_VERTEXBLEND state.
//
  PD3DVertexBlendFlags = ^TD3DVertexBlendFlags;
  _D3DVERTEXBLENDFLAGS = (
    D3DVBLEND_DISABLE , // Disable vertex blending
    D3DVBLEND_1WEIGHT , // blend between 2 matrices
    D3DVBLEND_2WEIGHTS, // blend between 3 matrices
    D3DVBLEND_3WEIGHTS  // blend between 4 matrices
  );
  {$EXTERNALSYM _D3DVERTEXBLENDFLAGS}
  D3DVERTEXBLENDFLAGS = _D3DVERTEXBLENDFLAGS;
  {$EXTERNALSYM D3DVERTEXBLENDFLAGS}
  TD3DVertexBlendFlags = _D3DVERTEXBLENDFLAGS;

  PD3DTextureTransformFlags = ^TD3DTextureTransformFlags;
  _D3DTEXTURETRANSFORMFLAGS = (
    D3DTTFF_DISABLE ,    // texture coordinates are passed directly
    D3DTTFF_COUNT1  ,    // rasterizer should expect 1-D texture coords
    D3DTTFF_COUNT2  ,    // rasterizer should expect 2-D texture coords
    D3DTTFF_COUNT3  ,    // rasterizer should expect 3-D texture coords
    D3DTTFF_COUNT4       // rasterizer should expect 4-D texture coords
  );
  {$EXTERNALSYM _D3DTEXTURETRANSFORMFLAGS}
  D3DTEXTURETRANSFORMFLAGS = _D3DTEXTURETRANSFORMFLAGS;
  {$EXTERNALSYM D3DTEXTURETRANSFORMFLAGS}
  TD3DTextureTransformFlags = _D3DTEXTURETRANSFORMFLAGS;

const
  D3DTTFF_PROJECTED       = TD3DTextureTransformFlags(256); // texcoords to be divided by COUNTth element
  {$EXTERNALSYM D3DTTFF_PROJECTED}

// Macros to set texture coordinate format bits in the FVF id

  D3DFVF_TEXTUREFORMAT2 = 0;         // Two floating point values
  {$EXTERNALSYM D3DFVF_TEXTUREFORMAT2}
  D3DFVF_TEXTUREFORMAT1 = 3;         // One floating point value
  {$EXTERNALSYM D3DFVF_TEXTUREFORMAT1}
  D3DFVF_TEXTUREFORMAT3 = 1;         // Three floating point values
  {$EXTERNALSYM D3DFVF_TEXTUREFORMAT3}
  D3DFVF_TEXTUREFORMAT4 = 2;         // Four floating point values
  {$EXTERNALSYM D3DFVF_TEXTUREFORMAT4}

function D3DFVF_TEXCOORDSIZE3(CoordIndex: DWORD): DWORD;
{$EXTERNALSYM D3DFVF_TEXCOORDSIZE3}
function D3DFVF_TEXCOORDSIZE2(CoordIndex: DWORD): DWORD;
{$EXTERNALSYM D3DFVF_TEXCOORDSIZE2}
function D3DFVF_TEXCOORDSIZE4(CoordIndex: DWORD): DWORD;
{$EXTERNALSYM D3DFVF_TEXCOORDSIZE4}
function D3DFVF_TEXCOORDSIZE1(CoordIndex: DWORD): DWORD;
{$EXTERNALSYM D3DFVF_TEXCOORDSIZE1}

{$ENDIF} // DIRECT3D_VERSION_7
{$ELSE}
//
// legacy vertex blend names
//
type
  PD3DVertexBlendFlags = ^TD3DVertexBlendFlags;
  TD3DVertexBlendFlags = Direct3D8.TD3DVertexBlendFlags;
  D3DVERTEXBLENDFLAGS = Direct3D8.D3DVERTEXBLENDFLAGS;
  _D3DVERTEXBLENDFLAGS = Direct3D8._D3DVERTEXBLENDFLAGS;

{$ENDIF} // DIRECT3D_VERSION_LESS_8


(*==========================================================================;
 *
 *
 *  File:       d3dcaps.h
 *  Content:    Direct3D capabilities include file
 *
 ***************************************************************************)

(* Description of capabilities of transform *)

type
  PD3DTransformCaps = ^TD3DTransformCaps;
  _D3DTRANSFORMCAPS = packed record
    dwSize: DWORD;
    dwCaps: DWORD;
  end;
  {$EXTERNALSYM _D3DTRANSFORMCAPS}
  D3DTRANSFORMCAPS = _D3DTRANSFORMCAPS;
  {$EXTERNALSYM D3DTRANSFORMCAPS}
  TD3DTransformCaps = _D3DTRANSFORMCAPS;

const
  D3DTRANSFORMCAPS_CLIP         = $00000001; (* Will clip whilst transforming *)
  {$EXTERNALSYM D3DTRANSFORMCAPS_CLIP}

(* Description of capabilities of lighting *)

type
  PD3DLightingCaps = ^TD3DLightingCaps;
  _D3DLIGHTINGCAPS = packed record
    dwSize: DWORD;
    dwCaps: DWORD;                   (* Lighting caps *)
    dwLightingModel: DWORD;          (* Lighting model - RGB or mono *)
    dwNumLights: DWORD;              (* Number of lights that can be handled *)
  end;
  {$EXTERNALSYM _D3DLIGHTINGCAPS}
  D3DLIGHTINGCAPS = _D3DLIGHTINGCAPS;
  {$EXTERNALSYM D3DLIGHTINGCAPS}
  TD3DLightingCaps = _D3DLIGHTINGCAPS;

const
  D3DLIGHTINGMODEL_RGB            = $00000001;
  {$EXTERNALSYM D3DLIGHTINGMODEL_RGB}
  D3DLIGHTINGMODEL_MONO           = $00000002;
  {$EXTERNALSYM D3DLIGHTINGMODEL_MONO}

  D3DLIGHTCAPS_POINT              = $00000001; (* Point lights supported *)
  {$EXTERNALSYM D3DLIGHTCAPS_POINT}
  D3DLIGHTCAPS_SPOT               = $00000002; (* Spot lights supported *)
  {$EXTERNALSYM D3DLIGHTCAPS_SPOT}
  D3DLIGHTCAPS_DIRECTIONAL        = $00000004; (* Directional lights supported *)
  {$EXTERNALSYM D3DLIGHTCAPS_DIRECTIONAL}
{$IFDEF DIRECT3D_VERSION_LESS_7}
  D3DLIGHTCAPS_PARALLELPOINT      = $00000008; (* Parallel point lights supported *)
  {$EXTERNALSYM D3DLIGHTCAPS_PARALLELPOINT}
{$ENDIF} // DIRECT3D_VERSION_LESS_7
{$IFDEF DIRECT3D_VERSION_LESS_5}
  D3DLIGHTCAPS_GLSPOT             = $00000010; (* GL syle spot lights supported *)
  {$EXTERNALSYM D3DLIGHTCAPS_GLSPOT}
{$ENDIF} // DIRECT3D_VERSION_LESS_5

(* Description of capabilities for each primitive type *)

type
  PD3DPrimCaps = ^TD3DPrimCaps;
  _D3DPrimCaps = packed record
    dwSize: DWORD;
    dwMiscCaps: DWORD;                 (* Capability flags *)
    dwRasterCaps: DWORD;
    dwZCmpCaps: DWORD;
    dwSrcBlendCaps: DWORD;
    dwDestBlendCaps: DWORD;
    dwAlphaCmpCaps: DWORD;
    dwShadeCaps: DWORD;
    dwTextureCaps: DWORD;
    dwTextureFilterCaps: DWORD;
    dwTextureBlendCaps: DWORD;
    dwTextureAddressCaps: DWORD;
    dwStippleWidth: DWORD;             (* maximum width and height of *)
    dwStippleHeight: DWORD;            (* of supported stipple (up to 32x32) *)
  end;
  {$EXTERNALSYM _D3DPrimCaps}
  D3DPrimCaps = _D3DPrimCaps;
  {$EXTERNALSYM D3DPrimCaps}
  TD3DPrimCaps = _D3DPrimCaps;

const
(* TD3DPrimCaps dwMiscCaps *)

  D3DPMISCCAPS_MASKPLANES         = $00000001;
  {$EXTERNALSYM D3DPMISCCAPS_MASKPLANES}
  D3DPMISCCAPS_MASKZ              = $00000002;
  {$EXTERNALSYM D3DPMISCCAPS_MASKZ}
  D3DPMISCCAPS_LINEPATTERNREP     = $00000004;
  {$EXTERNALSYM D3DPMISCCAPS_LINEPATTERNREP}
  D3DPMISCCAPS_CONFORMANT         = $00000008;
  {$EXTERNALSYM D3DPMISCCAPS_CONFORMANT}
  D3DPMISCCAPS_CULLNONE           = $00000010;
  {$EXTERNALSYM D3DPMISCCAPS_CULLNONE}
  D3DPMISCCAPS_CULLCW             = $00000020;
  {$EXTERNALSYM D3DPMISCCAPS_CULLCW}
  D3DPMISCCAPS_CULLCCW            = $00000040;
  {$EXTERNALSYM D3DPMISCCAPS_CULLCCW}

(* TD3DPrimCaps dwRasterCaps *)

  D3DPRASTERCAPS_DITHER           = $00000001;
  {$EXTERNALSYM D3DPRASTERCAPS_DITHER}
  D3DPRASTERCAPS_ROP2             = $00000002;
  {$EXTERNALSYM D3DPRASTERCAPS_ROP2}
  D3DPRASTERCAPS_XOR              = $00000004;
  {$EXTERNALSYM D3DPRASTERCAPS_XOR}
  D3DPRASTERCAPS_PAT              = $00000008;
  {$EXTERNALSYM D3DPRASTERCAPS_PAT}
  D3DPRASTERCAPS_ZTEST            = $00000010;
  {$EXTERNALSYM D3DPRASTERCAPS_ZTEST}
  D3DPRASTERCAPS_SUBPIXEL         = $00000020;
  {$EXTERNALSYM D3DPRASTERCAPS_SUBPIXEL}
  D3DPRASTERCAPS_SUBPIXELX        = $00000040;
  {$EXTERNALSYM D3DPRASTERCAPS_SUBPIXELX}
  D3DPRASTERCAPS_FOGVERTEX        = $00000080;
  {$EXTERNALSYM D3DPRASTERCAPS_FOGVERTEX}
  D3DPRASTERCAPS_FOGTABLE         = $00000100;
  {$EXTERNALSYM D3DPRASTERCAPS_FOGTABLE}
  D3DPRASTERCAPS_STIPPLE          = $00000200;
  {$EXTERNALSYM D3DPRASTERCAPS_STIPPLE}
{$IFDEF DIRECT3D_VERSION_5}
  D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT   = $00000400;
  {$EXTERNALSYM D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT}
  D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT = $00000800;
  {$EXTERNALSYM D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT}
  D3DPRASTERCAPS_ANTIALIASEDGES           = $00001000;
  {$EXTERNALSYM D3DPRASTERCAPS_ANTIALIASEDGES}
  D3DPRASTERCAPS_MIPMAPLODBIAS            = $00002000;
  {$EXTERNALSYM D3DPRASTERCAPS_MIPMAPLODBIAS}
  D3DPRASTERCAPS_ZBIAS                    = $00004000;
  {$EXTERNALSYM D3DPRASTERCAPS_ZBIAS}
  D3DPRASTERCAPS_ZBUFFERLESSHSR           = $00008000;
  {$EXTERNALSYM D3DPRASTERCAPS_ZBUFFERLESSHSR}
  D3DPRASTERCAPS_FOGRANGE                 = $00010000;
  {$EXTERNALSYM D3DPRASTERCAPS_FOGRANGE}
  D3DPRASTERCAPS_ANISOTROPY               = $00020000;
  {$EXTERNALSYM D3DPRASTERCAPS_ANISOTROPY}
{$ENDIF} // DIRECT3D_VERSION_5
{$IFDEF DIRECT3D_VERSION_6}
  D3DPRASTERCAPS_WBUFFER                      = $00040000;
  {$EXTERNALSYM D3DPRASTERCAPS_WBUFFER}
  D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT   = $00080000;
  {$EXTERNALSYM D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT}
  D3DPRASTERCAPS_WFOG                         = $00100000;
  {$EXTERNALSYM D3DPRASTERCAPS_WFOG}
  D3DPRASTERCAPS_ZFOG                         = $00200000;
  {$EXTERNALSYM D3DPRASTERCAPS_ZFOG}
{$ENDIF} // DIRECT3D_VERSION_6

(* TD3DPrimCaps dwZCmpCaps, dwAlphaCmpCaps *)

const
  D3DPCMPCAPS_NEVER               = $00000001;
  {$EXTERNALSYM D3DPCMPCAPS_NEVER}
  D3DPCMPCAPS_LESS                = $00000002;
  {$EXTERNALSYM D3DPCMPCAPS_LESS}
  D3DPCMPCAPS_EQUAL               = $00000004;
  {$EXTERNALSYM D3DPCMPCAPS_EQUAL}
  D3DPCMPCAPS_LESSEQUAL           = $00000008;
  {$EXTERNALSYM D3DPCMPCAPS_LESSEQUAL}
  D3DPCMPCAPS_GREATER             = $00000010;
  {$EXTERNALSYM D3DPCMPCAPS_GREATER}
  D3DPCMPCAPS_NOTEQUAL            = $00000020;
  {$EXTERNALSYM D3DPCMPCAPS_NOTEQUAL}
  D3DPCMPCAPS_GREATEREQUAL        = $00000040;
  {$EXTERNALSYM D3DPCMPCAPS_GREATEREQUAL}
  D3DPCMPCAPS_ALWAYS              = $00000080;
  {$EXTERNALSYM D3DPCMPCAPS_ALWAYS}

(* TD3DPrimCaps dwSourceBlendCaps, dwDestBlendCaps *)

  D3DPBLENDCAPS_ZERO              = $00000001;
  {$EXTERNALSYM D3DPBLENDCAPS_ZERO}
  D3DPBLENDCAPS_ONE               = $00000002;
  {$EXTERNALSYM D3DPBLENDCAPS_ONE}
  D3DPBLENDCAPS_SRCCOLOR          = $00000004;
  {$EXTERNALSYM D3DPBLENDCAPS_SRCCOLOR}
  D3DPBLENDCAPS_INVSRCCOLOR       = $00000008;
  {$EXTERNALSYM D3DPBLENDCAPS_INVSRCCOLOR}
  D3DPBLENDCAPS_SRCALPHA          = $00000010;
  {$EXTERNALSYM D3DPBLENDCAPS_SRCALPHA}
  D3DPBLENDCAPS_INVSRCALPHA       = $00000020;
  {$EXTERNALSYM D3DPBLENDCAPS_INVSRCALPHA}
  D3DPBLENDCAPS_DESTALPHA         = $00000040;
  {$EXTERNALSYM D3DPBLENDCAPS_DESTALPHA}
  D3DPBLENDCAPS_INVDESTALPHA      = $00000080;
  {$EXTERNALSYM D3DPBLENDCAPS_INVDESTALPHA}
  D3DPBLENDCAPS_DESTCOLOR         = $00000100;
  {$EXTERNALSYM D3DPBLENDCAPS_DESTCOLOR}
  D3DPBLENDCAPS_INVDESTCOLOR      = $00000200;
  {$EXTERNALSYM D3DPBLENDCAPS_INVDESTCOLOR}
  D3DPBLENDCAPS_SRCALPHASAT       = $00000400;
  {$EXTERNALSYM D3DPBLENDCAPS_SRCALPHASAT}
  D3DPBLENDCAPS_BOTHSRCALPHA      = $00000800;
  {$EXTERNALSYM D3DPBLENDCAPS_BOTHSRCALPHA}
  D3DPBLENDCAPS_BOTHINVSRCALPHA   = $00001000;
  {$EXTERNALSYM D3DPBLENDCAPS_BOTHINVSRCALPHA}

(* TD3DPrimCaps dwShadeCaps *)

  D3DPSHADECAPS_COLORFLATMONO             = $00000001;
  {$EXTERNALSYM D3DPSHADECAPS_COLORFLATMONO}
  D3DPSHADECAPS_COLORFLATRGB              = $00000002;
  {$EXTERNALSYM D3DPSHADECAPS_COLORFLATRGB}
  D3DPSHADECAPS_COLORGOURAUDMONO          = $00000004;
  {$EXTERNALSYM D3DPSHADECAPS_COLORGOURAUDMONO}
  D3DPSHADECAPS_COLORGOURAUDRGB           = $00000008;
  {$EXTERNALSYM D3DPSHADECAPS_COLORGOURAUDRGB}
  D3DPSHADECAPS_COLORPHONGMONO            = $00000010;
  {$EXTERNALSYM D3DPSHADECAPS_COLORPHONGMONO}
  D3DPSHADECAPS_COLORPHONGRGB             = $00000020;
  {$EXTERNALSYM D3DPSHADECAPS_COLORPHONGRGB}

  D3DPSHADECAPS_SPECULARFLATMONO          = $00000040;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARFLATMONO}
  D3DPSHADECAPS_SPECULARFLATRGB           = $00000080;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARFLATRGB}
  D3DPSHADECAPS_SPECULARGOURAUDMONO       = $00000100;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARGOURAUDMONO}
  D3DPSHADECAPS_SPECULARGOURAUDRGB        = $00000200;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARGOURAUDRGB}
  D3DPSHADECAPS_SPECULARPHONGMONO         = $00000400;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARPHONGMONO}
  D3DPSHADECAPS_SPECULARPHONGRGB          = $00000800;
  {$EXTERNALSYM D3DPSHADECAPS_SPECULARPHONGRGB}

  D3DPSHADECAPS_ALPHAFLATBLEND            = $00001000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAFLATBLEND}
  D3DPSHADECAPS_ALPHAFLATSTIPPLED         = $00002000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAFLATSTIPPLED}
  D3DPSHADECAPS_ALPHAGOURAUDBLEND         = $00004000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAGOURAUDBLEND}
  D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED      = $00008000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED}
  D3DPSHADECAPS_ALPHAPHONGBLEND           = $00010000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAPHONGBLEND}
  D3DPSHADECAPS_ALPHAPHONGSTIPPLED        = $00020000;
  {$EXTERNALSYM D3DPSHADECAPS_ALPHAPHONGSTIPPLED}

  D3DPSHADECAPS_FOGFLAT                   = $00040000;
  {$EXTERNALSYM D3DPSHADECAPS_FOGFLAT}
  D3DPSHADECAPS_FOGGOURAUD                = $00080000;
  {$EXTERNALSYM D3DPSHADECAPS_FOGGOURAUD}
  D3DPSHADECAPS_FOGPHONG                  = $00100000;
  {$EXTERNALSYM D3DPSHADECAPS_FOGPHONG}

(* TD3DPrimCaps dwTextureCaps *)

(*
 * Perspective-correct texturing is supported
 *)
  D3DPTEXTURECAPS_PERSPECTIVE     = $00000001;
  {$EXTERNALSYM D3DPTEXTURECAPS_PERSPECTIVE}

(*
 * Power-of-2 texture dimensions are required
 *)
  D3DPTEXTURECAPS_POW2            = $00000002;
  {$EXTERNALSYM D3DPTEXTURECAPS_POW2}

(*
 * Alpha in texture pixels is supported
 *)
  D3DPTEXTURECAPS_ALPHA           = $00000004;
  {$EXTERNALSYM D3DPTEXTURECAPS_ALPHA}

(*
 * Color-keyed textures are supported
 *)
  D3DPTEXTURECAPS_TRANSPARENCY    = $00000008;
  {$EXTERNALSYM D3DPTEXTURECAPS_TRANSPARENCY}

(*
 * obsolete, see D3DPTADDRESSCAPS_BORDER
 *)
  D3DPTEXTURECAPS_BORDER          = $00000010;
  {$EXTERNALSYM D3DPTEXTURECAPS_BORDER}

(*
 * Only square textures are supported
 *)
  D3DPTEXTURECAPS_SQUAREONLY      = $00000020;
  {$EXTERNALSYM D3DPTEXTURECAPS_SQUAREONLY}

{$IFDEF DIRECT3D_VERSION_6}
(*
 * Texture indices are not scaled by the texture size prior
 * to interpolation.
 *)
  D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE = $00000040;
  {$EXTERNALSYM D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE}

(*
 * Device can draw alpha from texture palettes
 *)
  D3DPTEXTURECAPS_ALPHAPALETTE    = $00000080;
  {$EXTERNALSYM D3DPTEXTURECAPS_ALPHAPALETTE}

(*
 * Device can use non-POW2 textures if:
 *  1) D3DTEXTURE_ADDRESS is set to CLAMP for this texture's stage
 *  2) D3DRS_WRAP(N) is zero for this texture's coordinates
 *  3) mip mapping is not enabled (use magnification filter only)
 *)
  D3DPTEXTURECAPS_NONPOW2CONDITIONAL  = $00000100;
  {$EXTERNALSYM D3DPTEXTURECAPS_NONPOW2CONDITIONAL}
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}
// 0x00000200L unused

(*
 * Device can divide transformed texture coordinates by the
 * COUNTth texture coordinate (can do D3DTTFF_PROJECTED)
 *)
  D3DPTEXTURECAPS_PROJECTED  = $00000400;
  {$EXTERNALSYM D3DPTEXTURECAPS_PROJECTED}

(*
 * Device can do cubemap textures
 *)
  D3DPTEXTURECAPS_CUBEMAP           = $00000800;
  {$EXTERNALSYM D3DPTEXTURECAPS_CUBEMAP}

  D3DPTEXTURECAPS_COLORKEYBLEND     = $00001000;
  {$EXTERNALSYM D3DPTEXTURECAPS_COLORKEYBLEND}
{$ENDIF} // DIRECT3D_VERSION_7


(* TD3DPrimCaps dwTextureFilterCaps *)

  D3DPTFILTERCAPS_NEAREST         = $00000001;
  {$EXTERNALSYM D3DPTFILTERCAPS_NEAREST}
  D3DPTFILTERCAPS_LINEAR          = $00000002;
  {$EXTERNALSYM D3DPTFILTERCAPS_LINEAR}
  D3DPTFILTERCAPS_MIPNEAREST      = $00000004;
  {$EXTERNALSYM D3DPTFILTERCAPS_MIPNEAREST}
  D3DPTFILTERCAPS_MIPLINEAR       = $00000008;
  {$EXTERNALSYM D3DPTFILTERCAPS_MIPLINEAR}
  D3DPTFILTERCAPS_LINEARMIPNEAREST = $00000010;
  {$EXTERNALSYM D3DPTFILTERCAPS_LINEARMIPNEAREST}
  D3DPTFILTERCAPS_LINEARMIPLINEAR = $00000020;
  {$EXTERNALSYM D3DPTFILTERCAPS_LINEARMIPLINEAR}

{$IFDEF DIRECT3D_VERSION_6}
(* Device3 Min Filter *)
  D3DPTFILTERCAPS_MINFPOINT       = $00000100;
  {$EXTERNALSYM D3DPTFILTERCAPS_MINFPOINT}
  D3DPTFILTERCAPS_MINFLINEAR      = $00000200;
  {$EXTERNALSYM D3DPTFILTERCAPS_MINFLINEAR}
  D3DPTFILTERCAPS_MINFANISOTROPIC = $00000400;
  {$EXTERNALSYM D3DPTFILTERCAPS_MINFANISOTROPIC}

(* Device3 Mip Filter *)
  D3DPTFILTERCAPS_MIPFPOINT       = $00010000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MIPFPOINT}
  D3DPTFILTERCAPS_MIPFLINEAR      = $00020000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MIPFLINEAR}

(* Device3 Mag Filter *)
  D3DPTFILTERCAPS_MAGFPOINT         = $01000000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MAGFPOINT}
  D3DPTFILTERCAPS_MAGFLINEAR        = $02000000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MAGFLINEAR}
  D3DPTFILTERCAPS_MAGFANISOTROPIC   = $04000000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MAGFANISOTROPIC}
  D3DPTFILTERCAPS_MAGFAFLATCUBIC    = $08000000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MAGFAFLATCUBIC}
  D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC = $10000000;
  {$EXTERNALSYM D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC}
{$ENDIF} // DIRECT3D_VERSION_6

(* TD3DPrimCaps dwTextureBlendCaps *)

  D3DPTBLENDCAPS_DECAL            = $00000001;
  {$EXTERNALSYM D3DPTBLENDCAPS_DECAL}
  D3DPTBLENDCAPS_MODULATE         = $00000002;
  {$EXTERNALSYM D3DPTBLENDCAPS_MODULATE}
  D3DPTBLENDCAPS_DECALALPHA       = $00000004;
  {$EXTERNALSYM D3DPTBLENDCAPS_DECALALPHA}
  D3DPTBLENDCAPS_MODULATEALPHA    = $00000008;
  {$EXTERNALSYM D3DPTBLENDCAPS_MODULATEALPHA}
  D3DPTBLENDCAPS_DECALMASK        = $00000010;
  {$EXTERNALSYM D3DPTBLENDCAPS_DECALMASK}
  D3DPTBLENDCAPS_MODULATEMASK     = $00000020;
  {$EXTERNALSYM D3DPTBLENDCAPS_MODULATEMASK}
  D3DPTBLENDCAPS_COPY             = $00000040;
  {$EXTERNALSYM D3DPTBLENDCAPS_COPY}
{$IFDEF DIRECT3D_VERSION_5}
  D3DPTBLENDCAPS_ADD	        	  = $00000080;
  {$EXTERNALSYM D3DPTBLENDCAPS_ADD}
{$ENDIF} // DIRECT3D_VERSION_5

(* TD3DPrimCaps dwTextureAddressCaps *)
  D3DPTADDRESSCAPS_WRAP           = $00000001;
  {$EXTERNALSYM D3DPTADDRESSCAPS_WRAP}
  D3DPTADDRESSCAPS_MIRROR         = $00000002;
  {$EXTERNALSYM D3DPTADDRESSCAPS_MIRROR}
  D3DPTADDRESSCAPS_CLAMP          = $00000004;
  {$EXTERNALSYM D3DPTADDRESSCAPS_CLAMP}
{$IFDEF DIRECT3D_VERSION_5}
  D3DPTADDRESSCAPS_BORDER         = $00000008;
  {$EXTERNALSYM D3DPTADDRESSCAPS_BORDER}
  D3DPTADDRESSCAPS_INDEPENDENTUV  = $00000010;
  {$EXTERNALSYM D3DPTADDRESSCAPS_INDEPENDENTUV}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}

(* D3DDEVICEDESC dwStencilCaps *)

  D3DSTENCILCAPS_KEEP     = $00000001;
  {$EXTERNALSYM D3DSTENCILCAPS_KEEP}
  D3DSTENCILCAPS_ZERO     = $00000002;
  {$EXTERNALSYM D3DSTENCILCAPS_ZERO}
  D3DSTENCILCAPS_REPLACE  = $00000004;
  {$EXTERNALSYM D3DSTENCILCAPS_REPLACE}
  D3DSTENCILCAPS_INCRSAT  = $00000008;
  {$EXTERNALSYM D3DSTENCILCAPS_INCRSAT}
  D3DSTENCILCAPS_DECRSAT  = $00000010;
  {$EXTERNALSYM D3DSTENCILCAPS_DECRSAT}
  D3DSTENCILCAPS_INVERT   = $00000020;
  {$EXTERNALSYM D3DSTENCILCAPS_INVERT}
  D3DSTENCILCAPS_INCR     = $00000040;
  {$EXTERNALSYM D3DSTENCILCAPS_INCR}
  D3DSTENCILCAPS_DECR     = $00000080;
  {$EXTERNALSYM D3DSTENCILCAPS_DECR}

(* D3DDEVICEDESC dwTextureOpCaps *)

  D3DTEXOPCAPS_DISABLE                    = $00000001;
  {$EXTERNALSYM D3DTEXOPCAPS_DISABLE}
  D3DTEXOPCAPS_SELECTARG1                 = $00000002;
  {$EXTERNALSYM D3DTEXOPCAPS_SELECTARG1}
  D3DTEXOPCAPS_SELECTARG2                 = $00000004;
  {$EXTERNALSYM D3DTEXOPCAPS_SELECTARG2}
  D3DTEXOPCAPS_MODULATE                   = $00000008;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATE}
  D3DTEXOPCAPS_MODULATE2X                 = $00000010;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATE2X}
  D3DTEXOPCAPS_MODULATE4X                 = $00000020;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATE4X}
  D3DTEXOPCAPS_ADD                        = $00000040;
  {$EXTERNALSYM D3DTEXOPCAPS_ADD}
  D3DTEXOPCAPS_ADDSIGNED                  = $00000080;
  {$EXTERNALSYM D3DTEXOPCAPS_ADDSIGNED}
  D3DTEXOPCAPS_ADDSIGNED2X                = $00000100;
  {$EXTERNALSYM D3DTEXOPCAPS_ADDSIGNED2X}
  D3DTEXOPCAPS_SUBTRACT                   = $00000200;
  {$EXTERNALSYM D3DTEXOPCAPS_SUBTRACT}
  D3DTEXOPCAPS_ADDSMOOTH                  = $00000400;
  {$EXTERNALSYM D3DTEXOPCAPS_ADDSMOOTH}
  D3DTEXOPCAPS_BLENDDIFFUSEALPHA          = $00000800;
  {$EXTERNALSYM D3DTEXOPCAPS_BLENDDIFFUSEALPHA}
  D3DTEXOPCAPS_BLENDTEXTUREALPHA          = $00001000;
  {$EXTERNALSYM D3DTEXOPCAPS_BLENDTEXTUREALPHA}
  D3DTEXOPCAPS_BLENDFACTORALPHA           = $00002000;
  {$EXTERNALSYM D3DTEXOPCAPS_BLENDFACTORALPHA}
  D3DTEXOPCAPS_BLENDTEXTUREALPHAPM        = $00004000;
  {$EXTERNALSYM D3DTEXOPCAPS_BLENDTEXTUREALPHAPM}
  D3DTEXOPCAPS_BLENDCURRENTALPHA          = $00008000;
  {$EXTERNALSYM D3DTEXOPCAPS_BLENDCURRENTALPHA}
  D3DTEXOPCAPS_PREMODULATE                = $00010000;
  {$EXTERNALSYM D3DTEXOPCAPS_PREMODULATE}
  D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR     = $00020000;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR}
  D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA     = $00040000;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA}
  D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR  = $00080000;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR}
  D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA  = $00100000;
  {$EXTERNALSYM D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA}
  D3DTEXOPCAPS_BUMPENVMAP                 = $00200000;
  {$EXTERNALSYM D3DTEXOPCAPS_BUMPENVMAP}
  D3DTEXOPCAPS_BUMPENVMAPLUMINANCE        = $00400000;
  {$EXTERNALSYM D3DTEXOPCAPS_BUMPENVMAPLUMINANCE}
  D3DTEXOPCAPS_DOTPRODUCT3                = $00800000;
  {$EXTERNALSYM D3DTEXOPCAPS_DOTPRODUCT3}

(* D3DDEVICEDESC dwFVFCaps flags *)

  D3DFVFCAPS_TEXCOORDCOUNTMASK    = $0000ffff; (* mask for texture coordinate count field *)
  {$EXTERNALSYM D3DFVFCAPS_TEXCOORDCOUNTMASK}
  D3DFVFCAPS_DONOTSTRIPELEMENTS   = $00080000; (* Device prefers that vertex elements not be stripped *)
  {$EXTERNALSYM D3DFVFCAPS_DONOTSTRIPELEMENTS}

{$ENDIF} // DIRECT3D_VERSION_6

(*
 * Description for a device.
 * This is used to describe a device that is to be created or to query
 * the current device.
 *)

type
  PD3DDeviceDesc = ^TD3DDeviceDesc;
  _D3DDeviceDesc = packed record
    dwSize: DWORD;                       (* Size of TD3DDeviceDesc structure *)
    dwFlags: DWORD;                      (* Indicates which fields have valid data *)
    dcmColorModel: TD3DColorModel;       (* Color model of device *)
    dwDevCaps: DWORD;                    (* Capabilities of device *)
    dtcTransformCaps: TD3DTransformCaps; (* Capabilities of transform *)
    bClipping: BOOL;                     (* Device can do 3D clipping *)
    dlcLightingCaps: TD3DLightingCaps;   (* Capabilities of lighting *)
    dpcLineCaps: TD3DPrimCaps;
    dpcTriCaps: TD3DPrimCaps;
    dwDeviceRenderBitDepth: DWORD;       (* One of DDBB_8, 16, etc.. *)
    dwDeviceZBufferBitDepth: DWORD;      (* One of DDBD_16, 32, etc.. *)
    dwMaxBufferSize: DWORD;              (* Maximum execute buffer size *)
    dwMaxVertexCount: DWORD;             (* Maximum vertex count *)
{$IFDEF DIRECT3D_VERSION_5}
    // *** New fields for DX5 *** //

    // Width and height caps are 0 for legacy HALs.
    dwMinTextureWidth, dwMinTextureHeight  : DWORD;
    dwMaxTextureWidth, dwMaxTextureHeight  : DWORD;
    dwMinStippleWidth, dwMaxStippleWidth   : DWORD;
    dwMinStippleHeight, dwMaxStippleHeight : DWORD;
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
    // New fields for DX6
    dwMaxTextureRepeat : DWORD;
    dwMaxTextureAspectRatio : DWORD;
    dwMaxAnisotropy : DWORD;

    // Guard band that the rasterizer can accommodate
    // Screen-space vertices inside this space but outside the viewport
    // will get clipped properly.
    dvGuardBandLeft : TD3DValue;
    dvGuardBandTop : TD3DValue;
    dvGuardBandRight : TD3DValue;
    dvGuardBandBottom : TD3DValue;

    dvExtentsAdjust : TD3DValue;
    dwStencilCaps : DWORD;

    dwFVFCaps : DWORD;  (* low 4 bits: 0 implies TLVERTEX only, 1..8 imply FVF aware *)
    dwTextureOpCaps : DWORD;
    wMaxTextureBlendStages : WORD;
    wMaxSimultaneousTextures : WORD;
{$ENDIF} // DIRECT3D_VERSION_6
  end;
  {$EXTERNALSYM _D3DDeviceDesc}
  D3DDeviceDesc = _D3DDeviceDesc;
  {$EXTERNALSYM D3DDeviceDesc}
  TD3DDeviceDesc = _D3DDeviceDesc;

{$IFDEF DIRECT3D_VERSION_7}
  PD3DDeviceDesc7 = ^TD3DDeviceDesc7;
  _D3DDeviceDesc7 = packed record
    dwDevCaps:               DWORD;             (* Capabilities of device *)
    dpcLineCaps:             TD3DPrimCaps;
    dpcTriCaps:              TD3DPrimCaps;
    dwDeviceRenderBitDepth:  DWORD;             (* One of DDBB_8, 16, etc.. *)
    dwDeviceZBufferBitDepth: DWORD;             (* One of DDBD_16, 32, etc.. *)

    dwMinTextureWidth, dwMinTextureHeight: DWORD;
    dwMaxTextureWidth, dwMaxTextureHeight: DWORD;

    dwMaxTextureRepeat:                    DWORD;
    dwMaxTextureAspectRatio:               DWORD;
    dwMaxAnisotropy:                       DWORD;

    dvGuardBandLeft:                       TD3DValue;
    dvGuardBandTop:                        TD3DValue;
    dvGuardBandRight:                      TD3DValue;
    dvGuardBandBottom:                     TD3DValue;

    dvExtentsAdjust:                       TD3DValue;
    dwStencilCaps:                         DWORD;

    dwFVFCaps:                             DWORD;
    dwTextureOpCaps:                       DWORD;
    wMaxTextureBlendStages:                WORD;
    wMaxSimultaneousTextures:              WORD;

    dwMaxActiveLights:                     DWORD;
    dvMaxVertexW:                          TD3DValue;
    deviceGUID:                            TGUID;

    wMaxUserClipPlanes:                    WORD;
    wMaxVertexBlendMatrices:               WORD;

    dwVertexProcessingCaps:                DWORD;

    dwReserved1:                           DWORD;
    dwReserved2:                           DWORD;
    dwReserved3:                           DWORD;
    dwReserved4:                           DWORD;
  end;
  {$EXTERNALSYM _D3DDeviceDesc7}
  D3DDeviceDesc7 = _D3DDeviceDesc7;
  {$EXTERNALSYM D3DDeviceDesc7}
  TD3DDeviceDesc7 = _D3DDeviceDesc7;
{$ENDIF} // DIRECT3D_VERSION_7

const
  D3DDEVICEDESCSIZE = SizeOf(TD3DDeviceDesc);
  {$EXTERNALSYM D3DDEVICEDESCSIZE}
{$IFDEF DIRECT3D_VERSION_7} // There is the BUG in C++Headers
  D3DDEVICEDESC7SIZE = SizeOf(TD3DDeviceDesc7);
  {$EXTERNALSYM D3DDEVICEDESC7SIZE}
{$ENDIF} // DIRECT3D_VERSION_7

type
  TD3DEnumDevicesCallbackA = function (lpGuid: PGUID; // nil for the default device
      lpDeviceDescription: PAnsiChar; lpDeviceName: PAnsiChar;
      var lpD3DHWDeviceDesc: TD3DDeviceDesc;
      var lpD3DHELDeviceDesc: TD3DDeviceDesc;
      lpContext: Pointer): HResult; stdcall;
  TD3DEnumDevicesCallback = TD3DEnumDevicesCallbackA;
  {$NODEFINE TD3DEnumDevicesCallbackA}
  {$NODEFINE TD3DEnumDevicesCallback}

{$IFDEF DIRECT3D_VERSION_7}
  TD3DEnumDevicesCallback7A = function (
      lpDeviceDescription: PAnsiChar; lpDeviceName: PAnsiChar;
      const lpD3DDeviceDesc: TD3DDeviceDesc7; lpContext: Pointer): HResult; stdcall;
  TD3DEnumDevicesCallback7 = TD3DEnumDevicesCallback7A;
  {$NODEFINE TD3DEnumDevicesCallback7A}
  {$NODEFINE TD3DEnumDevicesCallback7}
{$ENDIF} // DIRECT3D_VERSION_7

(* TD3DDeviceDesc dwFlags indicating valid fields *)

const
  D3DDD_COLORMODEL            = $00000001; (* dcmColorModel is valid *)
  {$EXTERNALSYM D3DDD_COLORMODEL}
  D3DDD_DEVCAPS               = $00000002; (* dwDevCaps is valid *)
  {$EXTERNALSYM D3DDD_DEVCAPS}
  D3DDD_TRANSFORMCAPS         = $00000004; (* dtcTransformCaps is valid *)
  {$EXTERNALSYM D3DDD_TRANSFORMCAPS}
  D3DDD_LIGHTINGCAPS          = $00000008; (* dlcLightingCaps is valid *)
  {$EXTERNALSYM D3DDD_LIGHTINGCAPS}
  D3DDD_BCLIPPING             = $00000010; (* bClipping is valid *)
  {$EXTERNALSYM D3DDD_BCLIPPING}
  D3DDD_LINECAPS              = $00000020; (* dpcLineCaps is valid *)
  {$EXTERNALSYM D3DDD_LINECAPS}
  D3DDD_TRICAPS               = $00000040; (* dpcTriCaps is valid *)
  {$EXTERNALSYM D3DDD_TRICAPS}
  D3DDD_DEVICERENDERBITDEPTH  = $00000080; (* dwDeviceRenderBitDepth is valid *)
  {$EXTERNALSYM D3DDD_DEVICERENDERBITDEPTH}
  D3DDD_DEVICEZBUFFERBITDEPTH = $00000100; (* dwDeviceZBufferBitDepth is valid *)
  {$EXTERNALSYM D3DDD_DEVICEZBUFFERBITDEPTH}
  D3DDD_MAXBUFFERSIZE         = $00000200; (* dwMaxBufferSize is valid *)
  {$EXTERNALSYM D3DDD_MAXBUFFERSIZE}
  D3DDD_MAXVERTEXCOUNT        = $00000400; (* dwMaxVertexCount is valid *)
  {$EXTERNALSYM D3DDD_MAXVERTEXCOUNT}

(* TD3DDeviceDesc dwDevCaps flags *)

  D3DDEVCAPS_FLOATTLVERTEX        = $00000001; (* Device accepts floating point *)
                                               (* for post-transform vertex data *)
  {$EXTERNALSYM D3DDEVCAPS_FLOATTLVERTEX}
  D3DDEVCAPS_SORTINCREASINGZ      = $00000002; (* Device needs data sorted for increasing Z*)
  {$EXTERNALSYM D3DDEVCAPS_SORTINCREASINGZ}
  D3DDEVCAPS_SORTDECREASINGZ      = $00000004; (* Device needs data sorted for decreasing Z*)
  {$EXTERNALSYM D3DDEVCAPS_SORTDECREASINGZ}
  D3DDEVCAPS_SORTEXACT            = $00000008; (* Device needs data sorted exactly *)
  {$EXTERNALSYM D3DDEVCAPS_SORTEXACT}

  D3DDEVCAPS_EXECUTESYSTEMMEMORY  = $00000010; (* Device can use execute buffers from system memory *)
  {$EXTERNALSYM D3DDEVCAPS_EXECUTESYSTEMMEMORY}
  D3DDEVCAPS_EXECUTEVIDEOMEMORY   = $00000020; (* Device can use execute buffers from video memory *)
  {$EXTERNALSYM D3DDEVCAPS_EXECUTEVIDEOMEMORY}
  D3DDEVCAPS_TLVERTEXSYSTEMMEMORY = $00000040; (* Device can use TL buffers from system memory *)
  {$EXTERNALSYM D3DDEVCAPS_TLVERTEXSYSTEMMEMORY}
  D3DDEVCAPS_TLVERTEXVIDEOMEMORY  = $00000080; (* Device can use TL buffers from video memory *)
  {$EXTERNALSYM D3DDEVCAPS_TLVERTEXVIDEOMEMORY}
  D3DDEVCAPS_TEXTURESYSTEMMEMORY  = $00000100; (* Device can texture from system memory *)
  {$EXTERNALSYM D3DDEVCAPS_TEXTURESYSTEMMEMORY}
  D3DDEVCAPS_TEXTUREVIDEOMEMORY   = $00000200; (* Device can texture from device memory *)
  {$EXTERNALSYM D3DDEVCAPS_TEXTUREVIDEOMEMORY}
{$IFDEF DIRECT3D_VERSION_5}
  D3DDEVCAPS_DRAWPRIMTLVERTEX     = $00000400; (* Device can draw TLVERTEX primitives *)
  {$EXTERNALSYM D3DDEVCAPS_DRAWPRIMTLVERTEX}
  D3DDEVCAPS_CANRENDERAFTERFLIP	  = $00000800; (* Device can render without waiting for flip to complete *)
  {$EXTERNALSYM D3DDEVCAPS_CANRENDERAFTERFLIP}
  D3DDEVCAPS_TEXTURENONLOCALVIDMEM   = $00001000; (* Device can texture from nonlocal video memory *)
  {$EXTERNALSYM D3DDEVCAPS_TEXTURENONLOCALVIDMEM}
{$ENDIF} // DIRECT3D_VERSION_5
{$IFDEF DIRECT3D_VERSION_6}
  D3DDEVCAPS_DRAWPRIMITIVES2         = $00002000; (* Device can support DrawPrimitives2 *)
  {$EXTERNALSYM D3DDEVCAPS_DRAWPRIMITIVES2}
  D3DDEVCAPS_SEPARATETEXTUREMEMORIES = $00004000; (* Device is texturing from separate memory pools *)
  {$EXTERNALSYM D3DDEVCAPS_SEPARATETEXTUREMEMORIES}
  D3DDEVCAPS_DRAWPRIMITIVES2EX       = $00008000; (* Device can support Extended DrawPrimitives2 i.e. DX7 compliant driver*)
  {$EXTERNALSYM D3DDEVCAPS_DRAWPRIMITIVES2EX}
{$ENDIF} // DIRECT3D_VERSION_6
{$IFDEF DIRECT3D_VERSION_7}
  D3DDEVCAPS_HWTRANSFORMANDLIGHT     = $00010000; (* Device can support transformation and lighting in hardware and DRAWPRIMITIVES2EX must be also *)
  {$EXTERNALSYM D3DDEVCAPS_HWTRANSFORMANDLIGHT}
  D3DDEVCAPS_CANBLTSYSTONONLOCAL     = $00020000; (* Device supports a Tex Blt from system memory to non-local vidmem *)
  {$EXTERNALSYM D3DDEVCAPS_CANBLTSYSTONONLOCAL}
  D3DDEVCAPS_HWRASTERIZATION         = $00080000; (* Device has HW acceleration for rasterization *)
  {$EXTERNALSYM D3DDEVCAPS_HWRASTERIZATION}

(*
 * These are the flags in the D3DDEVICEDESC7.dwVertexProcessingCaps field
 *)

(* device can do texgen *)
  D3DVTXPCAPS_TEXGEN              = $00000001;
  {$EXTERNALSYM D3DVTXPCAPS_TEXGEN}
(* device can do IDirect3DDevice7 colormaterialsource ops *)
  D3DVTXPCAPS_MATERIALSOURCE7     = $00000002;
  {$EXTERNALSYM D3DVTXPCAPS_MATERIALSOURCE7}
(* device can do vertex fog *)
  D3DVTXPCAPS_VERTEXFOG           = $00000004;
  {$EXTERNALSYM D3DVTXPCAPS_VERTEXFOG}
(* device can do directional lights *)
  D3DVTXPCAPS_DIRECTIONALLIGHTS   = $00000008;
  {$EXTERNALSYM D3DVTXPCAPS_DIRECTIONALLIGHTS}
(* device can do positional lights (includes point and spot) *)
  D3DVTXPCAPS_POSITIONALLIGHTS    = $00000010;
  {$EXTERNALSYM D3DVTXPCAPS_POSITIONALLIGHTS}
(* device can do local viewer *)
  D3DVTXPCAPS_LOCALVIEWER         = $00000020;
  {$EXTERNALSYM D3DVTXPCAPS_LOCALVIEWER}
{$ENDIF} // DIRECT3D_VERSION_7

  D3DFDS_COLORMODEL        = $00000001; (* Match color model *)
  {$EXTERNALSYM D3DFDS_COLORMODEL}
  D3DFDS_GUID              = $00000002; (* Match guid *)
  {$EXTERNALSYM D3DFDS_GUID}
  D3DFDS_HARDWARE          = $00000004; (* Match hardware/software *)
  {$EXTERNALSYM D3DFDS_HARDWARE}
  D3DFDS_TRIANGLES         = $00000008; (* Match in triCaps *)
  {$EXTERNALSYM D3DFDS_TRIANGLES}
  D3DFDS_LINES             = $00000010; (* Match in lineCaps  *)
  {$EXTERNALSYM D3DFDS_LINES}
  D3DFDS_MISCCAPS          = $00000020; (* Match primCaps.dwMiscCaps *)
  {$EXTERNALSYM D3DFDS_MISCCAPS}
  D3DFDS_RASTERCAPS        = $00000040; (* Match primCaps.dwRasterCaps *)
  {$EXTERNALSYM D3DFDS_RASTERCAPS}
  D3DFDS_ZCMPCAPS          = $00000080; (* Match primCaps.dwZCmpCaps *)
  {$EXTERNALSYM D3DFDS_ZCMPCAPS}
  D3DFDS_ALPHACMPCAPS      = $00000100; (* Match primCaps.dwAlphaCmpCaps *)
  {$EXTERNALSYM D3DFDS_ALPHACMPCAPS}
  D3DFDS_SRCBLENDCAPS      = $00000200; (* Match primCaps.dwSourceBlendCaps *)
  {$EXTERNALSYM D3DFDS_SRCBLENDCAPS}
  D3DFDS_DSTBLENDCAPS      = $00000400; (* Match primCaps.dwDestBlendCaps *)
  {$EXTERNALSYM D3DFDS_DSTBLENDCAPS}
  D3DFDS_SHADECAPS         = $00000800; (* Match primCaps.dwShadeCaps *)
  {$EXTERNALSYM D3DFDS_SHADECAPS}
  D3DFDS_TEXTURECAPS       = $00001000; (* Match primCaps.dwTextureCaps *)
  {$EXTERNALSYM D3DFDS_TEXTURECAPS}
  D3DFDS_TEXTUREFILTERCAPS = $00002000; (* Match primCaps.dwTextureFilterCaps *)
  {$EXTERNALSYM D3DFDS_TEXTUREFILTERCAPS}
  D3DFDS_TEXTUREBLENDCAPS  = $00004000; (* Match primCaps.dwTextureBlendCaps *)
  {$EXTERNALSYM D3DFDS_TEXTUREBLENDCAPS}
  D3DFDS_TEXTUREADDRESSCAPS  = $00008000; (* Match primCaps.dwTextureBlendCaps *)
  {$EXTERNALSYM D3DFDS_TEXTUREADDRESSCAPS}

(*
 * FindDevice arguments
 *)
type
  PD3DFindDeviceSearch = ^TD3DFindDeviceSearch;
  _D3DFINDDEVICESEARCH = packed record
    dwSize: DWORD;
    dwFlags: DWORD;
    bHardware: BOOL;
    dcmColorModel: TD3DColorModel;
    guid: TGUID;
    dwCaps: DWORD;
    dpcPrimCaps: TD3DPrimCaps;
  end;
  {$EXTERNALSYM _D3DFINDDEVICESEARCH}
  D3DFINDDEVICESEARCH = _D3DFINDDEVICESEARCH;
  {$EXTERNALSYM D3DFINDDEVICESEARCH}
  TD3DFindDeviceSearch = _D3DFINDDEVICESEARCH;

  PD3DFindDeviceResult = ^TD3DFindDeviceResult;
  _D3DFINDDEVICERESULT = packed record
    dwSize: DWORD;
    guid: TGUID;                (* guid which matched *)
    ddHwDesc: TD3DDeviceDesc;   (* hardware TD3DDeviceDesc *)
    ddSwDesc: TD3DDeviceDesc;   (* software TD3DDeviceDesc *)
  end;
  {$EXTERNALSYM _D3DFINDDEVICERESULT}
  D3DFINDDEVICERESULT = _D3DFINDDEVICERESULT;
  {$EXTERNALSYM D3DFINDDEVICERESULT}
  TD3DFindDeviceResult = _D3DFINDDEVICERESULT;

(*
 * Description of execute buffer.
 *)
  PD3DExecuteBufferDesc = ^TD3DExecuteBufferDesc;
  _D3DExecuteBufferDesc = packed record
    dwSize: DWORD;         (* size of this structure *)
    dwFlags: DWORD;        (* flags indicating which fields are valid *)
    dwCaps: DWORD;         (* capabilities of execute buffer *)
    dwBufferSize: DWORD;   (* size of execute buffer data *)
    lpData: Pointer;       (* pointer to actual data *)
  end;
  {$EXTERNALSYM _D3DExecuteBufferDesc}
  D3DExecuteBufferDesc = _D3DExecuteBufferDesc;
  {$EXTERNALSYM D3DExecuteBufferDesc}
  TD3DExecuteBufferDesc = _D3DExecuteBufferDesc;

(* D3DEXECUTEBUFFER dwFlags indicating valid fields *)

const
  D3DDEB_BUFSIZE          = $00000001;     (* buffer size valid *)
  {$EXTERNALSYM D3DDEB_BUFSIZE}
  D3DDEB_CAPS             = $00000002;     (* caps valid *)
  {$EXTERNALSYM D3DDEB_CAPS}
  D3DDEB_LPDATA           = $00000004;     (* lpData valid *)
  {$EXTERNALSYM D3DDEB_LPDATA}

(* D3DEXECUTEBUFFER dwCaps *)

  D3DDEBCAPS_SYSTEMMEMORY = $00000001;     (* buffer in system memory *)
  {$EXTERNALSYM D3DDEBCAPS_SYSTEMMEMORY}
  D3DDEBCAPS_VIDEOMEMORY  = $00000002;     (* buffer in device memory *)
  {$EXTERNALSYM D3DDEBCAPS_VIDEOMEMORY}
  D3DDEBCAPS_MEM          = (D3DDEBCAPS_SYSTEMMEMORY or D3DDEBCAPS_VIDEOMEMORY);
  {$EXTERNALSYM D3DDEBCAPS_MEM}

{$IFDEF DIRECT3D_VERSION_LESS_8}
{$IFDEF DIRECT3D_VERSION_7}
type
  PD3DDevInfo_TextureManager = ^TD3DDevInfo_TextureManager;
  _D3DDEVINFO_TEXTUREMANAGER = packed record
    bThrashing:              BOOL;       (* indicates if thrashing *)
    dwApproxBytesDownloaded: DWORD;      (* Approximate number of bytes downloaded by texture manager *)
    dwNumEvicts:             DWORD;      (* number of textures evicted *)
    dwNumVidCreates:         DWORD;      (* number of textures created in video memory *)
    dwNumTexturesUsed:       DWORD;      (* number of textures used *)
    dwNumUsedTexInVid:       DWORD;      (* number of used textures present in video memory *)
    dwWorkingSet:            DWORD;      (* number of textures in video memory *)
    dwWorkingSetBytes:       DWORD;      (* number of bytes in video memory *)
    dwTotalManaged:          DWORD;      (* total number of managed textures *)
    dwTotalBytes:            DWORD;      (* total number of bytes of managed textures *)
    dwLastPri:               DWORD;      (* priority of last texture evicted *)
  end;
  {$EXTERNALSYM _D3DDEVINFO_TEXTUREMANAGER}
  D3DDEVINFO_TEXTUREMANAGER = _D3DDEVINFO_TEXTUREMANAGER;
  {$EXTERNALSYM D3DDEVINFO_TEXTUREMANAGER}
  TD3DDevInfo_TextureManager = _D3DDEVINFO_TEXTUREMANAGER;
  PD3DDevInfoTextureManager = PD3DDevInfo_TextureManager;
  TD3DDevInfoTextureManager = _D3DDEVINFO_TEXTUREMANAGER;

  PD3DDevInfo_Texturing = ^TD3DDevInfo_Texturing;
  _D3DDEVINFO_TEXTURING = packed record
    dwNumLoads:          DWORD;          (* counts Load() API calls *)
    dwApproxBytesLoaded: DWORD;          (* Approximate number bytes loaded via Load() *)
    dwNumPreLoads:       DWORD;          (* counts PreLoad() API calls *)
    dwNumSet:            DWORD;          (* counts SetTexture() API calls *)
    dwNumCreates:        DWORD;          (* counts texture creates *)
    dwNumDestroys:       DWORD;          (* counts texture destroys *)
    dwNumSetPriorities:  DWORD;          (* counts SetPriority() API calls *)
    dwNumSetLODs:        DWORD;          (* counts SetLOD() API calls *)
    dwNumLocks:          DWORD;          (* counts number of texture locks *)
    dwNumGetDCs:         DWORD;          (* counts number of GetDCs to textures *)
  end;
  {$EXTERNALSYM _D3DDEVINFO_TEXTURING}
  D3DDEVINFO_TEXTURING = _D3DDEVINFO_TEXTURING;
  {$EXTERNALSYM D3DDEVINFO_TEXTURING}
  TD3DDevInfo_Texturing = _D3DDEVINFO_TEXTURING;
  PD3DDevInfoTexturing = PD3DDevInfo_Texturing;
  TD3DDevInfoTexturing = TD3DDevInfo_Texturing;
{$ENDIF} // DIRECT3D_VERSION_7
{$ENDIF} // DIRECT3D_VERSION_LESS_8



(*==========================================================================;
 *
 *
 *  File:   d3d.h
 *  Content:    Direct3D include file
 *
 ****************************************************************************)

// include this file content only if compiling for <=DX7 interfaces
{$IFDEF DIRECT3D_VERSION_LESS_8}

function D3DErrorString(Value: HResult): String;


{$IFDEF DIRECT3D_VERSION_5}
const
  IID_IDirect3DRampDevice: TGUID =
      (D1:$F2086B20;D2:$259F;D3:$11CF;D4:($A3,$1A,$00,$AA,$00,$B9,$33,$56));
  {$EXTERNALSYM IID_IDirect3DRampDevice}
  IID_IDirect3DRGBDevice: TGUID =
      (D1:$A4665C60;D2:$2673;D3:$11CF;D4:($A3,$1A,$00,$AA,$00,$B9,$33,$56));
  {$EXTERNALSYM IID_IDirect3DRGBDevice}
  IID_IDirect3DHALDevice: TGUID =
      (D1:$84E63dE0;D2:$46AA;D3:$11CF;D4:($81,$6F,$00,$00,$C0,$20,$15,$6E));
  {$EXTERNALSYM IID_IDirect3DHALDevice}
  IID_IDirect3DMMXDevice: TGUID =
      (D1:$881949a1;D2:$d6f3;D3:$11d0;D4:($89,$ab,$00,$a0,$c9,$05,$41,$29));
  {$EXTERNALSYM IID_IDirect3DMMXDevice}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3DRefDevice: TGUID =
      (D1:$50936643;D2:$13e9;D3:$11d1;D4:($89,$aa,$00,$a0,$c9,$05,$41,$29));
  {$EXTERNALSYM IID_IDirect3DRefDevice}
  IID_IDirect3DNullDevice: TGUID =
      (D1:$8767df22;D2:$bacc;D3:$11d1;D4:($89,$69,$00,$a0,$c9,$06,$29,$a8));
  {$EXTERNALSYM IID_IDirect3DNullDevice}
{$ENDIF} // DIRECT3D_VERSION_6
{$IFDEF DIRECT3D_VERSION_7}
  IID_IDirect3DTnLHalDevice: TGUID = '{f5049e78-4861-11d2-a407-00a0c90629a8}';
  {$EXTERNALSYM IID_IDirect3DTnLHalDevice}
{$ENDIF} // DIRECT3D_VERSION_7

type
  IDirect3D = interface;
  {$EXTERNALSYM IDirect3D}
  {$IFDEF DIRECT3D_VERSION_5}
  IDirect3D2 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_6}
  IDirect3D3 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_7}
  IDirect3D7 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  IDirect3DDevice = interface;
  {$IFDEF DIRECT3D_VERSION_5}
  IDirect3DDevice2 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_6}
  IDirect3DDevice3 = interface;
  {$ENDIF} // DIRECT3D_VERSION_6
  {$IFDEF DIRECT3D_VERSION_7}
  IDirect3DDevice7 = interface;
  {$ENDIF} // DIRECT3D_VERSION_7
  IDirect3DExecuteBuffer = interface;
  IDirect3DLight = interface;
  IDirect3DMaterial = interface;
  {$IFDEF DIRECT3D_VERSION_5}
  IDirect3DMaterial2 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_6}
  IDirect3DMaterial3 = interface;
  {$ENDIF} // DIRECT3D_VERSION_6
  IDirect3DTexture = interface;
  {$IFDEF DIRECT3D_VERSION_5}
  IDirect3DTexture2 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  IDirect3DViewport = interface;
  {$IFDEF DIRECT3D_VERSION_5}
  IDirect3DViewport2 = interface;
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_6}
  IDirect3DViewport3 = interface;
  IDirect3DVertexBuffer = interface;
  {$ENDIF} // DIRECT3D_VERSION_6
  {$IFDEF DIRECT3D_VERSION_7}
  IDirect3DVertexBuffer7 = interface;
  {$ENDIF} // DIRECT3D_VERSION_7


(*
 * Interface IID's
 *)
  IID_IDirect3D = IDirect3D;
  {$EXTERNALSYM IID_IDirect3D}
  {$IFDEF DIRECT3D_VERSION_5}
  IID_IDirect3D2 = IDirect3D2;
  {$EXTERNALSYM IID_IDirect3D2}
  {$ENDIF} // DIRECT3D_VERSION_5
  {$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3D3 = IDirect3D3;
  {$EXTERNALSYM IID_IDirect3D3}
  {$ENDIF} // DIRECT3D_VERSION_6
  {$IFDEF DIRECT3D_VERSION_7}
  IID_IDirect3D7 = IDirect3D7;
  {$EXTERNALSYM IID_IDirect3D7}
  {$ENDIF} // DIRECT3D_VERSION_7


(*
 * Internal Guid to distinguish requested MMX from MMX being used as an RGB rasterizer
 *)

  IID_IDirect3DDevice = IDirect3DDevice;
  {$EXTERNALSYM IID_IDirect3DDevice}
  {$IFDEF DIRECT3D_VERSION_5}
  IID_IDirect3DDevice2 = IDirect3DDevice2;
  {$EXTERNALSYM IID_IDirect3DDevice2}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3DDevice3 = IDirect3DDevice3;
  {$EXTERNALSYM IID_IDirect3DDevice3}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_7}
  IID_IDirect3DDevice7 = IDirect3DDevice7;
  {$EXTERNALSYM IID_IDirect3DDevice7}
  {$ENDIF}

  IID_IDirect3DTexture = IDirect3DTexture;
  {$EXTERNALSYM IID_IDirect3DTexture}
  {$IFDEF DIRECT3D_VERSION_5}
  IID_IDirect3DTexture2 = IDirect3DTexture2;
  {$EXTERNALSYM IID_IDirect3DTexture2}
  {$ENDIF}

  IID_IDirect3DLight = IDirect3DLight;
  {$EXTERNALSYM IID_IDirect3DLight}

  IID_IDirect3DMaterial = IDirect3DMaterial;
  {$EXTERNALSYM IID_IDirect3DMaterial}
  {$IFDEF DIRECT3D_VERSION_5}
  IID_IDirect3DMaterial2 = IDirect3DMaterial2;
  {$EXTERNALSYM IID_IDirect3DMaterial2}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3DMaterial3 = IDirect3DMaterial3;
  {$EXTERNALSYM IID_IDirect3DMaterial3}
  {$ENDIF}

  IID_IDirect3DExecuteBuffer = IDirect3DExecuteBuffer;
  {$EXTERNALSYM IID_IDirect3DExecuteBuffer}
  IID_IDirect3DViewport = IDirect3DViewport;
  {$EXTERNALSYM IID_IDirect3DViewport}
  {$IFDEF DIRECT3D_VERSION_5}
  IID_IDirect3DViewport2 = IDirect3DViewport2;
  {$EXTERNALSYM IID_IDirect3DViewport2}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3DViewport3 = IDirect3DViewport3;
  {$EXTERNALSYM IID_IDirect3DViewport3}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_6}
  IID_IDirect3DVertexBuffer = IDirect3DVertexBuffer;
  {$EXTERNALSYM IID_IDirect3DVertexBuffer}
  {$ENDIF}
  {$IFDEF DIRECT3D_VERSION_7}
  IID_IDirect3DVertexBuffer7 = IDirect3DVertexBuffer7;
  {$EXTERNALSYM IID_IDirect3DVertexBuffer7}
  {$ENDIF}



(*
 * Direct3D interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3D);'}
  IDirect3D = interface(IUnknown)
    ['{3BBA0080-2421-11CF-A31A-00AA00B93356}']
    (*** IDirect3D methods ***)
    function Initialize(lpREFIID: {REFIID} PGUID): HResult; stdcall;
    function EnumDevices(lpEnumDevicesCallback: TD3DEnumDevicesCallback;
        lpUserArg: Pointer): HResult; stdcall;
    function CreateLight(var lplpDirect3Dlight: IDirect3DLight;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateMaterial(var lplpDirect3DMaterial: IDirect3DMaterial;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateViewport(var lplpD3DViewport: IDirect3DViewport;
        pUnkOuter: IUnknown): HResult; stdcall;
    function FindDevice(var lpD3DFDS: TD3DFindDeviceSearch;
        var lpD3DFDR: TD3DFindDeviceResult): HResult; stdcall;
  end;

{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3D2);'}
  {$EXTERNALSYM IDirect3D2}
  IDirect3D2 = interface(IUnknown)
    ['{6aae1ec1-662a-11d0-889d-00aa00bbb76a}']
    (*** IDirect3D2 methods ***)
    function EnumDevices(lpEnumDevicesCallback: TD3DEnumDevicesCallback;
        lpUserArg: Pointer): HResult; stdcall;
    function CreateLight(var lplpDirect3Dlight: IDirect3DLight;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateMaterial(var lplpDirect3DMaterial2: IDirect3DMaterial2;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateViewport(var lplpD3DViewport2: IDirect3DViewport2;
        pUnkOuter: IUnknown): HResult; stdcall;
    function FindDevice(var lpD3DFDS: TD3DFindDeviceSearch;
        var lpD3DFDR: TD3DFindDeviceResult): HResult; stdcall;
    function CreateDevice(const rclsid: TRefClsID; lpDDS: IDirectDrawSurface;
        out lplpD3DDevice2: IDirect3DDevice2): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3D3);'}
  {$EXTERNALSYM IDirect3D3}
  IDirect3D3 = interface(IUnknown)
    ['{bb223240-e72b-11d0-a9b4-00aa00c0993e}']
    (*** IDirect3D3 methods ***)
    function EnumDevices(lpEnumDevicesCallback: TD3DEnumDevicesCallback;
        lpUserArg: pointer): HResult; stdcall;
    function CreateLight(var lplpDirect3Dlight: IDirect3DLight;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateMaterial(var lplpDirect3DMaterial3: IDirect3DMaterial3;
        pUnkOuter: IUnknown): HResult; stdcall;
    function CreateViewport(var lplpD3DViewport3: IDirect3DViewport3;
        pUnkOuter: IUnknown): HResult; stdcall;
    function FindDevice(var lpD3DFDS: TD3DFindDeviceSearch;
        var lpD3DFDR: TD3DFindDeviceResult): HResult; stdcall;
    function CreateDevice(const rclsid: TRefClsID; lpDDS: IDirectDrawSurface4;
        out lplpD3DDevice: IDirect3DDevice3; pUnkOuter: IUnknown): HResult; stdcall;
    function CreateVertexBuffer(var lpVBDesc: TD3DVertexBufferDesc;
        var lpD3DVertexBuffer: IDirect3DVertexBuffer;
        dwFlags: DWORD; pUnkOuter: IUnknown): HResult; stdcall;
    function EnumZBufferFormats(const riidDevice: TRefClsID; lpEnumCallback:
        TD3DEnumPixelFormatsCallback; lpContext: Pointer): HResult; stdcall;
    function EvictManagedTextures : HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3D7);'}
  {$EXTERNALSYM IDirect3D7}
  IDirect3D7 = interface(IUnknown)
    ['{f5049e77-4861-11d2-a407-00a0c90629a8}']
    (*** IDirect3D7 methods ***)
    function EnumDevices(lpEnumDevicesCallback: TD3DEnumDevicesCallback7;
        lpUserArg: pointer): HResult; stdcall;
    function CreateDevice(const rclsid: TGUID; lpDDS: IDirectDrawSurface7;
        out lplpD3DDevice: IDirect3DDevice7): HResult; stdcall;
    function CreateVertexBuffer(const lpVBDesc: TD3DVertexBufferDesc;
        out lplpD3DVertexBuffer: IDirect3DVertexBuffer7;
        dwFlags: DWORD): HResult; stdcall;
    function EnumZBufferFormats(const riidDevice: TGUID; lpEnumCallback:
        TD3DEnumPixelFormatsCallback; lpContext: pointer): HResult; stdcall;
    function EvictManagedTextures : HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_7

(*
 * Direct3D Device interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DDevice);'}
  {$EXTERNALSYM IDirect3DDevice}
  IDirect3DDevice = interface(IUnknown)
    ['{64108800-957d-11d0-89ab-00a0c9054129}']
    (*** IDirect3DDevice methods ***)
    function Initialize(lpd3d: IDirect3D; lpGUID: PGUID;
        var lpd3ddvdesc: TD3DDeviceDesc): HResult; stdcall;
    function GetCaps(var lpD3DHWDevDesc: TD3DDeviceDesc;
        var lpD3DHELDevDesc: TD3DDeviceDesc): HResult; stdcall;
    function SwapTextureHandles(lpD3DTex1: IDirect3DTexture;
        lpD3DTex2: IDirect3DTexture): HResult; stdcall;
    function CreateExecuteBuffer(var lpDesc: TD3DExecuteBufferDesc ;
        var lplpDirect3DExecuteBuffer: IDirect3DExecuteBuffer;
        pUnkOuter: IUnknown): HResult; stdcall;
    function GetStats(var lpD3DStats: TD3DStats): HResult; stdcall;
    function Execute(lpDirect3DExecuteBuffer: IDirect3DExecuteBuffer;
        lpDirect3DViewport: IDirect3DViewport; dwFlags: DWORD): HResult; stdcall;
    function AddViewport(lpDirect3DViewport: IDirect3DViewport): HResult; stdcall;
    function DeleteViewport(lpDirect3DViewport: IDirect3DViewport): HResult; stdcall;
    function NextViewport(lpDirect3DViewport: IDirect3DViewport;
        var lplpDirect3DViewport: IDirect3DViewport; dwFlags: DWORD): HResult; stdcall;
    function Pick(lpDirect3DExecuteBuffer: IDirect3DExecuteBuffer;
        lpDirect3DViewport: IDirect3DViewport; dwFlags: DWORD;
        var lpRect: TD3DRect): HResult; stdcall;
    function GetPickRecords(var lpCount: DWORD;
        var lpD3DPickRec: TD3DPickRecord): HResult; stdcall;
    function EnumTextureFormats(lpd3dEnumTextureProc:
        TD3DEnumTextureFormatsCallback; lpArg: Pointer):
        HResult; stdcall;
    function CreateMatrix(var lpD3DMatHandle: TD3DMatrixHandle): HResult; stdcall;
    function SetMatrix(d3dMatHandle: TD3DMatrixHandle;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function GetMatrix(var lpD3DMatHandle: TD3DMatrixHandle;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function DeleteMatrix(d3dMatHandle: TD3DMatrixHandle): HResult; stdcall;
    function BeginScene: HResult; stdcall;
    function EndScene: HResult; stdcall;
    function GetDirect3D(var lpD3D: IDirect3D): HResult; stdcall;
  end;

{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DDevice2);'}
  {$EXTERNALSYM IDirect3DDevice2}
  IDirect3DDevice2 = interface(IUnknown)
    ['{93281501-8cf8-11d0-89ab-00a0c9054129}']
    (*** IDirect3DDevice2 methods ***)
    function GetCaps(var lpD3DHWDevDesc: TD3DDeviceDesc;
        var lpD3DHELDevDesc: TD3DDeviceDesc): HResult; stdcall;
    function SwapTextureHandles(lpD3DTex1: IDirect3DTexture2;
        lpD3DTex2: IDirect3DTexture2): HResult; stdcall;
    function GetStats(var lpD3DStats: TD3DStats): HResult; stdcall;
    function AddViewport(lpDirect3DViewport2: IDirect3DViewport2): HResult; stdcall;
    function DeleteViewport(lpDirect3DViewport: IDirect3DViewport2): HResult; stdcall;
    function NextViewport(lpDirect3DViewport: IDirect3DViewport2;
        var lplpDirect3DViewport: IDirect3DViewport2; dwFlags: DWORD):
        HResult; stdcall;
    function EnumTextureFormats(
        lpd3dEnumTextureProc: TD3DEnumTextureFormatsCallback; lpArg: Pointer):
        HResult; stdcall;
    function BeginScene: HResult; stdcall;
    function EndScene: HResult; stdcall;
    function GetDirect3D(var lpD3D: IDirect3D2): HResult; stdcall;

    (*** DrawPrimitive API ***)
    function SetCurrentViewport(lpd3dViewport2: IDirect3DViewport2)
        : HResult; stdcall;
    function GetCurrentViewport(var lplpd3dViewport2: IDirect3DViewport2)
        : HResult; stdcall;

    function SetRenderTarget(lpNewRenderTarget: IDirectDrawSurface)
        : HResult; stdcall;
    function GetRenderTarget(var lplpNewRenderTarget: IDirectDrawSurface)
        : HResult; stdcall;

    function Begin_(d3dpt: TD3DPrimitiveType; d3dvt: TD3DVertexType;
        dwFlags: DWORD): HResult; stdcall;
    function BeginIndexed(dptPrimitiveType: TD3DPrimitiveType; dvtVertexType:
        TD3DVertexType; lpvVertices: pointer; dwNumVertices: DWORD;
        dwFlags: DWORD): HResult; stdcall;
    function Vertex(lpVertexType: pointer): HResult;  stdcall;
    function Index(wVertexIndex: WORD): HResult;  stdcall;
    function End_(dwFlags: DWORD): HResult; stdcall;

    function GetRenderState(dwRenderStateType: TD3DRenderStateType;
        var lpdwRenderState): HResult; stdcall;
    function SetRenderState(dwRenderStateType: TD3DRenderStateType;
        dwRenderState: DWORD): HResult; stdcall;
    function GetLightState(dwLightStateType: TD3DLightStateType;
        var lpdwLightState): HResult; stdcall;
    function SetLightState(dwLightStateType: TD3DLightStateType;
        dwLightState: DWORD): HResult; stdcall;
    function SetTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function GetTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function MultiplyTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;

    function DrawPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dvtVertexType: TD3DVertexType; var lpvVertices; dwVertexCount,
        dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; lpvVertices: pointer; dwVertexCount: DWORD;
        var lpwIndices: WORD; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function SetClipStatus(var lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
    function GetClipStatus(var lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DDevice3);'}
  {$EXTERNALSYM IDirect3DDevice3}
  IDirect3DDevice3 = interface(IUnknown)
    ['{b0ab3b60-33d7-11d1-a981-00c04fd7b174}']
    (*** IDirect3DDevice2 methods ***)
    function GetCaps(var lpD3DHWDevDesc: TD3DDeviceDesc;
        var lpD3DHELDevDesc: TD3DDeviceDesc): HResult; stdcall;
    function GetStats(var lpD3DStats: TD3DStats): HResult; stdcall;
    function AddViewport(lpDirect3DViewport: IDirect3DViewport3): HResult; stdcall;
    function DeleteViewport(lpDirect3DViewport: IDirect3DViewport3): HResult; stdcall;
    function NextViewport(lpDirect3DViewport: IDirect3DViewport3;
        var lplpAnotherViewport: IDirect3DViewport3; dwFlags: DWORD): HResult; stdcall;
    function EnumTextureFormats(
        lpd3dEnumPixelProc: TD3DEnumPixelFormatsCallback; lpArg: Pointer):
        HResult; stdcall;
    function BeginScene: HResult; stdcall;
    function EndScene: HResult; stdcall;
    function GetDirect3D(var lpD3D: IDirect3D3): HResult; stdcall;
    function SetCurrentViewport(lpd3dViewport: IDirect3DViewport3)
        : HResult; stdcall;
    function GetCurrentViewport(var lplpd3dViewport: IDirect3DViewport3)
        : HResult; stdcall;
    function SetRenderTarget(lpNewRenderTarget: IDirectDrawSurface4)
        : HResult; stdcall;
    function GetRenderTarget(var lplpNewRenderTarget: IDirectDrawSurface4)
        : HResult; stdcall;
    function Begin_(d3dpt: TD3DPrimitiveType; dwVertexTypeDesc: DWORD;
        dwFlags: DWORD): HResult; stdcall;
    function BeginIndexed(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; lpvVertices: pointer; dwNumVertices: DWORD;
        dwFlags: DWORD): HResult; stdcall;
    function Vertex(lpVertex: pointer): HResult;  stdcall;
    function Index(wVertexIndex: WORD): HResult;  stdcall;
    function End_(dwFlags: DWORD): HResult; stdcall;
    function GetRenderState(dwRenderStateType: TD3DRenderStateType;
        var lpdwRenderState): HResult; stdcall;
    function SetRenderState(dwRenderStateType: TD3DRenderStateType;
        dwRenderState: DWORD): HResult; stdcall;
    function GetLightState(dwLightStateType: TD3DLightStateType;
        var lpdwLightState): HResult; stdcall;
    function SetLightState(dwLightStateType: TD3DLightStateType;
        dwLightState: DWORD): HResult; stdcall;
    function SetTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function GetTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function MultiplyTransform(dtstTransformStateType: TD3DTransformStateType;
        var lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function DrawPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; const lpvVertices;
        dwVertexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; const lpvVertices; dwVertexCount: DWORD;
        var lpwIndices: WORD; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function SetClipStatus(var lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
    function GetClipStatus(var lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
    function DrawPrimitiveStrided(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc : DWORD;
        var lpVertexArray: TD3DDrawPrimitiveStridedData;
        dwVertexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitiveStrided(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc : DWORD;
        var lpVertexArray: TD3DDrawPrimitiveStridedData; dwVertexCount: DWORD;
        var lpwIndices: WORD; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawPrimitiveVB(dptPrimitiveType: TD3DPrimitiveType;
        lpd3dVertexBuffer: IDirect3DVertexBuffer;
        dwStartVertex, dwNumVertices, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitiveVB(dptPrimitiveType: TD3DPrimitiveType;
        lpd3dVertexBuffer: IDirect3DVertexBuffer; var lpwIndices: WORD;
        dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function ComputeSphereVisibility(var lpCenters: TD3DVector;
        var lpRadii: TD3DValue; dwNumSpheres, dwFlags: DWORD;
        var lpdwReturnValues: DWORD): HResult; stdcall;
    function GetTexture(dwStage: DWORD; var lplpTexture: IDirect3DTexture2)
        : HResult; stdcall;
    function SetTexture(dwStage: DWORD; lplpTexture: IDirect3DTexture2)
        : HResult; stdcall;
    function GetTextureStageState(dwStage: DWORD;
        dwState: TD3DTextureStageStateType; var lpdwValue: DWORD): HResult; stdcall;
    function SetTextureStageState(dwStage: DWORD;
        dwState: TD3DTextureStageStateType; lpdwValue: DWORD): HResult; stdcall;
    function ValidateDevice(var lpdwExtraPasses: DWORD): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DDevice7);'}
  {$EXTERNALSYM IDirect3DDevice7}
  IDirect3DDevice7 = interface(IUnknown)
    ['{f5049e79-4861-11d2-a407-00a0c90629a8}']
    (*** IDirect3DDevice7 methods ***)
    function GetCaps(out lpD3DDevDesc: TD3DDeviceDesc7): HResult; stdcall;
    function EnumTextureFormats(lpd3dEnumPixelProc: TD3DEnumPixelFormatsCallback; lpArg: Pointer): HResult; stdcall;
    function BeginScene: HResult; stdcall;
    function EndScene: HResult; stdcall;
    function GetDirect3D(out lpD3D: IDirect3D7): HResult; stdcall;
    function SetRenderTarget(lpNewRenderTarget: IDirectDrawSurface7; dwFlags: DWORD): HResult; stdcall;
    function GetRenderTarget(out lplpRenderTarget: IDirectDrawSurface7): HResult; stdcall;
    function Clear(dwCount: DWORD; lpRects: PD3DRect; dwFlags, dwColor: DWORD; dvZ: TD3DValue; dwStencil: DWORD): HResult; stdcall;
    function SetTransform(dtstTransformStateType: TD3DTransformStateType;
        const lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function GetTransform(dtstTransformStateType: TD3DTransformStateType;
        out lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function SetViewport(const lpViewport: TD3DViewport7): HResult; stdcall;
    function MultiplyTransform(dtstTransformStateType: TD3DTransformStateType;
        const lpD3DMatrix: TD3DMatrix): HResult; stdcall;
    function GetViewport(out lpViewport: TD3DViewport7): HResult; stdcall;
    function SetMaterial(const lpMaterial: TD3DMaterial7): HResult; stdcall;
    function GetMaterial(out lpMaterial: TD3DMaterial7): HResult; stdcall;
    function SetLight(dwLightIndex: DWORD; const lpLight: TD3DLight7): HResult; stdcall;
    function GetLight(dwLightIndex: DWORD; out lpLight: TD3DLight7): HResult; stdcall;
    function SetRenderState(dwRenderStateType: TD3DRenderStateType; dwRenderState: DWORD): HResult; stdcall;
    function GetRenderState(dwRenderStateType: TD3DRenderStateType; out dwRenderState: DWORD): HResult; stdcall;
    function BeginStateBlock : HResult; stdcall;
    function EndStateBlock(out lpdwBlockHandle: DWORD): HResult; stdcall;
    function PreLoad(lpddsTexture: IDirectDrawSurface7): HResult; stdcall;
    function DrawPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; const lpvVertices;
        dwVertexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitive(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc: DWORD; const lpvVertices; dwVertexCount: DWORD;
        const lpwIndices; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function SetClipStatus(const lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
    function GetClipStatus(out lpD3DClipStatus: TD3DClipStatus): HResult; stdcall;
    function DrawPrimitiveStrided(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc : DWORD;
        const lpVertexArray: TD3DDrawPrimitiveStridedData;
        dwVertexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitiveStrided(dptPrimitiveType: TD3DPrimitiveType;
        dwVertexTypeDesc : DWORD;
        const lpVertexArray: TD3DDrawPrimitiveStridedData; dwVertexCount: DWORD;
        var lpwIndices: WORD; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function DrawPrimitiveVB(dptPrimitiveType: TD3DPrimitiveType;
        lpd3dVertexBuffer: IDirect3DVertexBuffer7;
        dwStartVertex, dwNumVertices, dwFlags: DWORD): HResult; stdcall;
    function DrawIndexedPrimitiveVB(dptPrimitiveType: TD3DPrimitiveType;
        lpd3dVertexBuffer: IDirect3DVertexBuffer7; dwStartVertex, dwNumVertices: DWORD;
        var lpwIndices: WORD; dwIndexCount, dwFlags: DWORD): HResult; stdcall;
    function ComputeSphereVisibility(const lpCenters: TD3DVector;
        var lpRadii: TD3DValue; dwNumSpheres, dwFlags: DWORD;
        var lpdwReturnValues: DWORD): HResult; stdcall;
    function GetTexture(dwStage: DWORD; out lplpTexture: IDirectDrawSurface7): HResult; stdcall;
    function SetTexture(dwStage: DWORD; lpTexture: IDirectDrawSurface7): HResult; stdcall;
    function GetTextureStageState(dwStage: DWORD;
        dwState: TD3DTextureStageStateType; out lpdwValue: DWORD): HResult; stdcall;
    function SetTextureStageState(dwStage: DWORD;
        dwState: TD3DTextureStageStateType; lpdwValue: DWORD): HResult; stdcall;
    function ValidateDevice(out lpdwExtraPasses: DWORD): HResult; stdcall;
    function ApplyStateBlock(dwBlockHandle: DWORD): HResult; stdcall;
    function CaptureStateBlock(dwBlockHandle: DWORD): HResult; stdcall;
    function DeleteStateBlock(dwBlockHandle: DWORD): HResult; stdcall;
    function CreateStateBlock(d3dsbType: TD3DStateBlockType; out lpdwBlockHandle: DWORD): HResult; stdcall;
    function Load(lpDestTex: IDirectDrawSurface7; lpDestPoint: PPoint;
        lpSrcTex: IDirectDrawSurface7; lprcSrcRect: PRect; dwFlags: DWORD): HResult; stdcall;
    function LightEnable(dwLightIndex: DWORD; bEnable: BOOL): HResult; stdcall;
    function GetLightEnable(dwLightIndex: DWORD; out bEnable: BOOL): HResult; stdcall;
    function SetClipPlane(dwIndex: DWORD; pPlaneEquation: PD3DValue): HResult; stdcall;
    function GetClipPlane(dwIndex: DWORD; pPlaneEquation: PD3DValue): HResult; stdcall;
    function GetInfo(dwDevInfoID: DWORD; pDevInfoStruct: Pointer; dwSize: DWORD): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_7

(*
 * Execute Buffer interface
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DExecuteBuffer);'}
  {$EXTERNALSYM IDirect3DExecuteBuffer}
  IDirect3DExecuteBuffer = interface(IUnknown)
    ['{4417C145-33AD-11CF-816F-0000C020156E}']
    (*** IDirect3DExecuteBuffer methods ***)
    function Initialize(lpDirect3DDevice: IDirect3DDevice;
        var lpDesc: TD3DExecuteBufferDesc): HResult; stdcall;
    function Lock(var lpDesc: TD3DExecuteBufferDesc): HResult; stdcall;
    function Unlock: HResult; stdcall;
    function SetExecuteData(var lpData: TD3DExecuteData): HResult; stdcall;
    function GetExecuteData(var lpData: TD3DExecuteData): HResult; stdcall;
    function Validate(var lpdwOffset: DWORD; lpFunc: TD3DValidateCallback;
        lpUserArg: Pointer; dwReserved: DWORD): HResult; stdcall;
    (*** Warning!  Optimize is defined differently in the header files
         and the online documentation ***)
    function Optimize(dwFlags: DWORD): HResult; stdcall;
  end;

(*
 * Light interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DLight);'}
  {$EXTERNALSYM IDirect3DLight}
  IDirect3DLight = interface(IUnknown)
    ['{4417C142-33AD-11CF-816F-0000C020156E}']
    (*** IDirect3DLight methods ***)
    function Initialize(lpDirect3D: IDirect3D): HResult; stdcall;
    function SetLight(var lpLight: TD3DLight2): HResult; stdcall;
    function GetLight(var lpLight: TD3DLight2): HResult; stdcall;
  end;

(*
 * Material interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DMaterial);'}
  {$EXTERNALSYM IDirect3DMaterial}
  IDirect3DMaterial = interface(IUnknown)
    ['{4417C144-33AD-11CF-816F-0000C020156E}']
    (*** IDirect3DMaterial methods ***)
    function Initialize(lpDirect3D: IDirect3D): HResult; stdcall;
    function SetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetHandle(lpDirect3DDevice: IDirect3DDevice;
        var lpHandle: TD3DMaterialHandle): HResult; stdcall;
    function Reserve: HResult; stdcall;
    function Unreserve: HResult; stdcall;
  end;

{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DMaterial2);'}
  {$EXTERNALSYM IDirect3DMaterial2}
  IDirect3DMaterial2 = interface(IUnknown)
    ['{93281503-8cf8-11d0-89ab-00a0c9054129}']
    (*** IDirect3DMaterial2 methods ***)
    function SetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetHandle(lpDirect3DDevice: IDirect3DDevice2;
        var lpHandle: TD3DMaterialHandle): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DMaterial3);'}
  {$EXTERNALSYM IDirect3DMaterial3}
  IDirect3DMaterial3 = interface(IUnknown)
    ['{ca9c46f4-d3c5-11d1-b75a-00600852b312}']
    (*** IDirect3DMaterial2 methods ***)
    function SetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetMaterial(var lpMat: TD3DMaterial): HResult; stdcall;
    function GetHandle(lpDirect3DDevice: IDirect3DDevice3;
        var lpHandle: TD3DMaterialHandle): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_6

(*
 * Texture interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DTexture);'}
  {$EXTERNALSYM IDirect3DTexture}
  IDirect3DTexture = interface(IUnknown)
    ['{2CDCD9E0-25A0-11CF-A31A-00AA00B93356}']
    (*** IDirect3DTexture methods ***)
    function Initialize(lpD3DDevice: IDirect3DDevice;
        lpDDSurface: IDirectDrawSurface): HResult; stdcall;
    function GetHandle(lpDirect3DDevice: IDirect3DDevice;
        var lpHandle: TD3DTextureHandle): HResult; stdcall;
    function PaletteChanged(dwStart: DWORD; dwCount: DWORD): HResult; stdcall;
    function Load(lpD3DTexture: IDirect3DTexture): HResult; stdcall;
    function Unload: HResult; stdcall;
  end;

{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DTexture2);'}
  {$EXTERNALSYM IDirect3DTexture2}
  IDirect3DTexture2 = interface(IUnknown)
    ['{93281502-8cf8-11d0-89ab-00a0c9054129}']
    (*** IDirect3DTexture2 methods ***)
    function GetHandle(lpDirect3DDevice: IDirect3DDevice2;
        var lpHandle: TD3DTextureHandle): HResult; stdcall;
    function PaletteChanged(dwStart: DWORD; dwCount: DWORD): HResult; stdcall;
    function Load(lpD3DTexture: IDirect3DTexture2): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_5

(*
 * Viewport interfaces
 *)

  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DViewport);'}
  {$EXTERNALSYM IDirect3DViewport}
  IDirect3DViewport = interface(IUnknown)
    ['{4417C146-33AD-11CF-816F-0000C020156E}']
    (*** IDirect3DViewport methods ***)
    function Initialize(lpDirect3D: IDirect3D): HResult; stdcall;
    function GetViewport(out lpData: TD3DViewport): HResult; stdcall;
    function SetViewport(const lpData: TD3DViewport): HResult; stdcall;
    function TransformVertices(dwVertexCount: DWORD;
        const lpData: TD3DTransformData; dwFlags: DWORD;
        out lpOffscreen: DWORD): HResult; stdcall;
    function LightElements(dwElementCount: DWORD;
        var lpData: TD3DLightData): HResult; stdcall;
    function SetBackground(hMat: TD3DMaterialHandle): HResult; stdcall;
    function GetBackground(out hMat: TD3DMaterialHandle): HResult; stdcall;
    function SetBackgroundDepth(lpDDSurface: IDirectDrawSurface):
        HResult; stdcall;
    function GetBackgroundDepth(out lplpDDSurface: IDirectDrawSurface;
        out lpValid: BOOL): HResult; stdcall;
    function Clear(dwCount: DWORD; const lpRects: TD3DRect; dwFlags: DWORD):
        HResult; stdcall;
    function AddLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
    function DeleteLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
     function NextLight(lpDirect3DLight: IDirect3DLight;
        out lplpDirect3DLight: IDirect3DLight; dwFlags: DWORD): HResult; stdcall;
  end;

{$IFDEF DIRECT3D_VERSION_5}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DViewport2);'}
  {$EXTERNALSYM IDirect3DViewport2}
  IDirect3DViewport2 = interface(IUnknown)
    ['{93281500-8cf8-11d0-89ab-00a0c9054129}']
    (*** IDirect3DViewport2 methods ***)
    function Initialize(lpDirect3D: IDirect3D): HResult; stdcall;
    function GetViewport(out lpData: TD3DViewport): HResult; stdcall;
    function SetViewport(const lpData: TD3DViewport): HResult; stdcall;
    function TransformVertices(dwVertexCount: DWORD;
        const lpData: TD3DTransformData; dwFlags: DWORD;
        out lpOffscreen: DWORD): HResult; stdcall;
    function LightElements(dwElementCount: DWORD;
        var lpData: TD3DLightData): HResult; stdcall;
    function SetBackground(hMat: TD3DMaterialHandle): HResult; stdcall;
    function GetBackground(out hMat: TD3DMaterialHandle): HResult; stdcall;
    function SetBackgroundDepth(lpDDSurface: IDirectDrawSurface):
        HResult; stdcall;
    function GetBackgroundDepth(out lplpDDSurface: IDirectDrawSurface;
        out lpValid: BOOL): HResult; stdcall;
    function Clear(dwCount: DWORD; const lpRects: TD3DRect; dwFlags: DWORD):
        HResult; stdcall;
    function AddLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
    function DeleteLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
    function NextLight(lpDirect3DLight: IDirect3DLight;
        out lplpDirect3DLight: IDirect3DLight; dwFlags: DWORD): HResult; stdcall;
    (*** IDirect3DViewport2 methods ***)
    function GetViewport2(out lpData: TD3DViewport2): HResult; stdcall;
    function SetViewport2(const lpData: TD3DViewport2): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DViewport3);'}
  {$EXTERNALSYM IDirect3DViewport3}
  IDirect3DViewport3 = interface(IUnknown)
    ['{b0ab3b61-33d7-11d1-a981-00c04fd7b174}']
    (*** IDirect3DViewport3 methods ***)
    function Initialize(lpDirect3D: IDirect3D): HResult; stdcall;
    function GetViewport(out lpData: TD3DViewport): HResult; stdcall;
    function SetViewport(const lpData: TD3DViewport): HResult; stdcall;
    function TransformVertices(dwVertexCount: DWORD;
        const lpData: TD3DTransformData; dwFlags: DWORD;
        out lpOffscreen: DWORD): HResult; stdcall;
    function LightElements(dwElementCount: DWORD;
        var lpData: TD3DLightData): HResult; stdcall;
    function SetBackground(hMat: TD3DMaterialHandle): HResult; stdcall;
    function GetBackground(var hMat: TD3DMaterialHandle): HResult; stdcall;
    function SetBackgroundDepth(
        lpDDSurface: IDirectDrawSurface): HResult; stdcall;
    function GetBackgroundDepth(out lplpDDSurface: IDirectDrawSurface;
        out lpValid: BOOL): HResult; stdcall;
    function Clear(dwCount: DWORD; const lpRects: TD3DRect; dwFlags: DWORD):
        HResult; stdcall;
    function AddLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
    function DeleteLight(lpDirect3DLight: IDirect3DLight): HResult; stdcall;
    function NextLight(lpDirect3DLight: IDirect3DLight;
        out lplpDirect3DLight: IDirect3DLight; dwFlags: DWORD): HResult; stdcall;
    function GetViewport2(out lpData: TD3DViewport2): HResult; stdcall;
    function SetViewport2(const lpData: TD3DViewport2): HResult; stdcall;
    function SetBackgroundDepth2(
        lpDDSurface: IDirectDrawSurface4): HResult; stdcall;
    function GetBackgroundDepth2(out lplpDDSurface: IDirectDrawSurface4;
        out lpValid: BOOL): HResult; stdcall;
    function Clear2(dwCount: DWORD; const lpRects: TD3DRect; dwFlags: DWORD;
        dwColor: DWORD; dvZ: TD3DValue; dwStencil: DWORD): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_6}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DVertexBuffer);'}
  {$EXTERNALSYM IDirect3DVertexBuffer}
  IDirect3DVertexBuffer = interface(IUnknown)
    ['{7a503555-4a83-11d1-a5db-00a0c90367f8}']
    (*** IDirect3DVertexBuffer methods ***)
    function Lock(dwFlags: DWORD; var lplpData: pointer; var lpdwSize: DWORD)
        : HResult; stdcall;
    function Unlock : HResult; stdcall;
    function ProcessVertices(dwVertexOp, dwDestIndex, dwCount: DWORD;
        lpSrcBuffer: IDirect3DVertexBuffer; dwSrcIndex: DWORD;
        lpD3DDevice: IDirect3DDevice3; dwFlags: DWORD): HResult; stdcall;
    function GetVertexBufferDesc(var lpVBDesc: TD3DVertexBufferDesc): HResult; stdcall;
    function Optimize(lpD3DDevice: IDirect3DDevice3; dwFlags: DWORD): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}
  {$HPPEMIT 'DECLARE_DINTERFACE_TYPE(IDirect3DVertexBuffer7);'}
  {$EXTERNALSYM IDirect3DVertexBuffer7}
  IDirect3DVertexBuffer7 = interface(IUnknown)
    ['{f5049e7d-4861-11d2-a407-00a0c90629a8}']
    (*** IDirect3DVertexBuffer methods ***)
    function Lock(dwFlags: DWORD; out lplpData: Pointer; out lpdwSize: DWORD): HResult; stdcall;
    function Unlock : HResult; stdcall;
    function ProcessVertices(dwVertexOp, dwDestIndex, dwCount: DWORD;
        lpSrcBuffer: IDirect3DVertexBuffer7; dwSrcIndex: DWORD;
        lpD3DDevice: IDirect3DDevice7; dwFlags: DWORD): HResult; stdcall;
    function GetVertexBufferDesc(out lpVBDesc: TD3DVertexBufferDesc): HResult; stdcall;
    function Optimize(lpD3DDevice: IDirect3DDevice7; dwFlags: DWORD): HResult; stdcall;
    function ProcessVerticesStrided(dwVertexOp, dwDestIndex, dwCount: DWORD;
      lpVertexArray: TD3DDrawPrimitiveStridedData; dwVertexTypeDesc: DWORD;
      lpD3DDevice: IDirect3DDevice7; dwFlags: DWORD): HResult; stdcall;
  end;
{$ENDIF} // DIRECT3D_VERSION_7

{$IFDEF DIRECT3D_VERSION_5}
const
(****************************************************************************
 *
 * Flags for IDirect3DDevice::NextViewport
 *
 ****************************************************************************)

(*
 * Return the next viewport
 *)
  D3DNEXT_NEXT =	$00000001;
  {$EXTERNALSYM D3DNEXT_NEXT}

(*
 * Return the first viewport
 *)
  D3DNEXT_HEAD =	$00000002;
  {$EXTERNALSYM D3DNEXT_HEAD}

(*
 * Return the last viewport
 *)
  D3DNEXT_TAIL =	$00000004;
  {$EXTERNALSYM D3DNEXT_TAIL}


(****************************************************************************
 *
 * Flags for DrawPrimitive/DrawIndexedPrimitive
 *   Also valid for Begin/BeginIndexed
 *   Also valid for VertexBuffer::CreateVertexBuffer
 ****************************************************************************)

(*
 * Wait until the device is ready to draw the primitive
 * This will cause DP to not return DDERR_WASSTILLDRAWING
 *)
  D3DDP_WAIT =					$00000001;
  {$EXTERNALSYM D3DDP_WAIT}

{$IFDEF DIRECT3D_VERSION_LESS_6}
(*
 * Hint that it is acceptable to render the primitive out of order.
 *)
  D3DDP_OUTOFORDER            = $00000002;
  {$EXTERNALSYM D3DDP_OUTOFORDER}
{$ENDIF} // DIRECT3D_VERSION_LESS_6

(*
 * Hint that the primitives have been clipped by the application.
 *)
  D3DDP_DONOTCLIP =				$00000004;
  {$EXTERNALSYM D3DDP_DONOTCLIP}

(*
 * Hint that the extents need not be updated.
 *)
  D3DDP_DONOTUPDATEEXTENTS =	$00000008;
  {$EXTERNALSYM D3DDP_DONOTUPDATEEXTENTS}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}

(*
 * Hint that the lighting should not be applied on vertices.
 *)

  D3DDP_DONOTLIGHT            = $00000010;
  {$EXTERNALSYM D3DDP_DONOTLIGHT}

{$ENDIF} // DIRECT3D_VERSION_6


(*
 * Direct3D Errors
 * DirectDraw error codes are used when errors not specified here.
 *)

const
  MAKE_DDHRESULT = HResult($88760000);
  {$EXTERNALSYM MAKE_DDHRESULT}

  D3D_OK                          = DD_OK;
  {$EXTERNALSYM D3D_OK}
  D3DERR_BADMAJORVERSION          = MAKE_DDHRESULT + 700;
  {$EXTERNALSYM D3DERR_BADMAJORVERSION}
  D3DERR_BADMINORVERSION          = MAKE_DDHRESULT + 701;
  {$EXTERNALSYM D3DERR_BADMINORVERSION}

{$IFDEF DIRECT3D_VERSION_5}
(*
 * An invalid device was requested by the application.
 *)
  D3DERR_INVALID_DEVICE   = MAKE_DDHRESULT + 705;
  {$EXTERNALSYM D3DERR_INVALID_DEVICE}
  D3DERR_INITFAILED       = MAKE_DDHRESULT + 706;
  {$EXTERNALSYM D3DERR_INITFAILED}

(*
 * SetRenderTarget attempted on a device that was
 * QI'd off the render target.
 *)
  D3DERR_DEVICEAGGREGATED = MAKE_DDHRESULT + 707;
  {$EXTERNALSYM D3DERR_DEVICEAGGREGATED}
{$ENDIF} // DIRECT3D_VERSION_5

  D3DERR_EXECUTE_CREATE_FAILED    = MAKE_DDHRESULT + 710;
  {$EXTERNALSYM D3DERR_EXECUTE_CREATE_FAILED}
  D3DERR_EXECUTE_DESTROY_FAILED   = MAKE_DDHRESULT + 711;
  {$EXTERNALSYM D3DERR_EXECUTE_DESTROY_FAILED}
  D3DERR_EXECUTE_LOCK_FAILED      = MAKE_DDHRESULT + 712;
  {$EXTERNALSYM D3DERR_EXECUTE_LOCK_FAILED}
  D3DERR_EXECUTE_UNLOCK_FAILED    = MAKE_DDHRESULT + 713;
  {$EXTERNALSYM D3DERR_EXECUTE_UNLOCK_FAILED}
  D3DERR_EXECUTE_LOCKED           = MAKE_DDHRESULT + 714;
  {$EXTERNALSYM D3DERR_EXECUTE_LOCKED}
  D3DERR_EXECUTE_NOT_LOCKED       = MAKE_DDHRESULT + 715;
  {$EXTERNALSYM D3DERR_EXECUTE_NOT_LOCKED}

  D3DERR_EXECUTE_FAILED           = MAKE_DDHRESULT + 716;
  {$EXTERNALSYM D3DERR_EXECUTE_FAILED}
  D3DERR_EXECUTE_CLIPPED_FAILED   = MAKE_DDHRESULT + 717;
  {$EXTERNALSYM D3DERR_EXECUTE_CLIPPED_FAILED}

  D3DERR_TEXTURE_NO_SUPPORT       = MAKE_DDHRESULT + 720;
  {$EXTERNALSYM D3DERR_TEXTURE_NO_SUPPORT}
  D3DERR_TEXTURE_CREATE_FAILED    = MAKE_DDHRESULT + 721;
  {$EXTERNALSYM D3DERR_TEXTURE_CREATE_FAILED}
  D3DERR_TEXTURE_DESTROY_FAILED   = MAKE_DDHRESULT + 722;
  {$EXTERNALSYM D3DERR_TEXTURE_DESTROY_FAILED}
  D3DERR_TEXTURE_LOCK_FAILED      = MAKE_DDHRESULT + 723;
  {$EXTERNALSYM D3DERR_TEXTURE_LOCK_FAILED}
  D3DERR_TEXTURE_UNLOCK_FAILED    = MAKE_DDHRESULT + 724;
  {$EXTERNALSYM D3DERR_TEXTURE_UNLOCK_FAILED}
  D3DERR_TEXTURE_LOAD_FAILED      = MAKE_DDHRESULT + 725;
  {$EXTERNALSYM D3DERR_TEXTURE_LOAD_FAILED}
  D3DERR_TEXTURE_SWAP_FAILED      = MAKE_DDHRESULT + 726;
  {$EXTERNALSYM D3DERR_TEXTURE_SWAP_FAILED}
  D3DERR_TEXTURE_LOCKED           = MAKE_DDHRESULT + 727;
  {$EXTERNALSYM D3DERR_TEXTURE_LOCKED}
  D3DERR_TEXTURE_NOT_LOCKED       = MAKE_DDHRESULT + 728;
  {$EXTERNALSYM D3DERR_TEXTURE_NOT_LOCKED}
  D3DERR_TEXTURE_GETSURF_FAILED   = MAKE_DDHRESULT + 729;
  {$EXTERNALSYM D3DERR_TEXTURE_GETSURF_FAILED}

  D3DERR_MATRIX_CREATE_FAILED     = MAKE_DDHRESULT + 730;
  {$EXTERNALSYM D3DERR_MATRIX_CREATE_FAILED}
  D3DERR_MATRIX_DESTROY_FAILED    = MAKE_DDHRESULT + 731;
  {$EXTERNALSYM D3DERR_MATRIX_DESTROY_FAILED}
  D3DERR_MATRIX_SETDATA_FAILED    = MAKE_DDHRESULT + 732;
  {$EXTERNALSYM D3DERR_MATRIX_SETDATA_FAILED}
  D3DERR_MATRIX_GETDATA_FAILED    = MAKE_DDHRESULT + 733;
  {$EXTERNALSYM D3DERR_MATRIX_GETDATA_FAILED}
  D3DERR_SETVIEWPORTDATA_FAILED   = MAKE_DDHRESULT + 734;
  {$EXTERNALSYM D3DERR_SETVIEWPORTDATA_FAILED}

{$IFDEF DIRECT3D_VERSION_5}
  D3DERR_INVALIDCURRENTVIEWPORT   = MAKE_DDHRESULT + 735;
  {$EXTERNALSYM D3DERR_INVALIDCURRENTVIEWPORT}
  D3DERR_INVALIDPRIMITIVETYPE     = MAKE_DDHRESULT + 736;
  {$EXTERNALSYM D3DERR_INVALIDPRIMITIVETYPE}
  D3DERR_INVALIDVERTEXTYPE        = MAKE_DDHRESULT + 737;
  {$EXTERNALSYM D3DERR_INVALIDVERTEXTYPE}
  D3DERR_TEXTURE_BADSIZE          = MAKE_DDHRESULT + 738;
  {$EXTERNALSYM D3DERR_TEXTURE_BADSIZE}
  D3DERR_INVALIDRAMPTEXTURE	  = MAKE_DDHRESULT + 739;
  {$EXTERNALSYM D3DERR_INVALIDRAMPTEXTURE}
{$ENDIF} // DIRECT3D_VERSION_5

  D3DERR_MATERIAL_CREATE_FAILED   = MAKE_DDHRESULT + 740;
  {$EXTERNALSYM D3DERR_MATERIAL_CREATE_FAILED}
  D3DERR_MATERIAL_DESTROY_FAILED  = MAKE_DDHRESULT + 741;
  {$EXTERNALSYM D3DERR_MATERIAL_DESTROY_FAILED}
  D3DERR_MATERIAL_SETDATA_FAILED  = MAKE_DDHRESULT + 742;
  {$EXTERNALSYM D3DERR_MATERIAL_SETDATA_FAILED}
  D3DERR_MATERIAL_GETDATA_FAILED  = MAKE_DDHRESULT + 743;
  {$EXTERNALSYM D3DERR_MATERIAL_GETDATA_FAILED}

{$IFDEF DIRECT3D_VERSION_5}
  D3DERR_INVALIDPALETTE	          = MAKE_DDHRESULT + 744;
  {$EXTERNALSYM D3DERR_INVALIDPALETTE}

  D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY = MAKE_DDHRESULT + 745;
  {$EXTERNALSYM D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY}
  D3DERR_ZBUFF_NEEDS_VIDEOMEMORY  = MAKE_DDHRESULT + 746;
  {$EXTERNALSYM D3DERR_ZBUFF_NEEDS_VIDEOMEMORY}
  D3DERR_SURFACENOTINVIDMEM       = MAKE_DDHRESULT + 747;
  {$EXTERNALSYM D3DERR_SURFACENOTINVIDMEM}
{$ENDIF} // DIRECT3D_VERSION_5

  D3DERR_LIGHT_SET_FAILED         = MAKE_DDHRESULT + 750;
  {$EXTERNALSYM D3DERR_LIGHT_SET_FAILED}
{$IFDEF DIRECT3D_VERSION_5}
  D3DERR_LIGHTHASVIEWPORT	  = MAKE_DDHRESULT + 751;
  {$EXTERNALSYM D3DERR_LIGHTHASVIEWPORT}
  D3DERR_LIGHTNOTINTHISVIEWPORT   = MAKE_DDHRESULT + 752;
  {$EXTERNALSYM D3DERR_LIGHTNOTINTHISVIEWPORT}
{$ENDIF} // DIRECT3D_VERSION_5

  D3DERR_SCENE_IN_SCENE           = MAKE_DDHRESULT + 760;
  {$EXTERNALSYM D3DERR_SCENE_IN_SCENE}
  D3DERR_SCENE_NOT_IN_SCENE       = MAKE_DDHRESULT + 761;
  {$EXTERNALSYM D3DERR_SCENE_NOT_IN_SCENE}
  D3DERR_SCENE_BEGIN_FAILED       = MAKE_DDHRESULT + 762;
  {$EXTERNALSYM D3DERR_SCENE_BEGIN_FAILED}
  D3DERR_SCENE_END_FAILED         = MAKE_DDHRESULT + 763;
  {$EXTERNALSYM D3DERR_SCENE_END_FAILED}

{$IFDEF DIRECT3D_VERSION_5}
  D3DERR_INBEGIN                  = MAKE_DDHRESULT + 770;
  {$EXTERNALSYM D3DERR_INBEGIN}
  D3DERR_NOTINBEGIN               = MAKE_DDHRESULT + 771;
  {$EXTERNALSYM D3DERR_NOTINBEGIN}
  D3DERR_NOVIEWPORTS              = MAKE_DDHRESULT + 772;
  {$EXTERNALSYM D3DERR_NOVIEWPORTS}
  D3DERR_VIEWPORTDATANOTSET       = MAKE_DDHRESULT + 773;
  {$EXTERNALSYM D3DERR_VIEWPORTDATANOTSET}
  D3DERR_VIEWPORTHASNODEVICE      = MAKE_DDHRESULT + 774;
  {$EXTERNALSYM D3DERR_VIEWPORTHASNODEVICE}
  D3DERR_NOCURRENTVIEWPORT        = MAKE_DDHRESULT + 775;
  {$EXTERNALSYM D3DERR_NOCURRENTVIEWPORT}
{$ENDIF} // DIRECT3D_VERSION_5

{$IFDEF DIRECT3D_VERSION_6}
  D3DERR_INVALIDVERTEXFORMAT      = MAKE_DDHRESULT + 2048;
  {$EXTERNALSYM D3DERR_INVALIDVERTEXFORMAT}

(*
 * Attempted to CreateTexture on a surface that had a color key
 *)
  D3DERR_COLORKEYATTACHED                 = MAKE_DDHRESULT + 2050;
  {$EXTERNALSYM D3DERR_COLORKEYATTACHED}

  D3DERR_VERTEXBUFFEROPTIMIZED            = MAKE_DDHRESULT + 2060;
  {$EXTERNALSYM D3DERR_VERTEXBUFFEROPTIMIZED}
  D3DERR_VBUF_CREATE_FAILED               = MAKE_DDHRESULT + 2061;
  {$EXTERNALSYM D3DERR_VBUF_CREATE_FAILED}
  D3DERR_VERTEXBUFFERLOCKED               = MAKE_DDHRESULT + 2062;
  {$EXTERNALSYM D3DERR_VERTEXBUFFERLOCKED}

  D3DERR_ZBUFFER_NOTPRESENT               = MAKE_DDHRESULT + 2070;
  {$EXTERNALSYM D3DERR_ZBUFFER_NOTPRESENT}
  D3DERR_STENCILBUFFER_NOTPRESENT         = MAKE_DDHRESULT + 2071;
  {$EXTERNALSYM D3DERR_STENCILBUFFER_NOTPRESENT}

  D3DERR_WRONGTEXTUREFORMAT               = MAKE_DDHRESULT + 2072;
  {$EXTERNALSYM D3DERR_WRONGTEXTUREFORMAT}
  D3DERR_UNSUPPORTEDCOLOROPERATION        = MAKE_DDHRESULT + 2073;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDCOLOROPERATION}
  D3DERR_UNSUPPORTEDCOLORARG              = MAKE_DDHRESULT + 2074;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDCOLORARG}
  D3DERR_UNSUPPORTEDALPHAOPERATION        = MAKE_DDHRESULT + 2075;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDALPHAOPERATION}
  D3DERR_UNSUPPORTEDALPHAARG              = MAKE_DDHRESULT + 2076;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDALPHAARG}
  D3DERR_TOOMANYOPERATIONS                = MAKE_DDHRESULT + 2077;
  {$EXTERNALSYM D3DERR_TOOMANYOPERATIONS}
  D3DERR_CONFLICTINGTEXTUREFILTER         = MAKE_DDHRESULT + 2078;
  {$EXTERNALSYM D3DERR_CONFLICTINGTEXTUREFILTER}
  D3DERR_UNSUPPORTEDFACTORVALUE           = MAKE_DDHRESULT + 2079;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDFACTORVALUE}
  D3DERR_CONFLICTINGRENDERSTATE           = MAKE_DDHRESULT + 2081;
  {$EXTERNALSYM D3DERR_CONFLICTINGRENDERSTATE}
  D3DERR_UNSUPPORTEDTEXTUREFILTER         = MAKE_DDHRESULT + 2082;
  {$EXTERNALSYM D3DERR_UNSUPPORTEDTEXTUREFILTER}
  D3DERR_TOOMANYPRIMITIVES                = MAKE_DDHRESULT + 2083;
  {$EXTERNALSYM D3DERR_TOOMANYPRIMITIVES}
  D3DERR_INVALIDMATRIX                    = MAKE_DDHRESULT + 2084;
  {$EXTERNALSYM D3DERR_INVALIDMATRIX}
  D3DERR_TOOMANYVERTICES                  = MAKE_DDHRESULT + 2085;
  {$EXTERNALSYM D3DERR_TOOMANYVERTICES}
  D3DERR_CONFLICTINGTEXTUREPALETTE        = MAKE_DDHRESULT + 2086;
  {$EXTERNALSYM D3DERR_CONFLICTINGTEXTUREPALETTE}

{$ENDIF} // DIRECT3D_VERSION_6

{$IFDEF DIRECT3D_VERSION_7}
  D3DERR_INVALIDSTATEBLOCK        = MAKE_DDHRESULT + 2100;
  {$EXTERNALSYM D3DERR_INVALIDSTATEBLOCK}
  D3DERR_INBEGINSTATEBLOCK        = MAKE_DDHRESULT + 2101;
  {$EXTERNALSYM D3DERR_INBEGINSTATEBLOCK}
  D3DERR_NOTINBEGINSTATEBLOCK     = MAKE_DDHRESULT + 2102;
  {$EXTERNALSYM D3DERR_NOTINBEGINSTATEBLOCK}
{$ENDIF} // DIRECT3D_VERSION_7

{$ENDIF} // DIRECT3D_VERSION_LESS_8

procedure DisableFPUExceptions;
procedure EnableFPUExceptions;

{$IFNDEF EXCLUDE_DXFILE_FROM_DIRECT3D}
(***************************************************************************
 *
 *  Copyright (C) 1998-1999 Microsoft Corporation.  All Rights Reserved.
 *
 *  File:       dxfile.h
 *
 *  Content:    DirectX File public header file
 *
 ***************************************************************************)

var
  DXFileDLL : HMODULE;

function DXFileErrorString(Value: HResult): string;

type
  TDXFileFormat = (
    DXFILEFORMAT_BINARY,
    DXFILEFORMAT_TEXT,
    DXFILEFORMAT_COMPRESSED
  );

  TDXFileLoadOptions = (
    DXFILELOAD_FROMFILE,
    DXFILELOAD_FROMRESOURCE,
    DXFILELOAD_FROMMEMORY,
    DXFILELOAD_INVALID_3,
    DXFILELOAD_FROMSTREAM,
    DXFILELOAD_INVALID_5,
    DXFILELOAD_INVALID_6,
    DXFILELOAD_INVALID_7,
    DXFILELOAD_FROMURL
  );

  PDXFileLoadResource = ^TDXFileLoadResource;
  TDXFileLoadResource = packed record
    hModule: HModule;
    lpName: PAnsiChar;
    lpType: PAnsiChar;
  end;

  PDXFileLoadMemory = ^TDXFileLoadMemory;
  TDXFileLoadMemory = packed record
    lpMemory: Pointer;
    dSize: DWORD;
  end;

(*
 * DirectX File object types.
 *)

  IDirectXFile = interface;
  IDirectXFileEnumObject = interface;
  IDirectXFileSaveObject = interface;
  IDirectXFileObject = interface;
  IDirectXFileData = interface;
  IDirectXFileDataReference = interface;
  IDirectXFileBinary = interface;

(*
 * DirectX File interfaces.
 *)

  IDirectXFile = interface(IUnknown)
    ['{3d82ab40-62da-11cf-ab39-0020af71e433}']
    function CreateEnumObject(pvSource: Pointer;
        dwLoadOptions: TDXFileLoadOptions;
        var ppEnumObj: IDirectXFileEnumObject): HResult; stdcall;
    function CreateSaveObject(szFileName: PChar; dwFileFormat: TDXFileFormat;
        var ppSaveObj: IDirectXFileSaveObject): HResult; stdcall;
    function RegisterTemplates(pvData: Pointer; cbSize: DWORD): HResult; stdcall;
  end;

  IDirectXFileEnumObject = interface(IUnknown)
    ['{3d82ab41-62da-11cf-ab39-0020af71e433}']
    function GetNextDataObject(var ppDataObj: IDirectXFileData): HResult; stdcall;
    function GetDataObjectById
        (const rguid: TGUID; var ppDataObj: IDirectXFileData): HResult; stdcall;
    function GetDataObjectByName
        (szName: PChar; var ppDataObj: IDirectXFileData): HResult; stdcall;
  end;

  IDirectXFileSaveObject = interface(IUnknown)
    ['{3d82ab42-62da-11cf-ab39-0020af71e433}']
    function SaveTemplates
        (cTemplates: DWORD; var ppguidTemplates: PGUID): HResult; stdcall;
    function CreateDataObject(const rguidTemplate: TGUID; szName: PChar;
        pguid: PGUID; cbSize: DWORD; pvData: Pointer;
        var ppDataObj: IDirectXFileData): HResult; stdcall;
    function SaveData(pDataObj: IDirectXFileData): HResult; stdcall;
  end;

  IDirectXFileObject = interface(IUnknown)
    ['{3d82ab43-62da-11cf-ab39-0020af71e433}']
    function GetName(pstrNameBuf: PChar; var dwBufLen: DWORD): HResult; stdcall;
    function GetId(var pGuidBuf: TGUID): HResult; stdcall;
  end;

  IDirectXFileData = interface(IDirectXFileObject)
    ['{3d82ab44-62da-11cf-ab39-0020af71e433}']
    function GetData
        (szMember: PChar; var pcbSize: DWORD; var ppvData: Pointer): HResult; stdcall;
    function GetType(var ppguid: PGUID): HResult; stdcall;
    function GetNextObject(var ppChildObj: IDirectXFileObject): HResult; stdcall;
    function AddDataObject(pDataObj: IDirectXFileData): HResult; stdcall;
    function AddDataReference(szRef: PChar; pguidRef: PGUID): HResult; stdcall;
    function AddBinaryObject(szName: PChar; pguid: PGUID; szMimeType: PChar;
        pvData: Pointer; cbSize: DWORD): HResult; stdcall;
  end;

  IDirectXFileDataReference = interface(IDirectXFileObject)
    ['{3d82ab45-62da-11cf-ab39-0020af71e433}']
    function Resolve(var ppDataObj: IDirectXFileData): HResult; stdcall;
  end;

  IDirectXFileBinary = interface(IDirectXFileObject)
    ['{3d82ab46-62da-11cf-ab39-0020af71e433}']
    function GetSize(var pcbSize: DWORD): HResult; stdcall;
    function GetMimeType(var pszMimeType: PChar): HResult; stdcall;
    function Read(pvData: Pointer; cbSize: DWORD; pcbRead: PDWORD{?}): HResult; stdcall;
  end;

const

(*
 * DirectXFile Object Class Id (for CoCreateInstance())
 *)

   CLSID_CDirectXFile: TGUID =
       (D1:$4516ec43;D2:$8f20;D3:$11d0;D4:($9b,$6d,$00,$00,$c0,$78,$1b,$c3));

(*
 * DirectX File Interface GUIDs.
 *)

type
  IID_IDirectXFile = IDirectXFile;
  IID_IDirectXFileEnumObject = IDirectXFileEnumObject;
  IID_IDirectXFileSaveObject = IDirectXFileSaveObject;
  IID_IDirectXFileObject = IDirectXFileObject;
  IID_IDirectXFileData = IDirectXFileData;
  IID_IDirectXFileDataReference = IDirectXFileDataReference;
  IID_IDirectXFileBinary = IDirectXFileBinary;

(*
 * DirectX File Header template's GUID.
 *)
const
  TID_DXFILEHeader: TGUID =
      (D1:$3d82ab43;D2:$62da;D3:$11cf;D4:($ab,$39,$00,$20,$af,$71,$e4,$33));

(*
 * DirectX File errors.
 *)

const
  DXFILE_OK = 0;

  DXFILEERR_BADOBJECT                 = MAKE_DDHRESULT or 850;
  DXFILEERR_BADVALUE                  = MAKE_DDHRESULT or 851;
  DXFILEERR_BADTYPE                   = MAKE_DDHRESULT or 852;
  DXFILEERR_BADSTREAMHANDLE           = MAKE_DDHRESULT or 853;
  DXFILEERR_BADALLOC                  = MAKE_DDHRESULT or 854;
  DXFILEERR_NOTFOUND                  = MAKE_DDHRESULT or 855;
  DXFILEERR_NOTDONEYET                = MAKE_DDHRESULT or 856;
  DXFILEERR_FILENOTFOUND              = MAKE_DDHRESULT or 857;
  DXFILEERR_RESOURCENOTFOUND          = MAKE_DDHRESULT or 858;
  DXFILEERR_URLNOTFOUND               = MAKE_DDHRESULT or 859;
  DXFILEERR_BADRESOURCE               = MAKE_DDHRESULT or 860;
  DXFILEERR_BADFILETYPE               = MAKE_DDHRESULT or 861;
  DXFILEERR_BADFILEVERSION            = MAKE_DDHRESULT or 862;
  DXFILEERR_BADFILEFLOATSIZE          = MAKE_DDHRESULT or 863;
  DXFILEERR_BADFILECOMPRESSIONTYPE    = MAKE_DDHRESULT or 864;
  DXFILEERR_BADFILE                   = MAKE_DDHRESULT or 865;
  DXFILEERR_PARSEERROR                = MAKE_DDHRESULT or 866;
  DXFILEERR_NOTEMPLATE                = MAKE_DDHRESULT or 867;
  DXFILEERR_BADARRAYSIZE              = MAKE_DDHRESULT or 868;
  DXFILEERR_BADDATAREFERENCE          = MAKE_DDHRESULT or 869;
  DXFILEERR_INTERNALERROR             = MAKE_DDHRESULT or 870;
  DXFILEERR_NOMOREOBJECTS             = MAKE_DDHRESULT or 871;
  DXFILEERR_BADINTRINSICS             = MAKE_DDHRESULT or 872;
  DXFILEERR_NOMORESTREAMHANDLES       = MAKE_DDHRESULT or 873;
  DXFILEERR_NOMOREDATA                = MAKE_DDHRESULT or 874;
  DXFILEERR_BADCACHEFILE              = MAKE_DDHRESULT or 875;
  DXFILEERR_NOINTERNET                = MAKE_DDHRESULT or 876;


(*
 * API for creating IDirectXFile interface.
 *)

var
  DirectXFileCreate : function
    (out lplpDirectXFile: IDirectXFile): HResult; stdcall;

(* D3DRM XFile templates in binary form *)
const
  D3DRM_XTEMPLATES: array [0..3214] of Byte = (
        $78, $6f, $66, $20, $30, $33, $30, $32, $62,
        $69, $6e, $20, $30, $30, $36, $34, $1f, 0, $1,
        0, $6, 0, 0, 0, $48, $65, $61, $64, $65,
        $72, $a, 0, $5, 0, $43, $ab, $82, $3d, $da,
        $62, $cf, $11, $ab, $39, 0, $20, $af, $71, $e4,
        $33, $28, 0, $1, 0, $5, 0, 0, 0, $6d, 
        $61, $6a, $6f, $72, $14, 0, $28, 0, $1, 0, 
        $5, 0, 0, 0, $6d, $69, $6e, $6f, $72, $14, 
        0, $29, 0, $1, 0, $5, 0, 0, 0, $66, 
        $6c, $61, $67, $73, $14, 0, $b, 0, $1f, 0, 
        $1, 0, $6, 0, 0, 0, $56, $65, $63, $74, 
        $6f, $72, $a, 0, $5, 0, $5e, $ab, $82, $3d,
        $da, $62, $cf, $11, $ab, $39, 0, $20, $af, $71,
        $e4, $33, $2a, 0, $1, 0, $1, 0, 0, 0,
        $78, $14, 0, $2a, 0, $1, 0, $1, 0, 0,
        0, $79, $14, 0, $2a, 0, $1, 0, $1, 0,
        0, 0, $7a, $14, 0, $b, 0, $1f, 0, $1, 
        0, $8, 0, 0, 0, $43, $6f, $6f, $72, $64, 
        $73, $32, $64, $a, 0, $5, 0, $44, $3f, $f2, 
        $f6, $86, $76, $cf, $11, $8f, $52, 0, $40, $33, 
        $35, $94, $a3, $2a, 0, $1, 0, $1, 0, 0, 
        0, $75, $14, 0, $2a, 0, $1, 0, $1, 0, 
        0, 0, $76, $14, 0, $b, 0, $1f, 0, $1, 
        0, $9, 0, 0, 0, $4d, $61, $74, $72, $69, 
        $78, $34, $78, $34, $a, 0, $5, 0, $45, $3f, 
        $f2, $f6, $86, $76, $cf, $11, $8f, $52, 0, $40, 
        $33, $35, $94, $a3, $34, 0, $2a, 0, $1, 0, 
        $6, 0, 0, 0, $6d, $61, $74, $72, $69, $78, 
        $e, 0, $3, 0, $10, 0, 0, 0, $f, 0, 
        $14, 0, $b, 0, $1f, 0, $1, 0, $9, 0, 
        0, 0, $43, $6f, $6c, $6f, $72, $52, $47, $42, 
        $41, $a, 0, $5, 0, $e0, $44, $ff, $35, $7c, 
        $6c, $cf, $11, $8f, $52, 0, $40, $33, $35, $94, 
        $a3, $2a, 0, $1, 0, $3, 0, 0, 0, $72, 
        $65, $64, $14, 0, $2a, 0, $1, 0, $5, 0, 
        0, 0, $67, $72, $65, $65, $6e, $14, 0, $2a, 
        0, $1, 0, $4, 0, 0, 0, $62, $6c, $75, 
        $65, $14, 0, $2a, 0, $1, 0, $5, 0, 0, 
        0, $61, $6c, $70, $68, $61, $14, 0, $b, 0, 
        $1f, 0, $1, 0, $8, 0, 0, 0, $43, $6f,
        $6c, $6f, $72, $52, $47, $42, $a, 0, $5, 0, 
        $81, $6e, $e1, $d3, $35, $78, $cf, $11, $8f, $52, 
        0, $40, $33, $35, $94, $a3, $2a, 0, $1, 0,
        $3, 0, 0, 0, $72, $65, $64, $14, 0, $2a,
        0, $1, 0, $5, 0, 0, 0, $67, $72, $65, 
        $65, $6e, $14, 0, $2a, 0, $1, 0, $4, 0, 
        0, 0, $62, $6c, $75, $65, $14, 0, $b, 0, 
        $1f, 0, $1, 0, $c, 0, 0, 0, $49, $6e, 
        $64, $65, $78, $65, $64, $43, $6f, $6c, $6f, $72, 
        $a, 0, $5, 0, $20, $b8, $30, $16, $42, $78, 
        $cf, $11, $8f, $52, 0, $40, $33, $35, $94, $a3, 
        $29, 0, $1, 0, $5, 0, 0, 0, $69, $6e, 
        $64, $65, $78, $14, 0, $1, 0, $9, 0, 0, 
        0, $43, $6f, $6c, $6f, $72, $52, $47, $42, $41, 
        $1, 0, $a, 0, 0, 0, $69, $6e, $64, $65, 
        $78, $43, $6f, $6c, $6f, $72, $14, 0, $b, 0, 
        $1f, 0, $1, 0, $7, 0, 0, 0, $42, $6f, 
        $6f, $6c, $65, $61, $6e, $a, 0, $5, 0, $a0, 
        $a6, $7d, $53, $37, $ca, $d0, $11, $94, $1c, 0, 
        $80, $c8, $c, $fa, $7b, $29, 0, $1, 0, $9, 
        0, 0, 0, $74, $72, $75, $65, $66, $61, $6c, 
        $73, $65, $14, 0, $b, 0, $1f, 0, $1, 0, 
        $9, 0, 0, 0, $42, $6f, $6f, $6c, $65, $61, 
        $6e, $32, $64, $a, 0, $5, 0, $63, $ae, $85, 
        $48, $e8, $78, $cf, $11, $8f, $52, 0, $40, $33, 
        $35, $94, $a3, $1, 0, $7, 0, 0, 0, $42, 
        $6f, $6f, $6c, $65, $61, $6e, $1, 0, $1, 0, 
        0, 0, $75, $14, 0, $1, 0, $7, 0, 0, 
        0, $42, $6f, $6f, $6c, $65, $61, $6e, $1, 0, 
        $1, 0, 0, 0, $76, $14, 0, $b, 0, $1f, 
        0, $1, 0, $c, 0, 0, 0, $4d, $61, $74,
        $65, $72, $69, $61, $6c, $57, $72, $61, $70, $a, 
        0, $5, 0, $60, $ae, $85, $48, $e8, $78, $cf, 
        $11, $8f, $52, 0, $40, $33, $35, $94, $a3, $1, 
        0, $7, 0, 0, 0, $42, $6f, $6f, $6c, $65, 
        $61, $6e, $1, 0, $1, 0, 0, 0, $75, $14, 
        0, $1, 0, $7, 0, 0, 0, $42, $6f, $6f,
        $6c, $65, $61, $6e, $1, 0, $1, 0, 0, 0, 
        $76, $14, 0, $b, 0, $1f, 0, $1, 0, $f, 
        0, 0, 0, $54, $65, $78, $74, $75, $72, $65,
        $46, $69, $6c, $65, $6e, $61, $6d, $65, $a, 0, 
        $5, 0, $e1, $90, $27, $a4, $10, $78, $cf, $11, 
        $8f, $52, 0, $40, $33, $35, $94, $a3, $31, 0, 
        $1, 0, $8, 0, 0, 0, $66, $69, $6c, $65,
        $6e, $61, $6d, $65, $14, 0, $b, 0, $1f, 0, 
        $1, 0, $8, 0, 0, 0, $4d, $61, $74, $65, 
        $72, $69, $61, $6c, $a, 0, $5, 0, $4d, $ab, 
        $82, $3d, $da, $62, $cf, $11, $ab, $39, 0, $20, 
        $af, $71, $e4, $33, $1, 0, $9, 0, 0, 0, 
        $43, $6f, $6c, $6f, $72, $52, $47, $42, $41, $1, 
        0, $9, 0, 0, 0, $66, $61, $63, $65, $43, 
        $6f, $6c, $6f, $72, $14, 0, $2a, 0, $1, 0, 
        $5, 0, 0, 0, $70, $6f, $77, $65, $72, $14, 
        0, $1, 0, $8, 0, 0, 0, $43, $6f, $6c, 
        $6f, $72, $52, $47, $42, $1, 0, $d, 0, 0, 
        0, $73, $70, $65, $63, $75, $6c, $61, $72, $43, 
        $6f, $6c, $6f, $72, $14, 0, $1, 0, $8, 0, 
        0, 0, $43, $6f, $6c, $6f, $72, $52, $47, $42, 
        $1, 0, $d, 0, 0, 0, $65, $6d, $69, $73,
        $73, $69, $76, $65, $43, $6f, $6c, $6f, $72, $14, 
        0, $e, 0, $12, 0, $12, 0, $12, 0, $f, 
        0, $b, 0, $1f, 0, $1, 0, $8, 0, 0, 
        0, $4d, $65, $73, $68, $46, $61, $63, $65, $a, 
        0, $5, 0, $5f, $ab, $82, $3d, $da, $62, $cf, 
        $11, $ab, $39, 0, $20, $af, $71, $e4, $33, $29, 
        0, $1, 0, $12, 0, 0, 0, $6e, $46, $61, 
        $63, $65, $56, $65, $72, $74, $65, $78, $49, $6e, 
        $64, $69, $63, $65, $73, $14, 0, $34, 0, $29, 
        0, $1, 0, $11, 0, 0, 0, $66, $61, $63, 
        $65, $56, $65, $72, $74, $65, $78, $49, $6e, $64, 
        $69, $63, $65, $73, $e, 0, $1, 0, $12, 0, 
        0, 0, $6e, $46, $61, $63, $65, $56, $65, $72, 
        $74, $65, $78, $49, $6e, $64, $69, $63, $65, $73, 
        $f, 0, $14, 0, $b, 0, $1f, 0, $1, 0,
        $d, 0, 0, 0, $4d, $65, $73, $68, $46, $61, 
        $63, $65, $57, $72, $61, $70, $73, $a, 0, $5, 
        0, $c0, $c5, $1e, $ed, $a8, $c0, $d0, $11, $94, 
        $1c, 0, $80, $c8, $c, $fa, $7b, $29, 0, $1, 
        0, $f, 0, 0, 0, $6e, $46, $61, $63, $65, 
        $57, $72, $61, $70, $56, $61, $6c, $75, $65, $73,
        $14, 0, $34, 0, $1, 0, $9, 0, 0, 0, 
        $42, $6f, $6f, $6c, $65, $61, $6e, $32, $64, $1, 
        0, $e, 0, 0, 0, $66, $61, $63, $65, $57, 
        $72, $61, $70, $56, $61, $6c, $75, $65, $73, $e,
        0, $1, 0, $f, 0, 0, 0, $6e, $46, $61, 
        $63, $65, $57, $72, $61, $70, $56, $61, $6c, $75, 
        $65, $73, $f, 0, $14, 0, $b, 0, $1f, 0,
        $1, 0, $11, 0, 0, 0, $4d, $65, $73, $68, 
        $54, $65, $78, $74, $75, $72, $65, $43, $6f, $6f, 
        $72, $64, $73, $a, 0, $5, 0, $40, $3f, $f2, 
        $f6, $86, $76, $cf, $11, $8f, $52, 0, $40, $33, 
        $35, $94, $a3, $29, 0, $1, 0, $e, 0, 0, 
        0, $6e, $54, $65, $78, $74, $75, $72, $65, $43, 
        $6f, $6f, $72, $64, $73, $14, 0, $34, 0, $1, 
        0, $8, 0, 0, 0, $43, $6f, $6f, $72, $64, 
        $73, $32, $64, $1, 0, $d, 0, 0, 0, $74, 
        $65, $78, $74, $75, $72, $65, $43, $6f, $6f, $72, 
        $64, $73, $e, 0, $1, 0, $e, 0, 0, 0, 
        $6e, $54, $65, $78, $74, $75, $72, $65, $43, $6f, 
        $6f, $72, $64, $73, $f, 0, $14, 0, $b, 0, 
        $1f, 0, $1, 0, $10, 0, 0, 0, $4d, $65, 
        $73, $68, $4d, $61, $74, $65, $72, $69, $61, $6c, 
        $4c, $69, $73, $74, $a, 0, $5, 0, $42, $3f, 
        $f2, $f6, $86, $76, $cf, $11, $8f, $52, 0, $40, 
        $33, $35, $94, $a3, $29, 0, $1, 0, $a, 0, 
        0, 0, $6e, $4d, $61, $74, $65, $72, $69, $61, 
        $6c, $73, $14, 0, $29, 0, $1, 0, $c, 0, 
        0, 0, $6e, $46, $61, $63, $65, $49, $6e, $64, 
        $65, $78, $65, $73, $14, 0, $34, 0, $29, 0, 
        $1, 0, $b, 0, 0, 0, $66, $61, $63, $65, 
        $49, $6e, $64, $65, $78, $65, $73, $e, 0, $1,
        0, $c, 0, 0, 0, $6e, $46, $61, $63, $65, 
        $49, $6e, $64, $65, $78, $65, $73, $f, 0, $14, 
        0, $e, 0, $1, 0, $8, 0, 0, 0, $4d, 
        $61, $74, $65, $72, $69, $61, $6c, $f, 0, $b,
        0, $1f, 0, $1, 0, $b, 0, 0, 0, $4d, 
        $65, $73, $68, $4e, $6f, $72, $6d, $61, $6c, $73, 
        $a, 0, $5, 0, $43, $3f, $f2, $f6, $86, $76, 
        $cf, $11, $8f, $52, 0, $40, $33, $35, $94, $a3, 
        $29, 0, $1, 0, $8, 0, 0, 0, $6e, $4e,
        $6f, $72, $6d, $61, $6c, $73, $14, 0, $34, 0, 
        $1, 0, $6, 0, 0, 0, $56, $65, $63, $74, 
        $6f, $72, $1, 0, $7, 0, 0, 0, $6e, $6f, 
        $72, $6d, $61, $6c, $73, $e, 0, $1, 0, $8,
        0, 0, 0, $6e, $4e, $6f, $72, $6d, $61, $6c, 
        $73, $f, 0, $14, 0, $29, 0, $1, 0, $c, 
        0, 0, 0, $6e, $46, $61, $63, $65, $4e, $6f, 
        $72, $6d, $61, $6c, $73, $14, 0, $34, 0, $1, 
        0, $8, 0, 0, 0, $4d, $65, $73, $68, $46, 
        $61, $63, $65, $1, 0, $b, 0, 0, 0, $66, 
        $61, $63, $65, $4e, $6f, $72, $6d, $61, $6c, $73, 
        $e, 0, $1, 0, $c, 0, 0, 0, $6e, $46, 
        $61, $63, $65, $4e, $6f, $72, $6d, $61, $6c, $73, 
        $f, 0, $14, 0, $b, 0, $1f, 0, $1, 0, 
        $10, 0, 0, 0, $4d, $65, $73, $68, $56, $65, 
        $72, $74, $65, $78, $43, $6f, $6c, $6f, $72, $73, 
        $a, 0, $5, 0, $21, $b8, $30, $16, $42, $78, 
        $cf, $11, $8f, $52, 0, $40, $33, $35, $94, $a3, 
        $29, 0, $1, 0, $d, 0, 0, 0, $6e, $56, 
        $65, $72, $74, $65, $78, $43, $6f, $6c, $6f, $72, 
        $73, $14, 0, $34, 0, $1, 0, $c, 0, 0, 
        0, $49, $6e, $64, $65, $78, $65, $64, $43, $6f, 
        $6c, $6f, $72, $1, 0, $c, 0, 0, 0, $76,
        $65, $72, $74, $65, $78, $43, $6f, $6c, $6f, $72, 
        $73, $e, 0, $1, 0, $d, 0, 0, 0, $6e, 
        $56, $65, $72, $74, $65, $78, $43, $6f, $6c, $6f, 
        $72, $73, $f, 0, $14, 0, $b, 0, $1f, 0, 
        $1, 0, $4, 0, 0, 0, $4d, $65, $73, $68,
        $a, 0, $5, 0, $44, $ab, $82, $3d, $da, $62, 
        $cf, $11, $ab, $39, 0, $20, $af, $71, $e4, $33, 
        $29, 0, $1, 0, $9, 0, 0, 0, $6e, $56, 
        $65, $72, $74, $69, $63, $65, $73, $14, 0, $34, 
        0, $1, 0, $6, 0, 0, 0, $56, $65, $63, 
        $74, $6f, $72, $1, 0, $8, 0, 0, 0, $76, 
        $65, $72, $74, $69, $63, $65, $73, $e, 0, $1, 
        0, $9, 0, 0, 0, $6e, $56, $65, $72, $74, 
        $69, $63, $65, $73, $f, 0, $14, 0, $29, 0, 
        $1, 0, $6, 0, 0, 0, $6e, $46, $61, $63, 
        $65, $73, $14, 0, $34, 0, $1, 0, $8, 0, 
        0, 0, $4d, $65, $73, $68, $46, $61, $63, $65,
        $1, 0, $5, 0, 0, 0, $66, $61, $63, $65, 
        $73, $e, 0, $1, 0, $6, 0, 0, 0, $6e, 
        $46, $61, $63, $65, $73, $f, 0, $14, 0, $e, 
        0, $12, 0, $12, 0, $12, 0, $f, 0, $b,
        0, $1f, 0, $1, 0, $14, 0, 0, 0, $46, 
        $72, $61, $6d, $65, $54, $72, $61, $6e, $73, $66, 
        $6f, $72, $6d, $4d, $61, $74, $72, $69, $78, $a, 
        0, $5, 0, $41, $3f, $f2, $f6, $86, $76, $cf, 
        $11, $8f, $52, 0, $40, $33, $35, $94, $a3, $1, 
        0, $9, 0, 0, 0, $4d, $61, $74, $72, $69, 
        $78, $34, $78, $34, $1, 0, $b, 0, 0, 0,
        $66, $72, $61, $6d, $65, $4d, $61, $74, $72, $69, 
        $78, $14, 0, $b, 0, $1f, 0, $1, 0, $5, 
        0, 0, 0, $46, $72, $61, $6d, $65, $a, 0, 
        $5, 0, $46, $ab, $82, $3d, $da, $62, $cf, $11, 
        $ab, $39, 0, $20, $af, $71, $e4, $33, $e, 0, 
        $12, 0, $12, 0, $12, 0, $f, 0, $b, 0, 
        $1f, 0, $1, 0, $9, 0, 0, 0, $46, $6c, 
        $6f, $61, $74, $4b, $65, $79, $73, $a, 0, $5, 
        0, $a9, $46, $dd, $10, $5b, $77, $cf, $11, $8f, 
        $52, 0, $40, $33, $35, $94, $a3, $29, 0, $1, 
        0, $7, 0, 0, 0, $6e, $56, $61, $6c, $75, 
        $65, $73, $14, 0, $34, 0, $2a, 0, $1, 0, 
        $6, 0, 0, 0, $76, $61, $6c, $75, $65, $73, 
        $e, 0, $1, 0, $7, 0, 0, 0, $6e, $56,
        $61, $6c, $75, $65, $73, $f, 0, $14, 0, $b, 
        0, $1f, 0, $1, 0, $e, 0, 0, 0, $54, 
        $69, $6d, $65, $64, $46, $6c, $6f, $61, $74, $4b, 
        $65, $79, $73, $a, 0, $5, 0, $80, $b1, $6, 
        $f4, $3b, $7b, $cf, $11, $8f, $52, 0, $40, $33, 
        $35, $94, $a3, $29, 0, $1, 0, $4, 0, 0, 
        0, $74, $69, $6d, $65, $14, 0, $1, 0, $9, 
        0, 0, 0, $46, $6c, $6f, $61, $74, $4b, $65, 
        $79, $73, $1, 0, $6, 0, 0, 0, $74, $66, 
        $6b, $65, $79, $73, $14, 0, $b, 0, $1f, 0, 
        $1, 0, $c, 0, 0, 0, $41, $6e, $69, $6d, 
        $61, $74, $69, $6f, $6e, $4b, $65, $79, $a, 0, 
        $5, 0, $a8, $46, $dd, $10, $5b, $77, $cf, $11, 
        $8f, $52, 0, $40, $33, $35, $94, $a3, $29, 0,
        $1, 0, $7, 0, 0, 0, $6b, $65, $79, $54,
        $79, $70, $65, $14, 0, $29, 0, $1, 0, $5, 
        0, 0, 0, $6e, $4b, $65, $79, $73, $14, 0, 
        $34, 0, $1, 0, $e, 0, 0, 0, $54, $69, 
        $6d, $65, $64, $46, $6c, $6f, $61, $74, $4b, $65,
        $79, $73, $1, 0, $4, 0, 0, 0, $6b, $65, 
        $79, $73, $e, 0, $1, 0, $5, 0, 0, 0, 
        $6e, $4b, $65, $79, $73, $f, 0, $14, 0, $b, 
        0, $1f, 0, $1, 0, $10, 0, 0, 0, $41, 
        $6e, $69, $6d, $61, $74, $69, $6f, $6e, $4f, $70, 
        $74, $69, $6f, $6e, $73, $a, 0, $5, 0, $c0, 
        $56, $bf, $e2, $f, $84, $cf, $11, $8f, $52, 0, 
        $40, $33, $35, $94, $a3, $29, 0, $1, 0, $a, 
        0, 0, 0, $6f, $70, $65, $6e, $63, $6c, $6f, 
        $73, $65, $64, $14, 0, $29, 0, $1, 0, $f, 
        0, 0, 0, $70, $6f, $73, $69, $74, $69, $6f, 
        $6e, $71, $75, $61, $6c, $69, $74, $79, $14, 0, 
        $b, 0, $1f, 0, $1, 0, $9, 0, 0, 0, 
        $41, $6e, $69, $6d, $61, $74, $69, $6f, $6e, $a, 
        0, $5, 0, $4f, $ab, $82, $3d, $da, $62, $cf, 
        $11, $ab, $39, 0, $20, $af, $71, $e4, $33, $e, 
        0, $12, 0, $12, 0, $12, 0, $f, 0, $b, 
        0, $1f, 0, $1, 0, $c, 0, 0, 0, $41,
        $6e, $69, $6d, $61, $74, $69, $6f, $6e, $53, $65, 
        $74, $a, 0, $5, 0, $50, $ab, $82, $3d, $da, 
        $62, $cf, $11, $ab, $39, 0, $20, $af, $71, $e4, 
        $33, $e, 0, $1, 0, $9, 0, 0, 0, $41, 
        $6e, $69, $6d, $61, $74, $69, $6f, $6e, $f, 0,
        $b, 0, $1f, 0, $1, 0, $a, 0, 0, 0, 
        $49, $6e, $6c, $69, $6e, $65, $44, $61, $74, $61, 
        $a, 0, $5, 0, $a0, $ee, $23, $3a, $b1, $94, 
        $d0, $11, $ab, $39, 0, $20, $af, $71, $e4, $33, 
        $e, 0, $1, 0, $6, 0, 0, 0, $42, $49, 
        $4e, $41, $52, $59, $f, 0, $b, 0, $1f, 0, 
        $1, 0, $3, 0, 0, 0, $55, $72, $6c, $a, 
        0, $5, 0, $a1, $ee, $23, $3a, $b1, $94, $d0, 
        $11, $ab, $39, 0, $20, $af, $71, $e4, $33, $29, 
        0, $1, 0, $5, 0, 0, 0, $6e, $55, $72, 
        $6c, $73, $14, 0, $34, 0, $31, 0, $1, 0, 
        $4, 0, 0, 0, $75, $72, $6c, $73, $e, 0, 
        $1, 0, $5, 0, 0, 0, $6e, $55, $72, $6c,
        $73, $f, 0, $14, 0, $b, 0, $1f, 0, $1, 
        0, $f, 0, 0, 0, $50, $72, $6f, $67, $72, 
        $65, $73, $73, $69, $76, $65, $4d, $65, $73, $68, 
        $a, 0, $5, 0, $60, $c3, $63, $8a, $7d, $99,
        $d0, $11, $94, $1c, 0, $80, $c8, $c, $fa, $7b, 
        $e, 0, $1, 0, $3, 0, 0, 0, $55, $72, 
        $6c, $13, 0, $1, 0, $a, 0, 0, 0, $49, 
        $6e, $6c, $69, $6e, $65, $44, $61, $74, $61, $f, 
        0, $b, 0, $1f, 0, $1, 0, $4, 0, 0, 
        0, $47, $75, $69, $64, $a, 0, $5, 0, $e0, 
        $90, $27, $a4, $10, $78, $cf, $11, $8f, $52, 0, 
        $40, $33, $35, $94, $a3, $29, 0, $1, 0, $5, 
        0, 0, 0, $64, $61, $74, $61, $31, $14, 0, 
        $28, 0, $1, 0, $5, 0, 0, 0, $64, $61, 
        $74, $61, $32, $14, 0, $28, 0, $1, 0, $5,
        0, 0, 0, $64, $61, $74, $61, $33, $14, 0, 
        $34, 0, $2d, 0, $1, 0, $5, 0, 0, 0, 
        $64, $61, $74, $61, $34, $e, 0, $3, 0, $8, 
        0, 0, 0, $f, 0, $14, 0, $b, 0, $1f,
        0, $1, 0, $e, 0, 0, 0, $53, $74, $72,
        $69, $6e, $67, $50, $72, $6f, $70, $65, $72, $74,
        $79, $a, 0, $5, 0, $e0, $21, $f, $7f, $e1,
        $bf, $d1, $11, $82, $c0, 0, $a0, $c9, $69, $72,
        $71, $31, 0, $1, 0, $3, 0, 0, 0, $6b,
        $65, $79, $14, 0, $31, 0, $1, 0, $5, 0,
        0, 0, $76, $61, $6c, $75, $65, $14, 0, $b,
        0, $1f, 0, $1, 0, $b, 0, 0, 0, $50,
        $72, $6f, $70, $65, $72, $74, $79, $42, $61, $67,
        $a, 0, $5, 0, $e1, $21, $f, $7f, $e1, $bf,
        $d1, $11, $82, $c0, 0, $a0, $c9, $69, $72, $71,
        $e, 0, $1, 0, $e, 0, 0, 0, $53, $74,
        $72, $69, $6e, $67, $50, $72, $6f, $70, $65, $72,
        $74, $79, $f, 0, $b, 0, $1f, 0, $1, 0,
        $e, 0, 0, 0, $45, $78, $74, $65, $72, $6e,
        $61, $6c, $56, $69, $73, $75, $61, $6c, $a, 0,
        $5, 0, $a0, $6a, $11, $98, $ba, $bd, $d1, $11,
        $82, $c0, 0, $a0, $c9, $69, $72, $71, $1, 0,
        $4, 0, 0, 0, $47, $75, $69, $64, $1, 0,
        $12, 0, 0, 0, $67, $75, $69, $64, $45, $78,
        $74, $65, $72, $6e, $61, $6c, $56, $69, $73, $75,
        $61, $6c, $14, 0, $e, 0, $12, 0, $12, 0,
        $12, 0, $f, 0, $b, 0);
{$ENDIF}

implementation

{$IFDEF DIRECT3D_VERSION_LESS_8}
{$IFDEF DIRECT3D_VERSION_7}

function D3DFVF_TEXCOORDSIZE3(CoordIndex: DWORD): DWORD;
begin
  Result := (D3DFVF_TEXTUREFORMAT3 shl (CoordIndex*2 + 16));
end;

function D3DFVF_TEXCOORDSIZE2(CoordIndex: DWORD): DWORD;
begin
  Result := (D3DFVF_TEXTUREFORMAT2);
end;

function D3DFVF_TEXCOORDSIZE4(CoordIndex: DWORD): DWORD;
begin
  Result := (D3DFVF_TEXTUREFORMAT4 shl (CoordIndex*2 + 16));
end;

function D3DFVF_TEXCOORDSIZE1(CoordIndex: DWORD): DWORD;
begin
  Result := (D3DFVF_TEXTUREFORMAT1 shl (CoordIndex*2 + 16));
end;

{$ENDIF} // DIRECT3D_VERSION_7
{$ENDIF} // DIRECT3D_VERSION_LESS_8

function D3DVal(val: variant): Single;
begin
  Result := val;
end;

function D3DDivide(a, b: double): Single;
begin
  Result := a / b;
end;

function D3DMultiply(a, b: double): Single;
begin
  Result := a * b;
end;

// #define CI_GETALPHA(ci)    ((ci) >> 24)
function CI_GETALPHA(ci: DWORD): DWORD;
begin
  Result := ci shr 24;
end;

// #define CI_GETINDEX(ci)    (((ci) >> 8) & 0xffff)
function CI_GETINDEX(ci: DWORD): DWORD;
begin
  Result := (ci shr 8) and $ffff;
end;

// #define CI_GETFRACTION(ci) ((ci) & 0xff)
function CI_GETFRACTION(ci: DWORD): DWORD;
begin
  Result := ci and $ff;
end;

// #define CI_ROUNDINDEX(ci)  CI_GETINDEX((ci) + 0x80)
function CI_ROUNDINDEX(ci: DWORD): DWORD;
begin
  Result := CI_GETINDEX(ci + $80);
end;

// #define CI_MASKALPHA(ci)   ((ci) & 0xffffff)
function CI_MASKALPHA(ci: DWORD): DWORD;
begin
  Result := ci and $ffffff;
end;

// #define CI_MAKE(a, i, f)    (((a) << 24) | ((i) << 8) | (f))
function CI_MAKE(a,i,f: DWORD): DWORD;
begin
  Result := (a shl 24) or (i shl 8) or f;
end;

// #define RGBA_GETALPHA(rgb)      ((rgb) >> 24)
function RGBA_GETALPHA(rgb: TD3DColor): DWORD;
begin
  Result := rgb shr 24;
end;

// #define RGBA_GETRED(rgb)        (((rgb) >> 16) & 0xff)
function RGBA_GETRED(rgb: TD3DColor): DWORD;
begin
  Result := (rgb shr 16) and $ff;
end;

// #define RGBA_GETGREEN(rgb)      (((rgb) >> 8) & 0xff)
function RGBA_GETGREEN(rgb: TD3DColor): DWORD;
begin
  Result := (rgb shr 8) and $ff;
end;

// #define RGBA_GETBLUE(rgb)       ((rgb) & 0xff)
function RGBA_GETBLUE(rgb: TD3DColor): DWORD;
begin
  Result := rgb and $ff;
end;

// #define RGBA_MAKE(r, g, b, a)   ((TD3DColor) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
function RGBA_MAKE(r, g, b, a: DWORD): TD3DColor;
begin
  Result := (a shl 24) or (r shl 16) or (g shl 8) or b;
end;

// #define D3DRGB(r, g, b) \
//     (0xff000000L | (((long)((r) * 255)) << 16) | (((long)((g) * 255)) << 8) | (long)((b) * 255))
function D3DRGB(r, g, b: Single): TD3DColor;
begin
  Result := $ff000000 or DWORD(Round(r * 255) shl 16)
                      or DWORD(Round(g * 255) shl 8)
                      or DWORD(Round(b * 255));
end;

// #define D3DRGBA(r, g, b, a) \
//     (  (((long)((a) * 255)) << 24) | (((long)((r) * 255)) << 16) \
//     |   (((long)((g) * 255)) << 8) | (long)((b) * 255) \
//    )
function D3DRGBA(r, g, b, a: Single): TD3DColor;
begin
  Result := DWORD(Round(a * 255) shl 24) or DWORD(Round(r * 255) shl 16)
                                         or DWORD(Round(g * 255) shl 8)
                                         or DWORD(Round(b * 255));
end;

// #define RGB_GETRED(rgb)         (((rgb) >> 16) & 0xff)
function RGB_GETRED(rgb: TD3DColor): DWORD;
begin
  Result := (rgb shr 16) and $ff;
end;

// #define RGB_GETGREEN(rgb)       (((rgb) >> 8) & 0xff)
function RGB_GETGREEN(rgb: TD3DColor): DWORD;
begin
  Result := (rgb shr 8) and $ff;
end;

// #define RGB_GETBLUE(rgb)        ((rgb) & 0xff)
function RGB_GETBLUE(rgb: TD3DColor): DWORD;
begin
  Result := rgb and $ff;
end;

// #define RGBA_SETALPHA(rgba, x) (((x) << 24) | ((rgba) & 0x00ffffff))
function RGBA_SETALPHA(rgba: TD3DColor; x: DWORD): TD3DColor;
begin
  Result := (x shl 24) or (rgba and $00ffffff);
end;

// #define RGB_MAKE(r, g, b)       ((TD3DColor) (((r) << 16) | ((g) << 8) | (b)))
function RGB_MAKE(r, g, b: DWORD): TD3DColor;
begin
  Result := (r shl 16) or (g shl 8) or b;
end;

// #define RGBA_TORGB(rgba)       ((TD3DColor) ((rgba) & 0xffffff))
function RGBA_TORGB(rgba: TD3DColor): TD3DColor;
begin
  Result := rgba and $00ffffff;
end;

// #define RGB_TORGBA(rgb)        ((TD3DColor) ((rgb) | 0xff000000))
function RGB_TORGBA(rgb: TD3DColor): TD3DColor;
begin
  Result := rgb or $ff000000;
end;


function D3DSTATE_OVERRIDE(StateType: DWORD): DWORD;
begin
  Result := StateType + D3DSTATE_OVERRIDE_BIAS;
end;

function D3DTRIFLAG_STARTFLAT(len: DWORD): DWORD;
begin
  if not (len in [1..29]) then len := 0;
  Result := len;
end;

// #define D3DRENDERSTATE_STIPPLEPATTERN(y) (D3DRENDERSTATE_STIPPLEPATTERN00 + (y))
function D3DRENDERSTATE_STIPPLEPATTERN(y: Integer): TD3DRenderStateType;
begin
  Result := TD3DRenderStateType(Ord(D3DRENDERSTATE_STIPPLEPATTERN00) + y);
end;




    // Addition and subtraction
function VectorAdd(const v1, v2: TD3DVector): TD3DVector;
begin
  Result.x := v1.x+v2.x;
  Result.y := v1.y+v2.y;
  Result.z := v1.z+v2.z;
end;

function VectorSub(const v1, v2: TD3DVector): TD3DVector;
begin
  Result.x := v1.x-v2.x;
  Result.y := v1.y-v2.y;
  Result.z := v1.z-v2.z;
end;

    // Scalar multiplication and division
function VectorMulS(const v: TD3DVector; s: TD3DValue): TD3DVector;
begin
  Result.x := v.x*s;
  Result.y := v.y*s;
  Result.z := v.z*s;
end;

function VectorDivS(const v: TD3DVector; s: TD3DValue): TD3DVector;
begin
  Result.x := v.x/s;
  Result.y := v.y/s;
  Result.z := v.z/s;
end;

    // Memberwise multiplication and division
function VectorMul(const v1, v2: TD3DVector): TD3DVector;
begin
  Result.x := v1.x*v2.x;
  Result.y := v1.y*v2.y;
  Result.z := v1.z*v2.z;
end;

function VectorDiv(const v1, v2: TD3DVector): TD3DVector;
begin
  Result.x := v1.x/v2.x;
  Result.y := v1.y/v2.y;
  Result.z := v1.z/v2.z;
end;

    // Vector dominance
function VectorSmaller(v1, v2: TD3DVector): boolean;
begin
  result := (v1.x < v2.x) and (v1.y < v2.y) and (v1.z < v2.z);
end;

function VectorSmallerEqual(v1, v2: TD3DVector): boolean;
begin
  result := (v1.x <= v2.x) and (v1.y <= v2.y) and (v1.z <= v2.z);
end;

    // Bitwise equality
function VectorEqual(v1, v2: TD3DVector): boolean;
begin
  result := (v1.x = v2.x) and (v1.y = v2.y) and (v1.z = v2.z);
end;

    // Length-related functions
function VectorSquareMagnitude(v: TD3DVector): TD3DValue;
begin
  result := (v.x*v.x) + (v.y*v.y) + (v.z*v.z);
end;

function VectorMagnitude(v: TD3DVector): TD3DValue;
begin
  result := sqrt((v.x*v.x) + (v.y*v.y) + (v.z*v.z));
end;

    // Returns vector with same direction and unit length
function VectorNormalize(const v: TD3DVector): TD3DVector;
begin
  result := VectorDivS(v,VectorMagnitude(v));
end;

    // Return min/max component of the input vector
function VectorMin(v: TD3DVector): TD3DValue;
var
  ret : TD3DValue;
begin
  ret := v.x;
  if (v.y < ret) then ret := v.y;
  if (v.z < ret) then ret := v.z;
  Result := ret;
end;

function VectorMax(v: TD3DVector): TD3DValue;
var
  ret : TD3DValue;
begin
  ret := v.x;
  if (ret < v.y) then ret := v.y;
  if (ret < v.z) then ret := v.z;
  Result := ret;
end;

    // Return memberwise min/max of input vectors
function VectorMinimize(const v1, v2: TD3DVector): TD3DVector;
begin
  if v1.x < v2.x then Result.x := v1.x else Result.x := v2.x;
  if v1.y < v2.y then Result.y := v1.y else Result.y := v2.y;
  if v1.z < v2.z then Result.z := v1.z else Result.z := v2.z;
end;

function VectorMaximize(const v1, v2: TD3DVector): TD3DVector;
begin
  if v1.x > v2.x then Result.x := v1.x else Result.x := v2.x;
  if v1.y > v2.y then Result.y := v1.y else Result.y := v2.y;
  if v1.z > v2.z then Result.z := v1.z else Result.z := v2.z;
end;

    // Dot and cross product
function VectorDotProduct(v1, v2: TD3DVector): TD3DValue;
begin
  Result := (v1.x*v2.x) + (v1.y * v2.y) + (v1.z*v2.z);
end;

function VectorCrossProduct(const v1, v2: TD3DVector): TD3DVector;
begin
  Result.x := (v1.y*v2.z) - (v1.z*v2.y);
  Result.y := (v1.z*v2.x) - (v1.x*v2.z);
  Result.z := (v1.x*v2.y) - (v1.y*v2.x);
end;

procedure DisableFPUExceptions;
var
  FPUControlWord: Word;
asm
  FSTCW   FPUControlWord;
  OR      FPUControlWord, $4 + $1; { Divide by zero + invalid operation }
  FLDCW   FPUControlWord;
end;

procedure EnableFPUExceptions;
var
  FPUControlWord: Word;
asm
  FSTCW   FPUControlWord;
  AND     FPUControlWord, $FFFF - $4 - $1; { Divide by zero + invalid operation }
  FLDCW   FPUControlWord;
end;

{$IFDEF DIRECT3D_VERSION_LESS_8}
function D3DErrorString(Value: HResult): String; //Full description not available yet
begin
  case Value of
    D3D_OK: Result := 'No error';

    D3DERR_BADMAJORVERSION: Result := 'D3DERR_BADMAJORVERSION';
    D3DERR_BADMINORVERSION: Result := 'D3DERR_BADMINORVERSION';

  {$IFDEF DIRECT3D_VERSION_5}
    D3DERR_INVALID_DEVICE: Result := 'D3DERR_INITFAILED';
    D3DERR_INITFAILED: Result := 'D3DERR_INITFAILED';

    D3DERR_DEVICEAGGREGATED: Result := 'D3DERR_DEVICEAGGREGATED';
  {$ENDIF} // DIRECT3D_VERSION_5

    D3DERR_EXECUTE_CREATE_FAILED: Result := 'D3DERR_EXECUTE_CREATE_FAILED';
    D3DERR_EXECUTE_DESTROY_FAILED: Result := 'D3DERR_EXECUTE_DESTROY_FAILED';
    D3DERR_EXECUTE_LOCK_FAILED: Result := 'D3DERR_EXECUTE_LOCK_FAILED';
    D3DERR_EXECUTE_UNLOCK_FAILED: Result := 'D3DERR_EXECUTE_UNLOCK_FAILED';
    D3DERR_EXECUTE_LOCKED: Result := 'D3DERR_EXECUTE_LOCKED';
    D3DERR_EXECUTE_NOT_LOCKED: Result := 'D3DERR_EXECUTE_NOT_LOCKED';

    D3DERR_EXECUTE_FAILED: Result := 'D3DERR_EXECUTE_FAILED';
    D3DERR_EXECUTE_CLIPPED_FAILED: Result := 'D3DERR_EXECUTE_CLIPPED_FAILED';

    D3DERR_TEXTURE_NO_SUPPORT: Result := 'D3DERR_TEXTURE_NO_SUPPORT';
    D3DERR_TEXTURE_CREATE_FAILED: Result := 'D3DERR_TEXTURE_CREATE_FAILED';
    D3DERR_TEXTURE_DESTROY_FAILED: Result := 'D3DERR_TEXTURE_DESTROY_FAILED';
    D3DERR_TEXTURE_LOCK_FAILED: Result := 'D3DERR_TEXTURE_LOCK_FAILED';
    D3DERR_TEXTURE_UNLOCK_FAILED: Result := 'D3DERR_TEXTURE_UNLOCK_FAILED';
    D3DERR_TEXTURE_LOAD_FAILED: Result := 'D3DERR_TEXTURE_LOAD_FAILED';
    D3DERR_TEXTURE_SWAP_FAILED: Result := 'D3DERR_TEXTURE_SWAP_FAILED';
    D3DERR_TEXTURE_LOCKED: Result := 'D3DERR_TEXTURELOCKED';
    D3DERR_TEXTURE_NOT_LOCKED: Result := 'D3DERR_TEXTURE_NOT_LOCKED';
    D3DERR_TEXTURE_GETSURF_FAILED: Result := 'D3DERR_TEXTURE_GETSURF_FAILED';

    D3DERR_MATRIX_CREATE_FAILED: Result := 'D3DERR_MATRIX_CREATE_FAILED';
    D3DERR_MATRIX_DESTROY_FAILED: Result := 'D3DERR_MATRIX_DESTROY_FAILED';
    D3DERR_MATRIX_SETDATA_FAILED: Result := 'D3DERR_MATRIX_SETDATA_FAILED';
    D3DERR_MATRIX_GETDATA_FAILED: Result := 'D3DERR_MATRIX_GETDATA_FAILED';
    D3DERR_SETVIEWPORTDATA_FAILED: Result := 'D3DERR_SETVIEWPORTDATA_FAILED';

  {$IFDEF DIRECT3D_VERSION_5}
    D3DERR_INVALIDCURRENTVIEWPORT: Result := 'D3DERR_INVALIDCURRENTVIEWPORT';
    D3DERR_INVALIDPRIMITIVETYPE: Result := 'D3DERR_INVALIDPRIMITIVETYPE';
    D3DERR_INVALIDVERTEXTYPE: Result := 'D3DERR_INVALIDVERTEXTYPE';
    D3DERR_TEXTURE_BADSIZE: Result := 'D3DERR_TEXTURE_BADSIZE';
    D3DERR_INVALIDRAMPTEXTURE: Result := 'D3DERR_INVALIDRAMPTEXTURE';
  {$ENDIF} // DIRECT3D_VERSION_5

    D3DERR_MATERIAL_CREATE_FAILED: Result := 'D3DERR_MATERIAL_CREATE_FAILED';
    D3DERR_MATERIAL_DESTROY_FAILED: Result := 'D3DERR_MATERIAL_DESTROY_FAILED';
    D3DERR_MATERIAL_SETDATA_FAILED: Result := 'D3DERR_MATERIAL_SETDATA_FAILED';
    D3DERR_MATERIAL_GETDATA_FAILED: Result := 'D3DERR_MATERIAL_GETDATA_FAILED';

  {$IFDEF DIRECT3D_VERSION_5}
    D3DERR_INVALIDPALETTE: Result := 'D3DERR_INVALIDPALETTE';

    D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY: Result := 'D3DERR_ZBUFF_NEEDS_SYSTEMMEMORY';
    D3DERR_ZBUFF_NEEDS_VIDEOMEMORY: Result := 'D3DERR_ZBUFF_NEEDS_VIDEOMEMORY';
    D3DERR_SURFACENOTINVIDMEM: Result := 'D3DERR_SURFACENOTINVIDMEM';
  {$ENDIF} // DIRECT3D_VERSION_5

    D3DERR_LIGHT_SET_FAILED: Result := 'D3DERR_LIGHT_SET_FAILED';
  {$IFDEF DIRECT3D_VERSION_5}
    D3DERR_LIGHTHASVIEWPORT: Result := 'D3DERR_LIGHTHASVIEWPORT';
    D3DERR_LIGHTNOTINTHISVIEWPORT: Result := 'D3DERR_LIGHTNOTINTHISVIEWPORT';
  {$ENDIF} // DIRECT3D_VERSION_5

    D3DERR_SCENE_IN_SCENE: Result := 'D3DERR_SCENE_IN_SCENE';
    D3DERR_SCENE_NOT_IN_SCENE: Result := 'D3DERR_SCENE_NOT_IN_SCENE';
    D3DERR_SCENE_BEGIN_FAILED: Result := 'D3DERR_SCENE_BEGIN_FAILED';
    D3DERR_SCENE_END_FAILED: Result := 'D3DERR_SCENE_END_FAILED';

  {$IFDEF DIRECT3D_VERSION_5}
    D3DERR_INBEGIN: Result := 'D3DERR_INBEGIN';
    D3DERR_NOTINBEGIN: Result := 'D3DERR_NOTINBEGIN';
    D3DERR_NOVIEWPORTS: Result := 'D3DERR_NOVIEWPORTS';
    D3DERR_VIEWPORTDATANOTSET: Result := 'D3DERR_VIEWPORTDATANOTSET';
    D3DERR_VIEWPORTHASNODEVICE: Result := 'D3DERR_VIEWPORTHASNODEVICE';
    D3DERR_NOCURRENTVIEWPORT: Result := 'D3DERR_NOCURRENTVIEWPORT';
  {$ENDIF} // DIRECT3D_VERSION_5

  {$IFDEF DIRECT3D_VERSION_6}
    D3DERR_INVALIDVERTEXFORMAT: Result := 'D3DERR_INVALIDVERTEXFORMAT';

    D3DERR_COLORKEYATTACHED: Result := 'D3DERR_COLORKEYATTACHED';

    D3DERR_VERTEXBUFFEROPTIMIZED: Result := 'D3DERR_VERTEXBUFFEROPTIMIZED';
    D3DERR_VBUF_CREATE_FAILED: Result := 'D3DERR_VBUF_CREATE_FAILED';
    D3DERR_VERTEXBUFFERLOCKED: Result := 'D3DERR_VERTEXBUFFERLOCKED';

    D3DERR_ZBUFFER_NOTPRESENT: Result := 'D3DERR_ZBUFFER_NOTPRESENT';
    D3DERR_STENCILBUFFER_NOTPRESENT: Result := 'D3DERR_STENCILBUFFER_NOTPRESENT';

    D3DERR_WRONGTEXTUREFORMAT: Result := 'D3DERR_WRONGTEXTUREFORMAT';
    D3DERR_UNSUPPORTEDCOLOROPERATION: Result := 'D3DERR_UNSUPPORTEDCOLOROPERATION';
    D3DERR_UNSUPPORTEDCOLORARG: Result := 'D3DERR_UNSUPPORTEDCOLORARG';
    D3DERR_UNSUPPORTEDALPHAOPERATION: Result := 'D3DERR_UNSUPPORTEDALPHAOPERATION';
    D3DERR_UNSUPPORTEDALPHAARG: Result := 'D3DERR_UNSUPPORTEDALPHAARG';
    D3DERR_TOOMANYOPERATIONS: Result := 'D3DERR_TOOMANYOPERATIONS';
    D3DERR_CONFLICTINGTEXTUREFILTER: Result := 'D3DERR_CONFLICTINGTEXTUREFILTER';
    D3DERR_UNSUPPORTEDFACTORVALUE: Result := 'D3DERR_UNSUPPORTEDFACTORVALUE';

    D3DERR_CONFLICTINGRENDERSTATE: Result := 'D3DERR_CONFLICTINGRENDERSTATE';
    D3DERR_UNSUPPORTEDTEXTUREFILTER: Result := 'D3DERR_UNSUPPORTEDTEXTUREFILTER';
    D3DERR_TOOMANYPRIMITIVES: Result := 'D3DERR_TOOMANYPRIMITIVES';
    D3DERR_INVALIDMATRIX: Result := 'D3DERR_INVALIDMATRIX';
    D3DERR_TOOMANYVERTICES: Result := 'D3DERR_TOOMANYVERTICES';
    D3DERR_CONFLICTINGTEXTUREPALETTE: Result := 'D3DERR_CONFLICTINGTEXTUREPALETTE';
  {$ENDIF} // DIRECT3D_VERSION_6

  {$IFDEF DIRECT3D_VERSION_7}
    D3DERR_INVALIDSTATEBLOCK: Result := 'D3DERR_INVALIDSTATEBLOCK';
    D3DERR_INBEGINSTATEBLOCK: Result := 'D3DERR_INBEGINSTATEBLOCK';
    D3DERR_NOTINBEGINSTATEBLOCK: Result := 'D3DERR_NOTINBEGINSTATEBLOCK';
  {$ENDIF} // DIRECT3D_VERSION_7

    else Result := 'Unrecognized Error';
  end;
end;
{$ENDIF} // DIRECT3D_VERSION_LESS_8

{$IFNDEF EXCLUDE_DXFILE_FROM_DIRECT3D}

function DXFileErrorString(Value: HResult): string;
begin
  case Value of
    DXFILE_OK: Result := 'Command completed successfully. Equivalent to DD_OK.';
    DXFILEERR_BADVALUE: Result := 'Parameter is invalid.';
    DXFILEERR_BADTYPE: Result := 'Object type is invalid.';
    DXFILEERR_BADALLOC: Result := 'Memory allocation failed.';
    DXFILEERR_NOTFOUND: Result := 'Object could not be found.';
    DXFILEERR_FILENOTFOUND: Result := 'File could not be found.';
    DXFILEERR_RESOURCENOTFOUND: Result := 'Resource could not be found.';
    DXFILEERR_URLNOTFOUND: Result := 'URL could not be found.';
    DXFILEERR_BADRESOURCE: Result := 'Resource is invalid.';
    DXFILEERR_BADFILETYPE: Result := 'File is not a DirectX file.';
    DXFILEERR_BADFILEVERSION: Result := 'File version is not valid.';
    DXFILEERR_BADFILEFLOATSIZE: Result := 'Floating-point size is invalid.';
    DXFILEERR_BADFILE: Result := 'File is invalid.';
    DXFILEERR_PARSEERROR: Result := 'File could not be parsed.';
    DXFILEERR_BADARRAYSIZE: Result := 'Array size is invalid.';
    DXFILEERR_BADDATAREFERENCE: Result := 'Data reference is invalid.';
    DXFILEERR_NOMOREOBJECTS: Result := 'All objects have been enumerated.';
    DXFILEERR_NOMOREDATA: Result := 'No further data is available.';
    else Result := 'Unrecognized Error';
  end;
end;


initialization
begin
  DisableFPUExceptions;
  DXFileDLL := LoadLibrary('D3DXOF.DLL');
  DirectXFileCreate := GetProcAddress(DXFileDLL,'DirectXFileCreate');
end;

finalization
begin
  FreeLibrary(DXFileDLL);
end;

{$ENDIF}
end.