| 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 |
* DESCRIPTION: |
| 30 |
* The actual span/column drawing functions. |
| 31 |
* Here find the main potential for optimization, |
| 32 |
* e.g. inline assembly, different algorithms. |
| 33 |
* |
| 34 |
*-----------------------------------------------------------------------------*/ |
| 35 |
|
| 36 |
#include <stdint.h> |
| 37 |
|
| 38 |
#include "doomstat.h" |
| 39 |
#include "w_wad.h" |
| 40 |
#include "r_main.h" |
| 41 |
#include "r_draw.h" |
| 42 |
#include "v_video.h" |
| 43 |
#include "st_stuff.h" |
| 44 |
#include "g_game.h" |
| 45 |
#include "am_map.h" |
| 46 |
#include "lprintf.h" |
| 47 |
|
| 48 |
#include "dsda/stretch.h" |
| 49 |
|
| 50 |
// |
| 51 |
// All drawing to the view buffer is accomplished in this file. |
| 52 |
// The other refresh files only know about ccordinates, |
| 53 |
// not the architecture of the frame buffer. |
| 54 |
// Conveniently, the frame buffer is a linear one, |
| 55 |
// and we need only the base address, |
| 56 |
// and the total size == width*height*depth/8., |
| 57 |
// |
| 58 |
|
| 59 |
byte *viewimage; |
| 60 |
int viewwidth; |
| 61 |
int viewheight; |
| 62 |
|
| 63 |
// Color tables for different players, |
| 64 |
// translate a limited part to another |
| 65 |
// (color ramps used for suit colors). |
| 66 |
// |
| 67 |
|
| 68 |
// CPhipps - made const*'s |
| 69 |
const byte *tranmap; // translucency filter maps 256x256 // phares |
| 70 |
const byte *main_tranmap; // killough 4/11/98 |
| 71 |
|
| 72 |
// |
| 73 |
// R_DrawColumn |
| 74 |
// Source is the top of the column to scale. |
| 75 |
// |
| 76 |
|
| 77 |
// SoM: OPTIMIZE for ANYRES |
| 78 |
typedef enum |
| 79 |
{ |
| 80 |
COL_NONE, |
| 81 |
COL_OPAQUE, |
| 82 |
COL_TRANS, |
| 83 |
COL_FLEXTRANS, |
| 84 |
COL_FUZZ, |
| 85 |
COL_FLEXADD |
| 86 |
} columntype_e; |
| 87 |
|
| 88 |
static int temp_x = 0; |
| 89 |
static int tempyl[4], tempyh[4]; |
| 90 |
|
| 91 |
// e6y: resolution limitation is removed |
| 92 |
static byte *tempbuf; |
| 93 |
|
| 94 |
static int startx = 0; |
| 95 |
static int temptype = COL_NONE; |
| 96 |
static int commontop, commonbot; |
| 97 |
static const byte *temptranmap = NULL; |
| 98 |
// SoM 7-28-04: Fix the fuzz problem. |
| 99 |
static const byte *tempfuzzmap; |
| 100 |
|
| 101 |
// |
| 102 |
// Spectre/Invisibility. |
| 103 |
// |
| 104 |
|
| 105 |
#define FUZZTABLE 50 |
| 106 |
// proff 08/17/98: Changed for high-res |
| 107 |
//#define FUZZOFF (SCREENWIDTH) |
| 108 |
#define FUZZOFF 1 |
| 109 |
|
| 110 |
static const int fuzzoffset_org[FUZZTABLE] = { |
| 111 |
FUZZOFF,-FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF, |
| 112 |
FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF, |
| 113 |
FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF, |
| 114 |
FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF, |
| 115 |
FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF, |
| 116 |
FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF, |
| 117 |
FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF,FUZZOFF,-FUZZOFF,FUZZOFF |
| 118 |
}; |
| 119 |
|
| 120 |
static int fuzzoffset[FUZZTABLE]; |
| 121 |
|
| 122 |
static int fuzzpos = 0; |
| 123 |
|
| 124 |
// Fuzz cell size for scaled software fuzz |
| 125 |
static int fuzzcellsize; |
| 126 |
|
| 127 |
// render pipelines |
| 128 |
#define RDC_STANDARD 1 |
| 129 |
#define RDC_TRANSLUCENT 2 |
| 130 |
#define RDC_TRANSLATED 4 |
| 131 |
#define RDC_FUZZ 8 |
| 132 |
// no color mapping |
| 133 |
#define RDC_NOCOLMAP 16 |
| 134 |
|
| 135 |
draw_vars_t drawvars = { |
| 136 |
NULL, // topleft |
| 137 |
0, // pitch |
| 138 |
}; |
| 139 |
|
| 140 |
dboolean R_FullView(void) |
| 141 |
{ |
| 142 |
return viewheight == SCREENHEIGHT; |
| 143 |
} |
| 144 |
|
| 145 |
dboolean R_PartialView(void) |
| 146 |
{ |
| 147 |
return viewheight != SCREENHEIGHT; |
| 148 |
} |
| 149 |
|
| 150 |
dboolean R_StatusBarVisible(void) |
| 151 |
{ |
| 152 |
return R_PartialView() || automap_on; |
| 153 |
} |
| 154 |
|
| 155 |
// |
| 156 |
// Error functions that will abort if R_FlushColumns tries to flush |
| 157 |
// columns without a column type. |
| 158 |
// |
| 159 |
|
| 160 |
static void R_FlushWholeError(void) |
| 161 |
{ |
| 162 |
I_Error("R_FlushWholeColumns called without being initialized.\n"); |
| 163 |
} |
| 164 |
|
| 165 |
static void R_FlushHTError(void) |
| 166 |
{ |
| 167 |
I_Error("R_FlushHTColumns called without being initialized.\n"); |
| 168 |
} |
| 169 |
|
| 170 |
static void R_QuadFlushError(void) |
| 171 |
{ |
| 172 |
I_Error("R_FlushQuadColumn called without being initialized.\n"); |
| 173 |
} |
| 174 |
|
| 175 |
static void (*R_FlushWholeColumns)(void) = R_FlushWholeError; |
| 176 |
static void (*R_FlushHTColumns)(void) = R_FlushHTError; |
| 177 |
static void (*R_FlushQuadColumn)(void) = R_QuadFlushError; |
| 178 |
|
| 179 |
static void R_FlushColumns(void) |
| 180 |
{ |
| 181 |
if(temp_x != 4 || commontop >= commonbot) |
| 182 |
R_FlushWholeColumns(); |
| 183 |
else |
| 184 |
{ |
| 185 |
R_FlushHTColumns(); |
| 186 |
R_FlushQuadColumn(); |
| 187 |
} |
| 188 |
temp_x = 0; |
| 189 |
} |
| 190 |
|
| 191 |
// |
| 192 |
// R_ResetColumnBuffer |
| 193 |
// |
| 194 |
// haleyjd 09/13/04: new function to call from main rendering loop |
| 195 |
// which gets rid of the unnecessary reset of various variables during |
| 196 |
// column drawing. |
| 197 |
// |
| 198 |
void R_ResetColumnBuffer(void) |
| 199 |
{ |
| 200 |
// haleyjd 10/06/05: this must not be done if temp_x == 0! |
| 201 |
if(temp_x) |
| 202 |
R_FlushColumns(); |
| 203 |
temptype = COL_NONE; |
| 204 |
R_FlushWholeColumns = R_FlushWholeError; |
| 205 |
R_FlushHTColumns = R_FlushHTError; |
| 206 |
R_FlushQuadColumn = R_QuadFlushError; |
| 207 |
} |
| 208 |
|
| 209 |
#define R_DRAWCOLUMN_PIPELINE RDC_STANDARD |
| 210 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole |
| 211 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT |
| 212 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad |
| 213 |
#include "r_drawflush.inl" |
| 214 |
|
| 215 |
#define R_DRAWCOLUMN_PIPELINE RDC_TRANSLUCENT |
| 216 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeTL |
| 217 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTTL |
| 218 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadTL |
| 219 |
#include "r_drawflush.inl" |
| 220 |
|
| 221 |
#define R_DRAWCOLUMN_PIPELINE RDC_FUZZ |
| 222 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeFuzz |
| 223 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTFuzz |
| 224 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadFuzz |
| 225 |
#include "r_drawflush.inl" |
| 226 |
|
| 227 |
// |
| 228 |
// R_DrawColumn |
| 229 |
// |
| 230 |
|
| 231 |
// |
| 232 |
// A column is a vertical slice/span from a wall texture that, |
| 233 |
// given the DOOM style restrictions on the view orientation, |
| 234 |
// will always have constant z depth. |
| 235 |
// Thus a special case loop for very fast rendering can |
| 236 |
// be used. It has also been used with Wolfenstein 3D. |
| 237 |
// |
| 238 |
|
| 239 |
byte *translationtables; |
| 240 |
|
| 241 |
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_STANDARD |
| 242 |
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_STANDARD |
| 243 |
|
| 244 |
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawColumn ## postfix |
| 245 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole |
| 246 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT |
| 247 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad |
| 248 |
#include "r_drawcolpipeline.inl" |
| 249 |
|
| 250 |
#undef R_DRAWCOLUMN_PIPELINE_BASE |
| 251 |
#undef R_DRAWCOLUMN_PIPELINE_TYPE |
| 252 |
|
| 253 |
// Here is the version of R_DrawColumn that deals with translucent // phares |
| 254 |
// textures and sprites. It's identical to R_DrawColumn except // | |
| 255 |
// for the spot where the color index is stuffed into *dest. At // V |
| 256 |
// that point, the existing color index and the new color index |
| 257 |
// are mapped through the TRANMAP lump filters to get a new color |
| 258 |
// index whose RGB values are the average of the existing and new |
| 259 |
// colors. |
| 260 |
// |
| 261 |
// Since we're concerned about performance, the 'translucent or |
| 262 |
// opaque' decision is made outside this routine, not down where the |
| 263 |
// actual code differences are. |
| 264 |
|
| 265 |
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_TRANSLUCENT |
| 266 |
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_TRANSLUCENT |
| 267 |
|
| 268 |
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawTLColumn ## postfix |
| 269 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeTL |
| 270 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTTL |
| 271 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadTL |
| 272 |
#include "r_drawcolpipeline.inl" |
| 273 |
|
| 274 |
#undef R_DRAWCOLUMN_PIPELINE_BASE |
| 275 |
#undef R_DRAWCOLUMN_PIPELINE_TYPE |
| 276 |
|
| 277 |
// |
| 278 |
// R_DrawTranslatedColumn |
| 279 |
// Used to draw player sprites |
| 280 |
// with the green colorramp mapped to others. |
| 281 |
// Could be used with different translation |
| 282 |
// tables, e.g. the lighter colored version |
| 283 |
// of the BaronOfHell, the HellKnight, uses |
| 284 |
// identical sprites, kinda brightened up. |
| 285 |
// |
| 286 |
|
| 287 |
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_TRANSLATED |
| 288 |
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_TRANSLATED |
| 289 |
|
| 290 |
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawTranslatedColumn ## postfix |
| 291 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWhole |
| 292 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHT |
| 293 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuad |
| 294 |
#include "r_drawcolpipeline.inl" |
| 295 |
|
| 296 |
#undef R_DRAWCOLUMN_PIPELINE_BASE |
| 297 |
#undef R_DRAWCOLUMN_PIPELINE_TYPE |
| 298 |
|
| 299 |
// |
| 300 |
// Framebuffer postprocessing. |
| 301 |
// Creates a fuzzy image by copying pixels |
| 302 |
// from adjacent ones to left and right. |
| 303 |
// Used with an all black colormap, this |
| 304 |
// could create the SHADOW effect, |
| 305 |
// i.e. spectres and invisible players. |
| 306 |
// |
| 307 |
|
| 308 |
#define R_DRAWCOLUMN_PIPELINE_TYPE RDC_PIPELINE_FUZZ |
| 309 |
#define R_DRAWCOLUMN_PIPELINE_BASE RDC_FUZZ |
| 310 |
|
| 311 |
#define R_DRAWCOLUMN_FUNCNAME_COMPOSITE(postfix) R_DrawFuzzColumn ## postfix |
| 312 |
#define R_FLUSHWHOLE_FUNCNAME R_FlushWholeFuzz |
| 313 |
#define R_FLUSHHEADTAIL_FUNCNAME R_FlushHTFuzz |
| 314 |
#define R_FLUSHQUAD_FUNCNAME R_FlushQuadFuzz |
| 315 |
#include "r_drawcolpipeline.inl" |
| 316 |
|
| 317 |
#undef R_DRAWCOLUMN_PIPELINE_BASE |
| 318 |
#undef R_DRAWCOLUMN_PIPELINE_TYPE |
| 319 |
|
| 320 |
static R_DrawColumn_f drawcolumnfuncs[RDRAW_FILTER_MAXFILTERS][RDC_PIPELINE_MAXPIPELINES] = { |
| 321 |
{ |
| 322 |
R_DrawColumn_PointUV, |
| 323 |
R_DrawTLColumn_PointUV, |
| 324 |
R_DrawTranslatedColumn_PointUV, |
| 325 |
R_DrawFuzzColumn_PointUV, |
| 326 |
}, |
| 327 |
{ |
| 328 |
R_DrawColumn_PointUV_PointZ, |
| 329 |
R_DrawTLColumn_PointUV_PointZ, |
| 330 |
R_DrawTranslatedColumn_PointUV_PointZ, |
| 331 |
R_DrawFuzzColumn_PointUV_PointZ, |
| 332 |
}, |
| 333 |
}; |
| 334 |
|
| 335 |
R_DrawColumn_f R_GetDrawColumnFunc(enum column_pipeline_e type, enum draw_filter_type_e filterz) { |
| 336 |
R_DrawColumn_f result = drawcolumnfuncs[filterz][type]; |
| 337 |
if (result == NULL) |
| 338 |
I_Error("R_GetDrawColumnFunc: undefined function (%d, %d)", type, filterz); |
| 339 |
return result; |
| 340 |
} |
| 341 |
|
| 342 |
void R_SetDefaultDrawColumnVars(draw_column_vars_t *dcvars) { |
| 343 |
dcvars->x = dcvars->yl = dcvars->yh = 0; |
| 344 |
dcvars->iscale = dcvars->texturemid = dcvars->texheight = 0; |
| 345 |
dcvars->source = dcvars->prevsource = dcvars->nextsource = NULL; |
| 346 |
dcvars->colormap = colormaps[0]; |
| 347 |
dcvars->translation = NULL; |
| 348 |
dcvars->edgeslope = dcvars->drawingmasked = 0; |
| 349 |
dcvars->flags = 0; |
| 350 |
|
| 351 |
// heretic |
| 352 |
dcvars->baseclip = -1; |
| 353 |
} |
| 354 |
|
| 355 |
// |
| 356 |
// R_InitTranslationTables |
| 357 |
// Creates the translation tables to map |
| 358 |
// the green color ramp to gray, brown, red. |
| 359 |
// Assumes a given structure of the PLAYPAL. |
| 360 |
// Could be read from a lump instead. |
| 361 |
// |
| 362 |
|
| 363 |
byte playernumtotrans[MAX_MAXPLAYERS]; |
| 364 |
|
| 365 |
// HERETIC_TODO: player colors |
| 366 |
const byte player_colors[] = { 0x70, 0x60, 0x40, 0x20 }; |
| 367 |
|
| 368 |
void R_InitTranslationTables (void) |
| 369 |
{ |
| 370 |
int i, j; |
| 371 |
#define MAXTRANS 3 |
| 372 |
byte transtocolour[MAXTRANS]; |
| 373 |
|
| 374 |
if (hexen) |
| 375 |
{ |
| 376 |
int lumpnum = W_GetNumForName("trantbl0"); |
| 377 |
translationtables = Z_Malloc(256 * 3 * (g_maxplayers - 1)); |
| 378 |
|
| 379 |
for (i = 0; i < g_maxplayers; i++) |
| 380 |
playernumtotrans[i] = i; |
| 381 |
|
| 382 |
for (i = 0; i < 3 * (g_maxplayers - 1); i++) |
| 383 |
{ |
| 384 |
const byte* transLump = W_LumpByNum(lumpnum + i); |
| 385 |
memcpy(translationtables + i * 256, transLump, 256); |
| 386 |
} |
| 387 |
|
| 388 |
return; |
| 389 |
} |
| 390 |
|
| 391 |
// killough 5/2/98: |
| 392 |
// Remove dependency of colormaps aligned on 256-byte boundary |
| 393 |
|
| 394 |
if (translationtables == NULL) // CPhipps - allow multiple calls |
| 395 |
translationtables = Z_Malloc(256*MAXTRANS); |
| 396 |
|
| 397 |
for (i=0; i<MAXTRANS; i++) transtocolour[i] = 255; |
| 398 |
|
| 399 |
for (i = 0; i < g_maxplayers; i++) { |
| 400 |
byte wantcolour = player_colors[i]; |
| 401 |
playernumtotrans[i] = 0; |
| 402 |
if (wantcolour != 0x70) // Not green, would like translation |
| 403 |
for (j = 0; j < MAXTRANS; j++) |
| 404 |
if (transtocolour[j] == 255) { |
| 405 |
transtocolour[j] = wantcolour; |
| 406 |
playernumtotrans[i] = j + 1; |
| 407 |
break; |
| 408 |
} |
| 409 |
} |
| 410 |
|
| 411 |
// translate just the 16 green colors |
| 412 |
for (i=0; i<256; i++) |
| 413 |
if (i >= 0x70 && i<= 0x7f) |
| 414 |
{ |
| 415 |
// CPhipps - configurable player colours |
| 416 |
translationtables[i] = colormaps[0][(i&0xf) + transtocolour[0]]; |
| 417 |
translationtables[i+256] = colormaps[0][(i&0xf) + transtocolour[1]]; |
| 418 |
translationtables[i+512] = colormaps[0][(i&0xf) + transtocolour[2]]; |
| 419 |
} |
| 420 |
else // Keep all other colors as is. |
| 421 |
translationtables[i]=translationtables[i+256]=translationtables[i+512]=i; |
| 422 |
} |
| 423 |
|
| 424 |
// |
| 425 |
// R_DrawSpan |
| 426 |
// With DOOM style restrictions on view orientation, |
| 427 |
// the floors and ceilings consist of horizontal slices |
| 428 |
// or spans with constant z depth. |
| 429 |
// However, rotation around the world z axis is possible, |
| 430 |
// thus this mapping, while simpler and faster than |
| 431 |
// perspective correct texture mapping, has to traverse |
| 432 |
// the texture at an angle in all but a few cases. |
| 433 |
// In consequence, flats are not stored by column (like walls), |
| 434 |
// and the inner loop has to step in texture space u and v. |
| 435 |
// |
| 436 |
|
| 437 |
void R_DrawSpan(draw_span_vars_t *dsvars) { |
| 438 |
unsigned count = dsvars->x2 - dsvars->x1 + 1; |
| 439 |
fixed_t xfrac = dsvars->xfrac; |
| 440 |
fixed_t yfrac = dsvars->yfrac; |
| 441 |
const fixed_t xstep = dsvars->xstep; |
| 442 |
const fixed_t ystep = dsvars->ystep; |
| 443 |
const byte *source = dsvars->source; |
| 444 |
const byte *colormap = dsvars->colormap; |
| 445 |
byte *dest = drawvars.topleft + dsvars->y*drawvars.pitch + dsvars->x1; |
| 446 |
|
| 447 |
while (count) { |
| 448 |
const fixed_t xtemp = (xfrac >> 16) & 63; |
| 449 |
const fixed_t ytemp = (yfrac >> 10) & 4032; |
| 450 |
const fixed_t spot = xtemp | ytemp; |
| 451 |
xfrac += xstep; |
| 452 |
yfrac += ystep; |
| 453 |
*dest++ = colormap[source[spot]]; |
| 454 |
count--; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
void R_InitBuffersRes(void) |
| 459 |
{ |
| 460 |
extern byte *solidcol; |
| 461 |
|
| 462 |
if (solidcol) Z_Free(solidcol); |
| 463 |
if (tempbuf) Z_Free(tempbuf); |
| 464 |
|
| 465 |
solidcol = Z_Calloc(1, SCREENWIDTH * sizeof(*solidcol)); |
| 466 |
tempbuf = Z_Calloc(1, (SCREENHEIGHT * 4) * sizeof(*tempbuf)); |
| 467 |
|
| 468 |
temp_x = 0; |
| 469 |
} |
| 470 |
|
| 471 |
// |
| 472 |
// R_InitBuffer |
| 473 |
// Creats lookup tables that avoid |
| 474 |
// multiplies and other hazzles |
| 475 |
// for getting the framebuffer address |
| 476 |
// of a pixel to draw. |
| 477 |
// |
| 478 |
|
| 479 |
void R_InitBuffer(int width, int height) |
| 480 |
{ |
| 481 |
int i; |
| 482 |
|
| 483 |
drawvars.topleft = screens[0].data; |
| 484 |
drawvars.pitch = screens[0].pitch; |
| 485 |
|
| 486 |
for (i=0; i<FUZZTABLE; i++) |
| 487 |
fuzzoffset[i] = fuzzoffset_org[i]*screens[0].pitch; |
| 488 |
|
| 489 |
if (!tallscreen) |
| 490 |
fuzzcellsize = (SCREENHEIGHT + 100) / 200; |
| 491 |
else |
| 492 |
fuzzcellsize = (SCREENWIDTH + 160) / 320; |
| 493 |
} |
| 494 |
|
| 495 |
// |
| 496 |
// R_FillBackColor |
| 497 |
// Fills the statusbar widescreen area |
| 498 |
// with a color |
| 499 |
// |
| 500 |
|
| 501 |
void R_FillBackColor (void) |
| 502 |
{ |
| 503 |
extern patchnum_t stbarbg; |
| 504 |
static byte col; |
| 505 |
static byte col_top; |
| 506 |
static int prevlump = -1; |
| 507 |
const int stbar_top = SCREENHEIGHT - ST_SCALED_HEIGHT; |
| 508 |
const int ST_SCALED_BORDER = brdr_b.height * patches_scaley/2; |
| 509 |
int lump = stbarbg.lumpnum; |
| 510 |
|
| 511 |
if (prevlump != lump) |
| 512 |
{ |
| 513 |
const unsigned char *playpal = V_GetPlaypal(); |
| 514 |
SDL_Color stbar_color = V_GetPatchColor(lump); |
| 515 |
int r = stbar_color.r; |
| 516 |
int g = stbar_color.g; |
| 517 |
int b = stbar_color.b; |
| 518 |
|
| 519 |
// Convert to palette and tune down saturation |
| 520 |
col = V_BestColor(playpal, r/3, g/3, b/3); |
| 521 |
col_top = V_BestColor(playpal, r/2, g/2, b/2); |
| 522 |
|
| 523 |
// If colors are the same, brighten top |
| 524 |
if (col_top == col) |
| 525 |
col_top = V_BestColor(playpal, r, g, b); |
| 526 |
|
| 527 |
prevlump = lump; |
| 528 |
} |
| 529 |
|
| 530 |
V_BeginMenuDraw(); |
| 531 |
V_FillRect(1, 0, stbar_top, SCREENWIDTH, ST_SCALED_BORDER, col_top); |
| 532 |
V_FillRect(1, 0, stbar_top + ST_SCALED_BORDER, SCREENWIDTH, ST_SCALED_HEIGHT - ST_SCALED_BORDER, col); |
| 533 |
V_EndMenuDraw(); |
| 534 |
} |
| 535 |
|
| 536 |
// |
| 537 |
// R_FillBackScreen |
| 538 |
// Fills the back screen with a pattern |
| 539 |
// for variable screen sizes |
| 540 |
// Also draws a beveled edge. |
| 541 |
// |
| 542 |
// CPhipps - patch drawing updated |
| 543 |
|
| 544 |
void R_FillBackScreen (void) |
| 545 |
{ |
| 546 |
int automap = automap_on; |
| 547 |
|
| 548 |
if (grnrock.lumpnum == 0) |
| 549 |
return; |
| 550 |
|
| 551 |
V_BeginUIDraw(); |
| 552 |
|
| 553 |
// e6y: wide-res |
| 554 |
if (ratio_multiplier != ratio_scale || wide_offsety) |
| 555 |
{ |
| 556 |
int only_stbar; |
| 557 |
|
| 558 |
only_stbar = V_IsSoftwareMode() || automap || R_PartialView(); |
| 559 |
|
| 560 |
if (only_stbar && ST_SCALED_OFFSETX > 0) |
| 561 |
{ |
| 562 |
int stbar_top = SCREENHEIGHT - ST_SCALED_HEIGHT; |
| 563 |
int stbar_solid_bg = dsda_IntConfig(dsda_config_sts_solid_bg_color); |
| 564 |
|
| 565 |
if (stbar_solid_bg) |
| 566 |
{ |
| 567 |
R_FillBackColor(); |
| 568 |
V_EndUIDraw(); |
| 569 |
return; |
| 570 |
} |
| 571 |
|
| 572 |
if (V_IsOpenGLMode()) // OpenGL has no way to adjust y-offset independent from height |
| 573 |
V_FillFlat(grnrock.lumpnum, 1, 0, 0, SCREENWIDTH, SCREENHEIGHT, VPT_STRETCH); |
| 574 |
else |
| 575 |
V_FillFlat(grnrock.lumpnum, 1, 0, stbar_top, SCREENWIDTH, ST_SCALED_HEIGHT, VPT_STRETCH); |
| 576 |
|
| 577 |
// heretic_note: I think this looks bad, so I'm skipping it... |
| 578 |
if (!heretic) |
| 579 |
{ |
| 580 |
// line between view and status bar |
| 581 |
V_FillPatch(brdr_b.lumpnum, 1, 0, stbar_top, ST_SCALED_OFFSETX, brdr_b.height, VPT_NONE); |
| 582 |
V_FillPatch(brdr_b.lumpnum, 1, SCREENWIDTH - ST_SCALED_OFFSETX, stbar_top, ST_SCALED_OFFSETX, brdr_b.height, VPT_NONE); |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
V_EndUIDraw(); |
| 588 |
} |
| 589 |
|
| 590 |
// |
| 591 |
// Copy a screen buffer. |
| 592 |
// |
| 593 |
|
| 594 |
static void R_CopyScreenBufferSection(int x, int y, int count) |
| 595 |
{ |
| 596 |
if (V_IsSoftwareMode()) |
| 597 |
memcpy(screens[0].data+y*screens[0].pitch+x, |
| 598 |
screens[1].data+y*screens[1].pitch+x, |
| 599 |
count); // LFB copy. |
| 600 |
} |
| 601 |
|
| 602 |
// |
| 603 |
// R_DrawViewBorder |
| 604 |
// Draws the border around the view |
| 605 |
// for different size windows? |
| 606 |
// |
| 607 |
|
| 608 |
void R_DrawViewBorder(void) |
| 609 |
{ |
| 610 |
int i; |
| 611 |
|
| 612 |
if (V_IsOpenGLMode()) { |
| 613 |
// proff 11/99: we don't have a backscreen in OpenGL from where we can copy this |
| 614 |
R_FillBackScreen(); |
| 615 |
return; |
| 616 |
} |
| 617 |
|
| 618 |
// e6y: wide-res |
| 619 |
if ((ratio_multiplier != ratio_scale || wide_offsety) && R_StatusBarVisible()) |
| 620 |
{ |
| 621 |
for (i = SCREENHEIGHT - ST_SCALED_HEIGHT; i < SCREENHEIGHT; i++) |
| 622 |
{ |
| 623 |
R_CopyScreenBufferSection(0, i, ST_SCALED_OFFSETX); |
| 624 |
R_CopyScreenBufferSection(SCREENWIDTH - ST_SCALED_OFFSETX, i, ST_SCALED_OFFSETX); |
| 625 |
} |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
void R_SetFuzzPos(int fp) |
| 630 |
{ |
| 631 |
fuzzpos = fp; |
| 632 |
} |
| 633 |
|
| 634 |
int R_GetFuzzPos() |
| 635 |
{ |
| 636 |
return fuzzpos; |
| 637 |
} |
| 638 |
|
| 639 |
void R_ResetFuzzCol(int height) |
| 640 |
{ |
| 641 |
R_ResetColumnBuffer(); |
| 642 |
|
| 643 |
fuzzpos = (fuzzpos + (height / fuzzcellsize)) % FUZZTABLE; |
| 644 |
} |
| 645 |
|
| 646 |
void R_CheckFuzzCol(int x, int height) |
| 647 |
{ |
| 648 |
if (!(x % fuzzcellsize)) |
| 649 |
R_ResetFuzzCol(height); |
| 650 |
} |