2001-08-25 02:47:11 +00:00
|
|
|
/*
|
|
|
|
sw32_rmisc.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
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
static __attribute__ ((used)) const char rcsid[] = "$Id$";
|
|
|
|
|
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/draw.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "compat.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
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
R_CheckVariables (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
R_TimeRefresh_f
|
|
|
|
|
|
|
|
For program optimization
|
|
|
|
*/
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TimeRefresh_f (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
float start, stop, time;
|
|
|
|
int startangle;
|
2001-08-28 22:46:02 +00:00
|
|
|
vrect_t vr;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
startangle = r_refdef.viewangles[1];
|
|
|
|
|
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
r_refdef.viewangles[1] = i / 128.0 * 360.0;
|
|
|
|
|
|
|
|
VID_LockBuffer ();
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RenderView ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
VID_UnlockBuffer ();
|
|
|
|
|
|
|
|
vr.x = r_refdef.vrect.x;
|
|
|
|
vr.y = r_refdef.vrect.y;
|
|
|
|
vr.width = r_refdef.vrect.width;
|
|
|
|
vr.height = r_refdef.vrect.height;
|
2012-01-06 00:52:14 +00:00
|
|
|
vr.next = NULL;
|
2001-08-25 02:47:11 +00:00
|
|
|
VID_Update (&vr);
|
|
|
|
}
|
|
|
|
stop = Sys_DoubleTime ();
|
|
|
|
time = stop - start;
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%f seconds (%f fps)\n", time, 128 / time);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
r_refdef.viewangles[1] = startangle;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_LoadSky_f (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
if (Cmd_Argc () != 2) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("loadsky <name> : load a skybox\n");
|
2001-08-25 02:47:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_LoadSkys (Cmd_Argv (1));
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_PrintTimes (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
float r_time2;
|
|
|
|
float ms;
|
|
|
|
|
|
|
|
r_time2 = Sys_DoubleTime ();
|
|
|
|
|
|
|
|
ms = 1000 * (r_time2 - r_time1);
|
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%5.1f ms %3i/%3i/%3i poly %3i surf\n",
|
2012-02-22 07:32:34 +00:00
|
|
|
ms, sw32_c_faceclip, sw32_r_polycount, sw32_r_drawnpolycount, sw32_c_surf);
|
|
|
|
sw32_c_surf = 0;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_PrintAliasStats (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
2012-02-22 07:32:34 +00:00
|
|
|
Sys_Printf ("%3i polygon model drawn\n", sw32_r_amodels_drawn);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformFrustum (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
vec3_t v, v2;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
2012-02-22 07:32:34 +00:00
|
|
|
v[0] = sw32_screenedge[i].normal[2];
|
|
|
|
v[1] = -sw32_screenedge[i].normal[0];
|
|
|
|
v[2] = sw32_screenedge[i].normal[1];
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
v2[0] = v[1] * vright[0] + v[2] * vup[0] + v[0] * vpn[0];
|
|
|
|
v2[1] = v[1] * vright[1] + v[2] * vup[1] + v[0] * vpn[1];
|
|
|
|
v2[2] = v[1] * vright[2] + v[2] * vup[2] + v[0] * vpn[2];
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
VectorCopy (v2, sw32_view_clipplanes[i].normal);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_view_clipplanes[i].dist = DotProduct (modelorg, v2);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (const vec3_t in, vec3_t out)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
out[0] = DotProduct (in, vright);
|
|
|
|
out[1] = DotProduct (in, vup);
|
|
|
|
out[2] = DotProduct (in, vpn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformPlane (plane_t *p, float *normal, float *dist)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
float d;
|
|
|
|
|
|
|
|
d = DotProduct (r_origin, p->normal);
|
|
|
|
*dist = p->dist - d;
|
|
|
|
// TODO: when we have rotating entities, this will need to use the view matrix
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (p->normal, normal);
|
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_SetUpFrustumIndexes (void)
|
|
|
|
{
|
|
|
|
int i, j, *pindex;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
pindex = sw32_r_frustum_indexes;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
2012-02-22 07:32:34 +00:00
|
|
|
if (sw32_view_clipplanes[i].normal[j] < 0) {
|
2001-08-25 02:47:11 +00:00
|
|
|
pindex[j] = j;
|
|
|
|
pindex[j + 3] = j + 3;
|
|
|
|
} else {
|
|
|
|
pindex[j] = j + 3;
|
|
|
|
pindex[j + 3] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: do just once at start
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_pfrustum_indexes[i] = pindex;
|
2001-08-25 02:47:11 +00:00
|
|
|
pindex += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_SetupFrame (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int edgecount;
|
|
|
|
vrect_t vrect;
|
|
|
|
float w, h;
|
|
|
|
|
|
|
|
// don't allow cheats in multiplayer
|
|
|
|
Cvar_SetValue (r_ambient, 0);
|
|
|
|
Cvar_SetValue (r_drawflat, 0);
|
|
|
|
|
|
|
|
if (r_numsurfs->int_val) {
|
2012-02-22 07:32:34 +00:00
|
|
|
if ((sw32_surface_p - sw32_surfaces) > sw32_r_maxsurfsseen)
|
|
|
|
sw32_r_maxsurfsseen = sw32_surface_p - sw32_surfaces;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Used %ld of %ld surfs; %d max\n",
|
2012-02-22 07:32:34 +00:00
|
|
|
(long) (sw32_surface_p - sw32_surfaces),
|
|
|
|
(long) (sw32_surf_max - sw32_surfaces), sw32_r_maxsurfsseen);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r_numedges->int_val) {
|
2012-02-22 07:32:34 +00:00
|
|
|
edgecount = sw32_edge_p - sw32_r_edges;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (edgecount > sw32_r_maxedgesseen)
|
|
|
|
sw32_r_maxedgesseen = edgecount;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Used %d of %d edges; %d max\n", edgecount,
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_numallocatededges, sw32_r_maxedgesseen);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_refdef.ambientlight = max (r_ambient->value, 0);
|
|
|
|
|
|
|
|
R_CheckVariables ();
|
|
|
|
|
|
|
|
R_AnimateLight ();
|
2010-12-25 10:47:31 +00:00
|
|
|
R_ClearEnts ();
|
2001-08-25 02:47:11 +00:00
|
|
|
r_framecount++;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_numbtofpolys = 0;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// debugging
|
|
|
|
#if 0
|
|
|
|
r_refdef.vieworg[0] = 80;
|
|
|
|
r_refdef.vieworg[1] = 64;
|
|
|
|
r_refdef.vieworg[2] = 40;
|
|
|
|
r_refdef.viewangles[0] = 0;
|
|
|
|
r_refdef.viewangles[1] = 46.763641357;
|
|
|
|
r_refdef.viewangles[2] = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// build the transformation matrix for the given view angles
|
|
|
|
VectorCopy (r_refdef.vieworg, modelorg);
|
|
|
|
VectorCopy (r_refdef.vieworg, r_origin);
|
|
|
|
|
|
|
|
AngleVectors (r_refdef.viewangles, vpn, vright, vup);
|
|
|
|
|
|
|
|
// current viewleaf
|
|
|
|
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.model);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_dowarpold = sw32_r_dowarp;
|
|
|
|
sw32_r_dowarp = r_waterwarp->int_val && (r_viewleaf->contents <=
|
2001-08-25 02:47:11 +00:00
|
|
|
CONTENTS_WATER);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if ((sw32_r_dowarp != sw32_r_dowarpold) || sw32_r_viewchanged) {
|
|
|
|
if (sw32_r_dowarp) {
|
2003-04-17 00:01:48 +00:00
|
|
|
if ((vid.width <= (unsigned int) vid.maxwarpwidth) &&
|
|
|
|
(vid.height <= (unsigned int) vid.maxwarpheight)) {
|
2001-08-25 02:47:11 +00:00
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = vid.width;
|
|
|
|
vrect.height = vid.height;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
R_SetVrect (&vrect, &r_refdef.vrect, vr_data.lineadj);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ViewChanged (vid.aspect);
|
2001-08-25 02:47:11 +00:00
|
|
|
} else {
|
|
|
|
w = vid.width;
|
|
|
|
h = vid.height;
|
|
|
|
|
|
|
|
if (w > vid.maxwarpwidth) {
|
|
|
|
h *= (float) vid.maxwarpwidth / w;
|
|
|
|
w = vid.maxwarpwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h > vid.maxwarpheight) {
|
|
|
|
h = vid.maxwarpheight;
|
|
|
|
w *= (float) vid.maxwarpheight / h;
|
|
|
|
}
|
|
|
|
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = (int) w;
|
|
|
|
vrect.height = (int) h;
|
|
|
|
|
2004-02-08 00:37:11 +00:00
|
|
|
R_SetVrect (&vrect, &r_refdef.vrect,
|
2012-02-14 08:28:09 +00:00
|
|
|
(int) ((float) vr_data.lineadj *
|
2004-02-08 00:37:11 +00:00
|
|
|
(h / (float) vid.height)));
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ViewChanged (vid.aspect * (h / w) * ((float) vid.width /
|
2001-08-25 02:47:11 +00:00
|
|
|
(float) vid.height));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
vrect.x = 0;
|
|
|
|
vrect.y = 0;
|
|
|
|
vrect.width = vid.width;
|
|
|
|
vrect.height = vid.height;
|
|
|
|
|
2004-02-08 00:37:11 +00:00
|
|
|
r_refdef.vrect = scr_vrect;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_ViewChanged (vid.aspect);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_viewchanged = false;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
// start off with just the four screen edge clip planes
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformFrustum ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// save base values
|
|
|
|
VectorCopy (vpn, base_vpn);
|
|
|
|
VectorCopy (vright, base_vright);
|
|
|
|
VectorCopy (vup, base_vup);
|
|
|
|
VectorCopy (modelorg, base_modelorg);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_SetSkyFrame ();
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
R_SetUpFrustumIndexes ();
|
|
|
|
|
|
|
|
r_cache_thrash = false;
|
|
|
|
|
|
|
|
// clear frame counts
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_c_faceclip = 0;
|
|
|
|
sw32_r_polycount = 0;
|
|
|
|
sw32_r_drawnpolycount = 0;
|
|
|
|
sw32_r_amodels_drawn = 0;
|
|
|
|
sw32_r_outofsurfaces = 0;
|
|
|
|
sw32_r_outofedges = 0;
|
|
|
|
|
|
|
|
sw32_D_SetupFrame ();
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|