Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

459 lines
12 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: span_t.h *
  3. * *
  4. * This include file is used to generate various flavors of textured *
  5. * spans, or scanlines. The variations cover only RGB operation, *
  6. * dithering, and pixel-depth. Not your typical include file. *
  7. * *
  8. * Created: 11-April-1994 *
  9. * Author: Otto Berkes [ottob] *
  10. * *
  11. * Copyright (c) 1994 Microsoft Corporation *
  12. \**************************************************************************/
  13. void
  14. #if DITHER
  15. #if (BPP == 8)
  16. __fastGenTex8DithSmoothSpan(__GLGENcontext *gengc)
  17. #elif (BPP == 16)
  18. __fastGenTex16DithSmoothSpan(__GLGENcontext *gengc)
  19. #elif (BPP == 24)
  20. __fastGenTex24DithSmoothSpan(__GLGENcontext *gengc)
  21. #else
  22. __fastGenTex32DithSmoothSpan(__GLGENcontext *gengc)
  23. #endif
  24. #else //!DITHER
  25. #if (BPP == 8)
  26. __fastGenTex8SmoothSpan(__GLGENcontext *gengc)
  27. #elif (BPP == 16)
  28. __fastGenTex16SmoothSpan(__GLGENcontext *gengc)
  29. #elif (BPP == 24)
  30. __fastGenTex24SmoothSpan(__GLGENcontext *gengc)
  31. #else
  32. __fastGenTex32SmoothSpan(__GLGENcontext *gengc)
  33. #endif
  34. #endif //!DITHER
  35. {
  36. ULONG rAccum;
  37. ULONG gAccum;
  38. ULONG bAccum;
  39. ULONG sAccum;
  40. ULONG tAccum;
  41. LONG rDelta;
  42. LONG gDelta;
  43. LONG bDelta;
  44. LONG sDelta;
  45. LONG tDelta;
  46. ULONG rShift;
  47. ULONG gShift;
  48. ULONG bShift;
  49. ULONG rtShift;
  50. ULONG gtShift;
  51. ULONG btShift;
  52. ULONG tShift;
  53. ULONG sMask, tMask;
  54. ULONG wLog2;
  55. ULONG hLog2;
  56. GENACCEL *pGenAccel;
  57. __GLcolorBuffer *cfb;
  58. BYTE *pPix;
  59. UCHAR *texAddr;
  60. USHORT *texBits;
  61. #if DITHER
  62. ULONG ditherVal;
  63. #endif
  64. #if (BPP == 8)
  65. BYTE *pXlat;
  66. #endif
  67. ULONG *pMask;
  68. #if DITHER
  69. ULONG ditherShift;
  70. ULONG ditherRow;
  71. #endif
  72. LONG count;
  73. LONG totalCount;
  74. __GLtexture *tex = ((__GLcontext *)gengc)->texture.currentTexture;
  75. wLog2 = tex->level[0].widthLog2;
  76. hLog2 = tex->level[0].heightLog2;
  77. sMask = (~(~0 << wLog2)) << 16;
  78. tMask = (~(~0 << hLog2)) << 16;
  79. tShift = 13 - wLog2;
  80. // get color deltas and accumulators
  81. pGenAccel = (GENACCEL *)(gengc->pPrivateArea);
  82. texAddr = (UCHAR *)pGenAccel->texImage;
  83. rDelta = pGenAccel->spanDelta.r;
  84. gDelta = pGenAccel->spanDelta.g;
  85. bDelta = pGenAccel->spanDelta.b;
  86. sDelta = pGenAccel->spanDelta.s;
  87. tDelta = pGenAccel->spanDelta.t;
  88. rAccum = pGenAccel->spanValue.r;
  89. gAccum = pGenAccel->spanValue.g;
  90. bAccum = pGenAccel->spanValue.b;
  91. sAccum = pGenAccel->spanValue.s;
  92. tAccum = pGenAccel->spanValue.t;
  93. cfb = gengc->gc.polygon.shader.cfb;
  94. rShift = cfb->redShift;
  95. gShift = cfb->greenShift;
  96. bShift = cfb->blueShift;
  97. #if DITHER
  98. rtShift = 8 + ((__GLcontext *)gengc)->modes.redBits;
  99. gtShift = 8 + ((__GLcontext *)gengc)->modes.greenBits;
  100. btShift = 8 + ((__GLcontext *)gengc)->modes.blueBits;
  101. #else
  102. rtShift = 16 + ((__GLcontext *)gengc)->modes.redBits;
  103. gtShift = 16 + ((__GLcontext *)gengc)->modes.greenBits;
  104. btShift = 16 + ((__GLcontext *)gengc)->modes.blueBits;
  105. #endif
  106. // get address of destination
  107. if (pGenAccel->flags & SURFACE_TYPE_DIB) {
  108. int xScr;
  109. int yScr;
  110. xScr = gengc->gc.polygon.shader.frag.x -
  111. gengc->gc.constants.viewportXAdjust +
  112. cfb->buf.xOrigin;
  113. yScr = gengc->gc.polygon.shader.frag.y -
  114. gengc->gc.constants.viewportYAdjust +
  115. cfb->buf.yOrigin;
  116. pPix = (BYTE *)cfb->buf.base + (yScr * cfb->buf.outerWidth) +
  117. #if (BPP == 8)
  118. xScr;
  119. #elif (BPP == 16)
  120. (xScr << 1);
  121. #elif (BPP == 24)
  122. xScr + (xScr << 1);
  123. #else
  124. (xScr << 2);
  125. #endif //BPP
  126. } else
  127. pPix = gengc->ColorsBits;
  128. // set up pointer to translation table as needed
  129. #if (BPP == 8)
  130. pXlat = gengc->pajTranslateVector;
  131. #endif
  132. #if DITHER
  133. ditherRow = Dither_4x4[gengc->gc.polygon.shader.frag.y & 0x3];
  134. ditherShift = (gengc->gc.polygon.shader.frag.x & 0x3) << 3;
  135. #endif
  136. pMask = gengc->gc.polygon.shader.stipplePat;
  137. if ((totalCount = count = gengc->gc.polygon.shader.length) > 32)
  138. count = 32;
  139. for (; totalCount > 0; totalCount -= 32) {
  140. ULONG mask;
  141. ULONG maskTest;
  142. if ((mask = *pMask++) == 0) {
  143. rAccum += (rDelta << 5);
  144. gAccum += (gDelta << 5);
  145. bAccum += (bDelta << 5);
  146. sAccum += (sDelta << 5);
  147. tAccum += (tDelta << 5);
  148. pPix += (32 * (BPP / 8));
  149. continue;
  150. }
  151. maskTest = 0x80000000;
  152. if ((count = totalCount) > 32)
  153. count = 32;
  154. for (; count; count--, maskTest >>= 1) {
  155. if (mask & maskTest) {
  156. DWORD color;
  157. texBits = (USHORT *)(texAddr + ((sAccum & sMask) >> 13) +
  158. ((tAccum & tMask) >> tShift));
  159. #if DITHER
  160. ditherVal = (ditherRow >> ditherShift) & 0xff;
  161. ditherShift = (ditherShift + 8) & 0x18;
  162. color =
  163. ((((((ULONG)texBits[0] * (rAccum >> 8)) >> rtShift) + ditherVal) >> 8) << rShift) |
  164. ((((((ULONG)texBits[1] * (gAccum >> 8)) >> gtShift) + ditherVal) >> 8) << gShift) |
  165. ((((((ULONG)texBits[2] * (bAccum >> 8)) >> btShift) + ditherVal) >> 8) << bShift);
  166. #else
  167. color =
  168. ((((ULONG)texBits[0] * (rAccum >> 8)) >> rtShift) << rShift) |
  169. ((((ULONG)texBits[1] * (gAccum >> 8)) >> gtShift) << gShift) |
  170. ((((ULONG)texBits[2] * (bAccum >> 8)) >> btShift) << bShift);
  171. #endif
  172. #if (BPP == 8)
  173. // XXX the color value should *not* have to be masked!
  174. color = *(pXlat + (color & 0xff));
  175. #endif
  176. #if (BPP == 8)
  177. *pPix = (BYTE)color;
  178. #elif (BPP == 16)
  179. *((WORD *)pPix) = (USHORT)color;
  180. #elif (BPP == 24)
  181. *pPix = (BYTE)color;
  182. *(pPix + 1) = (BYTE)(color >> 8);
  183. *(pPix + 2) = (BYTE)(color >> 16);
  184. #else
  185. *((DWORD *)pPix) = color;
  186. #endif //BPP
  187. }
  188. rAccum += rDelta;
  189. gAccum += gDelta;
  190. bAccum += bDelta;
  191. sAccum += sDelta;
  192. tAccum += tDelta;
  193. pPix += (BPP / 8);
  194. }
  195. }
  196. }
  197. void
  198. #if DITHER
  199. #if (BPP == 8)
  200. __fastGenTex8DithDecalSpan(__GLGENcontext *gengc)
  201. #elif (BPP == 16)
  202. __fastGenTex16DithDecalSpan(__GLGENcontext *gengc)
  203. #elif (BPP == 24)
  204. __fastGenTex24DithDecalSpan(__GLGENcontext *gengc)
  205. #else
  206. __fastGenTex32DithDecalSpan(__GLGENcontext *gengc)
  207. #endif
  208. #else //!DITHER
  209. #if (BPP == 8)
  210. __fastGenTex8DecalSpan(__GLGENcontext *gengc)
  211. #elif (BPP == 16)
  212. __fastGenTex16DecalSpan(__GLGENcontext *gengc)
  213. #elif (BPP == 24)
  214. __fastGenTex24DecalSpan(__GLGENcontext *gengc)
  215. #else
  216. __fastGenTex32DecalSpan(__GLGENcontext *gengc)
  217. #endif
  218. #endif //!DITHER
  219. {
  220. register ULONG sAccum;
  221. register ULONG tAccum;
  222. LONG sDelta;
  223. LONG tDelta;
  224. ULONG rShift;
  225. ULONG gShift;
  226. ULONG bShift;
  227. ULONG tShift;
  228. ULONG sMask, tMask;
  229. ULONG wLog2;
  230. ULONG hLog2;
  231. GENACCEL *pGenAccel;
  232. __GLcolorBuffer *cfb;
  233. BYTE *pPix;
  234. UCHAR *texAddr;
  235. USHORT *texBits;
  236. #if DITHER
  237. ULONG ditherVal;
  238. #endif
  239. #if (BPP == 8)
  240. BYTE *pXlat;
  241. #endif
  242. ULONG *pMask;
  243. #if DITHER
  244. ULONG ditherShift;
  245. ULONG ditherRow;
  246. #endif
  247. LONG count;
  248. LONG totalCount;
  249. __GLtexture *tex = ((__GLcontext *)gengc)->texture.currentTexture;
  250. wLog2 = tex->level[0].widthLog2;
  251. hLog2 = tex->level[0].heightLog2;
  252. sMask = (~(~0 << wLog2)) << 16;
  253. tMask = (~(~0 << hLog2)) << 16;
  254. tShift = 13 - wLog2;
  255. // get color deltas and accumulators
  256. pGenAccel = (GENACCEL *)(gengc->pPrivateArea);
  257. sDelta = pGenAccel->spanDelta.s;
  258. tDelta = pGenAccel->spanDelta.t;
  259. sAccum = pGenAccel->spanValue.s;
  260. tAccum = pGenAccel->spanValue.t;
  261. texAddr = (UCHAR *)pGenAccel->texImage;
  262. cfb = gengc->gc.polygon.shader.cfb;
  263. rShift = cfb->redShift;
  264. gShift = cfb->greenShift;
  265. bShift = cfb->blueShift;
  266. // get address of destination
  267. if (pGenAccel->flags & SURFACE_TYPE_DIB) {
  268. int xScr;
  269. int yScr;
  270. xScr = gengc->gc.polygon.shader.frag.x -
  271. gengc->gc.constants.viewportXAdjust +
  272. cfb->buf.xOrigin;
  273. yScr = gengc->gc.polygon.shader.frag.y -
  274. gengc->gc.constants.viewportYAdjust +
  275. cfb->buf.yOrigin;
  276. pPix = (BYTE *)cfb->buf.base + (yScr * cfb->buf.outerWidth) +
  277. #if (BPP == 8)
  278. xScr;
  279. #elif (BPP == 16)
  280. (xScr << 1);
  281. #elif (BPP == 24)
  282. xScr + (xScr << 1);
  283. #else
  284. (xScr << 2);
  285. #endif //BPP
  286. } else
  287. pPix = gengc->ColorsBits;
  288. // set up pointer to translation table as needed
  289. #if (BPP == 8)
  290. pXlat = gengc->pajTranslateVector;
  291. #endif
  292. #if DITHER
  293. ditherRow = Dither_4x4[gengc->gc.polygon.shader.frag.y & 0x3];
  294. ditherShift = (gengc->gc.polygon.shader.frag.x & 0x3) << 3;
  295. #endif
  296. pMask = gengc->gc.polygon.shader.stipplePat;
  297. if ((totalCount = count = gengc->gc.polygon.shader.length) > 32)
  298. count = 32;
  299. for (; totalCount > 0; totalCount -= 32) {
  300. ULONG mask;
  301. ULONG maskTest;
  302. if ((mask = *pMask++) == 0) {
  303. sAccum += (sDelta << 5);
  304. tAccum += (tDelta << 5);
  305. pPix += (32 * (BPP / 8));
  306. continue;
  307. }
  308. maskTest = 0x80000000;
  309. if ((count = totalCount) > 32)
  310. count = 32;
  311. for (; count; count--, maskTest >>= 1) {
  312. if (mask & maskTest) {
  313. #if (DITHER) || (BPP >= 24)
  314. DWORD color;
  315. #endif
  316. texBits = (USHORT *)(texAddr + ((sAccum & sMask) >> 13) +
  317. ((tAccum & tMask) >> tShift));
  318. #if DITHER
  319. ditherVal = ((ditherRow >> ditherShift) & 0xff);
  320. ditherShift = (ditherShift + 8) & 0x18;
  321. color =
  322. (((texBits[0] + ditherVal) >> 8) << rShift) |
  323. (((texBits[1] + ditherVal) >> 8) << gShift) |
  324. (((texBits[2] + ditherVal) >> 8) << bShift);
  325. #if (BPP == 8)
  326. // XXX the color value should *not* have to be masked!
  327. color = *(pXlat + (color & 0xff));
  328. *pPix = (BYTE)color;
  329. #elif (BPP == 16)
  330. *((WORD *)pPix) = (USHORT)color;
  331. #elif (BPP == 24)
  332. *pPix = (BYTE)color;
  333. *(pPix + 1) = (BYTE)(color >> 8);
  334. *(pPix + 2) = (BYTE)(color >> 16);
  335. #else
  336. *((DWORD *)pPix) = color;
  337. #endif //BPP
  338. #else //!DITHER
  339. #if (BPP == 8)
  340. *pPix = *((BYTE *)&texBits[3]);
  341. #elif (BPP == 16)
  342. *((WORD *)pPix) = *((WORD *)&texBits[3]);
  343. #elif (BPP == 24)
  344. color =
  345. ((texBits[0] >> 8) << rShift) |
  346. ((texBits[1] >> 8) << gShift) |
  347. ((texBits[2] >> 8) << bShift);
  348. *pPix = (BYTE)color;
  349. *(pPix + 1) = (BYTE)(color >> 8);
  350. *(pPix + 2) = (BYTE)(color >> 16);
  351. #else
  352. color =
  353. ((texBits[0] >> 8) << rShift) |
  354. ((texBits[1] >> 8) << gShift) |
  355. ((texBits[2] >> 8) << bShift);
  356. *((DWORD *)pPix) = color;
  357. #endif //BPP
  358. #endif //DITHER
  359. }
  360. sAccum += sDelta;
  361. tAccum += tDelta;
  362. pPix += (BPP / 8);
  363. }
  364. }
  365. }
  366. #if !DITHER
  367. #undef ditherVal
  368. #endif