Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
21 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // d3dif.cpp
  4. //
  5. // shared interface functions
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. //----------------------------------------------------------------------------
  13. //
  14. // FindOutSurfFormat
  15. //
  16. // Converts a DDPIXELFORMAT to D3DI_SPANTEX_FORMAT.
  17. //
  18. //----------------------------------------------------------------------------
  19. HRESULT FASTCALL
  20. FindOutSurfFormat(LPDDPIXELFORMAT pDdPixFmt,
  21. D3DI_SPANTEX_FORMAT *pFmt)
  22. {
  23. if (pDdPixFmt->dwFlags & DDPF_ZBUFFER)
  24. {
  25. switch(pDdPixFmt->dwZBitMask)
  26. {
  27. default:
  28. case 0x0000FFFF: *pFmt = D3DI_SPTFMT_Z16S0; break;
  29. case 0xFFFFFF00: *pFmt = D3DI_SPTFMT_Z24S8; break;
  30. case 0x0000FFFE: *pFmt = D3DI_SPTFMT_Z15S1; break;
  31. case 0xFFFFFFFF: *pFmt = D3DI_SPTFMT_Z32S0; break;
  32. }
  33. }
  34. else if (pDdPixFmt->dwFlags & DDPF_BUMPDUDV)
  35. {
  36. UINT uFmt = pDdPixFmt->dwBumpDvBitMask;
  37. switch (uFmt)
  38. {
  39. case 0x0000ff00:
  40. switch (pDdPixFmt->dwRGBBitCount)
  41. {
  42. case 24:
  43. *pFmt = D3DI_SPTFMT_U8V8L8;
  44. break;
  45. case 16:
  46. *pFmt = D3DI_SPTFMT_U8V8;
  47. break;
  48. }
  49. break;
  50. case 0x000003e0:
  51. *pFmt = D3DI_SPTFMT_U5V5L6;
  52. break;
  53. }
  54. }
  55. else if (pDdPixFmt->dwFlags & DDPF_PALETTEINDEXED8)
  56. {
  57. *pFmt = D3DI_SPTFMT_PALETTE8;
  58. }
  59. else if (pDdPixFmt->dwFlags & DDPF_PALETTEINDEXED4)
  60. {
  61. *pFmt = D3DI_SPTFMT_PALETTE4;
  62. }
  63. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('U', 'Y', 'V', 'Y'))
  64. {
  65. *pFmt = D3DI_SPTFMT_UYVY;
  66. }
  67. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('Y', 'U', 'Y', '2'))
  68. {
  69. *pFmt = D3DI_SPTFMT_YUY2;
  70. }
  71. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '1'))
  72. {
  73. *pFmt = D3DI_SPTFMT_DXT1;
  74. }
  75. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '2'))
  76. {
  77. *pFmt = D3DI_SPTFMT_DXT2;
  78. }
  79. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '3'))
  80. {
  81. *pFmt = D3DI_SPTFMT_DXT3;
  82. }
  83. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '4'))
  84. {
  85. *pFmt = D3DI_SPTFMT_DXT4;
  86. }
  87. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '5'))
  88. {
  89. *pFmt = D3DI_SPTFMT_DXT5;
  90. }
  91. else
  92. {
  93. UINT uFmt = pDdPixFmt->dwGBitMask | pDdPixFmt->dwRBitMask;
  94. if (pDdPixFmt->dwFlags & DDPF_ALPHAPIXELS)
  95. {
  96. uFmt |= pDdPixFmt->dwRGBAlphaBitMask;
  97. }
  98. switch (uFmt)
  99. {
  100. case 0x00ffff00:
  101. switch (pDdPixFmt->dwRGBBitCount)
  102. {
  103. case 32:
  104. *pFmt = D3DI_SPTFMT_B8G8R8X8;
  105. break;
  106. case 24:
  107. *pFmt = D3DI_SPTFMT_B8G8R8;
  108. break;
  109. }
  110. break;
  111. case 0xffffff00:
  112. *pFmt = D3DI_SPTFMT_B8G8R8A8;
  113. break;
  114. case 0xffe0:
  115. if (pDdPixFmt->dwFlags & DDPF_ALPHAPIXELS)
  116. {
  117. *pFmt = D3DI_SPTFMT_B5G5R5A1;
  118. }
  119. else
  120. {
  121. *pFmt = D3DI_SPTFMT_B5G6R5;
  122. }
  123. break;
  124. case 0x07fe0:
  125. *pFmt = D3DI_SPTFMT_B5G5R5;
  126. break;
  127. case 0xff0:
  128. *pFmt = D3DI_SPTFMT_B4G4R4;
  129. break;
  130. case 0xfff0:
  131. *pFmt = D3DI_SPTFMT_B4G4R4A4;
  132. break;
  133. case 0xff:
  134. *pFmt = D3DI_SPTFMT_L8;
  135. break;
  136. case 0xffff:
  137. *pFmt = D3DI_SPTFMT_L8A8;
  138. break;
  139. case 0xfc:
  140. *pFmt = D3DI_SPTFMT_B2G3R3;
  141. break;
  142. default:
  143. *pFmt = D3DI_SPTFMT_NULL;
  144. break;
  145. }
  146. }
  147. return D3D_OK;
  148. }
  149. //----------------------------------------------------------------------------
  150. //
  151. // ValidTextureSize
  152. //
  153. // checks for power of two texture size
  154. //
  155. //----------------------------------------------------------------------------
  156. BOOL FASTCALL
  157. ValidTextureSize(INT16 iuSize, INT16 iuShift,
  158. INT16 ivSize, INT16 ivShift)
  159. {
  160. if (iuSize == 1)
  161. {
  162. if (ivSize == 1)
  163. {
  164. return TRUE;
  165. }
  166. else
  167. {
  168. return !(ivSize & (~(1 << ivShift)));
  169. }
  170. }
  171. else
  172. {
  173. if (ivSize == 1)
  174. {
  175. return !(iuSize & (~(1 << iuShift)));
  176. }
  177. else
  178. {
  179. return (!(iuSize & (~(1 << iuShift)))
  180. && !(iuSize & (~(1 << iuShift))));
  181. }
  182. }
  183. }
  184. //----------------------------------------------------------------------------
  185. //
  186. // ValidMipmapSize
  187. //
  188. // Computes size of next smallest mipmap level, clamping at 1
  189. //
  190. //----------------------------------------------------------------------------
  191. BOOL FASTCALL
  192. ValidMipmapSize(INT16 iPreSize, INT16 iSize)
  193. {
  194. if (iPreSize == 1)
  195. {
  196. if (iSize == 1)
  197. {
  198. return TRUE;
  199. }
  200. else
  201. {
  202. return FALSE;
  203. }
  204. }
  205. else
  206. {
  207. return ((iPreSize >> 1) == iSize);
  208. }
  209. }
  210. //----------------------------------------------------------------------------
  211. //
  212. // TextureFormats
  213. //
  214. // Returns all the texture formats supported by our rasterizer.
  215. // Right now, it's called at device creation time to fill the driver gloabl
  216. // data.
  217. //
  218. //----------------------------------------------------------------------------
  219. #define NUM_SUPPORTED_TEXTURE_FORMATS 22
  220. int
  221. TextureFormats(LPDDSURFACEDESC* lplpddsd, DWORD dwVersion, SW_RAST_TYPE RastType)
  222. {
  223. int i = 0;
  224. if (RastType == SW_RAST_MMX && dwVersion < 3)
  225. {
  226. static DDSURFACEDESC mmx_ddsd[1];
  227. /* pal8 */
  228. mmx_ddsd[i].dwSize = sizeof(mmx_ddsd[0]);
  229. mmx_ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  230. mmx_ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  231. mmx_ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  232. mmx_ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
  233. mmx_ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  234. i++;
  235. *lplpddsd = mmx_ddsd;
  236. return i;
  237. }
  238. static DDSURFACEDESC ddsd_RefNull_Dev3[NUM_SUPPORTED_TEXTURE_FORMATS];
  239. static DDSURFACEDESC ddsd_RefNull_Dev2[NUM_SUPPORTED_TEXTURE_FORMATS];
  240. static DDSURFACEDESC ddsd_RGBMMX_Dev3[NUM_SUPPORTED_TEXTURE_FORMATS];
  241. static DDSURFACEDESC ddsd_RGBMMX_Dev2[NUM_SUPPORTED_TEXTURE_FORMATS];
  242. DDSURFACEDESC *ddsd;
  243. if (RastType == SW_RAST_REFNULL)
  244. {
  245. if (dwVersion >= 3)
  246. {
  247. ddsd = ddsd_RefNull_Dev3;
  248. }
  249. else
  250. {
  251. ddsd = ddsd_RefNull_Dev2;
  252. }
  253. }
  254. else
  255. {
  256. if (dwVersion >= 3)
  257. {
  258. ddsd = ddsd_RGBMMX_Dev3;
  259. }
  260. else
  261. {
  262. ddsd = ddsd_RGBMMX_Dev2;
  263. }
  264. }
  265. /* 888 */
  266. ddsd[i].dwSize = sizeof(ddsd[0]);
  267. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  268. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  269. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  270. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  271. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 32;
  272. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xff0000;
  273. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00ff00;
  274. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0000ff;
  275. i++;
  276. /* 8888 */
  277. ddsd[i].dwSize = sizeof(ddsd[0]);
  278. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  279. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  280. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  281. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  282. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 32;
  283. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
  284. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xff0000;
  285. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00ff00;
  286. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0000ff;
  287. i++;
  288. /* 565 */
  289. ddsd[i].dwSize = sizeof(ddsd[0]);
  290. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  291. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  292. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  293. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  294. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  295. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xf800;
  296. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x07e0;
  297. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  298. i++;
  299. /* 555 */
  300. ddsd[i].dwSize = sizeof(ddsd[0]);
  301. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  302. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  303. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  304. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  305. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  306. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x7c00;
  307. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x03e0;
  308. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  309. i++;
  310. /* pal4 */
  311. ddsd[i].dwSize = sizeof(ddsd[0]);
  312. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  313. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  314. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  315. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
  316. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 4;
  317. i++;
  318. /* pal8 */
  319. ddsd[i].dwSize = sizeof(ddsd[0]);
  320. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  321. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  322. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  323. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
  324. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  325. i++;
  326. if ((dwVersion >= 3) || (RastType == SW_RAST_REFNULL))
  327. {
  328. /* 1555 */
  329. ddsd[i].dwSize = sizeof(ddsd[0]);
  330. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  331. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  332. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  333. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  334. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  335. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0x8000;
  336. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x7c00;
  337. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x03e0;
  338. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  339. i++;
  340. // A formats for PC98 consistency
  341. // 4444 ARGB (it is already supported by S3 Virge)
  342. ddsd[i].dwSize = sizeof(ddsd[0]);
  343. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  344. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  345. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  346. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  347. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  348. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xf000;
  349. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x0f00;
  350. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00f0;
  351. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x000f;
  352. i++;
  353. }
  354. if ((dwVersion >= 2) && (RastType == SW_RAST_REFNULL))
  355. {
  356. // 332 8-bit RGB
  357. ddsd[i].dwSize = sizeof(ddsd[0]);
  358. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  359. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  360. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  361. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  362. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  363. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xe0;
  364. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x1c;
  365. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x03;
  366. i++;
  367. }
  368. if (dwVersion >= 3)
  369. {
  370. /* 8 bit luminance-only */
  371. ddsd[i].dwSize = sizeof(ddsd[0]);
  372. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  373. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  374. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  375. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_LUMINANCE;
  376. ddsd[i].ddpfPixelFormat.dwLuminanceBitCount = 8;
  377. ddsd[i].ddpfPixelFormat.dwLuminanceBitMask = 0xff;
  378. i++;
  379. /* 16 bit alpha-luminance */
  380. ddsd[i].dwSize = sizeof(ddsd[0]);
  381. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  382. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  383. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  384. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_LUMINANCE | DDPF_ALPHAPIXELS;
  385. ddsd[i].ddpfPixelFormat.dwLuminanceBitCount = 16;
  386. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xff00;
  387. ddsd[i].ddpfPixelFormat.dwLuminanceBitMask = 0xff;
  388. i++;
  389. if (RastType == SW_RAST_REFNULL)
  390. {
  391. // A couple of formats for PC98 consistency
  392. // UYVY
  393. ddsd[i].dwSize = sizeof(ddsd[0]);
  394. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  395. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  396. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  397. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  398. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('U', 'Y', 'V', 'Y');
  399. i++;
  400. // YVY2
  401. ddsd[i].dwSize = sizeof(ddsd[0]);
  402. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  403. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  404. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  405. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  406. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y', 'U', 'Y', '2');
  407. i++;
  408. // S3 compressed texture format 1
  409. ddsd[i].dwSize = sizeof(ddsd[0]);
  410. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  411. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  412. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  413. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  414. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '1');
  415. i++;
  416. // S3 compressed texture format 2
  417. ddsd[i].dwSize = sizeof(ddsd[0]);
  418. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  419. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  420. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  421. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  422. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '2');
  423. i++;
  424. // S3 compressed texture format 3
  425. ddsd[i].dwSize = sizeof(ddsd[0]);
  426. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  427. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  428. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  429. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  430. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '3');
  431. i++;
  432. // S3 compressed texture format 4
  433. ddsd[i].dwSize = sizeof(ddsd[0]);
  434. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  435. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  436. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  437. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  438. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '4');
  439. i++;
  440. // S3 compressed texture format 5
  441. ddsd[i].dwSize = sizeof(ddsd[0]);
  442. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  443. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  444. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  445. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  446. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '5');
  447. i++;
  448. // Add a few bump map formats
  449. // U8V8
  450. ddsd[i].dwSize = sizeof(ddsd[0]);
  451. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  452. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  453. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  454. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV;
  455. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 16;
  456. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x00ff;
  457. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0xff00;
  458. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0x0;
  459. i++;
  460. // U5V5L6
  461. ddsd[i].dwSize = sizeof(ddsd[0]);
  462. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  463. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  464. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  465. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV |
  466. DDPF_BUMPLUMINANCE;
  467. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 16;
  468. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x001f;
  469. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0x03e0;
  470. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0xfc00;
  471. i++;
  472. // U8V8L8
  473. ddsd[i].dwSize = sizeof(ddsd[0]);
  474. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  475. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  476. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  477. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV |
  478. DDPF_BUMPLUMINANCE;
  479. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 24;
  480. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x0000ff;
  481. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0x00ff00;
  482. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0xff0000;
  483. i++;
  484. }
  485. }
  486. *lplpddsd = ddsd;
  487. return i;
  488. }
  489. //----------------------------------------------------------------------------
  490. //
  491. // ZBufferFormats
  492. //
  493. // Must return union of all the Z buffer formats supported by all rasterizers.
  494. // CreateDevice will screen out device-specific ones (i.e. ones ramp doesnt handle) later.
  495. // Called at device creation time and by DDHEL to validate software ZBuffer
  496. // creation.
  497. //
  498. //----------------------------------------------------------------------------
  499. #define NUM_SUPPORTED_ZBUFFER_FORMATS 4
  500. int
  501. ZBufferFormats(DDPIXELFORMAT** ppDDPF, BOOL bIsRefOrNull)
  502. {
  503. static DDPIXELFORMAT DDPF[NUM_SUPPORTED_ZBUFFER_FORMATS];
  504. int i = 0;
  505. memset(&DDPF[0],0,sizeof(DDPF));
  506. /* 16 bit Z; no stencil */
  507. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  508. DDPF[i].dwFlags = DDPF_ZBUFFER;
  509. DDPF[i].dwZBufferBitDepth = 16;
  510. DDPF[i].dwStencilBitDepth = 0;
  511. DDPF[i].dwZBitMask = 0xffff;
  512. DDPF[i].dwStencilBitMask = 0x0000;
  513. i++;
  514. /* 24 bit Z; 8 bit stencil */
  515. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  516. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  517. DDPF[i].dwZBufferBitDepth = 32; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  518. DDPF[i].dwStencilBitDepth = 8;
  519. DDPF[i].dwZBitMask = 0xffffff00;
  520. DDPF[i].dwStencilBitMask = 0x000000ff;
  521. i++;
  522. if (bIsRefOrNull)
  523. {
  524. /* 15 bit Z; 1 bit stencil */
  525. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  526. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  527. DDPF[i].dwZBufferBitDepth = 16; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  528. DDPF[i].dwStencilBitDepth = 1;
  529. DDPF[i].dwZBitMask = 0xfffe;
  530. DDPF[i].dwStencilBitMask = 0x0001;
  531. i++;
  532. /* 32bit Z; no stencil */
  533. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  534. DDPF[i].dwFlags = DDPF_ZBUFFER;
  535. DDPF[i].dwZBufferBitDepth = 32;
  536. DDPF[i].dwStencilBitDepth = 0;
  537. DDPF[i].dwZBitMask = 0xffffffff;
  538. DDPF[i].dwStencilBitMask = 0x00000000;
  539. i++;
  540. }
  541. *ppDDPF = DDPF;
  542. return i;
  543. }
  544. // this fn is exported externally to be called by the directdraw HEL
  545. DWORD WINAPI Direct3DGetSWRastZPixFmts(DDPIXELFORMAT** ppDDPF)
  546. {
  547. // try to get texture formats from external DLL ref device
  548. PFNGETREFZBUFFERFORMATS pfnGetRefZBufferFormats;
  549. if (NULL != (pfnGetRefZBufferFormats =
  550. (PFNGETREFZBUFFERFORMATS)LoadReferenceDeviceProc("GetRefZBufferFormats")))
  551. {
  552. D3D_INFO(0,"Direct3DGetSWRastZPixFmts: getting Z buffer formats from d3dref");
  553. return pfnGetRefZBufferFormats(IID_IDirect3DRefDevice, ppDDPF);
  554. }
  555. // always return all formats so DDraw creates
  556. // all surfaces which it should
  557. return (DWORD) ZBufferFormats(ppDDPF, TRUE);
  558. }