2001-02-19 21:15:25 +00:00
|
|
|
/*
|
2001-08-25 02:47:11 +00:00
|
|
|
sw_r_draw.c
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-11 01:01:27 +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-19 00:23:21 +00:00
|
|
|
#include "QF/render.h"
|
2022-03-29 05:40:48 +00:00
|
|
|
#include "QF/scene/entity.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define MAXLEFTCLIPEDGES 100
|
|
|
|
|
|
|
|
// !!! if these are changed, they must be changed in asm_draw.h too !!!
|
|
|
|
#define FULLY_CLIPPED_CACHED 0x80000000
|
|
|
|
#define FRAMECOUNT_MASK 0x7FFFFFFF
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
unsigned int cacheoffset;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int c_faceclip; // number of faces clipped
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
zpointdesc_t r_zpointdesc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-18 05:34:14 +00:00
|
|
|
static polydesc_t r_polydesc;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
clipplane_t view_clipplanes[4];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-07-26 12:14:28 +00:00
|
|
|
medge_t *r_pedge; // FIXME used by asm
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean r_leftclipped, r_rightclipped;
|
|
|
|
static qboolean makeleftedge, makerightedge;
|
|
|
|
qboolean r_nearzionly;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int sintable[SIN_BUFFER_SIZE];
|
|
|
|
int intsintable[SIN_BUFFER_SIZE];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
mvertex_t r_leftenter, r_leftexit;
|
|
|
|
mvertex_t r_rightenter, r_rightexit;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
typedef struct {
|
|
|
|
float u, v;
|
|
|
|
int ceilv;
|
2001-02-19 21:15:25 +00:00
|
|
|
} evert_t;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int r_emitted;
|
|
|
|
float r_nearzi;
|
|
|
|
float r_u1, r_v1, r_lzi1;
|
|
|
|
int r_ceilv1;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean r_lastvertvalid;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-06-11 20:59:48 +00:00
|
|
|
#ifdef PIC
|
2001-05-25 14:57:31 +00:00
|
|
|
#undef USE_INTEL_ASM //XXX asm pic hack
|
2001-06-11 20:59:48 +00:00
|
|
|
#endif
|
2001-05-25 14:57:31 +00:00
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#ifndef USE_INTEL_ASM
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
edge_t *edge, *pcheck;
|
|
|
|
int u_check;
|
|
|
|
float u, u_step;
|
|
|
|
vec3_t local, transformed;
|
|
|
|
float *world;
|
|
|
|
int v, v2, ceilv0;
|
|
|
|
float scale, lzi0, u0, v0;
|
|
|
|
int side;
|
|
|
|
|
|
|
|
if (r_lastvertvalid) {
|
2001-02-19 21:15:25 +00:00
|
|
|
u0 = r_u1;
|
|
|
|
v0 = r_v1;
|
|
|
|
lzi0 = r_lzi1;
|
|
|
|
ceilv0 = r_ceilv1;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
world = &pv0->position[0];
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
// transform and project
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorSubtract (world, modelorg, local);
|
|
|
|
TransformVector (local, transformed);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
if (transformed[2] < NEAR_CLIP)
|
|
|
|
transformed[2] = NEAR_CLIP;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
lzi0 = 1.0 / transformed[2];
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
// FIXME: build x/yscale into transform?
|
2001-02-19 21:15:25 +00:00
|
|
|
scale = xscale * lzi0;
|
2001-02-26 06:48:02 +00:00
|
|
|
u0 = (xcenter + scale * transformed[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (u0 < r_refdef.fvrectx_adj)
|
|
|
|
u0 = r_refdef.fvrectx_adj;
|
|
|
|
if (u0 > r_refdef.fvrectright_adj)
|
|
|
|
u0 = r_refdef.fvrectright_adj;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
scale = yscale * lzi0;
|
2001-02-26 06:48:02 +00:00
|
|
|
v0 = (ycenter - scale * transformed[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (v0 < r_refdef.fvrecty_adj)
|
|
|
|
v0 = r_refdef.fvrecty_adj;
|
|
|
|
if (v0 > r_refdef.fvrectbottom_adj)
|
|
|
|
v0 = r_refdef.fvrectbottom_adj;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
ceilv0 = (int) ceil (v0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
world = &pv1->position[0];
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// transform and project
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorSubtract (world, modelorg, local);
|
|
|
|
TransformVector (local, transformed);
|
|
|
|
|
|
|
|
if (transformed[2] < NEAR_CLIP)
|
|
|
|
transformed[2] = NEAR_CLIP;
|
|
|
|
|
|
|
|
r_lzi1 = 1.0 / transformed[2];
|
|
|
|
|
|
|
|
scale = xscale * r_lzi1;
|
2001-02-26 06:48:02 +00:00
|
|
|
r_u1 = (xcenter + scale * transformed[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (r_u1 < r_refdef.fvrectx_adj)
|
|
|
|
r_u1 = r_refdef.fvrectx_adj;
|
|
|
|
if (r_u1 > r_refdef.fvrectright_adj)
|
|
|
|
r_u1 = r_refdef.fvrectright_adj;
|
|
|
|
|
|
|
|
scale = yscale * r_lzi1;
|
2001-02-26 06:48:02 +00:00
|
|
|
r_v1 = (ycenter - scale * transformed[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (r_v1 < r_refdef.fvrecty_adj)
|
|
|
|
r_v1 = r_refdef.fvrecty_adj;
|
|
|
|
if (r_v1 > r_refdef.fvrectbottom_adj)
|
|
|
|
r_v1 = r_refdef.fvrectbottom_adj;
|
|
|
|
|
|
|
|
if (r_lzi1 > lzi0)
|
|
|
|
lzi0 = r_lzi1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lzi0 > r_nearzi) // for mipmap finding
|
2001-02-19 21:15:25 +00:00
|
|
|
r_nearzi = lzi0;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// for right edges, all we want is the effect on 1/z
|
2001-02-19 21:15:25 +00:00
|
|
|
if (r_nearzionly)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r_emitted = 1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r_ceilv1 = (int) ceil (r_v1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// create the edge
|
2001-02-26 06:48:02 +00:00
|
|
|
if (ceilv0 == r_ceilv1) {
|
|
|
|
// we cache unclipped horizontal edges as fully clipped
|
|
|
|
if (cacheoffset != 0x7FFFFFFF) {
|
2001-02-19 21:15:25 +00:00
|
|
|
cacheoffset = FULLY_CLIPPED_CACHED |
|
2001-02-26 06:48:02 +00:00
|
|
|
(r_framecount & FRAMECOUNT_MASK);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return; // horizontal edge
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
side = ceilv0 > r_ceilv1;
|
|
|
|
|
|
|
|
edge = edge_p++;
|
|
|
|
|
|
|
|
edge->owner = r_pedge;
|
|
|
|
|
|
|
|
edge->nearzi = lzi0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (side == 0) {
|
|
|
|
// trailing edge (go from p1 to p2)
|
2001-02-19 21:15:25 +00:00
|
|
|
v = ceilv0;
|
|
|
|
v2 = r_ceilv1 - 1;
|
|
|
|
|
|
|
|
edge->surfs[0] = surface_p - surfaces;
|
|
|
|
edge->surfs[1] = 0;
|
|
|
|
|
|
|
|
u_step = ((r_u1 - u0) / (r_v1 - v0));
|
2001-02-26 06:48:02 +00:00
|
|
|
u = u0 + ((float) v - v0) * u_step;
|
|
|
|
} else {
|
|
|
|
// leading edge (go from p2 to p1)
|
2001-02-19 21:15:25 +00:00
|
|
|
v2 = ceilv0 - 1;
|
|
|
|
v = r_ceilv1;
|
|
|
|
|
|
|
|
edge->surfs[0] = 0;
|
|
|
|
edge->surfs[1] = surface_p - surfaces;
|
|
|
|
|
|
|
|
u_step = ((u0 - r_u1) / (v0 - r_v1));
|
2001-02-26 06:48:02 +00:00
|
|
|
u = r_u1 + ((float) v - r_v1) * u_step;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
edge->u_step = u_step * 0x100000;
|
|
|
|
edge->u = u * 0x100000 + 0xFFFFF;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// we need to do this to avoid stepping off the edges if a very nearly
|
|
|
|
// horizontal edge is less than epsilon above a scan, and numeric error
|
|
|
|
// causes it to incorrectly extend to the scan, and the extension of the
|
|
|
|
// line goes off the edge of the screen
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: is this actually needed?
|
2022-03-27 06:27:35 +00:00
|
|
|
if (edge->u < r_refdef.vrectx_adj_shift20)
|
|
|
|
edge->u = r_refdef.vrectx_adj_shift20;
|
2001-02-19 21:15:25 +00:00
|
|
|
if (edge->u > r_refdef.vrectright_adj_shift20)
|
|
|
|
edge->u = r_refdef.vrectright_adj_shift20;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// sort the edge in normally
|
2001-02-19 21:15:25 +00:00
|
|
|
u_check = edge->u;
|
|
|
|
if (edge->surfs[0])
|
2001-02-26 06:48:02 +00:00
|
|
|
u_check++; // sort trailers after leaders
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!newedges[v] || newedges[v]->u >= u_check) {
|
2001-02-19 21:15:25 +00:00
|
|
|
edge->next = newedges[v];
|
|
|
|
newedges[v] = edge;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
pcheck = newedges[v];
|
|
|
|
while (pcheck->next && pcheck->next->u < u_check)
|
|
|
|
pcheck = pcheck->next;
|
|
|
|
edge->next = pcheck->next;
|
|
|
|
pcheck->next = edge;
|
|
|
|
}
|
|
|
|
|
|
|
|
edge->nextremove = removeedges[v2];
|
|
|
|
removeedges[v2] = edge;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_ClipEdge (mvertex_t *pv0, mvertex_t *pv1, clipplane_t *clip)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
float d0, d1, f;
|
|
|
|
mvertex_t clipvert;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (clip) {
|
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
d0 = DotProduct (pv0->position, clip->normal) - clip->dist;
|
|
|
|
d1 = DotProduct (pv1->position, clip->normal) - clip->dist;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (d0 >= 0) {
|
|
|
|
// point 0 is unclipped
|
|
|
|
if (d1 >= 0) {
|
|
|
|
// both points are unclipped
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// only point 1 is clipped
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// we don't cache clipped edges
|
2001-02-19 21:15:25 +00:00
|
|
|
cacheoffset = 0x7FFFFFFF;
|
|
|
|
|
|
|
|
f = d0 / (d0 - d1);
|
|
|
|
clipvert.position[0] = pv0->position[0] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[0] - pv0->position[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
clipvert.position[1] = pv0->position[1] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[1] - pv0->position[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
clipvert.position[2] = pv0->position[2] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[2] - pv0->position[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (clip->leftedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_leftclipped = true;
|
|
|
|
r_leftexit = clipvert;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (clip->rightedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_rightclipped = true;
|
|
|
|
r_rightexit = clipvert;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_ClipEdge (pv0, &clipvert, clip->next);
|
|
|
|
return;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// point 0 is clipped
|
|
|
|
if (d1 < 0) {
|
|
|
|
// both points are clipped
|
|
|
|
// we do cache fully clipped edges
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!r_leftclipped)
|
|
|
|
cacheoffset = FULLY_CLIPPED_CACHED |
|
2001-02-26 06:48:02 +00:00
|
|
|
(r_framecount & FRAMECOUNT_MASK);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// only point 0 is clipped
|
2001-02-19 21:15:25 +00:00
|
|
|
r_lastvertvalid = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// we don't cache partially clipped edges
|
2001-02-19 21:15:25 +00:00
|
|
|
cacheoffset = 0x7FFFFFFF;
|
|
|
|
|
|
|
|
f = d0 / (d0 - d1);
|
|
|
|
clipvert.position[0] = pv0->position[0] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[0] - pv0->position[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
clipvert.position[1] = pv0->position[1] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[1] - pv0->position[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
clipvert.position[2] = pv0->position[2] +
|
2001-02-26 06:48:02 +00:00
|
|
|
f * (pv1->position[2] - pv0->position[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (clip->leftedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_leftclipped = true;
|
|
|
|
r_leftenter = clipvert;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (clip->rightedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_rightclipped = true;
|
|
|
|
r_rightenter = clipvert;
|
|
|
|
}
|
|
|
|
|
|
|
|
R_ClipEdge (&clipvert, pv1, clip->next);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} while ((clip = clip->next) != NULL);
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// add the edge
|
2001-02-19 21:15:25 +00:00
|
|
|
R_EmitEdge (pv0, pv1);
|
|
|
|
}
|
|
|
|
|
2001-05-11 01:01:27 +00:00
|
|
|
#endif // !USE_INTEL_ASM
|
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_EmitCachedEdge (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
edge_t *pedge_t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2007-04-11 22:03:36 +00:00
|
|
|
pedge_t = (edge_t *) ((intptr_t) r_edges + r_pedge->cachededgeoffset);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!pedge_t->surfs[0])
|
|
|
|
pedge_t->surfs[0] = surface_p - surfaces;
|
|
|
|
else
|
|
|
|
pedge_t->surfs[1] = surface_p - surfaces;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (pedge_t->nearzi > r_nearzi) // for mipmap finding
|
2001-02-19 21:15:25 +00:00
|
|
|
r_nearzi = pedge_t->nearzi;
|
|
|
|
|
|
|
|
r_emitted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RenderFace (entity_t *ent, msurface_t *fa, int clipflags)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, lindex;
|
2001-05-11 01:01:27 +00:00
|
|
|
unsigned int mask;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2001-02-26 06:48:02 +00:00
|
|
|
float distinv;
|
|
|
|
vec3_t p_normal;
|
|
|
|
medge_t *pedges, tedge;
|
|
|
|
clipplane_t *pclip;
|
2022-03-11 07:39:08 +00:00
|
|
|
mod_brush_t *brush = &ent->renderer.model->brush;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// skip out if no more surfs
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((surface_p) >= surf_max) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_outofsurfaces++;
|
|
|
|
return;
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// ditto if not enough edges left, or switch to auxedges if possible
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((edge_p + fa->numedges + 4) >= edge_max) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_outofedges += fa->numedges;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_faceclip++;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// set up clip planes
|
2001-02-19 21:15:25 +00:00
|
|
|
pclip = NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 3, mask = 0x08; i >= 0; i--, mask >>= 1) {
|
|
|
|
if (clipflags & mask) {
|
2001-02-19 21:15:25 +00:00
|
|
|
view_clipplanes[i].next = pclip;
|
|
|
|
pclip = &view_clipplanes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// push the edges through
|
2001-02-19 21:15:25 +00:00
|
|
|
r_emitted = 0;
|
|
|
|
r_nearzi = 0;
|
|
|
|
r_nearzionly = false;
|
|
|
|
makeleftedge = makerightedge = false;
|
2021-02-01 10:31:11 +00:00
|
|
|
pedges = brush->edges;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_lastvertvalid = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < fa->numedges; i++) {
|
2021-02-01 10:31:11 +00:00
|
|
|
lindex = brush->surfedges[fa->firstedge + i];
|
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
|
|
|
r_pedge = &pedges[lindex];
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// if the edge is cached, we can just reuse the edge
|
|
|
|
if (!insubmodel) {
|
|
|
|
if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((r_pedge->cachededgeoffset & FRAMECOUNT_MASK) ==
|
2003-04-17 00:01:48 +00:00
|
|
|
(unsigned int) r_framecount) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_lastvertvalid = false;
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2007-04-11 22:03:36 +00:00
|
|
|
if ((((uintptr_t) edge_p - (uintptr_t) r_edges) >
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge->cachededgeoffset) &&
|
2007-04-11 22:03:36 +00:00
|
|
|
(((edge_t *) ((intptr_t) r_edges +
|
2001-02-26 06:48:02 +00:00
|
|
|
r_pedge->cachededgeoffset))->owner ==
|
|
|
|
r_pedge)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
R_EmitCachedEdge ();
|
|
|
|
r_lastvertvalid = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// assume it's cacheable
|
|
|
|
cacheoffset = (byte *) edge_p - (byte *) r_edges;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_leftclipped = r_rightclipped = false;
|
|
|
|
R_ClipEdge (&r_pcurrentvertbase[r_pedge->v[0]],
|
2001-02-26 06:48:02 +00:00
|
|
|
&r_pcurrentvertbase[r_pedge->v[1]], pclip);
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge->cachededgeoffset = cacheoffset;
|
|
|
|
|
|
|
|
if (r_leftclipped)
|
|
|
|
makeleftedge = true;
|
|
|
|
if (r_rightclipped)
|
|
|
|
makerightedge = true;
|
|
|
|
r_lastvertvalid = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
lindex = -lindex;
|
|
|
|
r_pedge = &pedges[lindex];
|
2001-02-26 06:48:02 +00:00
|
|
|
// if the edge is cached, we can just reuse the edge
|
|
|
|
if (!insubmodel) {
|
|
|
|
if (r_pedge->cachededgeoffset & FULLY_CLIPPED_CACHED) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if ((r_pedge->cachededgeoffset & FRAMECOUNT_MASK) ==
|
2003-04-17 00:01:48 +00:00
|
|
|
(unsigned int) r_framecount) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_lastvertvalid = false;
|
|
|
|
continue;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
// it's cached if the cached edge is valid and is owned
|
|
|
|
// by this medge_t
|
2007-04-11 22:03:36 +00:00
|
|
|
if ((((uintptr_t) edge_p - (uintptr_t) r_edges) >
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge->cachededgeoffset) &&
|
2007-04-11 22:03:36 +00:00
|
|
|
(((edge_t *) ((intptr_t) r_edges +
|
2001-02-26 06:48:02 +00:00
|
|
|
r_pedge->cachededgeoffset))->owner ==
|
|
|
|
r_pedge)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
R_EmitCachedEdge ();
|
|
|
|
r_lastvertvalid = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
// assume it's cacheable
|
|
|
|
cacheoffset = (byte *) edge_p - (byte *) r_edges;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_leftclipped = r_rightclipped = false;
|
|
|
|
R_ClipEdge (&r_pcurrentvertbase[r_pedge->v[1]],
|
2001-02-26 06:48:02 +00:00
|
|
|
&r_pcurrentvertbase[r_pedge->v[0]], pclip);
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge->cachededgeoffset = cacheoffset;
|
|
|
|
|
|
|
|
if (r_leftclipped)
|
|
|
|
makeleftedge = true;
|
|
|
|
if (r_rightclipped)
|
|
|
|
makerightedge = true;
|
|
|
|
r_lastvertvalid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// if there was a clip off the left edge, add that edge too
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: faster to do in screen space?
|
|
|
|
// FIXME: share clipped edges?
|
2001-02-26 06:48:02 +00:00
|
|
|
if (makeleftedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &tedge;
|
|
|
|
r_lastvertvalid = false;
|
|
|
|
R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next);
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// if there was a clip off the right edge, get the right r_nearzi
|
2001-02-26 06:48:02 +00:00
|
|
|
if (makerightedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &tedge;
|
|
|
|
r_lastvertvalid = false;
|
|
|
|
r_nearzionly = true;
|
|
|
|
R_ClipEdge (&r_rightexit, &r_rightenter, view_clipplanes[1].next);
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// if no edges made it out, return without posting the surface
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!r_emitted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r_polycount++;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
surface_p->data = (void *) fa;
|
2001-02-19 21:15:25 +00:00
|
|
|
surface_p->nearzi = r_nearzi;
|
|
|
|
surface_p->flags = fa->flags;
|
|
|
|
surface_p->insubmodel = insubmodel;
|
|
|
|
surface_p->spanstate = 0;
|
2022-03-11 07:39:08 +00:00
|
|
|
surface_p->entity = ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
surface_p->key = r_currentkey++;
|
|
|
|
surface_p->spans = NULL;
|
|
|
|
|
|
|
|
pplane = fa->plane;
|
|
|
|
// FIXME: cache this?
|
|
|
|
TransformVector (pplane->normal, p_normal);
|
|
|
|
// FIXME: cache this?
|
|
|
|
distinv = 1.0 / (pplane->dist - DotProduct (modelorg, pplane->normal));
|
|
|
|
|
|
|
|
surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv;
|
|
|
|
surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv;
|
|
|
|
surface_p->d_ziorigin = p_normal[2] * distinv -
|
2001-02-26 06:48:02 +00:00
|
|
|
xcenter * surface_p->d_zistepu - ycenter * surface_p->d_zistepv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
surface_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RenderBmodelFace (entity_t *ent, bedge_t *pedges, msurface_t *psurf)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
2001-05-11 01:01:27 +00:00
|
|
|
unsigned int mask;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2001-02-26 06:48:02 +00:00
|
|
|
float distinv;
|
|
|
|
vec3_t p_normal;
|
|
|
|
clipplane_t *pclip;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// skip out if no more surfs
|
2001-02-26 06:48:02 +00:00
|
|
|
if (surface_p >= surf_max) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_outofsurfaces++;
|
|
|
|
return;
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// ditto if not enough edges left, or switch to auxedges if possible
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((edge_p + psurf->numedges + 4) >= edge_max) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_outofedges += psurf->numedges;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_faceclip++;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// this is a dummy to give the caching mechanism someplace to write to
|
2022-07-26 12:14:28 +00:00
|
|
|
static medge_t tedge;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &tedge;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// set up clip planes
|
2001-02-19 21:15:25 +00:00
|
|
|
pclip = NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 3, mask = 0x08; i >= 0; i--, mask >>= 1) {
|
|
|
|
if (r_clipflags & mask) {
|
2001-02-19 21:15:25 +00:00
|
|
|
view_clipplanes[i].next = pclip;
|
|
|
|
pclip = &view_clipplanes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// push the edges through
|
2001-02-19 21:15:25 +00:00
|
|
|
r_emitted = 0;
|
|
|
|
r_nearzi = 0;
|
|
|
|
r_nearzionly = false;
|
|
|
|
makeleftedge = makerightedge = false;
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: keep clipped bmodel edges in clockwise order so last vertex
|
|
|
|
// caching can be used?
|
2001-02-19 21:15:25 +00:00
|
|
|
r_lastvertvalid = false;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; pedges; pedges = pedges->pnext) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_leftclipped = r_rightclipped = false;
|
|
|
|
R_ClipEdge (pedges->v[0], pedges->v[1], pclip);
|
|
|
|
|
|
|
|
if (r_leftclipped)
|
|
|
|
makeleftedge = true;
|
|
|
|
if (r_rightclipped)
|
|
|
|
makerightedge = true;
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// if there was a clip off the left edge, add that edge too
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: faster to do in screen space?
|
|
|
|
// FIXME: share clipped edges?
|
2001-02-26 06:48:02 +00:00
|
|
|
if (makeleftedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &tedge;
|
|
|
|
R_ClipEdge (&r_leftexit, &r_leftenter, pclip->next);
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// if there was a clip off the right edge, get the right r_nearzi
|
2001-02-26 06:48:02 +00:00
|
|
|
if (makerightedge) {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &tedge;
|
|
|
|
r_nearzionly = true;
|
|
|
|
R_ClipEdge (&r_rightexit, &r_rightenter, view_clipplanes[1].next);
|
|
|
|
}
|
2001-05-15 21:13:07 +00:00
|
|
|
// if no edges made it out, return without posting the surface
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!r_emitted)
|
|
|
|
return;
|
|
|
|
|
|
|
|
r_polycount++;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
surface_p->data = (void *) psurf;
|
2001-02-19 21:15:25 +00:00
|
|
|
surface_p->nearzi = r_nearzi;
|
|
|
|
surface_p->flags = psurf->flags;
|
|
|
|
surface_p->insubmodel = true;
|
|
|
|
surface_p->spanstate = 0;
|
2022-03-11 07:39:08 +00:00
|
|
|
surface_p->entity = ent;
|
2001-02-19 21:15:25 +00:00
|
|
|
surface_p->key = r_currentbkey;
|
|
|
|
surface_p->spans = NULL;
|
|
|
|
|
|
|
|
pplane = psurf->plane;
|
|
|
|
// FIXME: cache this?
|
|
|
|
TransformVector (pplane->normal, p_normal);
|
|
|
|
// FIXME: cache this?
|
|
|
|
distinv = 1.0 / (pplane->dist - DotProduct (modelorg, pplane->normal));
|
|
|
|
|
|
|
|
surface_p->d_zistepu = p_normal[0] * xscaleinv * distinv;
|
|
|
|
surface_p->d_zistepv = -p_normal[1] * yscaleinv * distinv;
|
|
|
|
surface_p->d_ziorigin = p_normal[2] * distinv -
|
2001-02-26 06:48:02 +00:00
|
|
|
xcenter * surface_p->d_zistepu - ycenter * surface_p->d_zistepv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
surface_p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RenderPoly (entity_t *ent, msurface_t *fa, int clipflags)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, lindex, lnumverts, s_axis, t_axis;
|
|
|
|
float dist, lastdist, lzi, scale, u, v, frac;
|
2001-05-11 01:01:27 +00:00
|
|
|
unsigned int mask;
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t local, transformed;
|
|
|
|
clipplane_t *pclip;
|
|
|
|
medge_t *pedges;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2001-02-26 06:48:02 +00:00
|
|
|
mvertex_t verts[2][100]; // FIXME: do real number
|
|
|
|
polyvert_t pverts[100]; // FIXME: do real number, safely
|
|
|
|
int vertpage, newverts, newpage, lastvert;
|
|
|
|
qboolean visible;
|
2022-03-11 07:39:08 +00:00
|
|
|
mod_brush_t *brush = &ent->renderer.model->brush;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: clean this up and make it faster
|
|
|
|
// FIXME: guard against running out of vertices
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
s_axis = t_axis = 0; // keep compiler happy
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// set up clip planes
|
2001-02-19 21:15:25 +00:00
|
|
|
pclip = NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 3, mask = 0x08; i >= 0; i--, mask >>= 1) {
|
|
|
|
if (clipflags & mask) {
|
2001-02-19 21:15:25 +00:00
|
|
|
view_clipplanes[i].next = pclip;
|
|
|
|
pclip = &view_clipplanes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// reconstruct the polygon
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: these should be precalculated and loaded off disk
|
2021-02-01 10:31:11 +00:00
|
|
|
pedges = brush->edges;
|
2001-02-19 21:15:25 +00:00
|
|
|
lnumverts = fa->numedges;
|
|
|
|
vertpage = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnumverts; i++) {
|
2021-02-01 10:31:11 +00:00
|
|
|
lindex = brush->surfedges[fa->firstedge + i];
|
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
|
|
|
r_pedge = &pedges[lindex];
|
|
|
|
verts[0][i] = r_pcurrentvertbase[r_pedge->v[0]];
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
r_pedge = &pedges[-lindex];
|
|
|
|
verts[0][i] = r_pcurrentvertbase[r_pedge->v[1]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// clip the polygon, done if not visible
|
2001-02-26 06:48:02 +00:00
|
|
|
while (pclip) {
|
2001-02-19 21:15:25 +00:00
|
|
|
lastvert = lnumverts - 1;
|
|
|
|
lastdist = DotProduct (verts[vertpage][lastvert].position,
|
|
|
|
pclip->normal) - pclip->dist;
|
|
|
|
|
|
|
|
visible = false;
|
|
|
|
newverts = 0;
|
|
|
|
newpage = vertpage ^ 1;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnumverts; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dist = DotProduct (verts[vertpage][i].position, pclip->normal) -
|
2001-02-26 06:48:02 +00:00
|
|
|
pclip->dist;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((lastdist > 0) != (dist > 0)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
frac = dist / (dist - lastdist);
|
|
|
|
verts[newpage][newverts].position[0] =
|
2001-02-26 06:48:02 +00:00
|
|
|
verts[vertpage][i].position[0] +
|
|
|
|
((verts[vertpage][lastvert].position[0] -
|
|
|
|
verts[vertpage][i].position[0]) * frac);
|
2001-02-19 21:15:25 +00:00
|
|
|
verts[newpage][newverts].position[1] =
|
2001-02-26 06:48:02 +00:00
|
|
|
verts[vertpage][i].position[1] +
|
|
|
|
((verts[vertpage][lastvert].position[1] -
|
|
|
|
verts[vertpage][i].position[1]) * frac);
|
2001-02-19 21:15:25 +00:00
|
|
|
verts[newpage][newverts].position[2] =
|
2001-02-26 06:48:02 +00:00
|
|
|
verts[vertpage][i].position[2] +
|
|
|
|
((verts[vertpage][lastvert].position[2] -
|
|
|
|
verts[vertpage][i].position[2]) * frac);
|
2001-02-19 21:15:25 +00:00
|
|
|
newverts++;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (dist >= 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
verts[newpage][newverts] = verts[vertpage][i];
|
|
|
|
newverts++;
|
|
|
|
visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastvert = i;
|
|
|
|
lastdist = dist;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!visible || (newverts < 3))
|
|
|
|
return;
|
|
|
|
|
|
|
|
lnumverts = newverts;
|
|
|
|
vertpage ^= 1;
|
|
|
|
pclip = pclip->next;
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// transform and project, remembering the z values at the vertices and
|
|
|
|
// r_nearzi, and extract the s and t coordinates at the vertices
|
2001-02-19 21:15:25 +00:00
|
|
|
pplane = fa->plane;
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (pplane->type) {
|
2001-05-19 23:38:56 +00:00
|
|
|
case PLANE_X:
|
|
|
|
case PLANE_ANYX:
|
|
|
|
s_axis = 1;
|
|
|
|
t_axis = 2;
|
|
|
|
break;
|
|
|
|
case PLANE_Y:
|
|
|
|
case PLANE_ANYY:
|
|
|
|
s_axis = 0;
|
|
|
|
t_axis = 2;
|
|
|
|
break;
|
|
|
|
case PLANE_Z:
|
|
|
|
case PLANE_ANYZ:
|
|
|
|
s_axis = 0;
|
|
|
|
t_axis = 1;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
r_nearzi = 0;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < lnumverts; i++) {
|
|
|
|
// transform and project
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorSubtract (verts[vertpage][i].position, modelorg, local);
|
|
|
|
TransformVector (local, transformed);
|
|
|
|
|
|
|
|
if (transformed[2] < NEAR_CLIP)
|
|
|
|
transformed[2] = NEAR_CLIP;
|
|
|
|
|
|
|
|
lzi = 1.0 / transformed[2];
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lzi > r_nearzi) // for mipmap finding
|
2001-02-19 21:15:25 +00:00
|
|
|
r_nearzi = lzi;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// FIXME: build x/yscale into transform?
|
2001-02-19 21:15:25 +00:00
|
|
|
scale = xscale * lzi;
|
2001-02-26 06:48:02 +00:00
|
|
|
u = (xcenter + scale * transformed[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (u < r_refdef.fvrectx_adj)
|
|
|
|
u = r_refdef.fvrectx_adj;
|
|
|
|
if (u > r_refdef.fvrectright_adj)
|
|
|
|
u = r_refdef.fvrectright_adj;
|
|
|
|
|
|
|
|
scale = yscale * lzi;
|
2001-02-26 06:48:02 +00:00
|
|
|
v = (ycenter - scale * transformed[1]);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (v < r_refdef.fvrecty_adj)
|
|
|
|
v = r_refdef.fvrecty_adj;
|
|
|
|
if (v > r_refdef.fvrectbottom_adj)
|
|
|
|
v = r_refdef.fvrectbottom_adj;
|
|
|
|
|
|
|
|
pverts[i].u = u;
|
|
|
|
pverts[i].v = v;
|
|
|
|
pverts[i].zi = lzi;
|
|
|
|
pverts[i].s = verts[vertpage][i].position[s_axis];
|
|
|
|
pverts[i].t = verts[vertpage][i].position[t_axis];
|
|
|
|
}
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// build the polygon descriptor, including fa, r_nearzi, and u, v, s, t,
|
|
|
|
// and z for each vertex
|
2001-02-19 21:15:25 +00:00
|
|
|
r_polydesc.numverts = lnumverts;
|
|
|
|
r_polydesc.nearzi = r_nearzi;
|
|
|
|
r_polydesc.pcurrentface = fa;
|
|
|
|
r_polydesc.pverts = pverts;
|
|
|
|
|
2001-05-15 21:13:07 +00:00
|
|
|
// draw the polygon
|
2001-02-19 21:15:25 +00:00
|
|
|
D_DrawPoly ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2022-03-11 07:39:08 +00:00
|
|
|
R_ZDrawSubmodelPolys (entity_t *ent, model_t *model)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, numsurfaces;
|
|
|
|
msurface_t *psurf;
|
|
|
|
float dot;
|
2011-11-14 02:18:22 +00:00
|
|
|
plane_t *pplane;
|
2021-02-01 10:31:11 +00:00
|
|
|
mod_brush_t *brush = &model->brush;
|
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))) {
|
2001-08-28 22:46:02 +00:00
|
|
|
// FIXME: use bounding-box-based frustum clipping info?
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RenderPoly (ent, psurf, 15);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|