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.

596 lines
21 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // swprov.cpp
  4. //
  5. // Implements software rasterizer HAL provider.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #define nullPrimCaps \
  12. { \
  13. sizeof(D3DPRIMCAPS), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \
  14. }
  15. #define nullTransCaps \
  16. { \
  17. sizeof(D3DTRANSFORMCAPS), 0 \
  18. }
  19. #define nullLightCaps \
  20. { \
  21. sizeof(D3DLIGHTINGCAPS), 0, 0, 0 \
  22. }
  23. D3DDEVICEDESC7 g_nullDevDesc =
  24. {
  25. 0, /* dwDevCaps */
  26. nullPrimCaps, /* lineCaps */
  27. nullPrimCaps, /* triCaps */
  28. 0, /* dwMaxBufferSize */
  29. 0, /* dwMaxVertexCount */
  30. 0, 0,
  31. 0, 0,
  32. };
  33. //----------------------------------------------------------------------------
  34. //
  35. // RefHalProvider::QueryInterface
  36. //
  37. // Internal interface, no need to implement.
  38. //
  39. //----------------------------------------------------------------------------
  40. STDMETHODIMP RefHalProvider::QueryInterface(THIS_ REFIID riid, LPVOID* ppvObj)
  41. {
  42. *ppvObj = NULL;
  43. return E_NOINTERFACE;
  44. }
  45. //----------------------------------------------------------------------------
  46. //
  47. // RefHalProvider::AddRef
  48. //
  49. // Static implementation, no real refcount.
  50. //
  51. //----------------------------------------------------------------------------
  52. STDMETHODIMP_(ULONG) RefHalProvider::AddRef(THIS)
  53. {
  54. return 1;
  55. }
  56. //----------------------------------------------------------------------------
  57. //
  58. // RefHalProvider::Release
  59. //
  60. // Static implementation, no real refcount.
  61. //
  62. //----------------------------------------------------------------------------
  63. STDMETHODIMP_(ULONG) RefHalProvider::Release(THIS)
  64. {
  65. return 0;
  66. }
  67. //----------------------------------------------------------------------------
  68. //
  69. // GetRefHALProvider
  70. //
  71. // Returns the appropriate reference software HAL provider based on the given
  72. // GUID.
  73. //
  74. //----------------------------------------------------------------------------
  75. static RefRastHalProvider g_RefRastHalProvider;
  76. static NullDeviceHalProvider g_NullDeviceHalProvider;
  77. STDAPI GetRefHalProvider(REFIID riid, IHalProvider **ppHalProvider,
  78. HINSTANCE *phDll)
  79. {
  80. *phDll = NULL;
  81. if (IsEqualIID(riid, IID_IDirect3DRefDevice))
  82. {
  83. *ppHalProvider = &g_RefRastHalProvider;
  84. }
  85. else if (IsEqualIID(riid, IID_IDirect3DNullDevice))
  86. {
  87. *ppHalProvider = &g_NullDeviceHalProvider;
  88. }
  89. else
  90. {
  91. *ppHalProvider = NULL;
  92. return E_NOINTERFACE;
  93. }
  94. return S_OK;
  95. }
  96. //----------------------------------------------------------------------------
  97. //
  98. // TextureFormats
  99. //
  100. // Returns all the texture formats supported by our rasterizer.
  101. // Right now, it's called at device creation time to fill the driver gloabl
  102. // data.
  103. //
  104. //----------------------------------------------------------------------------
  105. #define NUM_SUPPORTED_TEXTURE_FORMATS 28
  106. STDAPI
  107. GetRefTextureFormats(REFCLSID riid, LPDDSURFACEDESC* lplpddsd,
  108. DWORD dwVersion)
  109. {
  110. int i = 0;
  111. static DDSURFACEDESC ddsd_RefNull_Dev3[NUM_SUPPORTED_TEXTURE_FORMATS];
  112. static DDSURFACEDESC ddsd_RefNull_Dev2[NUM_SUPPORTED_TEXTURE_FORMATS];
  113. DDSURFACEDESC *ddsd;
  114. if (dwVersion >= 3)
  115. {
  116. ddsd = ddsd_RefNull_Dev3;
  117. }
  118. else
  119. {
  120. ddsd = ddsd_RefNull_Dev2;
  121. }
  122. /* 888 */
  123. ddsd[i].dwSize = sizeof(ddsd[0]);
  124. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  125. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  126. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  127. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  128. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 32;
  129. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xff0000;
  130. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00ff00;
  131. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0000ff;
  132. i++;
  133. /* 8888 */
  134. ddsd[i].dwSize = sizeof(ddsd[0]);
  135. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  136. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  137. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  138. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  139. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 32;
  140. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xff000000;
  141. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xff0000;
  142. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00ff00;
  143. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0000ff;
  144. i++;
  145. /* 565 */
  146. ddsd[i].dwSize = sizeof(ddsd[0]);
  147. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  148. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  149. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  150. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  151. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  152. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xf800;
  153. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x07e0;
  154. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  155. i++;
  156. /* 555 */
  157. ddsd[i].dwSize = sizeof(ddsd[0]);
  158. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  159. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  160. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  161. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  162. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  163. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x7c00;
  164. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x03e0;
  165. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  166. i++;
  167. /* pal4 */
  168. ddsd[i].dwSize = sizeof(ddsd[0]);
  169. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  170. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  171. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  172. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED4 | DDPF_RGB;
  173. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 4;
  174. i++;
  175. /* pal8 */
  176. ddsd[i].dwSize = sizeof(ddsd[0]);
  177. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  178. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  179. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  180. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_PALETTEINDEXED8 | DDPF_RGB;
  181. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  182. i++;
  183. /* 1555 */
  184. ddsd[i].dwSize = sizeof(ddsd[0]);
  185. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  186. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  187. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  188. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  189. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  190. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0x8000;
  191. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x7c00;
  192. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x03e0;
  193. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x001f;
  194. i++;
  195. // A formats for PC98 consistency
  196. // 4444 ARGB (it is already supported by S3 Virge)
  197. ddsd[i].dwSize = sizeof(ddsd[0]);
  198. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  199. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  200. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  201. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  202. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  203. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xf000;
  204. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x0f00;
  205. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00f0;
  206. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x000f;
  207. i++;
  208. if (dwVersion >= 2)
  209. {
  210. // 332 8-bit RGB
  211. ddsd[i].dwSize = sizeof(ddsd[0]);
  212. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  213. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  214. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  215. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  216. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 8;
  217. ddsd[i].ddpfPixelFormat.dwRBitMask = 0xe0;
  218. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x1c;
  219. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x03;
  220. i++;
  221. }
  222. if (dwVersion >= 3)
  223. {
  224. /* 8 bit luminance-only */
  225. ddsd[i].dwSize = sizeof(ddsd[0]);
  226. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  227. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  228. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  229. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_LUMINANCE;
  230. ddsd[i].ddpfPixelFormat.dwLuminanceBitCount = 8;
  231. ddsd[i].ddpfPixelFormat.dwLuminanceBitMask = 0xff;
  232. i++;
  233. /* 16 bit alpha-luminance */
  234. ddsd[i].dwSize = sizeof(ddsd[0]);
  235. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  236. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  237. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  238. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_LUMINANCE | DDPF_ALPHAPIXELS;
  239. ddsd[i].ddpfPixelFormat.dwLuminanceBitCount = 16;
  240. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xff00;
  241. ddsd[i].ddpfPixelFormat.dwLuminanceBitMask = 0xff;
  242. i++;
  243. // A couple of formats for PC98 consistency
  244. // UYVY
  245. ddsd[i].dwSize = sizeof(ddsd[0]);
  246. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  247. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  248. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  249. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  250. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('U', 'Y', 'V', 'Y');
  251. i++;
  252. // YVY2
  253. ddsd[i].dwSize = sizeof(ddsd[0]);
  254. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  255. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  256. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  257. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  258. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y', 'U', 'Y', '2');
  259. i++;
  260. // S3 compressed texture format 1
  261. ddsd[i].dwSize = sizeof(ddsd[0]);
  262. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  263. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  264. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  265. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  266. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '1');
  267. i++;
  268. // S3 compressed texture format 2
  269. ddsd[i].dwSize = sizeof(ddsd[0]);
  270. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  271. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  272. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  273. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  274. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '2');
  275. i++;
  276. // S3 compressed texture format 3
  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_FOURCC;
  282. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '3');
  283. i++;
  284. // S3 compressed texture format 4
  285. ddsd[i].dwSize = sizeof(ddsd[0]);
  286. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  287. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  288. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  289. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  290. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '4');
  291. i++;
  292. // S3 compressed texture format 5
  293. ddsd[i].dwSize = sizeof(ddsd[0]);
  294. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  295. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  296. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  297. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_FOURCC;
  298. ddsd[i].ddpfPixelFormat.dwFourCC = MAKEFOURCC('D', 'X', 'T', '5');
  299. i++;
  300. // Add a few bump map formats
  301. // U8V8
  302. ddsd[i].dwSize = sizeof(ddsd[0]);
  303. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  304. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  305. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  306. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV;
  307. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 16;
  308. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x00ff;
  309. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0xff00;
  310. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0x0;
  311. i++;
  312. // U5V5L6
  313. ddsd[i].dwSize = sizeof(ddsd[0]);
  314. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  315. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  316. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  317. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV |
  318. DDPF_BUMPLUMINANCE;
  319. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 16;
  320. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x001f;
  321. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0x03e0;
  322. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0xfc00;
  323. i++;
  324. // U8V8L8
  325. ddsd[i].dwSize = sizeof(ddsd[0]);
  326. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  327. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  328. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  329. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_BUMPDUDV |
  330. DDPF_BUMPLUMINANCE;
  331. ddsd[i].ddpfPixelFormat.dwBumpBitCount = 24;
  332. ddsd[i].ddpfPixelFormat.dwBumpDuBitMask = 0x0000ff;
  333. ddsd[i].ddpfPixelFormat.dwBumpDvBitMask = 0x00ff00;
  334. ddsd[i].ddpfPixelFormat.dwBumpLuminanceBitMask = 0xff0000;
  335. i++;
  336. /* 8 bit alpha-luminance */
  337. ddsd[i].dwSize = sizeof(ddsd[0]);
  338. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  339. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  340. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  341. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_LUMINANCE | DDPF_ALPHAPIXELS;
  342. ddsd[i].ddpfPixelFormat.dwLuminanceBitCount = 8;
  343. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xf0;
  344. ddsd[i].ddpfPixelFormat.dwLuminanceBitMask = 0x0f;
  345. i++;
  346. // 8332 16-bit ARGB
  347. ddsd[i].dwSize = sizeof(ddsd[0]);
  348. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  349. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  350. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  351. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
  352. ddsd[i].ddpfPixelFormat.dwRGBBitCount = 16;
  353. ddsd[i].ddpfPixelFormat.dwRGBAlphaBitMask = 0xff00;
  354. ddsd[i].ddpfPixelFormat.dwRBitMask = 0x00e0;
  355. ddsd[i].ddpfPixelFormat.dwGBitMask = 0x001c;
  356. ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0003;
  357. i++;
  358. #if 0
  359. // for Shadow Buffer prototype API
  360. // Z16S0 16 bit Z buffer format for shadow buffer
  361. ddsd[i].dwSize = sizeof(ddsd[0]);
  362. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  363. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
  364. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  365. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
  366. ddsd[i].ddpfPixelFormat.dwZBufferBitDepth = 16;
  367. ddsd[i].ddpfPixelFormat.dwStencilBitDepth = 0;
  368. ddsd[i].ddpfPixelFormat.dwZBitMask = 0xffff;
  369. ddsd[i].ddpfPixelFormat.dwStencilBitMask = 0x0000;
  370. i++;
  371. // Z24S8 16 bit Z buffer format for shadow buffer
  372. ddsd[i].dwSize = sizeof(ddsd[0]);
  373. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  374. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
  375. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  376. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
  377. ddsd[i].ddpfPixelFormat.dwZBufferBitDepth = 32;
  378. ddsd[i].ddpfPixelFormat.dwStencilBitDepth = 8;
  379. ddsd[i].ddpfPixelFormat.dwZBitMask = 0xffffff00;
  380. ddsd[i].ddpfPixelFormat.dwStencilBitMask = 0x000000ff;
  381. i++;
  382. // Z15S1 16 bit Z buffer format for shadow buffer
  383. ddsd[i].dwSize = sizeof(ddsd[0]);
  384. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  385. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
  386. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  387. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
  388. ddsd[i].ddpfPixelFormat.dwZBufferBitDepth = 16;
  389. ddsd[i].ddpfPixelFormat.dwStencilBitDepth = 1;
  390. ddsd[i].ddpfPixelFormat.dwZBitMask = 0xfffe;
  391. ddsd[i].ddpfPixelFormat.dwStencilBitMask = 0x0001;
  392. i++;
  393. // Z32S0 16 bit Z buffer format for shadow buffer
  394. ddsd[i].dwSize = sizeof(ddsd[0]);
  395. ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  396. ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
  397. ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  398. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_ZBUFFER;
  399. ddsd[i].ddpfPixelFormat.dwZBufferBitDepth = 32;
  400. ddsd[i].ddpfPixelFormat.dwStencilBitDepth = 0;
  401. ddsd[i].ddpfPixelFormat.dwZBitMask = 0xffffffff;
  402. ddsd[i].ddpfPixelFormat.dwStencilBitMask = 0x00000000;
  403. i++;
  404. #endif
  405. }
  406. *lplpddsd = ddsd;
  407. return i;
  408. }
  409. #define NUM_SUPPORTED_ZBUFFER_FORMATS 8
  410. //----------------------------------------------------------------------------
  411. //
  412. // GetRefZBufferFormats
  413. //
  414. // Must return union of all the Z buffer formats supported by all rasterizers.
  415. // CreateDevice will screen out device-specific ones (i.e. ones ramp doesnt handle) later.
  416. // Called at device creation time and by DDHEL to validate software ZBuffer
  417. // creation.
  418. //
  419. //----------------------------------------------------------------------------
  420. STDAPI
  421. GetRefZBufferFormats(REFCLSID riid, DDPIXELFORMAT **ppDDPF)
  422. {
  423. static DDPIXELFORMAT DDPF[NUM_SUPPORTED_ZBUFFER_FORMATS];
  424. int i = 0;
  425. memset(&DDPF[0],0,sizeof(DDPF));
  426. /* 16 bit Z; no stencil */
  427. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  428. DDPF[i].dwFlags = DDPF_ZBUFFER;
  429. DDPF[i].dwZBufferBitDepth = 16;
  430. DDPF[i].dwStencilBitDepth = 0;
  431. DDPF[i].dwZBitMask = 0xffff;
  432. DDPF[i].dwStencilBitMask = 0x0000;
  433. i++;
  434. /* 24 bit Z; 8 bit stencil */
  435. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  436. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  437. DDPF[i].dwZBufferBitDepth = 32; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  438. DDPF[i].dwStencilBitDepth = 8;
  439. DDPF[i].dwZBitMask = 0xffffff00;
  440. DDPF[i].dwStencilBitMask = 0x000000ff;
  441. i++;
  442. /* 15 bit Z; 1 bit stencil */
  443. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  444. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  445. DDPF[i].dwZBufferBitDepth = 16; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  446. DDPF[i].dwStencilBitDepth = 1;
  447. DDPF[i].dwZBitMask = 0xfffe;
  448. DDPF[i].dwStencilBitMask = 0x0001;
  449. i++;
  450. /* 32bit Z; no stencil */
  451. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  452. DDPF[i].dwFlags = DDPF_ZBUFFER;
  453. DDPF[i].dwZBufferBitDepth = 32;
  454. DDPF[i].dwStencilBitDepth = 0;
  455. DDPF[i].dwZBitMask = 0xffffffff;
  456. DDPF[i].dwStencilBitMask = 0x00000000;
  457. i++;
  458. /* 8 bit stencil; 24 bit Z */
  459. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  460. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  461. DDPF[i].dwZBufferBitDepth = 32; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  462. DDPF[i].dwStencilBitDepth = 8;
  463. DDPF[i].dwZBitMask = 0x00ffffff;
  464. DDPF[i].dwStencilBitMask = 0xff000000;
  465. i++;
  466. /* 1 bit stencil; 15 bit Z */
  467. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  468. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  469. DDPF[i].dwZBufferBitDepth = 16; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  470. DDPF[i].dwStencilBitDepth = 1;
  471. DDPF[i].dwZBitMask = 0x7fff;
  472. DDPF[i].dwStencilBitMask = 0x8000;
  473. i++;
  474. /* 24 bit Z; 4 bit stencil */
  475. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  476. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  477. DDPF[i].dwZBufferBitDepth = 32; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  478. DDPF[i].dwStencilBitDepth = 4;
  479. DDPF[i].dwZBitMask = 0xffffff00;
  480. DDPF[i].dwStencilBitMask = 0x0000000f;
  481. i++;
  482. /* 4 bit stencil; 24 bit Z */
  483. DDPF[i].dwSize = sizeof(DDPIXELFORMAT);
  484. DDPF[i].dwFlags = DDPF_ZBUFFER | DDPF_STENCILBUFFER;
  485. DDPF[i].dwZBufferBitDepth = 32; // ZBufferBitDepth represents the total bits. Z Bits are ZBBitDepth-StencilBitDepth
  486. DDPF[i].dwStencilBitDepth = 4;
  487. DDPF[i].dwZBitMask = 0x00ffffff;
  488. DDPF[i].dwStencilBitMask = 0x0f000000;
  489. i++;
  490. *ppDDPF = DDPF;
  491. return i;
  492. }