2001-08-25 02:47:11 +00:00
|
|
|
/*
|
|
|
|
sw32_rmain.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/mathlib.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/screen.h"
|
|
|
|
#include "QF/sound.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2004-07-11 00:37:48 +00:00
|
|
|
#include "compat.h"
|
2012-04-10 04:27:53 +00:00
|
|
|
#include "mod_internal.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
//define PASSAGES
|
|
|
|
|
2012-02-18 05:34:14 +00:00
|
|
|
static vec3_t viewlightvec;
|
|
|
|
static alight_t r_viewlighting = { 128, 192, viewlightvec };
|
2012-02-22 07:32:34 +00:00
|
|
|
int sw32_r_numallocatededges;
|
|
|
|
qboolean sw32_r_drawpolys;
|
|
|
|
qboolean sw32_r_drawculledpolys;
|
|
|
|
qboolean sw32_r_worldpolysbacktofront;
|
|
|
|
float sw32_r_aliasuvscale = 1.0;
|
|
|
|
int sw32_r_outofsurfaces;
|
|
|
|
int sw32_r_outofedges;
|
|
|
|
|
|
|
|
qboolean sw32_r_dowarp, sw32_r_dowarpold, sw32_r_viewchanged;
|
|
|
|
|
|
|
|
int sw32_c_surf;
|
|
|
|
int sw32_r_maxsurfsseen, sw32_r_maxedgesseen;
|
2012-02-18 05:34:14 +00:00
|
|
|
static int r_cnumsurfs;
|
|
|
|
static qboolean r_surfsonstack;
|
2012-02-22 07:32:34 +00:00
|
|
|
int sw32_r_clipflags;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
byte *sw32_r_warpbuffer;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-18 05:34:14 +00:00
|
|
|
static byte *r_stack_start;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// screen size info
|
2012-02-22 07:32:34 +00:00
|
|
|
float sw32_xcenter, sw32_ycenter;
|
|
|
|
float sw32_xscale, sw32_yscale;
|
|
|
|
float sw32_xscaleinv, sw32_yscaleinv;
|
|
|
|
float sw32_xscaleshrink, sw32_yscaleshrink;
|
|
|
|
float sw32_aliasxscale, sw32_aliasyscale, sw32_aliasxcenter, sw32_aliasycenter;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
int sw32_screenwidth;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
float sw32_pixelAspect;
|
2012-02-18 05:34:14 +00:00
|
|
|
static float screenAspect;
|
|
|
|
static float verticalFieldOfView;
|
|
|
|
static float xOrigin, yOrigin;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
plane_t sw32_screenedge[4];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// refresh flags
|
2012-02-22 07:32:34 +00:00
|
|
|
int sw32_r_polycount;
|
|
|
|
int sw32_r_drawnpolycount;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
int *sw32_pfrustum_indexes[4];
|
|
|
|
int sw32_r_frustum_indexes[4 * 6];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
float sw32_r_aliastransition, sw32_r_resfudge;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-21 05:10:20 +00:00
|
|
|
static float dp_time1, dp_time2, db_time1, db_time2, rw_time1, rw_time2;
|
|
|
|
static float se_time1, se_time2, de_time1, de_time2, dv_time1, dv_time2;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_Textures_Init (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int x, y, m;
|
|
|
|
byte *dest;
|
|
|
|
|
|
|
|
// create a simple checkerboard texture for the default
|
|
|
|
r_notexture_mip =
|
2021-07-28 06:01:45 +00:00
|
|
|
Hunk_AllocName (0, sizeof (texture_t) + 16 * 16 + 8 * 8 + 4 * 4 + 2 * 2,
|
2001-08-25 02:47:11 +00:00
|
|
|
"notexture");
|
|
|
|
|
|
|
|
r_notexture_mip->width = r_notexture_mip->height = 16;
|
|
|
|
r_notexture_mip->offsets[0] = sizeof (texture_t);
|
|
|
|
|
|
|
|
r_notexture_mip->offsets[1] = r_notexture_mip->offsets[0] + 16 * 16;
|
|
|
|
r_notexture_mip->offsets[2] = r_notexture_mip->offsets[1] + 8 * 8;
|
|
|
|
r_notexture_mip->offsets[3] = r_notexture_mip->offsets[2] + 4 * 4;
|
|
|
|
|
|
|
|
for (m = 0; m < 4; m++) {
|
|
|
|
dest = (byte *) r_notexture_mip + r_notexture_mip->offsets[m];
|
|
|
|
for (y = 0; y < (16 >> m); y++)
|
|
|
|
for (x = 0; x < (16 >> m); x++) {
|
|
|
|
if ((y < (8 >> m)) ^ (x < (8 >> m)))
|
|
|
|
*dest++ = 0;
|
|
|
|
else
|
|
|
|
*dest++ = 0xff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_Init (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
|
|
|
|
// get stack position so we can guess if we are going to overflow
|
|
|
|
r_stack_start = (byte *) & dummy;
|
|
|
|
|
2012-04-10 04:27:53 +00:00
|
|
|
R_Init_Cvars ();
|
|
|
|
sw32_R_Particles_Init_Cvars ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_Draw_Init ();
|
2012-02-01 12:52:47 +00:00
|
|
|
SCR_Init ();
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_InitTurb ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
Cmd_AddCommand ("timerefresh", sw32_R_TimeRefresh_f, "Tests the current "
|
2001-08-25 02:47:11 +00:00
|
|
|
"refresh rate for the current location");
|
2012-02-22 07:32:34 +00:00
|
|
|
Cmd_AddCommand ("pointfile", sw32_R_ReadPointFile_f, "Load a pointfile to "
|
2001-08-25 02:47:11 +00:00
|
|
|
"determine map leaks");
|
2012-02-22 07:32:34 +00:00
|
|
|
Cmd_AddCommand ("loadsky", sw32_R_LoadSky_f, "Load a skybox");
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
Cvar_SetValue (r_maxedges, (float) NUMSTACKEDGES);
|
|
|
|
Cvar_SetValue (r_maxsurfs, (float) NUMSTACKSURFACES);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_view_clipplanes[0].leftedge = true;
|
|
|
|
sw32_view_clipplanes[1].rightedge = true;
|
|
|
|
sw32_view_clipplanes[1].leftedge = sw32_view_clipplanes[2].leftedge =
|
|
|
|
sw32_view_clipplanes[3].leftedge = false;
|
|
|
|
sw32_view_clipplanes[0].rightedge = sw32_view_clipplanes[2].rightedge =
|
|
|
|
sw32_view_clipplanes[3].rightedge = false;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
r_refdef.xOrigin = XCENTERING;
|
|
|
|
r_refdef.yOrigin = YCENTERING;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_Init ();
|
2012-04-10 04:27:53 +00:00
|
|
|
|
|
|
|
Skin_Init ();
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_NewMap (model_t *worldmodel, struct model_s **models, int num_models)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
2021-02-01 10:31:11 +00:00
|
|
|
mod_brush_t *brush = &worldmodel->brush;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
memset (&r_worldentity, 0, sizeof (r_worldentity));
|
2021-03-09 14:52:40 +00:00
|
|
|
r_worldentity.renderer.model = worldmodel;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2010-12-03 09:21:07 +00:00
|
|
|
R_FreeAllEntities ();
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// clear out efrags in case the level hasn't been reloaded
|
2021-07-27 03:32:40 +00:00
|
|
|
for (unsigned i = 0; i < brush->modleafs; i++)
|
2021-02-01 10:31:11 +00:00
|
|
|
brush->leafs[i].efrags = NULL;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-02-01 10:31:11 +00:00
|
|
|
if (brush->skytexture)
|
|
|
|
sw32_R_InitSky (brush->skytexture);
|
2004-11-06 02:21:00 +00:00
|
|
|
|
2012-01-29 07:09:35 +00:00
|
|
|
// Force a vis update
|
2001-08-25 02:47:11 +00:00
|
|
|
r_viewleaf = NULL;
|
2012-01-29 07:09:35 +00:00
|
|
|
R_MarkLeaves ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ClearParticles ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
r_cnumsurfs = r_maxsurfs->int_val;
|
|
|
|
|
|
|
|
if (r_cnumsurfs <= MINSURFACES)
|
|
|
|
r_cnumsurfs = MINSURFACES;
|
|
|
|
|
|
|
|
if (r_cnumsurfs > NUMSTACKSURFACES) {
|
2021-07-28 06:01:45 +00:00
|
|
|
sw32_surfaces = Hunk_AllocName (0, r_cnumsurfs * sizeof (surf_t),
|
|
|
|
"surfaces");
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_surface_p = sw32_surfaces;
|
|
|
|
sw32_surf_max = &sw32_surfaces[r_cnumsurfs];
|
2001-08-25 02:47:11 +00:00
|
|
|
r_surfsonstack = false;
|
|
|
|
// surface 0 doesn't really exist; it's just a dummy because index 0
|
|
|
|
// is used to indicate no edge attached to surface
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_surfaces--;
|
2001-08-25 02:47:11 +00:00
|
|
|
} else {
|
|
|
|
r_surfsonstack = true;
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_maxedgesseen = 0;
|
|
|
|
sw32_r_maxsurfsseen = 0;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_numallocatededges = r_maxedges->int_val;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_r_numallocatededges < MINEDGES)
|
|
|
|
sw32_r_numallocatededges = MINEDGES;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_r_numallocatededges <= NUMSTACKEDGES) {
|
|
|
|
sw32_auxedges = NULL;
|
2001-08-25 02:47:11 +00:00
|
|
|
} else {
|
2021-07-28 06:01:45 +00:00
|
|
|
sw32_auxedges = Hunk_AllocName (0,
|
|
|
|
sw32_r_numallocatededges * sizeof (edge_t),
|
|
|
|
"edges");
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_dowarpold = false;
|
|
|
|
sw32_r_viewchanged = false;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_ViewChanged
|
|
|
|
|
|
|
|
Called every time the vid structure or r_refdef changes.
|
|
|
|
Guaranteed to be called before the first refresh
|
|
|
|
*/
|
|
|
|
void
|
2021-04-01 10:17:19 +00:00
|
|
|
sw32_R_ViewChanged (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float res_scale;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_viewchanged = true;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
r_refdef.horizontalFieldOfView = 2.0 * tan (r_refdef.fov_x / 360 * M_PI);
|
|
|
|
r_refdef.fvrectx = (float) r_refdef.vrect.x;
|
|
|
|
r_refdef.fvrectx_adj = (float) r_refdef.vrect.x - 0.5;
|
|
|
|
r_refdef.vrect_x_adj_shift20 = (r_refdef.vrect.x << 20) + (1 << 19) - 1;
|
|
|
|
r_refdef.fvrecty = (float) r_refdef.vrect.y;
|
|
|
|
r_refdef.fvrecty_adj = (float) r_refdef.vrect.y - 0.5;
|
|
|
|
r_refdef.vrectright = r_refdef.vrect.x + r_refdef.vrect.width;
|
|
|
|
r_refdef.vrectright_adj_shift20 =
|
|
|
|
(r_refdef.vrectright << 20) + (1 << 19) - 1;
|
|
|
|
r_refdef.fvrectright = (float) r_refdef.vrectright;
|
|
|
|
r_refdef.fvrectright_adj = (float) r_refdef.vrectright - 0.5;
|
|
|
|
r_refdef.vrectrightedge = (float) r_refdef.vrectright - 0.99;
|
|
|
|
r_refdef.vrectbottom = r_refdef.vrect.y + r_refdef.vrect.height;
|
|
|
|
r_refdef.fvrectbottom = (float) r_refdef.vrectbottom;
|
|
|
|
r_refdef.fvrectbottom_adj = (float) r_refdef.vrectbottom - 0.5;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
r_refdef.aliasvrect.x = (int) (r_refdef.vrect.x * sw32_r_aliasuvscale);
|
|
|
|
r_refdef.aliasvrect.y = (int) (r_refdef.vrect.y * sw32_r_aliasuvscale);
|
|
|
|
r_refdef.aliasvrect.width = (int) (r_refdef.vrect.width * sw32_r_aliasuvscale);
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.aliasvrect.height = (int) (r_refdef.vrect.height *
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_aliasuvscale);
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.aliasvrectright = r_refdef.aliasvrect.x +
|
|
|
|
r_refdef.aliasvrect.width;
|
|
|
|
r_refdef.aliasvrectbottom = r_refdef.aliasvrect.y +
|
|
|
|
r_refdef.aliasvrect.height;
|
|
|
|
|
2021-04-01 10:17:19 +00:00
|
|
|
sw32_pixelAspect = 1;//FIXME vid.aspect;
|
2001-08-25 02:47:11 +00:00
|
|
|
xOrigin = r_refdef.xOrigin;
|
|
|
|
yOrigin = r_refdef.yOrigin;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
screenAspect = r_refdef.vrect.width * sw32_pixelAspect / r_refdef.vrect.height;
|
|
|
|
// 320*200 1.0 sw32_pixelAspect = 1.6 screenAspect
|
|
|
|
// 320*240 1.0 sw32_pixelAspect = 1.3333 screenAspect
|
|
|
|
// proper 320*200 sw32_pixelAspect = 0.8333333
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
verticalFieldOfView = r_refdef.horizontalFieldOfView / screenAspect;
|
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// values for perspective projection
|
|
|
|
// if math were exact, the values would range from 0.5 to to range+0.5
|
|
|
|
// hopefully they wll be in the 0.000001 to range+.999999 and truncate
|
|
|
|
// the polygon rasterization will never render in the first row or column
|
|
|
|
// but will definately render in the [range] row and column, so adjust the
|
|
|
|
// buffer origin to get an exact edge to edge fill
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_xcenter = ((float) r_refdef.vrect.width * XCENTERING) +
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.vrect.x - 0.5;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_aliasxcenter = sw32_xcenter * sw32_r_aliasuvscale;
|
|
|
|
sw32_ycenter = ((float) r_refdef.vrect.height * YCENTERING) +
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.vrect.y - 0.5;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_aliasycenter = sw32_ycenter * sw32_r_aliasuvscale;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_xscale = r_refdef.vrect.width / r_refdef.horizontalFieldOfView;
|
|
|
|
sw32_aliasxscale = sw32_xscale * sw32_r_aliasuvscale;
|
|
|
|
sw32_xscaleinv = 1.0 / sw32_xscale;
|
|
|
|
sw32_yscale = sw32_xscale * sw32_pixelAspect;
|
|
|
|
sw32_aliasyscale = sw32_yscale * sw32_r_aliasuvscale;
|
|
|
|
sw32_yscaleinv = 1.0 / sw32_yscale;
|
|
|
|
sw32_xscaleshrink = (r_refdef.vrect.width - 6) / r_refdef.horizontalFieldOfView;
|
|
|
|
sw32_yscaleshrink = sw32_xscaleshrink * sw32_pixelAspect;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// left side clip
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[0].normal[0] = -1.0 / (xOrigin *
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.horizontalFieldOfView);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[0].normal[1] = 0;
|
|
|
|
sw32_screenedge[0].normal[2] = 1;
|
|
|
|
sw32_screenedge[0].type = PLANE_ANYZ;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// right side clip
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[1].normal[0] = 1.0 / ((1.0 - xOrigin) *
|
2001-08-25 02:47:11 +00:00
|
|
|
r_refdef.horizontalFieldOfView);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[1].normal[1] = 0;
|
|
|
|
sw32_screenedge[1].normal[2] = 1;
|
|
|
|
sw32_screenedge[1].type = PLANE_ANYZ;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// top side clip
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[2].normal[0] = 0;
|
|
|
|
sw32_screenedge[2].normal[1] = -1.0 / (yOrigin * verticalFieldOfView);
|
|
|
|
sw32_screenedge[2].normal[2] = 1;
|
|
|
|
sw32_screenedge[2].type = PLANE_ANYZ;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// bottom side clip
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_screenedge[3].normal[0] = 0;
|
|
|
|
sw32_screenedge[3].normal[1] = 1.0 / ((1.0 - yOrigin) * verticalFieldOfView);
|
|
|
|
sw32_screenedge[3].normal[2] = 1;
|
|
|
|
sw32_screenedge[3].type = PLANE_ANYZ;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
2012-02-22 07:32:34 +00:00
|
|
|
VectorNormalize (sw32_screenedge[i].normal);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
res_scale = sqrt ((double) (r_refdef.vrect.width * r_refdef.vrect.height) /
|
|
|
|
(320.0 * 152.0)) * (2.0 /
|
|
|
|
r_refdef.horizontalFieldOfView);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_aliastransition = r_aliastransbase->value * res_scale;
|
|
|
|
sw32_r_resfudge = r_aliastransadj->value * res_scale;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_ViewChanged ();
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_DrawEntitiesOnList (void)
|
|
|
|
{
|
2010-12-03 05:54:39 +00:00
|
|
|
int j;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int lnum;
|
2001-08-25 02:47:11 +00:00
|
|
|
alight_t lighting;
|
2010-12-03 05:54:39 +00:00
|
|
|
entity_t *ent;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// FIXME: remove and do real lighting
|
|
|
|
float lightvec[3] = { -1, 0, 0 };
|
|
|
|
vec3_t dist;
|
|
|
|
float add;
|
2004-07-11 00:37:48 +00:00
|
|
|
float minlight;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2003-04-21 18:26:21 +00:00
|
|
|
if (!r_drawentities->int_val)
|
2001-08-25 02:47:11 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-03 05:54:39 +00:00
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) {
|
|
|
|
currententity = ent;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (Transform_GetWorldPosition (currententity->transform),
|
|
|
|
r_entorigin);
|
2021-03-09 14:52:40 +00:00
|
|
|
switch (currententity->renderer.model->type) {
|
2001-08-25 02:47:11 +00:00
|
|
|
case mod_sprite:
|
|
|
|
VectorSubtract (r_origin, r_entorigin, modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_DrawSprite ();
|
2001-08-25 02:47:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case mod_alias:
|
2012-05-20 05:23:41 +00:00
|
|
|
case mod_iqm:
|
2001-08-25 02:47:11 +00:00
|
|
|
VectorSubtract (r_origin, r_entorigin, modelorg);
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
minlight = max (currententity->renderer.min_light,
|
|
|
|
currententity->renderer.model->min_light);
|
2004-07-11 00:37:48 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
// see if the bounding box lets us trivially reject, also
|
|
|
|
// sets trivial accept status
|
2021-03-09 14:52:40 +00:00
|
|
|
currententity->visibility.trivial_accept = 0; //FIXME
|
|
|
|
if (currententity->renderer.model->type == mod_iqm//FIXME
|
2012-05-20 05:23:41 +00:00
|
|
|
|| sw32_R_AliasCheckBBox ()) {
|
2004-07-11 00:37:48 +00:00
|
|
|
// 128 instead of 255 due to clamping below
|
2021-03-09 14:52:40 +00:00
|
|
|
j = max (R_LightPoint (&r_worldentity.renderer.model->brush,
|
2021-03-19 11:18:45 +00:00
|
|
|
r_entorigin),
|
2021-02-01 10:31:11 +00:00
|
|
|
minlight * 128);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
lighting.ambientlight = j;
|
|
|
|
lighting.shadelight = j;
|
|
|
|
|
|
|
|
lighting.plightvec = lightvec;
|
|
|
|
|
2001-10-09 20:35:17 +00:00
|
|
|
for (lnum = 0; lnum < r_maxdlights; lnum++) {
|
2012-02-14 08:28:09 +00:00
|
|
|
if (r_dlights[lnum].die >= vr_data.realtime) {
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_entorigin,
|
2001-08-25 02:47:11 +00:00
|
|
|
r_dlights[lnum].origin, dist);
|
2002-08-20 02:22:40 +00:00
|
|
|
add = r_dlights[lnum].radius - VectorLength (dist);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (add > 0)
|
|
|
|
lighting.ambientlight += add;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clamp lighting so it doesn't overbright as much
|
|
|
|
if (lighting.ambientlight > 128)
|
|
|
|
lighting.ambientlight = 128;
|
|
|
|
if (lighting.ambientlight + lighting.shadelight > 192)
|
|
|
|
lighting.shadelight = 192 - lighting.ambientlight;
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
if (currententity->renderer.model->type == mod_iqm)
|
2012-05-20 05:23:41 +00:00
|
|
|
sw32_R_IQMDrawModel (&lighting);
|
|
|
|
else
|
|
|
|
sw32_R_AliasDrawModel (&lighting);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_DrawViewModel (void)
|
|
|
|
{
|
|
|
|
// FIXME: remove and do real lighting
|
|
|
|
float lightvec[3] = { -1, 0, 0 };
|
|
|
|
int j;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int lnum;
|
2001-08-25 02:47:11 +00:00
|
|
|
vec3_t dist;
|
|
|
|
float add;
|
2004-07-11 00:37:48 +00:00
|
|
|
float minlight;
|
2001-08-25 02:47:11 +00:00
|
|
|
dlight_t *dl;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
if (vr_data.inhibit_viewmodel || !r_drawviewmodel->int_val
|
2001-08-25 02:47:11 +00:00
|
|
|
|| !r_drawentities->int_val)
|
|
|
|
return;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
currententity = vr_data.view_model;
|
2021-03-09 14:52:40 +00:00
|
|
|
if (!currententity->renderer.model)
|
2001-08-25 02:47:11 +00:00
|
|
|
return;
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (Transform_GetWorldPosition (currententity->transform),
|
|
|
|
r_entorigin);
|
2001-08-25 02:47:11 +00:00
|
|
|
VectorSubtract (r_origin, r_entorigin, modelorg);
|
|
|
|
|
|
|
|
VectorCopy (vup, viewlightvec);
|
2007-03-10 12:00:59 +00:00
|
|
|
VectorNegate (viewlightvec, viewlightvec);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
minlight = max (currententity->renderer.min_light,
|
|
|
|
currententity->renderer.model->min_light);
|
2004-07-11 00:37:48 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
j = max (R_LightPoint (&r_worldentity.renderer.model->brush,
|
2021-03-19 11:18:45 +00:00
|
|
|
r_entorigin), minlight * 128);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
r_viewlighting.ambientlight = j;
|
|
|
|
r_viewlighting.shadelight = j;
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// add dynamic lights
|
2001-10-09 20:35:17 +00:00
|
|
|
for (lnum = 0; lnum < r_maxdlights; lnum++) {
|
2001-08-25 02:47:11 +00:00
|
|
|
dl = &r_dlights[lnum];
|
|
|
|
if (!dl->radius)
|
|
|
|
continue;
|
|
|
|
if (!dl->radius)
|
|
|
|
continue;
|
2012-02-14 08:28:09 +00:00
|
|
|
if (dl->die < vr_data.realtime)
|
2001-08-25 02:47:11 +00:00
|
|
|
continue;
|
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_entorigin, dl->origin, dist);
|
2002-08-20 02:22:40 +00:00
|
|
|
add = dl->radius - VectorLength (dist);
|
2001-08-25 02:47:11 +00:00
|
|
|
if (add > 0)
|
|
|
|
r_viewlighting.ambientlight += add;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clamp lighting so it doesn't overbright as much
|
|
|
|
if (r_viewlighting.ambientlight > 128)
|
|
|
|
r_viewlighting.ambientlight = 128;
|
|
|
|
if (r_viewlighting.ambientlight + r_viewlighting.shadelight > 192)
|
|
|
|
r_viewlighting.shadelight = 192 - r_viewlighting.ambientlight;
|
|
|
|
|
|
|
|
r_viewlighting.plightvec = lightvec;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_AliasDrawModel (&r_viewlighting);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static int
|
2001-08-25 02:47:11 +00:00
|
|
|
R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
|
|
|
|
{
|
|
|
|
int i, *pindex, clipflags;
|
|
|
|
vec3_t acceptpt, rejectpt;
|
|
|
|
double d;
|
2021-03-09 14:52:40 +00:00
|
|
|
mat4f_t mat;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
clipflags = 0;
|
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
Transform_GetWorldMatrix (currententity->transform, mat);
|
|
|
|
if (mat[0][0] != 1 || mat[1][1] != 1 || mat[2][2] != 1) {
|
2001-08-25 02:47:11 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2021-03-19 11:18:45 +00:00
|
|
|
d = DotProduct (mat[3], sw32_view_clipplanes[i].normal);
|
2012-02-22 07:32:34 +00:00
|
|
|
d -= sw32_view_clipplanes[i].dist;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (d <= -clmodel->radius)
|
|
|
|
return BMODEL_FULLY_CLIPPED;
|
|
|
|
|
|
|
|
if (d <= clmodel->radius)
|
|
|
|
clipflags |= (1 << i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
// generate accept and reject points
|
|
|
|
// FIXME: do with fast look-ups or integer tests based on the
|
|
|
|
// sign bit of the floating point values
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
pindex = sw32_pfrustum_indexes[i];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
rejectpt[0] = minmaxs[pindex[0]];
|
|
|
|
rejectpt[1] = minmaxs[pindex[1]];
|
|
|
|
rejectpt[2] = minmaxs[pindex[2]];
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
d = DotProduct (rejectpt, sw32_view_clipplanes[i].normal);
|
|
|
|
d -= sw32_view_clipplanes[i].dist;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (d <= 0)
|
|
|
|
return BMODEL_FULLY_CLIPPED;
|
|
|
|
|
|
|
|
acceptpt[0] = minmaxs[pindex[3 + 0]];
|
|
|
|
acceptpt[1] = minmaxs[pindex[3 + 1]];
|
|
|
|
acceptpt[2] = minmaxs[pindex[3 + 2]];
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
d = DotProduct (acceptpt, sw32_view_clipplanes[i].normal);
|
|
|
|
d -= sw32_view_clipplanes[i].dist;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (d <= 0)
|
|
|
|
clipflags |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clipflags;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_DrawBEntitiesOnList (void)
|
|
|
|
{
|
2010-12-03 05:54:39 +00:00
|
|
|
int j, clipflags;
|
2003-04-17 00:01:48 +00:00
|
|
|
unsigned int k;
|
2001-08-25 02:47:11 +00:00
|
|
|
vec3_t oldorigin;
|
2021-03-19 11:18:45 +00:00
|
|
|
vec3_t origin;
|
2001-08-25 02:47:11 +00:00
|
|
|
model_t *clmodel;
|
|
|
|
float minmaxs[6];
|
2010-12-03 05:54:39 +00:00
|
|
|
entity_t *ent;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (!r_drawentities->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
VectorCopy (modelorg, oldorigin);
|
|
|
|
insubmodel = true;
|
|
|
|
|
2010-12-03 05:54:39 +00:00
|
|
|
for (ent = r_ent_queue; ent; ent = ent->next) {
|
|
|
|
currententity = ent;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (Transform_GetWorldPosition (currententity->transform),
|
|
|
|
origin);
|
2021-03-09 14:52:40 +00:00
|
|
|
switch (currententity->renderer.model->type) {
|
2001-08-28 20:51:51 +00:00
|
|
|
case mod_brush:
|
2021-03-09 14:52:40 +00:00
|
|
|
clmodel = currententity->renderer.model;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// see if the bounding box lets us trivially reject, also
|
|
|
|
// sets trivial accept status
|
|
|
|
for (j = 0; j < 3; j++) {
|
2021-03-19 11:18:45 +00:00
|
|
|
minmaxs[j] = origin[j] + clmodel->mins[j];
|
|
|
|
minmaxs[3 + j] = origin[j] + clmodel->maxs[j];
|
2001-08-28 20:51:51 +00:00
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
clipflags = R_BmodelCheckBBox (clmodel, minmaxs);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
if (clipflags != BMODEL_FULLY_CLIPPED) {
|
2021-02-01 10:31:11 +00:00
|
|
|
mod_brush_t *brush = &clmodel->brush;
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorCopy (origin, r_entorigin);
|
2001-08-28 20:51:51 +00:00
|
|
|
VectorSubtract (r_origin, r_entorigin, modelorg);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: is this needed?
|
2012-02-22 07:32:34 +00:00
|
|
|
VectorCopy (modelorg, sw32_r_worldmodelorg);
|
2021-02-01 10:31:11 +00:00
|
|
|
r_pcurrentvertbase = brush->vertexes;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: stop transforming twice
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RotateBmodel ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// calculate dynamic lighting for bmodel if it's not an
|
|
|
|
// instanced model
|
2021-02-01 10:31:11 +00:00
|
|
|
if (brush->firstmodelsurface != 0) {
|
2001-08-28 20:51:51 +00:00
|
|
|
vec3_t lightorigin;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-10-09 20:35:17 +00:00
|
|
|
for (k = 0; k < r_maxdlights; k++) {
|
2012-02-14 08:28:09 +00:00
|
|
|
if ((r_dlights[k].die < vr_data.realtime) ||
|
2001-08-28 20:51:51 +00:00
|
|
|
(!r_dlights[k].radius)) continue;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_dlights[k].origin, origin,
|
2001-08-28 20:51:51 +00:00
|
|
|
lightorigin);
|
2021-02-01 10:31:11 +00:00
|
|
|
R_RecursiveMarkLights (brush, lightorigin,
|
|
|
|
&r_dlights[k], k,
|
|
|
|
brush->nodes
|
|
|
|
+ brush->hulls[0].firstclipnode);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
2001-08-28 20:51:51 +00:00
|
|
|
}
|
|
|
|
// if the driver wants polygons, deliver those.
|
|
|
|
// Z-buffering is on at this point, so no clipping to the
|
|
|
|
// world tree is needed, just frustum clipping
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_r_drawpolys | sw32_r_drawculledpolys) {
|
|
|
|
sw32_R_ZDrawSubmodelPolys (clmodel);
|
2001-08-28 20:51:51 +00:00
|
|
|
} else {
|
2021-03-09 14:52:40 +00:00
|
|
|
if (currententity->visibility.topnode) {
|
|
|
|
mnode_t *topnode
|
|
|
|
= currententity->visibility.topnode;
|
2001-08-28 20:51:51 +00:00
|
|
|
|
2010-12-01 23:31:48 +00:00
|
|
|
if (topnode->contents >= 0) {
|
2012-05-21 23:23:22 +00:00
|
|
|
// not a leaf; has to be clipped to the world
|
2001-08-28 20:51:51 +00:00
|
|
|
// BSP
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_clipflags = clipflags;
|
|
|
|
sw32_R_DrawSolidClippedSubmodelPolygons (clmodel);
|
2001-08-28 20:51:51 +00:00
|
|
|
} else {
|
2012-05-21 23:23:22 +00:00
|
|
|
// falls entirely in one leaf, so we just put
|
2001-08-28 20:51:51 +00:00
|
|
|
// all the edges in the edge list and let 1/z
|
|
|
|
// sorting handle drawing order
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_DrawSubmodelPolygons (clmodel, clipflags);
|
2001-08-28 20:51:51 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// put back world rotation and frustum clipping
|
2012-02-22 07:32:34 +00:00
|
|
|
// FIXME: sw32_R_RotateBmodel should just work off base_vxx
|
2001-08-28 20:51:51 +00:00
|
|
|
VectorCopy (base_vpn, vpn);
|
|
|
|
VectorCopy (base_vup, vup);
|
|
|
|
VectorCopy (base_vright, vright);
|
|
|
|
VectorCopy (base_modelorg, modelorg);
|
|
|
|
VectorCopy (oldorigin, modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformFrustum ();
|
2001-08-28 20:51:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
insubmodel = false;
|
|
|
|
}
|
|
|
|
|
2012-02-21 05:10:20 +00:00
|
|
|
static void
|
|
|
|
R_PrintDSpeeds (void)
|
|
|
|
{
|
|
|
|
float ms, dp_time, r_time2, rw_time, db_time, se_time, de_time,
|
|
|
|
|
|
|
|
dv_time;
|
|
|
|
|
|
|
|
r_time2 = Sys_DoubleTime ();
|
|
|
|
|
|
|
|
dp_time = (dp_time2 - dp_time1) * 1000;
|
|
|
|
rw_time = (rw_time2 - rw_time1) * 1000;
|
|
|
|
db_time = (db_time2 - db_time1) * 1000;
|
|
|
|
se_time = (se_time2 - se_time1) * 1000;
|
|
|
|
de_time = (de_time2 - de_time1) * 1000;
|
|
|
|
dv_time = (dv_time2 - dv_time1) * 1000;
|
|
|
|
ms = (r_time2 - r_time1) * 1000;
|
|
|
|
|
|
|
|
Sys_Printf ("%3i %4.1fp %3iw %4.1fb %3is %4.1fe %4.1fv\n",
|
|
|
|
(int) ms, dp_time, (int) rw_time, db_time, (int) se_time,
|
|
|
|
de_time, dv_time);
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_EdgeDrawing (void)
|
|
|
|
{
|
|
|
|
edge_t ledges[NUMSTACKEDGES +
|
|
|
|
((CACHE_SIZE - 1) / sizeof (edge_t)) + 1];
|
|
|
|
surf_t lsurfs[NUMSTACKSURFACES +
|
|
|
|
((CACHE_SIZE - 1) / sizeof (surf_t)) + 1];
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_auxedges) {
|
|
|
|
sw32_r_edges = sw32_auxedges;
|
2001-08-25 02:47:11 +00:00
|
|
|
} else {
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_edges = (edge_t *)
|
2007-04-11 22:03:36 +00:00
|
|
|
(((intptr_t) &ledges[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r_surfsonstack) {
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_surfaces = (surf_t *)
|
2007-04-11 22:03:36 +00:00
|
|
|
(((intptr_t) &lsurfs[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_surf_max = &sw32_surfaces[r_cnumsurfs];
|
2001-08-25 02:47:11 +00:00
|
|
|
// surface 0 doesn't really exist; it's just a dummy because index 0
|
|
|
|
// is used to indicate no edge attached to surface
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_surfaces--;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_BeginEdgeFrame ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
rw_time1 = Sys_DoubleTime ();
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RenderWorld ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_r_drawculledpolys)
|
|
|
|
sw32_R_ScanEdges ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// only the world can be drawn back to front with no z reads or compares,
|
|
|
|
// just z writes, so have the driver turn z compares on now
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_TurnZOn ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
rw_time2 = Sys_DoubleTime ();
|
|
|
|
db_time1 = rw_time2;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_DrawBEntitiesOnList ();
|
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
db_time2 = Sys_DoubleTime ();
|
|
|
|
se_time1 = db_time2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!r_dspeeds->int_val) {
|
|
|
|
VID_UnlockBuffer ();
|
2001-08-28 20:51:51 +00:00
|
|
|
S_ExtraUpdate (); // don't let sound get messed up if going slow
|
2001-08-25 02:47:11 +00:00
|
|
|
VID_LockBuffer ();
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (!(sw32_r_drawpolys | sw32_r_drawculledpolys))
|
|
|
|
sw32_R_ScanEdges ();
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LordHavoc: took out of stack and made 4x size for 32bit capacity
|
2012-02-18 05:34:14 +00:00
|
|
|
static byte warpbuffer[WARP_WIDTH * WARP_HEIGHT * 4];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
R_RenderView
|
|
|
|
|
|
|
|
r_refdef must be set before the first call
|
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_RenderView_ (void)
|
|
|
|
{
|
2004-04-16 03:24:10 +00:00
|
|
|
if (r_norefresh->int_val)
|
|
|
|
return;
|
2021-12-02 09:30:57 +00:00
|
|
|
if (!r_worldentity.renderer.model) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-16 03:24:10 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_warpbuffer = warpbuffer;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
|
|
|
|
r_time1 = Sys_DoubleTime ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_SetupFrame ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
#ifdef PASSAGES
|
|
|
|
SetVisibilityByPassages ();
|
|
|
|
#else
|
2001-08-28 20:51:51 +00:00
|
|
|
R_MarkLeaves (); // done here so we know if we're in water
|
2001-08-25 02:47:11 +00:00
|
|
|
#endif
|
2001-08-28 20:51:51 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2021-03-09 14:52:40 +00:00
|
|
|
if (!r_worldentity.renderer.model)
|
2001-08-25 02:47:11 +00:00
|
|
|
Sys_Error ("R_RenderView: NULL worldmodel");
|
|
|
|
|
|
|
|
if (!r_dspeeds->int_val) {
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
S_ExtraUpdate (); // don't let sound get messed up if going slow
|
|
|
|
VID_LockBuffer ();
|
|
|
|
}
|
|
|
|
|
|
|
|
R_EdgeDrawing ();
|
|
|
|
|
|
|
|
if (!r_dspeeds->int_val) {
|
|
|
|
VID_UnlockBuffer ();
|
2001-08-25 03:24:44 +00:00
|
|
|
S_ExtraUpdate (); // don't let sound get messed up if going slow
|
2001-08-25 02:47:11 +00:00
|
|
|
VID_LockBuffer ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
se_time2 = Sys_DoubleTime ();
|
|
|
|
de_time1 = se_time2;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_DrawEntitiesOnList ();
|
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
de_time2 = Sys_DoubleTime ();
|
|
|
|
dv_time1 = de_time2;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_DrawViewModel ();
|
|
|
|
|
|
|
|
if (r_dspeeds->int_val) {
|
|
|
|
dv_time2 = Sys_DoubleTime ();
|
|
|
|
dp_time1 = Sys_DoubleTime ();
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_DrawParticles ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_dspeeds->int_val)
|
|
|
|
dp_time2 = Sys_DoubleTime ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_r_dowarp)
|
|
|
|
sw32_D_WarpScreen ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_timegraph->int_val)
|
|
|
|
R_TimeGraph ();
|
|
|
|
|
|
|
|
if (r_zgraph->int_val)
|
|
|
|
R_ZGraph ();
|
|
|
|
|
|
|
|
if (r_aliasstats->int_val)
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_PrintAliasStats ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_speeds->int_val)
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_PrintTimes ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (r_dspeeds->int_val)
|
|
|
|
R_PrintDSpeeds ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (r_reportsurfout->int_val && sw32_r_outofsurfaces)
|
|
|
|
Sys_Printf ("Short %d surfaces\n", sw32_r_outofsurfaces);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (r_reportedgeout->int_val && sw32_r_outofedges)
|
|
|
|
Sys_Printf ("Short roughly %d edges\n", sw32_r_outofedges * 2 / 3);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 13:28:42 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RenderView (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int dummy;
|
|
|
|
int delta;
|
|
|
|
|
|
|
|
delta = (byte *) & dummy - r_stack_start;
|
|
|
|
if (delta < -10000 || delta > 10000)
|
|
|
|
Sys_Error ("R_RenderView: called without enough stack");
|
|
|
|
|
2021-07-28 06:01:45 +00:00
|
|
|
if (Hunk_LowMark (0) & 3)
|
2001-08-25 02:47:11 +00:00
|
|
|
Sys_Error ("Hunk is missaligned");
|
|
|
|
|
2007-04-11 22:03:36 +00:00
|
|
|
if ((intptr_t) (&dummy) & 3)
|
2001-08-25 02:47:11 +00:00
|
|
|
Sys_Error ("Stack is missaligned");
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if ((intptr_t) (&sw32_r_warpbuffer) & 3)
|
2001-08-25 02:47:11 +00:00
|
|
|
Sys_Error ("Globals are missaligned");
|
|
|
|
|
|
|
|
R_RenderView_ ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_InitTurb (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2009-12-20 05:34:41 +00:00
|
|
|
for (i = 0; i < MAXWIDTH; i++) {
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_sintable[i] = AMP + sin (i * 3.14159 * 2 / CYCLE) * AMP;
|
|
|
|
sw32_intsintable[i] = AMP2 + sin (i * 3.14159 * 2 / CYCLE) * AMP2;
|
2001-08-25 02:47:11 +00:00
|
|
|
// AMP2 not 20
|
|
|
|
}
|
|
|
|
}
|
2004-02-15 00:02:04 +00:00
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ClearState (void)
|
2011-12-23 03:51:47 +00:00
|
|
|
{
|
2021-12-02 09:30:57 +00:00
|
|
|
r_worldentity.renderer.model = 0;
|
2011-12-23 03:51:47 +00:00
|
|
|
R_ClearEfrags ();
|
|
|
|
R_ClearDlights ();
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ClearParticles ();
|
2011-12-23 03:51:47 +00:00
|
|
|
}
|