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

635 lines
21 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 <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <stddef.h>
  21. #include <windows.h>
  22. #include <winddi.h>
  23. #include "render.h"
  24. #include "context.h"
  25. #include "global.h"
  26. #include "gencx.h"
  27. #include "..\inc\wglp.h"
  28. #define FLT_TO_FIX(value) \
  29. *((GLint *)&value) = (GLint)(*((__GLfloat *)&(value)) * (__GLfloat)65536.0)
  30. /* This routine sets gc->polygon.shader.cfb to gc->drawBuffer */
  31. void __fastTriangleSetup(__GLcontext *gc)
  32. {
  33. SPANREC deltaRec;
  34. if (gc->polygon.shader.modeFlags & __GL_SHADE_RGB) {
  35. if (gc->polygon.shader.modeFlags & __GL_SHADE_DITHER) {
  36. __fastRGBSmoothSpanSetup(gc);
  37. __fastRGBFlatSpanSetup(gc);
  38. } else {
  39. __fastRGBNDSmoothSpanSetup(gc);
  40. __fastRGBNDFlatSpanSetup(gc);
  41. }
  42. } else {
  43. if (gc->polygon.shader.modeFlags & __GL_SHADE_DITHER) {
  44. __fastCISmoothSpanSetup(gc);
  45. __fastCIFlatSpanSetup(gc);
  46. } else {
  47. __fastCINDSmoothSpanSetup(gc);
  48. __fastCINDFlatSpanSetup(gc);
  49. }
  50. }
  51. deltaRec.r = 0;
  52. deltaRec.g = 0;
  53. deltaRec.b = 0;
  54. deltaRec.a = 0;
  55. deltaRec.z = 0;
  56. __fastDeltaSpan(gc, &deltaRec); // Set up initial delta values
  57. }
  58. /*static*/ void fastFillSubTriangle(__GLcontext *gc, GLint iyBottom, GLint iyTop)
  59. {
  60. GLint ixLeft, ixRight;
  61. GLint ixLeftFrac, ixRightFrac;
  62. GLint dxLeftFrac, dxRightFrac;
  63. GLint dxLeftLittle, dxRightLittle;
  64. GLint dxLeftBig, dxRightBig;
  65. GLint spanWidth, clipY0, clipY1;
  66. GLuint modeFlags;
  67. __GLGENcontext *gengc = (__GLGENcontext *)gc;
  68. #ifdef NT
  69. __GLstippleWord stackWords[__GL_MAX_STACK_STIPPLE_WORDS];
  70. __GLstippleWord *words;
  71. GLuint maxWidth;
  72. #else
  73. __GLstippleWord words[__GL_MAX_STIPPLE_WORDS];
  74. #endif
  75. __GLspanFunc spanFunc =
  76. ((FASTFUNCS *)(*((VOID **)(gengc->pPrivateArea))))->__fastSpanFuncPtr;
  77. #ifdef NT
  78. maxWidth = (gc->transform.clipX1 - gc->transform.clipX0) + 31;
  79. if (maxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  80. {
  81. words = __wglTempAlloc(gc, (maxWidth+__GL_STIPPLE_BITS-1)/8);
  82. if (words == NULL)
  83. {
  84. return;
  85. }
  86. }
  87. else
  88. {
  89. words = stackWords;
  90. }
  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.stipplePat = words;
  106. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  107. gc->polygon.shader.zbuf =
  108. __GL_DEPTH_ADDR(&gc->depthBuffer, (__GLzValue*),
  109. ixLeft, iyBottom);
  110. }
  111. gc->polygon.shader.cfb = gc->drawBuffer;
  112. while (iyBottom < iyTop) {
  113. spanWidth = ixRight - ixLeft;
  114. /*
  115. ** Only render spans that have non-zero width and which are
  116. ** not scissored out vertically.
  117. */
  118. if ((spanWidth > 0) && (iyBottom >= clipY0) && (iyBottom < clipY1)) {
  119. gc->polygon.shader.frag.x = ixLeft;
  120. gc->polygon.shader.frag.y = iyBottom;
  121. gc->polygon.shader.length = spanWidth;
  122. if (gc->state.raster.drawBuffer == GL_FRONT_AND_BACK) {
  123. gc->polygon.shader.cfb = &gc->frontBuffer;
  124. (*spanFunc)(gc);
  125. if (!((GLint)gc->polygon.shader.cfb->buf.other & DIB_FORMAT))
  126. wglCopyBits(gengc->pdco, gengc->pwo, gengc->ColorsBitmap,
  127. __GL_UNBIAS_X(gc, ixLeft) +
  128. gc->drawBuffer->buf.xOrigin,
  129. __GL_UNBIAS_Y(gc, iyBottom) +
  130. gc->drawBuffer->buf.yOrigin,
  131. spanWidth, TRUE);
  132. gc->polygon.shader.cfb = &gc->backBuffer;
  133. (*spanFunc)(gc);
  134. } else {
  135. (*spanFunc)(gc);
  136. if (!((GLint)gc->drawBuffer->buf.other & DIB_FORMAT))
  137. wglCopyBits(gengc->pdco, gengc->pwo, gengc->ColorsBitmap,
  138. __GL_UNBIAS_X(gc, ixLeft) +
  139. gc->drawBuffer->buf.xOrigin,
  140. __GL_UNBIAS_Y(gc, iyBottom) +
  141. gc->drawBuffer->buf.yOrigin,
  142. spanWidth, TRUE);
  143. }
  144. }
  145. /* Advance right edge fixed point, adjusting for carry */
  146. ixRightFrac += dxRightFrac;
  147. if (ixRightFrac < 0) {
  148. /* Carry/Borrow'd. Use large step */
  149. ixRight += dxRightBig;
  150. ixRightFrac &= ~0x80000000;
  151. } else {
  152. ixRight += dxRightLittle;
  153. }
  154. iyBottom++;
  155. ixLeftFrac += dxLeftFrac;
  156. if (ixLeftFrac < 0) {
  157. /* Carry/Borrow'd. Use large step */
  158. ixLeft += dxLeftBig;
  159. ixLeftFrac &= ~0x80000000;
  160. if (modeFlags & __GL_SHADE_RGB) {
  161. if (modeFlags & __GL_SHADE_SMOOTH) {
  162. *((GLint *)&gc->polygon.shader.frag.color.r) +=
  163. *((GLint *)&gc->polygon.shader.rBig);
  164. *((GLint *)&gc->polygon.shader.frag.color.g) +=
  165. *((GLint *)&gc->polygon.shader.gBig);
  166. *((GLint *)&gc->polygon.shader.frag.color.b) +=
  167. *((GLint *)&gc->polygon.shader.bBig);
  168. *((GLint *)&gc->polygon.shader.frag.color.a) +=
  169. *((GLint *)&gc->polygon.shader.aBig);
  170. }
  171. } else {
  172. if (modeFlags & __GL_SHADE_SMOOTH) {
  173. *((GLint *)&gc->polygon.shader.frag.color.r) +=
  174. *((GLint *)&gc->polygon.shader.rBig);
  175. }
  176. }
  177. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  178. gc->polygon.shader.frag.z += gc->polygon.shader.zBig;
  179. }
  180. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  181. /* The implicit multiply is taken out of the loop */
  182. gc->polygon.shader.zbuf = (__GLzValue*)
  183. ((GLubyte*) gc->polygon.shader.zbuf
  184. + gc->polygon.shader.zbufBig);
  185. }
  186. } else {
  187. /* Use small step */
  188. ixLeft += dxLeftLittle;
  189. if (modeFlags & __GL_SHADE_RGB) {
  190. if (modeFlags & __GL_SHADE_SMOOTH) {
  191. *((GLint *)&gc->polygon.shader.frag.color.r) +=
  192. *((GLint *)&gc->polygon.shader.rLittle);
  193. *((GLint *)&gc->polygon.shader.frag.color.g) +=
  194. *((GLint *)&gc->polygon.shader.gLittle);
  195. *((GLint *)&gc->polygon.shader.frag.color.b) +=
  196. *((GLint *)&gc->polygon.shader.bLittle);
  197. *((GLint *)&gc->polygon.shader.frag.color.a) +=
  198. *((GLint *)&gc->polygon.shader.aLittle);
  199. }
  200. } else {
  201. if (modeFlags & __GL_SHADE_SMOOTH) {
  202. *((GLint *)&gc->polygon.shader.frag.color.r) +=
  203. *((GLint *)&gc->polygon.shader.rLittle);
  204. }
  205. }
  206. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  207. gc->polygon.shader.frag.z += gc->polygon.shader.zLittle;
  208. }
  209. if (modeFlags & __GL_SHADE_DEPTH_TEST) {
  210. /* The implicit multiply is taken out of the loop */
  211. gc->polygon.shader.zbuf = (__GLzValue*)
  212. ((GLubyte*) gc->polygon.shader.zbuf
  213. + gc->polygon.shader.zbufLittle);
  214. }
  215. }
  216. }
  217. gc->polygon.shader.ixLeft = ixLeft;
  218. gc->polygon.shader.ixLeftFrac = ixLeftFrac;
  219. gc->polygon.shader.ixRight = ixRight;
  220. gc->polygon.shader.ixRightFrac = ixRightFrac;
  221. #ifdef NT
  222. if (maxWidth > __GL_MAX_STACK_STIPPLE_BITS)
  223. {
  224. __wglTempFree(gc, words);
  225. }
  226. #endif
  227. }
  228. #define __TWO_31 ((__GLfloat) 2147483648.0)
  229. #define __FRACTION(result,f) \
  230. result = (GLint) ((f) * __TWO_31)
  231. static void SnapXLeft(__GLcontext *gc, __GLfloat xLeft, __GLfloat dxdyLeft)
  232. {
  233. __GLfloat little, dx;
  234. GLint ixLeft, ixLeftFrac, frac, lineBytes, elementSize, ilittle, ibig;
  235. ixLeft = (GLint) xLeft;
  236. dx = xLeft - ixLeft;
  237. __FRACTION(ixLeftFrac,dx);
  238. /* Pre-add .5 to allow truncation in spanWidth calculation */
  239. ixLeftFrac += 0x40000000;
  240. gc->polygon.shader.ixLeft = ixLeft + (((GLuint) ixLeftFrac) >> 31);
  241. gc->polygon.shader.ixLeftFrac = ixLeftFrac & ~0x80000000;
  242. /* Compute big and little steps */
  243. ilittle = (GLint) dxdyLeft;
  244. little = (__GLfloat) ilittle;
  245. if (dxdyLeft < 0) {
  246. ibig = ilittle - 1;
  247. dx = little - dxdyLeft;
  248. __FRACTION(frac,dx);
  249. gc->polygon.shader.dxLeftFrac = -frac;
  250. } else {
  251. ibig = ilittle + 1;
  252. dx = dxdyLeft - little;
  253. __FRACTION(frac,dx);
  254. gc->polygon.shader.dxLeftFrac = frac;
  255. }
  256. if (gc->polygon.shader.modeFlags & __GL_SHADE_DEPTH_TEST) {
  257. /*
  258. ** Compute the big and little depth buffer steps. We walk the
  259. ** memory pointers for the depth buffer along the edge of the
  260. ** triangle as we walk the edge. This way we don't have to
  261. ** recompute the buffer address as we go.
  262. */
  263. elementSize = gc->depthBuffer.buf.elementSize;
  264. lineBytes = elementSize * gc->depthBuffer.buf.outerWidth;
  265. gc->polygon.shader.zbufLittle = lineBytes + ilittle * elementSize;
  266. gc->polygon.shader.zbufBig = lineBytes + ibig * elementSize;
  267. }
  268. gc->polygon.shader.dxLeftLittle = ilittle;
  269. gc->polygon.shader.dxLeftBig = ibig;
  270. }
  271. static void SnapXRight(__GLshade *sh, __GLfloat xRight, __GLfloat dxdyRight)
  272. {
  273. __GLfloat little, big, dx;
  274. GLint ixRight, ixRightFrac, frac;
  275. ixRight = (GLint) xRight;
  276. dx = xRight - ixRight;
  277. __FRACTION(ixRightFrac,dx);
  278. /* Pre-add .5 to allow truncation in spanWidth calculation */
  279. ixRightFrac += 0x40000000;
  280. sh->ixRight = ixRight + (((GLuint) ixRightFrac) >> 31);
  281. sh->ixRightFrac = ixRightFrac & ~0x80000000;
  282. /* Compute big and little steps */
  283. little = (__GLfloat) ((GLint) dxdyRight);
  284. if (dxdyRight < 0) {
  285. big = little - 1;
  286. dx = little - dxdyRight;
  287. __FRACTION(frac,dx);
  288. sh->dxRightFrac = -frac;
  289. } else {
  290. big = little + 1;
  291. dx = dxdyRight - little;
  292. __FRACTION(frac,dx);
  293. sh->dxRightFrac = frac;
  294. }
  295. sh->dxRightLittle = (GLint) little;
  296. sh->dxRightBig = (GLint) big;
  297. }
  298. static void SetInitialParameters(__GLshade *sh, const __GLvertex *a,
  299. const __GLcolor *ac, __GLfloat aFog,
  300. __GLfloat dx, __GLfloat dy)
  301. {
  302. __GLfloat little = sh->dxLeftLittle;
  303. __GLfloat big = sh->dxLeftBig;
  304. GLuint modeFlags = sh->modeFlags;
  305. if (big > little) {
  306. if (modeFlags & __GL_SHADE_RGB) {
  307. if (modeFlags & __GL_SHADE_SMOOTH) {
  308. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  309. sh->rLittle = sh->drdy + little * sh->drdx;
  310. sh->rBig = sh->rLittle + sh->drdx;
  311. sh->frag.color.g = ac->g + dx*sh->dgdx + dy*sh->dgdy;
  312. sh->gLittle = sh->dgdy + little * sh->dgdx;
  313. sh->gBig = sh->gLittle + sh->dgdx;
  314. sh->frag.color.b = ac->b + dx*sh->dbdx + dy*sh->dbdy;
  315. sh->bLittle = sh->dbdy + little * sh->dbdx;
  316. sh->bBig = sh->bLittle + sh->dbdx;
  317. sh->frag.color.a = ac->a + dx*sh->dadx + dy*sh->dady;
  318. sh->aLittle = sh->dady + little * sh->dadx;
  319. sh->aBig =sh->aLittle + sh->dadx;
  320. FLT_TO_FIX(sh->frag.color.r);
  321. FLT_TO_FIX(sh->frag.color.g);
  322. FLT_TO_FIX(sh->frag.color.b);
  323. FLT_TO_FIX(sh->frag.color.a);
  324. FLT_TO_FIX(sh->rLittle);
  325. FLT_TO_FIX(sh->gLittle);
  326. FLT_TO_FIX(sh->bLittle);
  327. FLT_TO_FIX(sh->aLittle);
  328. FLT_TO_FIX(sh->rBig);
  329. FLT_TO_FIX(sh->gBig);
  330. FLT_TO_FIX(sh->bBig);
  331. FLT_TO_FIX(sh->aBig);
  332. }
  333. } else {
  334. if (modeFlags & __GL_SHADE_SMOOTH) {
  335. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  336. sh->rLittle = sh->drdy + little * sh->drdx;
  337. sh->rBig = sh->rLittle + sh->drdx;
  338. FLT_TO_FIX(sh->frag.color.r);
  339. FLT_TO_FIX(sh->rLittle);
  340. FLT_TO_FIX(sh->rBig);
  341. }
  342. }
  343. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  344. __GLfloat zLittle;
  345. sh->frag.z = (__GLzValue)
  346. (a->window.z + dx*sh->dzdxf + dy*sh->dzdyf);
  347. zLittle = sh->dzdyf + little * sh->dzdxf;
  348. sh->zLittle = (GLint)zLittle;
  349. sh->zBig = (GLint)(zLittle + sh->dzdxf);
  350. }
  351. if (modeFlags & __GL_SHADE_SLOW_FOG) {
  352. sh->frag.f = aFog + dx*sh->dfdx + dy*sh->dfdy;
  353. sh->fLittle = sh->dfdy + little * sh->dfdx;
  354. sh->fBig = sh->fLittle + sh->dfdx;
  355. FLT_TO_FIX(sh->frag.f);
  356. FLT_TO_FIX(sh->fLittle);
  357. FLT_TO_FIX(sh->fBig);
  358. }
  359. } else {
  360. if (modeFlags & __GL_SHADE_RGB) {
  361. if (modeFlags & __GL_SHADE_SMOOTH) {
  362. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  363. sh->rLittle = sh->drdy + little * sh->drdx;
  364. sh->rBig = sh->rLittle - sh->drdx;
  365. sh->frag.color.g = ac->g + dx*sh->dgdx + dy*sh->dgdy;
  366. sh->gLittle = sh->dgdy + little * sh->dgdx;
  367. sh->gBig = sh->gLittle - sh->dgdx;
  368. sh->frag.color.b = ac->b + dx*sh->dbdx + dy*sh->dbdy;
  369. sh->bLittle = sh->dbdy + little * sh->dbdx;
  370. sh->bBig = sh->bLittle - sh->dbdx;
  371. sh->frag.color.a = ac->a + dx*sh->dadx + dy*sh->dady;
  372. sh->aLittle = sh->dady + little * sh->dadx;
  373. sh->aBig =sh->aLittle - sh->dadx;
  374. FLT_TO_FIX(sh->frag.color.r);
  375. FLT_TO_FIX(sh->frag.color.g);
  376. FLT_TO_FIX(sh->frag.color.b);
  377. FLT_TO_FIX(sh->frag.color.a);
  378. FLT_TO_FIX(sh->rLittle);
  379. FLT_TO_FIX(sh->gLittle);
  380. FLT_TO_FIX(sh->bLittle);
  381. FLT_TO_FIX(sh->aLittle);
  382. FLT_TO_FIX(sh->rBig);
  383. FLT_TO_FIX(sh->gBig);
  384. FLT_TO_FIX(sh->bBig);
  385. FLT_TO_FIX(sh->aBig);
  386. }
  387. } else {
  388. if (modeFlags & __GL_SHADE_SMOOTH) {
  389. sh->frag.color.r = ac->r + dx*sh->drdx + dy*sh->drdy;
  390. sh->rLittle = sh->drdy + little * sh->drdx;
  391. sh->rBig = sh->rLittle - sh->drdx;
  392. FLT_TO_FIX(sh->frag.color.r);
  393. FLT_TO_FIX(sh->rLittle);
  394. FLT_TO_FIX(sh->rBig);
  395. }
  396. }
  397. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  398. __GLfloat zLittle;
  399. sh->frag.z = (__GLzValue)
  400. (a->window.z + dx*sh->dzdxf + dy*sh->dzdyf);
  401. zLittle = sh->dzdyf + little * sh->dzdxf;
  402. sh->zLittle = (GLint)zLittle;
  403. sh->zBig = (GLint)(zLittle - sh->dzdxf);
  404. }
  405. if (modeFlags & __GL_SHADE_SLOW_FOG) {
  406. sh->frag.f = aFog + dx*sh->dfdx + dy*sh->dfdy;
  407. sh->fLittle = sh->dfdy + little * sh->dfdx;
  408. sh->fBig = sh->fLittle - sh->dfdx;
  409. FLT_TO_FIX(sh->frag.f);
  410. FLT_TO_FIX(sh->fLittle);
  411. FLT_TO_FIX(sh->fBig);
  412. }
  413. }
  414. }
  415. void __fastFillTriangle(__GLcontext *gc, __GLvertex *a, __GLvertex *b,
  416. __GLvertex *c, GLboolean ccw)
  417. {
  418. __GLfloat oneOverArea, t1, t2, t3, t4;
  419. __GLfloat dxAC, dxBC, dyAC, dyBC;
  420. __GLfloat aFog, bFog;
  421. __GLfloat dxAB, dyAB;
  422. __GLfloat dx, dy, dxdyLeft, dxdyRight;
  423. __GLcolor *ac, *bc;
  424. GLint aIY, bIY, cIY;
  425. GLuint modeFlags;
  426. SPANREC deltaRec;
  427. /* Pre-compute one over polygon area */
  428. oneOverArea = __glOne / gc->polygon.shader.area;
  429. /* Fetch some stuff we are going to reuse */
  430. modeFlags = gc->polygon.shader.modeFlags;
  431. dxAC = gc->polygon.shader.dxAC;
  432. dxBC = gc->polygon.shader.dxBC;
  433. dyAC = gc->polygon.shader.dyAC;
  434. dyBC = gc->polygon.shader.dyBC;
  435. ac = a->color;
  436. bc = b->color;
  437. /*
  438. ** Compute delta values for unit changes in x or y for each
  439. ** parameter.
  440. */
  441. t1 = dyAC * oneOverArea;
  442. t2 = dyBC * oneOverArea;
  443. t3 = dxAC * oneOverArea;
  444. t4 = dxBC * oneOverArea;
  445. if (modeFlags & __GL_SHADE_RGB) {
  446. if (modeFlags & __GL_SHADE_SMOOTH) {
  447. __GLfloat drAC, dgAC, dbAC, daAC;
  448. __GLfloat drBC, dgBC, dbBC, daBC;
  449. __GLcolor *cc;
  450. cc = c->color;
  451. drAC = ac->r - cc->r;
  452. drBC = bc->r - cc->r;
  453. gc->polygon.shader.drdx = drAC * t2 - drBC * t1;
  454. gc->polygon.shader.drdy = drBC * t3 - drAC * t4;
  455. dgAC = ac->g - cc->g;
  456. dgBC = bc->g - cc->g;
  457. gc->polygon.shader.dgdx = dgAC * t2 - dgBC * t1;
  458. gc->polygon.shader.dgdy = dgBC * t3 - dgAC * t4;
  459. dbAC = ac->b - cc->b;
  460. dbBC = bc->b - cc->b;
  461. gc->polygon.shader.dbdx = dbAC * t2 - dbBC * t1;
  462. gc->polygon.shader.dbdy = dbBC * t3 - dbAC * t4;
  463. daAC = ac->a - cc->a;
  464. daBC = bc->a - cc->a;
  465. gc->polygon.shader.dadx = daAC * t2 - daBC * t1;
  466. gc->polygon.shader.dady = daBC * t3 - daAC * t4;
  467. RtlCopyMemory(&deltaRec.r, &gc->polygon.shader.drdx,
  468. 4 * sizeof(__GLfloat));
  469. FLT_TO_FIX(deltaRec.r);
  470. FLT_TO_FIX(deltaRec.g);
  471. FLT_TO_FIX(deltaRec.b);
  472. FLT_TO_FIX(deltaRec.a);
  473. } else {
  474. __GLcolor *flatColor = gc->vertex.provoking->color;
  475. gc->polygon.shader.frag.color.r = flatColor->r;
  476. gc->polygon.shader.frag.color.g = flatColor->g;
  477. gc->polygon.shader.frag.color.b = flatColor->b;
  478. gc->polygon.shader.frag.color.a = flatColor->a;
  479. FLT_TO_FIX(gc->polygon.shader.frag.color.r);
  480. FLT_TO_FIX(gc->polygon.shader.frag.color.g);
  481. FLT_TO_FIX(gc->polygon.shader.frag.color.b);
  482. FLT_TO_FIX(gc->polygon.shader.frag.color.a);
  483. }
  484. } else {
  485. if (modeFlags & __GL_SHADE_SMOOTH) {
  486. __GLfloat drAC;
  487. __GLfloat drBC;
  488. __GLcolor *cc;
  489. cc = c->color;
  490. drAC = ac->r - cc->r;
  491. drBC = bc->r - cc->r;
  492. gc->polygon.shader.drdx = drAC * t2 - drBC * t1;
  493. gc->polygon.shader.drdy = drBC * t3 - drAC * t4;
  494. deltaRec.r = *((GLint *)&gc->polygon.shader.drdx);
  495. FLT_TO_FIX(deltaRec.r);
  496. } else {
  497. __GLcolor *flatColor = gc->vertex.provoking->color;
  498. gc->polygon.shader.frag.color.r = flatColor->r;
  499. FLT_TO_FIX(gc->polygon.shader.frag.color.r);
  500. }
  501. }
  502. if (modeFlags & __GL_SHADE_DEPTH_ITER) {
  503. __GLfloat dzAC, dzBC;
  504. dzAC = a->window.z - c->window.z;
  505. dzBC = b->window.z - c->window.z;
  506. gc->polygon.shader.dzdxf = dzAC * t2 - dzBC * t1;
  507. gc->polygon.shader.dzdyf = dzBC * t3 - dzAC * t4;
  508. deltaRec.z = gc->polygon.shader.dzdx = (GLint) gc->polygon.shader.dzdxf;
  509. }
  510. __fastDeltaSpan(gc, &deltaRec); // Set up span delta values
  511. /* Snap each y coordinate to its pixel center */
  512. aIY = (GLint) (a->window.y + __glHalf);
  513. bIY = (GLint) (b->window.y + __glHalf);
  514. cIY = (GLint) (c->window.y + __glHalf);
  515. /*
  516. ** This algorithim always fills from bottom to top, left to right.
  517. ** Because of this, ccw triangles are inherently faster because
  518. ** the parameter values need not be recomputed.
  519. */
  520. dxAB = a->window.x - b->window.x;
  521. dyAB = a->window.y - b->window.y;
  522. if (ccw) {
  523. dxdyLeft = dxAC / dyAC;
  524. dy = (aIY + __glHalf) - a->window.y;
  525. SnapXLeft(gc, a->window.x + dy*dxdyLeft, dxdyLeft);
  526. dx = (gc->polygon.shader.ixLeft + __glHalf) - a->window.x;
  527. SetInitialParameters(&gc->polygon.shader, a, ac, aFog, dx, dy);
  528. if (aIY != bIY) {
  529. dxdyRight = dxAB / dyAB;
  530. SnapXRight(&gc->polygon.shader, a->window.x + dy*dxdyRight,
  531. dxdyRight);
  532. fastFillSubTriangle(gc, aIY, bIY);
  533. }
  534. if (bIY != cIY) {
  535. dxdyRight = dxBC / dyBC;
  536. dy = (bIY + __glHalf) - b->window.y;
  537. SnapXRight(&gc->polygon.shader, b->window.x + dy*dxdyRight,
  538. dxdyRight);
  539. fastFillSubTriangle(gc, bIY, cIY);
  540. }
  541. } else {
  542. dxdyRight = dxAC / dyAC;
  543. dy = (aIY + __glHalf) - a->window.y;
  544. SnapXRight(&gc->polygon.shader, a->window.x + dy*dxdyRight, dxdyRight);
  545. if (aIY != bIY) {
  546. dxdyLeft = dxAB / dyAB;
  547. SnapXLeft(gc, a->window.x + dy*dxdyLeft, dxdyLeft);
  548. dx = (gc->polygon.shader.ixLeft + __glHalf) - a->window.x;
  549. SetInitialParameters(&gc->polygon.shader, a, ac, aFog, dx, dy);
  550. fastFillSubTriangle(gc, aIY, bIY);
  551. }
  552. if (bIY != cIY) {
  553. dxdyLeft = dxBC / dyBC;
  554. dy = (bIY + __glHalf) - b->window.y;
  555. SnapXLeft(gc, b->window.x + dy*dxdyLeft, dxdyLeft);
  556. dx = (gc->polygon.shader.ixLeft + __glHalf) - b->window.x;
  557. SetInitialParameters(&gc->polygon.shader, b, bc, bFog, dx, dy);
  558. fastFillSubTriangle(gc, bIY, cIY);
  559. }
  560. }
  561. }