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.

380 lines
9.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: texspan.h
  3. *
  4. * Main header file for textured spans.
  5. *
  6. * 22-Nov-1995 ottob Created
  7. *
  8. * Copyright (c) 1995 Microsoft Corporation
  9. \**************************************************************************/
  10. typedef LONG FIXED16;
  11. #define RMASK (((1 << RBITS) - 1) << RSHIFT)
  12. #define GMASK (((1 << GBITS) - 1) << GSHIFT)
  13. #define BMASK (((1 << BBITS) - 1) << BSHIFT)
  14. #if (REPLACE || FAST_REPLACE)
  15. #define RRIGHTSHIFTADJ (16 - (RSHIFT + RBITS))
  16. #define GRIGHTSHIFTADJ (16 - (GSHIFT + GBITS))
  17. #define BRIGHTSHIFTADJ (16 - (BSHIFT + BBITS))
  18. #else
  19. #define RRIGHTSHIFTADJ (16 - (RSHIFT))
  20. #define GRIGHTSHIFTADJ (16 - (GSHIFT))
  21. #define BRIGHTSHIFTADJ (16 - (BSHIFT))
  22. #endif
  23. #define S_SHIFT_PAL 16
  24. #define T_SHIFT_PAL 6
  25. #define TMASK_SUBDIV GENACCEL(gengc).tMaskSubDiv
  26. #define TSHIFT_SUBDIV GENACCEL(gengc).tShiftSubDiv
  27. #if (FAST_REPLACE)
  28. #define TEX_PALETTE GENACCEL(gengc).texImageReplace
  29. #if (PALETTE_ONLY)
  30. #define TEX_IMAGE GENACCEL(gengc).texImage
  31. #else
  32. #define TEX_IMAGE GENACCEL(gengc).texImageReplace
  33. #endif
  34. #if (PALETTE_ONLY)
  35. #define S_SHIFT S_SHIFT_PAL
  36. #define T_SHIFT 6
  37. #elif (BPP == 8)
  38. #define S_SHIFT 16
  39. #define T_SHIFT 6
  40. #else
  41. #define S_SHIFT 15
  42. #define T_SHIFT 5
  43. #endif
  44. #else
  45. #if (PALETTE_ONLY)
  46. #define S_SHIFT S_SHIFT_PAL
  47. #define T_SHIFT 6
  48. #else
  49. #define S_SHIFT 14
  50. #define T_SHIFT 4
  51. #endif
  52. #define TEX_IMAGE GENACCEL(gengc).texImage
  53. #define TEX_PALETTE GENACCEL(gengc).texPalette
  54. #endif
  55. #define ALPHA_MODULATE \
  56. aDisplay = (ULONG)(gbMulTable[((aAccum >> 8) & 0xff00) | texBits[3]]) << 8;
  57. #define ALPHA_NOMODULATE \
  58. aDisplay = ((ULONG)texBits[3] << 8);
  59. #define ALPHA_READ_8 \
  60. {\
  61. ULONG pix = (ULONG)gengc->pajInvTranslateVector[*pPix];\
  62. ULONG alphaVal = (0xff00 - aDisplay);\
  63. \
  64. rDisplay = gbMulTable[((pix & RMASK) << (GBITS + BBITS)) | alphaVal];\
  65. gDisplay = gbMulTable[((pix & GMASK) << (BBITS)) | alphaVal];\
  66. bDisplay = gbMulTable[(pix & BMASK) | alphaVal];\
  67. }
  68. #define ALPHA_READ_16 \
  69. {\
  70. ULONG pix = *((USHORT *)pPix);\
  71. ULONG alphaVal = (0xff00 - aDisplay);\
  72. \
  73. rDisplay = gbMulTable[((pix & RMASK) >> (RSHIFT - (8 - RBITS))) | alphaVal];\
  74. gDisplay = gbMulTable[((pix & GMASK) >> (GSHIFT - (8 - GBITS))) | alphaVal];\
  75. bDisplay = gbMulTable[((pix & BMASK) << (8 - BBITS)) | alphaVal];\
  76. }
  77. #define ALPHA_READ_32 \
  78. {\
  79. ULONG alphaVal = (0xff00 - aDisplay);\
  80. \
  81. rDisplay = gbMulTable[pPix[2] | alphaVal];\
  82. gDisplay = gbMulTable[pPix[1] | alphaVal];\
  83. bDisplay = gbMulTable[pPix[0] | alphaVal];\
  84. }
  85. #if (BPP == 8)
  86. #define ALPHA_READ ALPHA_READ_8
  87. #elif (BPP == 16)
  88. #define ALPHA_READ ALPHA_READ_16
  89. #else
  90. #define ALPHA_READ ALPHA_READ_32
  91. #endif
  92. #undef STRING1
  93. #undef STRING2
  94. #undef STRING3
  95. #undef STRING4
  96. #if FAST_REPLACE
  97. #if PALETTE_ONLY
  98. #define STRING1 __fastFastPerspPalReplace
  99. #else
  100. #define STRING1 __fastFastPerspReplace
  101. #endif
  102. #elif REPLACE
  103. #if (PALETTE_ONLY)
  104. #define STRING1 __fastPerspPalReplace
  105. #else
  106. #define STRING1 __fastPerspReplace
  107. #endif
  108. #elif FLAT_SHADING
  109. #define STRING1 __fastPerspFlat
  110. #else
  111. #define STRING1 __fastPerspSmooth
  112. #endif
  113. #if ALPHA
  114. #define STRING2 Alpha
  115. #endif
  116. #if ZBUFFER
  117. #if (ZCMP_L)
  118. #define STRING3 Zlt
  119. #else
  120. #define STRING3 Zle
  121. #endif
  122. #endif
  123. #if (BPP == 8)
  124. #define STRING4 332
  125. #elif (BPP == 16)
  126. #if (GBITS == 5)
  127. #define STRING4 555
  128. #else
  129. #define STRING4 565
  130. #endif
  131. #else
  132. #define STRING4 888
  133. #endif
  134. #ifdef STRING2
  135. #ifdef STRING3
  136. void FASTCALL STRCAT4(STRING1, STRING2, STRING3, STRING4)
  137. #else
  138. void FASTCALL STRCAT3(STRING1, STRING2, STRING4)
  139. #endif
  140. #else
  141. #ifdef STRING3
  142. void FASTCALL STRCAT3(STRING1, STRING3, STRING4)
  143. #else
  144. void FASTCALL STRCAT2(STRING1, STRING4)
  145. #endif
  146. #endif
  147. (__GLGENcontext *gengc)
  148. {
  149. __GLfloat qwInv;
  150. ULONG count;
  151. LONG subDivCount;
  152. FIXED16 sAccum;
  153. FIXED16 tAccum;
  154. __GLfloat qwAccum;
  155. FIXED16 subDs, subDt;
  156. FIXED16 sResult, tResult;
  157. FIXED16 sResultNew, tResultNew;
  158. BYTE *pPix;
  159. BYTE *texAddr;
  160. BYTE *texBits;
  161. #if ALPHA
  162. ULONG rDisplay, gDisplay, bDisplay, aDisplay;
  163. #endif
  164. #if (FLAT_SHADING || SMOOTH_SHADING)
  165. PDWORD pdither;
  166. FIXED16 rAccum, gAccum, bAccum;
  167. #if (ALPHA)
  168. FIXED16 aAccum;
  169. #endif
  170. #endif
  171. #if (BPP == 32)
  172. ULONG pixAdj;
  173. #if (FLAT_SHADING || SMOOTH_SHADING)
  174. ULONG ditherVal;
  175. #endif
  176. #endif
  177. #if PALETTE_ENABLED
  178. BOOL bPalette = (GENACCEL(gengc).texPalette != NULL);
  179. #endif
  180. BOOL bOrtho = (GENACCEL(gengc).flags & GEN_TEXTURE_ORTHO);
  181. if (!bOrtho) {
  182. if (CASTINT(gengc->gc.polygon.shader.frag.qw) <= 0)
  183. gengc->gc.polygon.shader.frag.qw = (__GLfloat)1.0;
  184. __GL_FLOAT_BEGIN_DIVIDE(__glOne, gengc->gc.polygon.shader.frag.qw,
  185. &qwInv);
  186. }
  187. subDivCount = 7;
  188. sAccum = GENACCEL(gengc).spanValue.s;
  189. tAccum = GENACCEL(gengc).spanValue.t;
  190. qwAccum = gengc->gc.polygon.shader.frag.qw;
  191. #if (FLAT_SHADING)
  192. rAccum = ((GENACCEL(gengc).spanValue.r >> RBITS) & 0xff00);
  193. gAccum = ((GENACCEL(gengc).spanValue.g >> GBITS) & 0xff00);
  194. bAccum = ((GENACCEL(gengc).spanValue.b >> BBITS) & 0xff00);
  195. #if (ALPHA)
  196. aAccum = GENACCEL(gengc).spanValue.a;
  197. #endif
  198. #elif (SMOOTH_SHADING)
  199. rAccum = GENACCEL(gengc).spanValue.r;
  200. gAccum = GENACCEL(gengc).spanValue.g;
  201. bAccum = GENACCEL(gengc).spanValue.b;
  202. #if ALPHA
  203. aAccum = GENACCEL(gengc).spanValue.a;
  204. #endif
  205. #endif
  206. #if ((BPP == 32) && (FLAT_SHADING || SMOOTH_SHADING))
  207. ditherVal = ditherShade[0];
  208. #endif
  209. if (!bOrtho) {
  210. __GL_FLOAT_SIMPLE_END_DIVIDE(qwInv);
  211. sResult = FTOL((__GLfloat)sAccum * qwInv);
  212. tResult = ((FTOL((__GLfloat)tAccum * qwInv)) >> TSHIFT_SUBDIV) & ~7;
  213. qwAccum += GENACCEL(gengc).qwStepX;
  214. if (CASTINT(qwAccum) <= 0)
  215. qwAccum = (__GLfloat)1.0;
  216. __GL_FLOAT_SIMPLE_BEGIN_DIVIDE(__glOne, qwAccum, qwInv);
  217. } else {
  218. sResult = sAccum;
  219. tResult = (tAccum >> TSHIFT_SUBDIV) & ~7;
  220. }
  221. sAccum += GENACCEL(gengc).sStepX;
  222. tAccum += GENACCEL(gengc).tStepX;
  223. if (GENACCEL(gengc).flags & SURFACE_TYPE_DIB) {
  224. #if (BPP != 32)
  225. pPix = GENACCEL(gengc).pPix +
  226. gengc->gc.polygon.shader.frag.x * (BPP / 8);
  227. #else
  228. if (GENACCEL(gengc).bpp == 32) {
  229. pPix = GENACCEL(gengc).pPix +
  230. gengc->gc.polygon.shader.frag.x * 4;
  231. pixAdj = 4;
  232. } else {
  233. pPix = GENACCEL(gengc).pPix +
  234. gengc->gc.polygon.shader.frag.x * 3;
  235. pixAdj = 3;
  236. }
  237. #endif
  238. } else {
  239. pPix = gengc->ColorsBits;
  240. #if (BPP == 32)
  241. pixAdj = GENACCEL(gengc).xMultiplier;
  242. #endif
  243. }
  244. #if (FLAT_SHADING || SMOOTH_SHADING)
  245. #if (BPP != 32)
  246. pdither = (gengc->gc.polygon.shader.frag.y & 0x3) * 8 + ditherShade +
  247. (((gengc->gc.polygon.shader.frag.x & 0x3) -
  248. (((ULONG_PTR)pPix / (BPP / 8)) & 0x3)) & 0x3);
  249. #endif
  250. #endif
  251. if (!bOrtho) {
  252. __GL_FLOAT_SIMPLE_END_DIVIDE(qwInv);
  253. sResultNew = FTOL((__GLfloat)sAccum * qwInv);
  254. tResultNew = ((FTOL((__GLfloat)tAccum * qwInv)) >> TSHIFT_SUBDIV) & ~7;
  255. qwAccum += GENACCEL(gengc).qwStepX;
  256. if (CASTINT(qwAccum) <= 0)
  257. qwAccum = (__GLfloat)1.0;
  258. __GL_FLOAT_SIMPLE_BEGIN_DIVIDE(__glOne, qwAccum, qwInv);
  259. } else {
  260. sResultNew = sAccum;
  261. tResultNew = (tAccum >> TSHIFT_SUBDIV) & ~7;
  262. }
  263. sAccum += GENACCEL(gengc).sStepX;
  264. tAccum += GENACCEL(gengc).tStepX;
  265. subDs = (sResultNew - sResult) >> 3;
  266. subDt = (tResultNew - tResult) >> 3;
  267. #if ZBUFFER
  268. {
  269. GLuint zAccum = gengc->gc.polygon.shader.frag.z;
  270. GLint zDelta = gengc->gc.polygon.shader.dzdx;
  271. PBYTE zbuf = (PBYTE)gengc->gc.polygon.shader.zbuf;
  272. if (GENACCEL(gengc).flags & GEN_LESS) {
  273. for (count = gengc->gc.polygon.shader.length;;) {
  274. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) < *((__GLz16Value*)zbuf) ) {
  275. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  276. #include "texspan2.h"
  277. }
  278. if (--count == 0)
  279. goto exit;
  280. zbuf += 2;
  281. zAccum += zDelta;
  282. #include "texspan3.h"
  283. }
  284. } else {
  285. for (count = gengc->gc.polygon.shader.length;;) {
  286. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  287. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  288. #include "texspan2.h"
  289. }
  290. if (--count == 0)
  291. goto exit;
  292. zbuf += 2;
  293. zAccum += zDelta;
  294. #include "texspan3.h"
  295. }
  296. }
  297. }
  298. #else
  299. for (count = gengc->gc.polygon.shader.length;;) {
  300. #include "texspan2.h"
  301. if (--count == 0)
  302. goto exit;
  303. #include "texspan3.h"
  304. }
  305. #endif
  306. exit:
  307. if (!bOrtho) {
  308. __GL_FLOAT_SIMPLE_END_DIVIDE(qwInv);
  309. }
  310. }
  311. #undef RMASK
  312. #undef GMASK
  313. #undef BMASK
  314. #undef RRIGHTSHIFTADJ
  315. #undef GRIGHTSHIFTADJ
  316. #undef BRIGHTSHIFTADJ
  317. #undef ALPHA_MODULATE
  318. #undef ALPHA_NOMODULATE
  319. #undef ALPHA_READ_8
  320. #undef ALPHA_READ_16
  321. #undef ALPHA_READ_32
  322. #undef ALPHA_READ
  323. #undef S_SHIFT
  324. #undef T_SHIFT
  325. #undef TMASK_SUBDIV
  326. #undef TSHIFT_SUBDIV
  327. #undef TEX_IMAGE
  328. #undef TEX_PALETTE
  329. #undef S_SHIFT_PAL
  330. #undef T_SHIFT_PAL