2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
d_edge.c
|
|
|
|
|
2001-05-18 20:19:20 +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-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/render.h"
|
|
|
|
|
2021-07-24 05:19:52 +00:00
|
|
|
#include "QF/scene/entity.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "d_local.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int miplevel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
float scale_for_mip;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t transformed_modelorg;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_DrawPoly (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// this driver takes spans, not polygons
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
D_MipLevelForScale (float scale)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int lmiplevel;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (scale >= d_scalemip[0])
|
2001-02-19 21:15:25 +00:00
|
|
|
lmiplevel = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (scale >= d_scalemip[1])
|
2001-02-19 21:15:25 +00:00
|
|
|
lmiplevel = 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
else if (scale >= d_scalemip[2])
|
2001-02-19 21:15:25 +00:00
|
|
|
lmiplevel = 2;
|
|
|
|
else
|
|
|
|
lmiplevel = 3;
|
|
|
|
|
|
|
|
if (lmiplevel < d_minmip)
|
|
|
|
lmiplevel = d_minmip;
|
|
|
|
|
|
|
|
return lmiplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: clean this up
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2022-03-09 11:19:14 +00:00
|
|
|
static void
|
|
|
|
D_DrawSolidSurface (surf_t *surf, int color)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-03-09 11:19:14 +00:00
|
|
|
espan_t *span;
|
2001-02-26 06:48:02 +00:00
|
|
|
byte *pdest;
|
|
|
|
int u, u2, pix;
|
|
|
|
|
|
|
|
pix = (color << 24) | (color << 16) | (color << 8) | color;
|
2022-03-09 11:19:14 +00:00
|
|
|
for (span = surf->spans; span; span = span->pnext) {
|
2022-03-21 14:15:14 +00:00
|
|
|
pdest = d_viewbuffer + screenwidth * span->v;
|
2001-02-19 21:15:25 +00:00
|
|
|
u = span->u;
|
|
|
|
u2 = span->u + span->count - 1;
|
2001-02-26 06:48:02 +00:00
|
|
|
((byte *) pdest)[u] = pix;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (u2 - u < 8) {
|
|
|
|
for (u++; u <= u2; u++)
|
|
|
|
((byte *) pdest)[u] = pix;
|
|
|
|
} else {
|
|
|
|
for (u++; u & 3; u++)
|
|
|
|
((byte *) pdest)[u] = pix;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
u2 -= 4;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; u <= u2; u += 4)
|
|
|
|
*(int *) ((byte *) pdest + u) = pix;
|
2001-02-19 21:15:25 +00:00
|
|
|
u2 += 4;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; u <= u2; u++)
|
|
|
|
((byte *) pdest)[u] = pix;
|
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
|
|
|
D_CalcGradients (msurface_t *pface)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-29 01:28:03 +00:00
|
|
|
float mipscale, t;
|
|
|
|
vec3_t p_temp1, p_saxis, p_taxis;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
mipscale = 1.0 / (float) (1 << miplevel);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
TransformVector (pface->texinfo->vecs[0], p_saxis);
|
|
|
|
TransformVector (pface->texinfo->vecs[1], p_taxis);
|
|
|
|
|
|
|
|
t = xscaleinv * mipscale;
|
|
|
|
d_sdivzstepu = p_saxis[0] * t;
|
|
|
|
d_tdivzstepu = p_taxis[0] * t;
|
|
|
|
|
|
|
|
t = yscaleinv * mipscale;
|
|
|
|
d_sdivzstepv = -p_saxis[1] * t;
|
|
|
|
d_tdivzstepv = -p_taxis[1] * t;
|
|
|
|
|
|
|
|
d_sdivzorigin = p_saxis[2] * mipscale - xcenter * d_sdivzstepu -
|
2001-02-26 06:48:02 +00:00
|
|
|
ycenter * d_sdivzstepv;
|
2001-02-19 21:15:25 +00:00
|
|
|
d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu -
|
2001-02-26 06:48:02 +00:00
|
|
|
ycenter * d_tdivzstepv;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VectorScale (transformed_modelorg, mipscale, p_temp1);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
t = 0x10000 * mipscale;
|
|
|
|
sadjust = ((fixed16_t) (DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
|
|
|
|
((pface->texturemins[0] << 16) >> miplevel)
|
2001-08-29 01:28:03 +00:00
|
|
|
+ pface->texinfo->vecs[0][3] * t;
|
2001-02-26 06:48:02 +00:00
|
|
|
tadjust = ((fixed16_t) (DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
|
|
|
|
((pface->texturemins[1] << 16) >> miplevel)
|
2001-08-29 01:28:03 +00:00
|
|
|
+ pface->texinfo->vecs[1][3] * t;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-15 17:38:43 +00:00
|
|
|
// -1 (-epsilon) so we never wander off the edge of the texture
|
2001-02-19 21:15:25 +00:00
|
|
|
bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
|
|
|
|
bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
D_DrawSurfaces (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
surf_t *s;
|
|
|
|
msurface_t *pface;
|
|
|
|
surfcache_t *pcurrentcache;
|
|
|
|
vec3_t world_transformed_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
|
|
|
vec4f_t local_modelorg;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
TransformVector (modelorg, transformed_modelorg);
|
|
|
|
VectorCopy (transformed_modelorg, world_transformed_modelorg);
|
|
|
|
|
2001-05-18 20:19:20 +00:00
|
|
|
// TODO: could preset a lot of this at mode set time
|
2022-03-09 13:51:21 +00:00
|
|
|
if (r_refdef.drawflat) {
|
2001-02-26 06:48:02 +00:00
|
|
|
for (s = &surfaces[1]; s < surface_p; s++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!s->spans)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d_zistepu = s->d_zistepu;
|
|
|
|
d_zistepv = s->d_zistepv;
|
|
|
|
d_ziorigin = s->d_ziorigin;
|
|
|
|
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawSolidSurface (s, ((size_t) s->data & 0xFF));
|
2001-02-19 21:15:25 +00:00
|
|
|
D_DrawZSpans (s->spans);
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
for (s = &surfaces[1]; s < surface_p; s++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!s->spans)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
r_drawnpolycount++;
|
|
|
|
|
|
|
|
d_zistepu = s->d_zistepu;
|
|
|
|
d_zistepv = s->d_zistepv;
|
|
|
|
d_ziorigin = s->d_ziorigin;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (s->flags & SURF_DRAWSKY) {
|
|
|
|
if (!r_skymade) {
|
2022-03-09 11:19:14 +00:00
|
|
|
R_MakeSky ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawSkyScans (s->spans);
|
2001-02-19 21:15:25 +00:00
|
|
|
D_DrawZSpans (s->spans);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (s->flags & SURF_DRAWBACKGROUND) {
|
|
|
|
// set up a gradient for the background surface that places
|
2001-08-29 01:28:03 +00:00
|
|
|
// it effectively at infinity distance from the viewpoint
|
2001-02-19 21:15:25 +00:00
|
|
|
d_zistepu = 0;
|
|
|
|
d_zistepv = 0;
|
|
|
|
d_ziorigin = -0.9;
|
|
|
|
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawSolidSurface (s, r_clearcolor->int_val & 0xFF);
|
2001-02-19 21:15:25 +00:00
|
|
|
D_DrawZSpans (s->spans);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (s->flags & SURF_DRAWTURB) {
|
2001-02-19 21:15:25 +00:00
|
|
|
pface = s->data;
|
|
|
|
miplevel = 0;
|
2001-08-25 02:47:11 +00:00
|
|
|
cacheblock = ((byte *) pface->texinfo->texture +
|
|
|
|
pface->texinfo->texture->offsets[0]);
|
2001-02-19 21:15:25 +00:00
|
|
|
cachewidth = 64;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (s->insubmodel) {
|
|
|
|
// FIXME: we don't want to do all this for every polygon!
|
|
|
|
// TODO: store once at start of frame
|
2022-03-11 07:39:08 +00:00
|
|
|
transform_t *transform = s->entity->transform;
|
|
|
|
transform = s->entity->transform;
|
[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
|
|
|
local_modelorg = r_refdef.frame.position -
|
|
|
|
Transform_GetWorldPosition (transform);
|
|
|
|
TransformVector (&local_modelorg[0], transformed_modelorg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RotateBmodel (transform); // FIXME: don't mess with the
|
2001-05-15 17:38:43 +00:00
|
|
|
// frustum, make entity passed in
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
D_CalcGradients (pface);
|
2001-05-18 20:19:20 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
Turbulent (s->spans);
|
2001-02-19 21:15:25 +00:00
|
|
|
D_DrawZSpans (s->spans);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (s->insubmodel) {
|
|
|
|
// restore the old drawing state
|
|
|
|
// FIXME: we don't want to do this every time!
|
|
|
|
// TODO: speed up
|
2001-05-15 17:38:43 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (world_transformed_modelorg,
|
|
|
|
transformed_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
|
|
|
VectorCopy (base_vfwd, vfwd);
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (base_vup, vup);
|
|
|
|
VectorCopy (base_vright, vright);
|
|
|
|
VectorCopy (base_modelorg, modelorg);
|
|
|
|
R_TransformFrustum ();
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
|
|
|
if (s->insubmodel) {
|
|
|
|
// FIXME: we don't want to do all this for every polygon!
|
|
|
|
// TODO: store once at start of frame
|
2022-03-11 07:39:08 +00:00
|
|
|
transform_t *transform = s->entity->transform;
|
[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
|
|
|
local_modelorg = r_refdef.frame.position -
|
|
|
|
Transform_GetWorldPosition (transform);
|
|
|
|
TransformVector (&local_modelorg[0], transformed_modelorg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-11 07:39:08 +00:00
|
|
|
R_RotateBmodel (transform); // FIXME: don't mess with the
|
2001-05-15 17:38:43 +00:00
|
|
|
// frustum, make entity passed in
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pface = s->data;
|
|
|
|
miplevel = D_MipLevelForScale (s->nearzi * scale_for_mip
|
2001-02-26 06:48:02 +00:00
|
|
|
* pface->texinfo->mipadjust);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// FIXME: make this passed in to D_CacheSurface
|
2022-03-11 07:39:08 +00:00
|
|
|
pcurrentcache = D_CacheSurface (s->entity, pface, miplevel);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
cacheblock = (byte *) pcurrentcache->data;
|
2001-02-19 21:15:25 +00:00
|
|
|
cachewidth = pcurrentcache->width;
|
|
|
|
|
|
|
|
D_CalcGradients (pface);
|
|
|
|
|
|
|
|
(*d_drawspans) (s->spans);
|
|
|
|
|
|
|
|
D_DrawZSpans (s->spans);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (s->insubmodel) {
|
|
|
|
// restore the old drawing state
|
|
|
|
// FIXME: we don't want to do this every time!
|
|
|
|
// TODO: speed up
|
2001-05-15 17:38:43 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (world_transformed_modelorg,
|
|
|
|
transformed_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
|
|
|
VectorCopy (base_vfwd, vfwd);
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (base_vup, vup);
|
|
|
|
VectorCopy (base_vright, vright);
|
|
|
|
VectorCopy (base_modelorg, modelorg);
|
|
|
|
R_TransformFrustum ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|