2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-08-25 02:47:11 +00:00
|
|
|
sw_r_bsp.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 04:50:53 +00:00
|
|
|
(description)
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
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-05-15 04:50:53 +00:00
|
|
|
#include <math.h>
|
2013-01-10 12:54:37 +00:00
|
|
|
#include <stdlib.h>
|
2001-05-15 04:50:53 +00:00
|
|
|
|
2013-01-22 05:09:41 +00:00
|
|
|
#include "qfalloca.h"
|
|
|
|
|
2001-05-20 04:26:22 +00:00
|
|
|
#include "QF/render.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-05-10 06:01:11 +00:00
|
|
|
|
2022-03-14 06:27:43 +00:00
|
|
|
typedef struct glbspctx_s {
|
|
|
|
mod_brush_t *brush;
|
2022-10-25 10:36:09 +00:00
|
|
|
uint32_t render_id;
|
2022-03-14 06:27:43 +00:00
|
|
|
} swbspctx_t;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// current entity info
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean insubmodel;
|
2001-08-28 20:51:51 +00:00
|
|
|
vec3_t r_worldmodelorg;
|
2022-03-17 04:09:20 +00:00
|
|
|
mvertex_t *r_pcurrentvertbase;
|
2012-02-18 05:34:14 +00:00
|
|
|
static float entity_rotation[3][3];
|
2001-05-18 17:50:19 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int r_currentbkey;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef enum { touchessolid, drawnode, nodrawnode } solidstate_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define MAX_BMODEL_VERTS 500 // 6K
|
|
|
|
#define MAX_BMODEL_EDGES 1000 // 12K
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static mvertex_t *pbverts;
|
|
|
|
static bedge_t *pbedges;
|
|
|
|
static int numbverts, numbedges;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-21 05:10:20 +00:00
|
|
|
int numbtofpolys;
|
|
|
|
static btofpoly_t *pbtofpolys;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static mvertex_t *pfrontenter, *pfrontexit;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean makeclippededge;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_EntityRotate (vec3_t vec)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t tvec;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorCopy (vec, tvec);
|
|
|
|
vec[0] = DotProduct (entity_rotation[0], tvec);
|
|
|
|
vec[1] = DotProduct (entity_rotation[1], tvec);
|
|
|
|
vec[2] = DotProduct (entity_rotation[2], tvec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RotateBmodel (vec4f_t *mat)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2021-03-09 14:52:40 +00:00
|
|
|
VectorCopy (mat[0], entity_rotation[0]);
|
|
|
|
VectorCopy (mat[1], entity_rotation[1]);
|
|
|
|
VectorCopy (mat[2], entity_rotation[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// rotate modelorg and the transformation matrix
|
2001-02-19 21:15:25 +00:00
|
|
|
R_EntityRotate (modelorg);
|
[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
|
|
|
R_EntityRotate (vfwd);
|
2001-02-19 21:15:25 +00:00
|
|
|
R_EntityRotate (vright);
|
|
|
|
R_EntityRotate (vup);
|
|
|
|
|
|
|
|
R_TransformFrustum ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RecursiveClipBPoly (uint32_t render_id, bedge_t *pedges, mnode_t *pnode,
|
2022-03-11 07:39:08 +00:00
|
|
|
msurface_t *psurf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
bedge_t *psideedges[2], *pnextedge, *ptedge;
|
|
|
|
int i, side, lastside;
|
|
|
|
float dist, frac, lastdist;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *splitplane, tplane;
|
2001-02-26 06:48:02 +00:00
|
|
|
mvertex_t *pvert, *plastvert, *ptvert;
|
|
|
|
mnode_t *pn;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
psideedges[0] = psideedges[1] = NULL;
|
|
|
|
|
|
|
|
makeclippededge = false;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// transform the BSP plane into model space
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: cache these?
|
2022-05-22 02:18:32 +00:00
|
|
|
splitplane = (plane_t *) &pnode->plane;
|
|
|
|
tplane.dist = splitplane->dist +
|
2001-02-26 06:48:02 +00:00
|
|
|
DotProduct (r_entorigin, splitplane->normal);
|
2001-02-19 21:15:25 +00:00
|
|
|
tplane.normal[0] = DotProduct (entity_rotation[0], splitplane->normal);
|
|
|
|
tplane.normal[1] = DotProduct (entity_rotation[1], splitplane->normal);
|
|
|
|
tplane.normal[2] = DotProduct (entity_rotation[2], splitplane->normal);
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// clip edges to BSP plane
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; pedges; pedges = pnextedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pnextedge = pedges->pnext;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// set the status for the last point as the previous point
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: cache this stuff somehow?
|
2001-02-19 21:15:25 +00:00
|
|
|
plastvert = pedges->v[0];
|
2022-05-22 02:18:32 +00:00
|
|
|
lastdist = DotProduct (plastvert->position, tplane.normal) +
|
2001-02-26 06:48:02 +00:00
|
|
|
tplane.dist;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (lastdist > 0)
|
|
|
|
lastside = 0;
|
|
|
|
else
|
|
|
|
lastside = 1;
|
|
|
|
|
|
|
|
pvert = pedges->v[1];
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
dist = DotProduct (pvert->position, tplane.normal) + tplane.dist;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (dist > 0)
|
|
|
|
side = 0;
|
|
|
|
else
|
|
|
|
side = 1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (side != lastside) {
|
|
|
|
// clipped
|
2001-02-19 21:15:25 +00:00
|
|
|
if (numbverts >= MAX_BMODEL_VERTS)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// generate the clipped vertex
|
2001-02-19 21:15:25 +00:00
|
|
|
frac = lastdist / (lastdist - dist);
|
|
|
|
ptvert = &pbverts[numbverts++];
|
|
|
|
ptvert->position[0] = plastvert->position[0] +
|
2001-02-26 06:48:02 +00:00
|
|
|
frac * (pvert->position[0] - plastvert->position[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
ptvert->position[1] = plastvert->position[1] +
|
2001-02-26 06:48:02 +00:00
|
|
|
frac * (pvert->position[1] - plastvert->position[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
ptvert->position[2] = plastvert->position[2] +
|
2001-02-26 06:48:02 +00:00
|
|
|
frac * (pvert->position[2] - plastvert->position[2]);
|
|
|
|
|
|
|
|
// split into two edges, one on each side, and remember entering
|
|
|
|
// and exiting points
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: share the clip edge by having a winding direction flag?
|
2001-02-26 06:48:02 +00:00
|
|
|
if (numbedges >= (MAX_BMODEL_EDGES - 1)) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Out of edges for bmodel\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptedge = &pbedges[numbedges];
|
|
|
|
ptedge->pnext = psideedges[lastside];
|
|
|
|
psideedges[lastside] = ptedge;
|
|
|
|
ptedge->v[0] = plastvert;
|
|
|
|
ptedge->v[1] = ptvert;
|
|
|
|
|
|
|
|
ptedge = &pbedges[numbedges + 1];
|
|
|
|
ptedge->pnext = psideedges[side];
|
|
|
|
psideedges[side] = ptedge;
|
|
|
|
ptedge->v[0] = ptvert;
|
|
|
|
ptedge->v[1] = pvert;
|
|
|
|
|
|
|
|
numbedges += 2;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (side == 0) {
|
|
|
|
// entering for front, exiting for back
|
2001-02-19 21:15:25 +00:00
|
|
|
pfrontenter = ptvert;
|
|
|
|
makeclippededge = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
pfrontexit = ptvert;
|
|
|
|
makeclippededge = true;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// add the edge to the appropriate side
|
2001-02-19 21:15:25 +00:00
|
|
|
pedges->pnext = psideedges[side];
|
|
|
|
psideedges[side] = pedges;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// if anything was clipped, reconstitute and add the edges along the clip
|
|
|
|
// plane to both sides (but in opposite directions)
|
2001-02-26 06:48:02 +00:00
|
|
|
if (makeclippededge) {
|
|
|
|
if (numbedges >= (MAX_BMODEL_EDGES - 2)) {
|
2007-11-06 10:17:14 +00:00
|
|
|
Sys_Printf ("Out of edges for bmodel\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptedge = &pbedges[numbedges];
|
|
|
|
ptedge->pnext = psideedges[0];
|
|
|
|
psideedges[0] = ptedge;
|
|
|
|
ptedge->v[0] = pfrontexit;
|
|
|
|
ptedge->v[1] = pfrontenter;
|
|
|
|
|
|
|
|
ptedge = &pbedges[numbedges + 1];
|
|
|
|
ptedge->pnext = psideedges[1];
|
|
|
|
psideedges[1] = ptedge;
|
|
|
|
ptedge->v[0] = pfrontenter;
|
|
|
|
ptedge->v[1] = pfrontexit;
|
|
|
|
|
|
|
|
numbedges += 2;
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// draw or recurse further
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (psideedges[i]) {
|
2001-05-15 21:13:07 +00:00
|
|
|
// draw if we've reached a non-solid leaf, done if all that's left
|
|
|
|
// is a solid leaf, and continue down the tree if it's not a leaf
|
2022-05-22 02:18:32 +00:00
|
|
|
int child_id = pnode->children[i];
|
|
|
|
pn = r_refdef.worldmodel->brush.nodes + child_id;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// we're done with this branch if the node or leaf isn't in the PVS
|
2022-05-22 02:18:32 +00:00
|
|
|
if (child_id < 0) {
|
|
|
|
mleaf_t *leaf = r_refdef.worldmodel->brush.leafs + ~child_id;
|
2022-05-22 05:43:07 +00:00
|
|
|
if (r_leaf_visframes[~child_id] == r_visframecount
|
2022-05-22 02:18:32 +00:00
|
|
|
&& leaf->contents != CONTENTS_SOLID) {
|
|
|
|
r_currentbkey = leaf->key;
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RenderBmodelFace (render_id, psideedges[i], psurf);
|
2022-05-22 02:18:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (r_node_visframes[child_id] == r_visframecount) {
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RecursiveClipBPoly (render_id, psideedges[i], pn, psurf);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-10-25 10:36:09 +00:00
|
|
|
R_DrawSolidClippedSubmodelPolygons (uint32_t render_id, mod_brush_t *brush,
|
2022-03-11 07:39:08 +00:00
|
|
|
mnode_t *topnode)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j, lindex;
|
|
|
|
vec_t dot;
|
|
|
|
msurface_t *psurf;
|
|
|
|
int numsurfaces;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2001-02-26 06:48:02 +00:00
|
|
|
mvertex_t bverts[MAX_BMODEL_VERTS];
|
|
|
|
bedge_t bedges[MAX_BMODEL_EDGES], *pbedge;
|
|
|
|
medge_t *pedge, *pedges;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: use bounding-box-based frustum clipping info?
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 10:31:11 +00:00
|
|
|
psurf = &brush->surfaces[brush->firstmodelsurface];
|
|
|
|
numsurfaces = brush->nummodelsurfaces;
|
|
|
|
pedges = brush->edges;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < numsurfaces; i++, psurf++) {
|
|
|
|
// find which side of the node we are on
|
2001-02-19 21:15:25 +00:00
|
|
|
pplane = psurf->plane;
|
|
|
|
|
|
|
|
dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// draw the polygon
|
2001-02-19 21:15:25 +00:00
|
|
|
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: use bounding-box-based frustum clipping info?
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// copy the edges to bedges, flipping if necessary so always
|
|
|
|
// clockwise winding
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: if edges and vertices get caches, these assignments must
|
|
|
|
// move outside the loop, and overflow checking must be done here
|
2001-02-19 21:15:25 +00:00
|
|
|
pbverts = bverts;
|
|
|
|
pbedges = bedges;
|
|
|
|
numbverts = numbedges = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (psurf->numedges > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pbedge = &bedges[numbedges];
|
|
|
|
numbedges += psurf->numedges;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < psurf->numedges; j++) {
|
2021-02-01 10:31:11 +00:00
|
|
|
lindex = brush->surfedges[psurf->firstedge + j];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lindex > 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pedge = &pedges[lindex];
|
|
|
|
pbedge[j].v[0] = &r_pcurrentvertbase[pedge->v[0]];
|
|
|
|
pbedge[j].v[1] = &r_pcurrentvertbase[pedge->v[1]];
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
lindex = -lindex;
|
|
|
|
pedge = &pedges[lindex];
|
|
|
|
pbedge[j].v[0] = &r_pcurrentvertbase[pedge->v[1]];
|
|
|
|
pbedge[j].v[1] = &r_pcurrentvertbase[pedge->v[0]];
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
pbedge[j].pnext = &pbedge[j + 1];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
pbedge[j - 1].pnext = NULL; // mark end of edges
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RecursiveClipBPoly (render_id, pbedge, topnode, psurf);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("no edges in bmodel");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-10-25 10:36:09 +00:00
|
|
|
R_DrawSubmodelPolygons (uint32_t render_id, mod_brush_t *brush, int clipflags,
|
2022-05-22 02:18:32 +00:00
|
|
|
mleaf_t *topleaf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
vec_t dot;
|
|
|
|
msurface_t *psurf;
|
|
|
|
int numsurfaces;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 20:51:51 +00:00
|
|
|
// FIXME: use bounding-box-based frustum clipping info?
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-02-01 10:31:11 +00:00
|
|
|
psurf = &brush->surfaces[brush->firstmodelsurface];
|
|
|
|
numsurfaces = brush->nummodelsurfaces;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < numsurfaces; i++, psurf++) {
|
|
|
|
// find which side of the node we are on
|
2001-02-19 21:15:25 +00:00
|
|
|
pplane = psurf->plane;
|
|
|
|
|
|
|
|
dot = DotProduct (modelorg, pplane->normal) - pplane->dist;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// draw the polygon
|
2001-02-19 21:15:25 +00:00
|
|
|
if (((psurf->flags & SURF_PLANEBACK) && (dot < -BACKFACE_EPSILON)) ||
|
2001-02-26 06:48:02 +00:00
|
|
|
(!(psurf->flags & SURF_PLANEBACK) && (dot > BACKFACE_EPSILON))) {
|
2022-05-22 02:18:32 +00:00
|
|
|
r_currentkey = topleaf->key;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// FIXME: use bounding-box-based frustum clipping info?
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RenderFace (render_id, psurf, clipflags);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-15 03:46:55 +00:00
|
|
|
static inline void
|
|
|
|
visit_leaf (mleaf_t *leaf)
|
|
|
|
{
|
|
|
|
// deal with model fragments in this leaf
|
|
|
|
if (leaf->efrags)
|
2010-12-03 04:28:58 +00:00
|
|
|
R_StoreEfrags (leaf->efrags);
|
2004-02-15 03:46:55 +00:00
|
|
|
leaf->key = r_currentkey;
|
|
|
|
r_currentkey++; // all bmodels in a leaf share the same key
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
get_side (mnode_t *node)
|
|
|
|
{
|
|
|
|
// find which side of the node we are on
|
[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
|
|
|
vec4f_t org = r_refdef.frame.position;
|
2004-02-15 03:46:55 +00:00
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
return dotf (org, node->plane)[0] < 0;
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2004-02-15 03:46:55 +00:00
|
|
|
static void
|
2022-03-14 06:27:43 +00:00
|
|
|
visit_node (swbspctx_t *bctx, mnode_t *node, int side, int clipflags)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
msurface_t *surf;
|
2022-10-25 10:36:09 +00:00
|
|
|
uint32_t render_id = bctx->render_id;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
mod_brush_t *brush = bctx->brush;
|
2004-02-15 03:46:55 +00:00
|
|
|
|
|
|
|
// sneaky hack for side = side ? SURF_PLANEBACK : 0;
|
|
|
|
side = (~side + 1) & SURF_PLANEBACK;
|
|
|
|
// draw stuff
|
|
|
|
if ((c = node->numsurfaces)) {
|
2022-05-22 07:31:24 +00:00
|
|
|
int surf_id = node->firstsurface;
|
|
|
|
surf = brush->surfaces + surf_id;
|
|
|
|
for (; c; c--, surf++, surf_id++) {
|
|
|
|
if (r_face_visframes[surf_id] != r_visframecount)
|
2004-02-15 03:46:55 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// side is either 0 or SURF_PLANEBACK
|
|
|
|
if (side ^ (surf->flags & SURF_PLANEBACK))
|
|
|
|
continue; // wrong side
|
|
|
|
|
|
|
|
if (r_drawpolys) {
|
|
|
|
if (r_worldpolysbacktofront) {
|
|
|
|
if (numbtofpolys < MAX_BTOFPOLYS) {
|
|
|
|
pbtofpolys[numbtofpolys].clipflags = clipflags;
|
|
|
|
pbtofpolys[numbtofpolys].psurf = surf;
|
|
|
|
numbtofpolys++;
|
|
|
|
}
|
|
|
|
} else {
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RenderPoly (render_id, surf, clipflags);
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RenderFace (render_id, surf, clipflags);
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// all surfaces on the same node share the same sequence number
|
|
|
|
r_currentkey++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2022-05-22 02:18:32 +00:00
|
|
|
test_node (swbspctx_t *bctx, int node_id, int *clipflags)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
|
|
|
int i, *pindex;
|
|
|
|
vec3_t acceptpt, rejectpt;
|
|
|
|
double d;
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
if (node_id < 0)
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
2022-05-22 02:18:32 +00:00
|
|
|
if (r_node_visframes[node_id] != r_visframecount)
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
|
|
|
// cull the clipping planes if not trivial accept
|
|
|
|
// FIXME: the compiler is doing a lousy job of optimizing here; it could be
|
|
|
|
// twice as fast in ASM
|
2004-02-26 22:53:30 +00:00
|
|
|
if (*clipflags) {
|
2022-05-22 02:18:32 +00:00
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2004-02-26 22:53:30 +00:00
|
|
|
if (!(*clipflags & (1 << i)))
|
2004-02-15 03:46:55 +00:00
|
|
|
continue; // don't need to clip against it
|
|
|
|
|
|
|
|
// generate accept and reject points
|
|
|
|
// FIXME: do with fast look-ups or integer tests based on the
|
|
|
|
// sign bit of the floating point values
|
|
|
|
|
|
|
|
pindex = pfrustum_indexes[i];
|
|
|
|
|
|
|
|
rejectpt[0] = (float) node->minmaxs[pindex[0]];
|
|
|
|
rejectpt[1] = (float) node->minmaxs[pindex[1]];
|
|
|
|
rejectpt[2] = (float) node->minmaxs[pindex[2]];
|
|
|
|
|
|
|
|
d = DotProduct (rejectpt, view_clipplanes[i].normal);
|
|
|
|
d -= view_clipplanes[i].dist;
|
|
|
|
|
2004-02-26 22:53:30 +00:00
|
|
|
if (d <= 0)
|
2004-02-15 03:46:55 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
acceptpt[0] = (float) node->minmaxs[pindex[3 + 0]];
|
|
|
|
acceptpt[1] = (float) node->minmaxs[pindex[3 + 1]];
|
|
|
|
acceptpt[2] = (float) node->minmaxs[pindex[3 + 2]];
|
|
|
|
|
|
|
|
d = DotProduct (acceptpt, view_clipplanes[i].normal);
|
|
|
|
d -= view_clipplanes[i].dist;
|
|
|
|
if (d >= 0)
|
2004-02-26 22:53:30 +00:00
|
|
|
*clipflags &= ~(1 << i); // node is entirely on screen
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2022-03-14 06:27:43 +00:00
|
|
|
R_VisitWorldNodes (swbspctx_t *bctx, int clipflags)
|
2004-02-15 03:46:55 +00:00
|
|
|
{
|
2013-01-07 10:51:36 +00:00
|
|
|
typedef struct {
|
2022-05-22 02:18:32 +00:00
|
|
|
int node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
int side, clipflags;
|
2013-01-07 10:51:36 +00:00
|
|
|
} rstack_t;
|
|
|
|
rstack_t *node_ptr;
|
|
|
|
rstack_t *node_stack;
|
2022-05-22 02:18:32 +00:00
|
|
|
int front;
|
2004-02-26 22:53:30 +00:00
|
|
|
int side, cf;
|
2022-05-22 02:18:32 +00:00
|
|
|
int node_id;
|
[scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).
While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 01:32:09 +00:00
|
|
|
mod_brush_t *brush = bctx->brush;
|
2004-02-15 03:46:55 +00:00
|
|
|
|
2013-01-07 10:51:36 +00:00
|
|
|
// +2 for paranoia
|
2021-02-01 10:31:11 +00:00
|
|
|
node_stack = alloca ((brush->depth + 2) * sizeof (rstack_t));
|
2004-02-15 03:46:55 +00:00
|
|
|
node_ptr = node_stack;
|
|
|
|
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = 0;
|
2004-02-26 22:53:30 +00:00
|
|
|
cf = clipflags;
|
2004-02-15 03:46:55 +00:00
|
|
|
while (1) {
|
2022-05-22 02:18:32 +00:00
|
|
|
while (test_node (bctx, node_id, &cf)) {
|
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2004-02-26 22:53:30 +00:00
|
|
|
cf = clipflags;
|
2004-02-15 03:46:55 +00:00
|
|
|
side = get_side (node);
|
|
|
|
front = node->children[side];
|
2022-05-22 02:18:32 +00:00
|
|
|
if (test_node (bctx, front, &cf)) {
|
|
|
|
node_ptr->node_id = node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
node_ptr->side = side;
|
|
|
|
node_ptr->clipflags = clipflags;
|
|
|
|
node_ptr++;
|
2004-02-26 22:53:30 +00:00
|
|
|
clipflags = cf;
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = front;
|
2004-02-15 03:46:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-05-22 02:18:32 +00:00
|
|
|
if (front < 0) {
|
|
|
|
mleaf_t *leaf = bctx->brush->leafs + ~front;
|
|
|
|
if (leaf->contents != CONTENTS_SOLID) {
|
|
|
|
visit_leaf (leaf);
|
|
|
|
}
|
|
|
|
}
|
2022-03-14 06:27:43 +00:00
|
|
|
visit_node (bctx, node, side, clipflags);
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node->children[side ^ 1];
|
|
|
|
}
|
|
|
|
if (node_id < 0) {
|
|
|
|
mleaf_t *leaf = bctx->brush->leafs + ~node_id;
|
|
|
|
if (leaf->contents != CONTENTS_SOLID) {
|
|
|
|
visit_leaf (leaf);
|
|
|
|
}
|
2004-02-15 03:46:55 +00:00
|
|
|
}
|
|
|
|
if (node_ptr != node_stack) {
|
|
|
|
node_ptr--;
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node_ptr->node_id;
|
|
|
|
mnode_t *node = bctx->brush->nodes + node_id;
|
2004-02-15 03:46:55 +00:00
|
|
|
side = node_ptr->side;
|
|
|
|
clipflags = node_ptr->clipflags;
|
2022-03-14 06:27:43 +00:00
|
|
|
visit_node (bctx, node, side, clipflags);
|
2022-05-22 02:18:32 +00:00
|
|
|
node_id = node->children[side ^ 1];
|
2004-02-15 03:46:55 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_RenderWorld (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
btofpoly_t btofpolys[MAX_BTOFPOLYS];
|
2022-03-14 06:27:43 +00:00
|
|
|
mod_brush_t *brush = &r_refdef.worldmodel->brush;
|
|
|
|
swbspctx_t bspctx = {
|
|
|
|
brush,
|
2022-10-25 10:36:09 +00:00
|
|
|
0,
|
2022-03-14 06:27:43 +00:00
|
|
|
};
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
pbtofpolys = btofpolys;
|
|
|
|
|
2022-03-14 06:27:43 +00:00
|
|
|
brush = &r_refdef.worldmodel->brush;
|
2021-02-01 10:31:11 +00:00
|
|
|
r_pcurrentvertbase = brush->vertexes;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-14 06:27:43 +00:00
|
|
|
R_VisitWorldNodes (&bspctx, 15);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// if the driver wants the polygons back to front, play the visible ones
|
|
|
|
// back in that order
|
2001-02-26 06:48:02 +00:00
|
|
|
if (r_worldpolysbacktofront) {
|
|
|
|
for (i = numbtofpolys - 1; i >= 0; i--) {
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RenderPoly (0, btofpolys[i].psurf, btofpolys[i].clipflags);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|