newtree/source/d_edge.c

332 lines
7.6 KiB
C
Raw Normal View History

/*
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
$Id$
*/
2000-05-10 11:29:38 +00:00
2000-05-17 10:03:19 +00:00
#ifdef HAVE_CONFIG_H
# include "config.h"
2000-05-17 10:03:19 +00:00
#endif
2000-12-30 02:16:36 +00:00
2000-05-10 11:29:38 +00:00
#include "d_local.h"
static int miplevel;
2000-05-10 11:29:38 +00:00
float scale_for_mip;
extern int screenwidth;
int ubasestep, errorterm, erroradjustup, erroradjustdown;
int vstartscan;
2000-05-10 11:29:38 +00:00
// FIXME: should go away
extern void R_RotateBmodel (void);
extern void R_TransformFrustum (void);
2000-05-10 11:29:38 +00:00
vec3_t transformed_modelorg;
2000-05-10 11:29:38 +00:00
/*
==============
D_DrawPoly
==============
*/
void
D_DrawPoly (void)
2000-05-10 11:29:38 +00:00
{
// this driver takes spans, not polygons
}
/*
=============
D_MipLevelForScale
=============
*/
int
D_MipLevelForScale (float scale)
2000-05-10 11:29:38 +00:00
{
int lmiplevel;
2000-05-10 11:29:38 +00:00
if (scale >= d_scalemip[0])
2000-05-10 11:29:38 +00:00
lmiplevel = 0;
else if (scale >= d_scalemip[1])
2000-05-10 11:29:38 +00:00
lmiplevel = 1;
else if (scale >= d_scalemip[2])
2000-05-10 11:29:38 +00:00
lmiplevel = 2;
else
lmiplevel = 3;
if (lmiplevel < d_minmip)
lmiplevel = d_minmip;
return lmiplevel;
}
/*
==============
D_DrawSolidSurface
==============
*/
// FIXME: clean this up
void
D_DrawSolidSurface (surf_t *surf, int color)
2000-05-10 11:29:38 +00:00
{
espan_t *span;
byte *pdest;
int u, u2, pix;
pix = (color << 24) | (color << 16) | (color << 8) | color;
for (span = surf->spans; span; span = span->pnext) {
pdest = (byte *) d_viewbuffer + screenwidth * span->v;
2000-05-10 11:29:38 +00:00
u = span->u;
u2 = span->u + span->count - 1;
((byte *) pdest)[u] = pix;
2000-05-10 11:29:38 +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;
2000-05-10 11:29:38 +00:00
u2 -= 4;
for (; u <= u2; u += 4)
*(int *) ((byte *) pdest + u) = pix;
2000-05-10 11:29:38 +00:00
u2 += 4;
for (; u <= u2; u++)
((byte *) pdest)[u] = pix;
2000-05-10 11:29:38 +00:00
}
}
}
/*
==============
D_CalcGradients
==============
*/
void
D_CalcGradients (msurface_t *pface)
2000-05-10 11:29:38 +00:00
{
mplane_t *pplane;
float mipscale;
vec3_t p_temp1;
vec3_t p_saxis, p_taxis;
float t;
2000-05-10 11:29:38 +00:00
pplane = pface->plane;
mipscale = 1.0 / (float) (1 << miplevel);
2000-05-10 11:29:38 +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 -
ycenter * d_sdivzstepv;
2000-05-10 11:29:38 +00:00
d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu -
ycenter * d_tdivzstepv;
2000-05-10 11:29:38 +00:00
VectorScale (transformed_modelorg, mipscale, p_temp1);
t = 0x10000 * mipscale;
sadjust = ((fixed16_t) (DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
((pface->texturemins[0] << 16) >> miplevel)
+ pface->texinfo->vecs[0][3] * t;
tadjust = ((fixed16_t) (DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
((pface->texturemins[1] << 16) >> miplevel)
+ pface->texinfo->vecs[1][3] * t;
2000-05-10 11:29:38 +00:00
//
// -1 (-epsilon) so we never wander off the edge of the texture
//
bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
}
/*
==============
D_DrawSurfaces
==============
*/
void
D_DrawSurfaces (void)
2000-05-10 11:29:38 +00:00
{
surf_t *s;
msurface_t *pface;
surfcache_t *pcurrentcache;
vec3_t world_transformed_modelorg;
vec3_t local_modelorg;
2000-05-10 11:29:38 +00:00
currententity = &r_worldentity;
TransformVector (modelorg, transformed_modelorg);
VectorCopy (transformed_modelorg, world_transformed_modelorg);
// TODO: could preset a lot of this at mode set time
if (r_drawflat->int_val) {
for (s = &surfaces[1]; s < surface_p; s++) {
2000-05-10 11:29:38 +00:00
if (!s->spans)
continue;
d_zistepu = s->d_zistepu;
d_zistepv = s->d_zistepv;
d_ziorigin = s->d_ziorigin;
D_DrawSolidSurface (s, (int) ((long) s->data & 0xFF));
2000-05-10 11:29:38 +00:00
D_DrawZSpans (s->spans);
}
} else {
for (s = &surfaces[1]; s < surface_p; s++) {
2000-05-10 11:29:38 +00:00
if (!s->spans)
continue;
r_drawnpolycount++;
d_zistepu = s->d_zistepu;
d_zistepv = s->d_zistepv;
d_ziorigin = s->d_ziorigin;
if (s->flags & SURF_DRAWSKY) {
if (!r_skymade) {
2000-05-10 11:29:38 +00:00
R_MakeSky ();
}
D_DrawSkyScans8 (s->spans);
D_DrawZSpans (s->spans);
} else if (s->flags & SURF_DRAWBACKGROUND) {
// set up a gradient for the background surface that places
// it
// effectively at infinity distance from the viewpoint
2000-05-10 11:29:38 +00:00
d_zistepu = 0;
d_zistepv = 0;
d_ziorigin = -0.9;
D_DrawSolidSurface (s, r_clearcolor->int_val & 0xFF);
2000-05-10 11:29:38 +00:00
D_DrawZSpans (s->spans);
} else if (s->flags & SURF_DRAWTURB) {
2000-05-10 11:29:38 +00:00
pface = s->data;
miplevel = 0;
cacheblock = (pixel_t *)
((byte *) pface->texinfo->texture +
pface->texinfo->texture->offsets[0]);
2000-05-10 11:29:38 +00:00
cachewidth = 64;
if (s->insubmodel) {
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
currententity = s->entity; // FIXME: make this passed in
// to
// R_RotateBmodel ()
2000-05-10 11:29:38 +00:00
VectorSubtract (r_origin, currententity->origin,
local_modelorg);
2000-05-10 11:29:38 +00:00
TransformVector (local_modelorg, transformed_modelorg);
R_RotateBmodel (); // FIXME: don't mess with the
// frustum,
// make entity passed in
2000-05-10 11:29:38 +00:00
}
D_CalcGradients (pface);
Turbulent8 (s->spans);
D_DrawZSpans (s->spans);
2000-05-10 11:29:38 +00:00
if (s->insubmodel) {
//
// restore the old drawing state
// FIXME: we don't want to do this every time!
// TODO: speed up
//
2000-05-10 11:29:38 +00:00
currententity = &r_worldentity;
VectorCopy (world_transformed_modelorg,
transformed_modelorg);
VectorCopy (base_vpn, vpn);
VectorCopy (base_vup, vup);
VectorCopy (base_vright, vright);
2000-05-10 11:29:38 +00:00
VectorCopy (base_modelorg, modelorg);
R_TransformFrustum ();
}
} else {
if (s->insubmodel) {
// FIXME: we don't want to do all this for every polygon!
// TODO: store once at start of frame
currententity = s->entity; // FIXME: make this passed in
// to
// R_RotateBmodel ()
VectorSubtract (r_origin, currententity->origin,
local_modelorg);
2000-05-10 11:29:38 +00:00
TransformVector (local_modelorg, transformed_modelorg);
R_RotateBmodel (); // FIXME: don't mess with the
// frustum,
// make entity passed in
2000-05-10 11:29:38 +00:00
}
pface = s->data;
miplevel = D_MipLevelForScale (s->nearzi * scale_for_mip
* pface->texinfo->mipadjust);
2000-05-10 11:29:38 +00:00
// FIXME: make this passed in to D_CacheSurface
2000-05-10 11:29:38 +00:00
pcurrentcache = D_CacheSurface (pface, miplevel);
cacheblock = (pixel_t *) pcurrentcache->data;
2000-05-10 11:29:38 +00:00
cachewidth = pcurrentcache->width;
D_CalcGradients (pface);
(*d_drawspans) (s->spans);
D_DrawZSpans (s->spans);
if (s->insubmodel) {
//
// restore the old drawing state
// FIXME: we don't want to do this every time!
// TODO: speed up
//
2000-05-10 11:29:38 +00:00
VectorCopy (world_transformed_modelorg,
transformed_modelorg);
VectorCopy (base_vpn, vpn);
VectorCopy (base_vup, vup);
VectorCopy (base_vright, vright);
VectorCopy (base_modelorg, modelorg);
2000-05-10 11:29:38 +00:00
R_TransformFrustum ();
currententity = &r_worldentity;
}
}
}
}
}