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.

1481 lines
42 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #include "genclear.h"
  4. // Null stores...
  5. static void FASTCALL Store_NOT(__GLcolorBuffer *cfb, const __GLfragment *frag)
  6. {
  7. }
  8. static GLboolean FASTCALL StoreSpanNone(__GLcontext *gc)
  9. {
  10. return GL_FALSE;
  11. }
  12. /* XXX! Current policy for >8-bit ColorIndex:
  13. - The index<->Color mapping will be kept in gengc->pajTranslateVector,
  14. viewed as an array of longs. The first entry in the array will be
  15. the number of valid entries in the table.
  16. - gengc->pajTranslateVector will never be NULL, it is always allocated
  17. at MakeCurrent, and tracks any palette changes.
  18. - the minimum indexBits is 8 if the pixel format is > 8 bits deep
  19. */
  20. /******************************Public*Routine******************************\
  21. * dibSetPixelCI
  22. *
  23. * Special case version of GDI SetPixel API for use when the destination
  24. * surface is a DIB and rendering in color index mode.
  25. *
  26. * This function *must* be used in lieu of gdiCopyPixels if we are
  27. * accessing the screen directly as it is not safe to call GDI entry
  28. * points with a screen lock
  29. *
  30. * History:
  31. * 29-May-1995 -by- Gilman Wong [gilmanw]
  32. * Wrote it.
  33. \**************************************************************************/
  34. void dibSetPixelCI(__GLGENcontext *gengc, __GLcolorBuffer *cfb,
  35. GLint x, GLint y, DWORD dwColor)
  36. {
  37. GLuint flags;
  38. flags = cfb->buf.flags;
  39. ASSERTOPENGL(flags & DIB_FORMAT,
  40. "dibSetPixelCI called on non-DIB\n");
  41. if ( (flags & NO_CLIP) || wglPixelVisible(x, y) )
  42. {
  43. if ( gengc->gsurf.pfd.cColorBits > 4 )
  44. {
  45. VOID *pvDib;
  46. UINT cjPixel = gengc->gsurf.pfd.cColorBits >> 3;
  47. pvDib = (VOID *) (((BYTE *) gengc->gc.front->buf.base) +
  48. gengc->gc.front->buf.outerWidth * y +
  49. cjPixel * x);
  50. if ( gengc->gsurf.pfd.cColorBits == 8 )
  51. *((BYTE *) pvDib) = gengc->pajTranslateVector[dwColor];
  52. else
  53. {
  54. GLuint *pTrans = ((GLuint *) gengc->pajTranslateVector) + 1;
  55. dwColor &= cfb->redMax;
  56. switch (gengc->gsurf.pfd.cColorBits)
  57. {
  58. case 16:
  59. *((WORD *) pvDib) = (WORD) pTrans[dwColor];
  60. break;
  61. case 24:
  62. Copy3Bytes(pvDib, &(pTrans[dwColor]));
  63. break;
  64. case 32:
  65. *((DWORD *) pvDib) = (DWORD) pTrans[dwColor];
  66. break;
  67. default:
  68. WARNING1("dibSetPixelCI: bad cColorBits = %ld\n",
  69. gengc->gsurf.pfd.cColorBits);
  70. break;
  71. }
  72. }
  73. }
  74. else
  75. {
  76. BYTE *puj = (BYTE *)((ULONG_PTR)cfb->buf.base +
  77. (y*cfb->buf.outerWidth) + (x >> 1));
  78. dwColor = gengc->pajTranslateVector[dwColor & 0xf] & 0xf;
  79. if( x & 1 )
  80. *puj = (*puj & 0xf0) | (BYTE) dwColor;
  81. else
  82. *puj = (*puj & 0x0f) | (BYTE) (dwColor << 4);
  83. }
  84. }
  85. }
  86. /*
  87. ** No dither, no logicOp.
  88. */
  89. static void FASTCALL Store(__GLcolorBuffer *cfb, const __GLfragment *frag)
  90. {
  91. GLint x, y;
  92. __GLcontext *gc = cfb->buf.gc;
  93. __GLGENcontext *genGc = (__GLGENcontext *)gc;
  94. COLORREF Cr;
  95. DWORD index;
  96. DBGLEVEL(32, "Store(CI)\n");
  97. index = (DWORD) (frag->color.r + __glHalf);
  98. Cr = PALETTEINDEX(index);
  99. x = __GL_UNBIAS_X(gc, frag->x);
  100. y = __GL_UNBIAS_Y(gc, frag->y);
  101. if ( !(genGc->fsLocks & LOCKFLAG_FRONT_BUFFER) )
  102. SetPixel( CURRENT_DC, x, y, Cr );
  103. else
  104. dibSetPixelCI(genGc, cfb, x, y, index);
  105. }
  106. /* XXX! The Store_* routines do not handle double buffering. Gilman
  107. has said that they will not be compatible with his 'cursor
  108. tear-down' strategy. Therefore we probably won't use them.
  109. BUT, they are about 30% faster than their Display*Store
  110. counterparts, so we'll keep them around for further study
  111. */
  112. /*
  113. ** Dither, no logicOp.
  114. */
  115. static void FASTCALL Store_D(__GLcolorBuffer *cfb, const __GLfragment *frag)
  116. {
  117. GLint x, y;
  118. __GLcontext *gc = cfb->buf.gc;
  119. __GLGENcontext *genGc = (__GLGENcontext *)gc;
  120. COLORREF Cr;
  121. DWORD index;
  122. DBGLEVEL(32, "Store_D\n");
  123. index = (DWORD) (frag->color.r + __glHalf);
  124. Cr = PALETTEINDEX(index);
  125. x = __GL_UNBIAS_X(gc, frag->x);
  126. y = __GL_UNBIAS_Y(gc, frag->y);
  127. if ( !(genGc->fsLocks & LOCKFLAG_FRONT_BUFFER) )
  128. SetPixel( CURRENT_DC, x, y, Cr );
  129. else
  130. dibSetPixelCI(genGc, cfb, x, y, index);
  131. }
  132. /*
  133. ** No dither, logicOp
  134. */
  135. static void FASTCALL Store_L(__GLcolorBuffer *cfb, const __GLfragment *frag)
  136. {
  137. GLint x, y;
  138. __GLcontext *gc = cfb->buf.gc;
  139. __GLGENcontext *genGc = (__GLGENcontext *)gc;
  140. COLORREF Cr;
  141. DWORD index;
  142. DBGLEVEL(32, "Store_L\n");
  143. index = (DWORD) (frag->color.r + __glHalf);
  144. Cr = PALETTEINDEX(index);
  145. x = __GL_UNBIAS_X(gc, frag->x);
  146. y = __GL_UNBIAS_Y(gc, frag->y);
  147. if ( !(genGc->fsLocks & LOCKFLAG_FRONT_BUFFER) )
  148. SetPixel( CURRENT_DC, x, y, Cr );
  149. else
  150. dibSetPixelCI(genGc, cfb, x, y, index);
  151. }
  152. /*
  153. ** Dither, logicOp
  154. */
  155. static void FASTCALL Store_DL(__GLcolorBuffer *cfb, const __GLfragment *frag)
  156. {
  157. GLint x, y;
  158. __GLcontext *gc = cfb->buf.gc;
  159. __GLGENcontext *genGc = (__GLGENcontext *)gc;
  160. COLORREF Cr;
  161. DWORD index;
  162. DBGLEVEL(32, "Store_DL\n");
  163. index = (DWORD) (frag->color.r + __glHalf);
  164. Cr = PALETTEINDEX(index);
  165. x = __GL_UNBIAS_X(gc, frag->x);
  166. y = __GL_UNBIAS_Y(gc, frag->y);
  167. if ( !(genGc->fsLocks & LOCKFLAG_FRONT_BUFFER) )
  168. SetPixel( CURRENT_DC, x, y, Cr );
  169. else
  170. dibSetPixelCI(genGc, cfb, x, y, index);
  171. }
  172. GLuint FASTCALL ColorToIndex( __GLGENcontext *genGc, GLuint color )
  173. {
  174. int i, imax;
  175. GLuint *pTrans = (GLuint *) genGc->pajTranslateVector;
  176. color &= genGc->gc.modes.rgbMask;
  177. imax = *pTrans++; // first element of pTrans is # entries
  178. for( i=0; i<imax; i++ ) {
  179. if( color == *pTrans++ )
  180. return i;
  181. }
  182. return 0;
  183. }
  184. GLuint FASTCALL DoLogicOp( GLenum logicOp, GLuint SrcColor, GLuint DstColor )
  185. {
  186. GLuint result;
  187. switch (logicOp) {
  188. case GL_CLEAR: result = 0; break;
  189. case GL_AND: result = SrcColor & DstColor; break;
  190. case GL_AND_REVERSE: result = SrcColor & (~DstColor); break;
  191. case GL_COPY: result = SrcColor; break;
  192. case GL_AND_INVERTED: result = (~SrcColor) & DstColor; break;
  193. case GL_NOOP: result = DstColor; break;
  194. case GL_XOR: result = SrcColor ^ DstColor; break;
  195. case GL_OR: result = SrcColor | DstColor; break;
  196. case GL_NOR: result = ~(SrcColor | DstColor); break;
  197. case GL_EQUIV: result = ~(SrcColor ^ DstColor); break;
  198. case GL_INVERT: result = ~DstColor; break;
  199. case GL_OR_REVERSE: result = SrcColor | (~DstColor); break;
  200. case GL_COPY_INVERTED: result = ~SrcColor; break;
  201. case GL_OR_INVERTED: result = (~SrcColor) | DstColor; break;
  202. case GL_NAND: result = ~(SrcColor & DstColor); break;
  203. case GL_SET: result = (GLuint)~0; break;
  204. }
  205. return result;
  206. }
  207. /************************************************************************/
  208. void FASTCALL DIBIndex4CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  209. {
  210. GLint x, y;
  211. GLubyte *puj;
  212. __GLcontext *gc = cfb->buf.gc;
  213. __GLGENcontext *gengc;
  214. __GLfloat inc;
  215. GLuint enables = gc->state.enables.general;
  216. GLubyte index;
  217. gengc = (__GLGENcontext *)gc;
  218. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  219. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  220. inc = (enables & __GL_DITHER_ENABLE) ?
  221. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  222. if ( (cfb->buf.flags & NO_CLIP) ||
  223. (*gengc->pfnPixelVisible)(x, y) ) {
  224. index = (BYTE) (frag->color.r + inc);
  225. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  226. (y*cfb->buf.outerWidth) + (x >> 1));
  227. if( cfb->buf.flags & NEED_FETCH ) {
  228. GLubyte DstIndex;
  229. if (x & 1)
  230. DstIndex = gengc->pajInvTranslateVector[*puj & 0x0f];
  231. else
  232. DstIndex = gengc->pajInvTranslateVector[(*puj & 0xf0) >> 4];
  233. // apply logicop
  234. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  235. index = (GLubyte) DoLogicOp( gc->state.raster.logicOp,
  236. (GLuint) index, (GLuint) DstIndex );
  237. index &= 0xf;
  238. }
  239. // apply indexmask
  240. if( cfb->buf.flags & INDEXMASK_ON ) {
  241. index = (GLubyte)((index & cfb->sourceMask) | (DstIndex & cfb->destMask));
  242. }
  243. }
  244. index = gengc->pajTranslateVector[index & 0xf] & 0xf;
  245. if( x & 1 )
  246. *puj = (*puj & 0xf0) | index;
  247. else
  248. *puj = (*puj & 0x0f) | (index << 4);
  249. }
  250. }
  251. // Put fragment into created DIB and call copybits for one pixel
  252. void FASTCALL DisplayIndex4CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  253. {
  254. GLint x, y;
  255. GLubyte *puj;
  256. __GLcontext *gc = cfb->buf.gc;
  257. __GLGENcontext *gengc;
  258. __GLfloat inc;
  259. GLuint enables = gc->state.enables.general;
  260. GLubyte index;
  261. gengc = (__GLGENcontext *)gc;
  262. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  263. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  264. inc = (enables & __GL_DITHER_ENABLE) ?
  265. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  266. index = (BYTE) (frag->color.r + inc);
  267. puj = gengc->ColorsBits;
  268. if( cfb->buf.flags & NEED_FETCH ) {
  269. GLubyte DstIndex;
  270. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  271. DstIndex = gengc->pajInvTranslateVector[(*puj & 0xf0) >> 4];
  272. // apply logicop
  273. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  274. index = (GLubyte) DoLogicOp( gc->state.raster.logicOp,
  275. (GLuint) index, (GLuint) DstIndex );
  276. index &= 0xf;
  277. }
  278. // apply indexmask
  279. if( cfb->buf.flags & INDEXMASK_ON ) {
  280. index = (GLubyte)((index & cfb->sourceMask) | (DstIndex & cfb->destMask));
  281. }
  282. }
  283. *puj = gengc->pajTranslateVector[index & 0xf] << 4;
  284. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  285. }
  286. /************************************************************************/
  287. void FASTCALL DIBIndex8CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  288. {
  289. GLint x, y;
  290. GLubyte *puj;
  291. __GLcontext *gc = cfb->buf.gc;
  292. __GLGENcontext *gengc;
  293. __GLfloat inc;
  294. GLuint enables = gc->state.enables.general;
  295. GLubyte index;
  296. gengc = (__GLGENcontext *)gc;
  297. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  298. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  299. inc = (enables & __GL_DITHER_ENABLE) ?
  300. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  301. if ( (cfb->buf.flags & NO_CLIP) ||
  302. (*gengc->pfnPixelVisible)(x, y) ) {
  303. index = (BYTE) (frag->color.r + inc);
  304. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  305. if( cfb->buf.flags & NEED_FETCH ) {
  306. GLubyte DstIndex = gengc->pajInvTranslateVector[*puj];
  307. // apply logicop
  308. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  309. index = (GLubyte) DoLogicOp( gc->state.raster.logicOp,
  310. (GLuint) index, (GLuint) DstIndex );
  311. }
  312. // apply indexmask
  313. if( cfb->buf.flags & INDEXMASK_ON ) {
  314. index = (GLubyte)((DstIndex & cfb->destMask) | (index & cfb->sourceMask));
  315. }
  316. }
  317. *puj = gengc->pajTranslateVector[index];
  318. }
  319. }
  320. /************************************************************************/
  321. void FASTCALL DisplayIndex8CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  322. {
  323. GLint x, y;
  324. GLubyte *puj;
  325. __GLcontext *gc = cfb->buf.gc;
  326. __GLGENcontext *gengc;
  327. __GLfloat inc;
  328. GLuint enables = gc->state.enables.general;
  329. GLubyte index;
  330. gengc = (__GLGENcontext *)gc;
  331. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  332. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  333. inc = (enables & __GL_DITHER_ENABLE) ?
  334. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  335. index = (BYTE) (frag->color.r + inc);
  336. puj = gengc->ColorsBits;
  337. if( cfb->buf.flags & NEED_FETCH ) {
  338. GLubyte DstIndex;
  339. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  340. DstIndex = gengc->pajInvTranslateVector[*puj];
  341. // apply logicop
  342. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  343. index = (GLubyte) DoLogicOp( gc->state.raster.logicOp,
  344. (GLuint) index, (GLuint) DstIndex );
  345. }
  346. // apply indexmask
  347. if( cfb->buf.flags & INDEXMASK_ON ) {
  348. index = (GLubyte)((DstIndex & cfb->destMask) | (index & cfb->sourceMask));
  349. }
  350. }
  351. *puj = gengc->pajTranslateVector[index];
  352. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  353. }
  354. /************************************************************************/
  355. void FASTCALL DIBRGBCIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  356. {
  357. GLint x, y;
  358. GLubyte *puj;
  359. GLuint index;
  360. __GLcontext *gc = cfb->buf.gc;
  361. __GLGENcontext *gengc;
  362. GLuint enables = gc->state.enables.general;
  363. GLuint color, *pTrans;
  364. gengc = (__GLGENcontext *)gc;
  365. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  366. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  367. if ( (cfb->buf.flags & NO_CLIP) ||
  368. (*gengc->pfnPixelVisible)(x, y) ) {
  369. index = (GLuint) (frag->color.r + __glHalf);
  370. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  371. (y*cfb->buf.outerWidth) + (x * 3));
  372. pTrans = ((GLuint *) gengc->pajTranslateVector) + 1;
  373. if( cfb->buf.flags & NEED_FETCH ) {
  374. GLuint DstIndex; // represents both RGB and index
  375. Copy3Bytes( &DstIndex, puj );
  376. DstIndex = ColorToIndex( gengc, DstIndex );
  377. // apply logicop
  378. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  379. index = (GLuint) DoLogicOp( gc->state.raster.logicOp,
  380. (GLuint) index, (GLuint) DstIndex);
  381. }
  382. // apply indexmask
  383. if( cfb->buf.flags & INDEXMASK_ON ) {
  384. index = ((GLuint) DstIndex & cfb->destMask) |
  385. (index & cfb->sourceMask);
  386. }
  387. }
  388. index &= cfb->redMax; // ceiling
  389. color = pTrans[index]; // guaranteed to be in range
  390. Copy3Bytes( puj, &color );
  391. }
  392. }
  393. /************************************************************************/
  394. void FASTCALL DisplayRGBCIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  395. {
  396. GLint x, y;
  397. GLubyte *puj;
  398. GLuint index, color, *pTrans;
  399. __GLcontext *gc = cfb->buf.gc;
  400. __GLGENcontext *gengc;
  401. GLuint enables = gc->state.enables.general;
  402. gengc = (__GLGENcontext *)gc;
  403. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  404. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  405. index = (GLuint) (frag->color.r + __glHalf);
  406. puj = gengc->ColorsBits;
  407. pTrans = (GLuint *) gengc->pajTranslateVector;
  408. if( cfb->buf.flags & NEED_FETCH ) {
  409. GLuint DstIndex; // represents both RGB and index
  410. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  411. Copy3Bytes( &DstIndex, puj );
  412. DstIndex = ColorToIndex( gengc, DstIndex );
  413. // apply logicop
  414. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  415. index = (GLuint) DoLogicOp( gc->state.raster.logicOp,
  416. (GLuint) index, (GLuint) DstIndex );
  417. }
  418. // apply indexmask
  419. if( cfb->buf.flags & INDEXMASK_ON ) {
  420. index = ((GLuint) DstIndex & cfb->destMask) |
  421. (index & cfb->sourceMask);
  422. }
  423. }
  424. // Get RGB values that correspond to index
  425. index &= cfb->redMax; // ceiling
  426. color = pTrans[index+1]; // guaranteed to be in range
  427. Copy3Bytes( puj, &color );
  428. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  429. }
  430. /************************************************************************/
  431. void FASTCALL DIBBitfield16CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  432. {
  433. GLint x, y;
  434. GLushort index, *pus;
  435. GLuint *pTrans;
  436. __GLcontext *gc = cfb->buf.gc;
  437. __GLGENcontext *gengc;
  438. __GLfloat inc;
  439. GLuint enables = gc->state.enables.general;
  440. gengc = (__GLGENcontext *)gc;
  441. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  442. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  443. inc = (enables & __GL_DITHER_ENABLE) ?
  444. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  445. if ( (cfb->buf.flags & NO_CLIP) ||
  446. (*gengc->pfnPixelVisible)(x, y) ) {
  447. index = (GLushort) (frag->color.r + inc);
  448. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  449. (y*cfb->buf.outerWidth) + (x << 1));
  450. pTrans = (GLuint *) gengc->pajTranslateVector;
  451. if( cfb->buf.flags & NEED_FETCH ) {
  452. GLushort DstIndex; // represents both RGB and index
  453. DstIndex = *pus;
  454. DstIndex = (GLushort) ColorToIndex( gengc, (GLuint) DstIndex );
  455. // apply logicop
  456. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  457. index = (GLushort) DoLogicOp( gc->state.raster.logicOp,
  458. (GLuint) index, (GLuint) DstIndex);
  459. }
  460. // apply indexmask
  461. if( cfb->buf.flags & INDEXMASK_ON ) {
  462. index = (GLushort)((DstIndex & cfb->destMask) | (index & cfb->sourceMask));
  463. }
  464. }
  465. index &= cfb->redMax;
  466. *pus = (GLushort) pTrans[index+1];
  467. }
  468. }
  469. // Put fragment into created DIB and call copybits for one pixel
  470. void FASTCALL DisplayBitfield16CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  471. {
  472. GLint x, y;
  473. GLushort index, *pus;
  474. GLuint *pTrans;
  475. __GLcontext *gc = cfb->buf.gc;
  476. __GLGENcontext *gengc;
  477. __GLfloat inc;
  478. GLuint enables = gc->state.enables.general;
  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. inc = (enables & __GL_DITHER_ENABLE) ?
  483. fDitherIncTable[__GL_DITHER_INDEX(frag->x, frag->y)] : __glHalf;
  484. index = (GLushort) (frag->color.r + inc);
  485. pus = gengc->ColorsBits;
  486. pTrans = (GLuint *) gengc->pajTranslateVector;
  487. if( cfb->buf.flags & NEED_FETCH ) {
  488. GLushort DstIndex; // represents both RGB and index
  489. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  490. DstIndex = *pus;
  491. DstIndex = (GLushort) ColorToIndex( gengc, (GLuint) DstIndex );
  492. // apply logicop
  493. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  494. index = (GLushort) DoLogicOp( gc->state.raster.logicOp,
  495. (GLuint) index, (GLuint) DstIndex);
  496. }
  497. // apply indexmask
  498. if( cfb->buf.flags & INDEXMASK_ON ) {
  499. index = (GLushort)((DstIndex & cfb->destMask) | (index & cfb->sourceMask));
  500. }
  501. }
  502. index &= cfb->redMax;
  503. *pus = (GLushort) pTrans[index+1];
  504. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  505. }
  506. /************************************************************************/
  507. void FASTCALL DIBBitfield32CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  508. {
  509. GLint x, y;
  510. GLuint index, *pul, *pTrans;
  511. __GLcontext *gc = cfb->buf.gc;
  512. __GLGENcontext *gengc;
  513. GLuint enables = gc->state.enables.general;
  514. gengc = (__GLGENcontext *)gc;
  515. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  516. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  517. if ( (cfb->buf.flags & NO_CLIP) ||
  518. (*gengc->pfnPixelVisible)(x, y) ) {
  519. index = (GLuint) (frag->color.r + __glHalf);
  520. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  521. (y*cfb->buf.outerWidth) + (x << 2));
  522. pTrans = ((GLuint *) gengc->pajTranslateVector) + 1;
  523. if( cfb->buf.flags & NEED_FETCH ) {
  524. GLuint DstIndex; // represents both RGB and index
  525. DstIndex = ColorToIndex( gengc, *pul );
  526. // apply logicop
  527. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  528. index = (GLuint) DoLogicOp( gc->state.raster.logicOp, index,
  529. DstIndex );
  530. }
  531. // apply indexmask
  532. if( cfb->buf.flags & INDEXMASK_ON ) {
  533. index = (GLuint)((DstIndex & cfb->destMask) | (index & cfb->sourceMask));
  534. }
  535. }
  536. index &= cfb->redMax;
  537. *pul = pTrans[index];
  538. }
  539. }
  540. // Put fragment into created DIB and call copybits for one pixel
  541. void FASTCALL DisplayBitfield32CIStore(__GLcolorBuffer *cfb, const __GLfragment *frag)
  542. {
  543. GLint x, y;
  544. GLuint index, *pul, *pTrans;
  545. __GLcontext *gc = cfb->buf.gc;
  546. __GLGENcontext *gengc;
  547. GLuint enables = gc->state.enables.general;
  548. gengc = (__GLGENcontext *)gc;
  549. x = __GL_UNBIAS_X(gc, frag->x) + cfb->buf.xOrigin;
  550. y = __GL_UNBIAS_Y(gc, frag->y) + cfb->buf.yOrigin;
  551. index = (GLuint) (frag->color.r + __glHalf);
  552. pul = gengc->ColorsBits;
  553. pTrans = ((GLuint *) gengc->pajTranslateVector) + 1;
  554. if( cfb->buf.flags & NEED_FETCH ) {
  555. GLuint DstIndex; // represents both RGB and index
  556. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  557. DstIndex = ColorToIndex( gengc, *pul );
  558. // apply logicop
  559. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  560. index = (GLuint) DoLogicOp( gc->state.raster.logicOp, index,
  561. DstIndex );
  562. }
  563. // apply indexmask
  564. if( cfb->buf.flags & INDEXMASK_ON ) {
  565. index = (DstIndex & cfb->destMask) | (index & cfb->sourceMask);
  566. }
  567. }
  568. index &= cfb->redMax;
  569. *pul = pTrans[index];
  570. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, TRUE);
  571. }
  572. /************************************************************************/
  573. static GLboolean FASTCALL SlowStoreSpan(__GLcontext *gc)
  574. {
  575. int x, x1;
  576. int i;
  577. __GLfragment frag;
  578. __GLcolor *cp;
  579. __GLcolorBuffer *cfb;
  580. GLint w;
  581. DBGENTRY("CI:StoreSpan\n");
  582. w = gc->polygon.shader.length;
  583. frag.y = gc->polygon.shader.frag.y;
  584. x = gc->polygon.shader.frag.x;
  585. x1 = gc->polygon.shader.frag.x + w;
  586. cp = gc->polygon.shader.colors;
  587. cfb = gc->polygon.shader.cfb;
  588. for (i = x; i < x1; i++) {
  589. frag.x = i;
  590. frag.color.r = cp->r;
  591. cp++;
  592. (*cfb->store)(cfb, &frag);
  593. }
  594. return GL_FALSE;
  595. }
  596. static GLboolean FASTCALL SlowStoreStippledSpan(__GLcontext *gc)
  597. {
  598. int x;
  599. __GLfragment frag;
  600. __GLcolor *cp;
  601. __GLcolorBuffer *cfb;
  602. __GLstippleWord inMask, bit, *sp;
  603. GLint count;
  604. GLint w;
  605. DBGENTRY("CI:StoreStippledSpan\n");
  606. w = gc->polygon.shader.length;
  607. sp = gc->polygon.shader.stipplePat;
  608. frag.y = gc->polygon.shader.frag.y;
  609. x = gc->polygon.shader.frag.x;
  610. cp = gc->polygon.shader.colors;
  611. cfb = gc->polygon.shader.cfb;
  612. while (w) {
  613. count = w;
  614. if (count > __GL_STIPPLE_BITS) {
  615. count = __GL_STIPPLE_BITS;
  616. }
  617. w -= count;
  618. inMask = *sp++;
  619. bit = (GLuint) __GL_STIPPLE_SHIFT(0);
  620. while (--count >= 0) {
  621. if (inMask & bit) {
  622. frag.x = x;
  623. frag.color.r = cp->r;
  624. (*cfb->store)(cfb, &frag);
  625. }
  626. x++;
  627. cp++;
  628. #ifdef __GL_STIPPLE_MSB
  629. bit >>= 1;
  630. #else
  631. bit <<= 1;
  632. #endif
  633. }
  634. }
  635. return GL_FALSE;
  636. }
  637. void
  638. CIFetchNone(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  639. {
  640. result->r = 0.0F;
  641. }
  642. void
  643. CIReadSpanNone(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  644. GLint w)
  645. {
  646. GLint i;
  647. __GLcolor *pResults;
  648. for (i = 0, pResults = results; i < w; i++, pResults++)
  649. {
  650. pResults->r = 0.0F;
  651. }
  652. }
  653. void
  654. DIBIndex4CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  655. {
  656. __GLcontext *gc = cfb->buf.gc;
  657. __GLGENcontext *gengc;
  658. GLubyte *puj, pixel;
  659. gengc = (__GLGENcontext *)gc;
  660. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  661. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  662. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  663. (y*cfb->buf.outerWidth) + (x >> 1));
  664. pixel = *puj;
  665. if (!(x & 1))
  666. pixel >>= 4;
  667. result->r = (__GLfloat) gengc->pajInvTranslateVector[pixel & 0xf];
  668. }
  669. void
  670. DIBIndex8CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  671. {
  672. __GLcontext *gc = cfb->buf.gc;
  673. __GLGENcontext *gengc;
  674. GLubyte *puj;
  675. gengc = (__GLGENcontext *)gc;
  676. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  677. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  678. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  679. result->r = (__GLfloat) gengc->pajInvTranslateVector[*puj];
  680. }
  681. void
  682. DIBRGBCIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  683. {
  684. __GLcontext *gc = cfb->buf.gc;
  685. __GLGENcontext *gengc;
  686. GLubyte *puj;
  687. GLuint iColor;
  688. gengc = (__GLGENcontext *)gc;
  689. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  690. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  691. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  692. (y*cfb->buf.outerWidth) + (x * 3));
  693. Copy3Bytes( &iColor, puj );
  694. result->r = (float) ColorToIndex( gengc, iColor );
  695. }
  696. void
  697. DIBBitfield16CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  698. {
  699. __GLcontext *gc = cfb->buf.gc;
  700. __GLGENcontext *gengc;
  701. GLushort *pus;
  702. GLuint iColor;
  703. gengc = (__GLGENcontext *)gc;
  704. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  705. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  706. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  707. (y*cfb->buf.outerWidth) + (x << 1));
  708. iColor = (GLuint) *pus;
  709. result->r = (float) ColorToIndex( gengc, iColor );
  710. }
  711. void
  712. DIBBitfield32CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  713. {
  714. __GLcontext *gc = cfb->buf.gc;
  715. __GLGENcontext *gengc;
  716. GLuint *pul;
  717. GLuint iColor;
  718. gengc = (__GLGENcontext *)gc;
  719. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  720. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  721. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  722. (y*cfb->buf.outerWidth) + (x << 2));
  723. iColor = *pul; // need to clamp to <= 24 bits ?
  724. result->r = (float) ColorToIndex( gengc, iColor );
  725. }
  726. void
  727. DisplayIndex4CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  728. {
  729. __GLcontext *gc = cfb->buf.gc;
  730. __GLGENcontext *gengc;
  731. GLubyte *puj, pixel;
  732. gengc = (__GLGENcontext *)gc;
  733. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  734. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  735. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  736. puj = gengc->ColorsBits;
  737. pixel = *puj >> 4;
  738. result->r = (__GLfloat) gengc->pajInvTranslateVector[pixel];
  739. }
  740. void
  741. DisplayIndex8CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  742. {
  743. __GLcontext *gc = cfb->buf.gc;
  744. __GLGENcontext *gengc;
  745. GLubyte *puj;
  746. gengc = (__GLGENcontext *)gc;
  747. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  748. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  749. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  750. puj = gengc->ColorsBits;
  751. result->r = (__GLfloat) gengc->pajInvTranslateVector[*puj];
  752. }
  753. void
  754. DisplayRGBCIFetch(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *result)
  755. {
  756. __GLcontext *gc = cfb->buf.gc;
  757. __GLGENcontext *gengc;
  758. GLubyte *puj;
  759. GLuint iColor;
  760. gengc = (__GLGENcontext *)gc;
  761. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  762. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  763. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  764. puj = gengc->ColorsBits;
  765. Copy3Bytes( &iColor, puj );
  766. result->r = (float) ColorToIndex( gengc, iColor );
  767. }
  768. void
  769. DisplayBitfield16CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  770. __GLcolor *result)
  771. {
  772. __GLcontext *gc = cfb->buf.gc;
  773. __GLGENcontext *gengc;
  774. GLushort *pus;
  775. GLuint iColor;
  776. gengc = (__GLGENcontext *)gc;
  777. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  778. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  779. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  780. pus = gengc->ColorsBits;
  781. iColor = (GLuint) *pus;
  782. result->r = (float) ColorToIndex( gengc, iColor );
  783. }
  784. void
  785. DisplayBitfield32CIFetch(__GLcolorBuffer *cfb, GLint x, GLint y,
  786. __GLcolor *result)
  787. {
  788. __GLcontext *gc = cfb->buf.gc;
  789. __GLGENcontext *gengc;
  790. GLuint *pul;
  791. GLuint iColor;
  792. gengc = (__GLGENcontext *)gc;
  793. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  794. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  795. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, 1, FALSE);
  796. pul = gengc->ColorsBits;
  797. iColor = *pul; // need to clamp to <= 24 bits ?
  798. result->r = (float) ColorToIndex( gengc, iColor );
  799. }
  800. void
  801. Index4CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  802. GLint w, GLboolean bDIB)
  803. {
  804. __GLcontext *gc = cfb->buf.gc;
  805. __GLGENcontext *gengc;
  806. GLubyte *puj, pixel;
  807. __GLcolor *pResults;
  808. gengc = (__GLGENcontext *)gc;
  809. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  810. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  811. if (bDIB)
  812. {
  813. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) +
  814. (x >> 1));
  815. }
  816. else
  817. {
  818. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  819. puj = gengc->ColorsBits;
  820. x = 0;
  821. }
  822. pResults = results;
  823. if (x & 1)
  824. {
  825. pixel = *puj++;
  826. pResults->r = (__GLfloat) gengc->pajInvTranslateVector[pixel & 0xf];
  827. pResults++;
  828. w--;
  829. }
  830. while (w > 1)
  831. {
  832. pixel = *puj >> 4;
  833. pResults->r = (__GLfloat) gengc->pajInvTranslateVector[pixel];
  834. pResults++;
  835. pixel = *puj++;
  836. pResults->r = (__GLfloat) gengc->pajInvTranslateVector[pixel & 0xf];
  837. pResults++;
  838. w -= 2;
  839. }
  840. if (w > 0)
  841. {
  842. pixel = *puj >> 4;
  843. pResults->r = (__GLfloat) gengc->pajInvTranslateVector[pixel];
  844. }
  845. }
  846. void
  847. DIBIndex4CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  848. GLint w)
  849. {
  850. Index4CIReadSpan(cfb, x, y, results, w, TRUE);
  851. }
  852. void
  853. DisplayIndex4CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  854. __GLcolor *results, GLint w)
  855. {
  856. Index4CIReadSpan(cfb, x, y, results, w, FALSE);
  857. }
  858. void
  859. Index8CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  860. GLint w, GLboolean bDIB)
  861. {
  862. __GLcontext *gc = cfb->buf.gc;
  863. __GLGENcontext *gengc;
  864. GLubyte *puj;
  865. GLint i;
  866. __GLcolor *pResults;
  867. gengc = (__GLGENcontext *)gc;
  868. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  869. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  870. if (bDIB)
  871. {
  872. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base + (y*cfb->buf.outerWidth) + x);
  873. }
  874. else
  875. {
  876. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  877. puj = gengc->ColorsBits;
  878. }
  879. for (i = 0, pResults = results; i < w; i++, pResults++)
  880. {
  881. pResults->r = (__GLfloat) gengc->pajInvTranslateVector[*puj++];
  882. }
  883. }
  884. void
  885. DIBIndex8CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  886. GLint w)
  887. {
  888. Index8CIReadSpan(cfb, x, y, results, w, TRUE);
  889. }
  890. void
  891. DisplayIndex8CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  892. __GLcolor *results, GLint w)
  893. {
  894. Index8CIReadSpan(cfb, x, y, results, w, FALSE);
  895. }
  896. void
  897. RGBCIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  898. GLint w, GLboolean bDIB)
  899. {
  900. __GLcontext *gc = cfb->buf.gc;
  901. __GLGENcontext *gengc;
  902. GLubyte *puj;
  903. GLint i;
  904. __GLcolor *pResults;
  905. GLuint iColor;
  906. gengc = (__GLGENcontext *)gc;
  907. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  908. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  909. if (bDIB)
  910. {
  911. puj = (GLubyte *)((ULONG_PTR)cfb->buf.base +
  912. (y*cfb->buf.outerWidth) + (x * 3));
  913. }
  914. else
  915. {
  916. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  917. puj = gengc->ColorsBits;
  918. }
  919. for (i = 0, pResults = results; i < w; i++, pResults++, puj += 3)
  920. {
  921. Copy3Bytes( &iColor, puj );
  922. pResults->r = (float) ColorToIndex( gengc, iColor );
  923. }
  924. }
  925. void
  926. DIBRGBCIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  927. GLint w)
  928. {
  929. RGBCIReadSpan(cfb, x, y, results, w, TRUE);
  930. }
  931. void
  932. DisplayRGBCIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y, __GLcolor *results,
  933. GLint w)
  934. {
  935. RGBCIReadSpan(cfb, x, y, results, w, FALSE);
  936. }
  937. void
  938. Bitfield16CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  939. __GLcolor *results, GLint w, GLboolean bDIB)
  940. {
  941. __GLcontext *gc = cfb->buf.gc;
  942. __GLGENcontext *gengc;
  943. GLushort *pus;
  944. GLint i;
  945. __GLcolor *pResults;
  946. GLuint iColor;
  947. gengc = (__GLGENcontext *)gc;
  948. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  949. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  950. if (bDIB)
  951. {
  952. pus = (GLushort *)((ULONG_PTR)cfb->buf.base +
  953. (y*cfb->buf.outerWidth) + (x << 1));
  954. }
  955. else
  956. {
  957. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  958. pus = gengc->ColorsBits;
  959. }
  960. for (i = 0, pResults = results; i < w; i++, pResults++)
  961. {
  962. iColor = *pus++;
  963. pResults->r = (__GLfloat) ColorToIndex( gengc, iColor );
  964. }
  965. }
  966. void
  967. DIBBitfield16CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  968. __GLcolor *results, GLint w)
  969. {
  970. Bitfield16CIReadSpan(cfb, x, y, results, w, TRUE);
  971. }
  972. void
  973. DisplayBitfield16CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  974. __GLcolor *results, GLint w)
  975. {
  976. Bitfield16CIReadSpan(cfb, x, y, results, w, FALSE);
  977. }
  978. void
  979. Bitfield32CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  980. __GLcolor *results, GLint w, GLboolean bDIB)
  981. {
  982. __GLcontext *gc = cfb->buf.gc;
  983. __GLGENcontext *gengc;
  984. GLuint *pul;
  985. GLint i;
  986. __GLcolor *pResults;
  987. GLuint iColor;
  988. gengc = (__GLGENcontext *)gc;
  989. x = __GL_UNBIAS_X(gc, x) + cfb->buf.xOrigin;
  990. y = __GL_UNBIAS_Y(gc, y) + cfb->buf.yOrigin;
  991. if (bDIB)
  992. {
  993. pul = (GLuint *)((ULONG_PTR)cfb->buf.base +
  994. (y*cfb->buf.outerWidth) + (x << 2));
  995. }
  996. else
  997. {
  998. (*gengc->pfnCopyPixels)(gengc, cfb, x, y, w, FALSE);
  999. pul = gengc->ColorsBits;
  1000. }
  1001. for (i = 0, pResults = results; i < w; i++, pResults++)
  1002. {
  1003. iColor = *pul++;
  1004. pResults->r = (__GLfloat) ColorToIndex( gengc, iColor );
  1005. }
  1006. }
  1007. void
  1008. DIBBitfield32CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  1009. __GLcolor *results, GLint w)
  1010. {
  1011. Bitfield32CIReadSpan(cfb, x, y, results, w, TRUE);
  1012. }
  1013. void
  1014. DisplayBitfield32CIReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  1015. __GLcolor *results, GLint w)
  1016. {
  1017. Bitfield32CIReadSpan(cfb, x, y, results, w, FALSE);
  1018. }
  1019. /************************************************************************/
  1020. static void Resize(__GLGENbuffers *buffers, __GLcolorBuffer *cfb,
  1021. GLint w, GLint h)
  1022. {
  1023. DBGENTRY("CI:Resize\n");
  1024. #ifdef __GL_LINT
  1025. dp = dp;
  1026. #endif
  1027. cfb->buf.width = w;
  1028. cfb->buf.height = h;
  1029. }
  1030. /************************************************************************/
  1031. static void (FASTCALL *StoreProcs[4])(__GLcolorBuffer*, const __GLfragment*) = {
  1032. Store,
  1033. Store_D,
  1034. Store_L,
  1035. Store_DL,
  1036. };
  1037. void FASTCALL PickCI(__GLcontext *gc, __GLcolorBuffer *cfb)
  1038. {
  1039. GLuint enables = gc->state.enables.general;
  1040. GLint ix = 0;
  1041. __GLGENcontext *gengc;
  1042. PIXELFORMATDESCRIPTOR *pfmt;
  1043. GLboolean needFetch = GL_FALSE;
  1044. DBGENTRY("PickCI\n");
  1045. /* predetermine if fetch required for Store procs: we'll assume
  1046. always need to if logicOp or indexMask (i.e: assume if needFetch
  1047. not set, then no logicOp or indexMask used)
  1048. */
  1049. if( gc->state.raster.writeMask == cfb->redMax ) {
  1050. cfb->buf.flags = cfb->buf.flags & ~INDEXMASK_ON;
  1051. cfb->sourceMask = cfb->redMax; // mf: these 2 may not be needed
  1052. cfb->destMask = ~cfb->sourceMask;
  1053. } else {
  1054. cfb->sourceMask = gc->state.raster.writeMask & cfb->redMax;
  1055. cfb->destMask = ~cfb->sourceMask & cfb->redMax;
  1056. cfb->buf.flags = cfb->buf.flags | INDEXMASK_ON;
  1057. needFetch = GL_TRUE;
  1058. }
  1059. if (enables & __GL_DITHER_ENABLE) {
  1060. ix |= 1;
  1061. }
  1062. if (enables & __GL_INDEX_LOGIC_OP_ENABLE) {
  1063. ix |= 2;
  1064. needFetch = GL_TRUE; // don't need to fetch for some logicOps, but
  1065. // we'll deal with that later
  1066. }
  1067. if( needFetch )
  1068. cfb->buf.flags = cfb->buf.flags | NEED_FETCH;
  1069. else
  1070. cfb->buf.flags = cfb->buf.flags & ~NEED_FETCH;
  1071. cfb->store = StoreProcs[ix];
  1072. // Figure out store and fetch routines
  1073. if (gc->state.raster.drawBuffer == GL_NONE)
  1074. {
  1075. cfb->store = Store_NOT;
  1076. cfb->fetch = CIFetchNone;
  1077. cfb->readColor = CIFetchNone;
  1078. cfb->readSpan = CIReadSpanNone;
  1079. cfb->storeSpan = StoreSpanNone;
  1080. cfb->storeStippledSpan = StoreSpanNone;
  1081. }
  1082. else
  1083. {
  1084. gengc = (__GLGENcontext *)gc;
  1085. pfmt = &gengc->gsurf.pfd;
  1086. if (cfb->buf.flags & DIB_FORMAT)
  1087. {
  1088. switch(pfmt->cColorBits) {
  1089. case 4:
  1090. cfb->fetch = DIBIndex4CIFetch;
  1091. cfb->readColor = DIBIndex4CIFetch;
  1092. cfb->readSpan = DIBIndex4CIReadSpan;
  1093. cfb->store = DIBIndex4CIStore;
  1094. cfb->clear = Index4Clear;
  1095. break;
  1096. case 8:
  1097. cfb->fetch = DIBIndex8CIFetch;
  1098. cfb->readColor = DIBIndex8CIFetch;
  1099. cfb->readSpan = DIBIndex8CIReadSpan;
  1100. cfb->store = DIBIndex8CIStore;
  1101. cfb->clear = Index8Clear;
  1102. break;
  1103. case 16:
  1104. cfb->fetch = DIBBitfield16CIFetch;
  1105. cfb->readColor = DIBBitfield16CIFetch;
  1106. cfb->readSpan = DIBBitfield16CIReadSpan;
  1107. cfb->store = DIBBitfield16CIStore;
  1108. cfb->clear = Bitfield16Clear;
  1109. break;
  1110. case 24:
  1111. cfb->readSpan = DIBRGBCIReadSpan;
  1112. cfb->readColor = DIBRGBCIFetch;
  1113. cfb->fetch = DIBRGBCIFetch;
  1114. cfb->store = DIBRGBCIStore;
  1115. cfb->clear = RGBClear;
  1116. break;
  1117. case 32:
  1118. cfb->fetch = DIBBitfield32CIFetch;
  1119. cfb->readColor = DIBBitfield32CIFetch;
  1120. cfb->readSpan = DIBBitfield32CIReadSpan;
  1121. cfb->store = DIBBitfield32CIStore;
  1122. cfb->clear = Bitfield32Clear;
  1123. break;
  1124. }
  1125. }
  1126. else
  1127. {
  1128. switch(pfmt->cColorBits) {
  1129. case 4:
  1130. cfb->fetch = DisplayIndex4CIFetch;
  1131. cfb->readColor = DisplayIndex4CIFetch;
  1132. cfb->readSpan = DisplayIndex4CIReadSpan;
  1133. cfb->store = DisplayIndex4CIStore;
  1134. cfb->clear = Index4Clear;
  1135. break;
  1136. case 8:
  1137. cfb->fetch = DisplayIndex8CIFetch;
  1138. cfb->readColor = DisplayIndex8CIFetch;
  1139. cfb->readSpan = DisplayIndex8CIReadSpan;
  1140. cfb->store = DisplayIndex8CIStore;
  1141. cfb->clear = Index8Clear;
  1142. break;
  1143. case 16:
  1144. cfb->fetch = DisplayBitfield16CIFetch;
  1145. cfb->readColor = DisplayBitfield16CIFetch;
  1146. cfb->readSpan = DisplayBitfield16CIReadSpan;
  1147. cfb->store = DisplayBitfield16CIStore;
  1148. cfb->clear = Bitfield16Clear;
  1149. break;
  1150. case 24:
  1151. cfb->readSpan = DisplayRGBCIReadSpan;
  1152. cfb->fetch = DisplayRGBCIFetch;
  1153. cfb->readColor = DisplayRGBCIFetch;
  1154. cfb->store = DisplayRGBCIStore;
  1155. cfb->clear = RGBClear;
  1156. break;
  1157. case 32:
  1158. cfb->fetch = DisplayBitfield32CIFetch;
  1159. cfb->readColor = DisplayBitfield32CIFetch;
  1160. cfb->readSpan = DisplayBitfield32CIReadSpan;
  1161. cfb->store = DisplayBitfield32CIStore;
  1162. cfb->clear = Bitfield32Clear;
  1163. break;
  1164. }
  1165. }
  1166. }
  1167. }
  1168. void FASTCALL __glGenInitCI(__GLcontext *gc, __GLcolorBuffer *cfb, GLenum type)
  1169. {
  1170. __GLGENcontext *gengc = (__GLGENcontext *)gc;
  1171. PIXELFORMATDESCRIPTOR *pfmt;
  1172. DBGENTRY("__glGenInitCI\n");
  1173. __glInitGenericCB(gc, cfb);
  1174. cfb->pick = PickCI;
  1175. gc->redVertexScale = cfb->redScale = (__GLfloat)1.0;
  1176. gc->greenVertexScale = cfb->greenScale = (__GLfloat)1.0;
  1177. gc->blueVertexScale = cfb->blueScale = (__GLfloat)1.0;
  1178. gc->alphaVertexScale = cfb->alphaScale = (__GLfloat)1.0;
  1179. cfb->buf.elementSize = sizeof(GLubyte);
  1180. cfb->resize = Resize;
  1181. cfb->fetchSpan = __glFetchSpan;
  1182. cfb->fetchStippledSpan = __glFetchSpan;
  1183. cfb->storeSpan = SlowStoreSpan;
  1184. cfb->storeStippledSpan = SlowStoreStippledSpan;
  1185. pfmt = &gengc->gsurf.pfd;
  1186. /* XXX! redMax is used for index lighting in soft, and for setting
  1187. raster.writeMask
  1188. */
  1189. cfb->redMax = (1 << gc->modes.indexBits) - 1;
  1190. cfb->redShift = pfmt->cRedShift;
  1191. cfb->greenShift = pfmt->cGreenShift;
  1192. cfb->blueShift = pfmt->cBlueShift;
  1193. cfb->allShifts =
  1194. (cfb->redShift << 0) |
  1195. (cfb->greenShift << 8) |
  1196. (cfb->blueShift << 16) |
  1197. (cfb->alphaShift << 24);
  1198. glGenInitCommon(gengc, cfb, type);
  1199. }
  1200. void FASTCALL __glGenFreeCI(__GLcontext *gc, __GLcolorBuffer *cfb)
  1201. {
  1202. DBGENTRY("__glGenFreeCI\n");
  1203. #ifdef __GL_LINT
  1204. gc = gc;
  1205. cfb = cfb;
  1206. #endif
  1207. }