2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-08-25 02:47:11 +00:00
|
|
|
sw_rmisc.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
(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
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/cmd.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
#include "QF/draw.h"
|
2001-05-22 06:00:38 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
#include "QF/sys.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
2001-05-09 22:40:51 +00:00
|
|
|
|
2022-03-04 16:48:10 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#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"
|
2019-07-08 16:00:47 +00:00
|
|
|
#include "vid_sw.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
R_TimeRefresh_f
|
|
|
|
|
|
|
|
For program optimization
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
R_TimeRefresh_f (void)
|
|
|
|
{
|
2021-03-19 11:18:45 +00:00
|
|
|
/* FIXME update for simd
|
2001-02-19 21:15:25 +00:00
|
|
|
int i;
|
|
|
|
float start, stop, time;
|
|
|
|
int startangle;
|
|
|
|
vrect_t vr;
|
|
|
|
|
|
|
|
startangle = r_refdef.viewangles[1];
|
|
|
|
|
|
|
|
start = Sys_DoubleTime ();
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
r_refdef.viewangles[1] = i / 128.0 * 360.0;
|
|
|
|
|
|
|
|
R_RenderView ();
|
|
|
|
|
|
|
|
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;
|
2019-07-08 16:00:47 +00:00
|
|
|
sw_ctx->update (&vr);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
stop = Sys_DoubleTime ();
|
|
|
|
time = stop - start;
|
2013-02-18 04:57:45 +00:00
|
|
|
Sys_Printf ("%g seconds (%g fps)\n", time, 128 / time);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_refdef.viewangles[1] = startangle;
|
2021-03-19 11:18:45 +00:00
|
|
|
*/
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_LoadSky_f (void)
|
|
|
|
{
|
|
|
|
if (Cmd_Argc () != 2) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("loadsky <name> : load a skybox\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_LoadSkys (Cmd_Argv (1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_PrintTimes (void)
|
|
|
|
{
|
|
|
|
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",
|
2001-02-19 21:15:25 +00:00
|
|
|
ms, c_faceclip, r_polycount, r_drawnpolycount, c_surf);
|
|
|
|
c_surf = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_PrintAliasStats (void)
|
|
|
|
{
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("%3i polygon model drawn\n", r_amodels_drawn);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_TransformFrustum (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
vec3_t v, v2;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
v[0] = screenedge[i].normal[2];
|
|
|
|
v[1] = -screenedge[i].normal[0];
|
|
|
|
v[2] = screenedge[i].normal[1];
|
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
v2[0] = v[1] * vright[0] + v[2] * vup[0] + v[0] * vfwd[0];
|
|
|
|
v2[1] = v[1] * vright[1] + v[2] * vup[1] + v[0] * vfwd[1];
|
|
|
|
v2[2] = v[1] * vright[2] + v[2] * vup[2] + v[0] * vfwd[2];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (v2, view_clipplanes[i].normal);
|
|
|
|
|
|
|
|
view_clipplanes[i].dist = DotProduct (modelorg, v2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-11 20:59:48 +00:00
|
|
|
#ifdef PIC
|
2001-08-25 02:47:11 +00:00
|
|
|
# undef USE_INTEL_ASM //XXX asm pic hack
|
2001-06-11 20:59:48 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifndef USE_INTEL_ASM
|
|
|
|
void
|
2002-01-03 05:29:38 +00:00
|
|
|
TransformVector (const vec3_t in, vec3_t out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
out[0] = DotProduct (in, vright);
|
|
|
|
out[1] = DotProduct (in, vup);
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
out[2] = DotProduct (in, vfwd);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-19 21:15:25 +00:00
|
|
|
R_SetUpFrustumIndexes (void)
|
|
|
|
{
|
|
|
|
int i, j, *pindex;
|
|
|
|
|
|
|
|
pindex = r_frustum_indexes;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
for (j = 0; j < 3; j++) {
|
|
|
|
if (view_clipplanes[i].normal[j] < 0) {
|
|
|
|
pindex[j] = j;
|
|
|
|
pindex[j + 3] = j + 3;
|
|
|
|
} else {
|
|
|
|
pindex[j] = j + 3;
|
|
|
|
pindex[j + 3] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: do just once at start
|
2001-02-19 21:15:25 +00:00
|
|
|
pfrustum_indexes[i] = pindex;
|
|
|
|
pindex += 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
R_SetupFrame (void)
|
|
|
|
{
|
|
|
|
numbtofpolys = 0;
|
|
|
|
|
|
|
|
// build the transformation matrix for the given view angles
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorCopy (r_refdef.frame.position, modelorg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorCopy (r_refdef.frame.right, vright);
|
|
|
|
VectorCopy (r_refdef.frame.forward, vfwd);
|
|
|
|
VectorCopy (r_refdef.frame.up, vup);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// start off with just the four screen edge clip planes
|
2001-02-19 21:15:25 +00:00
|
|
|
R_TransformFrustum ();
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// save base values
|
[renderer] Clean up use of vup/vright/vpn
This moves the common camera setup code out of the individual drivers,
and completely removes vup/vright/vpn from the non-software renderers.
This has highlighted the craziness around AngleVectors with it putting
+X forward, -Y right and +Z up. The main issue with this is it requires
a 90 degree pre-rotation about the Z axis to get the camera pointing in
the right direction, and that's for the native sw renderer (vulkan needs
a 90 degree pre-rotation about X, and gl and glsl need to invert an
axis, too), though at least it's just a matrix swizzle and vector
negation. However, it does mean the camera matrices can't be used
directly.
Also rename vpn to vfwd (still abbreviated, but fwd is much clearer in
meaning (to me, at least) than pn (plane normal, I guess, but which
way?)).
2022-03-14 00:34:24 +00:00
|
|
|
VectorCopy (vfwd, base_vfwd);
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (vright, base_vright);
|
|
|
|
VectorCopy (vup, base_vup);
|
|
|
|
VectorCopy (modelorg, base_modelorg);
|
|
|
|
|
2022-03-14 02:56:10 +00:00
|
|
|
VectorCopy (vright, r_viewmatrix[0]);
|
|
|
|
VectorNegate (vup, r_viewmatrix[1]);
|
|
|
|
VectorCopy (vfwd, r_viewmatrix[2]);
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
R_SetSkyFrame ();
|
|
|
|
|
|
|
|
R_SetUpFrustumIndexes ();
|
|
|
|
|
|
|
|
r_cache_thrash = false;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// clear frame counts
|
2001-02-19 21:15:25 +00:00
|
|
|
c_faceclip = 0;
|
|
|
|
r_polycount = 0;
|
|
|
|
r_drawnpolycount = 0;
|
|
|
|
r_amodels_drawn = 0;
|
|
|
|
r_outofsurfaces = 0;
|
|
|
|
r_outofedges = 0;
|
|
|
|
|
|
|
|
D_SetupFrame ();
|
|
|
|
}
|