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.

429 lines
13 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. void Load(__GLaccumBuffer* afb, __GLfloat val)
  20. {
  21. __GLcontext *gc = afb->buf.gc;
  22. GLint x0 = gc->transform.clipX0;
  23. GLint y0 = gc->transform.clipY0;
  24. GLint x1 = gc->transform.clipX1;
  25. GLint y1 = gc->transform.clipY1;
  26. GLint w, w4, w1, ow, skip;
  27. __GLfloat rval, gval, bval, aval;
  28. __GLaccumCell *ac;
  29. __GLcolorBuffer *cfb;
  30. #ifdef NT
  31. __GLcolor *cbuf;
  32. w = x1 - x0;
  33. cbuf = (__GLcolor *) gcTempAlloc(gc, w * sizeof(__GLcolor));
  34. if (NULL == cbuf)
  35. return;
  36. #else
  37. __GLcolor cbuf[4096];/*XXX*/
  38. w = x1 - x0;
  39. assert(w < 4096);/*XXX*/
  40. #endif
  41. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  42. cfb = gc->readBuffer;
  43. ow = w;
  44. w4 = w >> 2;
  45. w1 = w & 3;
  46. skip = afb->buf.outerWidth - w;
  47. rval = val * afb->redScale;
  48. gval = val * afb->greenScale;
  49. bval = val * afb->blueScale;
  50. aval = val * afb->alphaScale;
  51. for (; y0 < y1; y0++) {
  52. __GLcolor *cp = &cbuf[0];
  53. (*cfb->readSpan)(cfb, x0, y0, &cbuf[0], ow);
  54. w = w4;
  55. while (--w >= 0) {
  56. ac[0].r = (__GLaccumCellElement) (cp[0].r * rval);
  57. ac[0].g = (__GLaccumCellElement) (cp[0].g * gval);
  58. ac[0].b = (__GLaccumCellElement) (cp[0].b * bval);
  59. ac[0].a = (__GLaccumCellElement) (cp[0].a * aval);
  60. ac[1].r = (__GLaccumCellElement) (cp[1].r * rval);
  61. ac[1].g = (__GLaccumCellElement) (cp[1].g * gval);
  62. ac[1].b = (__GLaccumCellElement) (cp[1].b * bval);
  63. ac[1].a = (__GLaccumCellElement) (cp[1].a * aval);
  64. ac[2].r = (__GLaccumCellElement) (cp[2].r * rval);
  65. ac[2].g = (__GLaccumCellElement) (cp[2].g * gval);
  66. ac[2].b = (__GLaccumCellElement) (cp[2].b * bval);
  67. ac[2].a = (__GLaccumCellElement) (cp[2].a * aval);
  68. ac[3].r = (__GLaccumCellElement) (cp[3].r * rval);
  69. ac[3].g = (__GLaccumCellElement) (cp[3].g * gval);
  70. ac[3].b = (__GLaccumCellElement) (cp[3].b * bval);
  71. ac[3].a = (__GLaccumCellElement) (cp[3].a * aval);
  72. ac += 4;
  73. cp += 4;
  74. }
  75. w = w1;
  76. while (--w >= 0) {
  77. ac->r = (__GLaccumCellElement) (cp->r * rval);
  78. ac->g = (__GLaccumCellElement) (cp->g * gval);
  79. ac->b = (__GLaccumCellElement) (cp->b * bval);
  80. ac->a = (__GLaccumCellElement) (cp->a * aval);
  81. ac++;
  82. cp++;
  83. }
  84. ac += skip;
  85. }
  86. #ifdef NT
  87. gcTempFree(gc, cbuf);
  88. #endif
  89. }
  90. void Accumulate(__GLaccumBuffer* afb, __GLfloat val)
  91. {
  92. __GLcontext *gc = afb->buf.gc;
  93. GLint x0 = gc->transform.clipX0;
  94. GLint y0 = gc->transform.clipY0;
  95. GLint x1 = gc->transform.clipX1;
  96. GLint y1 = gc->transform.clipY1;
  97. GLint w, ow, skip, w4, w1;
  98. __GLfloat rval, gval, bval, aval;
  99. __GLaccumCell *ac;
  100. __GLcolorBuffer *cfb;
  101. #ifdef NT
  102. __GLcolor *cbuf;
  103. w = x1 - x0;
  104. cbuf = (__GLcolor *) gcTempAlloc(gc, w * sizeof(__GLcolor));
  105. if (NULL == cbuf)
  106. return;
  107. #else
  108. __GLcolor cbuf[4096];/*XXX*/
  109. w = x1 - x0;
  110. assert(w < 4096);/*XXX*/
  111. #endif
  112. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  113. cfb = gc->readBuffer;
  114. ow = w;
  115. w4 = w >> 2;
  116. w1 = w & 3;
  117. skip = afb->buf.outerWidth - w;
  118. rval = val * afb->redScale;
  119. gval = val * afb->greenScale;
  120. bval = val * afb->blueScale;
  121. aval = val * afb->alphaScale;
  122. for (; y0 < y1; y0++) {
  123. __GLcolor *cp = &cbuf[0];
  124. (*cfb->readSpan)(cfb, x0, y0, &cbuf[0], ow);
  125. w = w4;
  126. while (--w >= 0) {
  127. ac[0].r += (__GLaccumCellElement) (cp[0].r * rval);
  128. ac[0].g += (__GLaccumCellElement) (cp[0].g * gval);
  129. ac[0].b += (__GLaccumCellElement) (cp[0].b * bval);
  130. ac[0].a += (__GLaccumCellElement) (cp[0].a * aval);
  131. ac[1].r += (__GLaccumCellElement) (cp[1].r * rval);
  132. ac[1].g += (__GLaccumCellElement) (cp[1].g * gval);
  133. ac[1].b += (__GLaccumCellElement) (cp[1].b * bval);
  134. ac[1].a += (__GLaccumCellElement) (cp[1].a * aval);
  135. ac[2].r += (__GLaccumCellElement) (cp[2].r * rval);
  136. ac[2].g += (__GLaccumCellElement) (cp[2].g * gval);
  137. ac[2].b += (__GLaccumCellElement) (cp[2].b * bval);
  138. ac[2].a += (__GLaccumCellElement) (cp[2].a * aval);
  139. ac[3].r += (__GLaccumCellElement) (cp[3].r * rval);
  140. ac[3].g += (__GLaccumCellElement) (cp[3].g * gval);
  141. ac[3].b += (__GLaccumCellElement) (cp[3].b * bval);
  142. ac[3].a += (__GLaccumCellElement) (cp[3].a * aval);
  143. ac += 4;
  144. cp += 4;
  145. }
  146. w = w1;
  147. while (--w >= 0) {
  148. ac->r += (__GLaccumCellElement) (cp->r * rval);
  149. ac->g += (__GLaccumCellElement) (cp->g * gval);
  150. ac->b += (__GLaccumCellElement) (cp->b * bval);
  151. ac->a += (__GLaccumCellElement) (cp->a * aval);
  152. ac++;
  153. cp++;
  154. }
  155. ac += skip;
  156. }
  157. #ifdef NT
  158. gcTempFree(gc, cbuf);
  159. #endif
  160. }
  161. void Mult(__GLaccumBuffer *afb, __GLfloat val)
  162. {
  163. __GLcontext *gc = afb->buf.gc;
  164. GLint x0 = gc->transform.clipX0;
  165. GLint y0 = gc->transform.clipY0;
  166. GLint x1 = gc->transform.clipX1;
  167. GLint y1 = gc->transform.clipY1;
  168. GLint w, w4, w1, skip;
  169. __GLaccumCell *ac;
  170. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  171. w = x1 - x0;
  172. skip = afb->buf.outerWidth - w;
  173. if (val == __glZero) {
  174. /* Zero out the buffers contents */
  175. for (; y0 < y1; y0++) {
  176. GLint ww = w;
  177. while (ww > 0) {
  178. ac[0].r = 0; ac[0].g = 0; ac[0].b = 0; ac[0].a = 0;
  179. ac++;
  180. ww--;
  181. }
  182. ac += skip;
  183. }
  184. return;
  185. }
  186. w4 = w >> 2;
  187. w1 = w & 3;
  188. for (; y0 < y1; y0++) {
  189. w = w4;
  190. while (--w >= 0) {
  191. ac[0].r = (__GLaccumCellElement) (ac[0].r * val);
  192. ac[0].g = (__GLaccumCellElement) (ac[0].g * val);
  193. ac[0].b = (__GLaccumCellElement) (ac[0].b * val);
  194. ac[0].a = (__GLaccumCellElement) (ac[0].a * val);
  195. ac[1].r = (__GLaccumCellElement) (ac[1].r * val);
  196. ac[1].g = (__GLaccumCellElement) (ac[1].g * val);
  197. ac[1].b = (__GLaccumCellElement) (ac[1].b * val);
  198. ac[1].a = (__GLaccumCellElement) (ac[1].a * val);
  199. ac[2].r = (__GLaccumCellElement) (ac[2].r * val);
  200. ac[2].g = (__GLaccumCellElement) (ac[2].g * val);
  201. ac[2].b = (__GLaccumCellElement) (ac[2].b * val);
  202. ac[2].a = (__GLaccumCellElement) (ac[2].a * val);
  203. ac[3].r = (__GLaccumCellElement) (ac[3].r * val);
  204. ac[3].g = (__GLaccumCellElement) (ac[3].g * val);
  205. ac[3].b = (__GLaccumCellElement) (ac[3].b * val);
  206. ac[3].a = (__GLaccumCellElement) (ac[3].a * val);
  207. ac += 4;
  208. }
  209. w = w1;
  210. while (--w >= 0) {
  211. ac[0].r = (__GLaccumCellElement) (ac[0].r * val);
  212. ac[0].g = (__GLaccumCellElement) (ac[0].g * val);
  213. ac[0].b = (__GLaccumCellElement) (ac[0].b * val);
  214. ac[0].a = (__GLaccumCellElement) (ac[0].a * val);
  215. ac++;
  216. }
  217. ac += skip;
  218. }
  219. }
  220. void Add(__GLaccumBuffer *afb, __GLfloat value)
  221. {
  222. __GLcontext *gc = afb->buf.gc;
  223. GLint x0 = gc->transform.clipX0;
  224. GLint y0 = gc->transform.clipY0;
  225. GLint x1 = gc->transform.clipX1;
  226. GLint y1 = gc->transform.clipY1;
  227. GLint w, w4, w1, skip;
  228. __GLaccumCellElement rval, gval, bval, aval;
  229. __GLaccumCell *ac;
  230. rval = (__GLaccumCellElement)
  231. (value * gc->frontBuffer.redScale * afb->redScale + __glHalf);
  232. gval = (__GLaccumCellElement)
  233. (value * gc->frontBuffer.greenScale * afb->greenScale + __glHalf);
  234. bval = (__GLaccumCellElement)
  235. (value * gc->frontBuffer.blueScale * afb->blueScale + __glHalf);
  236. aval = (__GLaccumCellElement)
  237. (value * gc->frontBuffer.alphaScale * afb->alphaScale + __glHalf);
  238. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  239. w = x1 - x0;
  240. w4 = w >> 2;
  241. w1 = w & 3;
  242. skip = afb->buf.outerWidth - w;
  243. for (; y0 < y1; y0++) {
  244. w = w4;
  245. while (--w >= 0) {
  246. ac[0].r += rval; ac[0].g += gval; ac[0].b += bval; ac[0].a += aval;
  247. ac[1].r += rval; ac[1].g += gval; ac[1].b += bval; ac[1].a += aval;
  248. ac[2].r += rval; ac[2].g += gval; ac[2].b += bval; ac[2].a += aval;
  249. ac[3].r += rval; ac[3].g += gval; ac[3].b += bval; ac[3].a += aval;
  250. ac += 4;
  251. }
  252. w = w1;
  253. while (--w >= 0) {
  254. ac[0].r += rval; ac[0].g += gval; ac[0].b += bval; ac[0].a += aval;
  255. ac++;
  256. }
  257. ac += skip;
  258. }
  259. }
  260. void Return(__GLaccumBuffer* afb, __GLfloat val)
  261. {
  262. __GLcontext *gc = afb->buf.gc;
  263. GLint x0 = gc->transform.clipX0;
  264. GLint y0 = gc->transform.clipY0;
  265. GLint x1 = gc->transform.clipX1;
  266. GLint y1 = gc->transform.clipY1;
  267. GLint w, next;
  268. __GLaccumCell *ac;
  269. __GLcolorBuffer *cfb;
  270. __GLcolorBuffer *cfb2;
  271. __GLfragment frag;
  272. __GLcolor *pAccumCol;
  273. // The returnspan routines use FTOL
  274. FPU_SAVE_MODE();
  275. FPU_CHOP_ON_PREC_LOW();
  276. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  277. w = x1 - x0;
  278. next = afb->buf.outerWidth;
  279. frag.y = y0;
  280. // Preallocate a color buffer for the return span functions
  281. pAccumCol = (__GLcolor *) gcTempAlloc(gc, w * sizeof(__GLcolor));
  282. if( NULL == pAccumCol )
  283. return;
  284. afb->colors = pAccumCol;
  285. if (gc->buffers.doubleStore) {
  286. /* Store to both buffers */
  287. cfb = &gc->frontBuffer;
  288. cfb2 = &gc->backBuffer;
  289. for (; y0 < y1; y0++) {
  290. (*cfb->returnSpan)(cfb, x0, y0, ac, val, w);
  291. (*cfb2->returnSpan)(cfb2, x0, y0, ac, val, w);
  292. ac += next;
  293. }
  294. } else {
  295. cfb = gc->drawBuffer;
  296. for (; y0 < y1; y0++) {
  297. (*cfb->returnSpan)(cfb, x0, y0, ac, val, w);
  298. ac += next;
  299. }
  300. }
  301. FPU_RESTORE_MODE();
  302. gcTempFree( gc, pAccumCol );
  303. }
  304. void FASTCALL Clear(__GLaccumBuffer* afb)
  305. {
  306. __GLcontext *gc = afb->buf.gc;
  307. GLint x0 = gc->transform.clipX0;
  308. GLint y0 = gc->transform.clipY0;
  309. GLint y1 = gc->transform.clipY1;
  310. GLint w, w4, w1, skip;
  311. __GLaccumCell *ac;
  312. __GLaccumCellElement r, g, b, a;
  313. __GLcolorBuffer *cfb = &gc->frontBuffer;
  314. __GLcolor *val = &gc->state.accum.clear;
  315. /*
  316. ** Convert abstract color into specific color value.
  317. */
  318. r = (__GLaccumCellElement) (val->r * cfb->redScale * afb->redScale);
  319. g = (__GLaccumCellElement) (val->g * cfb->greenScale * afb->greenScale);
  320. b = (__GLaccumCellElement) (val->b * cfb->blueScale * afb->blueScale);
  321. a = (__GLaccumCellElement) (val->a * cfb->alphaScale * afb->alphaScale);
  322. ac = __GL_ACCUM_ADDRESS(afb,(__GLaccumCell*),x0,y0);
  323. w = gc->transform.clipX1 - x0;
  324. w4 = w >> 2;
  325. w1 = w & 3;
  326. skip = afb->buf.outerWidth - w;
  327. for (; y0 < y1; y0++) {
  328. w = w4;
  329. while (--w >= 0) {
  330. ac[0].r = r; ac[0].g = g; ac[0].b = b; ac[0].a = a;
  331. ac[1].r = r; ac[1].g = g; ac[1].b = b; ac[1].a = a;
  332. ac[2].r = r; ac[2].g = g; ac[2].b = b; ac[2].a = a;
  333. ac[3].r = r; ac[3].g = g; ac[3].b = b; ac[3].a = a;
  334. ac += 4;
  335. }
  336. w = w1;
  337. while (--w >= 0) {
  338. ac[0].r = r; ac[0].g = g; ac[0].b = b; ac[0].a = a;
  339. ac++;
  340. }
  341. ac += skip;
  342. }
  343. }
  344. /************************************************************************/
  345. void FASTCALL Pick(__GLcontext *gc, __GLaccumBuffer *afb)
  346. {
  347. #ifdef __GL_LINT
  348. gc = gc;
  349. afb = afb;
  350. #endif
  351. }
  352. void FASTCALL __glInitAccum64(__GLcontext *gc, __GLaccumBuffer *afb)
  353. {
  354. afb->buf.elementSize = sizeof(__GLaccumCell);
  355. afb->buf.gc = gc;
  356. if (gc->modes.rgbMode) {
  357. __GLcolorBuffer *cfb;
  358. __GLfloat scale;
  359. scale = (__GLfloat)((1 << (8 * sizeof(__GLaccumCellElement)))/2 - 1);
  360. cfb = &gc->frontBuffer;
  361. afb->redScale = scale / (cfb->redScale);
  362. afb->blueScale = scale / (cfb->blueScale);
  363. afb->greenScale = scale / (cfb->greenScale);
  364. afb->alphaScale = scale / (cfb->alphaScale);
  365. afb->oneOverRedScale = 1 / afb->redScale;
  366. afb->oneOverGreenScale = 1 / afb->greenScale;
  367. afb->oneOverBlueScale = 1 / afb->blueScale;
  368. afb->oneOverAlphaScale = 1 / afb->alphaScale;
  369. }
  370. afb->pick = Pick;
  371. afb->clear = Clear;
  372. afb->accumulate = Accumulate;
  373. afb->load = Load;
  374. afb->ret = Return;
  375. afb->mult = Mult;
  376. afb->add = Add;
  377. }
  378. void FASTCALL __glFreeAccum64(__GLcontext *gc, __GLaccumBuffer *afb)
  379. {
  380. #ifdef __GL_LINT
  381. gc = gc;
  382. afb = afb;
  383. #endif
  384. }