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