Source code of Windows XP (NT5)
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.

2491 lines
61 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. /*
  20. ** Process the incoming line by calling all of the appropriate line procs.
  21. ** Return value is ignored.
  22. **
  23. ** It sets gc->polygon.shader.cfb to gc->drawBuffer.
  24. */
  25. GLboolean FASTCALL __glProcessLine(__GLcontext *gc)
  26. {
  27. GLboolean stippling, retval;
  28. GLint i,n;
  29. #ifdef NT
  30. GLint length;
  31. __GLcolor colors[__GL_MAX_STACKED_COLORS>>1];
  32. __GLcolor fbcolors[__GL_MAX_STACKED_COLORS>>1];
  33. __GLcolor *vColors, *vFbcolors;
  34. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  35. __GLstippleWord *words;
  36. length = gc->polygon.shader.length;
  37. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  38. {
  39. words = gcTempAlloc(gc, (length+__GL_STIPPLE_BITS-1)/8);
  40. if (words == NULL)
  41. {
  42. return GL_TRUE;
  43. }
  44. }
  45. else
  46. {
  47. words = stackWords;
  48. }
  49. if (length > (__GL_MAX_STACKED_COLORS>>1))
  50. {
  51. vColors = (__GLcolor *) gcTempAlloc(gc, length * sizeof(__GLcolor));
  52. if (NULL == vColors)
  53. {
  54. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  55. {
  56. gcTempFree(gc, words);
  57. }
  58. return GL_TRUE;
  59. }
  60. vFbcolors = (__GLcolor *) gcTempAlloc(gc, length * sizeof(__GLcolor));
  61. if (NULL == vFbcolors)
  62. {
  63. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  64. {
  65. gcTempFree(gc, words);
  66. }
  67. gcTempFree(gc, vColors);
  68. return GL_TRUE;
  69. }
  70. }
  71. else
  72. {
  73. vColors = colors;
  74. vFbcolors = fbcolors;
  75. }
  76. #else
  77. __GLcolor vColors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  78. __GLcolor vFbcolors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  79. __GLstippleWord words[__GL_MAX_STIPPLE_WORDS];
  80. #endif
  81. gc->polygon.shader.colors = vColors;
  82. gc->polygon.shader.fbcolors = vFbcolors;
  83. gc->polygon.shader.stipplePat = words;
  84. gc->polygon.shader.cfb = gc->drawBuffer;
  85. stippling = GL_FALSE;
  86. n = gc->procs.line.n;
  87. gc->polygon.shader.done = GL_FALSE;
  88. /* Step 1: Perform early line stipple, coloring procs */
  89. for (i = 0; i < n; i++) {
  90. if (stippling) {
  91. if ((*gc->procs.line.stippledLineFuncs[i])(gc)) {
  92. /* Line stippled away! */
  93. retval = GL_TRUE;
  94. goto __glProcessLineExit;
  95. }
  96. } else {
  97. if ((*gc->procs.line.lineFuncs[i])(gc)) {
  98. if (gc->polygon.shader.done)
  99. {
  100. retval = GL_TRUE;
  101. goto __glProcessLineExit;
  102. }
  103. stippling = GL_TRUE;
  104. }
  105. }
  106. }
  107. if (stippling) {
  108. retval = (*gc->procs.line.wideStippledLineRep)(gc);
  109. } else {
  110. retval = (*gc->procs.line.wideLineRep)(gc);
  111. }
  112. __glProcessLineExit:
  113. #ifdef NT
  114. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  115. {
  116. gcTempFree(gc, words);
  117. }
  118. if (length > (__GL_MAX_STACKED_COLORS>>1))
  119. {
  120. gcTempFree(gc, vColors);
  121. gcTempFree(gc, vFbcolors);
  122. }
  123. #endif
  124. return (retval);
  125. }
  126. /*
  127. ** Process the incoming line by calling the 3 appropriate line procs. It does
  128. ** not chain to gc->procs.line.wideLineRep, but returns instead. This is a
  129. ** specific fast path.
  130. **
  131. ** Return value is ignored.
  132. **
  133. ** It sets gc->polygon.shader.cfb to gc->drawBuffer.
  134. */
  135. GLboolean FASTCALL __glProcessLine3NW(__GLcontext *gc)
  136. {
  137. GLboolean retval;
  138. #ifdef NT
  139. GLint length;
  140. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  141. __GLstippleWord *words;
  142. __GLcolor colors[__GL_MAX_STACKED_COLORS>>1];
  143. __GLcolor fbcolors[__GL_MAX_STACKED_COLORS>>1];
  144. __GLcolor *vColors, *vFbcolors;
  145. length = gc->polygon.shader.length;
  146. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  147. {
  148. words = gcTempAlloc(gc, (length+__GL_STIPPLE_BITS-1)/8);
  149. if (words == NULL)
  150. {
  151. return GL_TRUE;
  152. }
  153. }
  154. else
  155. {
  156. words = stackWords;
  157. }
  158. if (length > (__GL_MAX_STACKED_COLORS>>1))
  159. {
  160. vColors = (__GLcolor *) gcTempAlloc(gc, length * sizeof(__GLcolor));
  161. if (NULL == vColors)
  162. {
  163. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  164. {
  165. gcTempFree(gc, words);
  166. }
  167. return GL_TRUE;
  168. }
  169. vFbcolors = (__GLcolor *) gcTempAlloc(gc, length * sizeof(__GLcolor));
  170. if (NULL == vFbcolors)
  171. {
  172. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  173. {
  174. gcTempFree(gc, words);
  175. }
  176. gcTempFree(gc, vColors);
  177. return GL_TRUE;
  178. }
  179. }
  180. else
  181. {
  182. vColors = colors;
  183. vFbcolors = fbcolors;
  184. }
  185. #else
  186. __GLcolor vColors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  187. __GLcolor vFbcolors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  188. __GLstippleWord words[__GL_MAX_STIPPLE_WORDS];
  189. #endif
  190. gc->polygon.shader.colors = vColors;
  191. gc->polygon.shader.fbcolors = vFbcolors;
  192. gc->polygon.shader.stipplePat = words;
  193. gc->polygon.shader.cfb = gc->drawBuffer;
  194. gc->polygon.shader.done = GL_FALSE;
  195. /* Call non-stippled procs... */
  196. if ((*gc->procs.line.lineFuncs[0])(gc)) {
  197. if (gc->polygon.shader.done)
  198. {
  199. retval = GL_TRUE;
  200. goto __glProcessLine3NWExit;
  201. }
  202. goto stippled1;
  203. }
  204. if ((*gc->procs.line.lineFuncs[1])(gc)) {
  205. if (gc->polygon.shader.done)
  206. {
  207. retval = GL_TRUE;
  208. goto __glProcessLine3NWExit;
  209. }
  210. goto stippled2;
  211. }
  212. retval = (*gc->procs.line.lineFuncs[2])(gc);
  213. goto __glProcessLine3NWExit;
  214. stippled1:
  215. if ((*gc->procs.line.stippledLineFuncs[1])(gc)) {
  216. retval = GL_TRUE;
  217. goto __glProcessLine3NWExit;
  218. }
  219. stippled2:
  220. retval = (*gc->procs.line.stippledLineFuncs[2])(gc);
  221. __glProcessLine3NWExit:
  222. #ifdef NT
  223. if (length > __GL_MAX_STACK_STIPPLE_BITS)
  224. {
  225. gcTempFree(gc, words);
  226. }
  227. if (length > (__GL_MAX_STACKED_COLORS>>1))
  228. {
  229. gcTempFree(gc, vColors);
  230. gcTempFree(gc, vFbcolors);
  231. }
  232. #endif
  233. return (retval);
  234. }
  235. /*
  236. ** Take incoming line, duplicate it, and continue processing.
  237. **
  238. ** Return value is ignored.
  239. */
  240. GLboolean FASTCALL __glWideLineRep(__GLcontext *gc)
  241. {
  242. GLint i, m, n, width;
  243. GLboolean stippling;
  244. n = gc->procs.line.n;
  245. m = gc->procs.line.m;
  246. width = gc->line.options.width;
  247. /* Step 2: Replicate wide line */
  248. while (--width >= 0) {
  249. stippling = GL_FALSE;
  250. for (i = n; i < m; i++) {
  251. if (stippling) {
  252. if ((*gc->procs.line.stippledLineFuncs[i])(gc)) {
  253. /* Line stippled away! */
  254. goto nextLine;
  255. }
  256. } else {
  257. if ((*gc->procs.line.lineFuncs[i])(gc)) {
  258. if (gc->polygon.shader.done) {
  259. gc->polygon.shader.done = GL_FALSE;
  260. goto nextLine;
  261. }
  262. stippling = GL_TRUE;
  263. }
  264. }
  265. }
  266. if (stippling) {
  267. (*gc->procs.line.drawStippledLine)(gc);
  268. } else {
  269. (*gc->procs.line.drawLine)(gc);
  270. }
  271. nextLine:
  272. if (gc->line.options.axis == __GL_X_MAJOR) {
  273. gc->line.options.yStart++;
  274. } else {
  275. gc->line.options.xStart++;
  276. }
  277. }
  278. return GL_FALSE;
  279. }
  280. /*
  281. ** Take incoming stippled line, duplicate it, and continue processing.
  282. **
  283. ** Return value is ignored.
  284. */
  285. GLboolean FASTCALL __glWideStippleLineRep(__GLcontext *gc)
  286. {
  287. GLint i, m, n, width;
  288. GLint stipLen;
  289. GLint w;
  290. __GLlineState *ls = &gc->state.line;
  291. __GLstippleWord *fsp, *tsp;
  292. #ifndef NT
  293. __GLstippleWord stipplePat[__GL_MAX_STIPPLE_WORDS];
  294. w = gc->polygon.shader.length;
  295. #else
  296. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  297. __GLstippleWord *stipplePat;
  298. w = gc->polygon.shader.length;
  299. if (w > __GL_MAX_STACK_STIPPLE_BITS)
  300. {
  301. stipplePat = gcTempAlloc(gc, (w+__GL_STIPPLE_BITS-1)/8);
  302. if (stipplePat == NULL)
  303. {
  304. return GL_TRUE;
  305. }
  306. }
  307. else
  308. {
  309. stipplePat = stackWords;
  310. }
  311. #endif
  312. n = gc->procs.line.n;
  313. m = gc->procs.line.m;
  314. width = ls->aliasedWidth;
  315. /*
  316. ** XXX - Saving the stipple like this is only really necessary if
  317. ** depth or stencil testing.
  318. */
  319. stipLen = (w + __GL_STIPPLE_BITS - 1) >> __GL_STIPPLE_COUNT_BITS;
  320. fsp = gc->polygon.shader.stipplePat;
  321. tsp = stipplePat;
  322. for (i = 0; i < stipLen; i++) {
  323. *tsp++ = *fsp++;
  324. }
  325. /* Step 2: Replicate wide line */
  326. while (--width >= 0) {
  327. for (i = n; i < m; i++) {
  328. if ((*gc->procs.line.stippledLineFuncs[i])(gc)) {
  329. /* Line stippled away! */
  330. goto nextLine;
  331. }
  332. }
  333. (*gc->procs.line.drawStippledLine)(gc);
  334. nextLine:
  335. if (width) {
  336. tsp = gc->polygon.shader.stipplePat;
  337. fsp = stipplePat;
  338. for (i = 0; i < stipLen; i++) {
  339. *tsp++ = *fsp++;
  340. }
  341. if (gc->line.options.axis == __GL_X_MAJOR) {
  342. gc->line.options.yStart++;
  343. } else {
  344. gc->line.options.xStart++;
  345. }
  346. }
  347. }
  348. #ifdef NT
  349. if (w > __GL_MAX_STACK_STIPPLE_BITS)
  350. {
  351. gcTempFree(gc, stipplePat);
  352. }
  353. #endif
  354. return GL_FALSE;
  355. }
  356. /*
  357. ** Take incoming line and draw it to both FRONT and BACK buffers.
  358. **
  359. ** This routines sets gc->polygon.shader.cfb to &gc->frontBuffer
  360. ** and then to &gc->backBuffer
  361. **
  362. ** Return value is ignored.
  363. */
  364. GLboolean FASTCALL __glDrawBothLine(__GLcontext *gc)
  365. {
  366. GLint i, j, m, l;
  367. GLboolean stippling;
  368. GLint w;
  369. __GLcolor *fcp, *tcp;
  370. #ifdef NT
  371. __GLcolor colors[__GL_MAX_STACKED_COLORS];
  372. __GLcolor *vColors;
  373. w = gc->polygon.shader.length;
  374. if (w > __GL_MAX_STACKED_COLORS)
  375. {
  376. vColors = (__GLcolor *) gcTempAlloc(gc, w * sizeof(__GLcolor));
  377. if (NULL == vColors)
  378. return GL_TRUE;
  379. }
  380. else
  381. {
  382. vColors = colors;
  383. }
  384. #else
  385. __GLcolor vColors[__GL_MAX_MAX_VIEWPORT];
  386. w = gc->polygon.shader.length;
  387. #endif
  388. m = gc->procs.line.m;
  389. l = gc->procs.line.l;
  390. /*
  391. ** XXX - Saving colors like this is only really necessary if blending,
  392. ** logicOping, or masking.
  393. */
  394. fcp = gc->polygon.shader.colors;
  395. tcp = vColors;
  396. if (gc->modes.rgbMode) {
  397. for (i = 0; i < w; i++) {
  398. *tcp++ = *fcp++;
  399. }
  400. } else {
  401. for (i = 0; i < w; i++) {
  402. tcp->r = fcp->r;
  403. fcp++;
  404. tcp++;
  405. }
  406. }
  407. /* Step 3: Draw to FRONT_AND_BACK */
  408. for (j = 0; j < 2; j++) {
  409. if (j == 0) {
  410. gc->polygon.shader.cfb = &gc->frontBuffer;
  411. } else {
  412. gc->polygon.shader.cfb = &gc->backBuffer;
  413. }
  414. stippling = GL_FALSE;
  415. for (i = m; i < l; i++) {
  416. if (stippling) {
  417. if ((*gc->procs.line.stippledLineFuncs[i])(gc)) {
  418. /* Line stippled away! */
  419. break;
  420. }
  421. } else {
  422. if ((*gc->procs.line.lineFuncs[i])(gc)) {
  423. if (gc->polygon.shader.done) {
  424. gc->polygon.shader.done = GL_FALSE;
  425. break;
  426. }
  427. stippling = GL_TRUE;
  428. }
  429. }
  430. }
  431. if (j == 0) {
  432. tcp = gc->polygon.shader.colors;
  433. fcp = vColors;
  434. if (gc->modes.rgbMode) {
  435. for (i = 0; i < w; i++) {
  436. *tcp++ = *fcp++;
  437. }
  438. } else {
  439. for (i = 0; i < w; i++) {
  440. tcp->r = fcp->r;
  441. fcp++;
  442. tcp++;
  443. }
  444. }
  445. }
  446. }
  447. #ifdef NT
  448. if (w > __GL_MAX_STACKED_COLORS)
  449. {
  450. gcTempFree(gc, vColors);
  451. }
  452. #endif
  453. return GL_FALSE;
  454. }
  455. /*
  456. ** Take incoming stippled line and draw it to both FRONT and BACK buffers.
  457. **
  458. ** Return value is ignored.
  459. */
  460. GLboolean FASTCALL __glDrawBothStippledLine(__GLcontext *gc)
  461. {
  462. GLint i, m, l, j;
  463. GLint stipLen;
  464. GLint w;
  465. __GLstippleWord *fsp, *tsp;
  466. __GLcolor *fcp, *tcp;
  467. #ifdef NT
  468. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  469. __GLstippleWord *stipplePat;
  470. __GLcolor colors[__GL_MAX_STACKED_COLORS];
  471. __GLcolor *vColors;
  472. w = gc->polygon.shader.length;
  473. if (w > __GL_MAX_STACK_STIPPLE_BITS)
  474. {
  475. stipplePat = gcTempAlloc(gc, (w+__GL_STIPPLE_BITS-1)/8);
  476. if (stipplePat == NULL)
  477. {
  478. return GL_TRUE;
  479. }
  480. }
  481. else
  482. {
  483. stipplePat = stackWords;
  484. }
  485. if (w > __GL_MAX_STACKED_COLORS)
  486. {
  487. vColors = (__GLcolor *) gcTempAlloc(gc, w * sizeof(__GLcolor));
  488. if (NULL == vColors)
  489. {
  490. if (w > __GL_MAX_STACK_STIPPLE_BITS)
  491. {
  492. gcTempFree(gc, stipplePat);
  493. }
  494. return GL_TRUE;
  495. }
  496. }
  497. else
  498. {
  499. vColors = colors;
  500. }
  501. #else
  502. __GLstippleWord stipplePat[__GL_MAX_STIPPLE_WORDS];
  503. __GLcolor vColors[__GL_MAX_MAX_VIEWPORT];
  504. w = gc->polygon.shader.length;
  505. #endif
  506. l = gc->procs.line.l;
  507. m = gc->procs.line.m;
  508. /*
  509. ** XXX - Saving colors like this is only really necessary if blending,
  510. ** logicOping, or masking, and not drawing to FRONT_AND_BACK (because
  511. ** if we are, then that proc will save colors too)
  512. */
  513. fcp = gc->polygon.shader.colors;
  514. tcp = vColors;
  515. if (gc->modes.rgbMode) {
  516. for (i = 0; i < w; i++) {
  517. *tcp++ = *fcp++;
  518. }
  519. } else {
  520. for (i = 0; i < w; i++) {
  521. tcp->r = fcp->r;
  522. fcp++;
  523. tcp++;
  524. }
  525. }
  526. /*
  527. ** XXX - Saving the stipple like this is only really necessary if
  528. ** depth or stencil testing.
  529. */
  530. stipLen = (w + __GL_STIPPLE_BITS - 1) >> __GL_STIPPLE_COUNT_BITS;
  531. fsp = gc->polygon.shader.stipplePat;
  532. tsp = stipplePat;
  533. for (i = 0; i < stipLen; i++) {
  534. *tsp++ = *fsp++;
  535. }
  536. /* Step 2: Replicate wide line */
  537. for (j = 0; j < 2; j++) {
  538. if (j == 0) {
  539. gc->polygon.shader.cfb = &gc->frontBuffer;
  540. } else {
  541. gc->polygon.shader.cfb = &gc->backBuffer;
  542. }
  543. for (i = m; i < l; i++) {
  544. if ((*gc->procs.line.stippledLineFuncs[i])(gc)) {
  545. /* Line stippled away! */
  546. break;
  547. }
  548. }
  549. if (j == 0) {
  550. tcp = gc->polygon.shader.colors;
  551. fcp = vColors;
  552. if (gc->modes.rgbMode) {
  553. for (i = 0; i < w; i++) {
  554. *tcp++ = *fcp++;
  555. }
  556. } else {
  557. for (i = 0; i < w; i++) {
  558. tcp->r = fcp->r;
  559. fcp++;
  560. tcp++;
  561. }
  562. }
  563. tsp = gc->polygon.shader.stipplePat;
  564. fsp = stipplePat;
  565. for (i = 0; i < stipLen; i++) {
  566. *tsp++ = *fsp++;
  567. }
  568. }
  569. }
  570. #ifdef NT
  571. if (w > __GL_MAX_STACK_STIPPLE_BITS)
  572. {
  573. gcTempFree(gc, stipplePat);
  574. }
  575. if (w > __GL_MAX_STACKED_COLORS)
  576. {
  577. gcTempFree(gc, vColors);
  578. }
  579. #endif
  580. return GL_FALSE;
  581. }
  582. GLboolean FASTCALL __glScissorLine(__GLcontext *gc)
  583. {
  584. GLint clipX0, clipX1;
  585. GLint clipY0, clipY1;
  586. GLint xStart, yStart, xEnd, yEnd;
  587. GLint xLittle, yLittle;
  588. GLint xBig, yBig;
  589. GLint fraction, dfraction;
  590. GLint highWord, lowWord;
  591. GLint bigs, littles;
  592. GLint failed, count;
  593. GLint w;
  594. __GLstippleWord bit, outMask, *osp;
  595. w = gc->polygon.shader.length;
  596. clipX0 = gc->transform.clipX0;
  597. clipX1 = gc->transform.clipX1;
  598. clipY0 = gc->transform.clipY0;
  599. clipY1 = gc->transform.clipY1;
  600. xBig = gc->line.options.xBig;
  601. yBig = gc->line.options.yBig;
  602. xStart = gc->line.options.xStart;
  603. yStart = gc->line.options.yStart;
  604. /* If the start point is in the scissor region, we attempt to trivially
  605. ** accept the line.
  606. */
  607. if (xStart >= clipX0 && xStart < clipX1 &&
  608. yStart >= clipY0 && yStart < clipY1) {
  609. w--; /* Makes our math simpler */
  610. /* Trivial accept attempt */
  611. xEnd = xStart + xBig * w;
  612. yEnd = yStart + yBig * w;
  613. if (xEnd >= clipX0 && xEnd < clipX1 &&
  614. yEnd >= clipY0 && yEnd < clipY1) {
  615. return GL_FALSE;
  616. }
  617. xLittle = gc->line.options.xLittle;
  618. yLittle = gc->line.options.yLittle;
  619. fraction = gc->line.options.fraction;
  620. dfraction = gc->line.options.dfraction;
  621. /* Invert negative minor slopes so we can assume dfraction > 0 */
  622. if (dfraction < 0) {
  623. dfraction = -dfraction;
  624. fraction = 0x7fffffff - fraction;
  625. }
  626. /* Now we compute number of littles and bigs in this line */
  627. /* We perform a 16 by 32 bit multiply. Ugh. */
  628. highWord = (((GLuint) dfraction) >> 16) * w +
  629. (((GLuint) fraction) >> 16);
  630. lowWord = (dfraction & 0xffff) * w + (fraction & 0xffff);
  631. highWord += (((GLuint) lowWord) >> 16);
  632. bigs = ((GLuint) highWord) >> 15;
  633. littles = w - bigs;
  634. /* Second trivial accept attempt */
  635. xEnd = xStart + xBig*bigs + xLittle*littles;
  636. yEnd = yStart + yBig*bigs + yLittle*littles;
  637. if (xEnd >= clipX0 && xEnd < clipX1 &&
  638. yEnd >= clipY0 && yEnd < clipY1) {
  639. return GL_FALSE;
  640. }
  641. w++; /* Restore w */
  642. } else {
  643. xLittle = gc->line.options.xLittle;
  644. yLittle = gc->line.options.yLittle;
  645. fraction = gc->line.options.fraction;
  646. dfraction = gc->line.options.dfraction;
  647. }
  648. /*
  649. ** Note that we don't bother to try trivially rejecting this line. After
  650. ** all, it has already been clipped, and the only way that it might
  651. ** possibly be trivially rejected is if it is a piece of a wide line that
  652. ** runs right along the edge of the window.
  653. */
  654. /*
  655. ** This sucks. The line needs to be scissored.
  656. ** Well, it should only happen rarely, so we can afford
  657. ** to make it slow. We achieve this by tediously stippling the line.
  658. ** (rather than clipping it, of course, which would be faster but harder).
  659. */
  660. failed = 0;
  661. osp = gc->polygon.shader.stipplePat;
  662. while (w) {
  663. count = w;
  664. if (count > __GL_STIPPLE_BITS) {
  665. count = __GL_STIPPLE_BITS;
  666. }
  667. w -= count;
  668. outMask = (__GLstippleWord) ~0;
  669. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  670. while (--count >= 0) {
  671. if (xStart < clipX0 || xStart >= clipX1 ||
  672. yStart < clipY0 || yStart >= clipY1) {
  673. outMask &= ~bit;
  674. failed++;
  675. }
  676. fraction += dfraction;
  677. if (fraction < 0) {
  678. fraction &= ~0x80000000;
  679. xStart += xBig;
  680. yStart += yBig;
  681. } else {
  682. xStart += xLittle;
  683. yStart += yLittle;
  684. }
  685. #ifdef __GL_STIPPLE_MSB
  686. bit >>= 1;
  687. #else
  688. bit <<= 1;
  689. #endif
  690. }
  691. *osp++ = outMask;
  692. }
  693. if (failed != gc->polygon.shader.length) {
  694. /* Call next proc */
  695. return GL_TRUE;
  696. }
  697. gc->polygon.shader.done = GL_TRUE;
  698. return GL_TRUE;
  699. }
  700. GLboolean FASTCALL __glScissorStippledLine(__GLcontext *gc)
  701. {
  702. GLint clipX0, clipX1;
  703. GLint clipY0, clipY1;
  704. GLint xStart, yStart, xEnd, yEnd;
  705. GLint xLittle, yLittle;
  706. GLint xBig, yBig;
  707. GLint fraction, dfraction;
  708. GLint highWord, lowWord;
  709. GLint bigs, littles;
  710. GLint failed, count;
  711. GLint w;
  712. __GLstippleWord *sp;
  713. __GLstippleWord bit, outMask, inMask;
  714. w = gc->polygon.shader.length;
  715. clipX0 = gc->transform.clipX0;
  716. clipX1 = gc->transform.clipX1;
  717. clipY0 = gc->transform.clipY0;
  718. clipY1 = gc->transform.clipY1;
  719. xBig = gc->line.options.xBig;
  720. yBig = gc->line.options.yBig;
  721. xStart = gc->line.options.xStart;
  722. yStart = gc->line.options.yStart;
  723. /* If the start point is in the scissor region, we attempt to trivially
  724. ** accept the line.
  725. */
  726. if (xStart >= clipX0 && xStart < clipX1 &&
  727. yStart >= clipY0 && yStart < clipY1) {
  728. w--; /* Makes our math simpler */
  729. /* Trivial accept attempt */
  730. xEnd = xStart + xBig * w;
  731. yEnd = yStart + yBig * w;
  732. if (xEnd >= clipX0 && xEnd < clipX1 &&
  733. yEnd >= clipY0 && yEnd < clipY1) {
  734. return GL_FALSE;
  735. }
  736. xLittle = gc->line.options.xLittle;
  737. yLittle = gc->line.options.yLittle;
  738. fraction = gc->line.options.fraction;
  739. dfraction = gc->line.options.dfraction;
  740. /* Invert negative minor slopes so we can assume dfraction > 0 */
  741. if (dfraction < 0) {
  742. dfraction = -dfraction;
  743. fraction = 0x7fffffff - fraction;
  744. }
  745. /* Now we compute number of littles and bigs in this line */
  746. /* We perform a 16 by 32 bit multiply. Ugh. */
  747. highWord = (((GLuint) dfraction) >> 16) * w +
  748. (((GLuint) fraction) >> 16);
  749. lowWord = (dfraction & 0xffff) * w + (fraction & 0xffff);
  750. highWord += (((GLuint) lowWord) >> 16);
  751. bigs = ((GLuint) highWord) >> 15;
  752. littles = w - bigs;
  753. /* Second trivial accept attempt */
  754. xEnd = xStart + xBig*bigs + xLittle*littles;
  755. yEnd = yStart + yBig*bigs + yLittle*littles;
  756. if (xEnd >= clipX0 && xEnd < clipX1 &&
  757. yEnd >= clipY0 && yEnd < clipY1) {
  758. return GL_FALSE;
  759. }
  760. w++; /* Restore w */
  761. } else {
  762. xLittle = gc->line.options.xLittle;
  763. yLittle = gc->line.options.yLittle;
  764. fraction = gc->line.options.fraction;
  765. dfraction = gc->line.options.dfraction;
  766. }
  767. /*
  768. ** Note that we don't bother to try trivially rejecting this line. After
  769. ** all, it has already been clipped, and the only way that it might
  770. ** possibly be trivially rejected is if it is a piece of a wide line that
  771. ** runs right along the edge of the window.
  772. */
  773. /*
  774. ** This sucks. The line needs to be scissored.
  775. ** Well, it should only happen rarely, so we can afford
  776. ** to make it slow. We achieve this by tediously stippling the line.
  777. ** (rather than clipping it, of course, which would be faster but harder).
  778. */
  779. sp = gc->polygon.shader.stipplePat;
  780. failed = 0;
  781. while (w) {
  782. count = w;
  783. if (count > __GL_STIPPLE_BITS) {
  784. count = __GL_STIPPLE_BITS;
  785. }
  786. w -= count;
  787. inMask = *sp;
  788. outMask = (__GLstippleWord) ~0;
  789. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  790. while (--count >= 0) {
  791. if (inMask & bit) {
  792. if (xStart < clipX0 || xStart >= clipX1 ||
  793. yStart < clipY0 || yStart >= clipY1) {
  794. outMask &= ~bit;
  795. failed++;
  796. }
  797. } else failed++;
  798. fraction += dfraction;
  799. if (fraction < 0) {
  800. fraction &= ~0x80000000;
  801. xStart += xBig;
  802. yStart += yBig;
  803. } else {
  804. xStart += xLittle;
  805. yStart += yLittle;
  806. }
  807. #ifdef __GL_STIPPLE_MSB
  808. bit >>= 1;
  809. #else
  810. bit <<= 1;
  811. #endif
  812. }
  813. *sp++ = outMask & inMask;
  814. }
  815. if (failed != gc->polygon.shader.length) {
  816. /* Call next proc */
  817. return GL_FALSE;
  818. }
  819. return GL_TRUE;
  820. }
  821. /*
  822. ** Create a stipple based upon the current line stipple for this line.
  823. */
  824. GLboolean FASTCALL __glStippleLine(__GLcontext *gc)
  825. {
  826. GLint failed, count, stippleRepeat;
  827. GLint stipple, currentBit, stipplePos, repeat;
  828. __GLstippleWord bit, outMask, *osp;
  829. __GLlineState *ls = &gc->state.line;
  830. GLint w;
  831. w = gc->polygon.shader.length;
  832. osp = gc->polygon.shader.stipplePat;
  833. repeat = gc->line.repeat;
  834. stippleRepeat = ls->stippleRepeat;
  835. stipplePos = gc->line.stipplePosition;
  836. currentBit = 1 << stipplePos;
  837. stipple = ls->stipple;
  838. failed = 0;
  839. while (w) {
  840. count = w;
  841. if (count > __GL_STIPPLE_BITS) {
  842. count = __GL_STIPPLE_BITS;
  843. }
  844. w -= count;
  845. outMask = (__GLstippleWord) ~0;
  846. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  847. while (--count >= 0) {
  848. if ((stipple & currentBit) == 0) {
  849. /* Stippled fragment away */
  850. outMask &= ~bit;
  851. failed++;
  852. }
  853. if (++repeat >= stippleRepeat) {
  854. stipplePos = (stipplePos + 1) & 0xf;
  855. currentBit = 1 << stipplePos;
  856. repeat = 0;
  857. }
  858. #ifdef __GL_STIPPLE_MSB
  859. bit >>= 1;
  860. #else
  861. bit <<= 1;
  862. #endif
  863. }
  864. *osp++ = outMask;
  865. }
  866. gc->line.repeat = repeat;
  867. gc->line.stipplePosition = stipplePos;
  868. if (failed == 0) {
  869. return GL_FALSE;
  870. } else if (failed != gc->polygon.shader.length) {
  871. return GL_TRUE;
  872. }
  873. gc->polygon.shader.done = GL_TRUE;
  874. return GL_TRUE;
  875. }
  876. /*
  877. ** Apply the stencil test to this line.
  878. */
  879. GLboolean FASTCALL __glStencilTestLine(__GLcontext *gc)
  880. {
  881. __GLstencilCell *tft, *sfb, *fail, cell;
  882. GLint xLittle, xBig, yLittle, yBig;
  883. GLint fraction, dfraction;
  884. GLint dspLittle, dspBig;
  885. GLint count, failed;
  886. __GLstippleWord bit, outMask, *osp;
  887. GLuint smask;
  888. GLint w;
  889. w = gc->polygon.shader.length;
  890. xBig = gc->line.options.xBig;
  891. yBig = gc->line.options.yBig;
  892. xLittle = gc->line.options.xLittle;
  893. yLittle = gc->line.options.yLittle;
  894. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  895. gc->line.options.xStart, gc->line.options.yStart);
  896. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  897. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  898. fraction = gc->line.options.fraction;
  899. dfraction = gc->line.options.dfraction;
  900. tft = gc->stencilBuffer.testFuncTable;
  901. #ifdef NT
  902. if (!tft)
  903. return GL_FALSE;
  904. #endif // NT
  905. fail = gc->stencilBuffer.failOpTable;
  906. smask = gc->state.stencil.mask;
  907. osp = gc->polygon.shader.stipplePat;
  908. failed = 0;
  909. while (w) {
  910. count = w;
  911. if (count > __GL_STIPPLE_BITS) {
  912. count = __GL_STIPPLE_BITS;
  913. }
  914. w -= count;
  915. outMask = (__GLstippleWord) ~0;
  916. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  917. while (--count >= 0) {
  918. cell = sfb[0];
  919. if (!tft[cell & smask]) {
  920. /* Test failed */
  921. outMask &= ~bit;
  922. sfb[0] = fail[cell];
  923. failed++;
  924. }
  925. fraction += dfraction;
  926. if (fraction < 0) {
  927. fraction &= ~0x80000000;
  928. sfb += dspBig;
  929. } else {
  930. sfb += dspLittle;
  931. }
  932. #ifdef __GL_STIPPLE_MSB
  933. bit >>= 1;
  934. #else
  935. bit <<= 1;
  936. #endif
  937. }
  938. *osp++ = outMask;
  939. }
  940. if (failed == 0) {
  941. return GL_FALSE;
  942. } else {
  943. if (failed != gc->polygon.shader.length) {
  944. /* Call next proc */
  945. return GL_TRUE;
  946. }
  947. }
  948. gc->polygon.shader.done = GL_TRUE;
  949. return GL_TRUE;
  950. }
  951. /*
  952. ** Apply the stencil test to this stippled line.
  953. */
  954. GLboolean FASTCALL __glStencilTestStippledLine(__GLcontext *gc)
  955. {
  956. __GLstencilCell *tft, *sfb, *fail, cell;
  957. GLint xLittle, xBig, yLittle, yBig;
  958. GLint fraction, dfraction;
  959. GLint count, failed;
  960. __GLstippleWord bit, inMask, outMask, *sp;
  961. GLint dspLittle, dspBig;
  962. GLuint smask;
  963. GLint w;
  964. w = gc->polygon.shader.length;
  965. sp = gc->polygon.shader.stipplePat;
  966. xBig = gc->line.options.xBig;
  967. yBig = gc->line.options.yBig;
  968. xLittle = gc->line.options.xLittle;
  969. yLittle = gc->line.options.yLittle;
  970. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  971. gc->line.options.xStart, gc->line.options.yStart);
  972. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  973. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  974. fraction = gc->line.options.fraction;
  975. dfraction = gc->line.options.dfraction;
  976. tft = gc->stencilBuffer.testFuncTable;
  977. #ifdef NT
  978. if (!tft)
  979. return GL_FALSE;
  980. #endif // NT
  981. fail = gc->stencilBuffer.failOpTable;
  982. smask = gc->state.stencil.mask;
  983. failed = 0;
  984. while (w) {
  985. count = w;
  986. if (count > __GL_STIPPLE_BITS) {
  987. count = __GL_STIPPLE_BITS;
  988. }
  989. w -= count;
  990. inMask = *sp;
  991. outMask = (__GLstippleWord) ~0;
  992. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  993. while (--count >= 0) {
  994. if (inMask & bit) {
  995. cell = sfb[0];
  996. if (!tft[cell & smask]) {
  997. /* Test failed */
  998. outMask &= ~bit;
  999. sfb[0] = fail[cell];
  1000. failed++;
  1001. }
  1002. } else failed++;
  1003. fraction += dfraction;
  1004. if (fraction < 0) {
  1005. fraction &= ~0x80000000;
  1006. sfb += dspBig;
  1007. } else {
  1008. sfb += dspLittle;
  1009. }
  1010. #ifdef __GL_STIPPLE_MSB
  1011. bit >>= 1;
  1012. #else
  1013. bit <<= 1;
  1014. #endif
  1015. }
  1016. *sp++ = outMask & inMask;
  1017. }
  1018. if (failed != gc->polygon.shader.length) {
  1019. /* Call next proc */
  1020. return GL_FALSE;
  1021. }
  1022. return GL_TRUE;
  1023. }
  1024. #ifndef __GL_USEASMCODE
  1025. GLboolean FASTCALL __glDepthTestLine(__GLcontext *gc)
  1026. {
  1027. __GLzValue z, dzdx, *zfb;
  1028. GLint xLittle, xBig, yLittle, yBig;
  1029. GLint fraction, dfraction;
  1030. GLint dzpLittle, dzpBig;
  1031. GLint failed, count, testFunc;
  1032. __GLstippleWord bit, outMask, *osp;
  1033. GLboolean writeEnabled, passed;
  1034. GLint w;
  1035. w = gc->polygon.shader.length;
  1036. xBig = gc->line.options.xBig;
  1037. yBig = gc->line.options.yBig;
  1038. xLittle = gc->line.options.xLittle;
  1039. yLittle = gc->line.options.yLittle;
  1040. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  1041. gc->line.options.xStart, gc->line.options.yStart);
  1042. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1043. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1044. fraction = gc->line.options.fraction;
  1045. dfraction = gc->line.options.dfraction;
  1046. testFunc = gc->state.depth.testFunc & 0x7;
  1047. z = gc->polygon.shader.frag.z;
  1048. dzdx = gc->polygon.shader.dzdx;
  1049. writeEnabled = gc->state.depth.writeEnable;
  1050. osp = gc->polygon.shader.stipplePat;
  1051. failed = 0;
  1052. while (w) {
  1053. count = w;
  1054. if (count > __GL_STIPPLE_BITS) {
  1055. count = __GL_STIPPLE_BITS;
  1056. }
  1057. w -= count;
  1058. outMask = (__GLstippleWord) ~0;
  1059. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1060. while (--count >= 0) {
  1061. switch (testFunc) {
  1062. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1063. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1064. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1065. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1066. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1067. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1068. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1069. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1070. }
  1071. if (passed) {
  1072. if (writeEnabled) {
  1073. zfb[0] = z;
  1074. }
  1075. } else {
  1076. outMask &= ~bit;
  1077. failed++;
  1078. }
  1079. z += dzdx;
  1080. fraction += dfraction;
  1081. if (fraction < 0) {
  1082. fraction &= ~0x80000000;
  1083. zfb += dzpBig;
  1084. } else {
  1085. zfb += dzpLittle;
  1086. }
  1087. #ifdef __GL_STIPPLE_MSB
  1088. bit >>= 1;
  1089. #else
  1090. bit <<= 1;
  1091. #endif
  1092. }
  1093. *osp++ = outMask;
  1094. }
  1095. if (failed == 0) {
  1096. /* Call next span proc */
  1097. return GL_FALSE;
  1098. } else {
  1099. if (failed != gc->polygon.shader.length) {
  1100. /* Call next stippled span proc */
  1101. return GL_TRUE;
  1102. }
  1103. }
  1104. gc->polygon.shader.done = GL_TRUE;
  1105. return GL_TRUE;
  1106. }
  1107. #endif
  1108. GLboolean FASTCALL __glDepthTestStippledLine(__GLcontext *gc)
  1109. {
  1110. __GLzValue z, dzdx, *zfb;
  1111. GLint xLittle, xBig, yLittle, yBig;
  1112. GLint fraction, dfraction;
  1113. GLint dzpLittle, dzpBig;
  1114. GLint failed, count, testFunc;
  1115. __GLstippleWord bit, inMask, outMask, *sp;
  1116. GLboolean writeEnabled, passed;
  1117. GLint w;
  1118. w = gc->polygon.shader.length;
  1119. sp = gc->polygon.shader.stipplePat;
  1120. xBig = gc->line.options.xBig;
  1121. yBig = gc->line.options.yBig;
  1122. xLittle = gc->line.options.xLittle;
  1123. yLittle = gc->line.options.yLittle;
  1124. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  1125. gc->line.options.xStart, gc->line.options.yStart);
  1126. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1127. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1128. fraction = gc->line.options.fraction;
  1129. dfraction = gc->line.options.dfraction;
  1130. testFunc = gc->state.depth.testFunc & 0x7;
  1131. z = gc->polygon.shader.frag.z;
  1132. dzdx = gc->polygon.shader.dzdx;
  1133. writeEnabled = gc->state.depth.writeEnable;
  1134. failed = 0;
  1135. while (w) {
  1136. count = w;
  1137. if (count > __GL_STIPPLE_BITS) {
  1138. count = __GL_STIPPLE_BITS;
  1139. }
  1140. w -= count;
  1141. inMask = *sp;
  1142. outMask = (__GLstippleWord) ~0;
  1143. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1144. while (--count >= 0) {
  1145. if (inMask & bit) {
  1146. switch (testFunc) {
  1147. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1148. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1149. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1150. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1151. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1152. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1153. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1154. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1155. }
  1156. if (passed) {
  1157. if (writeEnabled) {
  1158. zfb[0] = z;
  1159. }
  1160. } else {
  1161. outMask &= ~bit;
  1162. failed++;
  1163. }
  1164. } else failed++;
  1165. z += dzdx;
  1166. fraction += dfraction;
  1167. if (fraction < 0) {
  1168. fraction &= ~0x80000000;
  1169. zfb += dzpBig;
  1170. } else {
  1171. zfb += dzpLittle;
  1172. }
  1173. #ifdef __GL_STIPPLE_MSB
  1174. bit >>= 1;
  1175. #else
  1176. bit <<= 1;
  1177. #endif
  1178. }
  1179. *sp++ = outMask & inMask;
  1180. }
  1181. if (failed != gc->polygon.shader.length) {
  1182. /* Call next proc */
  1183. return GL_FALSE;
  1184. }
  1185. return GL_TRUE;
  1186. }
  1187. GLboolean FASTCALL __glDepthTestStencilLine(__GLcontext *gc)
  1188. {
  1189. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1190. GLint xLittle, xBig, yLittle, yBig;
  1191. GLint fraction, dfraction;
  1192. GLint dzpLittle, dzpBig;
  1193. GLint dspLittle, dspBig;
  1194. __GLzValue z, dzdx, *zfb;
  1195. GLint failed, count, testFunc;
  1196. __GLstippleWord bit, outMask, *osp;
  1197. GLboolean writeEnabled, passed;
  1198. GLint w;
  1199. w = gc->polygon.shader.length;
  1200. xBig = gc->line.options.xBig;
  1201. yBig = gc->line.options.yBig;
  1202. xLittle = gc->line.options.xLittle;
  1203. yLittle = gc->line.options.yLittle;
  1204. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  1205. gc->line.options.xStart, gc->line.options.yStart);
  1206. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1207. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1208. fraction = gc->line.options.fraction;
  1209. dfraction = gc->line.options.dfraction;
  1210. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1211. gc->line.options.xStart, gc->line.options.yStart);
  1212. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1213. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1214. fraction = gc->line.options.fraction;
  1215. dfraction = gc->line.options.dfraction;
  1216. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1217. #ifdef NT
  1218. if (!zFailOp)
  1219. return GL_FALSE;
  1220. #endif // NT
  1221. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1222. testFunc = gc->state.depth.testFunc & 0x7;
  1223. z = gc->polygon.shader.frag.z;
  1224. dzdx = gc->polygon.shader.dzdx;
  1225. writeEnabled = gc->state.depth.writeEnable;
  1226. osp = gc->polygon.shader.stipplePat;
  1227. failed = 0;
  1228. while (w) {
  1229. count = w;
  1230. if (count > __GL_STIPPLE_BITS) {
  1231. count = __GL_STIPPLE_BITS;
  1232. }
  1233. w -= count;
  1234. outMask = (__GLstippleWord) ~0;
  1235. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1236. while (--count >= 0) {
  1237. switch (testFunc) {
  1238. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1239. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1240. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1241. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1242. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1243. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1244. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1245. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1246. }
  1247. if (passed) {
  1248. sfb[0] = zPassOp[sfb[0]];
  1249. if (writeEnabled) {
  1250. zfb[0] = z;
  1251. }
  1252. } else {
  1253. sfb[0] = zFailOp[sfb[0]];
  1254. outMask &= ~bit;
  1255. failed++;
  1256. }
  1257. z += dzdx;
  1258. fraction += dfraction;
  1259. if (fraction < 0) {
  1260. fraction &= ~0x80000000;
  1261. zfb += dzpBig;
  1262. sfb += dspBig;
  1263. } else {
  1264. zfb += dzpLittle;
  1265. sfb += dspLittle;
  1266. }
  1267. #ifdef __GL_STIPPLE_MSB
  1268. bit >>= 1;
  1269. #else
  1270. bit <<= 1;
  1271. #endif
  1272. }
  1273. *osp++ = outMask;
  1274. }
  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. GLboolean FASTCALL __glDepthTestStencilStippledLine(__GLcontext *gc)
  1288. {
  1289. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1290. GLint xLittle, xBig, yLittle, yBig;
  1291. GLint fraction, dfraction;
  1292. GLint dzpLittle, dzpBig;
  1293. GLint dspLittle, dspBig;
  1294. __GLzValue z, dzdx, *zfb;
  1295. GLint failed, count, testFunc;
  1296. __GLstippleWord bit, inMask, outMask, *sp;
  1297. GLboolean writeEnabled, passed;
  1298. GLint w;
  1299. w = gc->polygon.shader.length;
  1300. sp = gc->polygon.shader.stipplePat;
  1301. xBig = gc->line.options.xBig;
  1302. yBig = gc->line.options.yBig;
  1303. xLittle = gc->line.options.xLittle;
  1304. yLittle = gc->line.options.yLittle;
  1305. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  1306. gc->line.options.xStart, gc->line.options.yStart);
  1307. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1308. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1309. fraction = gc->line.options.fraction;
  1310. dfraction = gc->line.options.dfraction;
  1311. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1312. gc->line.options.xStart, gc->line.options.yStart);
  1313. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1314. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1315. fraction = gc->line.options.fraction;
  1316. dfraction = gc->line.options.dfraction;
  1317. testFunc = gc->state.depth.testFunc & 0x7;
  1318. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1319. #ifdef NT
  1320. if (!zFailOp)
  1321. return GL_FALSE;
  1322. #endif // NT
  1323. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1324. z = gc->polygon.shader.frag.z;
  1325. dzdx = gc->polygon.shader.dzdx;
  1326. writeEnabled = gc->state.depth.writeEnable;
  1327. failed = 0;
  1328. while (w) {
  1329. count = w;
  1330. if (count > __GL_STIPPLE_BITS) {
  1331. count = __GL_STIPPLE_BITS;
  1332. }
  1333. w -= count;
  1334. inMask = *sp;
  1335. outMask = (__GLstippleWord) ~0;
  1336. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1337. while (--count >= 0) {
  1338. if (inMask & bit) {
  1339. switch (testFunc) {
  1340. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1341. case (GL_LESS & 0x7): passed = z < zfb[0]; break;
  1342. case (GL_EQUAL & 0x7): passed = z == zfb[0]; break;
  1343. case (GL_LEQUAL & 0x7): passed = z <= zfb[0]; break;
  1344. case (GL_GREATER & 0x7): passed = z > zfb[0]; break;
  1345. case (GL_NOTEQUAL & 0x7): passed = z != zfb[0]; break;
  1346. case (GL_GEQUAL & 0x7): passed = z >= zfb[0]; break;
  1347. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1348. }
  1349. if (passed) {
  1350. sfb[0] = zPassOp[sfb[0]];
  1351. if (writeEnabled) {
  1352. zfb[0] = z;
  1353. }
  1354. } else {
  1355. sfb[0] = zFailOp[sfb[0]];
  1356. outMask &= ~bit;
  1357. failed++;
  1358. }
  1359. } else failed++;
  1360. z += dzdx;
  1361. fraction += dfraction;
  1362. if (fraction < 0) {
  1363. fraction &= ~0x80000000;
  1364. zfb += dzpBig;
  1365. sfb += dspBig;
  1366. } else {
  1367. zfb += dzpLittle;
  1368. sfb += dspLittle;
  1369. }
  1370. #ifdef __GL_STIPPLE_MSB
  1371. bit >>= 1;
  1372. #else
  1373. bit <<= 1;
  1374. #endif
  1375. }
  1376. *sp++ = outMask & inMask;
  1377. }
  1378. if (failed != gc->polygon.shader.length) {
  1379. /* Call next proc */
  1380. return GL_FALSE;
  1381. }
  1382. return GL_TRUE;
  1383. }
  1384. #ifdef NT
  1385. GLboolean FASTCALL __glDepth16TestLine(__GLcontext *gc)
  1386. {
  1387. __GLzValue z, dzdx;
  1388. __GLz16Value z16, *zfb;
  1389. GLint xLittle, xBig, yLittle, yBig;
  1390. GLint fraction, dfraction;
  1391. GLint dzpLittle, dzpBig;
  1392. GLint failed, count, testFunc;
  1393. __GLstippleWord bit, outMask, *osp;
  1394. GLboolean writeEnabled, passed;
  1395. GLint w;
  1396. w = gc->polygon.shader.length;
  1397. xBig = gc->line.options.xBig;
  1398. yBig = gc->line.options.yBig;
  1399. xLittle = gc->line.options.xLittle;
  1400. yLittle = gc->line.options.yLittle;
  1401. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLz16Value*),
  1402. gc->line.options.xStart, gc->line.options.yStart);
  1403. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1404. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1405. fraction = gc->line.options.fraction;
  1406. dfraction = gc->line.options.dfraction;
  1407. testFunc = gc->state.depth.testFunc & 0x7;
  1408. z = gc->polygon.shader.frag.z;
  1409. dzdx = gc->polygon.shader.dzdx;
  1410. writeEnabled = gc->state.depth.writeEnable;
  1411. osp = gc->polygon.shader.stipplePat;
  1412. failed = 0;
  1413. while (w) {
  1414. count = w;
  1415. if (count > __GL_STIPPLE_BITS) {
  1416. count = __GL_STIPPLE_BITS;
  1417. }
  1418. w -= count;
  1419. outMask = (__GLstippleWord) ~0;
  1420. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1421. while (--count >= 0) {
  1422. z16 = z >> Z16_SHIFT;
  1423. switch (testFunc) {
  1424. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1425. case (GL_LESS & 0x7): passed = z16 < zfb[0]; break;
  1426. case (GL_EQUAL & 0x7): passed = z16 == zfb[0]; break;
  1427. case (GL_LEQUAL & 0x7): passed = z16 <= zfb[0]; break;
  1428. case (GL_GREATER & 0x7): passed = z16 > zfb[0]; break;
  1429. case (GL_NOTEQUAL & 0x7): passed = z16 != zfb[0]; break;
  1430. case (GL_GEQUAL & 0x7): passed = z16 >= zfb[0]; break;
  1431. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1432. }
  1433. if (passed) {
  1434. if (writeEnabled) {
  1435. zfb[0] = z16;
  1436. }
  1437. } else {
  1438. outMask &= ~bit;
  1439. failed++;
  1440. }
  1441. z += dzdx;
  1442. fraction += dfraction;
  1443. if (fraction < 0) {
  1444. fraction &= ~0x80000000;
  1445. zfb += dzpBig;
  1446. } else {
  1447. zfb += dzpLittle;
  1448. }
  1449. #ifdef __GL_STIPPLE_MSB
  1450. bit >>= 1;
  1451. #else
  1452. bit <<= 1;
  1453. #endif
  1454. }
  1455. *osp++ = outMask;
  1456. }
  1457. if (failed == 0) {
  1458. /* Call next span proc */
  1459. return GL_FALSE;
  1460. } else {
  1461. if (failed != gc->polygon.shader.length) {
  1462. /* Call next stippled span proc */
  1463. return GL_TRUE;
  1464. }
  1465. }
  1466. gc->polygon.shader.done = GL_TRUE;
  1467. return GL_TRUE;
  1468. }
  1469. GLboolean FASTCALL __glDepth16TestStippledLine(__GLcontext *gc)
  1470. {
  1471. __GLzValue z, dzdx;
  1472. __GLz16Value z16, *zfb;
  1473. GLint xLittle, xBig, yLittle, yBig;
  1474. GLint fraction, dfraction;
  1475. GLint dzpLittle, dzpBig;
  1476. GLint failed, count, testFunc;
  1477. __GLstippleWord bit, inMask, outMask, *sp;
  1478. GLboolean writeEnabled, passed;
  1479. GLint w;
  1480. w = gc->polygon.shader.length;
  1481. sp = gc->polygon.shader.stipplePat;
  1482. xBig = gc->line.options.xBig;
  1483. yBig = gc->line.options.yBig;
  1484. xLittle = gc->line.options.xLittle;
  1485. yLittle = gc->line.options.yLittle;
  1486. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLz16Value*),
  1487. gc->line.options.xStart, gc->line.options.yStart);
  1488. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1489. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1490. fraction = gc->line.options.fraction;
  1491. dfraction = gc->line.options.dfraction;
  1492. testFunc = gc->state.depth.testFunc & 0x7;
  1493. z = gc->polygon.shader.frag.z;
  1494. dzdx = gc->polygon.shader.dzdx;
  1495. writeEnabled = gc->state.depth.writeEnable;
  1496. failed = 0;
  1497. while (w) {
  1498. count = w;
  1499. if (count > __GL_STIPPLE_BITS) {
  1500. count = __GL_STIPPLE_BITS;
  1501. }
  1502. w -= count;
  1503. inMask = *sp;
  1504. outMask = (__GLstippleWord) ~0;
  1505. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1506. while (--count >= 0) {
  1507. if (inMask & bit) {
  1508. z16 = z >> Z16_SHIFT;
  1509. switch (testFunc) {
  1510. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1511. case (GL_LESS & 0x7): passed = z16 < zfb[0]; break;
  1512. case (GL_EQUAL & 0x7): passed = z16 == zfb[0]; break;
  1513. case (GL_LEQUAL & 0x7): passed = z16 <= zfb[0]; break;
  1514. case (GL_GREATER & 0x7): passed = z16 > zfb[0]; break;
  1515. case (GL_NOTEQUAL & 0x7): passed = z16 != zfb[0]; break;
  1516. case (GL_GEQUAL & 0x7): passed = z16 >= zfb[0]; break;
  1517. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1518. }
  1519. if (passed) {
  1520. if (writeEnabled) {
  1521. zfb[0] = z16;
  1522. }
  1523. } else {
  1524. outMask &= ~bit;
  1525. failed++;
  1526. }
  1527. } else failed++;
  1528. z += dzdx;
  1529. fraction += dfraction;
  1530. if (fraction < 0) {
  1531. fraction &= ~0x80000000;
  1532. zfb += dzpBig;
  1533. } else {
  1534. zfb += dzpLittle;
  1535. }
  1536. #ifdef __GL_STIPPLE_MSB
  1537. bit >>= 1;
  1538. #else
  1539. bit <<= 1;
  1540. #endif
  1541. }
  1542. *sp++ = outMask & inMask;
  1543. }
  1544. if (failed != gc->polygon.shader.length) {
  1545. /* Call next proc */
  1546. return GL_FALSE;
  1547. }
  1548. return GL_TRUE;
  1549. }
  1550. GLboolean FASTCALL __glDepth16TestStencilLine(__GLcontext *gc)
  1551. {
  1552. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1553. GLint xLittle, xBig, yLittle, yBig;
  1554. GLint fraction, dfraction;
  1555. GLint dzpLittle, dzpBig;
  1556. GLint dspLittle, dspBig;
  1557. __GLzValue z, dzdx;
  1558. __GLz16Value z16, *zfb;
  1559. GLint failed, count, testFunc;
  1560. __GLstippleWord bit, outMask, *osp;
  1561. GLboolean writeEnabled, passed;
  1562. GLint w;
  1563. w = gc->polygon.shader.length;
  1564. xBig = gc->line.options.xBig;
  1565. yBig = gc->line.options.yBig;
  1566. xLittle = gc->line.options.xLittle;
  1567. yLittle = gc->line.options.yLittle;
  1568. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLz16Value*),
  1569. gc->line.options.xStart, gc->line.options.yStart);
  1570. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1571. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1572. fraction = gc->line.options.fraction;
  1573. dfraction = gc->line.options.dfraction;
  1574. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1575. gc->line.options.xStart, gc->line.options.yStart);
  1576. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1577. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1578. fraction = gc->line.options.fraction;
  1579. dfraction = gc->line.options.dfraction;
  1580. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1581. #ifdef NT
  1582. if (!zFailOp)
  1583. return GL_FALSE;
  1584. #endif // NT
  1585. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1586. testFunc = gc->state.depth.testFunc & 0x7;
  1587. z = gc->polygon.shader.frag.z;
  1588. dzdx = gc->polygon.shader.dzdx;
  1589. writeEnabled = gc->state.depth.writeEnable;
  1590. osp = gc->polygon.shader.stipplePat;
  1591. failed = 0;
  1592. while (w) {
  1593. count = w;
  1594. if (count > __GL_STIPPLE_BITS) {
  1595. count = __GL_STIPPLE_BITS;
  1596. }
  1597. w -= count;
  1598. outMask = (__GLstippleWord) ~0;
  1599. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1600. while (--count >= 0) {
  1601. z16 = z >> Z16_SHIFT;
  1602. switch (testFunc) {
  1603. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1604. case (GL_LESS & 0x7): passed = z16 < zfb[0]; break;
  1605. case (GL_EQUAL & 0x7): passed = z16 == zfb[0]; break;
  1606. case (GL_LEQUAL & 0x7): passed = z16 <= zfb[0]; break;
  1607. case (GL_GREATER & 0x7): passed = z16 > zfb[0]; break;
  1608. case (GL_NOTEQUAL & 0x7): passed = z16 != zfb[0]; break;
  1609. case (GL_GEQUAL & 0x7): passed = z16 >= zfb[0]; break;
  1610. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1611. }
  1612. if (passed) {
  1613. sfb[0] = zPassOp[sfb[0]];
  1614. if (writeEnabled) {
  1615. zfb[0] = z16;
  1616. }
  1617. } else {
  1618. sfb[0] = zFailOp[sfb[0]];
  1619. outMask &= ~bit;
  1620. failed++;
  1621. }
  1622. z += dzdx;
  1623. fraction += dfraction;
  1624. if (fraction < 0) {
  1625. fraction &= ~0x80000000;
  1626. zfb += dzpBig;
  1627. sfb += dspBig;
  1628. } else {
  1629. zfb += dzpLittle;
  1630. sfb += dspLittle;
  1631. }
  1632. #ifdef __GL_STIPPLE_MSB
  1633. bit >>= 1;
  1634. #else
  1635. bit <<= 1;
  1636. #endif
  1637. }
  1638. *osp++ = outMask;
  1639. }
  1640. if (failed == 0) {
  1641. /* Call next span proc */
  1642. return GL_FALSE;
  1643. } else {
  1644. if (failed != gc->polygon.shader.length) {
  1645. /* Call next stippled span proc */
  1646. return GL_TRUE;
  1647. }
  1648. }
  1649. gc->polygon.shader.done = GL_TRUE;
  1650. return GL_TRUE;
  1651. }
  1652. GLboolean FASTCALL __glDepth16TestStencilStippledLine(__GLcontext *gc)
  1653. {
  1654. __GLstencilCell *sfb, *zPassOp, *zFailOp;
  1655. GLint xLittle, xBig, yLittle, yBig;
  1656. GLint fraction, dfraction;
  1657. GLint dzpLittle, dzpBig;
  1658. GLint dspLittle, dspBig;
  1659. __GLzValue z, dzdx;
  1660. __GLz16Value z16, *zfb;
  1661. GLint failed, count, testFunc;
  1662. __GLstippleWord bit, inMask, outMask, *sp;
  1663. GLboolean writeEnabled, passed;
  1664. GLint w;
  1665. w = gc->polygon.shader.length;
  1666. sp = gc->polygon.shader.stipplePat;
  1667. xBig = gc->line.options.xBig;
  1668. yBig = gc->line.options.yBig;
  1669. xLittle = gc->line.options.xLittle;
  1670. yLittle = gc->line.options.yLittle;
  1671. zfb = __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLz16Value*),
  1672. gc->line.options.xStart, gc->line.options.yStart);
  1673. dzpLittle = xLittle + yLittle * gc->depthBuffer.buf.outerWidth;
  1674. dzpBig = xBig + yBig * gc->depthBuffer.buf.outerWidth;
  1675. fraction = gc->line.options.fraction;
  1676. dfraction = gc->line.options.dfraction;
  1677. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1678. gc->line.options.xStart, gc->line.options.yStart);
  1679. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1680. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1681. fraction = gc->line.options.fraction;
  1682. dfraction = gc->line.options.dfraction;
  1683. testFunc = gc->state.depth.testFunc & 0x7;
  1684. zFailOp = gc->stencilBuffer.depthFailOpTable;
  1685. #ifdef NT
  1686. if (!zFailOp)
  1687. return GL_FALSE;
  1688. #endif // NT
  1689. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1690. z = gc->polygon.shader.frag.z;
  1691. dzdx = gc->polygon.shader.dzdx;
  1692. writeEnabled = gc->state.depth.writeEnable;
  1693. failed = 0;
  1694. while (w) {
  1695. count = w;
  1696. if (count > __GL_STIPPLE_BITS) {
  1697. count = __GL_STIPPLE_BITS;
  1698. }
  1699. w -= count;
  1700. inMask = *sp;
  1701. outMask = (__GLstippleWord) ~0;
  1702. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1703. while (--count >= 0) {
  1704. if (inMask & bit) {
  1705. z16 = z >> Z16_SHIFT;
  1706. switch (testFunc) {
  1707. case (GL_NEVER & 0x7): passed = GL_FALSE; break;
  1708. case (GL_LESS & 0x7): passed = z16 < zfb[0]; break;
  1709. case (GL_EQUAL & 0x7): passed = z16 == zfb[0]; break;
  1710. case (GL_LEQUAL & 0x7): passed = z16 <= zfb[0]; break;
  1711. case (GL_GREATER & 0x7): passed = z16 > zfb[0]; break;
  1712. case (GL_NOTEQUAL & 0x7): passed = z16 != zfb[0]; break;
  1713. case (GL_GEQUAL & 0x7): passed = z16 >= zfb[0]; break;
  1714. case (GL_ALWAYS & 0x7): passed = GL_TRUE; break;
  1715. }
  1716. if (passed) {
  1717. sfb[0] = zPassOp[sfb[0]];
  1718. if (writeEnabled) {
  1719. zfb[0] = z16;
  1720. }
  1721. } else {
  1722. sfb[0] = zFailOp[sfb[0]];
  1723. outMask &= ~bit;
  1724. failed++;
  1725. }
  1726. } else failed++;
  1727. z += dzdx;
  1728. fraction += dfraction;
  1729. if (fraction < 0) {
  1730. fraction &= ~0x80000000;
  1731. zfb += dzpBig;
  1732. sfb += dspBig;
  1733. } else {
  1734. zfb += dzpLittle;
  1735. sfb += dspLittle;
  1736. }
  1737. #ifdef __GL_STIPPLE_MSB
  1738. bit >>= 1;
  1739. #else
  1740. bit <<= 1;
  1741. #endif
  1742. }
  1743. *sp++ = outMask & inMask;
  1744. }
  1745. if (failed != gc->polygon.shader.length) {
  1746. /* Call next proc */
  1747. return GL_FALSE;
  1748. }
  1749. return GL_TRUE;
  1750. }
  1751. #endif // NT
  1752. GLboolean FASTCALL __glDepthPassLine(__GLcontext *gc)
  1753. {
  1754. __GLstencilCell *sfb, *zPassOp;
  1755. GLint xLittle, xBig, yLittle, yBig;
  1756. GLint fraction, dfraction;
  1757. GLint dspLittle, dspBig;
  1758. GLint w;
  1759. w = gc->polygon.shader.length;
  1760. xBig = gc->line.options.xBig;
  1761. yBig = gc->line.options.yBig;
  1762. xLittle = gc->line.options.xLittle;
  1763. yLittle = gc->line.options.yLittle;
  1764. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1765. gc->line.options.xStart, gc->line.options.yStart);
  1766. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1767. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1768. fraction = gc->line.options.fraction;
  1769. dfraction = gc->line.options.dfraction;
  1770. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1771. #ifdef NT
  1772. if (!zPassOp)
  1773. return GL_FALSE;
  1774. #endif // NT
  1775. while (--w >= 0) {
  1776. sfb[0] = zPassOp[sfb[0]];
  1777. fraction += dfraction;
  1778. if (fraction < 0) {
  1779. fraction &= ~0x80000000;
  1780. sfb += dspBig;
  1781. } else {
  1782. sfb += dspLittle;
  1783. }
  1784. }
  1785. return GL_FALSE;
  1786. }
  1787. GLboolean FASTCALL __glDepthPassStippledLine(__GLcontext *gc)
  1788. {
  1789. __GLstencilCell *sfb, *zPassOp;
  1790. GLint xLittle, xBig, yLittle, yBig;
  1791. GLint fraction, dfraction;
  1792. GLint dspLittle, dspBig;
  1793. __GLstippleWord bit, inMask, *sp;
  1794. GLint count;
  1795. GLint w;
  1796. w = gc->polygon.shader.length;
  1797. sp = gc->polygon.shader.stipplePat;
  1798. xBig = gc->line.options.xBig;
  1799. yBig = gc->line.options.yBig;
  1800. xLittle = gc->line.options.xLittle;
  1801. yLittle = gc->line.options.yLittle;
  1802. sfb = __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  1803. gc->line.options.xStart, gc->line.options.yStart);
  1804. dspLittle = xLittle + yLittle * gc->stencilBuffer.buf.outerWidth;
  1805. dspBig = xBig + yBig * gc->stencilBuffer.buf.outerWidth;
  1806. fraction = gc->line.options.fraction;
  1807. dfraction = gc->line.options.dfraction;
  1808. zPassOp = gc->stencilBuffer.depthPassOpTable;
  1809. #ifdef NT
  1810. if (!zPassOp)
  1811. return GL_FALSE;
  1812. #endif // NT
  1813. while (w) {
  1814. count = w;
  1815. if (count > __GL_STIPPLE_BITS) {
  1816. count = __GL_STIPPLE_BITS;
  1817. }
  1818. w -= count;
  1819. inMask = *sp++;
  1820. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1821. while (--count >= 0) {
  1822. if (inMask & bit) {
  1823. sfb[0] = zPassOp[sfb[0]];
  1824. }
  1825. fraction += dfraction;
  1826. if (fraction < 0) {
  1827. fraction &= ~0x80000000;
  1828. sfb += dspBig;
  1829. } else {
  1830. sfb += dspLittle;
  1831. }
  1832. #ifdef __GL_STIPPLE_MSB
  1833. bit >>= 1;
  1834. #else
  1835. bit <<= 1;
  1836. #endif
  1837. }
  1838. }
  1839. return GL_FALSE;
  1840. }
  1841. GLboolean FASTCALL __glDitherCILine(__GLcontext *gc)
  1842. {
  1843. /* XXX - Dither the CI line */
  1844. return GL_FALSE;
  1845. }
  1846. GLboolean FASTCALL __glDitherCIStippledLine(__GLcontext *gc)
  1847. {
  1848. /* XXX - Dither the CI stippled line */
  1849. return GL_FALSE;
  1850. }
  1851. GLboolean FASTCALL __glDitherRGBALine(__GLcontext *gc)
  1852. {
  1853. /* XXX - Dither the RGBA line */
  1854. return GL_FALSE;
  1855. }
  1856. GLboolean FASTCALL __glDitherRGBAStippledLine(__GLcontext *gc)
  1857. {
  1858. /* XXX - Dither the RGBA stippled line */
  1859. return GL_FALSE;
  1860. }
  1861. /*
  1862. ** This store line proc lives just above cfb->store, so it does
  1863. ** fetching, blending, dithering, logicOping, masking, and storing.
  1864. **
  1865. ** It uses the colorBuffer pointed to by gc->polygon.shader.cfb.
  1866. */
  1867. GLboolean FASTCALL __glStoreLine(__GLcontext *gc)
  1868. {
  1869. GLint xLittle, xBig, yLittle, yBig;
  1870. GLint fraction, dfraction;
  1871. __GLfragment frag;
  1872. __GLcolor *cp;
  1873. __GLcolorBuffer *cfb;
  1874. void (FASTCALL *store)(__GLcolorBuffer *cfb, const __GLfragment *frag);
  1875. GLint len;
  1876. len = gc->polygon.shader.length;
  1877. xBig = gc->line.options.xBig;
  1878. yBig = gc->line.options.yBig;
  1879. xLittle = gc->line.options.xLittle;
  1880. yLittle = gc->line.options.yLittle;
  1881. fraction = gc->line.options.fraction;
  1882. dfraction = gc->line.options.dfraction;
  1883. cp = gc->polygon.shader.colors;
  1884. cfb = gc->polygon.shader.cfb;
  1885. store = cfb->store;
  1886. frag.x = gc->line.options.xStart;
  1887. frag.y = gc->line.options.yStart;
  1888. while (--len >= 0) {
  1889. frag.color = *cp++;
  1890. (*store)(cfb, &frag);
  1891. fraction += dfraction;
  1892. if (fraction < 0) {
  1893. fraction &= ~0x80000000;
  1894. frag.x += xBig;
  1895. frag.y += yBig;
  1896. } else {
  1897. frag.x += xLittle;
  1898. frag.y += yLittle;
  1899. }
  1900. }
  1901. return GL_FALSE;
  1902. }
  1903. /*
  1904. ** This store line proc lives just above cfb->store, so it does
  1905. ** fetching, blending, dithering, logicOping, masking, and storing.
  1906. **
  1907. ** It uses the colorBuffer pointed to by gc->polygon.shader.cfb.
  1908. */
  1909. GLboolean FASTCALL __glStoreStippledLine(__GLcontext *gc)
  1910. {
  1911. GLint x, y, xLittle, xBig, yLittle, yBig;
  1912. GLint fraction, dfraction;
  1913. __GLfragment frag;
  1914. __GLcolor *cp;
  1915. __GLcolorBuffer *cfb;
  1916. __GLstippleWord inMask, bit, *sp;
  1917. GLint count;
  1918. void (FASTCALL *store)(__GLcolorBuffer *cfb, const __GLfragment *frag);
  1919. GLint len;
  1920. len = gc->polygon.shader.length;
  1921. sp = gc->polygon.shader.stipplePat;
  1922. xBig = gc->line.options.xBig;
  1923. yBig = gc->line.options.yBig;
  1924. xLittle = gc->line.options.xLittle;
  1925. yLittle = gc->line.options.yLittle;
  1926. fraction = gc->line.options.fraction;
  1927. dfraction = gc->line.options.dfraction;
  1928. cp = gc->polygon.shader.colors;
  1929. cfb = gc->polygon.shader.cfb;
  1930. store = cfb->store;
  1931. x = gc->line.options.xStart;
  1932. y = gc->line.options.yStart;
  1933. while (len) {
  1934. count = len;
  1935. if (count > __GL_STIPPLE_BITS) {
  1936. count = __GL_STIPPLE_BITS;
  1937. }
  1938. len -= count;
  1939. inMask = *sp++;
  1940. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  1941. while (--count >= 0) {
  1942. if (inMask & bit) {
  1943. frag.x = x;
  1944. frag.y = y;
  1945. frag.color = *cp;
  1946. (*store)(cfb, &frag);
  1947. }
  1948. cp++;
  1949. fraction += dfraction;
  1950. if (fraction < 0) {
  1951. fraction &= ~0x80000000;
  1952. x += xBig;
  1953. y += yBig;
  1954. } else {
  1955. x += xLittle;
  1956. y += yLittle;
  1957. }
  1958. #ifdef __GL_STIPPLE_MSB
  1959. bit >>= 1;
  1960. #else
  1961. bit <<= 1;
  1962. #endif
  1963. }
  1964. }
  1965. return GL_FALSE;
  1966. }
  1967. GLboolean FASTCALL __glAntiAliasLine(__GLcontext *gc)
  1968. {
  1969. __GLfloat length; /* Dist along length */
  1970. __GLfloat width; /* Dist along width */
  1971. GLint fraction, dfraction;
  1972. __GLfloat dlLittle, dlBig;
  1973. __GLfloat ddLittle, ddBig;
  1974. __GLcolor *cp;
  1975. __GLfloat coverage;
  1976. __GLfloat lineWidth;
  1977. __GLfloat lineLength;
  1978. GLint failed, count;
  1979. __GLstippleWord bit, outMask, *osp;
  1980. GLint w;
  1981. GLuint modeFlags = gc->polygon.shader.modeFlags;
  1982. w = gc->polygon.shader.length;
  1983. fraction = gc->line.options.fraction;
  1984. dfraction = gc->line.options.dfraction;
  1985. cp = gc->polygon.shader.colors;
  1986. dlLittle = gc->line.options.dlLittle;
  1987. dlBig = gc->line.options.dlBig;
  1988. ddLittle = gc->line.options.ddLittle;
  1989. ddBig = gc->line.options.ddBig;
  1990. length = gc->line.options.plength;
  1991. width = gc->line.options.pwidth;
  1992. lineLength = gc->line.options.realLength - __glHalf;
  1993. lineWidth = __glHalf * gc->state.line.smoothWidth - __glHalf;
  1994. osp = gc->polygon.shader.stipplePat;
  1995. failed = 0;
  1996. while (w) {
  1997. count = w;
  1998. if (count > __GL_STIPPLE_BITS) {
  1999. count = __GL_STIPPLE_BITS;
  2000. }
  2001. w -= count;
  2002. outMask = (__GLstippleWord) ~0;
  2003. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  2004. while (--count >= 0) {
  2005. /* Coverage for sides */
  2006. if (width > lineWidth) {
  2007. coverage = lineWidth - width + __glOne;
  2008. if (coverage < __glZero) {
  2009. coverage = __glZero;
  2010. goto coverageZero;
  2011. }
  2012. } else if (width < -lineWidth) {
  2013. coverage = width + lineWidth + __glOne;
  2014. if (coverage < __glZero) {
  2015. coverage = __glZero;
  2016. goto coverageZero;
  2017. }
  2018. } else {
  2019. coverage = __glOne;
  2020. }
  2021. /* Coverage for start, end */
  2022. if (length < __glHalf) {
  2023. coverage *= length + __glHalf;
  2024. if (coverage < __glZero) {
  2025. coverage = __glZero;
  2026. goto coverageZero;
  2027. }
  2028. } else if (length > lineLength) {
  2029. coverage *= lineLength - length + __glOne;
  2030. if (coverage < __glZero) {
  2031. coverage = __glZero;
  2032. goto coverageZero;
  2033. }
  2034. }
  2035. /* Coverage for internal stipples */
  2036. if ( modeFlags & __GL_SHADE_LINE_STIPPLE ) {
  2037. __GLfloat stippleOffset;
  2038. GLint lowStip, highStip;
  2039. GLint lowBit, highBit;
  2040. GLint lowVal, highVal;
  2041. __GLfloat percent;
  2042. /* Minor correction */
  2043. if (length > __glHalf) {
  2044. stippleOffset = gc->line.options.stippleOffset + length;
  2045. } else {
  2046. stippleOffset = gc->line.options.stippleOffset + __glHalf;
  2047. }
  2048. lowStip = __GL_FAST_FLOORF_I(stippleOffset);
  2049. highStip = lowStip + 1;
  2050. /* percent is the percent of highStip that will be used */
  2051. percent = stippleOffset - lowStip;
  2052. lowBit = (GLint) (lowStip *
  2053. gc->line.options.oneOverStippleRepeat) & 0xf;
  2054. highBit = (GLint) (highStip *
  2055. gc->line.options.oneOverStippleRepeat) & 0xf;
  2056. if (gc->state.line.stipple & (1<<lowBit)) {
  2057. lowVal = 1;
  2058. } else {
  2059. lowVal = 0;
  2060. }
  2061. if (gc->state.line.stipple & (1<<highBit)) {
  2062. highVal = 1;
  2063. } else {
  2064. highVal = 0;
  2065. }
  2066. coverage *= lowVal * (__glOne - percent) +
  2067. highVal * percent;
  2068. }
  2069. if (coverage == __glZero) {
  2070. coverageZero:;
  2071. outMask &= ~bit;
  2072. failed++;
  2073. } else {
  2074. if (gc->modes.colorIndexMode) {
  2075. cp->r = __glBuildAntiAliasIndex(cp->r, coverage);
  2076. } else {
  2077. cp->a *= coverage;
  2078. }
  2079. }
  2080. cp++;
  2081. fraction += dfraction;
  2082. if (fraction < 0) {
  2083. fraction &= ~0x80000000;
  2084. length += dlBig;
  2085. width += ddBig;
  2086. } else {
  2087. length += dlLittle;
  2088. width += ddLittle;
  2089. }
  2090. #ifdef __GL_STIPPLE_MSB
  2091. bit >>= 1;
  2092. #else
  2093. bit <<= 1;
  2094. #endif
  2095. }
  2096. *osp++ = outMask;
  2097. }
  2098. if (failed == 0) {
  2099. /* Call next span proc */
  2100. return GL_FALSE;
  2101. } else {
  2102. if (failed != gc->polygon.shader.length) {
  2103. /* Call next stippled span proc */
  2104. return GL_TRUE;
  2105. }
  2106. }
  2107. gc->polygon.shader.done = GL_TRUE;
  2108. return GL_TRUE;
  2109. }
  2110. GLboolean FASTCALL __glAntiAliasStippledLine(__GLcontext *gc)
  2111. {
  2112. __GLfloat length; /* Dist along length */
  2113. __GLfloat width; /* Dist along width */
  2114. GLint fraction, dfraction;
  2115. __GLfloat dlLittle, dlBig;
  2116. __GLfloat ddLittle, ddBig;
  2117. __GLcolor *cp;
  2118. __GLfloat coverage;
  2119. __GLfloat lineWidth;
  2120. __GLfloat lineLength;
  2121. GLint failed, count;
  2122. __GLstippleWord bit, outMask, inMask, *sp;
  2123. GLint w;
  2124. GLuint modeFlags = gc->polygon.shader.modeFlags;
  2125. w = gc->polygon.shader.length;
  2126. sp = gc->polygon.shader.stipplePat;
  2127. fraction = gc->line.options.fraction;
  2128. dfraction = gc->line.options.dfraction;
  2129. cp = gc->polygon.shader.colors;
  2130. dlLittle = gc->line.options.dlLittle;
  2131. dlBig = gc->line.options.dlBig;
  2132. ddLittle = gc->line.options.ddLittle;
  2133. ddBig = gc->line.options.ddBig;
  2134. length = gc->line.options.plength;
  2135. width = gc->line.options.pwidth;
  2136. lineLength = gc->line.options.realLength - __glHalf;
  2137. lineWidth = __glHalf * gc->state.line.smoothWidth - __glHalf;
  2138. failed = 0;
  2139. while (w) {
  2140. count = w;
  2141. if (count > __GL_STIPPLE_BITS) {
  2142. count = __GL_STIPPLE_BITS;
  2143. }
  2144. w -= count;
  2145. inMask = *sp;
  2146. outMask = (__GLstippleWord) ~0;
  2147. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  2148. while (--count >= 0) {
  2149. if (inMask & bit) {
  2150. /* Coverage for sides */
  2151. if (width > lineWidth) {
  2152. coverage = lineWidth - width + __glOne;
  2153. if (coverage < __glZero) {
  2154. coverage = __glZero;
  2155. goto coverageZero;
  2156. }
  2157. } else if (width < -lineWidth) {
  2158. coverage = width + lineWidth + __glOne;
  2159. if (coverage < __glZero) {
  2160. coverage = __glZero;
  2161. goto coverageZero;
  2162. }
  2163. } else {
  2164. coverage = __glOne;
  2165. }
  2166. /* Coverage for start, end */
  2167. if (length < __glHalf) {
  2168. coverage *= length + __glHalf;
  2169. if (coverage < __glZero) {
  2170. coverage = __glZero;
  2171. goto coverageZero;
  2172. }
  2173. } else if (length > lineLength) {
  2174. coverage *= lineLength - length + __glOne;
  2175. if (coverage < __glZero) {
  2176. coverage = __glZero;
  2177. goto coverageZero;
  2178. }
  2179. }
  2180. /* Coverage for internal stipples */
  2181. if (modeFlags & __GL_SHADE_LINE_STIPPLE) {
  2182. __GLfloat stippleOffset;
  2183. GLint lowStip, highStip;
  2184. GLint lowBit, highBit;
  2185. GLint lowVal, highVal;
  2186. __GLfloat percent;
  2187. /* Minor correction */
  2188. if (length > __glHalf) {
  2189. stippleOffset = gc->line.options.stippleOffset + length;
  2190. } else {
  2191. stippleOffset = gc->line.options.stippleOffset + __glHalf;
  2192. }
  2193. lowStip = __GL_FAST_FLOORF_I(stippleOffset);
  2194. highStip = lowStip + 1;
  2195. /* percent is the percent of highStip that will be used */
  2196. percent = stippleOffset - lowStip;
  2197. lowBit = (GLint) (lowStip *
  2198. gc->line.options.oneOverStippleRepeat) & 0xf;
  2199. highBit = (GLint) (highStip *
  2200. gc->line.options.oneOverStippleRepeat) & 0xf;
  2201. if (gc->state.line.stipple & (1<<lowBit)) {
  2202. lowVal = 1;
  2203. } else {
  2204. lowVal = 0;
  2205. }
  2206. if (gc->state.line.stipple & (1<<highBit)) {
  2207. highVal = 1;
  2208. } else {
  2209. highVal = 0;
  2210. }
  2211. coverage *= lowVal * (__glOne - percent) +
  2212. highVal * percent;
  2213. }
  2214. if (coverage == __glZero) {
  2215. coverageZero:;
  2216. outMask &= ~bit;
  2217. failed++;
  2218. } else {
  2219. if (gc->modes.colorIndexMode) {
  2220. cp->r = __glBuildAntiAliasIndex(cp->r, coverage);
  2221. } else {
  2222. cp->a *= coverage;
  2223. }
  2224. }
  2225. } else failed++;
  2226. cp++;
  2227. fraction += dfraction;
  2228. if (fraction < 0) {
  2229. fraction &= ~0x80000000;
  2230. length += dlBig;
  2231. width += ddBig;
  2232. } else {
  2233. length += dlLittle;
  2234. width += ddLittle;
  2235. }
  2236. #ifdef __GL_STIPPLE_MSB
  2237. bit >>= 1;
  2238. #else
  2239. bit <<= 1;
  2240. #endif
  2241. }
  2242. *sp++ = outMask & inMask;
  2243. }
  2244. if (failed == gc->polygon.shader.length) {
  2245. return GL_TRUE;
  2246. }
  2247. return GL_FALSE;
  2248. }