r_drawcolumn.inl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /* Emacs style mode select -*- C++ -*-
  2. *-----------------------------------------------------------------------------
  3. *
  4. *
  5. * PrBoom: a Doom port merged with LxDoom and LSDLDoom
  6. * based on BOOM, a modified and improved DOOM engine
  7. * Copyright (C) 1999 by
  8. * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
  9. * Copyright (C) 1999-2000 by
  10. * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
  11. * Copyright 2005, 2006 by
  12. * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version 2
  17. * of the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  27. * 02111-1307, USA.
  28. *
  29. *-----------------------------------------------------------------------------*/
  30. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  31. #define SCREENTYPE byte
  32. #define TEMPBUF byte_tempbuf
  33. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 15)
  34. #define SCREENTYPE unsigned short
  35. #define TEMPBUF short_tempbuf
  36. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 16)
  37. #define SCREENTYPE unsigned short
  38. #define TEMPBUF short_tempbuf
  39. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 32)
  40. #define SCREENTYPE unsigned int
  41. #define TEMPBUF int_tempbuf
  42. #endif
  43. #define GETDESTCOLOR8(col) (col)
  44. #define GETDESTCOLOR15(col) (col)
  45. #define GETDESTCOLOR16(col) (col)
  46. #define GETDESTCOLOR32(col) (col)
  47. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLATED)
  48. #define GETCOL8_MAPPED(col) (translation[(col)])
  49. #else
  50. #define GETCOL8_MAPPED(col) (col)
  51. #endif
  52. #if (R_DRAWCOLUMN_PIPELINE & RDC_NOCOLMAP)
  53. #define GETCOL8_DEPTH(col) GETCOL8_MAPPED(col)
  54. #else
  55. #if (R_DRAWCOLUMN_PIPELINE & RDC_DITHERZ)
  56. #define GETCOL8_DEPTH(col) (dither_colormaps[filter_getDitheredPixelLevel(x, y, fracz)][GETCOL8_MAPPED(col)])
  57. #else
  58. #define GETCOL8_DEPTH(col) colormap[GETCOL8_MAPPED(col)]
  59. #endif
  60. #endif
  61. #if (R_DRAWCOLUMN_PIPELINE & RDC_BILINEAR)
  62. #define GETCOL8(frac, nextfrac) GETCOL8_DEPTH(filter_getDitheredForColumn(x,y,frac,nextfrac))
  63. #define GETCOL15(frac, nextfrac) filter_getFilteredForColumn15(GETCOL8_DEPTH,frac,nextfrac)
  64. #define GETCOL16(frac, nextfrac) filter_getFilteredForColumn16(GETCOL8_DEPTH,frac,nextfrac)
  65. #define GETCOL32(frac, nextfrac) filter_getFilteredForColumn32(GETCOL8_DEPTH,frac,nextfrac)
  66. #elif (R_DRAWCOLUMN_PIPELINE & RDC_ROUNDED)
  67. #define GETCOL8(frac, nextfrac) GETCOL8_DEPTH(filter_getRoundedForColumn(frac,nextfrac))
  68. #define GETCOL15(frac, nextfrac) VID_PAL15(GETCOL8_DEPTH(filter_getRoundedForColumn(frac,nextfrac)), VID_COLORWEIGHTMASK)
  69. #define GETCOL16(frac, nextfrac) VID_PAL16(GETCOL8_DEPTH(filter_getRoundedForColumn(frac,nextfrac)), VID_COLORWEIGHTMASK)
  70. #define GETCOL32(frac, nextfrac) VID_PAL32(GETCOL8_DEPTH(filter_getRoundedForColumn(frac,nextfrac)), VID_COLORWEIGHTMASK)
  71. #else
  72. #define GETCOL8(frac, nextfrac) GETCOL8_DEPTH(source[(frac)>>FRACBITS])
  73. #define GETCOL15(frac, nextfrac) VID_PAL15(GETCOL8_DEPTH(source[(frac)>>FRACBITS]), VID_COLORWEIGHTMASK)
  74. #define GETCOL16(frac, nextfrac) VID_PAL16(GETCOL8_DEPTH(source[(frac)>>FRACBITS]), VID_COLORWEIGHTMASK)
  75. #define GETCOL32(frac, nextfrac) VID_PAL32(GETCOL8_DEPTH(source[(frac)>>FRACBITS]), VID_COLORWEIGHTMASK)
  76. #endif
  77. #if (R_DRAWCOLUMN_PIPELINE & (RDC_BILINEAR|RDC_ROUNDED|RDC_DITHERZ))
  78. #define INCY(y) (y++)
  79. #else
  80. #define INCY(y)
  81. #endif
  82. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  83. #define COLTYPE (COL_TRANS)
  84. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  85. #define COLTYPE (COL_FUZZ)
  86. #else
  87. #define COLTYPE (COL_OPAQUE)
  88. #endif
  89. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  90. #define GETCOL(frac, nextfrac) GETCOL8(frac, nextfrac)
  91. #define GETDESTCOLOR(col) GETDESTCOLOR8(col)
  92. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 15)
  93. #define GETCOL(frac, nextfrac) GETCOL15(frac, nextfrac)
  94. #define GETDESTCOLOR(col) GETDESTCOLOR15(col)
  95. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 16)
  96. #define GETCOL(frac, nextfrac) GETCOL16(frac, nextfrac)
  97. #define GETDESTCOLOR(col) GETDESTCOLOR16(col)
  98. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 32)
  99. #define GETCOL(frac, nextfrac) GETCOL32(frac, nextfrac)
  100. #define GETDESTCOLOR(col) GETDESTCOLOR32(col)
  101. #endif
  102. static void R_DRAWCOLUMN_FUNCNAME(draw_column_vars_t *dcvars)
  103. {
  104. int count;
  105. SCREENTYPE *dest; // killough
  106. fixed_t frac;
  107. const fixed_t fracstep = dcvars->iscale;
  108. #if ((R_DRAWCOLUMN_PIPELINE & RDC_BILINEAR) && (R_DRAWCOLUMN_PIPELINE_BITS != 8))
  109. const fixed_t slope_texu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
  110. #else
  111. const fixed_t slope_texu = dcvars->texu;
  112. #endif
  113. // drop back to point filtering if we're minifying
  114. #if (R_DRAWCOLUMN_PIPELINE & (RDC_BILINEAR|RDC_ROUNDED))
  115. if (dcvars->iscale > drawvars.mag_threshold) {
  116. R_GetDrawColumnFunc(R_DRAWCOLUMN_PIPELINE_TYPE,
  117. RDRAW_FILTER_POINT,
  118. drawvars.filterz)(dcvars);
  119. return;
  120. }
  121. #endif
  122. #if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  123. // Adjust borders. Low...
  124. if (!dcvars->yl)
  125. dcvars->yl = 1;
  126. // .. and high.
  127. if (dcvars->yh == viewheight-1)
  128. dcvars->yh = viewheight - 2;
  129. #endif
  130. // leban 1/17/99:
  131. // removed the + 1 here, adjusted the if test, and added an increment
  132. // later. this helps a compiler pipeline a bit better. the x86
  133. // assembler also does this.
  134. count = dcvars->yh - dcvars->yl;
  135. // leban 1/17/99:
  136. // this case isn't executed too often. depending on how many instructions
  137. // there are between here and the second if test below, this case could
  138. // be moved down and might save instructions overall. since there are
  139. // probably different wads that favor one way or the other, i'll leave
  140. // this alone for now.
  141. if (count < 0) // Zero length, column does not exceed a pixel.
  142. return;
  143. #ifdef RANGECHECK
  144. if (dcvars->x >= SCREENWIDTH
  145. || dcvars->yl < 0
  146. || dcvars->yh >= SCREENHEIGHT)
  147. I_Error("R_DrawColumn: %i to %i at %i", dcvars->yl, dcvars->yh, dcvars->x);
  148. #endif
  149. // Determine scaling, which is the only mapping to be done.
  150. #if (R_DRAWCOLUMN_PIPELINE & RDC_BILINEAR)
  151. frac = dcvars->texturemid - (FRACUNIT>>1) + (dcvars->yl-centery)*fracstep;
  152. #else
  153. frac = dcvars->texturemid + (dcvars->yl-centery)*fracstep;
  154. #endif
  155. if (dcvars->drawingmasked && dcvars->edgetype == RDRAW_MASKEDCOLUMNEDGE_SLOPED) {
  156. // slope the top and bottom column edge based on the fractional u coordinate
  157. // and dcvars->edgeslope, which were set in R_DrawMaskedColumn
  158. // in r_things.c
  159. if (dcvars->yl != 0) {
  160. if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_UP) {
  161. // [/#]
  162. int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
  163. dcvars->yl += shift;
  164. count -= shift;
  165. frac += 0xffff-(slope_texu & 0xffff);
  166. }
  167. else if (dcvars->edgeslope & RDRAW_EDGESLOPE_TOP_DOWN) {
  168. // [#\]
  169. int shift = ((slope_texu & 0xffff)/dcvars->iscale);
  170. dcvars->yl += shift;
  171. count -= shift;
  172. frac += slope_texu & 0xffff;
  173. }
  174. }
  175. if (dcvars->yh != viewheight-1) {
  176. if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_UP) {
  177. // [#/]
  178. int shift = ((0xffff-(slope_texu & 0xffff))/dcvars->iscale);
  179. dcvars->yh -= shift;
  180. count -= shift;
  181. }
  182. else if (dcvars->edgeslope & RDRAW_EDGESLOPE_BOT_DOWN) {
  183. // [\#]
  184. int shift = ((slope_texu & 0xffff)/dcvars->iscale);
  185. dcvars->yh -= shift;
  186. count -= shift;
  187. }
  188. }
  189. if (count <= 0) return;
  190. }
  191. // Framebuffer destination address.
  192. // SoM: MAGIC
  193. {
  194. // haleyjd: reordered predicates
  195. if(temp_x == 4 ||
  196. (temp_x && (temptype != COLTYPE || temp_x + startx != dcvars->x)))
  197. R_FlushColumns();
  198. if(!temp_x)
  199. {
  200. startx = dcvars->x;
  201. tempyl[0] = commontop = dcvars->yl;
  202. tempyh[0] = commonbot = dcvars->yh;
  203. temptype = COLTYPE;
  204. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  205. temptranmap = tranmap;
  206. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  207. tempfuzzmap = fullcolormap; // SoM 7-28-04: Fix the fuzz problem.
  208. #endif
  209. R_FlushWholeColumns = R_FLUSHWHOLE_FUNCNAME;
  210. R_FlushHTColumns = R_FLUSHHEADTAIL_FUNCNAME;
  211. R_FlushQuadColumn = R_FLUSHQUAD_FUNCNAME;
  212. dest = &TEMPBUF[dcvars->yl << 2];
  213. } else {
  214. tempyl[temp_x] = dcvars->yl;
  215. tempyh[temp_x] = dcvars->yh;
  216. if(dcvars->yl > commontop)
  217. commontop = dcvars->yl;
  218. if(dcvars->yh < commonbot)
  219. commonbot = dcvars->yh;
  220. dest = &TEMPBUF[(dcvars->yl << 2) + temp_x];
  221. }
  222. temp_x += 1;
  223. }
  224. // do nothing else when drawin fuzz columns
  225. #if (!(R_DRAWCOLUMN_PIPELINE & RDC_FUZZ))
  226. {
  227. const byte *source = dcvars->source;
  228. const lighttable_t *colormap = dcvars->colormap;
  229. const byte *translation = dcvars->translation;
  230. #if (R_DRAWCOLUMN_PIPELINE & (RDC_BILINEAR|RDC_ROUNDED|RDC_DITHERZ))
  231. int y = dcvars->yl;
  232. const int x = dcvars->x;
  233. (void)x;
  234. #endif
  235. #if (R_DRAWCOLUMN_PIPELINE & RDC_DITHERZ)
  236. const int fracz = (dcvars->z >> 6) & 255;
  237. const byte *dither_colormaps[2] = { dcvars->colormap, dcvars->nextcolormap };
  238. #endif
  239. #if (R_DRAWCOLUMN_PIPELINE & RDC_BILINEAR)
  240. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  241. const int yl = dcvars->yl;
  242. const byte *dither_sources[2] = { dcvars->source, dcvars->nextsource };
  243. const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
  244. #else
  245. const byte *nextsource = dcvars->nextsource;
  246. const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : dcvars->texu & 0xffff;
  247. #endif
  248. #endif
  249. #if (R_DRAWCOLUMN_PIPELINE & RDC_ROUNDED)
  250. const byte *prevsource = dcvars->prevsource;
  251. const byte *nextsource = dcvars->nextsource;
  252. const unsigned int filter_fracu = (dcvars->source == dcvars->nextsource) ? 0 : (dcvars->texu>>8) & 0xff;
  253. #endif
  254. /* Prevent unused variable warnings. */
  255. (void)source;
  256. (void)colormap;
  257. (void)translation;
  258. count++;
  259. // Inner loop that does the actual texture mapping,
  260. // e.g. a DDA-lile scaling.
  261. // This is as fast as it gets. (Yeah, right!!! -- killough)
  262. //
  263. // killough 2/1/98: more performance tuning
  264. if (dcvars->texheight == 128) {
  265. #define FIXEDT_128MASK ((127<<FRACBITS)|0xffff)
  266. while(count--) {
  267. *dest = GETDESTCOLOR(GETCOL(frac & FIXEDT_128MASK, (frac+FRACUNIT) & FIXEDT_128MASK));
  268. INCY(y);
  269. dest += 4;
  270. frac += fracstep;
  271. }
  272. } else if (dcvars->texheight == 0) {
  273. /* cph - another special case */
  274. while (count--) {
  275. *dest = GETDESTCOLOR(GETCOL(frac, (frac+FRACUNIT)));
  276. INCY(y);
  277. dest += 4;
  278. frac += fracstep;
  279. }
  280. } else {
  281. unsigned heightmask = dcvars->texheight-1; // CPhipps - specify type
  282. if (! (dcvars->texheight & heightmask) ) { // power of 2 -- killough
  283. fixed_t fixedt_heightmask = (heightmask<<FRACBITS)|0xffff;
  284. while ((count-=2)>=0) { // texture height is a power of 2 -- killough
  285. *dest = GETDESTCOLOR(GETCOL(frac & fixedt_heightmask, (frac+FRACUNIT) & fixedt_heightmask));
  286. INCY(y);
  287. dest += 4;
  288. frac += fracstep;
  289. *dest = GETDESTCOLOR(GETCOL(frac & fixedt_heightmask, (frac+FRACUNIT) & fixedt_heightmask));
  290. INCY(y);
  291. dest += 4;
  292. frac += fracstep;
  293. }
  294. if (count & 1)
  295. *dest = GETDESTCOLOR(GETCOL(frac & fixedt_heightmask, (frac+FRACUNIT) & fixedt_heightmask));
  296. INCY(y);
  297. } else {
  298. fixed_t nextfrac = 0;
  299. (void)nextfrac;
  300. heightmask++;
  301. heightmask <<= FRACBITS;
  302. if (frac < 0)
  303. while ((frac += heightmask) < 0);
  304. else
  305. while (frac >= (int)heightmask)
  306. frac -= heightmask;
  307. #if (R_DRAWCOLUMN_PIPELINE & (RDC_BILINEAR|RDC_ROUNDED))
  308. nextfrac = frac + FRACUNIT;
  309. while (nextfrac >= (int)heightmask)
  310. nextfrac -= heightmask;
  311. #endif
  312. #define INCFRAC(f) if ((f += fracstep) >= (int)heightmask) f -= heightmask;
  313. while (count--) {
  314. // Re-map color indices from wall texture column
  315. // using a lighting/special effects LUT.
  316. // heightmask is the Tutti-Frutti fix -- killough
  317. *dest = GETDESTCOLOR(GETCOL(frac, nextfrac));
  318. INCY(y);
  319. dest += 4;
  320. INCFRAC(frac);
  321. #if (R_DRAWCOLUMN_PIPELINE & (RDC_BILINEAR|RDC_ROUNDED))
  322. INCFRAC(nextfrac);
  323. #endif
  324. }
  325. }
  326. }
  327. }
  328. #endif // (!(R_DRAWCOLUMN_PIPELINE & RDC_FUZZ))
  329. }
  330. #undef GETDESTCOLOR32
  331. #undef GETDESTCOLOR16
  332. #undef GETDESTCOLOR15
  333. #undef GETDESTCOLOR8
  334. #undef GETDESTCOLOR
  335. #undef GETCOL8_MAPPED
  336. #undef GETCOL8_DEPTH
  337. #undef GETCOL32
  338. #undef GETCOL16
  339. #undef GETCOL15
  340. #undef GETCOL8
  341. #undef GETCOL
  342. #undef INCY
  343. #undef INCFRAC
  344. #undef COLTYPE
  345. #undef TEMPBUF
  346. #undef SCREENTYPE
  347. #undef R_DRAWCOLUMN_FUNCNAME
  348. #undef R_DRAWCOLUMN_PIPELINE