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.

4450 lines
138 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 "genrgb.h"
  20. #include "genclear.h"
  21. #define STATIC
  22. __GLfloat fDitherIncTable[16] = {
  23. DITHER_INC(0), DITHER_INC(8), DITHER_INC(2), DITHER_INC(10),
  24. DITHER_INC(12), DITHER_INC(4), DITHER_INC(14), DITHER_INC(6),
  25. DITHER_INC(3), DITHER_INC(11), DITHER_INC(1), DITHER_INC(9),
  26. DITHER_INC(15), DITHER_INC(7), DITHER_INC(13), DITHER_INC(5)
  27. };
  28. /* No Dither, No blend, No Write, No Nothing */
  29. STATIC void FASTCALL Store_NOT(__GLcolorBuffer *cfb, const __GLfragment *frag)
  30. {
  31. }
  32. STATIC GLboolean FASTCALL StoreSpanNone(__GLcontext *gc)
  33. {
  34. return GL_FALSE;
  35. }
  36. //
  37. // Special case normal alpha blending (source alpha*src + dst*(1-sa))
  38. // This case is used in antialiasing and actually jumping through
  39. // the fetch and blend procs takes up a large amount of time. Moving
  40. // the code into the store proc removes this overhead
  41. //
  42. // The macro requires a standard store proc setup, with gc, cfb, frag,
  43. // blendColor and so on. It requires a dst_pix variable which
  44. // will hold a pixel in the destination format.
  45. // It also takes as an argument a statement which will set dst_pix.
  46. // The reason it doesn't take the pixel itself is because only the special case
  47. // actually needs the value. In all the flags cases the pixel
  48. // retrieval would be wasted.
  49. //
  50. extern void __glDoBlend_SA_MSA(__GLcontext *gc, const __GLcolor *source,
  51. const __GLcolor *dest, __GLcolor *result);
  52. #define SPECIAL_ALPHA_BLEND(dst_pix_gen) \
  53. color = &blendColor; \
  54. if( (gc->procs.blendColor == __glDoBlend_SA_MSA) && \
  55. !( ALPHA_WRITE_ENABLED( cfb )) ) \
  56. { \
  57. __GLfloat a, msa; \
  58. \
  59. a = frag->color.a * gc->frontBuffer.oneOverAlphaScale; \
  60. msa = __glOne - a; \
  61. \
  62. dst_pix_gen; \
  63. blendColor.r = frag->color.r*a + msa*(__GLfloat) \
  64. ((dst_pix & gc->modes.redMask) >> cfb->redShift); \
  65. blendColor.g = frag->color.g*a + msa*(__GLfloat) \
  66. ((dst_pix & gc->modes.greenMask) >> cfb->greenShift); \
  67. blendColor.b = frag->color.b*a + msa*(__GLfloat) \
  68. ((dst_pix & gc->modes.blueMask) >> cfb->blueShift); \
  69. } \
  70. else \
  71. { \
  72. (*gc->procs.blend)( gc, cfb, frag, &blendColor ); \
  73. }
  74. #define SPECIAL_ALPHA_BLEND_SPAN(dst_pix_gen) \
  75. if( (gc->procs.blendColor == __glDoBlend_SA_MSA) && \
  76. !( ALPHA_WRITE_ENABLED( cfb )) ) \
  77. { \
  78. __GLcolor *color = gc->polygon.shader.colors; \
  79. \
  80. for ( i = 0; i < w; i++, color++ ) \
  81. { \
  82. __GLfloat a, msa; \
  83. \
  84. a = color->a * gc->frontBuffer.oneOverAlphaScale; \
  85. msa = __glOne - a; \
  86. \
  87. dst_pix_gen; \
  88. color->r = color->r*a + msa*(__GLfloat) \
  89. ((dst_pix & gc->modes.redMask) >> cfb->redShift); \
  90. color->g = color->g*a + msa*(__GLfloat) \
  91. ((dst_pix & gc->modes.greenMask) >> cfb->greenShift); \
  92. color->b = color->b*a + msa*(__GLfloat) \
  93. ((dst_pix & gc->modes.blueMask) >> cfb->blueShift); \
  94. } \
  95. } \
  96. else \
  97. { \
  98. (*gc->procs.blendSpan)( gc ); \
  99. }
  100. #define DitheredRGBColorToBuffer(col, incr, cfb, dest, type) \
  101. ((dest) = (type)(( FTOL((col)->r+(incr)) << (cfb)->redShift) | \
  102. ( FTOL((col)->g+(incr)) << (cfb)->greenShift) | \
  103. ( FTOL((col)->b+(incr)) << (cfb)->blueShift)))
  104. #define UnditheredRGBColorToBuffer(col, cfb, dest, type) \
  105. ((dest) = (type)(( FTOL((col)->r) << (cfb)->redShift) | \
  106. ( FTOL((col)->g) << (cfb)->greenShift) | \
  107. ( FTOL((col)->b) << (cfb)->blueShift)))
  108. #define DitheredRGBAColorToBuffer(col, incr, cfb, dest, type) \
  109. ((dest) = (type)(( FTOL((col)->r+(incr)) << (cfb)->redShift) | \
  110. ( FTOL((col)->g+(incr)) << (cfb)->greenShift) | \
  111. ( FTOL((col)->b+(incr)) << (cfb)->blueShift) | \
  112. ( FTOL((col)->a+(incr)) << (cfb)->alphaShift)))
  113. #define UnditheredRGBAColorToBuffer(col, cfb, dest, type) \
  114. ((dest) = (type)(( FTOL((col)->r) << (cfb)->redShift) | \
  115. ( FTOL((col)->g) << (cfb)->greenShift) | \
  116. ( FTOL((col)->b) << (cfb)->blueShift) | \
  117. ( FTOL((col)->a) << (cfb)->alphaShift)))
  118. #define DitheredColorToBuffer(col, incr, cfb, dest, type) \
  119. if( ALPHA_PIXEL_WRITE( cfb ) ) \
  120. DitheredRGBAColorToBuffer(col, incr, cfb, dest, type); \
  121. else \
  122. DitheredRGBColorToBuffer(col, incr, cfb, dest, type);
  123. #define UnditheredColorToBuffer(col, cfb, dest, type) \
  124. if( ALPHA_PIXEL_WRITE( cfb ) ) \
  125. UnditheredRGBAColorToBuffer(col, cfb, dest, type); \
  126. else \
  127. UnditheredRGBColorToBuffer(col, cfb, dest, type);
  128. #define StoreColorAsRGB(col, dst) \
  129. (*(dst)++ = (BYTE) FTOL((col)->r), \
  130. *(dst)++ = (BYTE) FTOL((col)->g), \
  131. *(dst)++ = (BYTE) FTOL((col)->b) )
  132. #define StoreColorAsBGR(col, dst) \
  133. (*(dst)++ = (BYTE) FTOL((col)->b), \
  134. *(dst)++ = (BYTE) FTOL((col)->g), \
  135. *(dst)++ = (BYTE) FTOL((col)->r) )
  136. // Macro to read RGBA bitfield span, where alpha component has 3 possibilities:
  137. // 1) No alpha buffer, so use constant alpha
  138. // 2) Alpha is part of the pixel
  139. // 3) Alpha is in the software alpha buffer
  140. // Note, currently this is only used for 16 and 32bpp.
  141. #define READ_RGBA_BITFIELD_SPAN(src_pix_gen) \
  142. if( !gc->modes.alphaBits ) { \
  143. for( ; w; w--, pResults++ ) \
  144. { \
  145. src_pix_gen; \
  146. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift); \
  147. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift); \
  148. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift); \
  149. pResults->a = cfb->alphaScale; \
  150. } \
  151. } \
  152. else if( ALPHA_IN_PIXEL( cfb ) ) { \
  153. for( ; w; w--, pResults++ ) \
  154. { \
  155. src_pix_gen; \
  156. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift); \
  157. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift); \
  158. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift); \
  159. pResults->a = (__GLfloat) ((pixel & gc->modes.alphaMask) >> cfb->alphaShift); \
  160. } \
  161. } else { \
  162. (*cfb->alphaBuf.readSpan)(&cfb->alphaBuf, x, y, w, pResults); \
  163. for( ; w; w--, pResults++ ) \
  164. { \
  165. src_pix_gen; \
  166. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift); \
  167. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift); \
  168. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift); \
  169. } \
  170. }
  171. /*
  172. * write all
  173. */
  174. STATIC void FASTCALL DIBIndex4Store(__GLcolorBuffer *cfb,
  175. const __GLfragment *frag)
  176. {
  177. GLint x, y;
  178. GLubyte result, *puj;
  179. __GLcontext *gc = cfb->buf.gc;
  180. __GLGENcontext *gengc;
  181. __GLfloat incr;
  182. GLuint enables = gc->state.enables.general;
  183. __GLcolor blendColor;
  184. const __GLcolor *color;
  185. GLubyte dst_pix;
  186. ASSERT_CHOP_ROUND();
  187. gengc = (__GLGENcontext *)gc;
  188. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  189. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  190. // x & y are screen coords now
  191. if ( (cfb->buf.flags & NO_CLIP) ||
  192. (*gengc->pfnPixelVisible)(x, y) )
  193. {
  194. incr = (enables & __GL_DITHER_ENABLE) ?
  195. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  196. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  197. (y*cfb->buf.outerWidth) + (x >> 1));
  198. if( enables & __GL_BLEND_ENABLE )
  199. {
  200. SPECIAL_ALPHA_BLEND((dst_pix = gengc->pajInvTranslateVector
  201. [(x & 1) ? (*puj & 0xf) : (*puj >> 4)]));
  202. }
  203. else
  204. {
  205. color = &(frag->color);
  206. }
  207. DitheredRGBColorToBuffer(color, incr, cfb, result, GLubyte);
  208. if (cfb->buf.flags & NEED_FETCH)
  209. {
  210. if( x & 1 )
  211. {
  212. dst_pix = (*puj & 0x0f);
  213. }
  214. else
  215. {
  216. dst_pix = (*puj & 0xf0) >> 4;
  217. }
  218. dst_pix = gengc->pajInvTranslateVector[dst_pix];
  219. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  220. {
  221. result = (GLubyte)
  222. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  223. gc->modes.allMask);
  224. }
  225. if (cfb->buf.flags & COLORMASK_ON)
  226. {
  227. result = (GLubyte)
  228. ((dst_pix & cfb->destMask) | (result & cfb->sourceMask));
  229. }
  230. }
  231. // now put it in
  232. result = gengc->pajTranslateVector[result];
  233. if (x & 1)
  234. {
  235. *puj = (*puj & 0xf0) | result;
  236. }
  237. else
  238. {
  239. result <<= 4;
  240. *puj = (*puj & 0x0f) | result;
  241. }
  242. if( ALPHA_WRITE_ENABLED( cfb ) )
  243. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  244. }
  245. }
  246. STATIC void FASTCALL DIBIndex8Store(__GLcolorBuffer *cfb,
  247. const __GLfragment *frag)
  248. {
  249. GLint x, y;
  250. GLubyte result, *puj;
  251. __GLcontext *gc = cfb->buf.gc;
  252. __GLGENcontext *gengc;
  253. __GLfloat incr;
  254. GLuint enables = gc->state.enables.general;
  255. __GLcolor blendColor;
  256. const __GLcolor *color;
  257. GLubyte dst_pix;
  258. ASSERT_CHOP_ROUND();
  259. gengc = (__GLGENcontext *)gc;
  260. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  261. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  262. // x & y are screen coords now
  263. if ( (cfb->buf.flags & NO_CLIP) ||
  264. (*gengc->pfnPixelVisible)(x, y) )
  265. {
  266. incr = (enables & __GL_DITHER_ENABLE) ?
  267. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  268. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  269. (y*cfb->buf.outerWidth) + x);
  270. if( enables & __GL_BLEND_ENABLE )
  271. {
  272. SPECIAL_ALPHA_BLEND((dst_pix =
  273. gengc->pajInvTranslateVector[*puj]));
  274. }
  275. else
  276. {
  277. color = &(frag->color);
  278. }
  279. DitheredRGBColorToBuffer(color, incr, cfb, result, GLubyte);
  280. if (cfb->buf.flags & NEED_FETCH)
  281. {
  282. dst_pix = gengc->pajInvTranslateVector[*puj];
  283. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  284. {
  285. result = (GLubyte)
  286. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  287. gc->modes.allMask);
  288. }
  289. if (cfb->buf.flags & COLORMASK_ON)
  290. {
  291. result = (GLubyte)
  292. ((dst_pix & cfb->destMask) | (result & cfb->sourceMask));
  293. }
  294. }
  295. *puj = gengc->pajTranslateVector[result];
  296. if( ALPHA_WRITE_ENABLED( cfb ) )
  297. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  298. }
  299. }
  300. // BMF_24BPP in BGR format
  301. STATIC void FASTCALL DIBBGRStore(__GLcolorBuffer *cfb,
  302. const __GLfragment *frag)
  303. {
  304. GLint x, y;
  305. GLubyte *puj;
  306. GLuint result;
  307. __GLcontext *gc = cfb->buf.gc;
  308. __GLGENcontext *gengc;
  309. GLuint enables = gc->state.enables.general;
  310. __GLcolor blendColor;
  311. const __GLcolor *color;
  312. GLuint dst_pix;
  313. ASSERT_CHOP_ROUND();
  314. gengc = (__GLGENcontext *)gc;
  315. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  316. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  317. // x & y are screen coords now
  318. if ( (cfb->buf.flags & NO_CLIP) ||
  319. (*gengc->pfnPixelVisible)(x, y) )
  320. {
  321. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  322. (y*cfb->buf.outerWidth) + (x * 3));
  323. if( enables & __GL_BLEND_ENABLE )
  324. {
  325. SPECIAL_ALPHA_BLEND(Copy3Bytes(&dst_pix, puj));
  326. }
  327. else
  328. {
  329. color = &(frag->color);
  330. }
  331. if (cfb->buf.flags & NEED_FETCH)
  332. {
  333. Copy3Bytes( &dst_pix, puj );
  334. UnditheredRGBColorToBuffer(color, cfb, result, GLuint);
  335. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  336. {
  337. result = DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  338. gc->modes.allMask;
  339. }
  340. if (cfb->buf.flags & COLORMASK_ON)
  341. {
  342. result =
  343. (result & cfb->sourceMask) | (dst_pix & cfb->destMask);
  344. }
  345. Copy3Bytes( puj, &result );
  346. }
  347. else
  348. {
  349. StoreColorAsBGR(color, puj);
  350. }
  351. if( ALPHA_WRITE_ENABLED( cfb ) )
  352. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  353. }
  354. }
  355. // BMF_24BPP in RGB format
  356. STATIC void FASTCALL DIBRGBAStore(__GLcolorBuffer *cfb,
  357. const __GLfragment *frag)
  358. {
  359. GLint x, y;
  360. GLubyte *puj;
  361. GLuint result;
  362. __GLcontext *gc = cfb->buf.gc;
  363. __GLGENcontext *gengc;
  364. GLuint enables = gc->state.enables.general;
  365. __GLcolor blendColor;
  366. const __GLcolor *color;
  367. GLuint dst_pix;
  368. ASSERT_CHOP_ROUND();
  369. gengc = (__GLGENcontext *)gc;
  370. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  371. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  372. // x & y are screen coords now
  373. if ( (cfb->buf.flags & NO_CLIP) ||
  374. (*gengc->pfnPixelVisible)(x, y) )
  375. {
  376. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  377. (y*cfb->buf.outerWidth) + (x * 3));
  378. if( enables & __GL_BLEND_ENABLE )
  379. {
  380. SPECIAL_ALPHA_BLEND(Copy3Bytes(&dst_pix, puj));
  381. }
  382. else
  383. {
  384. color = &(frag->color);
  385. }
  386. if (cfb->buf.flags & NEED_FETCH)
  387. {
  388. Copy3Bytes( &dst_pix, puj );
  389. UnditheredRGBColorToBuffer(color, cfb, result, GLuint);
  390. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  391. {
  392. result = DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  393. gc->modes.allMask;
  394. }
  395. if (cfb->buf.flags & COLORMASK_ON)
  396. {
  397. result =
  398. (result & cfb->sourceMask) | (dst_pix & cfb->destMask);
  399. }
  400. Copy3Bytes( puj, &result );
  401. }
  402. else
  403. {
  404. StoreColorAsRGB(color, puj);
  405. }
  406. if( ALPHA_WRITE_ENABLED( cfb ) )
  407. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  408. }
  409. }
  410. // BMF_16BPP
  411. STATIC void FASTCALL DIBBitfield16Store(__GLcolorBuffer *cfb,
  412. const __GLfragment *frag)
  413. {
  414. GLint x, y;
  415. GLushort result, *pus;
  416. __GLcontext *gc = cfb->buf.gc;
  417. __GLGENcontext *gengc;
  418. __GLfloat incr;
  419. GLuint enables = gc->state.enables.general;
  420. __GLcolor blendColor;
  421. const __GLcolor *color;
  422. GLushort dst_pix;
  423. ASSERT_CHOP_ROUND();
  424. gengc = (__GLGENcontext *)gc;
  425. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  426. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  427. // x & y are screen coords now
  428. if ( (cfb->buf.flags & NO_CLIP) ||
  429. (*gengc->pfnPixelVisible)(x, y) )
  430. {
  431. incr = (enables & __GL_DITHER_ENABLE) ?
  432. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  433. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  434. (y*cfb->buf.outerWidth) + (x << 1));
  435. if( enables & __GL_BLEND_ENABLE )
  436. {
  437. SPECIAL_ALPHA_BLEND((dst_pix = *pus));
  438. }
  439. else
  440. {
  441. color = &(frag->color);
  442. }
  443. DitheredColorToBuffer(color, incr, cfb, result, GLushort);
  444. if (cfb->buf.flags & NEED_FETCH)
  445. {
  446. dst_pix = *pus;
  447. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  448. {
  449. result = (GLushort)
  450. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  451. gc->modes.allMask);
  452. }
  453. if (cfb->buf.flags & COLORMASK_ON)
  454. {
  455. result = (GLushort)((dst_pix & cfb->destMask) |
  456. (result & cfb->sourceMask));
  457. }
  458. }
  459. *pus = result;
  460. if( ALPHA_BUFFER_WRITE( cfb ) )
  461. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  462. }
  463. }
  464. // BMF_32BPP store
  465. // each component is 8 bits or less
  466. // XXX could special case if shifting by 8 or use the 24 bit RGB code
  467. STATIC void FASTCALL DIBBitfield32Store(__GLcolorBuffer *cfb,
  468. const __GLfragment *frag)
  469. {
  470. GLint x, y;
  471. GLuint result, *pul;
  472. __GLcontext *gc = cfb->buf.gc;
  473. __GLGENcontext *gengc;
  474. GLuint enables = gc->state.enables.general;
  475. __GLcolor blendColor;
  476. const __GLcolor *color;
  477. GLuint dst_pix;
  478. ASSERT_CHOP_ROUND();
  479. gengc = (__GLGENcontext *)gc;
  480. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  481. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  482. // x & y are screen coords now
  483. if ( (cfb->buf.flags & NO_CLIP) ||
  484. (*gengc->pfnPixelVisible)(x, y) )
  485. {
  486. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  487. (y*cfb->buf.outerWidth) + (x << 2));
  488. if( enables & __GL_BLEND_ENABLE )
  489. {
  490. SPECIAL_ALPHA_BLEND((dst_pix = *pul));
  491. }
  492. else
  493. {
  494. color = &(frag->color);
  495. }
  496. UnditheredColorToBuffer(color, cfb, result, GLuint);
  497. if (cfb->buf.flags & NEED_FETCH)
  498. {
  499. dst_pix = *pul;
  500. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  501. {
  502. result =
  503. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  504. gc->modes.allMask;
  505. }
  506. if (cfb->buf.flags & COLORMASK_ON)
  507. {
  508. result = (dst_pix & cfb->destMask) | (result & cfb->sourceMask);
  509. }
  510. }
  511. *pul = result;
  512. if( ALPHA_BUFFER_WRITE( cfb ) )
  513. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  514. }
  515. }
  516. static GLubyte vubRGBtoVGA[8] = {
  517. 0x00,
  518. 0x90,
  519. 0xa0,
  520. 0xb0,
  521. 0xc0,
  522. 0xd0,
  523. 0xe0,
  524. 0xf0
  525. };
  526. STATIC void FASTCALL DisplayIndex4Store(__GLcolorBuffer *cfb,
  527. const __GLfragment *frag)
  528. {
  529. GLint x, y;
  530. GLubyte result, *puj;
  531. __GLcontext *gc = cfb->buf.gc;
  532. __GLGENcontext *gengc;
  533. __GLfloat incr;
  534. GLuint enables = gc->state.enables.general;
  535. __GLcolor blendColor;
  536. const __GLcolor *color;
  537. GLubyte dst_pix;
  538. ASSERT_CHOP_ROUND();
  539. gengc = (__GLGENcontext *)gc;
  540. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  541. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  542. // x & y are screen coords now
  543. incr = (enables & __GL_DITHER_ENABLE) ?
  544. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  545. puj = gengc->ColorsBits;
  546. if( enables & __GL_BLEND_ENABLE )
  547. {
  548. color = &blendColor;
  549. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  550. }
  551. else
  552. {
  553. color = &(frag->color);
  554. }
  555. DitheredRGBColorToBuffer(color, incr, cfb, result, GLubyte);
  556. if (cfb->buf.flags & NEED_FETCH)
  557. {
  558. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  559. dst_pix = *puj >> 4;
  560. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  561. {
  562. result = (GLubyte)
  563. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  564. gc->modes.allMask);
  565. }
  566. if (cfb->buf.flags & COLORMASK_ON)
  567. {
  568. result = (GLubyte)((dst_pix & cfb->destMask) |
  569. (result & cfb->sourceMask));
  570. }
  571. }
  572. *puj = vubRGBtoVGA[result];
  573. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  574. if( ALPHA_WRITE_ENABLED( cfb ) )
  575. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  576. }
  577. // Put fragment into created DIB and call copybits for one pixel
  578. STATIC void FASTCALL DisplayIndex8Store(__GLcolorBuffer *cfb,
  579. const __GLfragment *frag)
  580. {
  581. GLint x, y;
  582. GLubyte result, *puj;
  583. __GLcontext *gc = cfb->buf.gc;
  584. __GLGENcontext *gengc;
  585. __GLfloat incr;
  586. GLuint enables = gc->state.enables.general;
  587. __GLcolor blendColor;
  588. const __GLcolor *color;
  589. GLubyte dst_pix;
  590. ASSERT_CHOP_ROUND();
  591. gengc = (__GLGENcontext *)gc;
  592. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  593. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  594. // x & y are screen coords now
  595. incr = (enables & __GL_DITHER_ENABLE) ?
  596. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  597. puj = gengc->ColorsBits;
  598. if( enables & __GL_BLEND_ENABLE )
  599. {
  600. color = &blendColor;
  601. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  602. }
  603. else
  604. {
  605. color = &(frag->color);
  606. }
  607. DitheredRGBColorToBuffer(color, incr, cfb, result, GLubyte);
  608. if (cfb->buf.flags & NEED_FETCH)
  609. {
  610. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  611. dst_pix = gengc->pajInvTranslateVector[*puj];
  612. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  613. {
  614. result = (GLubyte)
  615. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  616. gc->modes.allMask);
  617. }
  618. if (cfb->buf.flags & COLORMASK_ON)
  619. {
  620. result = (GLubyte)((dst_pix & cfb->destMask) |
  621. (result & cfb->sourceMask));
  622. }
  623. }
  624. *puj = gengc->pajTranslateVector[result];
  625. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  626. if( ALPHA_WRITE_ENABLED( cfb ) )
  627. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  628. }
  629. STATIC void FASTCALL DisplayBGRStore(__GLcolorBuffer *cfb,
  630. const __GLfragment *frag)
  631. {
  632. GLint x, y;
  633. GLubyte *puj;
  634. GLuint result;
  635. __GLcontext *gc = cfb->buf.gc;
  636. __GLGENcontext *gengc;
  637. GLuint enables = gc->state.enables.general;
  638. __GLcolor blendColor;
  639. const __GLcolor *color;
  640. GLuint dst_pix;
  641. ASSERT_CHOP_ROUND();
  642. gengc = (__GLGENcontext *)gc;
  643. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  644. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  645. // x & y are screen coords now
  646. puj = gengc->ColorsBits;
  647. if( enables & __GL_BLEND_ENABLE )
  648. {
  649. color = &blendColor;
  650. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  651. }
  652. else
  653. {
  654. color = &(frag->color);
  655. }
  656. if (cfb->buf.flags & NEED_FETCH)
  657. {
  658. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  659. dst_pix = *(GLuint *)puj;
  660. UnditheredRGBColorToBuffer(color, cfb, result, GLuint);
  661. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  662. {
  663. result =
  664. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  665. gc->modes.allMask;
  666. }
  667. if (cfb->buf.flags & COLORMASK_ON)
  668. {
  669. result = (dst_pix & cfb->destMask) |
  670. (result & cfb->sourceMask);
  671. }
  672. Copy3Bytes( puj, &result );
  673. }
  674. else
  675. {
  676. StoreColorAsBGR(color, puj);
  677. }
  678. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  679. if( ALPHA_WRITE_ENABLED( cfb ) )
  680. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  681. }
  682. STATIC void FASTCALL DisplayRGBStore(__GLcolorBuffer *cfb,
  683. const __GLfragment *frag)
  684. {
  685. GLint x, y;
  686. GLubyte *puj;
  687. GLuint result;
  688. __GLcontext *gc = cfb->buf.gc;
  689. __GLGENcontext *gengc;
  690. GLuint enables = gc->state.enables.general;
  691. __GLcolor blendColor;
  692. const __GLcolor *color;
  693. GLuint dst_pix;
  694. ASSERT_CHOP_ROUND();
  695. gengc = (__GLGENcontext *)gc;
  696. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  697. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  698. // x & y are screen coords now
  699. puj = gengc->ColorsBits;
  700. if( enables & __GL_BLEND_ENABLE )
  701. {
  702. color = &blendColor;
  703. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  704. }
  705. else
  706. {
  707. color = &(frag->color);
  708. }
  709. if (cfb->buf.flags & NEED_FETCH)
  710. {
  711. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  712. dst_pix = *(GLuint *)puj;
  713. UnditheredRGBColorToBuffer(color, cfb, result, GLuint);
  714. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  715. {
  716. result =
  717. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  718. gc->modes.allMask;
  719. }
  720. if (cfb->buf.flags & COLORMASK_ON)
  721. {
  722. result = (dst_pix & cfb->destMask) |
  723. (result & cfb->sourceMask);
  724. }
  725. Copy3Bytes( puj, &result );
  726. }
  727. else
  728. {
  729. StoreColorAsRGB(color, puj);
  730. }
  731. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  732. if( ALPHA_WRITE_ENABLED( cfb ) )
  733. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  734. }
  735. STATIC void FASTCALL DisplayBitfield16Store(__GLcolorBuffer *cfb,
  736. const __GLfragment *frag)
  737. {
  738. GLint x, y;
  739. GLushort result, *pus;
  740. __GLcontext *gc = cfb->buf.gc;
  741. __GLGENcontext *gengc;
  742. __GLfloat incr;
  743. GLuint enables = gc->state.enables.general;
  744. __GLcolor blendColor;
  745. const __GLcolor *color;
  746. GLushort dst_pix;
  747. ASSERT_CHOP_ROUND();
  748. gengc = (__GLGENcontext *)gc;
  749. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  750. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  751. // x & y are screen coords now
  752. incr = (enables & __GL_DITHER_ENABLE) ?
  753. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  754. pus = gengc->ColorsBits;
  755. if( enables & __GL_BLEND_ENABLE )
  756. {
  757. color = &blendColor;
  758. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  759. }
  760. else
  761. {
  762. color = &(frag->color);
  763. }
  764. DitheredColorToBuffer(color, incr, cfb, result, GLushort);
  765. if (cfb->buf.flags & NEED_FETCH)
  766. {
  767. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  768. dst_pix = *pus;
  769. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  770. {
  771. result = (GLushort)
  772. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  773. gc->modes.allMask);
  774. }
  775. if (cfb->buf.flags & COLORMASK_ON)
  776. {
  777. result = (GLushort)((dst_pix & cfb->destMask) |
  778. (result & cfb->sourceMask));
  779. }
  780. }
  781. *pus = result;
  782. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  783. if( ALPHA_BUFFER_WRITE( cfb ) )
  784. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  785. }
  786. STATIC void FASTCALL DisplayBitfield32Store(__GLcolorBuffer *cfb,
  787. const __GLfragment *frag)
  788. {
  789. GLint x, y;
  790. GLuint result, *pul;
  791. __GLcontext *gc = cfb->buf.gc;
  792. __GLGENcontext *gengc;
  793. GLuint enables = gc->state.enables.general;
  794. __GLcolor blendColor;
  795. const __GLcolor *color;
  796. GLuint dst_pix;
  797. ASSERT_CHOP_ROUND();
  798. gengc = (__GLGENcontext *)gc;
  799. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  800. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  801. // x & y are screen coords now
  802. pul = gengc->ColorsBits;
  803. if( enables & __GL_BLEND_ENABLE )
  804. {
  805. color = &blendColor;
  806. (*gc->procs.blend)( gc, cfb, frag, &blendColor );
  807. }
  808. else
  809. {
  810. color = &(frag->color);
  811. }
  812. UnditheredColorToBuffer(color, cfb, result, GLuint);
  813. if (cfb->buf.flags & NEED_FETCH)
  814. {
  815. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  816. dst_pix = *pul;
  817. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  818. {
  819. result =
  820. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  821. gc->modes.allMask;
  822. }
  823. if (cfb->buf.flags & COLORMASK_ON)
  824. {
  825. result = (dst_pix & cfb->destMask) |
  826. (result & cfb->sourceMask);
  827. }
  828. }
  829. *pul = result;
  830. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  831. if( ALPHA_BUFFER_WRITE( cfb ) )
  832. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, color);
  833. }
  834. STATIC void FASTCALL AlphaStore(__GLcolorBuffer *cfb,
  835. const __GLfragment *frag)
  836. {
  837. (*cfb->alphaBuf.store)(&cfb->alphaBuf, frag->x, frag->y, &(frag->color) );
  838. }
  839. /******************************Public*Routine******************************\
  840. * Index8StoreSpan
  841. *
  842. * Copies the current span in the renderer into a bitmap. If bDIB is TRUE,
  843. * then the bitmap is the display in DIB format (or a memory DC). If bDIB
  844. * is FALSE, then the bitmap is an offscreen scanline buffer and it will be
  845. * output to the buffer by (*gengc->pfnCopyPixels)().
  846. *
  847. * This handles 8-bit CI mode. Blending and dithering are supported.
  848. *
  849. * Returns:
  850. * GL_FALSE always. Soft code ignores return value.
  851. *
  852. * History:
  853. * 15-Nov-1993 -by- Gilman Wong [gilmanw]
  854. * Wrote it.
  855. \**************************************************************************/
  856. //XXX The returnSpan routine follows this routine very closely. Any changes
  857. //XXX to this routine should also be reflected in the returnSpan routine
  858. STATIC GLboolean FASTCALL Index8StoreSpan( __GLcontext *gc )
  859. {
  860. GLint xFrag, yFrag; // current fragment coordinates
  861. __GLcolor *cp; // current fragment color
  862. __GLcolorBuffer *cfb; // color frame buffer
  863. GLint xScr, yScr; // current screen (pixel) coordinates
  864. GLubyte result, *puj; // current pixel color, current pixel ptr
  865. GLubyte *pujEnd; // end of scan line
  866. __GLfloat incr; // current dither adj.
  867. GLint w; // span width
  868. ULONG ulSpanVisibility; // span visibility mode
  869. GLint cWalls;
  870. GLint *Walls;
  871. __GLGENcontext *gengc; // generic graphics context
  872. GLuint enables; // modes enabled in graphics context
  873. GLuint flags;
  874. GLboolean bDIB;
  875. GLubyte dst_pix;
  876. ASSERT_CHOP_ROUND();
  877. // Get span position and length.
  878. w = gc->polygon.shader.length;
  879. xFrag = gc->polygon.shader.frag.x;
  880. yFrag = gc->polygon.shader.frag.y;
  881. gengc = (__GLGENcontext *)gc;
  882. cfb = gc->drawBuffer;
  883. xScr = __GL_UNBIAS_X(gc, xFrag) + cfb->buf.xOrigin;
  884. yScr = __GL_UNBIAS_Y(gc, yFrag) + cfb->buf.yOrigin;
  885. enables = gc->state.enables.general;
  886. flags = cfb->buf.flags;
  887. bDIB = flags & DIB_FORMAT;
  888. if( !bDIB || (flags & NO_CLIP) )
  889. {
  890. // Device managed or unclipped surface
  891. ulSpanVisibility = WGL_SPAN_ALL;
  892. }
  893. else
  894. {
  895. // Device in BITMAP format
  896. ulSpanVisibility = wglSpanVisible(xScr, yScr, w, &cWalls, &Walls);
  897. }
  898. // Proceed as long as the span is (partially or fully) visible.
  899. if (ulSpanVisibility != WGL_SPAN_NONE)
  900. {
  901. GLboolean bCheckWalls = GL_FALSE;
  902. GLboolean bDraw;
  903. GLint NextWall;
  904. if (ulSpanVisibility == WGL_SPAN_PARTIAL)
  905. {
  906. bCheckWalls = GL_TRUE;
  907. if (cWalls & 0x01)
  908. {
  909. bDraw = GL_TRUE;
  910. }
  911. else
  912. {
  913. bDraw = GL_FALSE;
  914. }
  915. NextWall = *Walls++;
  916. cWalls--;
  917. }
  918. // Get pointers to fragment colors array and frame buffer.
  919. cp = gc->polygon.shader.colors;
  920. cfb = gc->polygon.shader.cfb;
  921. // Get pointer to bitmap.
  922. puj = bDIB ? (GLubyte *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + xScr)
  923. : gengc->ColorsBits;
  924. pujEnd = puj + w;
  925. // Case: no dithering, no masking, no blending
  926. //
  927. // Check for the common case (which we'll do the fastest).
  928. if ( !(enables & (__GL_DITHER_ENABLE)) &&
  929. !(cfb->buf.flags & NEED_FETCH) &&
  930. !(enables & __GL_BLEND_ENABLE ) )
  931. {
  932. //!!!XXX -- we can also opt. by unrolling the loops
  933. incr = __glHalf;
  934. for (; puj < pujEnd; puj++, cp++)
  935. {
  936. if (bCheckWalls)
  937. {
  938. if (xScr++ >= NextWall)
  939. {
  940. if (bDraw)
  941. bDraw = GL_FALSE;
  942. else
  943. bDraw = GL_TRUE;
  944. if (cWalls <= 0)
  945. {
  946. NextWall = gc->constants.maxViewportWidth;
  947. }
  948. else
  949. {
  950. NextWall = *Walls++;
  951. cWalls--;
  952. }
  953. }
  954. if (bDraw == GL_FALSE)
  955. continue;
  956. }
  957. DitheredRGBColorToBuffer(cp, incr, cfb, result, GLubyte);
  958. *puj = gengc->pajTranslateVector[result];
  959. }
  960. }
  961. // Case: dithering, no masking, no blending
  962. //
  963. // Dithering is pretty common for 8-bit displays, so its probably
  964. // worth special case also.
  965. else if ( !(cfb->buf.flags & NEED_FETCH) &&
  966. !(enables & __GL_BLEND_ENABLE) )
  967. {
  968. for (; puj < pujEnd; puj++, cp++, xFrag++)
  969. {
  970. if (bCheckWalls)
  971. {
  972. if (xScr++ >= NextWall)
  973. {
  974. if (bDraw)
  975. bDraw = GL_FALSE;
  976. else
  977. bDraw = GL_TRUE;
  978. if (cWalls <= 0)
  979. {
  980. NextWall = gc->constants.maxViewportWidth;
  981. }
  982. else
  983. {
  984. NextWall = *Walls++;
  985. cWalls--;
  986. }
  987. }
  988. if (bDraw == GL_FALSE)
  989. continue;
  990. }
  991. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  992. DitheredRGBColorToBuffer(cp, incr, cfb, result, GLubyte);
  993. *puj = gengc->pajTranslateVector[result];
  994. }
  995. }
  996. // Case: general
  997. //
  998. // Otherwise, we'll do it slower.
  999. else
  1000. {
  1001. // Fetch pixels we will modify:
  1002. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1003. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE );
  1004. // Blend.
  1005. if (enables & __GL_BLEND_ENABLE)
  1006. {
  1007. int i;
  1008. // this overwrites fragment colors array with blended values
  1009. SPECIAL_ALPHA_BLEND_SPAN(
  1010. (dst_pix =
  1011. gengc->pajInvTranslateVector[*(puj+i)]));
  1012. }
  1013. for (; puj < pujEnd; puj++, cp++)
  1014. {
  1015. if (bCheckWalls)
  1016. {
  1017. if (xScr++ >= NextWall)
  1018. {
  1019. if (bDraw)
  1020. bDraw = GL_FALSE;
  1021. else
  1022. bDraw = GL_TRUE;
  1023. if (cWalls <= 0)
  1024. {
  1025. NextWall = gc->constants.maxViewportWidth;
  1026. }
  1027. else
  1028. {
  1029. NextWall = *Walls++;
  1030. cWalls--;
  1031. }
  1032. }
  1033. if (bDraw == GL_FALSE)
  1034. continue;
  1035. }
  1036. // Dither.
  1037. if (enables & __GL_DITHER_ENABLE)
  1038. {
  1039. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1040. xFrag++;
  1041. }
  1042. else
  1043. {
  1044. incr = __glHalf;
  1045. }
  1046. // Convert the RGB color to color index.
  1047. DitheredRGBColorToBuffer(cp, incr, cfb, result, GLubyte);
  1048. // Color mask
  1049. if (cfb->buf.flags & NEED_FETCH)
  1050. {
  1051. dst_pix = gengc->pajInvTranslateVector[*puj];
  1052. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1053. {
  1054. result = (GLubyte)
  1055. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  1056. gc->modes.allMask);
  1057. }
  1058. if (cfb->buf.flags & COLORMASK_ON)
  1059. {
  1060. result = (GLubyte)((dst_pix & cfb->destMask) |
  1061. (result & cfb->sourceMask));
  1062. }
  1063. }
  1064. *puj = gengc->pajTranslateVector[result];
  1065. }
  1066. }
  1067. // Output the offscreen scanline buffer to the device. The function
  1068. // (*gengc->pfnCopyPixels) should handle clipping.
  1069. if (!bDIB)
  1070. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1071. // Note that we ignore walls here for simplicity...
  1072. if( ALPHA_WRITE_ENABLED( cfb ) )
  1073. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1074. }
  1075. return GL_FALSE;
  1076. }
  1077. /******************************Public*Routine******************************\
  1078. * Bitfield16StoreSpan
  1079. *
  1080. * Copies the current span in the renderer into a bitmap. If bDIB is TRUE,
  1081. * then the bitmap is the display in DIB format (or a memory DC). If bDIB
  1082. * is FALSE, then the bitmap is an offscreen scanline buffer and it will be
  1083. * output to the buffer by (*gengc->pfnCopyPixels)().
  1084. *
  1085. * This handles general 16-bit BITFIELDS mode. Blending is supported. There
  1086. * is dithering.
  1087. *
  1088. * Returns:
  1089. * GL_FALSE always. Soft code ignores return value.
  1090. *
  1091. * History:
  1092. * 08-Dec-1993 -by- Gilman Wong [gilmanw]
  1093. * Wrote it.
  1094. \**************************************************************************/
  1095. //XXX The returnSpan routine follows this routine very closely. Any changes
  1096. //XXX to this routine should also be reflected in the returnSpan routine
  1097. STATIC GLboolean FASTCALL
  1098. Bitfield16StoreSpanPartial(__GLcontext *gc, GLboolean bDIB, GLint cWalls, GLint *Walls )
  1099. {
  1100. GLint xFrag, yFrag; // current fragment coordinates
  1101. __GLcolor *cp; // current fragment color
  1102. __GLcolorBuffer *cfb; // color frame buffer
  1103. GLint xScr, yScr; // current screen (pixel) coordinates
  1104. GLushort result, *pus; // current pixel color, current pixel ptr
  1105. GLushort *pusEnd; // end of scan line
  1106. __GLfloat incr; // current dither adj.
  1107. GLint w; // span width
  1108. GLboolean bDraw;
  1109. GLint NextWall;
  1110. __GLGENcontext *gengc; // generic graphics context
  1111. GLuint enables; // modes enabled in graphics context
  1112. GLuint flags;
  1113. GLushort dst_pix;
  1114. // Get span position and length.
  1115. w = gc->polygon.shader.length;
  1116. xFrag = gc->polygon.shader.frag.x;
  1117. yFrag = gc->polygon.shader.frag.y;
  1118. gengc = (__GLGENcontext *)gc;
  1119. cfb = gc->drawBuffer;
  1120. xScr = __GL_UNBIAS_X(gc, xFrag) + cfb->buf.xOrigin;
  1121. yScr = __GL_UNBIAS_Y(gc, yFrag) + cfb->buf.yOrigin;
  1122. enables = gc->state.enables.general;
  1123. flags = cfb->buf.flags;
  1124. if (cWalls & 0x01)
  1125. {
  1126. bDraw = GL_TRUE;
  1127. }
  1128. else
  1129. {
  1130. bDraw = GL_FALSE;
  1131. }
  1132. NextWall = *Walls++;
  1133. cWalls--;
  1134. // Get pointers to fragment colors array and frame buffer.
  1135. cp = gc->polygon.shader.colors;
  1136. cfb = gc->polygon.shader.cfb;
  1137. // Get pointer to bitmap.
  1138. pus = bDIB ? (GLushort *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<1))
  1139. : gengc->ColorsBits;
  1140. pusEnd = pus + w;
  1141. // Case: no masking, no dithering, no blending
  1142. if ( !(enables & (__GL_DITHER_ENABLE)) &&
  1143. !(cfb->buf.flags & NEED_FETCH) &&
  1144. !(enables & __GL_BLEND_ENABLE) )
  1145. {
  1146. incr = __glHalf;
  1147. for (; pus < pusEnd; pus++, cp++)
  1148. {
  1149. if (xScr++ >= NextWall)
  1150. {
  1151. if (bDraw)
  1152. bDraw = GL_FALSE;
  1153. else
  1154. bDraw = GL_TRUE;
  1155. if (cWalls <= 0)
  1156. {
  1157. NextWall = gc->constants.maxViewportWidth;
  1158. }
  1159. else
  1160. {
  1161. NextWall = *Walls++;
  1162. cWalls--;
  1163. }
  1164. }
  1165. if (bDraw == GL_FALSE)
  1166. continue;
  1167. DitheredColorToBuffer(cp, incr, cfb, result, GLushort);
  1168. *pus = result;
  1169. }
  1170. }
  1171. // Case: dithering, no masking, no blending
  1172. else if ( !(cfb->buf.flags & NEED_FETCH) &&
  1173. !(enables & __GL_BLEND_ENABLE) )
  1174. {
  1175. for (; pus < pusEnd; pus++, cp++, xFrag++)
  1176. {
  1177. if (xScr++ >= NextWall)
  1178. {
  1179. if (bDraw)
  1180. bDraw = GL_FALSE;
  1181. else
  1182. bDraw = GL_TRUE;
  1183. if (cWalls <= 0)
  1184. {
  1185. NextWall = gc->constants.maxViewportWidth;
  1186. }
  1187. else
  1188. {
  1189. NextWall = *Walls++;
  1190. cWalls--;
  1191. }
  1192. }
  1193. if (bDraw == GL_FALSE)
  1194. continue;
  1195. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1196. DitheredColorToBuffer(cp, incr, cfb, result, GLushort);
  1197. *pus = result;
  1198. }
  1199. }
  1200. // All other cases
  1201. else
  1202. {
  1203. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1204. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  1205. if ( enables & __GL_BLEND_ENABLE )
  1206. {
  1207. int i;
  1208. // this overwrites fragment colors array with blended values
  1209. // XXX is the +i handled properly by the optimizer ?
  1210. SPECIAL_ALPHA_BLEND_SPAN((dst_pix = *(pus+i)));
  1211. }
  1212. for (; pus < pusEnd; pus++, cp++)
  1213. {
  1214. if (xScr++ >= NextWall)
  1215. {
  1216. if (bDraw)
  1217. bDraw = GL_FALSE;
  1218. else
  1219. bDraw = GL_TRUE;
  1220. if (cWalls <= 0)
  1221. {
  1222. NextWall = gc->constants.maxViewportWidth;
  1223. }
  1224. else
  1225. {
  1226. NextWall = *Walls++;
  1227. cWalls--;
  1228. }
  1229. }
  1230. if (bDraw == GL_FALSE)
  1231. continue;
  1232. // Dither.
  1233. if ( enables & __GL_DITHER_ENABLE )
  1234. {
  1235. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1236. xFrag++;
  1237. }
  1238. else
  1239. {
  1240. incr = __glHalf;
  1241. }
  1242. // Convert color to 16BPP format.
  1243. DitheredColorToBuffer(cp, incr, cfb, result, GLushort);
  1244. // Store result with optional masking.
  1245. if (cfb->buf.flags & NEED_FETCH)
  1246. {
  1247. dst_pix = *pus;
  1248. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1249. {
  1250. result = (GLushort)
  1251. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  1252. gc->modes.allMask);
  1253. }
  1254. if ( cfb->buf.flags & COLORMASK_ON )
  1255. {
  1256. result = (GLushort)((dst_pix & cfb->destMask) |
  1257. (result & cfb->sourceMask));
  1258. }
  1259. }
  1260. *pus = result;
  1261. }
  1262. }
  1263. // Output the offscreen scanline buffer to the device. The function
  1264. // (*gengc->pfnCopyPixels) should handle clipping.
  1265. if (!bDIB)
  1266. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1267. if( ALPHA_BUFFER_WRITE( cfb ) )
  1268. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1269. return GL_FALSE;
  1270. }
  1271. STATIC GLboolean FASTCALL Bitfield16StoreSpan(__GLcontext *gc)
  1272. {
  1273. GLint xFrag, yFrag; // current fragment coordinates
  1274. __GLcolor *cp; // current fragment color
  1275. __GLcolorBuffer *cfb; // color frame buffer
  1276. GLboolean bDIB;
  1277. GLint xScr, yScr; // current screen (pixel) coordinates
  1278. GLushort result, *pus; // current pixel color, current pixel ptr
  1279. GLushort *pusEnd; // end of scan line
  1280. __GLfloat incr; // current dither adj.
  1281. GLint w; // span width
  1282. GLint cWalls;
  1283. GLint *Walls;
  1284. __GLGENcontext *gengc; // generic graphics context
  1285. GLuint enables; // modes enabled in graphics context
  1286. GLuint flags;
  1287. GLushort dst_pix;
  1288. ASSERT_CHOP_ROUND();
  1289. // Get span position and length.
  1290. w = gc->polygon.shader.length;
  1291. xFrag = gc->polygon.shader.frag.x;
  1292. yFrag = gc->polygon.shader.frag.y;
  1293. gengc = (__GLGENcontext *)gc;
  1294. cfb = gc->drawBuffer;
  1295. xScr = __GL_UNBIAS_X(gc, xFrag) + cfb->buf.xOrigin;
  1296. yScr = __GL_UNBIAS_Y(gc, yFrag) + cfb->buf.yOrigin;
  1297. enables = gc->state.enables.general;
  1298. flags = cfb->buf.flags;
  1299. bDIB = flags & DIB_FORMAT;
  1300. // Check span visibility
  1301. if( bDIB && !(flags & NO_CLIP) )
  1302. {
  1303. // Device in BITMAP format
  1304. ULONG ulSpanVisibility; // span visibility mode
  1305. ulSpanVisibility = wglSpanVisible(xScr, yScr, w, &cWalls, &Walls);
  1306. if (ulSpanVisibility == WGL_SPAN_NONE)
  1307. return GL_FALSE;
  1308. else if (ulSpanVisibility == WGL_SPAN_PARTIAL)
  1309. return Bitfield16StoreSpanPartial( gc, bDIB, cWalls, Walls );
  1310. // else span fully visible
  1311. }
  1312. // Get pointers to fragment colors array and frame buffer.
  1313. cp = gc->polygon.shader.colors;
  1314. cfb = gc->polygon.shader.cfb;
  1315. // Get pointer to bitmap.
  1316. pus = bDIB ? (GLushort *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<1))
  1317. : gengc->ColorsBits;
  1318. pusEnd = pus + w;
  1319. // Case: no masking, no dithering, no blending
  1320. if ( !(enables & (__GL_DITHER_ENABLE)) &&
  1321. !(cfb->buf.flags & NEED_FETCH) &&
  1322. !(enables & __GL_BLEND_ENABLE) )
  1323. {
  1324. incr = __glHalf;
  1325. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  1326. for (; pus < pusEnd; pus++, cp++)
  1327. DitheredRGBAColorToBuffer(cp, incr, cfb, *pus, GLushort);
  1328. } else {
  1329. for (; pus < pusEnd; pus++, cp++)
  1330. DitheredRGBColorToBuffer(cp, incr, cfb, *pus, GLushort);
  1331. }
  1332. }
  1333. // Case: dithering, no masking, no blending
  1334. else if ( !(cfb->buf.flags & NEED_FETCH) &&
  1335. !(enables & __GL_BLEND_ENABLE) )
  1336. {
  1337. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  1338. for (; pus < pusEnd; pus++, cp++, xFrag++)
  1339. {
  1340. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1341. DitheredRGBAColorToBuffer(cp, incr, cfb, *pus, GLushort);
  1342. }
  1343. } else {
  1344. for (; pus < pusEnd; pus++, cp++, xFrag++)
  1345. {
  1346. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1347. DitheredRGBColorToBuffer(cp, incr, cfb, *pus, GLushort);
  1348. }
  1349. }
  1350. }
  1351. // All other cases
  1352. else
  1353. {
  1354. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1355. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  1356. if ( enables & __GL_BLEND_ENABLE )
  1357. {
  1358. int i;
  1359. // this overwrites fragment colors array with blended values
  1360. SPECIAL_ALPHA_BLEND_SPAN((dst_pix = *(pus+i)));
  1361. }
  1362. for (; pus < pusEnd; pus++, cp++)
  1363. {
  1364. // Dither.
  1365. if ( enables & __GL_DITHER_ENABLE )
  1366. {
  1367. incr = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  1368. xFrag++;
  1369. }
  1370. else
  1371. {
  1372. incr = __glHalf;
  1373. }
  1374. // Convert color to 16BPP format.
  1375. DitheredColorToBuffer(cp, incr, cfb, result, GLushort);
  1376. // Store result with optional masking.
  1377. if (cfb->buf.flags & NEED_FETCH)
  1378. {
  1379. dst_pix = *pus;
  1380. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1381. {
  1382. result = (GLushort)
  1383. (DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  1384. gc->modes.allMask);
  1385. }
  1386. if ( cfb->buf.flags & COLORMASK_ON )
  1387. {
  1388. result = (GLushort)((dst_pix & cfb->destMask) |
  1389. (result & cfb->sourceMask));
  1390. }
  1391. }
  1392. *pus = result;
  1393. }
  1394. }
  1395. // Output the offscreen scanline buffer to the device. The function
  1396. // (*gengc->pfnCopyPixels) should handle clipping.
  1397. if (!bDIB)
  1398. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1399. if( ALPHA_BUFFER_WRITE( cfb ) )
  1400. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1401. return GL_FALSE;
  1402. }
  1403. /******************************Public*Routine******************************\
  1404. * BGRStoreSpan
  1405. *
  1406. * Copies the current span in the renderer into a bitmap. If bDIB is TRUE,
  1407. * then the bitmap is the display in DIB format (or a memory DC). If bDIB
  1408. * is FALSE, then the bitmap is an offscreen scanline buffer and it will be
  1409. * output to the buffer by (*gengc->pfnCopyPixels)().
  1410. *
  1411. * This handles GBR 24-bit mode. Blending is supported. There
  1412. * is no dithering.
  1413. *
  1414. * Returns:
  1415. * GL_FALSE always. Soft code ignores return value.
  1416. *
  1417. * History:
  1418. * 10-Jan-1994 -by- Marc Fortier [v-marcf]
  1419. * Wrote it.
  1420. \**************************************************************************/
  1421. //XXX The returnSpan routine follows this routine very closely. Any changes
  1422. //XXX to this routine should also be reflected in the returnSpan routine
  1423. STATIC GLboolean FASTCALL BGRStoreSpan(__GLcontext *gc )
  1424. {
  1425. __GLcolor *cp; // current fragment color
  1426. __GLcolorBuffer *cfb; // color frame buffer
  1427. GLint xScr, yScr; // current screen (pixel) coordinates
  1428. GLubyte *puj; // current pixel ptr
  1429. GLuint *pul; // current pixel ptr
  1430. GLuint result; // current pixel color
  1431. GLubyte *pujEnd; // end of scan line
  1432. GLint w; // span width
  1433. ULONG ulSpanVisibility; // span visibility mode
  1434. GLint cWalls;
  1435. GLint *Walls;
  1436. __GLGENcontext *gengc; // generic graphics context
  1437. GLuint enables; // modes enabled in graphics context
  1438. GLuint flags;
  1439. GLboolean bDIB;
  1440. GLuint dst_pix;
  1441. ASSERT_CHOP_ROUND();
  1442. // Get span position and length.
  1443. w = gc->polygon.shader.length;
  1444. gengc = (__GLGENcontext *)gc;
  1445. cfb = gc->drawBuffer;
  1446. xScr = __GL_UNBIAS_X(gc, gc->polygon.shader.frag.x) + cfb->buf.xOrigin;
  1447. yScr = __GL_UNBIAS_Y(gc, gc->polygon.shader.frag.y) + cfb->buf.yOrigin;
  1448. enables = gc->state.enables.general;
  1449. flags = cfb->buf.flags;
  1450. bDIB = flags & DIB_FORMAT;
  1451. if( !bDIB || (flags & NO_CLIP) )
  1452. {
  1453. // Device managed or unclipped surface
  1454. ulSpanVisibility = WGL_SPAN_ALL;
  1455. }
  1456. else
  1457. {
  1458. // Device in BITMAP format
  1459. ulSpanVisibility = wglSpanVisible(xScr, yScr, w, &cWalls, &Walls);
  1460. }
  1461. // Proceed as long as the span is (partially or fully) visible.
  1462. if (ulSpanVisibility != WGL_SPAN_NONE)
  1463. {
  1464. GLboolean bCheckWalls = GL_FALSE;
  1465. GLboolean bDraw;
  1466. GLint NextWall;
  1467. if (ulSpanVisibility == WGL_SPAN_PARTIAL)
  1468. {
  1469. bCheckWalls = GL_TRUE;
  1470. if (cWalls & 0x01)
  1471. {
  1472. bDraw = GL_TRUE;
  1473. }
  1474. else
  1475. {
  1476. bDraw = GL_FALSE;
  1477. }
  1478. NextWall = *Walls++;
  1479. cWalls--;
  1480. }
  1481. // Get pointers to fragment colors array and frame buffer.
  1482. cp = gc->polygon.shader.colors;
  1483. cfb = gc->polygon.shader.cfb;
  1484. // Get pointer to bitmap.
  1485. puj = bDIB ? (GLubyte *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr*3))
  1486. : gengc->ColorsBits;
  1487. pujEnd = puj + 3*w;
  1488. // Case: no masking, no blending
  1489. //!!!XXX -- do extra opt. for RGB and BGR cases
  1490. //!!!XXX -- we can also opt. by unrolling the loops
  1491. if ( !(cfb->buf.flags & NEED_FETCH) &&
  1492. !(enables & __GL_BLEND_ENABLE) )
  1493. {
  1494. for (; puj < pujEnd; cp++)
  1495. {
  1496. if (bCheckWalls)
  1497. {
  1498. if (xScr++ >= NextWall)
  1499. {
  1500. if (bDraw)
  1501. bDraw = GL_FALSE;
  1502. else
  1503. bDraw = GL_TRUE;
  1504. if (cWalls <= 0)
  1505. {
  1506. NextWall = gc->constants.maxViewportWidth;
  1507. }
  1508. else
  1509. {
  1510. NextWall = *Walls++;
  1511. cWalls--;
  1512. }
  1513. }
  1514. if (bDraw == GL_FALSE) {
  1515. puj += 3;
  1516. continue;
  1517. }
  1518. }
  1519. StoreColorAsBGR(cp, puj);
  1520. }
  1521. }
  1522. // All other cases
  1523. else
  1524. {
  1525. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1526. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  1527. if (enables & __GL_BLEND_ENABLE)
  1528. {
  1529. // this overwrites fragment colors array with blended values
  1530. (*gc->procs.blendSpan)( gc );
  1531. }
  1532. for (; puj < pujEnd; cp++)
  1533. {
  1534. if (bCheckWalls)
  1535. {
  1536. if (xScr++ >= NextWall)
  1537. {
  1538. if (bDraw)
  1539. bDraw = GL_FALSE;
  1540. else
  1541. bDraw = GL_TRUE;
  1542. if (cWalls <= 0)
  1543. {
  1544. NextWall = gc->constants.maxViewportWidth;
  1545. }
  1546. else
  1547. {
  1548. NextWall = *Walls++;
  1549. cWalls--;
  1550. }
  1551. }
  1552. if (bDraw == GL_FALSE) {
  1553. puj += 3;
  1554. continue;
  1555. }
  1556. }
  1557. if (cfb->buf.flags & NEED_FETCH)
  1558. {
  1559. Copy3Bytes(&dst_pix, puj);
  1560. UnditheredRGBColorToBuffer(cp, cfb, result, GLuint);
  1561. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1562. {
  1563. result =
  1564. DoLogicOp(gc->state.raster.logicOp, result,
  1565. dst_pix) & gc->modes.allMask;
  1566. }
  1567. if (cfb->buf.flags & COLORMASK_ON)
  1568. {
  1569. result = (result & cfb->sourceMask) |
  1570. (dst_pix & cfb->destMask);
  1571. }
  1572. Copy3Bytes( puj, &result );
  1573. puj += 3;
  1574. }
  1575. else
  1576. {
  1577. StoreColorAsBGR(cp, puj);
  1578. }
  1579. }
  1580. }
  1581. // Output the offscreen scanline buffer to the device. The function
  1582. // (*gengc->pfnCopyPixels) should handle clipping.
  1583. if (!bDIB)
  1584. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1585. if( ALPHA_WRITE_ENABLED( cfb ) )
  1586. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1587. }
  1588. return GL_FALSE;
  1589. }
  1590. /******************************Public*Routine******************************\
  1591. * Bitfield32StoreSpan
  1592. *
  1593. * Copies the current span in the renderer into a bitmap. If bDIB is TRUE,
  1594. * then the bitmap is the display in DIB format (or a memory DC). If bDIB
  1595. * is FALSE, then the bitmap is an offscreen scanline buffer and it will be
  1596. * output to the buffer by (*gengc->pfnCopyPixels)().
  1597. *
  1598. * This handles general 32-bit BITFIELDS mode. Blending is supported. There
  1599. * is no dithering.
  1600. *
  1601. * Returns:
  1602. * GL_FALSE always. Soft code ignores return value.
  1603. *
  1604. * History:
  1605. * 15-Nov-1993 -by- Gilman Wong [gilmanw]
  1606. * Wrote it.
  1607. \**************************************************************************/
  1608. //XXX The returnSpan routine follows this routine very closely. Any changes
  1609. //XXX to this routine should also be reflected in the returnSpan routine
  1610. STATIC GLboolean FASTCALL
  1611. Bitfield32StoreSpanPartial(__GLcontext *gc, GLboolean bDIB, GLint cWalls, GLint *Walls )
  1612. {
  1613. __GLcolor *cp; // current fragment color
  1614. __GLcolorBuffer *cfb; // color frame buffer
  1615. GLint xScr, yScr; // current screen (pixel) coordinates
  1616. GLuint result, *pul; // current pixel color, current pixel ptr
  1617. GLuint *pulEnd; // end of scan line
  1618. GLint w; // span width
  1619. GLboolean bDraw;
  1620. GLint NextWall;
  1621. __GLGENcontext *gengc; // generic graphics context
  1622. GLuint enables; // modes enabled in graphics context
  1623. GLuint flags;
  1624. GLuint dst_pix;
  1625. // Get span position and length.
  1626. w = gc->polygon.shader.length;
  1627. gengc = (__GLGENcontext *)gc;
  1628. cfb = gc->drawBuffer;
  1629. xScr = __GL_UNBIAS_X(gc, gc->polygon.shader.frag.x) + cfb->buf.xOrigin;
  1630. yScr = __GL_UNBIAS_Y(gc, gc->polygon.shader.frag.y) + cfb->buf.yOrigin;
  1631. enables = gc->state.enables.general;
  1632. flags = cfb->buf.flags;
  1633. if (cWalls & 0x01)
  1634. {
  1635. bDraw = GL_TRUE;
  1636. }
  1637. else
  1638. {
  1639. bDraw = GL_FALSE;
  1640. }
  1641. NextWall = *Walls++;
  1642. cWalls--;
  1643. // Get pointers to fragment colors array and frame buffer.
  1644. cp = gc->polygon.shader.colors;
  1645. cfb = gc->polygon.shader.cfb;
  1646. // Get pointer to bitmap.
  1647. pul = bDIB ? (GLuint *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<2))
  1648. : gengc->ColorsBits;
  1649. pulEnd = pul + w;
  1650. // Case: no masking, no blending
  1651. //!!!XXX -- do extra opt. for RGB and BGR cases
  1652. //!!!XXX -- we can also opt. by unrolling the loops
  1653. if ( !(cfb->buf.flags & NEED_FETCH) &&
  1654. !(enables & __GL_BLEND_ENABLE) )
  1655. {
  1656. for (; pul < pulEnd; pul++, cp++)
  1657. {
  1658. if (xScr++ >= NextWall)
  1659. {
  1660. if (bDraw)
  1661. bDraw = GL_FALSE;
  1662. else
  1663. bDraw = GL_TRUE;
  1664. if (cWalls <= 0)
  1665. {
  1666. NextWall = gc->constants.maxViewportWidth;
  1667. }
  1668. else
  1669. {
  1670. NextWall = *Walls++;
  1671. cWalls--;
  1672. }
  1673. }
  1674. if (bDraw == GL_FALSE)
  1675. continue;
  1676. UnditheredColorToBuffer(cp, cfb, result, GLuint);
  1677. *pul = result;
  1678. }
  1679. }
  1680. // All other cases
  1681. else
  1682. {
  1683. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1684. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  1685. if (enables & __GL_BLEND_ENABLE)
  1686. {
  1687. int i;
  1688. SPECIAL_ALPHA_BLEND_SPAN((dst_pix = *(pul+i)));
  1689. }
  1690. for (; pul < pulEnd; pul++, cp++)
  1691. {
  1692. if (xScr++ >= NextWall)
  1693. {
  1694. if (bDraw)
  1695. bDraw = GL_FALSE;
  1696. else
  1697. bDraw = GL_TRUE;
  1698. if (cWalls <= 0)
  1699. {
  1700. NextWall = gc->constants.maxViewportWidth;
  1701. }
  1702. else
  1703. {
  1704. NextWall = *Walls++;
  1705. cWalls--;
  1706. }
  1707. }
  1708. if (bDraw == GL_FALSE)
  1709. continue;
  1710. UnditheredColorToBuffer(cp, cfb, result, GLuint);
  1711. //!!!XXX again, opt. by unrolling loop
  1712. if (cfb->buf.flags & NEED_FETCH)
  1713. {
  1714. dst_pix = *pul;
  1715. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1716. {
  1717. result =
  1718. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  1719. gc->modes.allMask;
  1720. }
  1721. if (cfb->buf.flags & COLORMASK_ON)
  1722. {
  1723. result = (dst_pix & cfb->destMask) |
  1724. (result & cfb->sourceMask);
  1725. }
  1726. }
  1727. *pul = result;
  1728. }
  1729. }
  1730. // Output the offscreen scanline buffer to the device. The function
  1731. // (*gengc->pfnCopyPixels) should handle clipping.
  1732. if (!bDIB)
  1733. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1734. if( ALPHA_BUFFER_WRITE( cfb ) )
  1735. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1736. return GL_FALSE;
  1737. }
  1738. STATIC GLboolean FASTCALL Bitfield32StoreSpan( __GLcontext *gc )
  1739. {
  1740. __GLcolor *cp; // current fragment color
  1741. __GLcolorBuffer *cfb; // color frame buffer
  1742. GLboolean bDIB;
  1743. GLint xScr, yScr; // current screen (pixel) coordinates
  1744. GLuint result, *pul; // current pixel color, current pixel ptr
  1745. GLuint *pulEnd; // end of scan line
  1746. GLint w; // span width
  1747. ULONG ulSpanVisibility; // span visibility mode
  1748. GLint cWalls;
  1749. GLint *Walls;
  1750. __GLGENcontext *gengc; // generic graphics context
  1751. GLuint enables; // modes enabled in graphics context
  1752. GLuint flags;
  1753. GLuint dst_pix;
  1754. ASSERT_CHOP_ROUND();
  1755. // Get span position and length.
  1756. w = gc->polygon.shader.length;
  1757. gengc = (__GLGENcontext *)gc;
  1758. cfb = gc->drawBuffer;
  1759. xScr = __GL_UNBIAS_X(gc, gc->polygon.shader.frag.x) + cfb->buf.xOrigin;
  1760. yScr = __GL_UNBIAS_Y(gc, gc->polygon.shader.frag.y) + cfb->buf.yOrigin;
  1761. enables = gc->state.enables.general;
  1762. flags = cfb->buf.flags;
  1763. bDIB = flags & DIB_FORMAT;
  1764. // Check span visibility
  1765. if( bDIB && !(flags & NO_CLIP) )
  1766. {
  1767. // Device in BITMAP format
  1768. ULONG ulSpanVisibility; // span visibility mode
  1769. ulSpanVisibility = wglSpanVisible(xScr, yScr, w, &cWalls, &Walls);
  1770. if (ulSpanVisibility == WGL_SPAN_NONE)
  1771. return GL_FALSE;
  1772. else if (ulSpanVisibility == WGL_SPAN_PARTIAL)
  1773. return Bitfield32StoreSpanPartial( gc, bDIB, cWalls, Walls );
  1774. // else span fully visible
  1775. }
  1776. // Get pointers to fragment colors array and frame buffer.
  1777. cp = gc->polygon.shader.colors;
  1778. cfb = gc->polygon.shader.cfb;
  1779. // Get pointer to bitmap.
  1780. pul = bDIB ? (GLuint *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<2))
  1781. : gengc->ColorsBits;
  1782. pulEnd = pul + w;
  1783. // Case: no masking, no blending
  1784. //!!!XXX -- do extra opt. for RGB and BGR cases
  1785. //!!!XXX -- we can also opt. by unrolling the loops
  1786. if ( !(cfb->buf.flags & NEED_FETCH) &&
  1787. !(enables & __GL_BLEND_ENABLE) )
  1788. {
  1789. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  1790. for (; pul < pulEnd; pul++, cp++)
  1791. {
  1792. UnditheredRGBAColorToBuffer(cp, cfb, result, GLuint);
  1793. *pul = result;
  1794. }
  1795. } else {
  1796. for (; pul < pulEnd; pul++, cp++)
  1797. {
  1798. UnditheredRGBColorToBuffer(cp, cfb, result, GLuint);
  1799. *pul = result;
  1800. }
  1801. }
  1802. }
  1803. // All other cases
  1804. else
  1805. {
  1806. if( (!bDIB) && (cfb->buf.flags & NEED_FETCH) )
  1807. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  1808. if (enables & __GL_BLEND_ENABLE)
  1809. {
  1810. int i;
  1811. SPECIAL_ALPHA_BLEND_SPAN((dst_pix = *(pul+i)));
  1812. }
  1813. for (; pul < pulEnd; pul++, cp++)
  1814. {
  1815. UnditheredColorToBuffer(cp, cfb, result, GLuint);
  1816. //!!!XXX again, opt. by unrolling loop
  1817. if (cfb->buf.flags & NEED_FETCH)
  1818. {
  1819. dst_pix = *pul;
  1820. if (enables & __GL_COLOR_LOGIC_OP_ENABLE)
  1821. {
  1822. result =
  1823. DoLogicOp(gc->state.raster.logicOp, result, dst_pix) &
  1824. gc->modes.allMask;
  1825. }
  1826. if (cfb->buf.flags & COLORMASK_ON)
  1827. {
  1828. result = (dst_pix & cfb->destMask) |
  1829. (result & cfb->sourceMask);
  1830. }
  1831. }
  1832. *pul = result;
  1833. }
  1834. }
  1835. // Output the offscreen scanline buffer to the device. The function
  1836. // (*gengc->pfnCopyPixels) should handle clipping.
  1837. if (!bDIB)
  1838. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  1839. if( ALPHA_BUFFER_WRITE( cfb ) )
  1840. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1841. return GL_FALSE;
  1842. }
  1843. STATIC GLboolean FASTCALL AlphaStoreSpan(__GLcontext *gc)
  1844. {
  1845. __GLcolorBuffer *cfb = gc->drawBuffer;
  1846. ASSERT_CHOP_ROUND();
  1847. (*cfb->alphaBuf.storeSpan)( &cfb->alphaBuf );
  1848. return GL_FALSE;
  1849. }
  1850. STATIC GLboolean FASTCALL StoreMaskedSpan(__GLcontext *gc, GLboolean masked)
  1851. {
  1852. #ifdef REWRITE
  1853. GLint x, y, len;
  1854. int i;
  1855. __GLcolor *cp;
  1856. DWORD *pul;
  1857. WORD *pus;
  1858. BYTE *puj;
  1859. __GLGENcontext *gengc = (__GLGENcontext *)gc;
  1860. len = gc->polygon.shader.length;
  1861. x = __GL_UNBIAS_X(gc, gc->polygon.shader.frag.x);
  1862. y = __GL_UNBIAS_Y(gc, gc->polygon.shader.frag.y);
  1863. cp = gc->polygon.shader.colors;
  1864. switch (gengc->iFormatDC)
  1865. {
  1866. case BMF_8BPP:
  1867. break;
  1868. case BMF_16BPP:
  1869. pus = gengc->ColorsBits;
  1870. for (i = 0; i < len; i++) {
  1871. *pus++ = __GL_COLOR_TO_BMF_16BPP(cp);
  1872. cp++;
  1873. }
  1874. break;
  1875. case BMF_24BPP:
  1876. puj = gengc->ColorsBits;
  1877. for (i = 0; i < len; i++) {
  1878. *puj++ = (BYTE)cp->b; // XXX check order
  1879. *puj++ = (BYTE)cp->g;
  1880. *puj++ = (BYTE)cp->r;
  1881. cp++;
  1882. }
  1883. break;
  1884. case BMF_32BPP:
  1885. pul = gengc->ColorsBits;
  1886. for (i = 0; i < len; i++) {
  1887. *pul++ = __GL_COLOR_TO_BMF_32BPP(cp);
  1888. cp++;
  1889. }
  1890. break;
  1891. default:
  1892. break;
  1893. }
  1894. if (masked == GL_TRUE) // XXX mask is BigEndian!!!
  1895. {
  1896. unsigned long *pulstipple;
  1897. unsigned long stip;
  1898. GLint count;
  1899. pul = gengc->StippleBits;
  1900. pulstipple = gc->polygon.shader.stipplePat;
  1901. count = (len+31)/32;
  1902. for (i = 0; i < count; i++) {
  1903. stip = *pulstipple++;
  1904. *pul++ = (stip&0xff)<<24 | (stip&0xff00)<<8 | (stip&0xff0000)>>8 |
  1905. (stip&0xff000000)>>24;
  1906. }
  1907. wglSpanBlt(CURRENT_DC, gengc->ColorsBitmap, gengc->StippleBitmap,
  1908. x, y, len);
  1909. }
  1910. else
  1911. {
  1912. wglSpanBlt(CURRENT_DC, gengc->ColorsBitmap, (HBITMAP)NULL,
  1913. x, y, len);
  1914. }
  1915. #endif
  1916. return GL_FALSE;
  1917. }
  1918. #ifdef TESTSTIPPLE
  1919. STATIC void FASTCALL MessUpStippledSpan(__GLcontext *gc)
  1920. {
  1921. __GLcolor *cp;
  1922. __GLcolorBuffer *cfb;
  1923. __GLstippleWord inMask, bit, *sp;
  1924. GLint count;
  1925. GLint w;
  1926. w = gc->polygon.shader.length;
  1927. sp = gc->polygon.shader.stipplePat;
  1928. cp = gc->polygon.shader.colors;
  1929. cfb = gc->polygon.shader.cfb;
  1930. while (w) {
  1931. count = w;
  1932. if (count > __GL_STIPPLE_BITS) {
  1933. count = __GL_STIPPLE_BITS;
  1934. }
  1935. w -= count;
  1936. inMask = *sp++;
  1937. bit = __GL_STIPPLE_SHIFT(0);
  1938. while (--count >= 0) {
  1939. if (!(inMask & bit)) {
  1940. cp->r = cfb->redMax;
  1941. cp->g = cfb->greenMax;
  1942. cp->b = cfb->blueMax;
  1943. }
  1944. cp++;
  1945. #ifdef __GL_STIPPLE_MSB
  1946. bit >>= 1;
  1947. #else
  1948. bit <<= 1;
  1949. #endif
  1950. }
  1951. }
  1952. }
  1953. #endif
  1954. // From the PIXMAP code, calls store for each fragment
  1955. STATIC GLboolean FASTCALL SlowStoreSpan(__GLcontext *gc)
  1956. {
  1957. int x, x1;
  1958. int i;
  1959. __GLfragment frag;
  1960. __GLcolor *cp;
  1961. __GLcolorBuffer *cfb;
  1962. GLint w;
  1963. w = gc->polygon.shader.length;
  1964. frag.y = gc->polygon.shader.frag.y;
  1965. x = gc->polygon.shader.frag.x;
  1966. x1 = gc->polygon.shader.frag.x + w;
  1967. cp = gc->polygon.shader.colors;
  1968. cfb = gc->polygon.shader.cfb;
  1969. for (i = x; i < x1; i++) {
  1970. frag.x = i;
  1971. frag.color = *cp++;
  1972. (*cfb->store)(cfb, &frag);
  1973. }
  1974. return GL_FALSE;
  1975. }
  1976. // From the PIXMAP code, calls store for each fragment with mask test
  1977. STATIC GLboolean FASTCALL SlowStoreStippledSpan(__GLcontext *gc)
  1978. {
  1979. int x;
  1980. __GLfragment frag;
  1981. __GLcolor *cp;
  1982. __GLcolorBuffer *cfb;
  1983. __GLstippleWord inMask, bit, *sp;
  1984. GLint count;
  1985. GLint w;
  1986. w = gc->polygon.shader.length;
  1987. sp = gc->polygon.shader.stipplePat;
  1988. frag.y = gc->polygon.shader.frag.y;
  1989. x = gc->polygon.shader.frag.x;
  1990. cp = gc->polygon.shader.colors;
  1991. cfb = gc->polygon.shader.cfb;
  1992. while (w) {
  1993. count = w;
  1994. if (count > __GL_STIPPLE_BITS) {
  1995. count = __GL_STIPPLE_BITS;
  1996. }
  1997. w -= count;
  1998. inMask = *sp++;
  1999. bit = __GL_STIPPLE_SHIFT((__GLstippleWord)0);
  2000. while (--count >= 0) {
  2001. if (inMask & bit) {
  2002. frag.x = x;
  2003. frag.color = *cp;
  2004. (*cfb->store)(cfb, &frag);
  2005. }
  2006. x++;
  2007. cp++;
  2008. #ifdef __GL_STIPPLE_MSB
  2009. bit >>= 1;
  2010. #else
  2011. bit <<= 1;
  2012. #endif
  2013. }
  2014. }
  2015. return GL_FALSE;
  2016. }
  2017. //
  2018. // Tables to convert 4-bit index to RGB component
  2019. // These tables assume the VGA fixed palette
  2020. // History:
  2021. // 22-NOV-93 Eddie Robinson [v-eddier] Wrote it.
  2022. //
  2023. #ifdef __GL_DOUBLE
  2024. static __GLfloat vfVGAtoR[16] = {
  2025. 0.0, // black
  2026. 0.5, // dim red
  2027. 0.0, // dim green
  2028. 0.5, // dim yellow
  2029. 0.0, // dim blue
  2030. 0.5, // dim magenta
  2031. 0.0, // dim cyan
  2032. 0.5, // dim grey
  2033. 0.75, // medium grey
  2034. 1.0, // bright red
  2035. 0.0, // bright green
  2036. 1.0, // bright yellow
  2037. 0.0, // bright blue
  2038. 1.0, // bright magenta
  2039. 0.0, // bright cyan
  2040. 1.0 // white
  2041. };
  2042. static __GLfloat vfVGAtoG[16] = {
  2043. 0.0, // black
  2044. 0.0, // dim red
  2045. 0.5, // dim green
  2046. 0.5, // dim yellow
  2047. 0.0, // dim blue
  2048. 0.0, // dim magenta
  2049. 0.5, // dim cyan
  2050. 0.5, // dim grey
  2051. 0.75, // medium grey
  2052. 0.0, // bright red
  2053. 1.0, // bright green
  2054. 1.0, // bright yellow
  2055. 0.0, // bright blue
  2056. 0.0, // bright magenta
  2057. 1.0, // bright cyan
  2058. 1.0 // white
  2059. };
  2060. static __GLfloat vfVGAtoB[16] = {
  2061. 0.0, // black
  2062. 0.0, // dim red
  2063. 0.0, // dim green
  2064. 0.0, // dim yellow
  2065. 0.5, // dim blue
  2066. 0.5, // dim magenta
  2067. 0.5, // dim cyan
  2068. 0.5, // dim grey
  2069. 0.75, // medium grey
  2070. 0.0, // bright red
  2071. 0.0, // bright green
  2072. 0.0, // bright yellow
  2073. 1.0, // bright blue
  2074. 1.0, // bright magenta
  2075. 1.0, // bright cyan
  2076. 1.0 // white
  2077. };
  2078. #else
  2079. static __GLfloat vfVGAtoR[16] = {
  2080. 0.0F, // black
  2081. 0.5F, // dim red
  2082. 0.0F, // dim green
  2083. 0.5F, // dim yellow
  2084. 0.0F, // dim blue
  2085. 0.5F, // dim magenta
  2086. 0.0F, // dim cyan
  2087. 0.5F, // dim grey
  2088. 0.75F, // medium grey
  2089. 1.0F, // bright red
  2090. 0.0F, // bright green
  2091. 1.0F, // bright yellow
  2092. 0.0F, // bright blue
  2093. 1.0F, // bright magenta
  2094. 0.0F, // bright cyan
  2095. 1.0F // white
  2096. };
  2097. static __GLfloat vfVGAtoG[16] = {
  2098. 0.0F, // black
  2099. 0.0F, // dim red
  2100. 0.5F, // dim green
  2101. 0.5F, // dim yellow
  2102. 0.0F, // dim blue
  2103. 0.0F, // dim magenta
  2104. 0.5F, // dim cyan
  2105. 0.5F, // dim grey
  2106. 0.75F, // medium grey
  2107. 0.0F, // bright red
  2108. 1.0F, // bright green
  2109. 1.0F, // bright yellow
  2110. 0.0F, // bright blue
  2111. 0.0F, // bright magenta
  2112. 1.0F, // bright cyan
  2113. 1.0F // white
  2114. };
  2115. static __GLfloat vfVGAtoB[16] = {
  2116. 0.0F, // black
  2117. 0.0F, // dim red
  2118. 0.0F, // dim green
  2119. 0.0F, // dim yellow
  2120. 0.5F, // dim blue
  2121. 0.5F, // dim magenta
  2122. 0.5F, // dim cyan
  2123. 0.5F, // dim grey
  2124. 0.75F, // medium grey
  2125. 0.0F, // bright red
  2126. 0.0F, // bright green
  2127. 0.0F, // bright yellow
  2128. 1.0F, // bright blue
  2129. 1.0F, // bright magenta
  2130. 1.0F, // bright cyan
  2131. 1.0F // white
  2132. };
  2133. #endif
  2134. void
  2135. RGBFetchNone(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2136. {
  2137. result->r = 0.0F;
  2138. result->g = 0.0F;
  2139. result->b = 0.0F;
  2140. if( cfb->buf.gc->modes.alphaBits )
  2141. result->a = 0.0F;
  2142. else
  2143. result->a = cfb->alphaScale;
  2144. }
  2145. void
  2146. RGBReadSpanNone(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  2147. GLint w)
  2148. {
  2149. GLint i;
  2150. __GLcolor *pResults;
  2151. __GLfloat alphaVal;
  2152. if( cfb->buf.gc->modes.alphaBits )
  2153. alphaVal = 0.0F;
  2154. else
  2155. alphaVal = cfb->alphaScale;
  2156. for (i = 0, pResults = results; i < w; i++, pResults++)
  2157. {
  2158. pResults->r = 0.0F;
  2159. pResults->g = 0.0F;
  2160. pResults->b = 0.0F;
  2161. pResults->a = alphaVal;
  2162. }
  2163. }
  2164. void
  2165. DIBIndex4RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2166. {
  2167. __GLcontext *gc = cfb->buf.gc;
  2168. __GLGENcontext *gengc;
  2169. GLubyte *puj, pixel;
  2170. // Do alpha first, before x,y unbiased
  2171. if( gc->modes.alphaBits ) {
  2172. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2173. } else
  2174. result->a = cfb->alphaScale;
  2175. gengc = (__GLGENcontext *)gc;
  2176. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2177. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2178. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2179. (y*cfb->buf.outerWidth) + (x >> 1));
  2180. pixel = *puj;
  2181. if (!(x & 1))
  2182. pixel >>= 4;
  2183. pixel = gengc->pajInvTranslateVector[pixel&0xf];
  2184. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2185. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2186. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2187. }
  2188. void
  2189. DIBIndex8RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2190. {
  2191. __GLcontext *gc = cfb->buf.gc;
  2192. __GLGENcontext *gengc;
  2193. GLubyte *puj, pixel;
  2194. gengc = (__GLGENcontext *)gc;
  2195. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2196. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2197. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  2198. pixel = gengc->pajInvTranslateVector[*puj];
  2199. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2200. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2201. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2202. result->a = cfb->alphaScale;
  2203. }
  2204. void
  2205. DIBIndex8RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2206. {
  2207. __GLcontext *gc = cfb->buf.gc;
  2208. __GLGENcontext *gengc;
  2209. GLubyte *puj, pixel;
  2210. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2211. gengc = (__GLGENcontext *)gc;
  2212. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2213. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2214. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  2215. pixel = gengc->pajInvTranslateVector[*puj];
  2216. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2217. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2218. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2219. }
  2220. void
  2221. DIBBGRFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2222. {
  2223. __GLcontext *gc = cfb->buf.gc;
  2224. __GLGENcontext *gengc;
  2225. GLubyte *puj;
  2226. gengc = (__GLGENcontext *)gc;
  2227. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2228. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2229. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2230. (y*cfb->buf.outerWidth) + (x * 3));
  2231. result->b = (__GLfloat) *puj++;
  2232. result->g = (__GLfloat) *puj++;
  2233. result->r = (__GLfloat) *puj;
  2234. result->a = cfb->alphaScale;
  2235. }
  2236. void
  2237. DIBBGRAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2238. {
  2239. __GLcontext *gc = cfb->buf.gc;
  2240. __GLGENcontext *gengc;
  2241. GLubyte *puj;
  2242. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2243. gengc = (__GLGENcontext *)gc;
  2244. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2245. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2246. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2247. (y*cfb->buf.outerWidth) + (x * 3));
  2248. result->b = (__GLfloat) *puj++;
  2249. result->g = (__GLfloat) *puj++;
  2250. result->r = (__GLfloat) *puj;
  2251. }
  2252. void
  2253. DIBRGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2254. {
  2255. __GLcontext *gc = cfb->buf.gc;
  2256. __GLGENcontext *gengc;
  2257. GLubyte *puj;
  2258. gengc = (__GLGENcontext *)gc;
  2259. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2260. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2261. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2262. (y*cfb->buf.outerWidth) + (x * 3));
  2263. result->r = (__GLfloat) *puj++;
  2264. result->g = (__GLfloat) *puj++;
  2265. result->b = (__GLfloat) *puj;
  2266. result->a = cfb->alphaScale;
  2267. }
  2268. void
  2269. DIBRGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2270. {
  2271. __GLcontext *gc = cfb->buf.gc;
  2272. __GLGENcontext *gengc;
  2273. GLubyte *puj;
  2274. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2275. gengc = (__GLGENcontext *)gc;
  2276. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2277. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2278. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2279. (y*cfb->buf.outerWidth) + (x * 3));
  2280. result->r = (__GLfloat) *puj++;
  2281. result->g = (__GLfloat) *puj++;
  2282. result->b = (__GLfloat) *puj;
  2283. }
  2284. void
  2285. DIBBitfield16RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2286. {
  2287. __GLcontext *gc = cfb->buf.gc;
  2288. __GLGENcontext *gengc;
  2289. GLushort *pus, pixel;
  2290. gengc = (__GLGENcontext *)gc;
  2291. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2292. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2293. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  2294. (y*cfb->buf.outerWidth) + (x << 1));
  2295. pixel = *pus;
  2296. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2297. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2298. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2299. result->a = cfb->alphaScale;
  2300. }
  2301. void
  2302. DIBBitfield16RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2303. {
  2304. __GLcontext *gc = cfb->buf.gc;
  2305. __GLGENcontext *gengc;
  2306. GLushort *pus, pixel;
  2307. GLint xScr, yScr; // current screen (pixel) coordinates
  2308. gengc = (__GLGENcontext *)gc;
  2309. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2310. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2311. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  2312. (yScr*cfb->buf.outerWidth) + (xScr << 1));
  2313. pixel = *pus;
  2314. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2315. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2316. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2317. if( ALPHA_IN_PIXEL( cfb ) )
  2318. result->a = (__GLfloat) ((pixel & gc->modes.alphaMask) >> cfb->alphaShift);
  2319. else
  2320. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2321. }
  2322. void
  2323. DIBBitfield32RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2324. {
  2325. __GLcontext *gc = cfb->buf.gc;
  2326. __GLGENcontext *gengc;
  2327. GLuint *pul, pixel;
  2328. gengc = (__GLGENcontext *)gc;
  2329. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2330. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2331. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  2332. (y*cfb->buf.outerWidth) + (x << 2));
  2333. pixel = *pul;
  2334. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2335. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2336. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2337. result->a = cfb->alphaScale;
  2338. }
  2339. void
  2340. DIBBitfield32RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2341. {
  2342. __GLcontext *gc = cfb->buf.gc;
  2343. __GLGENcontext *gengc;
  2344. GLuint *pul, pixel;
  2345. GLint xScr, yScr;
  2346. gengc = (__GLGENcontext *)gc;
  2347. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2348. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2349. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  2350. (yScr*cfb->buf.outerWidth) + (xScr << 2));
  2351. pixel = *pul;
  2352. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2353. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2354. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2355. if( ALPHA_IN_PIXEL( cfb ) )
  2356. result->a = (__GLfloat) ((pixel & gc->modes.alphaMask) >> cfb->alphaShift);
  2357. else
  2358. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2359. }
  2360. void
  2361. DisplayIndex4RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2362. {
  2363. __GLcontext *gc = cfb->buf.gc;
  2364. __GLGENcontext *gengc;
  2365. GLubyte *puj, pixel;
  2366. if( gc->modes.alphaBits ) {
  2367. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2368. } else
  2369. result->a = cfb->alphaScale;
  2370. gengc = (__GLGENcontext *)gc;
  2371. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2372. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2373. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2374. puj = gengc->ColorsBits;
  2375. pixel = *puj >> 4;
  2376. result->r = vfVGAtoR[pixel];
  2377. result->g = vfVGAtoG[pixel];
  2378. result->b = vfVGAtoB[pixel];
  2379. }
  2380. void
  2381. DisplayIndex8RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2382. {
  2383. __GLcontext *gc = cfb->buf.gc;
  2384. __GLGENcontext *gengc;
  2385. GLubyte *puj, pixel;
  2386. gengc = (__GLGENcontext *)gc;
  2387. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2388. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2389. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2390. puj = gengc->ColorsBits;
  2391. pixel = gengc->pajInvTranslateVector[*puj];
  2392. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2393. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2394. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2395. result->a = cfb->alphaScale;
  2396. }
  2397. void
  2398. DisplayIndex8RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2399. {
  2400. __GLcontext *gc = cfb->buf.gc;
  2401. __GLGENcontext *gengc;
  2402. GLubyte *puj, pixel;
  2403. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2404. gengc = (__GLGENcontext *)gc;
  2405. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2406. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2407. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2408. puj = gengc->ColorsBits;
  2409. pixel = gengc->pajInvTranslateVector[*puj];
  2410. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2411. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2412. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2413. }
  2414. void
  2415. DisplayBGRFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2416. {
  2417. __GLcontext *gc = cfb->buf.gc;
  2418. __GLGENcontext *gengc;
  2419. GLubyte *puj;
  2420. gengc = (__GLGENcontext *)gc;
  2421. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2422. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2423. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2424. puj = gengc->ColorsBits;
  2425. result->b = (__GLfloat) *puj++;
  2426. result->g = (__GLfloat) *puj++;
  2427. result->r = (__GLfloat) *puj;
  2428. result->a = cfb->alphaScale;
  2429. }
  2430. void
  2431. DisplayBGRAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2432. {
  2433. __GLcontext *gc = cfb->buf.gc;
  2434. __GLGENcontext *gengc;
  2435. GLubyte *puj;
  2436. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2437. gengc = (__GLGENcontext *)gc;
  2438. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2439. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2440. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2441. puj = gengc->ColorsBits;
  2442. result->b = (__GLfloat) *puj++;
  2443. result->g = (__GLfloat) *puj++;
  2444. result->r = (__GLfloat) *puj;
  2445. }
  2446. void
  2447. DisplayRGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2448. {
  2449. __GLcontext *gc = cfb->buf.gc;
  2450. __GLGENcontext *gengc;
  2451. GLubyte *puj;
  2452. gengc = (__GLGENcontext *)gc;
  2453. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2454. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2455. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2456. puj = gengc->ColorsBits;
  2457. result->r = (__GLfloat) *puj++;
  2458. result->g = (__GLfloat) *puj++;
  2459. result->b = (__GLfloat) *puj;
  2460. result->a = cfb->alphaScale;
  2461. }
  2462. void
  2463. DisplayRGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  2464. {
  2465. __GLcontext *gc = cfb->buf.gc;
  2466. __GLGENcontext *gengc;
  2467. GLubyte *puj;
  2468. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2469. gengc = (__GLGENcontext *)gc;
  2470. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2471. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2472. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2473. puj = gengc->ColorsBits;
  2474. result->r = (__GLfloat) *puj++;
  2475. result->g = (__GLfloat) *puj++;
  2476. result->b = (__GLfloat) *puj;
  2477. }
  2478. void
  2479. DisplayBitfield16RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  2480. __GLcolor *result)
  2481. {
  2482. __GLcontext *gc = cfb->buf.gc;
  2483. __GLGENcontext *gengc;
  2484. GLushort *pus, pixel;
  2485. gengc = (__GLGENcontext *)gc;
  2486. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2487. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2488. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2489. pus = gengc->ColorsBits;
  2490. pixel = *pus;
  2491. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2492. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2493. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2494. result->a = cfb->alphaScale;
  2495. }
  2496. void
  2497. DisplayBitfield16RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  2498. __GLcolor *result)
  2499. {
  2500. __GLcontext *gc = cfb->buf.gc;
  2501. __GLGENcontext *gengc;
  2502. GLushort *pus, pixel;
  2503. GLint xScr, yScr; // current screen (pixel) coordinates
  2504. gengc = (__GLGENcontext *)gc;
  2505. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2506. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2507. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2508. pus = gengc->ColorsBits;
  2509. pixel = *pus;
  2510. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2511. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2512. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2513. if( ALPHA_IN_PIXEL( cfb ) )
  2514. result->a = (__GLfloat) ((pixel & gc->modes.alphaMask) >> cfb->alphaShift);
  2515. else
  2516. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2517. }
  2518. void
  2519. DisplayBitfield32RGBFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  2520. __GLcolor *result)
  2521. {
  2522. __GLcontext *gc = cfb->buf.gc;
  2523. __GLGENcontext *gengc;
  2524. GLuint *pul, pixel;
  2525. gengc = (__GLGENcontext *)gc;
  2526. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2527. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2528. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  2529. pul = gengc->ColorsBits;
  2530. pixel = *pul;
  2531. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2532. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2533. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2534. result->a = cfb->alphaScale;
  2535. }
  2536. void
  2537. DisplayBitfield32RGBAFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  2538. __GLcolor *result)
  2539. {
  2540. __GLcontext *gc = cfb->buf.gc;
  2541. __GLGENcontext *gengc;
  2542. GLuint *pul, pixel;
  2543. GLint xScr, yScr;
  2544. gengc = (__GLGENcontext *)gc;
  2545. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2546. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2547. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, 1, FALSE);
  2548. pul = gengc->ColorsBits;
  2549. pixel = *pul;
  2550. result->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2551. result->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2552. result->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2553. if( ALPHA_IN_PIXEL( cfb ) )
  2554. result->a = (__GLfloat) ((pixel & gc->modes.alphaMask) >> cfb->alphaShift);
  2555. else
  2556. (*cfb->alphaBuf.fetch)(&cfb->alphaBuf, x, y, result);
  2557. }
  2558. static void
  2559. ReadAlphaSpan( __GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *pResults,
  2560. GLint w )
  2561. {
  2562. __GLcontext *gc = cfb->buf.gc;
  2563. if( gc->modes.alphaBits )
  2564. (*cfb->alphaBuf.readSpan)(&cfb->alphaBuf, x, y, w, pResults);
  2565. else {
  2566. for( ; w ; w--, pResults++ )
  2567. pResults->a = cfb->alphaScale;
  2568. }
  2569. }
  2570. void
  2571. DIBIndex4RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  2572. GLint w)
  2573. {
  2574. __GLcontext *gc = cfb->buf.gc;
  2575. __GLGENcontext *gengc;
  2576. GLubyte *puj, pixel;
  2577. __GLcolor *pResults;
  2578. ReadAlphaSpan( cfb, x, y, results, w );
  2579. gengc = (__GLGENcontext *)gc;
  2580. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2581. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2582. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) +
  2583. (x >> 1));
  2584. pResults = results;
  2585. if (x & 1)
  2586. {
  2587. pixel = *puj++;
  2588. pixel = gengc->pajInvTranslateVector[pixel & 0xf];
  2589. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2590. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2591. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2592. pResults++;
  2593. w--;
  2594. }
  2595. while (w > 1)
  2596. {
  2597. pixel = *puj >> 4;
  2598. pixel = gengc->pajInvTranslateVector[pixel];
  2599. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2600. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2601. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2602. pResults++;
  2603. pixel = *puj++;
  2604. pixel = gengc->pajInvTranslateVector[pixel & 0xf];
  2605. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2606. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2607. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2608. pResults++;
  2609. w -= 2;
  2610. }
  2611. if (w > 0)
  2612. {
  2613. pixel = *puj >> 4;
  2614. pixel = gengc->pajInvTranslateVector[pixel];
  2615. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2616. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2617. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2618. }
  2619. }
  2620. void
  2621. DisplayIndex4RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  2622. __GLcolor *results, GLint w)
  2623. {
  2624. __GLcontext *gc = cfb->buf.gc;
  2625. __GLGENcontext *gengc;
  2626. GLubyte *puj, pixel;
  2627. __GLcolor *pResults;
  2628. ReadAlphaSpan( cfb, x, y, results, w );
  2629. gengc = (__GLGENcontext *)gc;
  2630. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2631. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2632. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  2633. puj = gengc->ColorsBits;
  2634. pResults = results;
  2635. while (w > 1)
  2636. {
  2637. pixel = *puj >> 4;
  2638. pResults->r = vfVGAtoR[pixel];
  2639. pResults->g = vfVGAtoG[pixel];
  2640. pResults->b = vfVGAtoB[pixel];
  2641. pResults++;
  2642. pixel = *puj++ & 0xf;
  2643. pResults->r = vfVGAtoR[pixel];
  2644. pResults->g = vfVGAtoG[pixel];
  2645. pResults->b = vfVGAtoB[pixel];
  2646. pResults++;
  2647. w -= 2;
  2648. }
  2649. if (w > 0)
  2650. {
  2651. pixel = *puj >> 4;
  2652. pResults->r = vfVGAtoR[pixel];
  2653. pResults->g = vfVGAtoG[pixel];
  2654. pResults->b = vfVGAtoB[pixel];
  2655. }
  2656. }
  2657. void
  2658. Index8RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *pResults,
  2659. GLint w )
  2660. {
  2661. __GLcontext *gc = cfb->buf.gc;
  2662. __GLGENcontext *gengc;
  2663. GLubyte *puj, pixel;
  2664. ReadAlphaSpan( cfb, x, y, pResults, w );
  2665. gengc = (__GLGENcontext *)gc;
  2666. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2667. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2668. if( cfb->buf.flags & DIB_FORMAT )
  2669. {
  2670. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  2671. }
  2672. else
  2673. {
  2674. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  2675. puj = gengc->ColorsBits;
  2676. }
  2677. for ( ; w; w--, pResults++)
  2678. {
  2679. pixel = gengc->pajInvTranslateVector[*puj++];
  2680. pResults->r = (__GLfloat) ((pixel & gc->modes.redMask) >> cfb->redShift);
  2681. pResults->g = (__GLfloat) ((pixel & gc->modes.greenMask) >> cfb->greenShift);
  2682. pResults->b = (__GLfloat) ((pixel & gc->modes.blueMask) >> cfb->blueShift);
  2683. }
  2684. }
  2685. void
  2686. BGRAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *pResults, GLint w )
  2687. {
  2688. __GLcontext *gc = cfb->buf.gc;
  2689. __GLGENcontext *gengc;
  2690. GLubyte *puj;
  2691. ReadAlphaSpan( cfb, x, y, pResults, w );
  2692. gengc = (__GLGENcontext *)gc;
  2693. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2694. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2695. if( cfb->buf.flags & DIB_FORMAT )
  2696. {
  2697. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2698. (y*cfb->buf.outerWidth) + (x * 3));
  2699. }
  2700. else
  2701. {
  2702. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  2703. puj = gengc->ColorsBits;
  2704. }
  2705. for ( ; w; w--, pResults++)
  2706. {
  2707. pResults->b = (__GLfloat) *puj++;
  2708. pResults->g = (__GLfloat) *puj++;
  2709. pResults->r = (__GLfloat) *puj++;
  2710. }
  2711. }
  2712. void
  2713. RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *pResults, GLint w )
  2714. {
  2715. __GLcontext *gc = cfb->buf.gc;
  2716. __GLGENcontext *gengc;
  2717. GLubyte *puj;
  2718. ReadAlphaSpan( cfb, x, y, pResults, w );
  2719. gengc = (__GLGENcontext *)gc;
  2720. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2721. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2722. if( cfb->buf.flags & DIB_FORMAT )
  2723. {
  2724. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  2725. (y*cfb->buf.outerWidth) + (x * 3));
  2726. }
  2727. else
  2728. {
  2729. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  2730. puj = gengc->ColorsBits;
  2731. }
  2732. for ( ; w; w--, pResults++)
  2733. {
  2734. pResults->r = (__GLfloat) *puj++;
  2735. pResults->g = (__GLfloat) *puj++;
  2736. pResults->b = (__GLfloat) *puj++;
  2737. }
  2738. }
  2739. void
  2740. Bitfield16RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  2741. __GLcolor *pResults, GLint w )
  2742. {
  2743. __GLcontext *gc = cfb->buf.gc;
  2744. __GLGENcontext *gengc;
  2745. GLushort *pus, pixel;
  2746. GLint xScr, yScr;
  2747. gengc = (__GLGENcontext *)gc;
  2748. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2749. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2750. if( cfb->buf.flags & DIB_FORMAT )
  2751. {
  2752. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  2753. (yScr*cfb->buf.outerWidth) + (xScr << 1));
  2754. }
  2755. else
  2756. {
  2757. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  2758. pus = gengc->ColorsBits;
  2759. }
  2760. READ_RGBA_BITFIELD_SPAN( (pixel = *pus++) );
  2761. }
  2762. void
  2763. Bitfield32RGBAReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  2764. __GLcolor *pResults, GLint w )
  2765. {
  2766. __GLcontext *gc = cfb->buf.gc;
  2767. __GLGENcontext *gengc;
  2768. GLuint *pul, pixel;
  2769. GLint xScr, yScr;
  2770. gengc = (__GLGENcontext *)gc;
  2771. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2772. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2773. if( cfb->buf.flags & DIB_FORMAT )
  2774. {
  2775. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  2776. (yScr*cfb->buf.outerWidth) + (xScr << 2));
  2777. }
  2778. else
  2779. {
  2780. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  2781. pul = gengc->ColorsBits;
  2782. }
  2783. READ_RGBA_BITFIELD_SPAN( (pixel = *pul++) );
  2784. }
  2785. /************************************************************************/
  2786. // Used in accumulation
  2787. // Accumulation helper macros and functions
  2788. // Clamp a color component between 0 and max
  2789. #define ACCUM_CLAMP_COLOR_COMPONENT( col, max ) \
  2790. if ((col) < (__GLfloat) 0.0) \
  2791. (col) = (__GLfloat) 0.0; \
  2792. else if ((col) > max ) \
  2793. (col) = max;
  2794. // Extract an accumulation buffer color component by shifting and masking, then
  2795. // multiply it by scale (Requires ap and icol defined).
  2796. #define ACCUM_SCALE_SIGNED_COLOR_COMPONENT( col, shift, sign, mask, scale ) \
  2797. icol = (*ap >> shift) & mask; \
  2798. if (icol & sign) \
  2799. icol |= ~mask; \
  2800. (col) = (icol * scale);
  2801. // Fetch and scale a span of rgba values from a 32-bit accumulation buffer
  2802. void GetClampedRGBAccum32Values(
  2803. __GLcolorBuffer *cfb, GLuint *pac, __GLcolor *cDest, GLint width,
  2804. __GLfloat scale )
  2805. {
  2806. GLint w, i;
  2807. GLint icol;
  2808. __GLfloat rval, gval, bval, aval;
  2809. __GLuicolor *shift, *mask, *sign;
  2810. GLuint *ap;
  2811. __GLcolor *cp;
  2812. __GLcontext *gc = cfb->buf.gc;
  2813. __GLaccumBuffer *afb = &gc->accumBuffer;
  2814. rval = scale * afb->oneOverRedScale;
  2815. gval = scale * afb->oneOverGreenScale;
  2816. bval = scale * afb->oneOverBlueScale;
  2817. shift = &afb->shift;
  2818. mask = &afb->mask;
  2819. sign = &afb->sign;
  2820. for ( w = width, cp = cDest, ap = pac; w; w--, cp++, ap++ ) {
  2821. ACCUM_SCALE_SIGNED_COLOR_COMPONENT( cp->r, shift->r, sign->r, mask->r, rval );
  2822. ACCUM_CLAMP_COLOR_COMPONENT( cp->r, cfb->redScale );
  2823. ACCUM_SCALE_SIGNED_COLOR_COMPONENT( cp->g, shift->g, sign->g, mask->g, gval );
  2824. ACCUM_CLAMP_COLOR_COMPONENT( cp->g, cfb->greenScale );
  2825. ACCUM_SCALE_SIGNED_COLOR_COMPONENT( cp->b, shift->b, sign->b, mask->b, bval );
  2826. ACCUM_CLAMP_COLOR_COMPONENT( cp->b, cfb->blueScale );
  2827. }
  2828. if( ! ALPHA_WRITE_ENABLED( cfb ) )
  2829. return;
  2830. aval = scale * afb->oneOverAlphaScale;
  2831. for ( w = width, cp = cDest, ap = pac; w; w--, cp++, ap++ ) {
  2832. ACCUM_SCALE_SIGNED_COLOR_COMPONENT( cp->a, shift->a, sign->a, mask->a, aval );
  2833. ACCUM_CLAMP_COLOR_COMPONENT( cp->a, cfb->alphaScale );
  2834. }
  2835. }
  2836. // Fetch and scale a span of rgba values from a 64-bit accumulation buffer
  2837. void GetClampedRGBAccum64Values(
  2838. __GLcolorBuffer *cfb, GLshort *pac, __GLcolor *cDest, GLint width,
  2839. __GLfloat scale )
  2840. {
  2841. GLint w;
  2842. __GLcontext *gc = cfb->buf.gc;
  2843. __GLaccumBuffer *afb = &gc->accumBuffer;
  2844. __GLfloat rval, gval, bval, aval;
  2845. __GLcolor *cp;
  2846. GLshort *ap;
  2847. rval = scale * afb->oneOverRedScale;
  2848. gval = scale * afb->oneOverGreenScale;
  2849. bval = scale * afb->oneOverBlueScale;
  2850. for ( w = width, cp = cDest, ap = pac; w; w--, cp++, ap+=4 ) {
  2851. cp->r = (ap[0] * rval);
  2852. ACCUM_CLAMP_COLOR_COMPONENT( cp->r, cfb->redScale );
  2853. cp->g = (ap[1] * gval);
  2854. ACCUM_CLAMP_COLOR_COMPONENT( cp->g, cfb->greenScale );
  2855. cp->b = (ap[2] * bval);
  2856. ACCUM_CLAMP_COLOR_COMPONENT( cp->b, cfb->blueScale );
  2857. }
  2858. if( ! ALPHA_WRITE_ENABLED( cfb ) )
  2859. return;
  2860. aval = scale * afb->oneOverAlphaScale;
  2861. // Offset the accumulation pointer to the alpha value:
  2862. ap = pac + 3;
  2863. for ( w = width, cp = cDest; w; w--, cp++, ap+=4 ) {
  2864. cp->a = (*ap * rval);
  2865. ACCUM_CLAMP_COLOR_COMPONENT( cp->a, cfb->alphaScale );
  2866. }
  2867. }
  2868. /******************************Public*Routine******************************\
  2869. * Index4ReturnSpan
  2870. * Reads from a 16-bit accumulation buffer and writes the span to a device or
  2871. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  2872. * Since accumulation of 4-bit RGB isn't very useful, this routine is very
  2873. * general and calls through the store function pointers.
  2874. *
  2875. * History:
  2876. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  2877. \**************************************************************************/
  2878. //XXX This routine follows the store span routine very closely. Any changes
  2879. //XXX to the store span routine should also be reflected here
  2880. void Index4ReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  2881. const __GLaccumCell *ac, __GLfloat scale, GLint w)
  2882. {
  2883. __GLcontext *gc = cfb->buf.gc;
  2884. GLuint *ap; // current accum entry
  2885. __GLGENcontext *gengc; // generic graphics context
  2886. GLuint saveEnables; // modes enabled in graphics context
  2887. __GLaccumBuffer *afb;
  2888. __GLfragment frag;
  2889. __GLcolor *pAccumCol, *pac;
  2890. afb = &gc->accumBuffer;
  2891. ap = (GLuint *)ac;
  2892. saveEnables = gc->state.enables.general; // save current enables
  2893. gc->state.enables.general &= ~__GL_BLEND_ENABLE; // disable blend for store procs
  2894. frag.x = x;
  2895. frag.y = y;
  2896. // Pre-fetch/clamp/scale the accum buffer values
  2897. afb = &gc->accumBuffer;
  2898. pAccumCol = afb->colors;
  2899. GetClampedRGBAccum32Values( cfb, ap, pAccumCol, w, scale );
  2900. for( pac = pAccumCol ; w; w--, pac++ )
  2901. {
  2902. frag.color = *pac;
  2903. (*cfb->store)(cfb, &frag);
  2904. frag.x++;
  2905. }
  2906. gc->state.enables.general = saveEnables; // restore current enables
  2907. }
  2908. /******************************Public*Routine******************************\
  2909. * Index8ReturnSpan
  2910. * Reads from a 32-bit accumulation buffer and writes the span to a device or
  2911. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  2912. *
  2913. * History:
  2914. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  2915. \**************************************************************************/
  2916. //XXX This routine follows the store span routine very closely. Any changes
  2917. //XXX to the store span routine should also be reflected here
  2918. void Index8ReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  2919. const __GLaccumCell *ac, __GLfloat scale, GLint w )
  2920. {
  2921. __GLcontext *gc = cfb->buf.gc;
  2922. GLuint *ap; // current accum entry
  2923. GLint xFrag, yFrag; // current window (pixel) coordinates
  2924. GLint xScr, yScr; // current screen (pixel) coordinates
  2925. GLubyte result, *puj; // current pixel color, current pixel ptr
  2926. GLubyte *pujEnd; // end of scan line
  2927. __GLfloat inc; // current dither adj.
  2928. __GLGENcontext *gengc; // generic graphics context
  2929. GLuint enables; // modes enabled in graphics context
  2930. GLboolean bDIB;
  2931. __GLaccumBuffer *afb;
  2932. GLubyte dst_pix;
  2933. __GLcolor *pAccumCol, *pac;
  2934. ASSERT_CHOP_ROUND();
  2935. gengc = (__GLGENcontext *)gc;
  2936. ap = (GLuint *)ac;
  2937. xFrag = x;
  2938. yFrag = y;
  2939. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  2940. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  2941. enables = gc->state.enables.general;
  2942. bDIB = cfb->buf.flags & DIB_FORMAT;
  2943. // Use to call wglSpanVisible, if window level security is added reimplement
  2944. // Get pointer to bitmap.
  2945. puj = bDIB ? (GLubyte *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + xScr)
  2946. : gengc->ColorsBits;
  2947. pujEnd = puj + w;
  2948. afb = &gc->accumBuffer;
  2949. pAccumCol = afb->colors;
  2950. GetClampedRGBAccum32Values( cfb, ap, pAccumCol, w, scale );
  2951. pac = pAccumCol;
  2952. // Case: no dithering, no masking
  2953. //
  2954. // Check for the common case (which we'll do the fastest).
  2955. if ( !(enables & (__GL_DITHER_ENABLE)) &&
  2956. !(cfb->buf.flags & COLORMASK_ON) )
  2957. {
  2958. //!!!XXX -- we can also opt. by unrolling the loops
  2959. for ( ; puj < pujEnd; puj++, pac++ )
  2960. {
  2961. result = ((BYTE) FTOL(pac->r + __glHalf) << cfb->redShift) |
  2962. ((BYTE) FTOL(pac->g + __glHalf) << cfb->greenShift) |
  2963. ((BYTE) FTOL(pac->b + __glHalf) << cfb->blueShift);
  2964. *puj = gengc->pajTranslateVector[result];
  2965. }
  2966. }
  2967. // Case: dithering, no masking, no blending
  2968. //
  2969. // Dithering is pretty common for 8-bit displays, so its probably
  2970. // worth special case also.
  2971. else if ( !(cfb->buf.flags & COLORMASK_ON) )
  2972. {
  2973. for ( ; puj < pujEnd; puj++, pac++, xFrag++)
  2974. {
  2975. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  2976. result = ((BYTE) FTOL(pac->r + inc) << cfb->redShift) |
  2977. ((BYTE) FTOL(pac->g + inc) << cfb->greenShift) |
  2978. ((BYTE) FTOL(pac->b + inc) << cfb->blueShift);
  2979. *puj = gengc->pajTranslateVector[result];
  2980. }
  2981. }
  2982. // Case: general
  2983. //
  2984. // Otherwise, we'll do it slower.
  2985. else
  2986. {
  2987. // Color mask pre-fetch
  2988. if ((cfb->buf.flags & COLORMASK_ON) && !bDIB) {
  2989. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE );
  2990. }
  2991. for ( ; puj < pujEnd; puj++, pac++ )
  2992. {
  2993. if (enables & __GL_DITHER_ENABLE)
  2994. {
  2995. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  2996. xFrag++;
  2997. }
  2998. else
  2999. {
  3000. inc = __glHalf;
  3001. }
  3002. result = ((BYTE)FTOL(pac->r + inc) << cfb->redShift) |
  3003. ((BYTE)FTOL(pac->g + inc) << cfb->greenShift) |
  3004. ((BYTE)FTOL(pac->b + inc) << cfb->blueShift);
  3005. // Color mask
  3006. if (cfb->buf.flags & COLORMASK_ON)
  3007. {
  3008. dst_pix = gengc->pajInvTranslateVector[*puj];
  3009. result = (GLubyte)((dst_pix & cfb->destMask) |
  3010. (result & cfb->sourceMask));
  3011. }
  3012. *puj = gengc->pajTranslateVector[result];
  3013. }
  3014. }
  3015. // Output the offscreen scanline buffer to the device. The function
  3016. // (*gengc->pfnCopyPixels) should handle clipping.
  3017. if (!bDIB)
  3018. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  3019. // Store alpha values
  3020. if( ALPHA_WRITE_ENABLED( cfb ) )
  3021. (*cfb->alphaBuf.storeSpan2)( &cfb->alphaBuf, x, y, w, pAccumCol );
  3022. }
  3023. /******************************Public*Routine******************************\
  3024. * RGBReturnSpan
  3025. * Reads from a 64-bit accumulation buffer and writes the span to a device or
  3026. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  3027. *
  3028. * History:
  3029. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  3030. \**************************************************************************/
  3031. //XXX This routine follows the store span routine very closely. Any changes
  3032. //XXX to the store span routine should also be reflected here
  3033. void RGBReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  3034. const __GLaccumCell *ac, __GLfloat scale, GLint w )
  3035. {
  3036. __GLcontext *gc = cfb->buf.gc;
  3037. GLshort *ap; // current accum entry
  3038. GLint xScr, yScr; // current screen (pixel) coordinates
  3039. GLubyte *puj; // current pixel color, current pixel ptr
  3040. GLubyte *pujEnd; // end of scan line
  3041. __GLGENcontext *gengc; // generic graphics context
  3042. GLuint enables; // modes enabled in graphics context
  3043. GLboolean bDIB;
  3044. __GLaccumBuffer *afb;
  3045. __GLcolor *pAccumCol, *pac;
  3046. ASSERT_CHOP_ROUND();
  3047. afb = &gc->accumBuffer;
  3048. gengc = (__GLGENcontext *)gc;
  3049. ap = (GLshort *)ac;
  3050. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  3051. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  3052. enables = gc->state.enables.general;
  3053. bDIB = cfb->buf.flags & DIB_FORMAT;
  3054. // Use to call wglSpanVisible, if window level security is added reimplement
  3055. // Get pointer to bitmap.
  3056. puj = bDIB ? (GLuint *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr*3))
  3057. : gengc->ColorsBits;
  3058. pujEnd = puj + w*3;
  3059. // Pre-fetch/clamp/scale the accum buffer values
  3060. afb = &gc->accumBuffer;
  3061. pAccumCol = afb->colors;
  3062. GetClampedRGBAccum64Values( cfb, ap, pAccumCol, w, scale );
  3063. pac = pAccumCol;
  3064. // Case: no masking
  3065. if ( !(cfb->buf.flags & COLORMASK_ON) )
  3066. {
  3067. for ( ; puj < pujEnd; puj += 3, pac ++ )
  3068. {
  3069. puj[0] = (GLubyte) FTOL(pac->r);
  3070. puj[1] = (GLubyte) FTOL(pac->g);
  3071. puj[2] = (GLubyte) FTOL(pac->b);
  3072. }
  3073. }
  3074. // All other cases
  3075. else
  3076. {
  3077. GLboolean bRedMask, bGreenMask, bBlueMask;
  3078. GLubyte *pujStart = puj;
  3079. // Color mask pre-fetch
  3080. if (!bDIB)
  3081. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  3082. if( gc->state.raster.rMask ) {
  3083. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3084. *puj = (GLubyte) FTOL(pac->r);
  3085. }
  3086. pujStart++; pujEnd++;
  3087. if( gc->state.raster.gMask ) {
  3088. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3089. *puj = (GLubyte) FTOL(pac->g);
  3090. }
  3091. pujStart++; pujEnd++;
  3092. if( gc->state.raster.bMask ) {
  3093. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3094. *puj = (GLubyte) FTOL(pac->b);
  3095. }
  3096. }
  3097. // Output the offscreen scanline buffer to the device. The function
  3098. // (*gengc->pfnCopyPixels) should handle clipping.
  3099. if (!bDIB)
  3100. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  3101. // Store alpha values
  3102. if( ALPHA_WRITE_ENABLED( cfb ) )
  3103. (*cfb->alphaBuf.storeSpan2)( &cfb->alphaBuf, x, y, w, pAccumCol );
  3104. }
  3105. /******************************Public*Routine******************************\
  3106. * BGRReturnSpan
  3107. * Reads from a 64-bit accumulation buffer and writes the span to a device or
  3108. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  3109. *
  3110. * History:
  3111. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  3112. \**************************************************************************/
  3113. //XXX This routine follows the store span routine very closely. Any changes
  3114. //XXX to the store span routine should also be reflected here
  3115. void BGRReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  3116. const __GLaccumCell *ac, __GLfloat scale, GLint w )
  3117. {
  3118. __GLcontext *gc = cfb->buf.gc;
  3119. GLshort *ap; // current accum entry
  3120. __GLcolor *pAccumCol, *pac;
  3121. GLint xScr, yScr; // current screen (pixel) coordinates
  3122. GLubyte *puj; // current pixel color, current pixel ptr
  3123. GLubyte *pujEnd; // end of scan line
  3124. __GLGENcontext *gengc; // generic graphics context
  3125. GLuint enables; // modes enabled in graphics context
  3126. GLboolean bDIB;
  3127. __GLfloat r, g, b;
  3128. __GLfloat rval, gval, bval;
  3129. __GLaccumBuffer *afb;
  3130. ASSERT_CHOP_ROUND();
  3131. afb = &gc->accumBuffer;
  3132. rval = scale * afb->oneOverRedScale;
  3133. gval = scale * afb->oneOverGreenScale;
  3134. bval = scale * afb->oneOverBlueScale;
  3135. gengc = (__GLGENcontext *)gc;
  3136. ap = (GLshort *)ac;
  3137. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  3138. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  3139. enables = gc->state.enables.general;
  3140. bDIB = cfb->buf.flags & DIB_FORMAT;
  3141. // Use to call wglSpanVisible, if window level security is added reimplement
  3142. // Get pointer to bitmap.
  3143. puj = bDIB ? (GLuint *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr*3))
  3144. : gengc->ColorsBits;
  3145. pujEnd = puj + w*3;
  3146. // Pre-fetch/clamp/scale the accum buffer values
  3147. afb = &gc->accumBuffer;
  3148. pAccumCol = afb->colors;
  3149. GetClampedRGBAccum64Values( cfb, ap, pAccumCol, w, scale );
  3150. pac = pAccumCol;
  3151. // Case: no masking
  3152. if ( !(cfb->buf.flags & COLORMASK_ON) )
  3153. {
  3154. for ( ; puj < pujEnd; puj += 3, pac ++ )
  3155. {
  3156. puj[0] = (GLubyte) FTOL(pac->b);
  3157. puj[1] = (GLubyte) FTOL(pac->g);
  3158. puj[2] = (GLubyte) FTOL(pac->r);
  3159. }
  3160. }
  3161. // All other cases
  3162. else
  3163. {
  3164. GLboolean bRedMask, bGreenMask, bBlueMask;
  3165. GLubyte *pujStart = puj;
  3166. // Color mask pre-fetch
  3167. if (!bDIB)
  3168. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  3169. if( gc->state.raster.bMask ) {
  3170. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3171. *puj = (GLubyte) FTOL(pac->b);
  3172. }
  3173. pujStart++; pujEnd++;
  3174. if( gc->state.raster.gMask ) {
  3175. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3176. *puj = (GLubyte) FTOL(pac->g);
  3177. }
  3178. pujStart++; pujEnd++;
  3179. if( gc->state.raster.rMask ) {
  3180. for ( puj = pujStart, pac = pAccumCol; puj < pujEnd; puj += 3, pac++ )
  3181. *puj = (GLubyte) FTOL(pac->r);
  3182. }
  3183. }
  3184. // Output the offscreen scanline buffer to the device. The function
  3185. // (*gengc->pfnCopyPixels) should handle clipping.
  3186. if (!bDIB)
  3187. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  3188. // Store alpha values
  3189. if( ALPHA_WRITE_ENABLED( cfb ) )
  3190. (*cfb->alphaBuf.storeSpan2)( &cfb->alphaBuf, x, y, w, pAccumCol );
  3191. }
  3192. /******************************Public*Routine******************************\
  3193. * Bitfield16ReturnSpan
  3194. * Reads from a 32-bit accumulation buffer and writes the span to a device or
  3195. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  3196. *
  3197. * History:
  3198. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  3199. \**************************************************************************/
  3200. //XXX This routine follows the store span routine very closely. Any changes
  3201. //XXX to the store span routine should also be reflected here
  3202. void Bitfield16ReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  3203. const __GLaccumCell *ac, __GLfloat scale, GLint w )
  3204. {
  3205. __GLcontext *gc = cfb->buf.gc;
  3206. GLuint *ap; // current accum entry
  3207. GLint xFrag, yFrag; // current fragment coordinates
  3208. GLint xScr, yScr; // current screen (pixel) coordinates
  3209. GLushort result, *pus; // current pixel color, current pixel ptr
  3210. GLushort *pusEnd; // end of scan line
  3211. __GLfloat inc; // current dither adj.
  3212. __GLGENcontext *gengc; // generic graphics context
  3213. GLuint enables; // modes enabled in graphics context
  3214. GLboolean bDIB;
  3215. __GLcolor *pAccumCol, *pac;
  3216. __GLaccumBuffer *afb;
  3217. ASSERT_CHOP_ROUND();
  3218. afb = &gc->accumBuffer;
  3219. gengc = (__GLGENcontext *)gc;
  3220. ap = (GLuint *)ac;
  3221. xFrag = x;
  3222. yFrag = y;
  3223. xScr = __GL_UNBIAS_X(gc, xFrag) + cfb->buf.xOrigin;
  3224. yScr = __GL_UNBIAS_Y(gc, yFrag) + cfb->buf.yOrigin;
  3225. enables = gc->state.enables.general;
  3226. bDIB = cfb->buf.flags & DIB_FORMAT;
  3227. // Use to call wglSpanVisible, if window level security is added reimplement
  3228. // Get pointer to bitmap.
  3229. pus = bDIB ? (GLushort *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<1))
  3230. : gengc->ColorsBits;
  3231. pusEnd = pus + w;
  3232. // Pre-fetch/clamp/scale the accum buffer values
  3233. afb = &gc->accumBuffer;
  3234. pAccumCol = afb->colors;
  3235. GetClampedRGBAccum32Values( cfb, ap, pAccumCol, w, scale );
  3236. pac = pAccumCol;
  3237. // Case: no masking, no dithering
  3238. if ( !(enables & (__GL_DITHER_ENABLE)) &&
  3239. !(cfb->buf.flags & COLORMASK_ON) )
  3240. {
  3241. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  3242. for ( ; pus < pusEnd; pus++, pac++ )
  3243. {
  3244. *pus = ((BYTE) FTOL(pac->r + __glHalf) << cfb->redShift) |
  3245. ((BYTE) FTOL(pac->g + __glHalf) << cfb->greenShift) |
  3246. ((BYTE) FTOL(pac->b + __glHalf) << cfb->blueShift) |
  3247. ((BYTE) FTOL(pac->a + __glHalf) << cfb->alphaShift);
  3248. }
  3249. } else {
  3250. for ( ; pus < pusEnd; pus++, pac++ )
  3251. {
  3252. *pus = ((BYTE) FTOL(pac->r + __glHalf) << cfb->redShift) |
  3253. ((BYTE) FTOL(pac->g + __glHalf) << cfb->greenShift) |
  3254. ((BYTE) FTOL(pac->b + __glHalf) << cfb->blueShift);
  3255. }
  3256. }
  3257. }
  3258. // Case: dithering, no masking
  3259. else if ( !(cfb->buf.flags & COLORMASK_ON) )
  3260. {
  3261. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  3262. for ( ; pus < pusEnd; pus++, pac++, xFrag++ )
  3263. {
  3264. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  3265. *pus = ((BYTE) FTOL(pac->r + inc) << cfb->redShift) |
  3266. ((BYTE) FTOL(pac->g + inc) << cfb->greenShift) |
  3267. ((BYTE) FTOL(pac->b + inc) << cfb->blueShift) |
  3268. ((BYTE) FTOL(pac->a + inc) << cfb->alphaShift);
  3269. }
  3270. } else {
  3271. for ( ; pus < pusEnd; pus++, pac++, xFrag++ )
  3272. {
  3273. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  3274. *pus = ((BYTE) FTOL(pac->r + inc) << cfb->redShift) |
  3275. ((BYTE) FTOL(pac->g + inc) << cfb->greenShift) |
  3276. ((BYTE) FTOL(pac->b + inc) << cfb->blueShift);
  3277. }
  3278. }
  3279. }
  3280. // All other cases
  3281. else
  3282. {
  3283. // Color mask pre-fetch
  3284. if (!bDIB)
  3285. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  3286. for ( ; pus < pusEnd; pus++, pac++ )
  3287. {
  3288. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  3289. // Dither.
  3290. if ( enables & __GL_DITHER_ENABLE )
  3291. {
  3292. inc = fDitherIncTable[__GL_DITHER_INDEX(xFrag, yFrag)];
  3293. xFrag++;
  3294. }
  3295. else
  3296. {
  3297. inc = __glHalf;
  3298. }
  3299. // Convert color to 16BPP format.
  3300. result = ((BYTE) FTOL(pac->r + inc) << cfb->redShift) |
  3301. ((BYTE) FTOL(pac->g + inc) << cfb->greenShift) |
  3302. ((BYTE) FTOL(pac->b + inc) << cfb->blueShift);
  3303. if( ALPHA_PIXEL_WRITE( cfb ) )
  3304. result |= ((BYTE) FTOL(pac->a + inc) << cfb->alphaShift);
  3305. // Store result with optional masking.
  3306. *pus = (GLushort)((*pus & cfb->destMask) | (result & cfb->sourceMask));
  3307. }
  3308. }
  3309. // Output the offscreen scanline buffer to the device. The function
  3310. // (*gengc->pfnCopyPixels) should handle clipping.
  3311. if (!bDIB)
  3312. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  3313. if( ALPHA_BUFFER_WRITE( cfb ) )
  3314. (*cfb->alphaBuf.storeSpan2)( &cfb->alphaBuf, x, y, w, pAccumCol );
  3315. }
  3316. /******************************Public*Routine******************************\
  3317. * Bitfield32ReturnSpan
  3318. * Reads from a 64-bit accumulation buffer and writes the span to a device or
  3319. * a DIB. Only dithering and color mask are applied. Blend is ignored.
  3320. *
  3321. * History:
  3322. * 10-DEC-93 Eddie Robinson [v-eddier] Wrote it.
  3323. \**************************************************************************/
  3324. //XXX This routine follows the store span routine very closely. Any changes
  3325. //XXX to the store span routine should also be reflected here
  3326. void Bitfield32ReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  3327. const __GLaccumCell *ac, __GLfloat scale, GLint w )
  3328. {
  3329. __GLcontext *gc = cfb->buf.gc;
  3330. GLshort *ap; // current accum entry
  3331. GLint xScr, yScr; // current screen (pixel) coordinates
  3332. GLuint result, *pul; // current pixel color, current pixel ptr
  3333. GLuint *pulEnd; // end of scan line
  3334. __GLGENcontext *gengc; // generic graphics context
  3335. GLuint enables; // modes enabled in graphics context
  3336. GLboolean bDIB;
  3337. __GLfloat r, g, b;
  3338. __GLfloat rval, gval, bval;
  3339. __GLaccumBuffer *afb;
  3340. __GLcolor *pAccumCol, *pac;
  3341. ASSERT_CHOP_ROUND();
  3342. afb = &gc->accumBuffer;
  3343. rval = scale * afb->oneOverRedScale;
  3344. gval = scale * afb->oneOverGreenScale;
  3345. bval = scale * afb->oneOverBlueScale;
  3346. gengc = (__GLGENcontext *)gc;
  3347. ap = (GLshort *)ac;
  3348. xScr = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  3349. yScr = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  3350. enables = gc->state.enables.general;
  3351. bDIB = cfb->buf.flags & DIB_FORMAT;
  3352. // Use to call wglSpanVisible, if window level security is added reimplement
  3353. // Get pointer to bitmap.
  3354. pul = bDIB ? (GLuint *)((ULONG_PTR)cfb->buf.base + (yScr*cfb->buf.outerWidth) + (xScr<<2))
  3355. : gengc->ColorsBits;
  3356. pulEnd = pul + w;
  3357. // Pre-fetch/clamp/scale the accum buffer values
  3358. afb = &gc->accumBuffer;
  3359. pAccumCol = afb->colors;
  3360. GetClampedRGBAccum64Values( cfb, ap, pAccumCol, w, scale );
  3361. pac = pAccumCol;
  3362. // Case: no masking
  3363. if ( !(cfb->buf.flags & COLORMASK_ON) )
  3364. {
  3365. if( ALPHA_PIXEL_WRITE( cfb ) ) {
  3366. for ( ; pul < pulEnd; pul++, pac++ )
  3367. {
  3368. *pul = ((BYTE) FTOL(pac->r) << cfb->redShift) |
  3369. ((BYTE) FTOL(pac->g) << cfb->greenShift) |
  3370. ((BYTE) FTOL(pac->b) << cfb->blueShift) |
  3371. ((BYTE) FTOL(pac->a) << cfb->alphaShift);
  3372. }
  3373. } else {
  3374. for ( ; pul < pulEnd; pul++, pac++ )
  3375. {
  3376. *pul = ((BYTE) FTOL(pac->r) << cfb->redShift) |
  3377. ((BYTE) FTOL(pac->g) << cfb->greenShift) |
  3378. ((BYTE) FTOL(pac->b) << cfb->blueShift);
  3379. }
  3380. }
  3381. }
  3382. // All other cases
  3383. else
  3384. {
  3385. // Color mask pre-fetch
  3386. if( !bDIB )
  3387. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, FALSE);
  3388. for ( ; pul < pulEnd; pul++, pac++ )
  3389. {
  3390. result = ((BYTE) FTOL(pac->r) << cfb->redShift) |
  3391. ((BYTE) FTOL(pac->g) << cfb->greenShift) |
  3392. ((BYTE) FTOL(pac->b) << cfb->blueShift);
  3393. if( ALPHA_PIXEL_WRITE( cfb ) )
  3394. result |= ((BYTE) FTOL(pac->a) << cfb->alphaShift);
  3395. //!!!XXX again, opt. by unrolling loop
  3396. *pul = (*pul & cfb->destMask) | (result & cfb->sourceMask);
  3397. }
  3398. }
  3399. // Output the offscreen scanline buffer to the device. The function
  3400. // (*gengc->pfnCopyPixels) should handle clipping.
  3401. if (!bDIB)
  3402. (*gengc->pfnCopyPixels)(gengc, cfb, xScr, yScr, w, TRUE);
  3403. if( ALPHA_BUFFER_WRITE( cfb ) )
  3404. (*cfb->alphaBuf.storeSpan2)( &cfb->alphaBuf, x, y, w, pAccumCol );
  3405. }
  3406. STATIC void __glSetDrawBuffer(__GLcolorBuffer *cfb)
  3407. {
  3408. DBGENTRY("__glSetDrawBuffer\n");
  3409. }
  3410. STATIC void setReadBuffer(__GLcolorBuffer *cfb)
  3411. {
  3412. DBGENTRY("setReadBuffer\n");
  3413. }
  3414. /************************************************************************/
  3415. STATIC void Resize(__GLGENbuffers *buffers, __GLcolorBuffer *cfb,
  3416. GLint w, GLint h)
  3417. {
  3418. DBGENTRY("Resize\n");
  3419. cfb->buf.width = w;
  3420. cfb->buf.height = h;
  3421. }
  3422. #define DBG_PICK LEVEL_ENTRY
  3423. // Called at each validate (lots of times, whenever states change)
  3424. STATIC void FASTCALL PickRGB(__GLcontext *gc, __GLcolorBuffer *cfb)
  3425. {
  3426. __GLGENcontext *gengc;
  3427. GLuint totalMask, sourceMask;
  3428. GLboolean colormask;
  3429. PIXELFORMATDESCRIPTOR *pfmt;
  3430. GLuint enables = gc->state.enables.general;
  3431. sourceMask = 0;
  3432. colormask = GL_FALSE;
  3433. if (gc->state.raster.rMask) {
  3434. sourceMask |= gc->modes.redMask;
  3435. }
  3436. if (gc->state.raster.gMask) {
  3437. sourceMask |= gc->modes.greenMask;
  3438. }
  3439. if (gc->state.raster.bMask) {
  3440. sourceMask |= gc->modes.blueMask;
  3441. }
  3442. totalMask = gc->modes.redMask | gc->modes.greenMask | gc->modes.blueMask;
  3443. gengc = (__GLGENcontext *)gc;
  3444. // If we have alpha bits, need to determine where they belong : for a
  3445. // generic pixel format, they live in the software alpha buffer, but for
  3446. // an mcd type context they will be on the mcd device (or ALPHA_IN_PIXEL ).
  3447. // This is used by all the 'slow' store/fetch procs.
  3448. if( gc->modes.alphaBits && gengc->pMcdState ) {
  3449. // Set bit in buf.flags indicating alpha is in the pixel
  3450. cfb->buf.flags = cfb->buf.flags | ALPHA_IN_PIXEL_BIT;
  3451. } else {
  3452. // Alpha is not in the pixel, or there is no alpha
  3453. cfb->buf.flags = cfb->buf.flags & ~ALPHA_IN_PIXEL_BIT;
  3454. }
  3455. if( ALPHA_IN_PIXEL( cfb ) ) {
  3456. // There are alpha bits in the pixels, so need to include alpha in mask
  3457. if (gc->state.raster.aMask) {
  3458. sourceMask |= gc->modes.alphaMask;
  3459. }
  3460. totalMask |= gc->modes.alphaMask;
  3461. }
  3462. if (sourceMask == totalMask) {
  3463. cfb->buf.flags = cfb->buf.flags & ~COLORMASK_ON;
  3464. } else {
  3465. cfb->buf.flags = cfb->buf.flags | COLORMASK_ON;
  3466. }
  3467. cfb->sourceMask = sourceMask;
  3468. cfb->destMask = totalMask & ~sourceMask;
  3469. // Determine whether writing alpha values is required
  3470. if( gc->modes.alphaBits && gc->state.raster.aMask )
  3471. cfb->buf.flags = cfb->buf.flags | ALPHA_ON;
  3472. else
  3473. cfb->buf.flags = cfb->buf.flags & ~ALPHA_ON;
  3474. // If we're doing a logic op or there is a color mask we'll need
  3475. // to fetch the destination value before we write
  3476. if ((enables & __GL_COLOR_LOGIC_OP_ENABLE) ||
  3477. (cfb->buf.flags & COLORMASK_ON))
  3478. {
  3479. cfb->buf.flags = cfb->buf.flags | NEED_FETCH;
  3480. }
  3481. else
  3482. cfb->buf.flags = cfb->buf.flags & ~NEED_FETCH;
  3483. // Figure out store routines
  3484. if (gc->state.raster.drawBuffer == GL_NONE) {
  3485. cfb->store = Store_NOT;
  3486. cfb->fetch = RGBFetchNone;
  3487. cfb->readSpan = RGBReadSpanNone;
  3488. cfb->storeSpan = StoreSpanNone;
  3489. cfb->storeStippledSpan = StoreSpanNone;
  3490. } else {
  3491. pfmt = &gengc->gsurf.pfd;
  3492. // Pick functions that work for both DIB and Display formats
  3493. switch(pfmt->cColorBits) {
  3494. case 4:
  3495. cfb->clear = Index4Clear;
  3496. cfb->returnSpan = Index4ReturnSpan;
  3497. break;
  3498. case 8:
  3499. cfb->storeSpan = Index8StoreSpan;
  3500. cfb->readSpan = Index8RGBAReadSpan;
  3501. cfb->returnSpan = Index8ReturnSpan;
  3502. cfb->clear = Index8Clear;
  3503. break;
  3504. case 16:
  3505. cfb->storeSpan = Bitfield16StoreSpan;
  3506. cfb->readSpan = Bitfield16RGBAReadSpan;
  3507. cfb->returnSpan = Bitfield16ReturnSpan;
  3508. cfb->clear = Bitfield16Clear;
  3509. break;
  3510. case 24:
  3511. if (cfb->redShift == 16)
  3512. {
  3513. cfb->storeSpan = BGRStoreSpan;
  3514. cfb->readSpan = BGRAReadSpan;
  3515. cfb->returnSpan = BGRReturnSpan;
  3516. } else {
  3517. // XXX why no RGBStoreSpan ?
  3518. cfb->readSpan = RGBAReadSpan;
  3519. cfb->returnSpan = RGBReturnSpan;
  3520. }
  3521. cfb->clear = RGBClear;
  3522. break;
  3523. case 32:
  3524. cfb->storeSpan = Bitfield32StoreSpan;
  3525. cfb->readSpan = Bitfield32RGBAReadSpan;
  3526. cfb->returnSpan = Bitfield32ReturnSpan;
  3527. cfb->clear = Bitfield32Clear;
  3528. break;
  3529. }
  3530. // Pick specific functions for DIB or Display formats
  3531. if (cfb->buf.flags & DIB_FORMAT) {
  3532. switch(pfmt->cColorBits) {
  3533. case 4:
  3534. DBGLEVEL(DBG_PICK, "DIBIndex4Store\n");
  3535. cfb->store = DIBIndex4Store;
  3536. cfb->fetch = DIBIndex4RGBAFetch;
  3537. cfb->readSpan = DIBIndex4RGBAReadSpan;
  3538. break;
  3539. case 8:
  3540. DBGLEVEL(DBG_PICK, "DIBIndex8Store, "
  3541. "Index8StoreSpan\n");
  3542. cfb->store = DIBIndex8Store;
  3543. if( gc->modes.alphaBits )
  3544. cfb->fetch = DIBIndex8RGBAFetch;
  3545. else
  3546. cfb->fetch = DIBIndex8RGBFetch;
  3547. break;
  3548. case 16:
  3549. DBGLEVEL(DBG_PICK, "DIBBitfield16Store\n");
  3550. cfb->store = DIBBitfield16Store;
  3551. if( gc->modes.alphaBits )
  3552. cfb->fetch = DIBBitfield16RGBAFetch;
  3553. else
  3554. cfb->fetch = DIBBitfield16RGBFetch;
  3555. break;
  3556. case 24:
  3557. if (cfb->redShift == 16)
  3558. {
  3559. DBGLEVEL(DBG_PICK, "DIBBGRStore\n");
  3560. cfb->store = DIBBGRStore;
  3561. if( gc->modes.alphaBits )
  3562. cfb->fetch = DIBBGRAFetch;
  3563. else
  3564. cfb->fetch = DIBBGRFetch;
  3565. }
  3566. else
  3567. {
  3568. DBGLEVEL(DBG_PICK, "DIBRGBStore\n");
  3569. cfb->store = DIBRGBAStore;
  3570. if( gc->modes.alphaBits )
  3571. cfb->fetch = DIBRGBAFetch;
  3572. else
  3573. cfb->fetch = DIBRGBFetch;
  3574. }
  3575. break;
  3576. case 32:
  3577. DBGLEVEL(DBG_PICK, "DIBBitfield32Store, "
  3578. "Bitfield32StoreSpan\n");
  3579. cfb->store = DIBBitfield32Store;
  3580. if( gc->modes.alphaBits )
  3581. cfb->fetch = DIBBitfield32RGBAFetch;
  3582. else
  3583. cfb->fetch = DIBBitfield32RGBFetch;
  3584. break;
  3585. }
  3586. } else {
  3587. switch(pfmt->cColorBits) {
  3588. case 4:
  3589. DBGLEVEL(DBG_PICK, "DisplayIndex4Store\n");
  3590. cfb->store = DisplayIndex4Store;
  3591. cfb->fetch = DisplayIndex4RGBAFetch;
  3592. cfb->readSpan = DisplayIndex4RGBAReadSpan;
  3593. break;
  3594. case 8:
  3595. DBGLEVEL(DBG_PICK, "DisplayIndex8Store, "
  3596. "Index8StoreSpan\n");
  3597. cfb->store = DisplayIndex8Store;
  3598. if( gc->modes.alphaBits )
  3599. cfb->fetch = DisplayIndex8RGBAFetch;
  3600. else
  3601. cfb->fetch = DisplayIndex8RGBFetch;
  3602. break;
  3603. case 16:
  3604. DBGLEVEL(DBG_PICK, "DisplayBitfield16Store\n");
  3605. cfb->store = DisplayBitfield16Store;
  3606. if( gc->modes.alphaBits )
  3607. cfb->fetch = DisplayBitfield16RGBAFetch;
  3608. else
  3609. cfb->fetch = DisplayBitfield16RGBFetch;
  3610. break;
  3611. case 24:
  3612. // Must be RGB or BGR
  3613. if (cfb->redShift == 16)
  3614. {
  3615. DBGLEVEL(DBG_PICK, "DisplayBGRStore\n");
  3616. cfb->store = DisplayBGRStore;
  3617. if( gc->modes.alphaBits )
  3618. cfb->fetch = DisplayBGRAFetch;
  3619. else
  3620. cfb->fetch = DisplayBGRFetch;
  3621. }
  3622. else
  3623. {
  3624. DBGLEVEL(DBG_PICK, "DisplayRGBStore\n");
  3625. cfb->store = DisplayRGBStore;
  3626. if( gc->modes.alphaBits )
  3627. cfb->fetch = DisplayRGBAFetch;
  3628. else
  3629. cfb->fetch = DisplayRGBFetch;
  3630. }
  3631. break;
  3632. case 32:
  3633. DBGLEVEL(DBG_PICK, "DisplayBitfield32Store, "
  3634. "Bitfield32StoreSpan\n");
  3635. cfb->store = DisplayBitfield32Store;
  3636. if( gc->modes.alphaBits )
  3637. cfb->fetch = DisplayBitfield32RGBAFetch;
  3638. else
  3639. cfb->fetch = DisplayBitfield32RGBFetch;
  3640. break;
  3641. }
  3642. }
  3643. // cfb->readColor is the same as cfb->fetch (so why do we need it ?)
  3644. cfb->readColor = cfb->fetch;
  3645. // If we are only writing alpha (rgb all masked), can further optimize:
  3646. // Don't bother if logicOp or blending are enabled, and only if we
  3647. // have a software alpha buffer
  3648. if( gc->modes.alphaBits &&
  3649. ! ALPHA_IN_PIXEL( cfb ) &&
  3650. (sourceMask == 0) &&
  3651. gc->state.raster.aMask &&
  3652. !(enables & __GL_COLOR_LOGIC_OP_ENABLE) &&
  3653. ! (enables & __GL_BLEND_ENABLE) )
  3654. {
  3655. cfb->store = AlphaStore;
  3656. cfb->storeSpan = AlphaStoreSpan;
  3657. }
  3658. }
  3659. }
  3660. /************************************************************************/
  3661. void FASTCALL __glGenFreeRGB(__GLcontext *gc, __GLcolorBuffer *cfb)
  3662. {
  3663. DBGENTRY("__glGenFreeRGB\n");
  3664. }
  3665. /************************************************************************/
  3666. // Note: this used to be defined in generic\genrgb.h
  3667. #define __GL_GENRGB_COMPONENT_SCALE_ALPHA 255
  3668. // called at makecurrent time
  3669. // need to get info out of pixel format structure
  3670. void FASTCALL __glGenInitRGB(__GLcontext *gc, __GLcolorBuffer *cfb, GLenum type)
  3671. {
  3672. __GLGENcontext *gengc = (__GLGENcontext *)gc;
  3673. PIXELFORMATDESCRIPTOR *pfmt;
  3674. __glInitGenericCB(gc, cfb);
  3675. cfb->redMax = (1 << gc->modes.redBits) - 1;
  3676. cfb->greenMax = (1 << gc->modes.greenBits) - 1;
  3677. cfb->blueMax = (1 << gc->modes.blueBits) - 1;
  3678. gc->redVertexScale = cfb->redScale = (__GLfloat)cfb->redMax;
  3679. gc->greenVertexScale = cfb->greenScale = (__GLfloat)cfb->greenMax;
  3680. gc->blueVertexScale = cfb->blueScale = (__GLfloat)cfb->blueMax;
  3681. cfb->iRedScale = cfb->redMax;
  3682. cfb->iGreenScale = cfb->greenMax;
  3683. cfb->iBlueScale = cfb->blueMax;
  3684. // Do any initialization related to alpha
  3685. if( gc->modes.alphaBits ) {
  3686. cfb->alphaMax = (1 << gc->modes.alphaBits) - 1;
  3687. cfb->iAlphaScale = cfb->alphaMax;
  3688. gc->alphaVertexScale = cfb->alphaScale = (__GLfloat)cfb->alphaMax;
  3689. // Initialize the software alpha buffer. Actually, we may not need to
  3690. // do this, since if an mcd pixel format supports alpha, we don't need
  3691. // the software alpha buffer. But this is the most convenient place to
  3692. // do it, and no memory will be allocated anyways. just function ptrs
  3693. // initialized.
  3694. __glInitAlpha( gc, cfb );
  3695. } else {
  3696. cfb->alphaMax = __GL_GENRGB_COMPONENT_SCALE_ALPHA;
  3697. cfb->iAlphaScale = __GL_GENRGB_COMPONENT_SCALE_ALPHA;
  3698. gc->alphaVertexScale = cfb->alphaScale = (__GLfloat)cfb->redMax;
  3699. }
  3700. cfb->buf.elementSize = sizeof(GLubyte); // XXX needed?
  3701. cfb->pick = PickRGB; // called at each validate
  3702. cfb->resize = Resize;
  3703. cfb->fetchSpan = __glFetchSpan;
  3704. cfb->fetchStippledSpan = __glFetchSpan;
  3705. cfb->storeSpan = SlowStoreSpan;
  3706. cfb->storeStippledSpan = SlowStoreStippledSpan;
  3707. pfmt = &gengc->gsurf.pfd;
  3708. cfb->redShift = pfmt->cRedShift;
  3709. cfb->greenShift = pfmt->cGreenShift;
  3710. cfb->blueShift = pfmt->cBlueShift;
  3711. cfb->alphaShift = pfmt->cAlphaShift;
  3712. glGenInitCommon(gengc, cfb, type);
  3713. DBGLEVEL3(LEVEL_INFO,"GeninitRGB: redMax %d, greenMax %d, blueMax %d\n",
  3714. cfb->redMax, cfb->greenMax, cfb->blueMax);
  3715. DBGLEVEL3(LEVEL_INFO," redShift %d, greenShift %d, blueShift %d\n",
  3716. cfb->redShift, cfb->greenShift, cfb->blueShift);
  3717. DBGLEVEL2(LEVEL_INFO," dwFlags %X, cColorBits %d\n",
  3718. gengc->dwCurrentFlags, pfmt->cColorBits);
  3719. }