r_drawflush.inl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 TOPLEFT byte_topleft
  33. #define PITCH byte_pitch
  34. #define TEMPBUF byte_tempbuf
  35. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 15)
  36. #define SCREENTYPE unsigned short
  37. #define TOPLEFT short_topleft
  38. #define PITCH short_pitch
  39. #define TEMPBUF short_tempbuf
  40. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 16)
  41. #define SCREENTYPE unsigned short
  42. #define TOPLEFT short_topleft
  43. #define PITCH short_pitch
  44. #define TEMPBUF short_tempbuf
  45. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 32)
  46. #define SCREENTYPE unsigned int
  47. #define TOPLEFT int_topleft
  48. #define PITCH int_pitch
  49. #define TEMPBUF int_tempbuf
  50. #endif
  51. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  52. #define GETDESTCOLOR8(col1, col2) (temptranmap[((col1)<<8)+(col2)])
  53. #define GETDESTCOLOR15(col1, col2) (GETBLENDED15_3268((col1), (col2)))
  54. #define GETDESTCOLOR16(col1, col2) (GETBLENDED16_3268((col1), (col2)))
  55. #define GETDESTCOLOR32(col1, col2) (GETBLENDED32_3268((col1), (col2)))
  56. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  57. #define GETDESTCOLOR8(col) (tempfuzzmap[6*256+(col)])
  58. #define GETDESTCOLOR15(col) GETBLENDED15_9406(col, 0)
  59. #define GETDESTCOLOR16(col) GETBLENDED16_9406(col, 0)
  60. #define GETDESTCOLOR32(col) GETBLENDED32_9406(col, 0)
  61. #else
  62. #define GETDESTCOLOR8(col) (col)
  63. #define GETDESTCOLOR15(col) (col)
  64. #define GETDESTCOLOR16(col) (col)
  65. #define GETDESTCOLOR32(col) (col)
  66. #endif
  67. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  68. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  69. #define GETDESTCOLOR(col1, col2) GETDESTCOLOR8(col1, col2)
  70. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 15)
  71. #define GETDESTCOLOR(col1, col2) GETDESTCOLOR15(col1, col2)
  72. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 16)
  73. #define GETDESTCOLOR(col1, col2) GETDESTCOLOR16(col1, col2)
  74. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 32)
  75. #define GETDESTCOLOR(col1, col2) GETDESTCOLOR32(col1, col2)
  76. #endif
  77. #else
  78. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  79. #define GETDESTCOLOR(col) GETDESTCOLOR8(col)
  80. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 15)
  81. #define GETDESTCOLOR(col) GETDESTCOLOR15(col)
  82. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 16)
  83. #define GETDESTCOLOR(col) GETDESTCOLOR16(col)
  84. #elif (R_DRAWCOLUMN_PIPELINE_BITS == 32)
  85. #define GETDESTCOLOR(col) GETDESTCOLOR32(col)
  86. #endif
  87. #endif
  88. //
  89. // R_FlushWholeOpaque
  90. //
  91. // Flushes the entire columns in the buffer, one at a time.
  92. // This is used when a quad flush isn't possible.
  93. // Opaque version -- no remapping whatsoever.
  94. //
  95. static void R_FLUSHWHOLE_FUNCNAME(void)
  96. {
  97. SCREENTYPE *source;
  98. SCREENTYPE *dest;
  99. int count, yl;
  100. while(--temp_x >= 0)
  101. {
  102. yl = tempyl[temp_x];
  103. source = &TEMPBUF[temp_x + (yl << 2)];
  104. dest = drawvars.TOPLEFT + yl*drawvars.PITCH + startx + temp_x;
  105. count = tempyh[temp_x] - yl + 1;
  106. while(--count >= 0)
  107. {
  108. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  109. *dest = GETDESTCOLOR(*dest, *source);
  110. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  111. // SoM 7-28-04: Fix the fuzz problem.
  112. *dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);
  113. // Clamp table lookup index.
  114. if(++fuzzpos == FUZZTABLE)
  115. fuzzpos = 0;
  116. #else
  117. *dest = *source;
  118. #endif
  119. source += 4;
  120. dest += drawvars.PITCH;
  121. }
  122. }
  123. }
  124. //
  125. // R_FlushHTOpaque
  126. //
  127. // Flushes the head and tail of columns in the buffer in
  128. // preparation for a quad flush.
  129. // Opaque version -- no remapping whatsoever.
  130. //
  131. static void R_FLUSHHEADTAIL_FUNCNAME(void)
  132. {
  133. SCREENTYPE *source;
  134. SCREENTYPE *dest;
  135. int count, colnum = 0;
  136. int yl, yh;
  137. while(colnum < 4)
  138. {
  139. yl = tempyl[colnum];
  140. yh = tempyh[colnum];
  141. // flush column head
  142. if(yl < commontop)
  143. {
  144. source = &TEMPBUF[colnum + (yl << 2)];
  145. dest = drawvars.TOPLEFT + yl*drawvars.PITCH + startx + colnum;
  146. count = commontop - yl;
  147. while(--count >= 0)
  148. {
  149. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  150. // haleyjd 09/11/04: use temptranmap here
  151. *dest = GETDESTCOLOR(*dest, *source);
  152. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  153. // SoM 7-28-04: Fix the fuzz problem.
  154. *dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);
  155. // Clamp table lookup index.
  156. if(++fuzzpos == FUZZTABLE)
  157. fuzzpos = 0;
  158. #else
  159. *dest = *source;
  160. #endif
  161. source += 4;
  162. dest += drawvars.PITCH;
  163. }
  164. }
  165. // flush column tail
  166. if(yh > commonbot)
  167. {
  168. source = &TEMPBUF[colnum + ((commonbot + 1) << 2)];
  169. dest = drawvars.TOPLEFT + (commonbot + 1)*drawvars.PITCH + startx + colnum;
  170. count = yh - commonbot;
  171. while(--count >= 0)
  172. {
  173. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  174. // haleyjd 09/11/04: use temptranmap here
  175. *dest = GETDESTCOLOR(*dest, *source);
  176. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  177. // SoM 7-28-04: Fix the fuzz problem.
  178. *dest = GETDESTCOLOR(dest[fuzzoffset[fuzzpos]]);
  179. // Clamp table lookup index.
  180. if(++fuzzpos == FUZZTABLE)
  181. fuzzpos = 0;
  182. #else
  183. *dest = *source;
  184. #endif
  185. source += 4;
  186. dest += drawvars.PITCH;
  187. }
  188. }
  189. ++colnum;
  190. }
  191. }
  192. static void R_FLUSHQUAD_FUNCNAME(void)
  193. {
  194. SCREENTYPE *source = &TEMPBUF[commontop << 2];
  195. SCREENTYPE *dest = drawvars.TOPLEFT + commontop*drawvars.PITCH + startx;
  196. int count;
  197. #if (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  198. int fuzz1, fuzz2, fuzz3, fuzz4;
  199. fuzz1 = fuzzpos;
  200. fuzz2 = (fuzz1 + tempyl[1]) % FUZZTABLE;
  201. fuzz3 = (fuzz2 + tempyl[2]) % FUZZTABLE;
  202. fuzz4 = (fuzz3 + tempyl[3]) % FUZZTABLE;
  203. #endif
  204. count = commonbot - commontop + 1;
  205. #if (R_DRAWCOLUMN_PIPELINE & RDC_TRANSLUCENT)
  206. while(--count >= 0)
  207. {
  208. dest[0] = GETDESTCOLOR(dest[0], source[0]);
  209. dest[1] = GETDESTCOLOR(dest[1], source[1]);
  210. dest[2] = GETDESTCOLOR(dest[2], source[2]);
  211. dest[3] = GETDESTCOLOR(dest[3], source[3]);
  212. source += 4 * sizeof(byte);
  213. dest += drawvars.PITCH * sizeof(byte);
  214. }
  215. #elif (R_DRAWCOLUMN_PIPELINE & RDC_FUZZ)
  216. while(--count >= 0)
  217. {
  218. dest[0] = GETDESTCOLOR(dest[0 + fuzzoffset[fuzz1]]);
  219. dest[1] = GETDESTCOLOR(dest[1 + fuzzoffset[fuzz2]]);
  220. dest[2] = GETDESTCOLOR(dest[2 + fuzzoffset[fuzz3]]);
  221. dest[3] = GETDESTCOLOR(dest[3 + fuzzoffset[fuzz4]]);
  222. fuzz1 = (fuzz1 + 1) % FUZZTABLE;
  223. fuzz2 = (fuzz2 + 1) % FUZZTABLE;
  224. fuzz3 = (fuzz3 + 1) % FUZZTABLE;
  225. fuzz4 = (fuzz4 + 1) % FUZZTABLE;
  226. source += 4 * sizeof(byte);
  227. dest += drawvars.PITCH * sizeof(byte);
  228. }
  229. #else
  230. #if (R_DRAWCOLUMN_PIPELINE_BITS == 8)
  231. if ((sizeof(int) == 4) && (((int)source % 4) == 0) && (((int)dest % 4) == 0)) {
  232. while(--count >= 0)
  233. {
  234. *(int *)dest = *(int *)source;
  235. source += 4 * sizeof(byte);
  236. dest += drawvars.PITCH * sizeof(byte);
  237. }
  238. } else {
  239. while(--count >= 0)
  240. {
  241. dest[0] = source[0];
  242. dest[1] = source[1];
  243. dest[2] = source[2];
  244. dest[3] = source[3];
  245. source += 4 * sizeof(byte);
  246. dest += drawvars.PITCH * sizeof(byte);
  247. }
  248. }
  249. #else
  250. while(--count >= 0)
  251. {
  252. dest[0] = source[0];
  253. dest[1] = source[1];
  254. dest[2] = source[2];
  255. dest[3] = source[3];
  256. source += 4;
  257. dest += drawvars.PITCH;
  258. }
  259. #endif
  260. #endif
  261. }
  262. #undef GETDESTCOLOR32
  263. #undef GETDESTCOLOR16
  264. #undef GETDESTCOLOR15
  265. #undef GETDESTCOLOR8
  266. #undef GETDESTCOLOR
  267. #undef TEMPBUF
  268. #undef PITCH
  269. #undef TOPLEFT
  270. #undef SCREENTYPE
  271. #undef R_DRAWCOLUMN_PIPELINE_BITS
  272. #undef R_DRAWCOLUMN_PIPELINE
  273. #undef R_FLUSHWHOLE_FUNCNAME
  274. #undef R_FLUSHHEADTAIL_FUNCNAME
  275. #undef R_FLUSHQUAD_FUNCNAME