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.

1801 lines
55 KiB

  1. /*
  2. ** Copyright 1991, 1992, 1993, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #ifdef _MCD_
  20. void FASTCALL GenMcdClearDepthNOP(__GLdepthBuffer *dfb);
  21. /******************************Public*Routine******************************\
  22. * GenMcdReadZSpan
  23. *
  24. * Read specified span (starting from (x,y) and cx pels wide) of the depth
  25. * buffer. The read span is in the pMcdSurf->pDepthSpan buffer.
  26. *
  27. * Returns:
  28. * First depth value in the span.
  29. *
  30. * History:
  31. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  32. * Adpated from gendepth.c (3dddi).
  33. \**************************************************************************/
  34. __GLzValue GenMcdReadZSpan(__GLdepthBuffer *fb, GLint x, GLint y, GLint cx)
  35. {
  36. GENMCDSTATE *pMcdState;
  37. GENMCDSURFACE *pMcdSurf;
  38. LONG i;
  39. ULONG *pDest;
  40. ULONG shiftVal;
  41. ULONG maskVal;
  42. pMcdState = ((__GLGENcontext *)fb->buf.gc)->pMcdState;
  43. ASSERTOPENGL(pMcdState, "GenMcdReadZSpan: null pMcdState\n");
  44. pMcdSurf = pMcdState->pMcdSurf;
  45. ASSERTOPENGL(pMcdSurf, "GenMcdReadZSpan: null pMcdSurf\n");
  46. // Read MCD depth span.
  47. if ( !(gpMcdTable->pMCDReadSpan)(&pMcdState->McdContext,
  48. pMcdSurf->McdDepthBuf.pv,
  49. __GL_UNBIAS_X(fb->buf.gc, x),
  50. __GL_UNBIAS_Y(fb->buf.gc, y),
  51. cx, MCDSPAN_DEPTH) )
  52. {
  53. WARNING("GenMcdReadZSpan: MCDReadSpan failed\n");
  54. }
  55. // Shift and mask depth values so that they are in the most significant
  56. // bits of the __GLzValue.
  57. //
  58. // If MCD has a 16-bit depth buffer, then we utilize a separate translation
  59. // buffer (pDepthSpan). If MCD has a 32-bit depth buffer (implying that
  60. // pDepthSpan == McdDepthBuf.pv), then we do this in place.
  61. pDest = (ULONG *) pMcdState->pDepthSpan;
  62. shiftVal = pMcdState->McdPixelFmt.cDepthShift;
  63. maskVal = pMcdSurf->depthBitMask;
  64. if ( pDest == (ULONG *) pMcdSurf->McdDepthBuf.pv )
  65. {
  66. for (i = cx; i; i--, pDest++)
  67. *pDest = (*pDest << shiftVal) & maskVal;
  68. }
  69. else
  70. {
  71. USHORT *pSrc = (USHORT *) pMcdSurf->McdDepthBuf.pv;
  72. for (i = cx; i; i--)
  73. *pDest++ = ((ULONG)*pSrc++ << shiftVal) & maskVal;
  74. }
  75. return (*((__GLzValue *)pMcdState->pDepthSpan));
  76. }
  77. /******************************Public*Routine******************************\
  78. * GenMcdWriteZSpan
  79. *
  80. * Write depth span buffer to the specificed span (starting from (x,y) and
  81. * cx pels wide) of the MCD depth buffer. The span to be written is in
  82. * pMcdSurf->pDepthSpan.
  83. *
  84. * History:
  85. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  86. * Adpated from gendepth.c (3dddi).
  87. \**************************************************************************/
  88. void GenMcdWriteZSpan(__GLdepthBuffer *fb, GLint x, GLint y, GLint cx)
  89. {
  90. GENMCDSTATE *pMcdState;
  91. GENMCDSURFACE *pMcdSurf;
  92. LONG i;
  93. ULONG *pSrc;
  94. ULONG shiftVal;
  95. pMcdState = ((__GLGENcontext *)fb->buf.gc)->pMcdState;
  96. ASSERTOPENGL(pMcdState, "GenMcdWriteZSpan: null pMcdState\n");
  97. pMcdSurf = pMcdState->pMcdSurf;
  98. ASSERTOPENGL(pMcdSurf, "GenMcdWriteZSpan: null pMcdSurf\n");
  99. // Depth span buffer values are shifted into the most significant portion
  100. // of the __GLzValue. We need to shift these values back into position.
  101. //
  102. // Furthermore, the depth span buffer is always 32-bit. If the MCD depth
  103. // buffer is also 32-bit (implying that pDepthSpan == McdDepthBuf.pv),
  104. // then we can shift in place.
  105. pSrc = (ULONG *) pMcdState->pDepthSpan;
  106. shiftVal = pMcdState->McdPixelFmt.cDepthShift;
  107. if ( pSrc == (ULONG *) pMcdSurf->McdDepthBuf.pv )
  108. {
  109. for (i = cx; i; i--, pSrc++)
  110. *pSrc >>= shiftVal;
  111. }
  112. else
  113. {
  114. USHORT *pDest = (USHORT *) pMcdSurf->McdDepthBuf.pv;
  115. for (i = cx; i; i--)
  116. *pDest++ = (USHORT)(*pSrc++ >> shiftVal);
  117. }
  118. // Write MCD depth span.
  119. if ( !(gpMcdTable->pMCDWriteSpan)(&pMcdState->McdContext,
  120. pMcdSurf->McdDepthBuf.pv,
  121. __GL_UNBIAS_X(fb->buf.gc, x),
  122. __GL_UNBIAS_Y(fb->buf.gc, y),
  123. cx, MCDSPAN_DEPTH) )
  124. {
  125. WARNING("GenMcdWriteZSpan: MCDWriteSpan failed\n");
  126. }
  127. }
  128. /******************************Public*Routine******************************\
  129. * GenMcdWriteZ
  130. *
  131. * Write a single depth value to the specificed location.
  132. *
  133. * History:
  134. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  135. * Adpated from gendepth.c (3dddi).
  136. \**************************************************************************/
  137. void GenMcdWriteZ(__GLdepthBuffer *fb, GLint x, GLint y, __GLzValue z)
  138. {
  139. GENMCDSTATE *pMcdState;
  140. GENMCDSURFACE *pMcdSurf;
  141. pMcdState = ((__GLGENcontext *)fb->buf.gc)->pMcdState;
  142. ASSERTOPENGL(pMcdState, "GenMcdWriteZ: null pMcdState\n");
  143. pMcdSurf = pMcdState->pMcdSurf;
  144. ASSERTOPENGL(pMcdSurf, "GenMcdWriteZ: null pMcdSurf\n");
  145. // If (pmcd->pDepthSpan == pmcd->McdDepthBuf.pv) then MCD has a 32-bit
  146. // depth buffer; otherwise, 16-bit.
  147. if ( pMcdSurf->McdDepthBuf.pv == (PVOID) pMcdState->pDepthSpan )
  148. *((ULONG *)pMcdSurf->McdDepthBuf.pv) = (ULONG)z >> pMcdState->McdPixelFmt.cDepthShift;
  149. else
  150. *((USHORT *)pMcdSurf->McdDepthBuf.pv) = (USHORT)(z >> pMcdState->McdPixelFmt.cDepthShift);
  151. // Write depth value to MCD.
  152. if ( !(gpMcdTable->pMCDWriteSpan)(&pMcdState->McdContext,
  153. pMcdSurf->McdDepthBuf.pv,
  154. __GL_UNBIAS_X(fb->buf.gc, x),
  155. __GL_UNBIAS_Y(fb->buf.gc, y),
  156. 1, MCDSPAN_DEPTH) )
  157. {
  158. WARNING("GenMcdWriteZ: MCDWriteSpan failed\n");
  159. }
  160. }
  161. /******************************Public*Routine******************************\
  162. * GenMcdReadZRawSpan
  163. *
  164. * Unlike GenMcdReadZSpan, which reads the span from the MCD drivers into
  165. * the 32-bit z span buffer, GenMcdReadZRawSpan reads the span in its
  166. * native format and leaves it in the pMcdSurf->McdDepthBuf.pv buffer.
  167. *
  168. * History:
  169. * 14-Mar-1996 -by- Gilman Wong [gilmanw]
  170. * Wrote it.
  171. \**************************************************************************/
  172. PVOID FASTCALL
  173. GenMcdReadZRawSpan(__GLdepthBuffer *fb, GLint x, GLint y, GLint cx)
  174. {
  175. GENMCDSTATE *pMcdState;
  176. GENMCDSURFACE *pMcdSurf;
  177. #if DBG
  178. if (cx > fb->buf.gc->constants.width)
  179. WARNING2("GenMcdReadZRawSpan: cx (%ld) bigger than window width (%ld)\n", cx, fb->buf.gc->constants.width);
  180. ASSERTOPENGL(cx <= MCD_MAX_SCANLINE, "GenMcdReadZRawSpan: cx exceeds buffer width\n");
  181. #endif
  182. pMcdState = ((__GLGENcontext *)fb->buf.gc)->pMcdState;
  183. pMcdSurf = pMcdState->pMcdSurf;
  184. // Read MCD depth span.
  185. if ( !(gpMcdTable->pMCDReadSpan)(&pMcdState->McdContext,
  186. pMcdSurf->McdDepthBuf.pv,
  187. __GL_UNBIAS_X(fb->buf.gc, x),
  188. __GL_UNBIAS_Y(fb->buf.gc, y),
  189. cx, MCDSPAN_DEPTH) )
  190. {
  191. WARNING("GenMcdReadZRawSpan: MCDReadSpan failed\n");
  192. }
  193. return (pMcdSurf->McdDepthBuf.pv);
  194. }
  195. /******************************Public*Routine******************************\
  196. * GenMcdWriteZRawSpan
  197. *
  198. * Unlike GenMcdWriteZSpan, which writes the span in the 32-bit z span
  199. * buffer to the MCD driver, GenMcdWriteZRawSpan writes the native format
  200. * span in the pMcdSurf->McdDepthBuf.pv buffer to the driver.
  201. *
  202. * History:
  203. * 14-Mar-1996 -by- Gilman Wong [gilmanw]
  204. * Wrote it.
  205. \**************************************************************************/
  206. void FASTCALL
  207. GenMcdWriteZRawSpan(__GLdepthBuffer *fb, GLint x, GLint y, GLint cx)
  208. {
  209. GENMCDSTATE *pMcdState;
  210. GENMCDSURFACE *pMcdSurf;
  211. #if DBG
  212. if (cx > fb->buf.gc->constants.width)
  213. WARNING2("GenMcdWriteZRawSpan: cx (%ld) bigger than window width (%ld)\n", cx, fb->buf.gc->constants.width);
  214. ASSERTOPENGL(cx <= MCD_MAX_SCANLINE, "GenMcdWriteZRawSpan: cx exceeds buffer width\n");
  215. #endif
  216. pMcdState = ((__GLGENcontext *)fb->buf.gc)->pMcdState;
  217. pMcdSurf = pMcdState->pMcdSurf;
  218. // Write MCD depth span.
  219. if ( !(gpMcdTable->pMCDWriteSpan)(&pMcdState->McdContext,
  220. pMcdSurf->McdDepthBuf.pv,
  221. __GL_UNBIAS_X(fb->buf.gc, x),
  222. __GL_UNBIAS_Y(fb->buf.gc, y),
  223. cx, MCDSPAN_DEPTH) )
  224. {
  225. WARNING("GenMcdWriteZRawSpan: MCDWriteSpan failed\n");
  226. }
  227. }
  228. /************************************************************************/
  229. /* Fetch routines */
  230. __GLzValue FASTCALL McdFetch(__GLdepthBuffer *fb, GLint x, GLint y)
  231. {
  232. return GenMcdReadZSpan(fb, x, y, 1);
  233. }
  234. __GLzValue FASTCALL McdFetch16(__GLdepthBuffer *fb, GLint x, GLint y)
  235. {
  236. return (GenMcdReadZSpan(fb, x, y, 1) >> 16);
  237. }
  238. __GLzValue FASTCALL McdFetchNEVER(__GLdepthBuffer *fb, GLint x, GLint y)
  239. {
  240. return (__GLzValue) 0;
  241. }
  242. /************************************************************************/
  243. /* 32-bit depth buffer store routines, depth write is enabled. */
  244. /* */
  245. /* Note: McdStoreNEVER is usable for 16- and 32-bit, write enabled or */
  246. /* not. */
  247. GLboolean McdStoreNEVER(__GLdepthBuffer *fb,
  248. GLint x, GLint y, __GLzValue z)
  249. {
  250. return GL_FALSE;
  251. }
  252. GLboolean McdStoreLESS(__GLdepthBuffer *fb,
  253. GLint x, GLint y, __GLzValue z)
  254. {
  255. if ((z & fb->writeMask) < GenMcdReadZSpan(fb, x, y, 1)) {
  256. GenMcdWriteZ(fb, x, y, z);
  257. return GL_TRUE;
  258. }
  259. return GL_FALSE;
  260. }
  261. GLboolean McdStoreEQUAL(__GLdepthBuffer *fb,
  262. GLint x, GLint y, __GLzValue z)
  263. {
  264. if ((z & fb->writeMask) == GenMcdReadZSpan(fb, x, y, 1)) {
  265. GenMcdWriteZ(fb, x, y, z);
  266. return GL_TRUE;
  267. }
  268. return GL_FALSE;
  269. }
  270. GLboolean McdStoreLEQUAL(__GLdepthBuffer *fb,
  271. GLint x, GLint y, __GLzValue z)
  272. {
  273. if ((z & fb->writeMask) <= GenMcdReadZSpan(fb, x, y, 1)) {
  274. GenMcdWriteZ(fb, x, y, z);
  275. return GL_TRUE;
  276. }
  277. return GL_FALSE;
  278. }
  279. GLboolean McdStoreGREATER(__GLdepthBuffer *fb,
  280. GLint x, GLint y, __GLzValue z)
  281. {
  282. if ((z & fb->writeMask) > GenMcdReadZSpan(fb, x, y, 1)) {
  283. GenMcdWriteZ(fb, x, y, z);
  284. return GL_TRUE;
  285. }
  286. return GL_FALSE;
  287. }
  288. GLboolean McdStoreNOTEQUAL(__GLdepthBuffer *fb,
  289. GLint x, GLint y, __GLzValue z)
  290. {
  291. if ((z & fb->writeMask) != GenMcdReadZSpan(fb, x, y, 1)) {
  292. GenMcdWriteZ(fb, x, y, z);
  293. return GL_TRUE;
  294. }
  295. return GL_FALSE;
  296. }
  297. GLboolean McdStoreGEQUAL(__GLdepthBuffer *fb,
  298. GLint x, GLint y, __GLzValue z)
  299. {
  300. if ((z & fb->writeMask) >= GenMcdReadZSpan(fb, x, y, 1)) {
  301. GenMcdWriteZ(fb, x, y, z);
  302. return GL_TRUE;
  303. }
  304. return GL_FALSE;
  305. }
  306. GLboolean McdStoreALWAYS(__GLdepthBuffer *fb,
  307. GLint x, GLint y, __GLzValue z)
  308. {
  309. GenMcdWriteZ(fb, x, y, z);
  310. return GL_TRUE;
  311. }
  312. /************************************************************************/
  313. /* 32-bit depth buffer store routines, depth write not enabled. */
  314. /* */
  315. /* Note: McdStoreALWAYS_W usable for both 16- and 32-bit. */
  316. GLboolean McdStoreLESS_W(__GLdepthBuffer *fb,
  317. GLint x, GLint y, __GLzValue z)
  318. {
  319. return (z & fb->writeMask) < GenMcdReadZSpan(fb, x, y, 1);
  320. }
  321. GLboolean McdStoreEQUAL_W(__GLdepthBuffer *fb,
  322. GLint x, GLint y, __GLzValue z)
  323. {
  324. return (z & fb->writeMask) == GenMcdReadZSpan(fb, x, y, 1);
  325. }
  326. GLboolean McdStoreLEQUAL_W(__GLdepthBuffer *fb,
  327. GLint x, GLint y, __GLzValue z)
  328. {
  329. return (z & fb->writeMask) <= GenMcdReadZSpan(fb, x, y, 1);
  330. }
  331. GLboolean McdStoreGREATER_W(__GLdepthBuffer *fb,
  332. GLint x, GLint y, __GLzValue z)
  333. {
  334. return (z & fb->writeMask) > GenMcdReadZSpan(fb, x, y, 1);
  335. }
  336. GLboolean McdStoreNOTEQUAL_W(__GLdepthBuffer *fb,
  337. GLint x, GLint y, __GLzValue z)
  338. {
  339. return (z & fb->writeMask) != GenMcdReadZSpan(fb, x, y, 1);
  340. }
  341. GLboolean McdStoreGEQUAL_W(__GLdepthBuffer *fb,
  342. GLint x, GLint y, __GLzValue z)
  343. {
  344. return (z & fb->writeMask) >= GenMcdReadZSpan(fb, x, y, 1);
  345. }
  346. GLboolean McdStoreALWAYS_W(__GLdepthBuffer *fb,
  347. GLint x, GLint y, __GLzValue z)
  348. {
  349. return GL_TRUE;
  350. }
  351. /************************************************************************/
  352. /* 16-bit depth buffer store routines, depth write enabled. */
  353. GLboolean McdStore16LESS(__GLdepthBuffer *fb,
  354. GLint x, GLint y, __GLzValue z)
  355. {
  356. z <<= 16;
  357. if ((z & fb->writeMask) < GenMcdReadZSpan(fb, x, y, 1)) {
  358. GenMcdWriteZ(fb, x, y, z);
  359. return GL_TRUE;
  360. }
  361. return GL_FALSE;
  362. }
  363. GLboolean McdStore16EQUAL(__GLdepthBuffer *fb,
  364. GLint x, GLint y, __GLzValue z)
  365. {
  366. z <<= 16;
  367. if ((z & fb->writeMask) == GenMcdReadZSpan(fb, x, y, 1)) {
  368. GenMcdWriteZ(fb, x, y, z);
  369. return GL_TRUE;
  370. }
  371. return GL_FALSE;
  372. }
  373. GLboolean McdStore16LEQUAL(__GLdepthBuffer *fb,
  374. GLint x, GLint y, __GLzValue z)
  375. {
  376. z <<= 16;
  377. if ((z & fb->writeMask) <= GenMcdReadZSpan(fb, x, y, 1)) {
  378. GenMcdWriteZ(fb, x, y, z);
  379. return GL_TRUE;
  380. }
  381. return GL_FALSE;
  382. }
  383. GLboolean McdStore16GREATER(__GLdepthBuffer *fb,
  384. GLint x, GLint y, __GLzValue z)
  385. {
  386. z <<= 16;
  387. if ((z & fb->writeMask) > GenMcdReadZSpan(fb, x, y, 1)) {
  388. GenMcdWriteZ(fb, x, y, z);
  389. return GL_TRUE;
  390. }
  391. return GL_FALSE;
  392. }
  393. GLboolean McdStore16NOTEQUAL(__GLdepthBuffer *fb,
  394. GLint x, GLint y, __GLzValue z)
  395. {
  396. z <<= 16;
  397. if ((z & fb->writeMask) != GenMcdReadZSpan(fb, x, y, 1)) {
  398. GenMcdWriteZ(fb, x, y, z);
  399. return GL_TRUE;
  400. }
  401. return GL_FALSE;
  402. }
  403. GLboolean McdStore16GEQUAL(__GLdepthBuffer *fb,
  404. GLint x, GLint y, __GLzValue z)
  405. {
  406. z <<= 16;
  407. if ((z & fb->writeMask) >= GenMcdReadZSpan(fb, x, y, 1)) {
  408. GenMcdWriteZ(fb, x, y, z);
  409. return GL_TRUE;
  410. }
  411. return GL_FALSE;
  412. }
  413. GLboolean McdStore16ALWAYS(__GLdepthBuffer *fb,
  414. GLint x, GLint y, __GLzValue z)
  415. {
  416. z <<= 16;
  417. GenMcdWriteZ(fb, x, y, z);
  418. return GL_TRUE;
  419. }
  420. /************************************************************************/
  421. /* 16-bit depth buffer store routines, depth write not enabled. */
  422. GLboolean McdStore16LESS_W(__GLdepthBuffer *fb,
  423. GLint x, GLint y, __GLzValue z)
  424. {
  425. z <<= 16;
  426. return (z & fb->writeMask) < GenMcdReadZSpan(fb, x, y, 1);
  427. }
  428. GLboolean McdStore16EQUAL_W(__GLdepthBuffer *fb,
  429. GLint x, GLint y, __GLzValue z)
  430. {
  431. z <<= 16;
  432. return (z & fb->writeMask) == GenMcdReadZSpan(fb, x, y, 1);
  433. }
  434. GLboolean McdStore16LEQUAL_W(__GLdepthBuffer *fb,
  435. GLint x, GLint y, __GLzValue z)
  436. {
  437. z <<= 16;
  438. return (z & fb->writeMask) <= GenMcdReadZSpan(fb, x, y, 1);
  439. }
  440. GLboolean McdStore16GREATER_W(__GLdepthBuffer *fb,
  441. GLint x, GLint y, __GLzValue z)
  442. {
  443. z <<= 16;
  444. return (z & fb->writeMask) > GenMcdReadZSpan(fb, x, y, 1);
  445. }
  446. GLboolean McdStore16NOTEQUAL_W(__GLdepthBuffer *fb,
  447. GLint x, GLint y, __GLzValue z)
  448. {
  449. z <<= 16;
  450. return (z & fb->writeMask) != GenMcdReadZSpan(fb, x, y, 1);
  451. }
  452. GLboolean McdStore16GEQUAL_W(__GLdepthBuffer *fb,
  453. GLint x, GLint y, __GLzValue z)
  454. {
  455. z <<= 16;
  456. return (z & fb->writeMask) >= GenMcdReadZSpan(fb, x, y, 1);
  457. }
  458. /************************************************************************/
  459. /* Store proc table */
  460. /* */
  461. /* Functions are indexed by the depth function index (with offset of */
  462. /* GL_NEVER removed). If depth write is not enabled, an additional */
  463. /* offset of 8 must be added. If 16-bit depth, rather than 32-bit, */
  464. /* an additional offset of 16 must be added. */
  465. GLboolean (*McdStoreProcs[32])(__GLdepthBuffer*, GLint, GLint, __GLzValue)
  466. = {
  467. McdStoreNEVER, // 32-bit depth, write enabled
  468. McdStoreLESS,
  469. McdStoreEQUAL,
  470. McdStoreLEQUAL,
  471. McdStoreGREATER,
  472. McdStoreNOTEQUAL,
  473. McdStoreGEQUAL,
  474. McdStoreALWAYS,
  475. McdStoreNEVER, // 32-bit depth, write disabled
  476. McdStoreLESS_W,
  477. McdStoreEQUAL_W,
  478. McdStoreLEQUAL_W,
  479. McdStoreGREATER_W,
  480. McdStoreNOTEQUAL_W,
  481. McdStoreGEQUAL_W,
  482. McdStoreALWAYS_W,
  483. McdStoreNEVER, // 16-bit depth, write enabled
  484. McdStore16LESS,
  485. McdStore16EQUAL,
  486. McdStore16LEQUAL,
  487. McdStore16GREATER,
  488. McdStore16NOTEQUAL,
  489. McdStore16GEQUAL,
  490. McdStore16ALWAYS,
  491. McdStoreNEVER, // 16-bit depth, write disabled
  492. McdStore16LESS_W,
  493. McdStore16EQUAL_W,
  494. McdStore16LEQUAL_W,
  495. McdStore16GREATER_W,
  496. McdStore16NOTEQUAL_W,
  497. McdStore16GEQUAL_W,
  498. McdStoreALWAYS_W
  499. };
  500. /******************************Public*Routine******************************\
  501. * Pick
  502. *
  503. * Choose appropriate store proc for the MCD managed depth buffer.
  504. *
  505. * History:
  506. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  507. * Adpated from gendepth.c (3dddi).
  508. \**************************************************************************/
  509. // Note: depthIndex param not used - for compatibility with Pick in so_depth.c
  510. void FASTCALL GenMcdPickDepth(__GLcontext *gc, __GLdepthBuffer *fb,
  511. GLint depthIndex)
  512. {
  513. GLint ix;
  514. ix = gc->state.depth.testFunc - GL_NEVER;
  515. if (gc->modes.depthBits) {
  516. if (!gc->state.depth.writeEnable) {
  517. ix += 8;
  518. }
  519. if (gc->depthBuffer.buf.elementSize == 2) {
  520. ix += 16;
  521. }
  522. } else {
  523. // No depthBits so force McdStoreALWAYS_W.
  524. ix = (GL_ALWAYS - GL_NEVER) + 8;
  525. }
  526. fb->store = McdStoreProcs[ix];
  527. if (ix < 16)
  528. fb->storeRaw = McdStoreProcs[ix];
  529. else
  530. fb->storeRaw = McdStoreProcs[ix-16];
  531. }
  532. /******************************Public*Routine******************************\
  533. * __fastGenPickZStoreProc
  534. *
  535. \**************************************************************************/
  536. void FASTCALL __fastGenPickZStoreProc(__GLcontext *gc)
  537. {
  538. int index;
  539. index = gc->state.depth.testFunc - GL_NEVER;
  540. if (gc->modes.depthBits) {
  541. if (gc->state.depth.writeEnable == GL_FALSE)
  542. index += 8;
  543. if (gc->depthBuffer.buf.elementSize == 2)
  544. index += 16;
  545. } else {
  546. index = (GL_ALWAYS - GL_NEVER) + 8;
  547. }
  548. #if DBG
  549. {
  550. GENMCDSTATE *pMcdState = ((__GLGENcontext *)gc)->pMcdState;
  551. ASSERTOPENGL(!pMcdState || (pMcdState->McdBuffers.mcdDepthBuf.bufFlags & MCDBUF_ENABLED),
  552. "__fastGenPickZStoreProc: bad state\n");
  553. }
  554. #endif
  555. GENACCEL(gc).__fastGenZStore = __glCDTPixel[index];
  556. }
  557. /******************************Public*Routine******************************\
  558. * GenMcdInitDepth
  559. *
  560. * Initialize __GLdepthBuffer for MCD.
  561. *
  562. * History:
  563. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  564. * Adpated from gendepth.c (3dddi).
  565. \**************************************************************************/
  566. void FASTCALL GenMcdInitDepth(__GLcontext *gc, __GLdepthBuffer *fb)
  567. {
  568. GENMCDSTATE *pMcdState;
  569. ULONG zDepth;
  570. pMcdState = ((__GLGENcontext *)gc)->pMcdState;
  571. fb->buf.gc = gc;
  572. fb->scale = (__GLzValue) ~0;
  573. if (pMcdState)
  574. fb->writeMask = ((__GLzValue)~0) << (32 - pMcdState->McdPixelFmt.cDepthBits);
  575. else
  576. fb->writeMask = 0;
  577. fb->pick = GenMcdPickDepth;
  578. if (gc->modes.depthBits) {
  579. if (gc->modes.depthBits > 16)
  580. {
  581. fb->buf.elementSize = sizeof(__GLzValue);
  582. fb->clear = GenMcdClearDepth32;
  583. fb->store2 = McdStoreALWAYS;
  584. fb->fetch = McdFetch;
  585. } else {
  586. fb->buf.elementSize = sizeof(__GLz16Value);
  587. fb->clear = GenMcdClearDepth16;
  588. fb->store2 = McdStore16ALWAYS;
  589. fb->fetch = McdFetch16;
  590. }
  591. } else {
  592. // If no depth buffer, depth test always passes (according to spec).
  593. // However, writes must be masked. Also, I don't want to leave the
  594. // clear function pointer unitialized (even though it should never
  595. // be called) so use the NOP clear
  596. fb->clear = GenMcdClearDepthNOP;
  597. fb->store = McdStoreALWAYS_W;
  598. fb->store2 = McdStoreALWAYS_W;
  599. fb->fetch = McdFetchNEVER;
  600. }
  601. }
  602. /******************************Public*Routine******************************\
  603. * GenMcdFreeDepth
  604. *
  605. * Nothing to do. MCD driver manages its own resources.
  606. \**************************************************************************/
  607. void FASTCALL GenMcdFreeDepth(__GLcontext *gc, __GLdepthBuffer *fb)
  608. {
  609. }
  610. /******************************Public*Routine******************************\
  611. * GenMcdClearDepthNOP
  612. *
  613. * Nothing to do. This is used in the depthBits == 0 case.
  614. \**************************************************************************/
  615. void FASTCALL GenMcdClearDepthNOP(__GLdepthBuffer *dfb)
  616. {
  617. }
  618. /******************************Public*Routine******************************\
  619. * GenMcdClearDepth16
  620. *
  621. * MCD 16-bit depth buffer clear.
  622. *
  623. * History:
  624. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  625. * Wrote it.
  626. \**************************************************************************/
  627. void FASTCALL GenMcdClearDepth16(__GLdepthBuffer *dfb)
  628. {
  629. __GLGENcontext *gengc = (__GLGENcontext *) dfb->buf.gc;
  630. GENMCDSTATE *pMcdState;
  631. RECTL rcl;
  632. GLint cWidthBytes;
  633. USHORT usFillZ;
  634. if (!gengc || !(pMcdState = gengc->pMcdState))
  635. return;
  636. // No clipping to handle. If MCDBUF_ENABLED is set there is
  637. // no clipping to handle (see GenMcdUpdateBufferInfo in mcdcx.c).
  638. // If MCDBUF_ENABLE is not set, then we use the MCD span call which
  639. // will handle clipping for us.
  640. //
  641. // Therefore, the client rectangle from the WNDOBJ is the clear
  642. // rectangle.
  643. rcl = gengc->pwndLocked->rclClient;
  644. cWidthBytes = (rcl.right - rcl.left) * sizeof(USHORT);
  645. // Compute 16-bit z clear value.
  646. usFillZ = (USHORT)(gengc->gc.state.depth.clear * gengc->genAccel.zDevScale);
  647. // If MCDBUF_ENABLED, write directly into frame buffer memory.
  648. if (pMcdState->McdBuffers.mcdDepthBuf.bufFlags & MCDBUF_ENABLED)
  649. {
  650. USHORT *pus, *pusEnd;
  651. // Note: dfb->buf.base has a buffer origin offset of (0, 0).
  652. pus = (USHORT *) dfb->buf.base;
  653. pusEnd = pus + ((rcl.bottom - rcl.top) * dfb->buf.outerWidth);
  654. ASSERTOPENGL((((ULONG_PTR)pus) & 0x01) == 0,
  655. "GenMcdClearDepth16: depth buffer not WORD aligned\n");
  656. for ( ; pus != pusEnd; pus += dfb->buf.outerWidth)
  657. {
  658. RtlFillMemoryUshort(pus, cWidthBytes, usFillZ);
  659. }
  660. }
  661. // Otherwise, fill in one span's worth and write to MCD driver via
  662. // MCDWriteSpan.
  663. else
  664. {
  665. GLint y;
  666. GLint cWidth = rcl.right - rcl.left;
  667. GENMCDSURFACE *pMcdSurf;
  668. pMcdSurf = pMcdState->pMcdSurf;
  669. ASSERTOPENGL(pMcdSurf, "GenMcdClearDepth16: no MCD surface\n");
  670. // Fill in one span into the shared memory buffer.
  671. ASSERTOPENGL((((ULONG_PTR)pMcdSurf->McdDepthBuf.pv) & 0x01) == 0,
  672. "GenMcdClearDepth16: depth span buffer not WORD aligned\n");
  673. RtlFillMemoryUshort(pMcdSurf->McdDepthBuf.pv, cWidthBytes, usFillZ);
  674. // Write the span for each span in the clear rectangle.
  675. for (y = 0; y < (rcl.bottom - rcl.top); y++)
  676. {
  677. if ( !(gpMcdTable->pMCDWriteSpan)(&pMcdState->McdContext,
  678. pMcdSurf->McdDepthBuf.pv,
  679. //__GL_UNBIAS_X(dfb->buf.gc, 0),
  680. //__GL_UNBIAS_Y(dfb->buf.gc, y),
  681. 0, y,
  682. cWidth, MCDSPAN_DEPTH) )
  683. {
  684. WARNING("GenMcdClearDepth32: MCDWriteSpan failed\n");
  685. }
  686. }
  687. }
  688. }
  689. /******************************Public*Routine******************************\
  690. * GenMcdClearDepth32
  691. *
  692. * MCD 16-bit depth buffer clear.
  693. *
  694. * History:
  695. * 15-Feb-1996 -by- Gilman Wong [gilmanw]
  696. * Wrote it.
  697. \**************************************************************************/
  698. void FASTCALL GenMcdClearDepth32(__GLdepthBuffer *dfb)
  699. {
  700. __GLGENcontext *gengc = (__GLGENcontext *) dfb->buf.gc;
  701. GENMCDSTATE *pMcdState;
  702. RECTL rcl;
  703. GLint cWidthBytes;
  704. ULONG ulFillZ;
  705. if (!gengc || !(pMcdState = gengc->pMcdState))
  706. return;
  707. // No clipping to handle. If MCDBUF_ENABLED is set there is
  708. // no clipping to handle (see GenMcdUpdateBufferInfo in mcdcx.c).
  709. // If MCDBUF_ENABLE is not set, then we use the MCD span call which
  710. // will handle clipping for us.
  711. //
  712. // Therefore, the client rectangle from the WNDOBJ is the clear
  713. // rectangle.
  714. rcl = gengc->pwndLocked->rclClient;
  715. cWidthBytes = (rcl.right - rcl.left) * sizeof(ULONG);
  716. // Compute 32-bit z clear value.
  717. ulFillZ = (ULONG)(gengc->gc.state.depth.clear * gengc->genAccel.zDevScale);
  718. // If MCDBUF_ENABLED, write directly into frame buffer memory.
  719. if (pMcdState->McdBuffers.mcdDepthBuf.bufFlags & MCDBUF_ENABLED)
  720. {
  721. ULONG *pul, *pulEnd;
  722. // Note: dfb->buf.base has a buffer origin offset of (0, 0).
  723. pul = (ULONG *) dfb->buf.base;
  724. pulEnd = pul + ((rcl.bottom - rcl.top) * dfb->buf.outerWidth);
  725. ASSERTOPENGL((((ULONG_PTR)pul) & 0x03) == 0,
  726. "GenMcdClearDepth32: depth buffer not DWORD aligned\n");
  727. for ( ; pul != pulEnd; pul += dfb->buf.outerWidth)
  728. {
  729. RtlFillMemoryUlong(pul, cWidthBytes, ulFillZ);
  730. }
  731. }
  732. // Otherwise, fill in one span's worth and write to MCD driver via
  733. // MCDWriteSpan.
  734. else
  735. {
  736. GLint y;
  737. GLint cWidth = rcl.right - rcl.left;
  738. GENMCDSURFACE *pMcdSurf;
  739. pMcdSurf = pMcdState->pMcdSurf;
  740. ASSERTOPENGL(pMcdSurf, "GenMcdClearDepth32: no MCD surface\n");
  741. // Fill in one span into the shared memory buffer.
  742. ASSERTOPENGL((((ULONG_PTR)pMcdSurf->McdDepthBuf.pv) & 0x03) == 0,
  743. "GenMcdClearDepth32: depth span buffer not DWORD aligned\n");
  744. RtlFillMemoryUlong(pMcdSurf->McdDepthBuf.pv, cWidthBytes, ulFillZ);
  745. // Write the span for each span in the clear rectangle.
  746. for (y = 0; y < (rcl.bottom - rcl.top); y++)
  747. {
  748. if ( !(gpMcdTable->pMCDWriteSpan)(&pMcdState->McdContext,
  749. pMcdSurf->McdDepthBuf.pv,
  750. 0, y,
  751. cWidth, MCDSPAN_DEPTH) )
  752. {
  753. WARNING("GenMcdClearDepth32: MCDWriteSpan failed\n");
  754. }
  755. }
  756. }
  757. }
  758. /************************************************************************/
  759. GLboolean FASTCALL GenMcdDepthTestLine(__GLcontext *gc)
  760. {
  761. __GLzValue z, dzdx;
  762. GLint xLittle, xBig, yLittle, yBig;
  763. GLint xStart, yStart;
  764. GLint fraction, dfraction;
  765. GLint failed, count;
  766. __GLstippleWord bit, outMask, *osp;
  767. GLboolean writeEnabled, passed;
  768. GLint w;
  769. w = gc->polygon.shader.length;
  770. xBig = gc->line.options.xBig;
  771. yBig = gc->line.options.yBig;
  772. xLittle = gc->line.options.xLittle;
  773. yLittle = gc->line.options.yLittle;
  774. xStart = gc->line.options.xStart;
  775. yStart = gc->line.options.yStart;
  776. fraction = gc->line.options.fraction;
  777. dfraction = gc->line.options.dfraction;
  778. z = gc->polygon.shader.frag.z;
  779. dzdx = gc->polygon.shader.dzdx;
  780. writeEnabled = gc->state.depth.writeEnable;
  781. osp = gc->polygon.shader.stipplePat;
  782. failed = 0;
  783. while (w) {
  784. count = w;
  785. if (count > __GL_STIPPLE_BITS) {
  786. count = __GL_STIPPLE_BITS;
  787. }
  788. w -= count;
  789. outMask = (__GLstippleWord)~0;
  790. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  791. while (--count >= 0) {
  792. if (!(*gc->depthBuffer.storeRaw)(&gc->depthBuffer, xStart, yStart, z)) {
  793. outMask &= ~bit;
  794. failed++;
  795. }
  796. z += dzdx;
  797. fraction += dfraction;
  798. if (fraction < 0) {
  799. fraction &= ~0x80000000;
  800. xStart += xBig;
  801. yStart += yBig;
  802. } else {
  803. xStart += xLittle;
  804. yStart += yLittle;
  805. }
  806. #ifdef __GL_STIPPLE_MSB
  807. bit >>= 1;
  808. #else
  809. bit <<= 1;
  810. #endif
  811. }
  812. *osp++ = outMask;
  813. }
  814. if (failed == 0) {
  815. /* Call next span proc */
  816. return GL_FALSE;
  817. } else {
  818. if (failed != gc->polygon.shader.length) {
  819. /* Call next stippled span proc */
  820. return GL_TRUE;
  821. }
  822. }
  823. gc->polygon.shader.done = GL_TRUE;
  824. return GL_TRUE;
  825. }
  826. GLboolean FASTCALL GenMcdDepthTestStippledLine(__GLcontext *gc)
  827. {
  828. __GLzValue z, dzdx;
  829. GLint xLittle, xBig, yLittle, yBig;
  830. GLint xStart, yStart;
  831. GLint fraction, dfraction;
  832. GLint failed, count;
  833. __GLstippleWord bit, inMask, outMask, *sp;
  834. GLboolean writeEnabled, passed;
  835. GLint w;
  836. w = gc->polygon.shader.length;
  837. sp = gc->polygon.shader.stipplePat;
  838. xBig = gc->line.options.xBig;
  839. yBig = gc->line.options.yBig;
  840. xLittle = gc->line.options.xLittle;
  841. yLittle = gc->line.options.yLittle;
  842. xStart = gc->line.options.xStart;
  843. yStart = gc->line.options.yStart;
  844. fraction = gc->line.options.fraction;
  845. dfraction = gc->line.options.dfraction;
  846. z = gc->polygon.shader.frag.z;
  847. dzdx = gc->polygon.shader.dzdx;
  848. writeEnabled = gc->state.depth.writeEnable;
  849. failed = 0;
  850. while (w) {
  851. count = w;
  852. if (count > __GL_STIPPLE_BITS) {
  853. count = __GL_STIPPLE_BITS;
  854. }
  855. w -= count;
  856. inMask = *sp;
  857. outMask = (__GLstippleWord)~0;
  858. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  859. while (--count >= 0) {
  860. if (inMask & bit) {
  861. if (!(*gc->depthBuffer.storeRaw)(&gc->depthBuffer, xStart, yStart, z)) {
  862. outMask &= ~bit;
  863. failed++;
  864. }
  865. } else failed++;
  866. z += dzdx;
  867. fraction += dfraction;
  868. if (fraction < 0) {
  869. fraction &= ~0x80000000;
  870. fraction &= ~0x80000000;
  871. xStart += xBig;
  872. yStart += yBig;
  873. } else {
  874. xStart += xLittle;
  875. yStart += yLittle;
  876. }
  877. #ifdef __GL_STIPPLE_MSB
  878. bit >>= 1;
  879. #else
  880. bit <<= 1;
  881. #endif
  882. }
  883. *sp++ = outMask & inMask;
  884. }
  885. if (failed != gc->polygon.shader.length) {
  886. /* Call next proc */
  887. return GL_FALSE;
  888. }
  889. return GL_TRUE;
  890. }
  891. GLboolean FASTCALL GenMcdDepthTestStencilLine(__GLcontext *gc)
  892. {
  893. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  894. GLint xLittle, xBig, yLittle, yBig;
  895. GLint xStart, yStart;
  896. GLint fraction, dfraction;
  897. GLint dspLittle, dspBig;
  898. __GLzValue z, dzdx;
  899. GLint failed, count;
  900. __GLstippleWord bit, outMask, *osp;
  901. GLboolean writeEnabled, passed;
  902. GLint w;
  903. w = gc->polygon.shader.length;
  904. xBig = gc->line.options.xBig;
  905. yBig = gc->line.options.yBig;
  906. xLittle = gc->line.options.xLittle;
  907. yLittle = gc->line.options.yLittle;
  908. xStart = gc->line.options.xStart;
  909. yStart = gc->line.options.yStart;
  910. fraction = gc->line.options.fraction;
  911. dfraction = gc->line.options.dfraction;
  912. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  913. gc->line.options.xStart, gc->line.options.yStart);
  914. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  915. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  916. fraction = gc->line.options.fraction;
  917. dfraction = gc->line.options.dfraction;
  918. zFailOp = gc->stencilBuffer.depthFailOpTable;
  919. zPassOp = gc->stencilBuffer.depthPassOpTable;
  920. z = gc->polygon.shader.frag.z;
  921. dzdx = gc->polygon.shader.dzdx;
  922. writeEnabled = gc->state.depth.writeEnable;
  923. osp = gc->polygon.shader.stipplePat;
  924. failed = 0;
  925. while (w) {
  926. count = w;
  927. if (count > __GL_STIPPLE_BITS) {
  928. count = __GL_STIPPLE_BITS;
  929. }
  930. w -= count;
  931. outMask = (__GLstippleWord)~0;
  932. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  933. while (--count >= 0) {
  934. if (!(*gc->depthBuffer.storeRaw)(&gc->depthBuffer, xStart, yStart, z)) {
  935. sfb[0] = zFailOp[sfb[0]];
  936. outMask &= ~bit;
  937. failed++;
  938. } else {
  939. sfb[0] = zPassOp[sfb[0]];
  940. }
  941. z += dzdx;
  942. fraction += dfraction;
  943. if (fraction < 0) {
  944. fraction &= ~0x80000000;
  945. sfb += dspBig;
  946. xStart += xBig;
  947. yStart += yBig;
  948. } else {
  949. sfb += dspLittle;
  950. xStart += xLittle;
  951. yStart += yLittle;
  952. }
  953. #ifdef __GL_STIPPLE_MSB
  954. bit >>= 1;
  955. #else
  956. bit <<= 1;
  957. #endif
  958. }
  959. *osp++ = outMask;
  960. }
  961. if (failed == 0) {
  962. /* Call next span proc */
  963. return GL_FALSE;
  964. } else {
  965. if (failed != gc->polygon.shader.length) {
  966. /* Call next stippled span proc */
  967. return GL_TRUE;
  968. }
  969. }
  970. gc->polygon.shader.done = GL_TRUE;
  971. return GL_TRUE;
  972. }
  973. GLboolean FASTCALL GenMcdDepthTestStencilStippledLine(__GLcontext *gc)
  974. {
  975. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  976. GLint xLittle, xBig, yLittle, yBig;
  977. GLint xStart, yStart;
  978. GLint fraction, dfraction;
  979. GLint dspLittle, dspBig;
  980. __GLzValue z, dzdx;
  981. GLint failed, count;
  982. __GLstippleWord bit, inMask, outMask, *sp;
  983. GLboolean writeEnabled, passed;
  984. GLint w;
  985. w = gc->polygon.shader.length;
  986. sp = gc->polygon.shader.stipplePat;
  987. xBig = gc->line.options.xBig;
  988. yBig = gc->line.options.yBig;
  989. xLittle = gc->line.options.xLittle;
  990. yLittle = gc->line.options.yLittle;
  991. xStart = gc->line.options.xStart;
  992. yStart = gc->line.options.yStart;
  993. fraction = gc->line.options.fraction;
  994. dfraction = gc->line.options.dfraction;
  995. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  996. gc->line.options.xStart, gc->line.options.yStart);
  997. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  998. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  999. fraction = gc->line.options.fraction;
  1000. dfraction = gc->line.options.dfraction;
  1001. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1002. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1003. z = gc->polygon.shader.frag.z;
  1004. dzdx = gc->polygon.shader.dzdx;
  1005. writeEnabled = gc->state.depth.writeEnable;
  1006. failed = 0;
  1007. while (w) {
  1008. count = w;
  1009. if (count > __GL_STIPPLE_BITS) {
  1010. count = __GL_STIPPLE_BITS;
  1011. }
  1012. w -= count;
  1013. inMask = *sp;
  1014. outMask = (__GLstippleWord)~0;
  1015. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  1016. while (--count >= 0) {
  1017. if (inMask & bit) {
  1018. if (!(*gc->depthBuffer.storeRaw)(&gc->depthBuffer, xStart, yStart, z)) {
  1019. sfb[0] = zFailOp[sfb[0]];
  1020. outMask &= ~bit;
  1021. failed++;
  1022. } else {
  1023. sfb[0] = zPassOp[sfb[0]];
  1024. }
  1025. } else failed++;
  1026. z += dzdx;
  1027. fraction += dfraction;
  1028. if (fraction < 0) {
  1029. fraction &= ~0x80000000;
  1030. sfb += dspBig;
  1031. xStart += xBig;
  1032. yStart += yBig;
  1033. } else {
  1034. sfb += dspLittle;
  1035. xStart += xLittle;
  1036. yStart += yLittle;
  1037. }
  1038. #ifdef __GL_STIPPLE_MSB
  1039. bit >>= 1;
  1040. #else
  1041. bit <<= 1;
  1042. #endif
  1043. }
  1044. *sp++ = outMask & inMask;
  1045. }
  1046. if (failed != gc->polygon.shader.length) {
  1047. /* Call next proc */
  1048. return GL_FALSE;
  1049. }
  1050. return GL_TRUE;
  1051. }
  1052. /************************************************************************/
  1053. /*
  1054. ** Depth test a span, when stenciling is disabled.
  1055. */
  1056. GLboolean FASTCALL GenMcdDepthTestSpan(__GLcontext *gc)
  1057. {
  1058. __GLzValue z, dzdx, *zfb;
  1059. GLint failed, count, testFunc;
  1060. __GLstippleWord bit, outMask, *osp;
  1061. GLboolean writeEnabled, passed;
  1062. GLint w;
  1063. w = gc->polygon.shader.length;
  1064. GenMcdReadZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1065. gc->polygon.shader.frag.y, w);
  1066. if (((__GLGENcontext *)gc)->pMcdState->softZSpanFuncPtr) {
  1067. GLboolean retVal;
  1068. gc->polygon.shader.zbuf = (__GLzValue *)((__GLGENcontext *)gc)->pMcdState->pDepthSpan;
  1069. retVal =
  1070. (*(__GLspanFunc)((__GLGENcontext *)gc)->pMcdState->softZSpanFuncPtr)(gc);
  1071. if (gc->state.depth.writeEnable)
  1072. GenMcdWriteZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1073. gc->polygon.shader.frag.y,
  1074. gc->polygon.shader.length);
  1075. return retVal;
  1076. }
  1077. testFunc = gc->state.depth.testFunc & 0x7;
  1078. zfb = (__GLzValue *)((__GLGENcontext *)gc)->pMcdState->pDepthSpan;
  1079. z = gc->polygon.shader.frag.z;
  1080. dzdx = gc->polygon.shader.dzdx;
  1081. writeEnabled = gc->state.depth.writeEnable;
  1082. osp = gc->polygon.shader.stipplePat;
  1083. failed = 0;
  1084. while (w) {
  1085. count = w;
  1086. if (count > __GL_STIPPLE_BITS) {
  1087. count = __GL_STIPPLE_BITS;
  1088. }
  1089. w -= count;
  1090. outMask = (__GLstippleWord)~0;
  1091. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  1092. while (--count >= 0) {
  1093. switch (testFunc) {
  1094. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1095. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1096. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1097. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1098. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1099. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1100. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1101. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1102. }
  1103. if (passed) {
  1104. if (writeEnabled) {
  1105. zfb[0] = z;
  1106. }
  1107. } else {
  1108. outMask &= ~bit;
  1109. failed++;
  1110. }
  1111. z += dzdx;
  1112. zfb++;
  1113. #ifdef __GL_STIPPLE_MSB
  1114. bit >>= 1;
  1115. #else
  1116. bit <<= 1;
  1117. #endif
  1118. }
  1119. *osp++ = outMask;
  1120. }
  1121. if (writeEnabled)
  1122. GenMcdWriteZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1123. gc->polygon.shader.frag.y,
  1124. gc->polygon.shader.length);
  1125. if (failed == 0) {
  1126. /* Call next span proc */
  1127. return GL_FALSE;
  1128. } else {
  1129. if (failed != gc->polygon.shader.length) {
  1130. /* Call next stippled span proc */
  1131. return GL_TRUE;
  1132. }
  1133. }
  1134. gc->polygon.shader.done = GL_TRUE;
  1135. return GL_TRUE;
  1136. }
  1137. /*
  1138. ** Stippled form of depth test span, when stenciling is disabled.
  1139. */
  1140. GLboolean FASTCALL GenMcdDepthTestStippledSpan(__GLcontext *gc)
  1141. {
  1142. __GLzValue z, dzdx, *zfb;
  1143. GLint failed, count, testFunc;
  1144. __GLstippleWord bit, inMask, outMask, *sp;
  1145. GLboolean writeEnabled, passed;
  1146. GLint w;
  1147. sp = gc->polygon.shader.stipplePat;
  1148. w = gc->polygon.shader.length;
  1149. GenMcdReadZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1150. gc->polygon.shader.frag.y, w);
  1151. testFunc = gc->state.depth.testFunc & 0x7;
  1152. zfb = (__GLzValue *)((__GLGENcontext *)gc)->pMcdState->pDepthSpan;
  1153. z = gc->polygon.shader.frag.z;
  1154. dzdx = gc->polygon.shader.dzdx;
  1155. writeEnabled = gc->state.depth.writeEnable;
  1156. failed = 0;
  1157. while (w) {
  1158. count = w;
  1159. if (count > __GL_STIPPLE_BITS) {
  1160. count = __GL_STIPPLE_BITS;
  1161. }
  1162. w -= count;
  1163. inMask = *sp;
  1164. outMask = (__GLstippleWord)~0;
  1165. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  1166. while (--count >= 0) {
  1167. if (inMask & bit) {
  1168. switch (testFunc) {
  1169. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1170. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1171. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1172. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1173. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1174. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1175. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1176. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1177. }
  1178. if (passed) {
  1179. if (writeEnabled) {
  1180. zfb[0] = z;
  1181. }
  1182. } else {
  1183. outMask &= ~bit;
  1184. failed++;
  1185. }
  1186. } else failed++;
  1187. z += dzdx;
  1188. zfb++;
  1189. #ifdef __GL_STIPPLE_MSB
  1190. bit >>= 1;
  1191. #else
  1192. bit <<= 1;
  1193. #endif
  1194. }
  1195. *sp++ = outMask & inMask;
  1196. }
  1197. if (writeEnabled)
  1198. GenMcdWriteZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1199. gc->polygon.shader.frag.y,
  1200. gc->polygon.shader.length);
  1201. if (failed != gc->polygon.shader.length) {
  1202. /* Call next proc */
  1203. return GL_FALSE;
  1204. }
  1205. return GL_TRUE;
  1206. }
  1207. /*
  1208. ** Depth test a span when stenciling is enabled.
  1209. */
  1210. GLboolean FASTCALL GenMcdDepthTestStencilSpan(__GLcontext *gc)
  1211. {
  1212. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1213. __GLzValue z, dzdx, *zfb;
  1214. GLint failed, count, testFunc;
  1215. __GLstippleWord bit, outMask, *osp;
  1216. GLboolean writeEnabled, passed;
  1217. GLint w;
  1218. w = gc->polygon.shader.length;
  1219. GenMcdReadZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1220. gc->polygon.shader.frag.y, w);
  1221. testFunc = gc->state.depth.testFunc & 0x7;
  1222. zfb = (__GLzValue *)((__GLGENcontext *)gc)->pMcdState->pDepthSpan;
  1223. sfb = gc->polygon.shader.sbuf;
  1224. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1225. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1226. z = gc->polygon.shader.frag.z;
  1227. dzdx = gc->polygon.shader.dzdx;
  1228. writeEnabled = gc->state.depth.writeEnable;
  1229. osp = gc->polygon.shader.stipplePat;
  1230. failed = 0;
  1231. while (w) {
  1232. count = w;
  1233. if (count > __GL_STIPPLE_BITS) {
  1234. count = __GL_STIPPLE_BITS;
  1235. }
  1236. w -= count;
  1237. outMask = (__GLstippleWord)~0;
  1238. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  1239. while (--count >= 0) {
  1240. switch (testFunc) {
  1241. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1242. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1243. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1244. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1245. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1246. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1247. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1248. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1249. }
  1250. if (passed) {
  1251. sfb[0] = zPassOp[sfb[0]];
  1252. if (writeEnabled) {
  1253. zfb[0] = z;
  1254. }
  1255. } else {
  1256. sfb[0] = zFailOp[sfb[0]];
  1257. outMask &= ~bit;
  1258. failed++;
  1259. }
  1260. z += dzdx;
  1261. zfb++;
  1262. sfb++;
  1263. #ifdef __GL_STIPPLE_MSB
  1264. bit >>= 1;
  1265. #else
  1266. bit <<= 1;
  1267. #endif
  1268. }
  1269. *osp++ = outMask;
  1270. }
  1271. if (writeEnabled)
  1272. GenMcdWriteZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1273. gc->polygon.shader.frag.y,
  1274. gc->polygon.shader.length);
  1275. if (failed == 0) {
  1276. /* Call next span proc */
  1277. return GL_FALSE;
  1278. } else {
  1279. if (failed != gc->polygon.shader.length) {
  1280. /* Call next stippled span proc */
  1281. return GL_TRUE;
  1282. }
  1283. }
  1284. gc->polygon.shader.done = GL_TRUE;
  1285. return GL_TRUE;
  1286. }
  1287. /*
  1288. ** Stippled form of depth test span, when stenciling is enabled.
  1289. */
  1290. GLboolean FASTCALL GenMcdDepthTestStencilStippledSpan(__GLcontext *gc)
  1291. {
  1292. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1293. __GLzValue z, dzdx, *zfb;
  1294. GLint failed, count, testFunc;
  1295. __GLstippleWord bit, inMask, outMask, *sp;
  1296. GLboolean writeEnabled, passed;
  1297. GLint w;
  1298. w = gc->polygon.shader.length;
  1299. sp = gc->polygon.shader.stipplePat;
  1300. GenMcdReadZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1301. gc->polygon.shader.frag.y, w);
  1302. testFunc = gc->state.depth.testFunc & 0x7;
  1303. zfb = (__GLzValue *)((__GLGENcontext *)gc)->pMcdState->pDepthSpan;
  1304. sfb = gc->polygon.shader.sbuf;
  1305. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1306. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1307. z = gc->polygon.shader.frag.z;
  1308. dzdx = gc->polygon.shader.dzdx;
  1309. writeEnabled = gc->state.depth.writeEnable;
  1310. failed = 0;
  1311. while (w) {
  1312. count = w;
  1313. if (count > __GL_STIPPLE_BITS) {
  1314. count = __GL_STIPPLE_BITS;
  1315. }
  1316. w -= count;
  1317. inMask = *sp;
  1318. outMask = (__GLstippleWord)~0;
  1319. bit = (__GLstippleWord)__GL_STIPPLE_SHIFT(0);
  1320. while (--count >= 0) {
  1321. if (inMask & bit) {
  1322. switch (testFunc) {
  1323. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1324. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1325. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1326. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1327. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1328. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1329. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1330. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1331. }
  1332. if (passed) {
  1333. sfb[0] = zPassOp[sfb[0]];
  1334. if (writeEnabled) {
  1335. zfb[0] = z;
  1336. }
  1337. } else {
  1338. sfb[0] = zFailOp[sfb[0]];
  1339. outMask &= ~bit;
  1340. failed++;
  1341. }
  1342. } else failed++;
  1343. z += dzdx;
  1344. zfb++;
  1345. sfb++;
  1346. #ifdef __GL_STIPPLE_MSB
  1347. bit >>= 1;
  1348. #else
  1349. bit <<= 1;
  1350. #endif
  1351. }
  1352. *sp++ = outMask & inMask;
  1353. }
  1354. if (writeEnabled)
  1355. GenMcdWriteZSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1356. gc->polygon.shader.frag.y,
  1357. gc->polygon.shader.length);
  1358. if (failed != gc->polygon.shader.length) {
  1359. /* Call next proc */
  1360. return GL_FALSE;
  1361. }
  1362. return GL_TRUE;
  1363. }
  1364. /*
  1365. ** MCD version of __fastGenStippleAnyDepthTestSpan. See __fastGenPickSpanProcs
  1366. ** in genaccel.c and __fastGenStippleAnyDepthTestSpan in genspan.c.
  1367. */
  1368. GLboolean FASTCALL GenMcdStippleAnyDepthTestSpan(__GLcontext *gc)
  1369. {
  1370. // If the shader is done after this routine then
  1371. // the stipple pattern is all zeroes so we can
  1372. // skip the span
  1373. __glStippleSpan(gc);
  1374. if (gc->polygon.shader.done)
  1375. {
  1376. return GL_FALSE;
  1377. }
  1378. // If this returns true then all bits are off so
  1379. // we can skip the span
  1380. return !GenMcdDepthTestStippledSpan(gc);
  1381. }
  1382. #ifdef NT_DEADCODE_GENMCDSTIPPLESPAN
  1383. //
  1384. // The code below works (it must be enabled in the __fastGenPickSpanProcs
  1385. // function), but it doesn't seem worth turning it on and increasing the
  1386. // DLL size to slightly speed up a rarely used MCD kickback case.
  1387. //
  1388. // Here are the prototypes for mcdcx.h if the code is turned on:
  1389. //
  1390. // GLboolean FASTCALL GenMcdStippleLt32Span(__GLcontext *);
  1391. // GLboolean FASTCALL GenMcdStippleLt16Span(__GLcontext *);
  1392. //
  1393. /*
  1394. ** MCD version of __fastGenStippleLt32Span, a special case of
  1395. ** GenMcdStippleAnyDepthTestSpan for 32-bit depth buffers and GL_LESS
  1396. ** depth test.
  1397. **
  1398. ** See __fastGenPickSpanProcs in genaccel.c and __fastGenStippleLt32Span in
  1399. ** genspan.c.
  1400. */
  1401. GLboolean FASTCALL GenMcdStippleLt32Span(__GLcontext *gc)
  1402. {
  1403. register GLuint zAccum = gc->polygon.shader.frag.z;
  1404. register GLint zDelta = gc->polygon.shader.dzdx;
  1405. register GLuint *zbuf = (GLuint *)
  1406. ((__GLGENcontext *)gc)->pMcdState->pMcdSurf->McdDepthBuf.pv;
  1407. register GLuint *pStipple = gc->polygon.shader.stipplePat;
  1408. register GLint cTotalPix = gc->polygon.shader.length;
  1409. register GLuint mask;
  1410. register GLint cPix;
  1411. register GLint zPasses = 0;
  1412. register GLuint maskBit;
  1413. __GLstippleWord stipple;
  1414. GLint count;
  1415. GLint shift;
  1416. GenMcdReadZRawSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1417. gc->polygon.shader.frag.y, gc->polygon.shader.length);
  1418. if (gc->constants.yInverted) {
  1419. stipple = gc->polygon.stipple[(gc->constants.height -
  1420. (gc->polygon.shader.frag.y - gc->constants.viewportYAdjust)-1)
  1421. & (__GL_STIPPLE_BITS-1)];
  1422. } else {
  1423. stipple = gc->polygon.stipple[gc->polygon.shader.frag.y &
  1424. (__GL_STIPPLE_BITS-1)];
  1425. }
  1426. shift = gc->polygon.shader.frag.x & (__GL_STIPPLE_BITS - 1);
  1427. #ifdef __GL_STIPPLE_MSB
  1428. stipple = (stipple << shift) | (stipple >> (__GL_STIPPLE_BITS - shift));
  1429. #else
  1430. stipple = (stipple >> shift) | (stipple << (__GL_STIPPLE_BITS - shift));
  1431. #endif
  1432. if (stipple == 0) {
  1433. /* No point in continuing */
  1434. return GL_FALSE;
  1435. }
  1436. for (;cTotalPix > 0; cTotalPix-=32) {
  1437. mask = stipple;
  1438. maskBit = 0x80000000;
  1439. cPix = cTotalPix;
  1440. if (cPix > 32)
  1441. cPix = 32;
  1442. for (;cPix > 0; cPix --)
  1443. {
  1444. if (mask & maskBit)
  1445. {
  1446. if ((zAccum) < (*zbuf))
  1447. {
  1448. *zbuf = zAccum;
  1449. zPasses++;
  1450. }
  1451. else
  1452. {
  1453. mask &= ~maskBit;
  1454. }
  1455. }
  1456. zbuf++;
  1457. zAccum += zDelta;
  1458. maskBit >>= 1;
  1459. }
  1460. *pStipple++ = mask;
  1461. }
  1462. if (gc->state.depth.writeEnable)
  1463. GenMcdWriteZRawSpan(&gc->depthBuffer,
  1464. gc->polygon.shader.frag.x,
  1465. gc->polygon.shader.frag.y,
  1466. gc->polygon.shader.length);
  1467. if (zPasses == 0) {
  1468. return GL_FALSE;
  1469. } else {
  1470. return GL_TRUE;
  1471. }
  1472. }
  1473. /*
  1474. ** MCD version of __fastGenStippleLt16Span, a special case of
  1475. ** GenMcdStippleAnyDepthTestSpan for 16-bit depth buffers and GL_LESS
  1476. ** depth test.
  1477. **
  1478. ** See __fastGenPickSpanProcs in genaccel.c and __fastGenStippleLt16Span in
  1479. ** genspan.c.
  1480. */
  1481. GLboolean FASTCALL GenMcdStippleLt16Span(__GLcontext *gc)
  1482. {
  1483. register GLuint zAccum = gc->polygon.shader.frag.z;
  1484. register GLint zDelta = gc->polygon.shader.dzdx;
  1485. register __GLz16Value *zbuf = (__GLz16Value *)
  1486. ((__GLGENcontext *)gc)->pMcdState->pMcdSurf->McdDepthBuf.pv;
  1487. register GLuint *pStipple = gc->polygon.shader.stipplePat;
  1488. register GLint cTotalPix = gc->polygon.shader.length;
  1489. register GLuint mask;
  1490. register GLint cPix;
  1491. register GLint zPasses = 0;
  1492. register GLuint maskBit;
  1493. __GLstippleWord stipple;
  1494. GLint count;
  1495. GLint shift;
  1496. GenMcdReadZRawSpan(&gc->depthBuffer, gc->polygon.shader.frag.x,
  1497. gc->polygon.shader.frag.y, gc->polygon.shader.length);
  1498. if (gc->constants.yInverted) {
  1499. stipple = gc->polygon.stipple[(gc->constants.height -
  1500. (gc->polygon.shader.frag.y - gc->constants.viewportYAdjust)-1)
  1501. & (__GL_STIPPLE_BITS-1)];
  1502. } else {
  1503. stipple = gc->polygon.stipple[gc->polygon.shader.frag.y &
  1504. (__GL_STIPPLE_BITS-1)];
  1505. }
  1506. shift = gc->polygon.shader.frag.x & (__GL_STIPPLE_BITS - 1);
  1507. #ifdef __GL_STIPPLE_MSB
  1508. stipple = (stipple << shift) | (stipple >> (__GL_STIPPLE_BITS - shift));
  1509. #else
  1510. stipple = (stipple >> shift) | (stipple << (__GL_STIPPLE_BITS - shift));
  1511. #endif
  1512. if (stipple == 0) {
  1513. /* No point in continuing */
  1514. return GL_FALSE;
  1515. }
  1516. for (;cTotalPix > 0; cTotalPix-=32) {
  1517. mask = stipple;
  1518. maskBit = 0x80000000;
  1519. cPix = cTotalPix;
  1520. if (cPix > 32)
  1521. cPix = 32;
  1522. for (;cPix > 0; cPix --)
  1523. {
  1524. if (mask & maskBit)
  1525. {
  1526. if (((__GLz16Value)(zAccum >> Z16_SHIFT)) < (*zbuf))
  1527. {
  1528. *zbuf = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  1529. zPasses++;
  1530. }
  1531. else
  1532. {
  1533. mask &= ~maskBit;
  1534. }
  1535. }
  1536. zbuf++;
  1537. zAccum += zDelta;
  1538. maskBit >>= 1;
  1539. }
  1540. *pStipple++ = mask;
  1541. }
  1542. if (gc->state.depth.writeEnable)
  1543. GenMcdWriteZRawSpan(&gc->depthBuffer,
  1544. gc->polygon.shader.frag.x,
  1545. gc->polygon.shader.frag.y,
  1546. gc->polygon.shader.length);
  1547. if (zPasses == 0) {
  1548. return GL_FALSE;
  1549. } else {
  1550. return GL_TRUE;
  1551. }
  1552. }
  1553. #endif
  1554. #endif //_MCD_