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.

925 lines
23 KiB

  1. /*
  2. ** Copyright 1991, 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. ** $Revision: 1.14 $
  18. ** $Date: 1993/04/14 21:23:50 $
  19. */
  20. #include "precomp.h"
  21. #pragma hdrstop
  22. void __glDoBlendSourceZERO(__GLcontext *gc, const __GLcolor *source,
  23. const __GLcolor *dest, __GLcolor *result)
  24. {
  25. __GLfloat zero = __glZero;
  26. #ifdef __GL_LINT
  27. gc = gc;
  28. source = source;
  29. dest = dest;
  30. #endif
  31. result->r = zero;
  32. result->g = zero;
  33. result->b = zero;
  34. result->a = zero;
  35. }
  36. void __glDoBlendDestZERO(__GLcontext *gc, const __GLcolor *source,
  37. const __GLcolor *dest, __GLcolor *result)
  38. {
  39. #ifdef __GL_LINT
  40. gc = gc;
  41. source = source;
  42. dest = dest;
  43. result = result;
  44. #endif
  45. /* Pretend to add zero to each component of the result.
  46. **
  47. ** result->r += zero;
  48. ** result->g += zip;
  49. ** result->b += squat;
  50. ** result->a += a bagel;
  51. */
  52. }
  53. void __glDoBlendSourceONE(__GLcontext *gc, const __GLcolor *source,
  54. const __GLcolor *dest, __GLcolor *result)
  55. {
  56. /* Compiler hints */
  57. __GLfloat r, g, b, a;
  58. #ifdef __GL_LINT
  59. gc = gc;
  60. dest = dest;
  61. #endif
  62. r = source->r;
  63. g = source->g;
  64. b = source->b;
  65. a = source->a;
  66. result->r = r;
  67. result->g = g;
  68. result->b = b;
  69. result->a = a;
  70. }
  71. void __glDoBlendDestONE(__GLcontext *gc, const __GLcolor *source,
  72. const __GLcolor *dest, __GLcolor *result)
  73. {
  74. /* Compiler hints */
  75. __GLfloat r, g, b, a;
  76. #ifdef __GL_LINT
  77. gc = gc;
  78. source = source;
  79. #endif
  80. r = dest->r;
  81. g = dest->g;
  82. b = dest->b;
  83. a = dest->a;
  84. result->r += r;
  85. result->g += g;
  86. result->b += b;
  87. result->a += a;
  88. }
  89. void __glDoBlendDestSC(__GLcontext *gc, const __GLcolor *source,
  90. const __GLcolor *dest, __GLcolor *result)
  91. {
  92. /* Compiler hints */
  93. __GLfloat r, g, b, a;
  94. r = dest->r * source->r * gc->frontBuffer.oneOverRedScale;
  95. g = dest->g * source->g * gc->frontBuffer.oneOverGreenScale;
  96. b = dest->b * source->b * gc->frontBuffer.oneOverBlueScale;
  97. a = dest->a * source->a * gc->frontBuffer.oneOverAlphaScale;
  98. result->r += r;
  99. result->g += g;
  100. result->b += b;
  101. result->a += a;
  102. }
  103. void __glDoBlendDestMSC(__GLcontext *gc, const __GLcolor *source,
  104. const __GLcolor *dest, __GLcolor *result)
  105. {
  106. /* Compiler hints */
  107. __GLfloat r, g, b, a;
  108. __GLfloat one = __glOne;
  109. r = dest->r * (one - source->r * gc->frontBuffer.oneOverRedScale);
  110. g = dest->g * (one - source->g * gc->frontBuffer.oneOverGreenScale);
  111. b = dest->b * (one - source->b * gc->frontBuffer.oneOverBlueScale);
  112. a = dest->a * (one - source->a * gc->frontBuffer.oneOverAlphaScale);
  113. result->r += r;
  114. result->g += g;
  115. result->b += b;
  116. result->a += a;
  117. }
  118. void __glDoBlendSourceDC(__GLcontext *gc, const __GLcolor *source,
  119. const __GLcolor *dest, __GLcolor *result)
  120. {
  121. /* Compiler hints */
  122. __GLfloat r, g, b, a;
  123. r = source->r * dest->r * gc->frontBuffer.oneOverRedScale;
  124. g = source->g * dest->g * gc->frontBuffer.oneOverGreenScale;
  125. b = source->b * dest->b * gc->frontBuffer.oneOverBlueScale;
  126. a = source->a * dest->a * gc->frontBuffer.oneOverAlphaScale;
  127. result->r = r;
  128. result->g = g;
  129. result->b = b;
  130. result->a = a;
  131. }
  132. void __glDoBlendSourceMDC(__GLcontext *gc, const __GLcolor *source,
  133. const __GLcolor *dest, __GLcolor *result)
  134. {
  135. /* Compiler hints */
  136. __GLfloat r, g, b, a;
  137. __GLfloat one = __glOne;
  138. r = source->r * (one - dest->r * gc->frontBuffer.oneOverRedScale);
  139. g = source->g * (one - dest->g * gc->frontBuffer.oneOverGreenScale);
  140. b = source->b * (one - dest->b * gc->frontBuffer.oneOverBlueScale);
  141. a = source->a * (one - dest->a * gc->frontBuffer.oneOverAlphaScale);
  142. result->r = r;
  143. result->g = g;
  144. result->b = b;
  145. result->a = a;
  146. }
  147. void __glDoBlendSourceSA(__GLcontext *gc, const __GLcolor *source,
  148. const __GLcolor *dest, __GLcolor *result)
  149. {
  150. /* Compiler hints */
  151. __GLfloat r, g, b, a;
  152. #ifdef __GL_LINT
  153. dest = dest;
  154. #endif
  155. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  156. r = a * source->r;
  157. g = a * source->g;
  158. b = a * source->b;
  159. a = a * source->a;
  160. result->r = r;
  161. result->g = g;
  162. result->b = b;
  163. result->a = a;
  164. }
  165. void __glDoBlendDestSA(__GLcontext *gc, const __GLcolor *source,
  166. const __GLcolor *dest, __GLcolor *result)
  167. {
  168. /* Compiler hints */
  169. __GLfloat r, g, b, a;
  170. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  171. r = a * dest->r;
  172. g = a * dest->g;
  173. b = a * dest->b;
  174. a = a * dest->a;
  175. result->r += r;
  176. result->g += g;
  177. result->b += b;
  178. result->a += a;
  179. }
  180. void __glDoBlendSourceMSA(__GLcontext *gc, const __GLcolor *source,
  181. const __GLcolor *dest, __GLcolor *result)
  182. {
  183. /* Compiler hints */
  184. __GLfloat r, g, b, a;
  185. __GLfloat msa = __glOne - source->a * gc->frontBuffer.oneOverAlphaScale;
  186. #ifdef __GL_LINT
  187. dest = dest;
  188. #endif
  189. r = msa * source->r;
  190. g = msa * source->g;
  191. b = msa * source->b;
  192. a = msa * source->a;
  193. result->r = r;
  194. result->g = g;
  195. result->b = b;
  196. result->a = a;
  197. }
  198. void __glDoBlendDestMSA(__GLcontext *gc, const __GLcolor *source,
  199. const __GLcolor *dest, __GLcolor *result)
  200. {
  201. /* Compiler hints */
  202. __GLfloat r, g, b, a;
  203. __GLfloat msa =
  204. __glOne - source->a * gc->frontBuffer.oneOverAlphaScale;
  205. r = msa * dest->r;
  206. g = msa * dest->g;
  207. b = msa * dest->b;
  208. a = msa * dest->a;
  209. result->r += r;
  210. result->g += g;
  211. result->b += b;
  212. result->a += a;
  213. }
  214. void __glDoBlendSourceDA(__GLcontext *gc, const __GLcolor *source,
  215. const __GLcolor *dest, __GLcolor *result)
  216. {
  217. /* Compiler hints */
  218. __GLfloat r, g, b;
  219. __GLfloat a = dest->a * gc->frontBuffer.oneOverAlphaScale;
  220. r = a * source->r;
  221. g = a * source->g;
  222. b = a * source->b;
  223. a = a * source->a;
  224. result->r = r;
  225. result->g = g;
  226. result->b = b;
  227. result->a = a;
  228. }
  229. void __glDoBlendDestDA(__GLcontext *gc, const __GLcolor *source,
  230. const __GLcolor *dest, __GLcolor *result)
  231. {
  232. /* Compiler hints */
  233. __GLfloat r, g, b;
  234. __GLfloat a = dest->a * gc->frontBuffer.oneOverAlphaScale;
  235. #ifdef __GL_LINT
  236. source = source;
  237. #endif
  238. r = a * dest->r;
  239. g = a * dest->g;
  240. b = a * dest->b;
  241. a = a * dest->a;
  242. result->r += r;
  243. result->g += g;
  244. result->b += b;
  245. result->a += a;
  246. }
  247. void __glDoBlendSourceMDA(__GLcontext *gc, const __GLcolor *source,
  248. const __GLcolor *dest, __GLcolor *result)
  249. {
  250. /* Compiler hints */
  251. __GLfloat r, g, b, a;
  252. __GLfloat mda;
  253. mda = __glOne - dest->a * gc->frontBuffer.oneOverAlphaScale;
  254. r = mda * source->r;
  255. g = mda * source->g;
  256. b = mda * source->b;
  257. a = mda * source->a;
  258. result->r = r;
  259. result->g = g;
  260. result->b = b;
  261. result->a = a;
  262. }
  263. void __glDoBlendDestMDA(__GLcontext *gc, const __GLcolor *source,
  264. const __GLcolor *dest, __GLcolor *result)
  265. {
  266. /* Compiler hints */
  267. __GLfloat r, g, b, a;
  268. __GLfloat mda;
  269. #ifdef __GL_LINT
  270. source = source;
  271. #endif
  272. mda = __glOne - dest->a * gc->frontBuffer.oneOverAlphaScale;
  273. r = mda * dest->r;
  274. g = mda * dest->g;
  275. b = mda * dest->b;
  276. a = mda * dest->a;
  277. result->r += r;
  278. result->g += g;
  279. result->b += b;
  280. result->a += a;
  281. }
  282. void __glDoBlendSourceSAT(__GLcontext *gc, const __GLcolor *source,
  283. const __GLcolor *dest, __GLcolor *result)
  284. {
  285. /* Compiler hints */
  286. __GLfloat r, g, b;
  287. __GLfloat sa, mda;
  288. mda = __glOne - dest->a * gc->frontBuffer.oneOverAlphaScale;
  289. sa = source->a * gc->frontBuffer.oneOverAlphaScale;
  290. if (sa < mda) {
  291. r = sa * source->r;
  292. g = sa * source->g;
  293. b = sa * source->b;
  294. } else {
  295. r = mda * source->r;
  296. g = mda * source->g;
  297. b = mda * source->b;
  298. }
  299. result->a = source->a;
  300. result->r = r;
  301. result->g = g;
  302. result->b = b;
  303. }
  304. /************************************************************************/
  305. static void Nop(__GLcontext *gc, const __GLcolor *source,
  306. const __GLcolor *dest, __GLcolor *result)
  307. {
  308. #ifdef __GL_LINT
  309. gc = gc;
  310. source = source;
  311. dest = dest;
  312. result = result;
  313. #endif
  314. }
  315. /*
  316. ** Generic blend not handled by cases below
  317. */
  318. static void NoFetchBlend(__GLcontext *gc, __GLcolorBuffer *cfb,
  319. const __GLfragment *frag, __GLcolor *result)
  320. {
  321. #ifdef __GL_LINT
  322. cfb = cfb;
  323. #endif
  324. (*gc->procs.blendColor)(gc, &(frag->color), NULL, result);
  325. }
  326. /*
  327. ** Generic blend not handled by cases below
  328. */
  329. static void FetchBlend(__GLcontext *gc, __GLcolorBuffer *cfb,
  330. const __GLfragment *frag, __GLcolor *result)
  331. {
  332. __GLcolor dest;
  333. (*cfb->fetch)(cfb, frag->x, frag->y, &dest);
  334. (*gc->procs.blendColor)(gc, &(frag->color), &dest, result);
  335. }
  336. void __glDoBlend(__GLcontext *gc, const __GLcolor *source,
  337. const __GLcolor *dest, __GLcolor *result)
  338. {
  339. (*gc->procs.blendSrc)(gc, source, dest, result);
  340. (*gc->procs.blendDst)(gc, source, dest, result);
  341. if (result->r > gc->frontBuffer.redScale) {
  342. result->r = gc->frontBuffer.redScale;
  343. }
  344. if (result->g > gc->frontBuffer.greenScale) {
  345. result->g = gc->frontBuffer.greenScale;
  346. }
  347. if (result->b > gc->frontBuffer.blueScale) {
  348. result->b = gc->frontBuffer.blueScale;
  349. }
  350. if (result->a > gc->frontBuffer.alphaScale) {
  351. result->a = gc->frontBuffer.alphaScale;
  352. }
  353. }
  354. void __glDoBlendNoClamp(__GLcontext *gc, const __GLcolor *source,
  355. const __GLcolor *dest, __GLcolor *result)
  356. {
  357. (*gc->procs.blendSrc)(gc, source, dest, result);
  358. (*gc->procs.blendDst)(gc, source, dest, result);
  359. }
  360. /*
  361. ** Source function == SRC_ALPHA and dest function == ZERO
  362. */
  363. void __glDoBlend_SA_ZERO(__GLcontext *gc, const __GLcolor *source,
  364. const __GLcolor *dest, __GLcolor *result)
  365. {
  366. __GLfloat a;
  367. #ifdef __GL_LINT
  368. dest = dest;
  369. #endif
  370. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  371. result->r = source->r * a;
  372. result->g = source->g * a;
  373. result->b = source->b * a;
  374. result->a = source->a * a;
  375. }
  376. /*
  377. ** Source function == SRC_ALPHA and dest function == ONE
  378. */
  379. void __glDoBlend_SA_ONE(__GLcontext *gc, const __GLcolor *source,
  380. const __GLcolor *dest, __GLcolor *result)
  381. {
  382. __GLfloat a, ra, rr, rg, rb;
  383. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  384. rr = dest->r + source->r * a;
  385. if (rr > gc->frontBuffer.redScale) {
  386. rr = gc->frontBuffer.redScale;
  387. }
  388. rg = dest->g + source->g * a;
  389. if (rg > gc->frontBuffer.greenScale) {
  390. rg = gc->frontBuffer.greenScale;
  391. }
  392. rb = dest->b + source->b * a;
  393. if (rb > gc->frontBuffer.blueScale) {
  394. rb = gc->frontBuffer.blueScale;
  395. }
  396. ra = dest->a + source->a * a;
  397. if (ra > gc->frontBuffer.alphaScale) {
  398. ra = gc->frontBuffer.alphaScale;
  399. }
  400. result->r = rr;
  401. result->g = rg;
  402. result->b = rb;
  403. result->a = ra;
  404. }
  405. /*
  406. ** Source function == SRC_ALPHA and dest function == ONE_MINUS_SRC_ALPHA
  407. ** No clamping is done, because the incoming colors should already be
  408. ** in range, and the math of x a + y (1 - a) should give a result from
  409. ** 0 to 1 if x and y are both from 0 to 1.
  410. */
  411. void __glDoBlend_SA_MSA(__GLcontext *gc, const __GLcolor *source,
  412. const __GLcolor *dest, __GLcolor *result)
  413. {
  414. __GLfloat a, msa, rr, rg, rb, ra;
  415. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  416. msa = __glOne - a;
  417. rr = source->r * a + dest->r * msa;
  418. rg = source->g * a + dest->g * msa;
  419. rb = source->b * a + dest->b * msa;
  420. ra = source->a * a + dest->a * msa;
  421. result->r = rr;
  422. result->g = rg;
  423. result->b = rb;
  424. result->a = ra;
  425. }
  426. /*
  427. ** Source function == ONE_MINUS_SRC_ALPHA and dest function == SRC_ALPHA
  428. ** No clamping is done, because the incoming colors should already be
  429. ** in range, and the math of x a + y (1 - a) should give a result from
  430. ** 0 to 1 if x and y are both from 0 to 1.
  431. */
  432. void __glDoBlend_MSA_SA(__GLcontext *gc, const __GLcolor *source,
  433. const __GLcolor *dest, __GLcolor *result)
  434. {
  435. __GLfloat a, msa, rr, rg, rb, ra;
  436. a = source->a * gc->frontBuffer.oneOverAlphaScale;
  437. msa = __glOne - a;
  438. rr = source->r * msa + dest->r * a;
  439. rg = source->g * msa + dest->g * a;
  440. rb = source->b * msa + dest->b * a;
  441. ra = source->a * msa + dest->a * a;
  442. result->r = rr;
  443. result->g = rg;
  444. result->b = rb;
  445. result->a = ra;
  446. }
  447. /*
  448. ** Source function == DST_ALPHA and dest function == ONE_MINUS_DST_ALPHA
  449. ** No clamping is done, because the incoming colors should already be
  450. ** in range, and the math of x a + y (1 - a) should give a result from
  451. ** 0 to 1 if x and y are both from 0 to 1.
  452. */
  453. void __glDoBlend_DA_MDA(__GLcontext *gc, const __GLcolor *source,
  454. const __GLcolor *dest, __GLcolor *result)
  455. {
  456. __GLfloat a, mda;
  457. a = dest->a * gc->frontBuffer.oneOverAlphaScale;
  458. mda = __glOne - a;
  459. result->r = a * source->r + mda * dest->r;
  460. result->g = a * source->g + mda * dest->g;
  461. result->b = a * source->b + mda * dest->b;
  462. result->a = a * source->a + mda * dest->a;
  463. }
  464. /*
  465. ** Source function == ONE_MINUS_DST_ALPHA and dest function == DST_ALPHA
  466. ** No clamping is done, because the incoming colors should already be
  467. ** in range, and the math of x a + y (1 - a) should give a result from
  468. ** 0 to 1 if x and y are both from 0 to 1.
  469. */
  470. void __glDoBlend_MDA_DA(__GLcontext *gc, const __GLcolor *source,
  471. const __GLcolor *dest, __GLcolor *result)
  472. {
  473. __GLfloat a, mda;
  474. a = dest->a * gc->frontBuffer.oneOverAlphaScale;
  475. mda = __glOne - a;
  476. result->r = mda * source->r + a * dest->r;
  477. result->g = mda * source->g + a * dest->g;
  478. result->b = mda * source->b + a * dest->b;
  479. result->a = mda * source->a + a * dest->a;
  480. }
  481. /* Generic blend span func.
  482. */
  483. void FASTCALL __glBlendSpan(__GLcontext *gc)
  484. {
  485. __GLcolor *cp, *fcp, temp;
  486. GLint w;
  487. // Fetch span if required
  488. if( gc->procs.blend == FetchBlend )
  489. __glFetchSpan( gc );
  490. w = gc->polygon.shader.length;
  491. cp = gc->polygon.shader.colors;
  492. fcp = gc->polygon.shader.fbcolors;
  493. while (--w >= 0) {
  494. (*gc->procs.blendColor)(gc, cp, fcp, &temp);
  495. *cp = temp;
  496. cp++;
  497. fcp++;
  498. }
  499. }
  500. /*
  501. ** Source function == SRC_ALPHA and dest function == ONE_MINUS_SRC_ALPHA
  502. ** No clamping is done, because the incoming colors should already be
  503. ** in range, and the math of x a + y (1 - a) should give a result from
  504. ** 0 to 1 if x and y are both from 0 to 1.
  505. */
  506. void FASTCALL __glBlendSpan_SA_MSA(__GLcontext *gc)
  507. {
  508. __GLfloat a, msa, rr, rg, rb, ra, oneOverAlpha;
  509. __GLfloat one = __glOne;
  510. __GLcolor *cp, *fcp;
  511. GLint w;
  512. __glFetchSpan( gc );
  513. w = gc->polygon.shader.length;
  514. cp = gc->polygon.shader.colors;
  515. fcp = gc->polygon.shader.fbcolors;
  516. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  517. while (--w >= 0) {
  518. a = cp->a * oneOverAlpha;
  519. msa = one - a;
  520. rr = cp->r * a + fcp->r * msa;
  521. rg = cp->g * a + fcp->g * msa;
  522. rb = cp->b * a + fcp->b * msa;
  523. ra = cp->a * a + fcp->a * msa;
  524. cp->r = rr;
  525. cp->g = rg;
  526. cp->b = rb;
  527. cp->a = ra;
  528. cp++;
  529. fcp++;
  530. }
  531. }
  532. /*
  533. ** Source function == ONE_MINUS_SRC_ALPHA and dest function == SRC_ALPHA
  534. ** No clamping is done, because the incoming colors should already be
  535. ** in range, and the math of x a + y (1 - a) should give a result from
  536. ** 0 to 1 if x and y are both from 0 to 1.
  537. */
  538. void FASTCALL __glBlendSpan_MSA_SA(__GLcontext *gc)
  539. {
  540. __GLfloat a, msa, rr, rg, rb, ra, oneOverAlpha;
  541. __GLfloat one = __glOne;
  542. __GLcolor *cp, *fcp;
  543. GLint w;
  544. __glFetchSpan( gc );
  545. w = gc->polygon.shader.length;
  546. cp = gc->polygon.shader.colors;
  547. fcp = gc->polygon.shader.fbcolors;
  548. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  549. while (--w >= 0) {
  550. a = cp->a * oneOverAlpha;
  551. msa = __glOne - a;
  552. rr = cp->r * msa + fcp->r * a;
  553. rg = cp->g * msa + fcp->g * a;
  554. rb = cp->b * msa + fcp->b * a;
  555. ra = cp->a * msa + fcp->a * a;
  556. cp->r = rr;
  557. cp->g = rg;
  558. cp->b = rb;
  559. cp->a = ra;
  560. cp++;
  561. fcp++;
  562. }
  563. }
  564. void FASTCALL __glBlendSpan_SA_ZERO(__GLcontext *gc)
  565. {
  566. __GLfloat a, rr, rg, rb, ra, oneOverAlpha;
  567. __GLfloat one = __glOne;
  568. __GLcolor *cp;
  569. GLint w;
  570. w = gc->polygon.shader.length;
  571. cp = gc->polygon.shader.colors;
  572. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  573. while (--w >= 0) {
  574. a = cp->a * oneOverAlpha;
  575. rr = cp->r * a;
  576. rg = cp->g * a;
  577. rb = cp->b * a;
  578. ra = cp->a * a;
  579. cp->r = rr;
  580. cp->g = rg;
  581. cp->b = rb;
  582. cp->a = ra;
  583. cp++;
  584. }
  585. }
  586. /*
  587. ** Source function == SRC_ALPHA and dest function == ONE
  588. ** Clamping is required
  589. */
  590. void FASTCALL __glBlendSpan_SA_ONE(__GLcontext *gc)
  591. {
  592. __GLfloat a, rr, rg, rb, ra, oneOverAlpha;
  593. __GLfloat rs, gs, bs, as;
  594. __GLcolor *cp, *fcp;
  595. GLint w;
  596. __glFetchSpan( gc );
  597. w = gc->polygon.shader.length;
  598. cp = gc->polygon.shader.colors;
  599. fcp = gc->polygon.shader.fbcolors;
  600. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  601. rs = gc->frontBuffer.redScale;
  602. gs = gc->frontBuffer.greenScale;
  603. bs = gc->frontBuffer.blueScale;
  604. as = gc->frontBuffer.alphaScale;
  605. while (--w >= 0) {
  606. a = cp->a * gc->frontBuffer.oneOverAlphaScale;
  607. rr = fcp->r + cp->r * a;
  608. rg = fcp->g + cp->g * a;
  609. if (rr > rs) {
  610. rr = rs;
  611. }
  612. rb = fcp->b + cp->b * a;
  613. if (rg > gs) {
  614. rg = gs;
  615. }
  616. ra = fcp->a + cp->a * a;
  617. if (rb > bs) {
  618. rb = bs;
  619. }
  620. cp->r = rr;
  621. if (ra > as) {
  622. ra = as;
  623. }
  624. cp->g = rg;
  625. cp->b = rb;
  626. cp->a = ra;
  627. cp++;
  628. fcp++;
  629. }
  630. }
  631. /*
  632. ** Source function == DST_ALPHA and dest function == ONE_MINUS_DST_ALPHA
  633. ** No clamping is done, because the incoming colors should already be
  634. ** in range, and the math of x a + y (1 - a) should give a result from
  635. ** 0 to 1 if x and y are both from 0 to 1.
  636. */
  637. void FASTCALL __glBlendSpan_DA_MDA(__GLcontext *gc)
  638. {
  639. __GLfloat a, mda, oneOverAlpha;
  640. __GLfloat one = __glOne;
  641. __GLcolor *cp, *fcp;
  642. GLint w;
  643. __glFetchSpan( gc );
  644. w = gc->polygon.shader.length;
  645. cp = gc->polygon.shader.colors;
  646. fcp = gc->polygon.shader.fbcolors;
  647. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  648. while (--w >= 0) {
  649. a = fcp->a * oneOverAlpha;
  650. mda = one - a;
  651. cp->r = cp->r * a + fcp->r * mda;
  652. cp->g = cp->g * a + fcp->g * mda;
  653. cp->b = cp->b * a + fcp->b * mda;
  654. cp->a = cp->a * a + fcp->a * mda;
  655. cp++;
  656. fcp++;
  657. }
  658. }
  659. /*
  660. ** Source function == ONE_MINUS_DST_ALPHA and dest function == DST_ALPHA
  661. ** No clamping is done, because the incoming colors should already be
  662. ** in range, and the math of x a + y (1 - a) should give a result from
  663. ** 0 to 1 if x and y are both from 0 to 1.
  664. */
  665. void FASTCALL __glBlendSpan_MDA_DA(__GLcontext *gc)
  666. {
  667. __GLfloat a, mda, oneOverAlpha;
  668. __GLfloat one = __glOne;
  669. __GLcolor *cp, *fcp;
  670. GLint w;
  671. __glFetchSpan( gc );
  672. w = gc->polygon.shader.length;
  673. cp = gc->polygon.shader.colors;
  674. fcp = gc->polygon.shader.fbcolors;
  675. oneOverAlpha = gc->frontBuffer.oneOverAlphaScale;
  676. while (--w >= 0) {
  677. a = fcp->a * oneOverAlpha;
  678. mda = one - a;
  679. cp->r = cp->r * mda + fcp->r * a;
  680. cp->g = cp->g * mda + fcp->g * a;
  681. cp->b = cp->b * mda + fcp->b * a;
  682. cp->a = cp->a * mda + fcp->a * a;
  683. cp++;
  684. fcp++;
  685. }
  686. }
  687. /************************************************************************/
  688. void FASTCALL __glGenericPickBlendProcs(__GLcontext *gc)
  689. {
  690. GLenum s = gc->state.raster.blendSrc;
  691. GLenum d = gc->state.raster.blendDst;
  692. if (gc->modes.colorIndexMode) {
  693. return;
  694. }
  695. /* Does the blending function need to fetch the dst color? */
  696. gc->procs.blendSpan = __glBlendSpan;
  697. if (d == GL_ZERO && s != GL_DST_COLOR && s != GL_ONE_MINUS_DST_COLOR &&
  698. s != GL_DST_ALPHA && s != GL_ONE_MINUS_DST_ALPHA &&
  699. s != GL_SRC_ALPHA_SATURATE) {
  700. gc->procs.blend = NoFetchBlend;
  701. } else {
  702. gc->procs.blend = FetchBlend;
  703. }
  704. if (!(gc->state.enables.general & __GL_BLEND_ENABLE)) {
  705. gc->procs.blendColor = Nop;
  706. } else {
  707. /* Look for any fast paths */
  708. if (s == GL_SRC_ALPHA) {
  709. if (d == GL_ZERO) {
  710. gc->procs.blendColor = __glDoBlend_SA_ZERO;
  711. gc->procs.blendSpan = __glBlendSpan_SA_ZERO;
  712. return;
  713. }
  714. if (d == GL_ONE) {
  715. gc->procs.blendColor = __glDoBlend_SA_ONE;
  716. gc->procs.blendSpan = __glBlendSpan_SA_ONE;
  717. return;
  718. }
  719. if (d == GL_ONE_MINUS_SRC_ALPHA) {
  720. gc->procs.blendColor = __glDoBlend_SA_MSA;
  721. gc->procs.blendSpan = __glBlendSpan_SA_MSA;
  722. return;
  723. }
  724. }
  725. else if (s == GL_ONE_MINUS_SRC_ALPHA) {
  726. if (d == GL_SRC_ALPHA) {
  727. gc->procs.blendColor = __glDoBlend_MSA_SA;
  728. gc->procs.blendSpan = __glBlendSpan_MSA_SA;
  729. return;
  730. }
  731. }
  732. else if (s == GL_DST_ALPHA) {
  733. if (d == GL_ONE_MINUS_DST_ALPHA) {
  734. gc->procs.blendColor = __glDoBlend_DA_MDA;
  735. gc->procs.blendSpan = __glBlendSpan_DA_MDA;
  736. return;
  737. }
  738. }
  739. else if (s == GL_ONE_MINUS_DST_ALPHA) {
  740. if (d == GL_DST_ALPHA) {
  741. gc->procs.blendColor = __glDoBlend_MDA_DA;
  742. gc->procs.blendSpan = __glBlendSpan_MDA_DA;
  743. return;
  744. }
  745. }
  746. /* Use generic blend function */
  747. if ( (d == GL_ONE_MINUS_SRC_COLOR) ||
  748. (s == GL_ONE_MINUS_DST_COLOR) ||
  749. (d == GL_ZERO) ||
  750. (s == GL_ZERO)) {
  751. gc->procs.blendColor = __glDoBlendNoClamp;
  752. } else {
  753. gc->procs.blendColor = __glDoBlend;
  754. }
  755. switch (s) {
  756. case GL_ZERO:
  757. gc->procs.blendSrc = __glDoBlendSourceZERO;
  758. break;
  759. case GL_ONE:
  760. gc->procs.blendSrc = __glDoBlendSourceONE;
  761. break;
  762. case GL_DST_COLOR:
  763. gc->procs.blendSrc = __glDoBlendSourceDC;
  764. break;
  765. case GL_ONE_MINUS_DST_COLOR:
  766. gc->procs.blendSrc = __glDoBlendSourceMDC;
  767. break;
  768. case GL_SRC_ALPHA:
  769. gc->procs.blendSrc = __glDoBlendSourceSA;
  770. break;
  771. case GL_ONE_MINUS_SRC_ALPHA:
  772. gc->procs.blendSrc = __glDoBlendSourceMSA;
  773. break;
  774. case GL_DST_ALPHA:
  775. gc->procs.blendSrc = __glDoBlendSourceDA;
  776. break;
  777. case GL_ONE_MINUS_DST_ALPHA:
  778. gc->procs.blendSrc = __glDoBlendSourceMDA;
  779. break;
  780. case GL_SRC_ALPHA_SATURATE:
  781. gc->procs.blendSrc = __glDoBlendSourceSAT;
  782. break;
  783. }
  784. switch (d) {
  785. case GL_ZERO:
  786. gc->procs.blendDst = __glDoBlendDestZERO;
  787. break;
  788. case GL_ONE:
  789. gc->procs.blendDst = __glDoBlendDestONE;
  790. break;
  791. case GL_SRC_COLOR:
  792. gc->procs.blendDst = __glDoBlendDestSC;
  793. break;
  794. case GL_ONE_MINUS_SRC_COLOR:
  795. gc->procs.blendDst = __glDoBlendDestMSC;
  796. break;
  797. case GL_SRC_ALPHA:
  798. gc->procs.blendDst = __glDoBlendDestSA;
  799. break;
  800. case GL_ONE_MINUS_SRC_ALPHA:
  801. gc->procs.blendDst = __glDoBlendDestMSA;
  802. break;
  803. case GL_DST_ALPHA:
  804. gc->procs.blendDst = __glDoBlendDestDA;
  805. break;
  806. case GL_ONE_MINUS_DST_ALPHA:
  807. gc->procs.blendDst = __glDoBlendDestMDA;
  808. break;
  809. }
  810. }
  811. }