2001-08-25 02:47:11 +00:00
|
|
|
/*
|
|
|
|
d_edge.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
#define NH_DEFINE
|
|
|
|
#include "namehack.h"
|
2003-01-15 15:31:36 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/cvar.h"
|
2021-03-19 11:18:45 +00:00
|
|
|
#include "QF/entity.h"
|
2001-08-29 01:28:03 +00:00
|
|
|
#include "QF/render.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "d_local.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2012-02-17 07:13:56 +00:00
|
|
|
#include "vid_internal.h"
|
2021-07-10 15:09:41 +00:00
|
|
|
#include "vid_sw.h"
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2001-08-29 01:28:03 +00:00
|
|
|
static int miplevel;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
float sw32_scale_for_mip;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-21 05:10:20 +00:00
|
|
|
static vec3_t transformed_modelorg;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawPoly (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
// this driver takes spans, not polygons
|
|
|
|
}
|
|
|
|
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
int
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_MipLevelForScale (float scale)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
int lmiplevel;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (scale >= sw32_d_scalemip[0])
|
2001-08-25 02:47:11 +00:00
|
|
|
lmiplevel = 0;
|
2012-02-22 07:32:34 +00:00
|
|
|
else if (scale >= sw32_d_scalemip[1])
|
2001-08-25 02:47:11 +00:00
|
|
|
lmiplevel = 1;
|
2012-02-22 07:32:34 +00:00
|
|
|
else if (scale >= sw32_d_scalemip[2])
|
2001-08-25 02:47:11 +00:00
|
|
|
lmiplevel = 2;
|
|
|
|
else
|
|
|
|
lmiplevel = 3;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
if (lmiplevel < sw32_d_minmip)
|
|
|
|
lmiplevel = sw32_d_minmip;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
return lmiplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: clean this up
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
D_DrawSolidSurface (surf_t *surf, int color)
|
|
|
|
{
|
|
|
|
espan_t *span;
|
|
|
|
|
2021-07-10 15:09:41 +00:00
|
|
|
switch(sw32_ctx->pixbytes) {
|
2001-08-25 02:47:11 +00:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
byte *pdest, pix;
|
|
|
|
int u, u2;
|
|
|
|
|
|
|
|
pix = color;
|
|
|
|
for (span = surf->spans; span; span = span->pnext)
|
|
|
|
{
|
2012-02-22 07:32:34 +00:00
|
|
|
pdest = (byte *) sw32_d_viewbuffer + sw32_screenwidth * span->v;
|
2001-08-25 02:47:11 +00:00
|
|
|
u = span->u;
|
|
|
|
u2 = span->u + span->count - 1;
|
|
|
|
for (;u <= u2; u++)
|
|
|
|
pdest[u] = pix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
short *pdest, pix;
|
|
|
|
int u, u2;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
pix = sw32_8to16table[color];
|
2001-08-25 02:47:11 +00:00
|
|
|
for (span = surf->spans; span; span = span->pnext)
|
|
|
|
{
|
2012-02-22 07:32:34 +00:00
|
|
|
pdest = (short *) sw32_d_viewbuffer + sw32_screenwidth * span->v;
|
2001-08-25 02:47:11 +00:00
|
|
|
u = span->u;
|
|
|
|
u2 = span->u + span->count - 1;
|
|
|
|
for (;u <= u2; u++)
|
|
|
|
pdest[u] = pix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
int *pdest, pix;
|
|
|
|
int u, u2;
|
|
|
|
|
|
|
|
pix = d_8to24table[color];
|
|
|
|
for (span = surf->spans; span; span = span->pnext)
|
|
|
|
{
|
2012-02-22 07:32:34 +00:00
|
|
|
pdest = (int *) sw32_d_viewbuffer + sw32_screenwidth * span->v;
|
2001-08-25 02:47:11 +00:00
|
|
|
u = span->u;
|
|
|
|
u2 = span->u + span->count - 1;
|
|
|
|
for (;u <= u2; u++)
|
|
|
|
pdest[u] = pix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error("D_DrawSolidSurface: unsupported r_pixbytes %i",
|
2021-07-10 15:09:41 +00:00
|
|
|
sw32_ctx->pixbytes);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-08-25 02:47:11 +00:00
|
|
|
D_CalcGradients (msurface_t *pface)
|
|
|
|
{
|
|
|
|
float mipscale, t;
|
|
|
|
vec3_t p_temp1, p_saxis, p_taxis;
|
|
|
|
|
|
|
|
mipscale = 1.0 / (float) (1 << miplevel);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (pface->texinfo->vecs[0], p_saxis);
|
|
|
|
sw32_TransformVector (pface->texinfo->vecs[1], p_taxis);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
t = sw32_xscaleinv * mipscale;
|
|
|
|
sw32_d_sdivzstepu = p_saxis[0] * t;
|
|
|
|
sw32_d_tdivzstepu = p_taxis[0] * t;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
t = sw32_yscaleinv * mipscale;
|
|
|
|
sw32_d_sdivzstepv = -p_saxis[1] * t;
|
|
|
|
sw32_d_tdivzstepv = -p_taxis[1] * t;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_d_sdivzorigin = p_saxis[2] * mipscale -
|
|
|
|
sw32_xcenter * sw32_d_sdivzstepu -
|
|
|
|
sw32_ycenter * sw32_d_sdivzstepv;
|
|
|
|
sw32_d_tdivzorigin = p_taxis[2] * mipscale -
|
|
|
|
sw32_xcenter * sw32_d_tdivzstepu -
|
|
|
|
sw32_ycenter * sw32_d_tdivzstepv;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
VectorScale (transformed_modelorg, mipscale, p_temp1);
|
|
|
|
|
|
|
|
t = 0x10000 * mipscale;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_sadjust = ((fixed16_t) (DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
|
2001-08-29 01:28:03 +00:00
|
|
|
((pface->texturemins[0] << 16) >> miplevel)
|
|
|
|
+ pface->texinfo->vecs[0][3] * t;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_tadjust = ((fixed16_t) (DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
|
2001-08-29 01:28:03 +00:00
|
|
|
((pface->texturemins[1] << 16) >> miplevel)
|
|
|
|
+ pface->texinfo->vecs[1][3] * t;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
// -1 (-epsilon) so we never wander off the edge of the texture
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
|
|
|
|
sw32_bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
void
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawSurfaces (void)
|
2001-08-25 02:47:11 +00:00
|
|
|
{
|
|
|
|
surf_t *s;
|
|
|
|
msurface_t *pface;
|
|
|
|
surfcache_t *pcurrentcache;
|
2001-08-29 01:28:03 +00:00
|
|
|
vec3_t world_transformed_modelorg;
|
|
|
|
vec3_t local_modelorg;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
currententity = &r_worldentity;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (modelorg, transformed_modelorg);
|
2001-08-25 02:47:11 +00:00
|
|
|
VectorCopy (transformed_modelorg, world_transformed_modelorg);
|
|
|
|
|
|
|
|
// TODO: could preset a lot of this at mode set time
|
|
|
|
if (r_drawflat->int_val) {
|
2012-02-22 07:32:34 +00:00
|
|
|
for (s = &sw32_surfaces[1]; s < sw32_surface_p; s++) {
|
2001-08-25 02:47:11 +00:00
|
|
|
if (!s->spans)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
d_zistepu = s->d_zistepu;
|
|
|
|
d_zistepv = s->d_zistepv;
|
|
|
|
d_ziorigin = s->d_ziorigin;
|
|
|
|
|
2007-04-11 22:03:36 +00:00
|
|
|
D_DrawSolidSurface (s, ((intptr_t) s->data & 0xFF));
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawZSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-02-22 07:32:34 +00:00
|
|
|
for (s = &sw32_surfaces[1]; s < sw32_surface_p; s++) {
|
2001-08-25 02:47:11 +00:00
|
|
|
if (!s->spans)
|
|
|
|
continue;
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_r_drawnpolycount++;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
d_zistepu = s->d_zistepu;
|
|
|
|
d_zistepv = s->d_zistepv;
|
|
|
|
d_ziorigin = s->d_ziorigin;
|
|
|
|
|
|
|
|
if (s->flags & SURF_DRAWSKY) {
|
2012-02-22 07:32:34 +00:00
|
|
|
if (!sw32_r_skymade) {
|
|
|
|
sw32_R_MakeSky ();
|
2001-08-29 01:28:03 +00:00
|
|
|
}
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawSkyScans (s->spans);
|
|
|
|
sw32_D_DrawZSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
} else if (s->flags & SURF_DRAWBACKGROUND) {
|
|
|
|
// set up a gradient for the background surface that places
|
|
|
|
// it effectively at infinity distance from the viewpoint
|
|
|
|
d_zistepu = 0;
|
|
|
|
d_zistepv = 0;
|
|
|
|
d_ziorigin = -0.9;
|
|
|
|
|
|
|
|
D_DrawSolidSurface (s, r_clearcolor->int_val & 0xFF);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawZSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
} else if (s->flags & SURF_DRAWTURB) {
|
|
|
|
pface = s->data;
|
|
|
|
miplevel = 0;
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_cacheblock = ((byte *) pface->texinfo->texture +
|
2001-08-29 01:28:03 +00:00
|
|
|
pface->texinfo->texture->offsets[0]);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_cachewidth = 64;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (s->insubmodel) {
|
|
|
|
// FIXME: we don't want to do all this for every polygon!
|
|
|
|
// TODO: store once at start of frame
|
2012-05-21 23:23:22 +00:00
|
|
|
currententity = s->entity; // FIXME: make this passed in
|
2012-02-22 07:32:34 +00:00
|
|
|
// to sw32_R_RotateBmodel ()
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_origin,
|
|
|
|
Transform_GetWorldPosition (currententity->transform),
|
2001-08-25 02:47:11 +00:00
|
|
|
local_modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (local_modelorg, transformed_modelorg);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RotateBmodel (); // FIXME: don't mess with the
|
2001-08-25 02:47:11 +00:00
|
|
|
// frustum, make entity passed in
|
|
|
|
}
|
|
|
|
|
|
|
|
D_CalcGradients (pface);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_Turbulent (s->spans);
|
|
|
|
sw32_D_DrawZSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (s->insubmodel) {
|
|
|
|
// restore the old drawing state
|
|
|
|
// FIXME: we don't want to do this every time!
|
|
|
|
// TODO: speed up
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
currententity = &r_worldentity;
|
|
|
|
VectorCopy (world_transformed_modelorg,
|
|
|
|
transformed_modelorg);
|
|
|
|
VectorCopy (base_vpn, vpn);
|
|
|
|
VectorCopy (base_vup, vup);
|
|
|
|
VectorCopy (base_vright, vright);
|
|
|
|
VectorCopy (base_modelorg, modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformFrustum ();
|
2001-08-25 02:47:11 +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
|
2012-05-21 23:23:22 +00:00
|
|
|
currententity = s->entity; // FIXME: make this passed in
|
2012-02-22 07:32:34 +00:00
|
|
|
// to sw32_R_RotateBmodel ()
|
2021-03-19 11:18:45 +00:00
|
|
|
VectorSubtract (r_origin,
|
|
|
|
Transform_GetWorldPosition (currententity->transform),
|
2001-08-25 02:47:11 +00:00
|
|
|
local_modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_TransformVector (local_modelorg, transformed_modelorg);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_RotateBmodel (); // FIXME: don't mess with the
|
2001-08-25 02:47:11 +00:00
|
|
|
// frustum, make entity passed in
|
|
|
|
}
|
|
|
|
|
|
|
|
pface = s->data;
|
2012-02-22 07:32:34 +00:00
|
|
|
miplevel = sw32_D_MipLevelForScale (s->nearzi * sw32_scale_for_mip
|
2001-08-25 02:47:11 +00:00
|
|
|
* pface->texinfo->mipadjust);
|
|
|
|
|
|
|
|
// FIXME: make this passed in to D_CacheSurface
|
2012-02-22 07:32:34 +00:00
|
|
|
pcurrentcache = sw32_D_CacheSurface (pface, miplevel);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_cacheblock = (byte *) pcurrentcache->data;
|
|
|
|
sw32_cachewidth = pcurrentcache->width;
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
D_CalcGradients (pface);
|
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_D_DrawZSpans (s->spans);
|
2001-08-25 02:47:11 +00:00
|
|
|
|
|
|
|
if (s->insubmodel) {
|
|
|
|
// restore the old drawing state
|
|
|
|
// FIXME: we don't want to do this every time!
|
|
|
|
// TODO: speed up
|
2001-08-29 01:28:03 +00:00
|
|
|
|
2001-08-25 02:47:11 +00:00
|
|
|
VectorCopy (world_transformed_modelorg,
|
|
|
|
transformed_modelorg);
|
|
|
|
VectorCopy (base_vpn, vpn);
|
|
|
|
VectorCopy (base_vup, vup);
|
|
|
|
VectorCopy (base_vright, vright);
|
|
|
|
VectorCopy (base_modelorg, modelorg);
|
2012-02-22 07:32:34 +00:00
|
|
|
sw32_R_TransformFrustum ();
|
2001-08-25 02:47:11 +00:00
|
|
|
currententity = &r_worldentity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|