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.

619 lines
15 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.15 $
  18. ** $Date: 1993/10/07 18:46:43 $
  19. */
  20. #include "precomp.h"
  21. #pragma hdrstop
  22. GLboolean FASTCALL __glFogSpan(__GLcontext *gc)
  23. {
  24. __GLcolor *cp, *fogColor;
  25. __GLfloat f, oneMinusFog, fog;
  26. GLint w;
  27. GLboolean bGrayFog;
  28. w = gc->polygon.shader.length;
  29. f = gc->polygon.shader.frag.f;
  30. cp = gc->polygon.shader.colors;
  31. fogColor = &gc->state.fog.color;
  32. #ifdef NT
  33. bGrayFog = !gc->modes.colorIndexMode
  34. && (gc->state.fog.flags & __GL_FOG_GRAY_RGB);
  35. if (bGrayFog)
  36. {
  37. while (--w >= 0)
  38. {
  39. __GLfloat delta;
  40. /* clamp fog value */
  41. fog = f;
  42. if (fog < __glZero) fog = __glZero;
  43. else if (fog > __glOne) fog = __glOne;
  44. oneMinusFog = __glOne - fog;
  45. delta = oneMinusFog * fogColor->r;
  46. /* Blend incoming color against the fog color */
  47. cp->r = fog * cp->r + delta;
  48. cp->g = fog * cp->g + delta;
  49. cp->b = fog * cp->b + delta;
  50. f += gc->polygon.shader.dfdx;
  51. cp++;
  52. }
  53. }
  54. else
  55. #endif
  56. while (--w >= 0) {
  57. /* clamp fog value */
  58. fog = f;
  59. if (fog < __glZero) fog = __glZero;
  60. else if (fog > __glOne) fog = __glOne;
  61. oneMinusFog = __glOne - fog;
  62. /* Blend incoming color against the fog color */
  63. if (gc->modes.colorIndexMode) {
  64. cp->r = cp->r + oneMinusFog * gc->state.fog.index;
  65. } else {
  66. cp->r = fog * cp->r + oneMinusFog * fogColor->r;
  67. cp->g = fog * cp->g + oneMinusFog * fogColor->g;
  68. cp->b = fog * cp->b + oneMinusFog * fogColor->b;
  69. }
  70. f += gc->polygon.shader.dfdx;
  71. cp++;
  72. }
  73. return GL_FALSE;
  74. }
  75. GLboolean FASTCALL __glFogStippledSpan(__GLcontext *gc)
  76. {
  77. __GLstippleWord bit, inMask, *sp;
  78. __GLcolor *cp, *fogColor;
  79. __GLfloat f, oneMinusFog, fog;
  80. GLint count;
  81. GLint w;
  82. GLboolean bGrayFog;
  83. w = gc->polygon.shader.length;
  84. sp = gc->polygon.shader.stipplePat;
  85. f = gc->polygon.shader.frag.f;
  86. cp = gc->polygon.shader.colors;
  87. fogColor = &gc->state.fog.color;
  88. #ifdef NT
  89. bGrayFog = (gc->state.fog.flags & __GL_FOG_GRAY_RGB) ? GL_TRUE : GL_FALSE;
  90. #endif
  91. while (w) {
  92. count = w;
  93. if (count > __GL_STIPPLE_BITS) {
  94. count = __GL_STIPPLE_BITS;
  95. }
  96. w -= count;
  97. inMask = *sp++;
  98. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  99. while (--count >= 0) {
  100. if (inMask & bit) {
  101. /* clamp fog value */
  102. fog = f;
  103. if (fog < __glZero) fog = __glZero;
  104. else if (fog > __glOne) fog = __glOne;
  105. oneMinusFog = __glOne - fog;
  106. /* Blend incoming color against the fog color */
  107. if (gc->modes.colorIndexMode) {
  108. cp->r = cp->r + oneMinusFog * gc->state.fog.index;
  109. } else {
  110. #ifdef NT
  111. if (bGrayFog)
  112. {
  113. __GLfloat delta = oneMinusFog * fogColor->r;
  114. cp->r = fog * cp->r + delta;
  115. cp->g = fog * cp->g + delta;
  116. cp->b = fog * cp->b + delta;
  117. }
  118. else
  119. #endif
  120. {
  121. cp->r = fog * cp->r + oneMinusFog * fogColor->r;
  122. cp->g = fog * cp->g + oneMinusFog * fogColor->g;
  123. cp->b = fog * cp->b + oneMinusFog * fogColor->b;
  124. }
  125. }
  126. }
  127. f += gc->polygon.shader.dfdx;
  128. cp++;
  129. #ifdef __GL_STIPPLE_MSB
  130. bit >>= 1;
  131. #else
  132. bit <<= 1;
  133. #endif
  134. }
  135. }
  136. return GL_FALSE;
  137. }
  138. /************************************************************************/
  139. GLboolean FASTCALL __glFogSpanSlow(__GLcontext *gc)
  140. {
  141. __GLcolor *cp, *fogColor;
  142. __GLfloat f, oneMinusFog, fog, eyeZ;
  143. __GLfloat density, density2neg, end;
  144. GLint w;
  145. GLboolean bGrayFog;
  146. w = gc->polygon.shader.length;
  147. f = gc->polygon.shader.frag.f;
  148. cp = gc->polygon.shader.colors;
  149. fogColor = &gc->state.fog.color;
  150. density = gc->state.fog.density;
  151. #ifdef NT
  152. bGrayFog = (gc->state.fog.flags & __GL_FOG_GRAY_RGB) ? GL_TRUE : GL_FALSE;
  153. density2neg = gc->state.fog.density2neg;
  154. #else
  155. density2 = density * density;
  156. start = gc->state.fog.start;
  157. #endif
  158. end = gc->state.fog.end;
  159. while (--w >= 0) {
  160. #ifdef NT
  161. /* Compute fog value */
  162. eyeZ = f;
  163. switch (gc->state.fog.mode) {
  164. case GL_EXP:
  165. if (eyeZ < __glZero)
  166. fog = __GL_POWF(__glE, density * eyeZ);
  167. else
  168. fog = __GL_POWF(__glE, -density * eyeZ);
  169. /* clamp fog value */
  170. if (fog > __glOne) fog = __glOne;
  171. break;
  172. case GL_EXP2:
  173. fog = __GL_POWF(__glE, density2neg * eyeZ * eyeZ);
  174. /* clamp fog value */
  175. if (fog > __glOne) fog = __glOne;
  176. break;
  177. case GL_LINEAR:
  178. if (eyeZ < __glZero)
  179. fog = (end + eyeZ) * gc->state.fog.oneOverEMinusS;
  180. else
  181. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  182. /* clamp fog value */
  183. if (fog < __glZero) fog = __glZero;
  184. else if (fog > __glOne) fog = __glOne;
  185. break;
  186. }
  187. #else
  188. /* Compute fog value */
  189. eyeZ = f;
  190. if (eyeZ < __glZero) eyeZ = -eyeZ;
  191. switch (gc->state.fog.mode) {
  192. case GL_EXP:
  193. fog = __GL_POWF(__glE, -density * eyeZ);
  194. break;
  195. case GL_EXP2:
  196. fog = __GL_POWF(__glE, -(density2 * eyeZ * eyeZ));
  197. break;
  198. case GL_LINEAR:
  199. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  200. break;
  201. }
  202. /* clamp fog value */
  203. if (fog < __glZero) fog = __glZero;
  204. else if (fog > __glOne) fog = __glOne;
  205. #endif
  206. oneMinusFog = __glOne - fog;
  207. /* Blend incoming color against the fog color */
  208. if (gc->modes.colorIndexMode) {
  209. cp->r = cp->r + oneMinusFog * gc->state.fog.index;
  210. } else {
  211. #ifdef NT
  212. if (bGrayFog)
  213. {
  214. __GLfloat delta = oneMinusFog * fogColor->r;
  215. cp->r = fog * cp->r + delta;
  216. cp->g = fog * cp->g + delta;
  217. cp->b = fog * cp->b + delta;
  218. }
  219. else
  220. #endif
  221. {
  222. cp->r = fog * cp->r + oneMinusFog * fogColor->r;
  223. cp->g = fog * cp->g + oneMinusFog * fogColor->g;
  224. cp->b = fog * cp->b + oneMinusFog * fogColor->b;
  225. }
  226. }
  227. f += gc->polygon.shader.dfdx;
  228. cp++;
  229. }
  230. return GL_FALSE;
  231. }
  232. GLboolean FASTCALL __glFogStippledSpanSlow(__GLcontext *gc)
  233. {
  234. __GLstippleWord bit, inMask, *sp;
  235. __GLcolor *cp, *fogColor;
  236. __GLfloat f, oneMinusFog, fog, eyeZ;
  237. __GLfloat density, density2neg, end;
  238. GLint count;
  239. GLint w;
  240. GLboolean bGrayFog;
  241. w = gc->polygon.shader.length;
  242. sp = gc->polygon.shader.stipplePat;
  243. f = gc->polygon.shader.frag.f;
  244. cp = gc->polygon.shader.colors;
  245. fogColor = &gc->state.fog.color;
  246. #ifdef NT
  247. bGrayFog = (gc->state.fog.flags & __GL_FOG_GRAY_RGB) ? GL_TRUE : GL_FALSE;
  248. #endif
  249. density = gc->state.fog.density;
  250. #ifdef NT
  251. density2neg = gc->state.fog.density2neg;
  252. #else
  253. density2 = density * density;
  254. start = gc->state.fog.start;
  255. #endif
  256. end = gc->state.fog.end;
  257. while (w) {
  258. count = w;
  259. if (count > __GL_STIPPLE_BITS) {
  260. count = __GL_STIPPLE_BITS;
  261. }
  262. w -= count;
  263. inMask = *sp++;
  264. bit = (__GLstippleWord) __GL_STIPPLE_SHIFT(0);
  265. while (--count >= 0) {
  266. if (inMask & bit) {
  267. #ifdef NT
  268. /* Compute fog value */
  269. eyeZ = f;
  270. switch (gc->state.fog.mode) {
  271. case GL_EXP:
  272. if (eyeZ < __glZero)
  273. fog = __GL_POWF(__glE, density * eyeZ);
  274. else
  275. fog = __GL_POWF(__glE, -density * eyeZ);
  276. /* Clamp resulting fog value */
  277. if (fog > __glOne) fog = __glOne;
  278. break;
  279. case GL_EXP2:
  280. fog = __GL_POWF(__glE, density2neg * eyeZ * eyeZ);
  281. /* Clamp resulting fog value */
  282. if (fog > __glOne) fog = __glOne;
  283. break;
  284. case GL_LINEAR:
  285. if (eyeZ < __glZero)
  286. fog = (end + eyeZ) * gc->state.fog.oneOverEMinusS;
  287. else
  288. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  289. /* Clamp resulting fog value */
  290. if (fog < __glZero) fog = __glZero;
  291. else if (fog > __glOne) fog = __glOne;
  292. break;
  293. }
  294. #else
  295. /* Compute fog value */
  296. eyeZ = f;
  297. if (eyeZ < __glZero) eyeZ = -eyeZ;
  298. switch (gc->state.fog.mode) {
  299. case GL_EXP:
  300. fog = __GL_POWF(__glE, -density * eyeZ);
  301. break;
  302. case GL_EXP2:
  303. fog = __GL_POWF(__glE, -(density2 * eyeZ * eyeZ));
  304. break;
  305. case GL_LINEAR:
  306. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  307. break;
  308. }
  309. /* Clamp resulting fog value */
  310. if (fog < __glZero) fog = __glZero;
  311. else if (fog > __glOne) fog = __glOne;
  312. #endif
  313. oneMinusFog = __glOne - fog;
  314. /* Blend incoming color against the fog color */
  315. if (gc->modes.colorIndexMode) {
  316. cp->r = cp->r + oneMinusFog * gc->state.fog.index;
  317. } else {
  318. #ifdef NT
  319. if (bGrayFog)
  320. {
  321. __GLfloat delta = oneMinusFog * fogColor->r;
  322. cp->r = fog * cp->r + delta;
  323. cp->g = fog * cp->g + delta;
  324. cp->b = fog * cp->b + delta;
  325. }
  326. else
  327. #endif
  328. {
  329. cp->r = fog * cp->r + oneMinusFog * fogColor->r;
  330. cp->g = fog * cp->g + oneMinusFog * fogColor->g;
  331. cp->b = fog * cp->b + oneMinusFog * fogColor->b;
  332. }
  333. }
  334. }
  335. f += gc->polygon.shader.dfdx;
  336. cp++;
  337. #ifdef __GL_STIPPLE_MSB
  338. bit >>= 1;
  339. #else
  340. bit <<= 1;
  341. #endif
  342. }
  343. }
  344. return GL_FALSE;
  345. }
  346. /************************************************************************/
  347. /*
  348. ** Compute the fog value given an eyeZ. Then blend into fragment.
  349. ** This is used when fragment fogging is done (GL_FOG_HINT == GL_NICEST)
  350. ** or by the point rendering routines.
  351. ** NOTE: the code below has the -eyeZ factored out.
  352. */
  353. void __glFogFragmentSlow(__GLcontext *gc, __GLfragment *frag, __GLfloat eyeZ)
  354. {
  355. __GLfloat fog, oneMinusFog, density, density2neg, end;
  356. __GLcolor *fogColor;
  357. #ifdef NT
  358. switch (gc->state.fog.mode) {
  359. case GL_EXP:
  360. density = gc->state.fog.density;
  361. if (eyeZ < __glZero)
  362. fog = __GL_POWF(__glE, density * eyeZ);
  363. else
  364. fog = __GL_POWF(__glE, -density * eyeZ);
  365. /* clamp fog value */
  366. if (fog > __glOne) fog = __glOne;
  367. break;
  368. case GL_EXP2:
  369. density2neg = gc->state.fog.density2neg;
  370. fog = __GL_POWF(__glE, density2neg * eyeZ * eyeZ);
  371. /* clamp fog value */
  372. if (fog > __glOne) fog = __glOne;
  373. break;
  374. case GL_LINEAR:
  375. end = gc->state.fog.end;
  376. if (eyeZ < __glZero)
  377. fog = (end + eyeZ) * gc->state.fog.oneOverEMinusS;
  378. else
  379. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  380. /* clamp fog value */
  381. if (fog < __glZero) fog = __glZero;
  382. else if (fog > __glOne) fog = __glOne;
  383. break;
  384. }
  385. #else
  386. if (eyeZ < __glZero) eyeZ = -eyeZ;
  387. switch (gc->state.fog.mode) {
  388. case GL_EXP:
  389. density = gc->state.fog.density;
  390. fog = __GL_POWF(__glE, -density * eyeZ);
  391. break;
  392. case GL_EXP2:
  393. density = gc->state.fog.density;
  394. fog = __GL_POWF(__glE, -(density * eyeZ * density * eyeZ));
  395. break;
  396. case GL_LINEAR:
  397. end = gc->state.fog.end;
  398. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  399. break;
  400. }
  401. /*
  402. ** clamp fog value
  403. */
  404. if (fog < __glZero)
  405. fog = __glZero;
  406. else if (fog > __glOne)
  407. fog = __glOne;
  408. #endif
  409. oneMinusFog = __glOne - fog;
  410. /*
  411. ** Blend incoming color against the fog color
  412. */
  413. fogColor = &gc->state.fog.color;
  414. if (gc->modes.colorIndexMode) {
  415. frag->color.r = frag->color.r + oneMinusFog * gc->state.fog.index;
  416. } else {
  417. #ifdef NT
  418. if (gc->state.fog.flags & __GL_FOG_GRAY_RGB)
  419. {
  420. __GLfloat delta = oneMinusFog * fogColor->r;
  421. frag->color.r = fog * frag->color.r + delta;
  422. frag->color.g = fog * frag->color.g + delta;
  423. frag->color.b = fog * frag->color.b + delta;
  424. }
  425. else
  426. #endif
  427. {
  428. frag->color.r = fog * frag->color.r + oneMinusFog * fogColor->r;
  429. frag->color.g = fog * frag->color.g + oneMinusFog * fogColor->g;
  430. frag->color.b = fog * frag->color.b + oneMinusFog * fogColor->b;
  431. }
  432. }
  433. }
  434. /*
  435. ** Compute generic fog value for vertex.
  436. */
  437. __GLfloat FASTCALL __glFogVertex(__GLcontext *gc, __GLvertex *vx)
  438. {
  439. __GLfloat eyeZ, fog, density, density2neg, end;
  440. eyeZ = vx->eyeZ;
  441. #ifdef NT
  442. switch (gc->state.fog.mode) {
  443. case GL_EXP:
  444. density = gc->state.fog.density;
  445. if (eyeZ < __glZero)
  446. fog = __GL_POWF(__glE, density * eyeZ);
  447. else
  448. fog = __GL_POWF(__glE, -density * eyeZ);
  449. /* clamp fog value */
  450. if (fog > __glOne) fog = __glOne;
  451. break;
  452. case GL_EXP2:
  453. density2neg = gc->state.fog.density2neg;
  454. fog = __GL_POWF(__glE, density2neg * eyeZ * eyeZ);
  455. /* clamp fog value */
  456. if (fog > __glOne) fog = __glOne;
  457. break;
  458. case GL_LINEAR:
  459. end = gc->state.fog.end;
  460. if (eyeZ < __glZero)
  461. fog = (end + eyeZ) * gc->state.fog.oneOverEMinusS;
  462. else
  463. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  464. /* clamp fog value */
  465. if (fog < __glZero) fog = __glZero;
  466. else if (fog > __glOne) fog = __glOne;
  467. break;
  468. }
  469. #else
  470. if (eyeZ < __glZero) eyeZ = -eyeZ;
  471. switch (gc->state.fog.mode) {
  472. case GL_EXP:
  473. density = gc->state.fog.density;
  474. fog = __GL_POWF(__glE, -density * eyeZ);
  475. break;
  476. case GL_EXP2:
  477. density = gc->state.fog.density;
  478. fog = __GL_POWF(__glE, -(density * eyeZ * density * eyeZ));
  479. break;
  480. case GL_LINEAR:
  481. end = gc->state.fog.end;
  482. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  483. break;
  484. }
  485. /*
  486. ** Since this routine is called when we are doing slow fog, we can
  487. ** safely clamp the fog value here.
  488. */
  489. if (fog < __glZero)
  490. fog = __glZero;
  491. else if (fog > __glOne)
  492. fog = __glOne;
  493. #endif
  494. return fog;
  495. }
  496. /*
  497. ** Compute linear fog value for vertex
  498. */
  499. __GLfloat FASTCALL __glFogVertexLinear(__GLcontext *gc, __GLvertex *vx)
  500. {
  501. __GLfloat eyeZ, fog, end;
  502. eyeZ = vx->eyeZ;
  503. #ifdef NT
  504. end = gc->state.fog.end;
  505. if (eyeZ < __glZero)
  506. fog = (end + eyeZ) * gc->state.fog.oneOverEMinusS;
  507. else
  508. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  509. #else
  510. if (eyeZ < __glZero) eyeZ = -eyeZ;
  511. end = gc->state.fog.end;
  512. fog = (end - eyeZ) * gc->state.fog.oneOverEMinusS;
  513. #endif
  514. if (fog < __glZero)
  515. fog = __glZero;
  516. else if (fog > __glOne)
  517. fog = __glOne;
  518. return fog;
  519. }
  520. /*
  521. ** Compute the fogged color given an incoming color and a fog value.
  522. */
  523. void __glFogColorSlow(__GLcontext *gc, __GLcolor *out, __GLcolor *in,
  524. __GLfloat fog)
  525. {
  526. __GLcolor *fogColor;
  527. __GLfloat oneMinusFog;
  528. __GLfloat r, g, b;
  529. oneMinusFog = __glOne - fog;
  530. /*
  531. ** Blend incoming color against the fog color
  532. */
  533. fogColor = &gc->state.fog.color;
  534. if (gc->modes.colorIndexMode) {
  535. out->r = in->r + oneMinusFog * gc->state.fog.index;
  536. } else {
  537. #ifdef NT
  538. if (gc->state.fog.flags & __GL_FOG_GRAY_RGB)
  539. {
  540. __GLfloat delta = oneMinusFog * fogColor->r;
  541. out->r = fog * in->r + delta;
  542. out->g = fog * in->g + delta;
  543. out->b = fog * in->b + delta;
  544. }
  545. else
  546. #endif
  547. {
  548. /*
  549. ** The following is coded like this to give the instruction scheduler
  550. ** a hand.
  551. */
  552. r = fog * in->r;
  553. g = fog * in->g;
  554. b = fog * in->b;
  555. r += oneMinusFog * fogColor->r;
  556. g += oneMinusFog * fogColor->g;
  557. b += oneMinusFog * fogColor->b;
  558. out->r = r;
  559. out->g = g;
  560. out->b = b;
  561. }
  562. out->a = in->a;
  563. }
  564. }