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.

832 lines
29 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. #include <fixed.h>
  20. /* This routine sets gc->polygon.shader.cfb to gc->drawBuffer */
  21. static void FASTCALL FillSubTriangle(__GLcontext *gc, GLint iyBottom, GLint iyTop)
  22. {
  23. GLint ixLeft, ixRight;
  24. GLint ixLeftFrac, ixRightFrac;
  25. GLint dxLeftFrac, dxRightFrac;
  26. GLint dxLeftLittle, dxRightLittle;
  27. GLint dxLeftBig, dxRightBig;
  28. GLint spanWidth, clipY0, clipY1;
  29. GLuint modeFlags;
  30. #ifdef NT
  31. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  32. __GLstippleWord *words;
  33. __GLcolor colors[__GL_MAX_STACKED_COLORS>>1];
  34. __GLcolor fbcolors[__GL_MAX_STACKED_COLORS>>1];
  35. __GLcolor *vColors, *vFbcolors;
  36. int iMaxWidth, iDy, dxLeft, dxRight;
  37. ixLeft = gc->polygon.shader.ixLeft;
  38. dxLeft = (gc->polygon.shader.dxLeftBig < gc->polygon.shader.dxLeftLittle) ?
  39. gc->polygon.shader.dxLeftBig : gc->polygon.shader.dxLeftLittle;
  40. ixRight = gc->polygon.shader.ixRight;
  41. dxRight = (gc->polygon.shader.dxRightBig > gc->polygon.shader.dxRightLittle) ?
  42. gc->polygon.shader.dxRightBig : gc->polygon.shader.dxRightLittle;
  43. iMaxWidth = ixRight - ixLeft;
  44. iDy = iyTop - iyBottom - 1;
  45. ixRight += dxRight * iDy;
  46. ixLeft += dxLeft * iDy;
  47. iMaxWidth = (iMaxWidth < (ixRight - ixLeft)) ? ixRight - ixLeft :
  48. iMaxWidth;
  49. if (iMaxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  50. {
  51. words = gcTempAlloc(gc, (iMaxWidth+__GL_STIPPLE_BITS-1)/8);
  52. if (words == NULL)
  53. {
  54. return;
  55. }
  56. }
  57. else
  58. {
  59. words = stackWords;
  60. }
  61. if (iMaxWidth > (__GL_MAX_STACKED_COLORS>>1))
  62. {
  63. vColors = (__GLcolor *) gcTempAlloc(gc, iMaxWidth * sizeof(__GLcolor));
  64. if (NULL == vColors)
  65. {
  66. if (iMaxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  67. {
  68. gcTempFree(gc, words);
  69. }
  70. return;
  71. }
  72. vFbcolors = (__GLcolor *) gcTempAlloc(gc, iMaxWidth * sizeof(__GLcolor));
  73. if (NULL == vFbcolors) {
  74. if (iMaxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  75. {
  76. gcTempFree(gc, words);
  77. }
  78. gcTempFree(gc, vColors);
  79. return;
  80. }
  81. }
  82. else
  83. {
  84. vColors = colors;
  85. vFbcolors = fbcolors;
  86. }
  87. #else
  88. __GLstippleWord words[__GL_MAX_STIPPLE_WORDS];
  89. __GLcolor vColors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  90. __GLcolor vFbcolors[__GL_MAX_MAX_VIEWPORT];/*XXX oink */
  91. #endif
  92. ixLeft = gc->polygon.shader.ixLeft;
  93. ixLeftFrac = gc->polygon.shader.ixLeftFrac;
  94. ixRight = gc->polygon.shader.ixRight;
  95. ixRightFrac = gc->polygon.shader.ixRightFrac;
  96. clipY0 = gc->transform.clipY0;
  97. clipY1 = gc->transform.clipY1;
  98. dxLeftFrac = gc->polygon.shader.dxLeftFrac;
  99. dxLeftBig = gc->polygon.shader.dxLeftBig;
  100. dxLeftLittle = gc->polygon.shader.dxLeftLittle;
  101. dxRightFrac = gc->polygon.shader.dxRightFrac;
  102. dxRightBig = gc->polygon.shader.dxRightBig;
  103. dxRightLittle = gc->polygon.shader.dxRightLittle;
  104. modeFlags = gc->polygon.shader.modeFlags;
  105. gc->polygon.shader.colors = vColors;
  106. gc->polygon.shader.fbcolors = vFbcolors;
  107. gc->polygon.shader.stipplePat = words;
  108. if (modeFlags & __GL_SHADE_STENCIL_TEST) {
  109. gc->polygon.shader.sbuf =
  110. __GL_STENCIL_ADDR(&gc->stencilBuffer, (__GLstencilCell*),
  111. ixLeft, iyBottom);
  112. }
  113. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  114. #ifdef NT
  115. if( gc->modes.depthBits == 32 )
  116. gc->polygon.shader.zbuf = (__GLzValue *)
  117. __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  118. ixLeft, iyBottom);
  119. else
  120. gc->polygon.shader.zbuf = (__GLzValue *)
  121. __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLz16Value*),
  122. ixLeft, iyBottom);
  123. #else
  124. gc->polygon.shader.zbuf =
  125. __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  126. ixLeft, iyBottom);
  127. #endif
  128. }
  129. gc->polygon.shader.cfb = gc->drawBuffer;
  130. while (iyBottom < iyTop) {
  131. spanWidth = ixRight - ixLeft;
  132. /*
  133. ** Only render spans that have non-zero width and which are
  134. ** not scissored out vertically.
  135. */
  136. if ((spanWidth > 0) && (iyBottom >= clipY0) && (iyBottom < clipY1)) {
  137. gc->polygon.shader.frag.x = ixLeft;
  138. gc->polygon.shader.frag.y = iyBottom;
  139. gc->polygon.shader.length = spanWidth;
  140. (*gc->procs.span.processSpan)(gc);
  141. }
  142. /* Advance right edge fixed point, adjusting for carry */
  143. ixRightFrac += dxRightFrac;
  144. if (ixRightFrac < 0) {
  145. /* Carry/Borrow'd. Use large step */
  146. ixRight += dxRightBig;
  147. ixRightFrac &= ~0x80000000;
  148. } else {
  149. ixRight += dxRightLittle;
  150. }
  151. iyBottom++;
  152. ixLeftFrac += dxLeftFrac;
  153. if (ixLeftFrac < 0) {
  154. /* Carry/Borrow'd. Use large step */
  155. ixLeft += dxLeftBig;
  156. ixLeftFrac &= ~0x80000000;
  157. if (modeFlags & __GL_SHADE_RGB) {
  158. if (modeFlags & __GL_SHADE_SMOOTH) {
  159. gc->polygon.shader.frag.color.r += gc->polygon.shader.rBig;
  160. gc->polygon.shader.frag.color.g += gc->polygon.shader.gBig;
  161. gc->polygon.shader.frag.color.b += gc->polygon.shader.bBig;
  162. gc->polygon.shader.frag.color.a += gc->polygon.shader.aBig;
  163. }
  164. if (modeFlags & __GL_SHADE_TEXTURE) {
  165. gc->polygon.shader.frag.s += gc->polygon.shader.sBig;
  166. gc->polygon.shader.frag.t += gc->polygon.shader.tBig;
  167. gc->polygon.shader.frag.qw += gc->polygon.shader.qwBig;
  168. }
  169. } else {
  170. if (modeFlags & __GL_SHADE_SMOOTH) {
  171. gc->polygon.shader.frag.color.r += gc->polygon.shader.rBig;
  172. }
  173. }
  174. if (modeFlags & __GL_SHADE_STENCIL_TEST) {
  175. /* The implicit multiply is taken out of the loop */
  176. gc->polygon.shader.sbuf = (__GLstencilCell*)
  177. ((GLubyte*) gc->polygon.shader.sbuf
  178. + gc->polygon.shader.sbufBig);
  179. }
  180. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  181. gc->polygon.shader.frag.z += gc->polygon.shader.zBig;
  182. }
  183. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  184. /* The implicit multiply is taken out of the loop */
  185. gc->polygon.shader.zbuf = (__GLzValue*)
  186. ((GLubyte*) gc->polygon.shader.zbuf
  187. + gc->polygon.shader.zbufBig);
  188. }
  189. if (modeFlags & (__GL_SHADE_COMPUTE_FOG | __GL_SHADE_INTERP_FOG))
  190. {
  191. gc->polygon.shader.frag.f += gc->polygon.shader.fBig;
  192. }
  193. } else {
  194. /* Use small step */
  195. ixLeft += dxLeftLittle;
  196. if (modeFlags & __GL_SHADE_RGB) {
  197. if (modeFlags & __GL_SHADE_SMOOTH) {
  198. gc->polygon.shader.frag.color.r += gc->polygon.shader.rLittle;
  199. gc->polygon.shader.frag.color.g += gc->polygon.shader.gLittle;
  200. gc->polygon.shader.frag.color.b += gc->polygon.shader.bLittle;
  201. gc->polygon.shader.frag.color.a += gc->polygon.shader.aLittle;
  202. }
  203. if (modeFlags & __GL_SHADE_TEXTURE) {
  204. gc->polygon.shader.frag.s += gc->polygon.shader.sLittle;
  205. gc->polygon.shader.frag.t += gc->polygon.shader.tLittle;
  206. gc->polygon.shader.frag.qw += gc->polygon.shader.qwLittle;
  207. }
  208. } else {
  209. if (modeFlags & __GL_SHADE_SMOOTH) {
  210. gc->polygon.shader.frag.color.r += gc->polygon.shader.rLittle;
  211. }
  212. }
  213. if (modeFlags & __GL_SHADE_STENCIL_TEST) {
  214. /* The implicit multiply is taken out of the loop */
  215. gc->polygon.shader.sbuf = (__GLstencilCell*)
  216. ((GLubyte*) gc->polygon.shader.sbuf
  217. + gc->polygon.shader.sbufLittle);
  218. }
  219. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  220. gc->polygon.shader.frag.z += gc->polygon.shader.zLittle;
  221. }
  222. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  223. /* The implicit multiply is taken out of the loop */
  224. gc->polygon.shader.zbuf = (__GLzValue*)
  225. ((GLubyte*) gc->polygon.shader.zbuf
  226. + gc->polygon.shader.zbufLittle);
  227. }
  228. if (modeFlags & (__GL_SHADE_COMPUTE_FOG | __GL_SHADE_INTERP_FOG))
  229. {
  230. gc->polygon.shader.frag.f += gc->polygon.shader.fLittle;
  231. }
  232. }
  233. }
  234. gc->polygon.shader.ixLeft = ixLeft;
  235. gc->polygon.shader.ixLeftFrac = ixLeftFrac;
  236. gc->polygon.shader.ixRight = ixRight;
  237. gc->polygon.shader.ixRightFrac = ixRightFrac;
  238. #ifdef NT
  239. if (iMaxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  240. {
  241. gcTempFree(gc, words);
  242. }
  243. if (iMaxWidth > (__GL_MAX_STACKED_COLORS>>1))
  244. {
  245. gcTempFree(gc, vColors);
  246. gcTempFree(gc, vFbcolors);
  247. }
  248. #endif
  249. }
  250. static void SnapXLeft(__GLcontext *gc, __GLfloat xLeft, __GLfloat dxdyLeft)
  251. {
  252. GLint ixLeft, ixLeftFrac, lineBytes, elementSize, iLittle, iBig;
  253. ASSERT_CHOP_ROUND();
  254. ixLeft = __GL_VERTEX_FLOAT_TO_INT(xLeft);
  255. /* Pre-add .5 to allow truncation in spanWidth calculation */
  256. ixLeftFrac = __GL_VERTEX_PROMOTED_FRACTION(xLeft) + 0x40000000;
  257. gc->polygon.shader.ixLeft = ixLeft + (((GLuint) ixLeftFrac) >> 31);
  258. gc->polygon.shader.ixLeftFrac = ixLeftFrac & ~0x80000000;
  259. /* Compute big and little steps */
  260. iLittle = FTOL(dxdyLeft);
  261. gc->polygon.shader.dxLeftFrac = FLT_FRACTION(dxdyLeft - iLittle);
  262. if (dxdyLeft < 0) {
  263. iBig = iLittle - 1;
  264. } else {
  265. iBig = iLittle + 1;
  266. }
  267. if (gc->polygon.shader.modeFlags & __GL_SHADE_STENCIL_TEST) {
  268. /*
  269. ** Compute the big and little stencil buffer steps. We walk the
  270. ** memory pointers for the stencil buffer along the edge of the
  271. ** triangle as we walk the edge. This way we don't have to
  272. ** recompute the buffer address as we go.
  273. */
  274. elementSize = gc->stencilBuffer.buf.elementSize;
  275. lineBytes = elementSize * gc->stencilBuffer.buf.outerWidth;
  276. gc->polygon.shader.sbufLittle = lineBytes + iLittle * elementSize;
  277. gc->polygon.shader.sbufBig = lineBytes + iBig * elementSize;
  278. }
  279. if (gc->polygon.shader.modeFlags & __GL_SHADE_DEPTH_TEST) {
  280. /*
  281. ** Compute the big and little depth buffer steps. We walk the
  282. ** memory pointers for the depth buffer along the edge of the
  283. ** triangle as we walk the edge. This way we don't have to
  284. ** recompute the buffer address as we go.
  285. */
  286. elementSize = gc->depthBuffer.buf.elementSize;
  287. lineBytes = elementSize * gc->depthBuffer.buf.outerWidth;
  288. gc->polygon.shader.zbufLittle = lineBytes + iLittle * elementSize;
  289. gc->polygon.shader.zbufBig = lineBytes + iBig * elementSize;
  290. }
  291. gc->polygon.shader.dxLeftLittle = iLittle;
  292. gc->polygon.shader.dxLeftBig = iBig;
  293. }
  294. static void SnapXRight(__GLshade *sh, __GLfloat xRight, __GLfloat dxdyRight)
  295. {
  296. GLint ixRight, ixRightFrac, iLittle, iBig;
  297. ASSERT_CHOP_ROUND();
  298. ixRight = __GL_VERTEX_FLOAT_TO_INT(xRight);
  299. /* Pre-add .5 to allow truncation in spanWidth calculation */
  300. ixRightFrac = __GL_VERTEX_PROMOTED_FRACTION(xRight) + 0x40000000;
  301. sh->ixRight = ixRight + (((GLuint) ixRightFrac) >> 31);
  302. sh->ixRightFrac = ixRightFrac & ~0x80000000;
  303. /* Compute big and little steps */
  304. iLittle = FTOL(dxdyRight);
  305. sh->dxRightFrac = FLT_FRACTION(dxdyRight - iLittle);
  306. if (dxdyRight < 0) {
  307. iBig = iLittle - 1;
  308. } else {
  309. iBig = iLittle + 1;
  310. }
  311. sh->dxRightLittle = iLittle;
  312. sh->dxRightBig = iBig;
  313. }
  314. __GLfloat __glPolygonOffsetZ(__GLcontext *gc )
  315. {
  316. __GLshade *sh = &gc->polygon.shader;
  317. __GLfloat factor;
  318. __GLfloat maxdZ;
  319. __GLfloat bias;
  320. __GLfloat offsetZ;
  321. /*
  322. ** Calculate factor and bias
  323. */
  324. factor = gc->state.polygon.factor;
  325. // For 16-bit z, bias = units,
  326. // For 32-bit z, we only have 24 bits of resolution from the floating
  327. // point z value. Therefore, the minimum resolvable difference in z
  328. // values is 8-bits, and we multiply units by 2**8, or 256.
  329. if( gc->modes.depthBits == 16 )
  330. bias = gc->state.polygon.units;
  331. else
  332. bias = gc->state.polygon.units * __glVal256;
  333. /*
  334. ** find the maximum Z slope with respect to X and Y
  335. */
  336. // Note: all z values have already been scaled up from [0,1]
  337. if(__GL_ABSF(sh->dzdxf) > __GL_ABSF(sh->dzdyf))
  338. maxdZ = __GL_ABSF(sh->dzdxf);
  339. else
  340. maxdZ = __GL_ABSF(sh->dzdyf);
  341. offsetZ = factor * maxdZ + bias;
  342. // XXX! This value should really be clamped, but supposedly we don't
  343. // bother in other parts of the code, so leave it for now. Clamping
  344. // should also only be applied AFTER the addition of offsetZ to any
  345. // base value.
  346. return( offsetZ );
  347. }
  348. #ifdef NT
  349. static void SetInitialParameters(__GLcontext *gc, const __GLvertex *a,
  350. const __GLcolor *ac, __GLfloat aFog,
  351. __GLfloat dx, __GLfloat dy)
  352. {
  353. __GLshade *sh = &gc->polygon.shader;
  354. #else
  355. static void SetInitialParameters(__GLshade *sh, const __GLvertex *a,
  356. const __GLcolor *ac, __GLfloat aFog,
  357. __GLfloat dx, __GLfloat dy)
  358. {
  359. #endif
  360. __GLfloat little = sh->dxLeftLittle;
  361. __GLfloat big = sh->dxLeftBig;
  362. GLuint modeFlags = sh->modeFlags;
  363. #define bPolygonOffset \
  364. (gc->state.enables.general & __GL_POLYGON_OFFSET_FILL_ENABLE )
  365. if (big > little) {
  366. if (modeFlags & __GL_SHADE_RGB) {
  367. if (modeFlags & __GL_SHADE_SMOOTH) {
  368. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  369. sh->rLittle = sh->drdy + little * sh->drdx;
  370. sh->rBig = sh->rLittle + sh->drdx;
  371. sh->frag.color.g = ac->g + dx*sh->dgdx + dy*sh->dgdy;
  372. sh->gLittle = sh->dgdy + little * sh->dgdx;
  373. sh->gBig = sh->gLittle + sh->dgdx;
  374. sh->frag.color.b = ac->b + dx*sh->dbdx + dy*sh->dbdy;
  375. sh->bLittle = sh->dbdy + little * sh->dbdx;
  376. sh->bBig = sh->bLittle + sh->dbdx;
  377. sh->frag.color.a = ac->a + dx*sh->dadx + dy*sh->dady;
  378. sh->aLittle = sh->dady + little * sh->dadx;
  379. sh->aBig =sh->aLittle + sh->dadx;
  380. }
  381. if (modeFlags & __GL_SHADE_TEXTURE) {
  382. __GLfloat oneOverW = a->window.w;
  383. sh->frag.s = a->texture.x * oneOverW + dx*sh->dsdx
  384. + dy*sh->dsdy;
  385. sh->sLittle = sh->dsdy + little * sh->dsdx;
  386. sh->sBig = sh->sLittle + sh->dsdx;
  387. sh->frag.t = a->texture.y * oneOverW + dx*sh->dtdx
  388. + dy*sh->dtdy;
  389. sh->tLittle = sh->dtdy + little * sh->dtdx;
  390. sh->tBig = sh->tLittle + sh->dtdx;
  391. sh->frag.qw = a->texture.w * oneOverW + dx*sh->dqwdx
  392. + dy*sh->dqwdy;
  393. sh->qwLittle = sh->dqwdy + little * sh->dqwdx;
  394. sh->qwBig = sh->qwLittle + sh->dqwdx;
  395. }
  396. } else {
  397. if (modeFlags & __GL_SHADE_SMOOTH) {
  398. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  399. sh->rLittle = sh->drdy + little * sh->drdx;
  400. sh->rBig = sh->rLittle + sh->drdx;
  401. }
  402. }
  403. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  404. __GLfloat zLittle, zOffset;
  405. zOffset = bPolygonOffset ? __glPolygonOffsetZ(gc) : 0.0f;
  406. if (gc->modes.depthBits == 16) {
  407. sh->frag.z = (__GLzValue)
  408. FLT_TO_Z16_SCALE(a->window.z + dx*sh->dzdxf + dy*sh->dzdyf
  409. + zOffset );
  410. zLittle = sh->dzdyf + little * sh->dzdxf;
  411. sh->zLittle = FLT_TO_Z16_SCALE(zLittle);
  412. sh->zBig = FLT_TO_Z16_SCALE(zLittle + sh->dzdxf);
  413. }
  414. else {
  415. sh->frag.z = (__GLzValue)
  416. FTOL(a->window.z + dx*sh->dzdxf + dy*sh->dzdyf +
  417. zOffset );
  418. zLittle = sh->dzdyf + little * sh->dzdxf;
  419. sh->zLittle = FTOL(zLittle);
  420. sh->zBig = FTOL(zLittle + sh->dzdxf);
  421. }
  422. }
  423. if (modeFlags & (__GL_SHADE_COMPUTE_FOG | __GL_SHADE_INTERP_FOG))
  424. {
  425. sh->frag.f = aFog + dx*sh->dfdx + dy*sh->dfdy;
  426. sh->fLittle = sh->dfdy + little * sh->dfdx;
  427. sh->fBig = sh->fLittle + sh->dfdx;
  428. }
  429. } else {
  430. if (modeFlags & __GL_SHADE_RGB) {
  431. if (modeFlags & __GL_SHADE_SMOOTH) {
  432. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  433. sh->rLittle = sh->drdy + little * sh->drdx;
  434. sh->rBig = sh->rLittle - sh->drdx;
  435. sh->frag.color.g = ac->g + dx*sh->dgdx + dy*sh->dgdy;
  436. sh->gLittle = sh->dgdy + little * sh->dgdx;
  437. sh->gBig = sh->gLittle - sh->dgdx;
  438. sh->frag.color.b = ac->b + dx*sh->dbdx + dy*sh->dbdy;
  439. sh->bLittle = sh->dbdy + little * sh->dbdx;
  440. sh->bBig = sh->bLittle - sh->dbdx;
  441. sh->frag.color.a = ac->a + dx*sh->dadx + dy*sh->dady;
  442. sh->aLittle = sh->dady + little * sh->dadx;
  443. sh->aBig =sh->aLittle - sh->dadx;
  444. }
  445. if (modeFlags & __GL_SHADE_TEXTURE) {
  446. __GLfloat oneOverW = a->window.w;
  447. sh->frag.s = a->texture.x * oneOverW + dx*sh->dsdx
  448. + dy*sh->dsdy;
  449. sh->sLittle = sh->dsdy + little * sh->dsdx;
  450. sh->sBig = sh->sLittle - sh->dsdx;
  451. sh->frag.t = a->texture.y * oneOverW + dx*sh->dtdx
  452. + dy*sh->dtdy;
  453. sh->tLittle = sh->dtdy + little * sh->dtdx;
  454. sh->tBig = sh->tLittle - sh->dtdx;
  455. sh->frag.qw = a->texture.w * oneOverW + dx*sh->dqwdx
  456. + dy*sh->dqwdy;
  457. sh->qwLittle = sh->dqwdy + little * sh->dqwdx;
  458. sh->qwBig = sh->qwLittle - sh->dqwdx;
  459. }
  460. } else {
  461. if (modeFlags & __GL_SHADE_SMOOTH) {
  462. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  463. sh->rLittle = sh->drdy + little * sh->drdx;
  464. sh->rBig = sh->rLittle - sh->drdx;
  465. }
  466. }
  467. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  468. __GLfloat zLittle, zOffset;
  469. zOffset = bPolygonOffset ? __glPolygonOffsetZ(gc) : 0.0f;
  470. if(( gc->modes.depthBits == 16 ) &&
  471. ( gc->depthBuffer.scale <= (GLuint)0xffff )) {
  472. sh->frag.z = (__GLzValue)
  473. FLT_TO_Z16_SCALE(a->window.z + dx*sh->dzdxf + dy*sh->dzdyf
  474. + zOffset );
  475. zLittle = sh->dzdyf + little * sh->dzdxf;
  476. sh->zLittle = FLT_TO_Z16_SCALE(zLittle);
  477. sh->zBig = FLT_TO_Z16_SCALE(zLittle - sh->dzdxf);
  478. }
  479. else {
  480. sh->frag.z = (__GLzValue)
  481. FTOL( a->window.z + dx*sh->dzdxf + dy*sh->dzdyf+ zOffset );
  482. zLittle = sh->dzdyf + little * sh->dzdxf;
  483. sh->zLittle = FTOL(zLittle);
  484. sh->zBig = FTOL(zLittle - sh->dzdxf);
  485. }
  486. }
  487. if (modeFlags & (__GL_SHADE_COMPUTE_FOG | __GL_SHADE_INTERP_FOG))
  488. {
  489. sh->frag.f = aFog + dx*sh->dfdx + dy*sh->dfdy;
  490. sh->fLittle = sh->dfdy + little * sh->dfdx;
  491. sh->fBig = sh->fLittle - sh->dfdx;
  492. }
  493. }
  494. }
  495. void FASTCALL __glFillTriangle(__GLcontext *gc, __GLvertex *a, __GLvertex *b,
  496. __GLvertex *c, GLboolean ccw)
  497. {
  498. __GLfloat oneOverArea, t1, t2, t3, t4;
  499. __GLfloat dxAC, dxBC, dyAC, dyBC;
  500. __GLfloat aFog, bFog;
  501. __GLfloat dxAB, dyAB;
  502. __GLfloat dx, dy, dxdyLeft, dxdyRight;
  503. __GLcolor *ac, *bc;
  504. GLint aIY, bIY, cIY;
  505. GLuint modeFlags;
  506. __GLfloat dxdyAC;
  507. CHOP_ROUND_ON();
  508. /* Pre-compute one over polygon area */
  509. __GL_FLOAT_BEGIN_DIVIDE(__glOne, gc->polygon.shader.area, &oneOverArea);
  510. /* Fetch some stuff we are going to reuse */
  511. modeFlags = gc->polygon.shader.modeFlags;
  512. dxAC = gc->polygon.shader.dxAC;
  513. dxBC = gc->polygon.shader.dxBC;
  514. dyAC = gc->polygon.shader.dyAC;
  515. dyBC = gc->polygon.shader.dyBC;
  516. ac = a->color;
  517. bc = b->color;
  518. /*
  519. ** Compute delta values for unit changes in x or y for each
  520. ** parameter.
  521. */
  522. __GL_FLOAT_SIMPLE_END_DIVIDE(oneOverArea);
  523. t1 = dyAC * oneOverArea;
  524. t2 = dyBC * oneOverArea;
  525. t3 = dxAC * oneOverArea;
  526. t4 = dxBC * oneOverArea;
  527. if (modeFlags & __GL_SHADE_RGB) {
  528. if (modeFlags & __GL_SHADE_SMOOTH) {
  529. __GLfloat drAC, dgAC, dbAC, daAC;
  530. __GLfloat drBC, dgBC, dbBC, daBC;
  531. __GLcolor *cc;
  532. cc = c->color;
  533. drAC = ac->r - cc->r;
  534. drBC = bc->r - cc->r;
  535. dgAC = ac->g - cc->g;
  536. dgBC = bc->g - cc->g;
  537. dbAC = ac->b - cc->b;
  538. dbBC = bc->b - cc->b;
  539. daAC = ac->a - cc->a;
  540. daBC = bc->a - cc->a;
  541. gc->polygon.shader.drdx = drAC * t2 - drBC * t1;
  542. gc->polygon.shader.drdy = drBC * t3 - drAC * t4;
  543. gc->polygon.shader.dgdx = dgAC * t2 - dgBC * t1;
  544. gc->polygon.shader.dgdy = dgBC * t3 - dgAC * t4;
  545. gc->polygon.shader.dbdx = dbAC * t2 - dbBC * t1;
  546. gc->polygon.shader.dbdy = dbBC * t3 - dbAC * t4;
  547. gc->polygon.shader.dadx = daAC * t2 - daBC * t1;
  548. gc->polygon.shader.dady = daBC * t3 - daAC * t4;
  549. } else {
  550. __GLcolor *flatColor = gc->vertex.provoking->color;
  551. gc->polygon.shader.frag.color = *flatColor;
  552. }
  553. if (modeFlags & __GL_SHADE_TEXTURE) {
  554. __GLfloat awinv, bwinv, cwinv, scwinv, tcwinv, qwcwinv;
  555. __GLfloat dsAC, dsBC, dtAC, dtBC, dqwAC, dqwBC;
  556. awinv = a->window.w;
  557. bwinv = b->window.w;
  558. cwinv = c->window.w;
  559. scwinv = c->texture.x * cwinv;
  560. tcwinv = c->texture.y * cwinv;
  561. qwcwinv = c->texture.w * cwinv;
  562. dsAC = a->texture.x * awinv - scwinv;
  563. dsBC = b->texture.x * bwinv - scwinv;
  564. dtAC = a->texture.y * awinv - tcwinv;
  565. dtBC = b->texture.y * bwinv - tcwinv;
  566. dqwAC = a->texture.w * awinv - qwcwinv;
  567. dqwBC = b->texture.w * bwinv - qwcwinv;
  568. gc->polygon.shader.dsdx = dsAC * t2 - dsBC * t1;
  569. gc->polygon.shader.dsdy = dsBC * t3 - dsAC * t4;
  570. gc->polygon.shader.dtdx = dtAC * t2 - dtBC * t1;
  571. gc->polygon.shader.dtdy = dtBC * t3 - dtAC * t4;
  572. gc->polygon.shader.dqwdx = dqwAC * t2 - dqwBC * t1;
  573. gc->polygon.shader.dqwdy = dqwBC * t3 - dqwAC * t4;
  574. }
  575. } else {
  576. if (modeFlags & __GL_SHADE_SMOOTH) {
  577. __GLfloat drAC;
  578. __GLfloat drBC;
  579. __GLcolor *cc;
  580. cc = c->color;
  581. drAC = ac->r - cc->r;
  582. drBC = bc->r - cc->r;
  583. gc->polygon.shader.drdx = drAC * t2 - drBC * t1;
  584. gc->polygon.shader.drdy = drBC * t3 - drAC * t4;
  585. } else {
  586. __GLcolor *flatColor = gc->vertex.provoking->color;
  587. gc->polygon.shader.frag.color.r = flatColor->r;
  588. }
  589. }
  590. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  591. __GLfloat dzAC, dzBC;
  592. dzAC = a->window.z - c->window.z;
  593. dzBC = b->window.z - c->window.z;
  594. gc->polygon.shader.dzdxf = dzAC * t2 - dzBC * t1;
  595. gc->polygon.shader.dzdyf = dzBC * t3 - dzAC * t4;
  596. #ifdef NT
  597. if(( gc->modes.depthBits == 16 ) &&
  598. ( gc->depthBuffer.scale <= (GLuint)0xffff )) {
  599. gc->polygon.shader.dzdx =
  600. FLT_TO_Z16_SCALE(gc->polygon.shader.dzdxf);
  601. }
  602. else {
  603. gc->polygon.shader.dzdx = FTOL(gc->polygon.shader.dzdxf);
  604. }
  605. #else
  606. gc->polygon.shader.dzdx = (GLint) gc->polygon.shader.dzdxf;
  607. #endif
  608. }
  609. if (modeFlags & __GL_SHADE_COMPUTE_FOG)
  610. {
  611. __GLfloat dfAC, dfBC, cFog;
  612. aFog = a->eyeZ;
  613. bFog = b->eyeZ;
  614. cFog = c->eyeZ;
  615. dfAC = aFog - cFog;
  616. dfBC = bFog - cFog;
  617. gc->polygon.shader.dfdx = dfAC * t2 - dfBC * t1;
  618. gc->polygon.shader.dfdy = dfBC * t3 - dfAC * t4;
  619. }
  620. else if (modeFlags & __GL_SHADE_INTERP_FOG)
  621. {
  622. __GLfloat dfAC, dfBC, cFog;
  623. aFog = a->fog;
  624. bFog = b->fog;
  625. cFog = c->fog;
  626. dfAC = aFog - cFog;
  627. dfBC = bFog - cFog;
  628. gc->polygon.shader.dfdx = dfAC * t2 - dfBC * t1;
  629. gc->polygon.shader.dfdy = dfBC * t3 - dfAC * t4;
  630. }
  631. __GL_FLOAT_SIMPLE_BEGIN_DIVIDE(dxAC, dyAC, dxdyAC);
  632. /* Snap each y coordinate to its pixel center */
  633. aIY = __GL_VERTEX_FIXED_TO_INT(__GL_VERTEX_FLOAT_TO_FIXED(a->window.y)+
  634. __GL_VERTEX_FRAC_HALF);
  635. bIY = __GL_VERTEX_FIXED_TO_INT(__GL_VERTEX_FLOAT_TO_FIXED(b->window.y)+
  636. __GL_VERTEX_FRAC_HALF);
  637. cIY = __GL_VERTEX_FIXED_TO_INT(__GL_VERTEX_FLOAT_TO_FIXED(c->window.y)+
  638. __GL_VERTEX_FRAC_HALF);
  639. /*
  640. ** This algorithim always fills from bottom to top, left to right.
  641. ** Because of this, ccw triangles are inherently faster because
  642. ** the parameter values need not be recomputed.
  643. */
  644. dxAB = a->window.x - b->window.x;
  645. dyAB = a->window.y - b->window.y;
  646. if (ccw) {
  647. dy = (aIY + __glHalf) - a->window.y;
  648. __GL_FLOAT_SIMPLE_END_DIVIDE(dxdyAC);
  649. SnapXLeft(gc, a->window.x + dy*dxdyAC, dxdyAC);
  650. dx = (gc->polygon.shader.ixLeft + __glHalf) - a->window.x;
  651. #ifdef NT
  652. SetInitialParameters(gc, a, ac, aFog, dx, dy);
  653. #else
  654. SetInitialParameters(&gc->polygon.shader, a, ac, aFog, dx, dy);
  655. #endif
  656. if (aIY != bIY) {
  657. dxdyRight = dxAB / dyAB;
  658. SnapXRight(&gc->polygon.shader, a->window.x + dy*dxdyRight,
  659. dxdyRight);
  660. FillSubTriangle(gc, aIY, bIY);
  661. }
  662. if (bIY != cIY) {
  663. dxdyRight = dxBC / dyBC;
  664. dy = (bIY + __glHalf) - b->window.y;
  665. SnapXRight(&gc->polygon.shader, b->window.x + dy*dxdyRight,
  666. dxdyRight);
  667. FillSubTriangle(gc, bIY, cIY);
  668. }
  669. } else {
  670. dy = (aIY + __glHalf) - a->window.y;
  671. __GL_FLOAT_SIMPLE_END_DIVIDE(dxdyAC);
  672. SnapXRight(&gc->polygon.shader, a->window.x + dy*dxdyAC, dxdyAC);
  673. if (aIY != bIY) {
  674. dxdyLeft = dxAB / dyAB;
  675. SnapXLeft(gc, a->window.x + dy*dxdyLeft, dxdyLeft);
  676. dx = (gc->polygon.shader.ixLeft + __glHalf) - a->window.x;
  677. #ifdef NT
  678. SetInitialParameters(gc, a, ac, aFog, dx, dy);
  679. #else
  680. SetInitialParameters(&gc->polygon.shader, a, ac, aFog, dx, dy);
  681. #endif
  682. FillSubTriangle(gc, aIY, bIY);
  683. }
  684. if (bIY != cIY) {
  685. dxdyLeft = dxBC / dyBC;
  686. dy = (bIY + __glHalf) - b->window.y;
  687. SnapXLeft(gc, b->window.x + dy*dxdyLeft, dxdyLeft);
  688. dx = (gc->polygon.shader.ixLeft + __glHalf) - b->window.x;
  689. #ifdef NT
  690. SetInitialParameters(gc, b, bc, bFog, dx, dy);
  691. #else
  692. SetInitialParameters(&gc->polygon.shader, b, bc, bFog, dx, dy);
  693. #endif
  694. FillSubTriangle(gc, bIY, cIY);
  695. }
  696. }
  697. CHOP_ROUND_OFF();
  698. }
  699. void FASTCALL __glFillFlatFogTriangle(__GLcontext *gc, __GLvertex *a, __GLvertex *b,
  700. __GLvertex *c, GLboolean ccw)
  701. {
  702. __GLcolor acol, bcol, ccol;
  703. __GLcolor *aocp, *bocp, *cocp;
  704. __GLvertex *pv;
  705. pv = gc->vertex.provoking;
  706. (*gc->procs.fogColor)(gc, &acol, pv->color, a->fog);
  707. (*gc->procs.fogColor)(gc, &bcol, pv->color, b->fog);
  708. (*gc->procs.fogColor)(gc, &ccol, pv->color, c->fog);
  709. aocp = a->color;
  710. bocp = b->color;
  711. cocp = c->color;
  712. a->color = &acol;
  713. b->color = &bcol;
  714. c->color = &ccol;
  715. (*gc->procs.fillTriangle2)(gc, a, b, c, ccw);
  716. a->color = aocp;
  717. b->color = bocp;
  718. c->color = cocp;
  719. }
  720. #ifdef GL_WIN_specular_fog
  721. void FASTCALL __glFillFlatSpecFogTriangle(__GLcontext *gc, __GLvertex *a,
  722. __GLvertex *b, __GLvertex *c,
  723. GLboolean ccw)
  724. {
  725. __GLfloat af, bf, cf;
  726. __GLvertex *pv;
  727. pv = gc->vertex.provoking;
  728. af = a->fog;
  729. bf = b->fog;
  730. cf = c->fog;
  731. a->fog = b->fog = c->fog = pv->fog;
  732. (*gc->procs.fillTriangle2)(gc, a, b, c, ccw);
  733. a->fog = af;
  734. b->fog = bf;
  735. c->fog = cf;
  736. }
  737. #endif //GL_WIN_specular_fog