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-24 03:22:27 +00:00
|
|
|
pdest = d_viewbuffer + d_rowbytes * 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;
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
static void
|
|
|
|
transform_submodel_poly (surf_t *s)
|
|
|
|
{
|
|
|
|
// FIXME: we don't want to do all this for every polygon!
|
|
|
|
// TODO: store once at start of frame
|
2022-10-25 10:36:09 +00:00
|
|
|
vec4f_t *transform = SW_COMP(scene_sw_matrix, s->render_id);
|
|
|
|
vec4f_t local_modelorg = r_refdef.frame.position - transform[3];
|
[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
|
|
|
TransformVector ((vec_t*)&local_modelorg, transformed_modelorg);//FIXME
|
|
|
|
|
2022-10-25 10:36:09 +00:00
|
|
|
R_RotateBmodel (transform); // FIXME: don't mess with the
|
[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
|
|
|
// frustum, make entity passed in
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
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;
|
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;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
D_DrawSolidSurface (s, r_clearcolor & 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) {
|
[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
|
|
|
transform_submodel_poly (s);
|
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) {
|
[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
|
|
|
transform_submodel_poly (s);
|
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-10-25 10:36:09 +00:00
|
|
|
pcurrentcache = D_CacheSurface (s->render_id, 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 ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|