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.

398 lines
13 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: span.h
  3. *
  4. * This include file is used to generate various flavors of textured and
  5. * shaded spans, or scanlines.
  6. *
  7. * 14-Oct-1994 mikeke Combined span_t.h and span_s.h to share common
  8. * code. Speeded things up a little. Had a little
  9. * fun with the C preprocessor.
  10. * 11-April-1994 Otto Berkes [ottob] Created
  11. *
  12. * Copyright (c) 1994 Microsoft Corporation
  13. \**************************************************************************/
  14. #undef STRING1
  15. #undef STRING2
  16. #undef STRING3
  17. #undef STRING4
  18. #if GENERIC
  19. void FASTCALL __fastGenSpan
  20. #else
  21. #if ZBUFFER
  22. #define STRING1 __fastGenMask
  23. #else
  24. #define STRING1 __fastGen
  25. #endif
  26. #if TEXTURE
  27. #if SHADE
  28. #define STRING2 Tex
  29. #else
  30. #define STRING2 TexDecal
  31. #endif
  32. #elif RGBMODE
  33. #define STRING2 RGB
  34. #else
  35. #define STRING2 CI
  36. #endif
  37. #if DITHER
  38. #define STRING3 STRCAT2(COLORFORMAT, Dith)
  39. #else
  40. #define STRING3 COLORFORMAT
  41. #endif
  42. #define STRING4 Span
  43. void FASTCALL STRCAT4(STRING1, STRING2, STRING3, STRING4)
  44. #endif
  45. (__GLGENcontext *gengc)
  46. {
  47. #if (SHADE) || !(RGBMODE) || (TEXTURE && DITHER)
  48. ULONG rAccum;
  49. LONG rDelta;
  50. #if RGBMODE
  51. ULONG gAccum;
  52. ULONG bAccum;
  53. LONG gDelta;
  54. LONG bDelta;
  55. #endif
  56. #endif
  57. #if TEXTURE
  58. LONG sAccum;
  59. LONG tAccum;
  60. LONG sDelta;
  61. LONG tDelta;
  62. ULONG tShift;
  63. ULONG sMask, tMask;
  64. #endif
  65. ULONG rShift;
  66. ULONG rBits;
  67. #if RGBMODE
  68. ULONG gShift;
  69. ULONG gBits;
  70. ULONG bShift;
  71. ULONG bBits;
  72. #endif
  73. BYTE *pPix;
  74. BYTE *texAddr;
  75. BYTE *texBits;
  76. LONG count;
  77. LONG totalCount;
  78. #if DITHER
  79. PDWORD pdither;
  80. #if (BPP == 24) || (GENERIC)
  81. DWORD iDither;
  82. #endif
  83. #endif
  84. #if (BPP == 8) || (GENERIC)
  85. BYTE *pXlat;
  86. #elif (!RGBMODE)
  87. ULONG *pXlat;
  88. #endif
  89. #if GENERIC
  90. DWORD flags = GENACCEL(gengc).flags;
  91. DWORD bpp = GENACCEL(gengc).bpp;
  92. #endif
  93. #if GENERIC
  94. if (flags & GEN_TEXTURE)
  95. #endif
  96. #if TEXTURE
  97. {
  98. __GLtexture *tex = ((__GLcontext *)gengc)->texture.currentTexture;
  99. sMask = GENACCEL(gengc).sMask;
  100. tMask = GENACCEL(gengc).tMask;
  101. tShift = GENACCEL(gengc).tShift;
  102. sDelta = GENACCEL(gengc).spanDelta.s;
  103. tDelta = GENACCEL(gengc).spanDelta.t;
  104. sAccum = GENACCEL(gengc).spanValue.s;
  105. tAccum = GENACCEL(gengc).spanValue.t;
  106. #if !(SHADE) && !(DITHER) && ((BPP == 8) || (BPP == 16))
  107. texAddr = (BYTE *)GENACCEL(gengc).texImageReplace;
  108. #else
  109. texAddr = (BYTE *)GENACCEL(gengc).texImage;
  110. #endif
  111. }
  112. #endif
  113. // get color deltas and accumulators
  114. #ifndef RSHIFT
  115. rShift = gengc->gsurf.pfd.cRedShift;
  116. rBits = gengc->gsurf.pfd.cRedBits;
  117. #if RGBMODE
  118. gShift = gengc->gsurf.pfd.cGreenShift;
  119. gBits = gengc->gsurf.pfd.cGreenBits;
  120. bShift = gengc->gsurf.pfd.cBlueShift;
  121. bBits = gengc->gsurf.pfd.cBlueBits;
  122. #endif
  123. #endif
  124. #if (GENERIC)
  125. if (!(flags & GEN_SHADE) &&
  126. (flags & (GEN_TEXTURE | GEN_DITHER)) == (GEN_TEXTURE | GEN_DITHER)) {
  127. rAccum = (GENACCEL(gengc).spanValue.r >> rBits) & 0xff00;
  128. gAccum = (GENACCEL(gengc).spanValue.g >> gBits) & 0xff00;
  129. bAccum = (GENACCEL(gengc).spanValue.b >> bBits) & 0xff00;
  130. rDelta = 0;
  131. gDelta = 0;
  132. bDelta = 0;
  133. } else {
  134. rAccum = GENACCEL(gengc).spanValue.r;
  135. gAccum = GENACCEL(gengc).spanValue.g;
  136. bAccum = GENACCEL(gengc).spanValue.b;
  137. rDelta = GENACCEL(gengc).spanDelta.r;
  138. gDelta = GENACCEL(gengc).spanDelta.g;
  139. bDelta = GENACCEL(gengc).spanDelta.b;
  140. }
  141. #else
  142. #if !(SHADE) && (TEXTURE) && (DITHER)
  143. #ifndef RSHIFT
  144. rAccum = (GENACCEL(gengc).spanValue.r >> rBits) & 0xff00;
  145. gAccum = (GENACCEL(gengc).spanValue.g >> gBits) & 0xff00;
  146. bAccum = (GENACCEL(gengc).spanValue.b >> bBits) & 0xff00;
  147. #else
  148. rAccum = (GENACCEL(gengc).spanValue.r >> RBITS) & 0xff00;
  149. gAccum = (GENACCEL(gengc).spanValue.g >> GBITS) & 0xff00;
  150. bAccum = (GENACCEL(gengc).spanValue.b >> BBITS) & 0xff00;
  151. #endif
  152. #else
  153. #if (SHADE) || !(RGBMODE)
  154. rAccum = GENACCEL(gengc).spanValue.r;
  155. #if RGBMODE
  156. gAccum = GENACCEL(gengc).spanValue.g;
  157. bAccum = GENACCEL(gengc).spanValue.b;
  158. #endif
  159. #endif
  160. #endif
  161. #if (SHADE) || !(RGBMODE)
  162. rDelta = GENACCEL(gengc).spanDelta.r;
  163. #if RGBMODE
  164. gDelta = GENACCEL(gengc).spanDelta.g;
  165. bDelta = GENACCEL(gengc).spanDelta.b;
  166. #endif
  167. #endif
  168. #endif
  169. // get address of destination
  170. if (GENACCEL(gengc).flags & SURFACE_TYPE_DIB) {
  171. pPix = GENACCEL(gengc).pPix +
  172. gengc->gc.polygon.shader.frag.x * (BPP / 8);
  173. } else {
  174. pPix = gengc->ColorsBits;
  175. }
  176. // set up pointer to translation table as needed
  177. #if GENERIC
  178. if ((bpp != 8) && (!(flags & GEN_RGBMODE))) {
  179. pXlat = gengc->pajTranslateVector + sizeof(DWORD);
  180. }
  181. #else
  182. #if (BPP == 8)
  183. // No need to set up xlat vector
  184. #elif (!RGBMODE)
  185. pXlat = (ULONG *)(gengc->pajTranslateVector + sizeof(DWORD));
  186. #endif
  187. #endif
  188. #if GENERIC
  189. if (GENACCEL(gengc).flags & GEN_DITHER) {
  190. // LATER !!! mikeke
  191. // fix this so the destination is always aligned with the x value
  192. // !!! make sure this is correct in generic case
  193. // look at flat it assumes alignment
  194. //
  195. if (GENACCEL(gengc).flags & GEN_TEXTURE)
  196. pdither = ditherTexture;
  197. else
  198. pdither = ditherShade;
  199. pdither += (gengc->gc.polygon.shader.frag.y & 0x3) * 8;
  200. iDither = gengc->gc.polygon.shader.frag.x & 0x3;
  201. } else {
  202. // LATER !!! mikeke
  203. // add these outside of the loop
  204. if (!(GENACCEL(gengc).flags & GEN_TEXTURE)) {
  205. rAccum += 0x0800;
  206. gAccum += 0x0800;
  207. bAccum += 0x0800;
  208. }
  209. //pdither = 0;
  210. }
  211. #else
  212. #if DITHER
  213. // LATER !!! mikeke
  214. // fix this so the destination is always aligned with the x value
  215. // !!! make sure this is correct in generic case
  216. // look at flat it assumes alignment
  217. //
  218. #if (BPP == 24)
  219. pdither = (gengc->gc.polygon.shader.frag.y & 0x3) * 8
  220. #if (TEXTURE)
  221. + ditherTexture
  222. #else
  223. + ditherShade
  224. #endif
  225. ;
  226. iDither = gengc->gc.polygon.shader.frag.x & 0x3;
  227. #else
  228. pdither = (gengc->gc.polygon.shader.frag.y & 0x3) * 8
  229. #if (TEXTURE)
  230. + ditherTexture
  231. #else
  232. + ditherShade
  233. #endif
  234. + ((
  235. (gengc->gc.polygon.shader.frag.x & 0x3)
  236. - (((ULONG_PTR)pPix / (BPP / 8)) & 0x3)
  237. ) & 0x3 );
  238. #endif
  239. #else
  240. // LATER !!! mikeke
  241. // add these outside of the loop
  242. #if !(RGBMODE)
  243. rAccum += 0x0800;
  244. #else //RGBMODE
  245. #if (TEXTURE) && !(GENERIC)
  246. #else //!TEXTURE
  247. rAccum += 0x0800;
  248. gAccum += 0x0800;
  249. bAccum += 0x0800;
  250. #endif //TEXTURE
  251. #endif //RGBMODE
  252. #endif
  253. #endif
  254. #if GENERIC
  255. {
  256. ULONG *pMask;
  257. pMask = gengc->gc.polygon.shader.stipplePat;
  258. for (totalCount = gengc->gc.polygon.shader.length;
  259. totalCount > 0; totalCount -= 32
  260. ) {
  261. ULONG maskTest;
  262. ULONG mask = *pMask++;
  263. if (mask == 0) {
  264. #if (SHADE) || !(RGBMODE)
  265. rAccum += (rDelta << 5);
  266. #if RGBMODE
  267. gAccum += (gDelta << 5);
  268. bAccum += (bDelta << 5);
  269. #endif
  270. #endif
  271. #if TEXTURE
  272. sAccum += (sDelta << 5);
  273. tAccum += (tDelta << 5);
  274. #endif
  275. //iDither = (iDither + 32) & 0x3;
  276. pPix += (32 * (BPP / 8));
  277. } else {
  278. maskTest = 0x80000000;
  279. if ((count = totalCount) > 32)
  280. count = 32;
  281. for (; count; count--, maskTest >>= 1) {
  282. if (mask & maskTest) {
  283. #include "spangen.h"
  284. }
  285. #include "span3.h"
  286. }
  287. }
  288. }
  289. }
  290. #elif ZBUFFER
  291. {
  292. GLuint zAccum = gengc->gc.polygon.shader.frag.z;
  293. GLint zDelta = gengc->gc.polygon.shader.dzdx;
  294. PBYTE zbuf = (PBYTE)gengc->gc.polygon.shader.zbuf;
  295. if (GENACCEL(gengc).flags & GEN_LESS) {
  296. if (gengc->gc.modes.depthBits == 16) {
  297. for (count = gengc->gc.polygon.shader.length;;) {
  298. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) < *((__GLz16Value*)zbuf) ) {
  299. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  300. #include "span2.h"
  301. }
  302. if (--count == 0)
  303. return;
  304. zbuf += 2;
  305. zAccum += zDelta;
  306. #include "span3.h"
  307. }
  308. } else {
  309. for (count = gengc->gc.polygon.shader.length;;) {
  310. if ( zAccum < *((GLuint*)zbuf) ) {
  311. *((GLuint*)zbuf) = zAccum;
  312. #include "span2.h"
  313. }
  314. if (--count == 0)
  315. return;
  316. zbuf += 4;
  317. zAccum += zDelta;
  318. #include "span3.h"
  319. }
  320. }
  321. } else {
  322. if (gengc->gc.modes.depthBits == 16) {
  323. for (count = gengc->gc.polygon.shader.length;;) {
  324. if ( ((__GLz16Value)(zAccum >> Z16_SHIFT)) <= *((__GLz16Value*)zbuf) ) {
  325. *((__GLz16Value*)zbuf) = ((__GLz16Value)(zAccum >> Z16_SHIFT));
  326. #include "span2.h"
  327. }
  328. if (--count == 0)
  329. return;
  330. zbuf += 2;
  331. zAccum += zDelta;
  332. #include "span3.h"
  333. }
  334. } else {
  335. for (count = gengc->gc.polygon.shader.length;;) {
  336. if ( zAccum <= *((GLuint*)zbuf) ) {
  337. *((GLuint*)zbuf) = zAccum;
  338. #include "span2.h"
  339. }
  340. if (--count == 0)
  341. return;
  342. zbuf += 4;
  343. zAccum += zDelta;
  344. #include "span3.h"
  345. }
  346. }
  347. }
  348. }
  349. #else
  350. for (count = gengc->gc.polygon.shader.length;;) {
  351. #include "span2.h"
  352. if (--count == 0)
  353. return;
  354. #include "span3.h"
  355. }
  356. #endif
  357. }
  358. #undef ditherVal