r_drawspan.inl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. //
  31. // R_DrawSpan
  32. //
  33. #if (R_DRAWSPAN_PIPELINE_BITS == 8)
  34. #define SCREENTYPE byte
  35. #define TOPLEFT byte_topleft
  36. #define PITCH byte_pitch
  37. #elif (R_DRAWSPAN_PIPELINE_BITS == 15)
  38. #define SCREENTYPE unsigned short
  39. #define TOPLEFT short_topleft
  40. #define PITCH short_pitch
  41. #elif (R_DRAWSPAN_PIPELINE_BITS == 16)
  42. #define SCREENTYPE unsigned short
  43. #define TOPLEFT short_topleft
  44. #define PITCH short_pitch
  45. #elif (R_DRAWSPAN_PIPELINE_BITS == 32)
  46. #define SCREENTYPE unsigned int
  47. #define TOPLEFT int_topleft
  48. #define PITCH int_pitch
  49. #endif
  50. #if (R_DRAWSPAN_PIPELINE & RDC_DITHERZ)
  51. #define GETDEPTHMAP(col) dither_colormaps[filter_getDitheredPixelLevel(x1, y, fracz)][(col)]
  52. #else
  53. #define GETDEPTHMAP(col) colormap[(col)]
  54. #endif
  55. #if (R_DRAWSPAN_PIPELINE_BITS == 8)
  56. #define GETCOL_POINT(col) GETDEPTHMAP(col)
  57. #define GETCOL_LINEAR(col) GETDEPTHMAP(col)
  58. #elif (R_DRAWSPAN_PIPELINE_BITS == 15)
  59. #define GETCOL_POINT(col) VID_PAL15(GETDEPTHMAP(col), VID_COLORWEIGHTMASK)
  60. #define GETCOL_LINEAR(col) filter_getFilteredForSpan15(GETDEPTHMAP, xfrac, yfrac)
  61. #elif (R_DRAWSPAN_PIPELINE_BITS == 16)
  62. #define GETCOL_POINT(col) VID_PAL16(GETDEPTHMAP(col), VID_COLORWEIGHTMASK)
  63. #define GETCOL_LINEAR(col) filter_getFilteredForSpan16(GETDEPTHMAP, xfrac, yfrac)
  64. #elif (R_DRAWSPAN_PIPELINE_BITS == 32)
  65. #define GETCOL_POINT(col) VID_PAL32(GETDEPTHMAP(col), VID_COLORWEIGHTMASK)
  66. #define GETCOL_LINEAR(col) filter_getFilteredForSpan32(GETDEPTHMAP, xfrac, yfrac)
  67. #endif
  68. #if (R_DRAWSPAN_PIPELINE & RDC_BILINEAR)
  69. #define GETCOL(col) GETCOL_LINEAR(col)
  70. #else
  71. #define GETCOL(col) GETCOL_POINT(col)
  72. #endif
  73. static void R_DRAWSPAN_FUNCNAME(draw_span_vars_t *dsvars)
  74. {
  75. #if (R_DRAWSPAN_PIPELINE & (RDC_ROUNDED|RDC_BILINEAR))
  76. // drop back to point filtering if we're minifying
  77. // 49152 = FRACUNIT * 0.75
  78. if ((D_abs(dsvars->xstep) > drawvars.mag_threshold)
  79. || (D_abs(dsvars->ystep) > drawvars.mag_threshold))
  80. {
  81. R_GetDrawSpanFunc(RDRAW_FILTER_POINT,
  82. drawvars.filterz)(dsvars);
  83. return;
  84. }
  85. #endif
  86. {
  87. unsigned count = dsvars->x2 - dsvars->x1 + 1;
  88. fixed_t xfrac = dsvars->xfrac;
  89. fixed_t yfrac = dsvars->yfrac;
  90. const fixed_t xstep = dsvars->xstep;
  91. const fixed_t ystep = dsvars->ystep;
  92. const byte *source = dsvars->source;
  93. const byte *colormap = dsvars->colormap;
  94. (void)colormap;
  95. SCREENTYPE *dest = drawvars.TOPLEFT + dsvars->y*drawvars.PITCH + dsvars->x1;
  96. #if (R_DRAWSPAN_PIPELINE & (RDC_DITHERZ|RDC_BILINEAR))
  97. const int y = dsvars->y;
  98. int x1 = dsvars->x1;
  99. (void)y;
  100. (void)x1;
  101. #endif
  102. #if (R_DRAWSPAN_PIPELINE & RDC_DITHERZ)
  103. const int fracz = (dsvars->z >> 12) & 255;
  104. const byte *dither_colormaps[2] = { dsvars->colormap, dsvars->nextcolormap };
  105. #endif
  106. while (count) {
  107. #if ((R_DRAWSPAN_PIPELINE_BITS != 8) && (R_DRAWSPAN_PIPELINE & RDC_BILINEAR))
  108. // truecolor bilinear filtered
  109. *dest++ = GETCOL(0);
  110. xfrac += xstep;
  111. yfrac += ystep;
  112. count--;
  113. #if (R_DRAWSPAN_PIPELINE & RDC_DITHERZ)
  114. x1--;
  115. #endif
  116. #elif (R_DRAWSPAN_PIPELINE & RDC_ROUNDED)
  117. *dest++ = GETCOL(filter_getRoundedForSpan(xfrac, yfrac));
  118. xfrac += xstep;
  119. yfrac += ystep;
  120. count--;
  121. #if (R_DRAWSPAN_PIPELINE & RDC_DITHERZ)
  122. x1--;
  123. #endif
  124. #else
  125. #if (R_DRAWSPAN_PIPELINE & RDC_BILINEAR)
  126. // 8 bit bilinear
  127. const fixed_t xtemp = ((xfrac >> 16) + (filter_getDitheredPixelLevel(x1, y, ((xfrac>>8)&0xff)))) & 63;
  128. const fixed_t ytemp = ((yfrac >> 10) + 64*(filter_getDitheredPixelLevel(x1, y, ((yfrac>>8)&0xff)))) & 4032;
  129. #else
  130. const fixed_t xtemp = (xfrac >> 16) & 63;
  131. const fixed_t ytemp = (yfrac >> 10) & 4032;
  132. #endif
  133. const fixed_t spot = xtemp | ytemp;
  134. xfrac += xstep;
  135. yfrac += ystep;
  136. *dest++ = GETCOL(source[spot]);
  137. count--;
  138. #if (R_DRAWSPAN_PIPELINE & (RDC_DITHERZ|RDC_BILINEAR))
  139. x1--;
  140. #endif
  141. #endif
  142. }
  143. }
  144. }
  145. #undef GETDEPTHMAP
  146. #undef GETCOL_LINEAR
  147. #undef GETCOL_POINT
  148. #undef GETCOL
  149. #undef PITCH
  150. #undef TOPLEFT
  151. #undef SCREENTYPE
  152. #undef R_DRAWSPAN_PIPELINE_BITS
  153. #undef R_DRAWSPAN_PIPELINE
  154. #undef R_DRAWSPAN_FUNCNAME