2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
d_scan.c
|
|
|
|
|
|
|
|
Portable C scan-level rasterization code, all pixel depths.
|
|
|
|
|
|
|
|
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-08-16 06:58:55 +00:00
|
|
|
#include "QF/render.h"
|
2021-07-10 09:04:34 +00:00
|
|
|
#include "QF/ui/view.h"
|
2001-08-16 06:58:55 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "d_local.h"
|
2012-02-14 08:28:09 +00:00
|
|
|
#include "r_internal.h"
|
2022-03-24 03:22:27 +00:00
|
|
|
#include "vid_sw.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-29 02:16:17 +00:00
|
|
|
byte *r_turb_pbase;
|
|
|
|
byte *r_turb_pdest;
|
2001-02-19 21:15:25 +00:00
|
|
|
fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
|
|
|
|
int *r_turb_turb;
|
|
|
|
int r_turb_spancount;
|
|
|
|
|
|
|
|
/*
|
|
|
|
D_WarpScreen
|
|
|
|
|
|
|
|
this performs a slight compression of the screen at the same time as
|
|
|
|
the sine warp, to keep the edges from wrapping
|
|
|
|
*/
|
|
|
|
void
|
2022-03-25 15:29:34 +00:00
|
|
|
D_WarpScreen (framebuffer_t *src)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2022-03-25 15:29:34 +00:00
|
|
|
sw_framebuffer_t *buffer = src->buffer;
|
2001-02-19 21:15:25 +00:00
|
|
|
int w, h;
|
|
|
|
int u, v;
|
2022-10-31 15:40:52 +00:00
|
|
|
int scr_x = vr_data.refdef->vrect.x;
|
|
|
|
int scr_y = vr_data.refdef->vrect.y;
|
|
|
|
int scr_w = vr_data.refdef->vrect.width;
|
|
|
|
int scr_h = vr_data.refdef->vrect.height;
|
2001-02-19 21:15:25 +00:00
|
|
|
byte *dest;
|
|
|
|
int *turb;
|
|
|
|
int *col;
|
|
|
|
byte **row;
|
2022-03-25 15:29:34 +00:00
|
|
|
byte *color = buffer->color;
|
|
|
|
int rowbytes = buffer->rowbytes;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2002-11-23 05:47:17 +00:00
|
|
|
/* FIXME: allocate these arrays properly */
|
2009-12-20 05:34:41 +00:00
|
|
|
byte *rowptr[MAXHEIGHT + AMP2 * 2];
|
|
|
|
int column[MAXWIDTH + AMP2 * 2];
|
2001-02-19 21:15:25 +00:00
|
|
|
float wratio, hratio;
|
|
|
|
|
|
|
|
w = r_refdef.vrect.width;
|
|
|
|
h = r_refdef.vrect.height;
|
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
wratio = w / (float) scr_w;
|
|
|
|
hratio = h / (float) scr_h;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
for (v = 0; v < scr_h + AMP2 * 2; v++) {
|
2022-03-25 15:29:34 +00:00
|
|
|
rowptr[v] = color + (0*r_refdef.vrect.y * rowbytes) +
|
2022-03-24 03:22:27 +00:00
|
|
|
(d_rowbytes * (int) ((float) v * hratio * h / (h + AMP2 * 2)));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 09:04:34 +00:00
|
|
|
for (u = 0; u < scr_w + AMP2 * 2; u++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
column[u] = r_refdef.vrect.x +
|
|
|
|
(int) ((float) u * wratio * w / (w + AMP2 * 2));
|
|
|
|
}
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
turb = intsintable + ((int) (vr_data.realtime * SPEED) & (CYCLE - 1));
|
2022-03-25 15:29:34 +00:00
|
|
|
dest = d_viewbuffer + scr_y * d_rowbytes + scr_x;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2022-03-25 15:29:34 +00:00
|
|
|
for (v = 0; v < scr_h; v++, dest += d_rowbytes) {
|
2001-02-19 21:15:25 +00:00
|
|
|
col = &column[turb[v]];
|
|
|
|
row = &rowptr[v];
|
2021-07-10 09:04:34 +00:00
|
|
|
for (u = 0; u < scr_w; u += 4) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dest[u + 0] = row[turb[u + 0]][col[u + 0]];
|
|
|
|
dest[u + 1] = row[turb[u + 1]][col[u + 1]];
|
|
|
|
dest[u + 2] = row[turb[u + 2]][col[u + 2]];
|
|
|
|
dest[u + 3] = row[turb[u + 3]][col[u + 3]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-02-19 21:15:25 +00:00
|
|
|
#ifndef USE_INTEL_ASM
|
|
|
|
void
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawTurbulent8Span (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int sturb, tturb;
|
|
|
|
|
|
|
|
do {
|
|
|
|
sturb =
|
|
|
|
((r_turb_s + r_turb_turb[(r_turb_t >> 16) & (CYCLE - 1)]) >> 16) &
|
|
|
|
63;
|
|
|
|
tturb =
|
|
|
|
((r_turb_t + r_turb_turb[(r_turb_s >> 16) & (CYCLE - 1)]) >> 16) &
|
|
|
|
63;
|
|
|
|
*r_turb_pdest++ = *(r_turb_pbase + (tturb << 6) + sturb);
|
|
|
|
r_turb_s += r_turb_sstep;
|
|
|
|
r_turb_t += r_turb_tstep;
|
|
|
|
} while (--r_turb_spancount > 0);
|
|
|
|
}
|
|
|
|
#endif // !USE_INTEL_ASM
|
|
|
|
|
|
|
|
void
|
2001-08-25 02:47:11 +00:00
|
|
|
Turbulent (espan_t *pspan)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
fixed16_t snext, tnext;
|
|
|
|
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
|
|
|
|
float sdivz16stepu, tdivz16stepu, zi16stepu;
|
|
|
|
|
2012-02-14 08:28:09 +00:00
|
|
|
r_turb_turb = sintable + ((int) (vr_data.realtime * SPEED) & (CYCLE - 1));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_turb_sstep = 0; // keep compiler happy
|
|
|
|
r_turb_tstep = 0; // ditto
|
|
|
|
|
2001-08-29 02:16:17 +00:00
|
|
|
r_turb_pbase = (byte *) cacheblock;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
sdivz16stepu = d_sdivzstepu * 16;
|
|
|
|
tdivz16stepu = d_tdivzstepu * 16;
|
|
|
|
zi16stepu = d_zistepu * 16;
|
|
|
|
|
|
|
|
do {
|
2022-03-24 03:22:27 +00:00
|
|
|
r_turb_pdest = d_viewbuffer + (d_rowbytes * pspan->v) + pspan->u;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
count = pspan->count;
|
|
|
|
|
|
|
|
// calculate the initial s/z, t/z, 1/z, s, and t and clamp
|
|
|
|
du = (float) pspan->u;
|
|
|
|
dv = (float) pspan->v;
|
|
|
|
|
|
|
|
sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
|
|
|
|
tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
|
|
|
|
zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
|
|
|
|
r_turb_s = (int) (sdivz * z) + sadjust;
|
|
|
|
if (r_turb_s > bbextents)
|
|
|
|
r_turb_s = bbextents;
|
|
|
|
else if (r_turb_s < 0)
|
|
|
|
r_turb_s = 0;
|
|
|
|
|
|
|
|
r_turb_t = (int) (tdivz * z) + tadjust;
|
|
|
|
if (r_turb_t > bbextentt)
|
|
|
|
r_turb_t = bbextentt;
|
|
|
|
else if (r_turb_t < 0)
|
|
|
|
r_turb_t = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// calculate s and t at the far end of the span
|
|
|
|
if (count >= 16)
|
|
|
|
r_turb_spancount = 16;
|
|
|
|
else
|
|
|
|
r_turb_spancount = count;
|
|
|
|
|
|
|
|
count -= r_turb_spancount;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
// calculate s/z, t/z, zi->fixed s and t at far end of span,
|
|
|
|
// calculate s and t steps across span by shifting
|
|
|
|
sdivz += sdivz16stepu;
|
|
|
|
tdivz += tdivz16stepu;
|
|
|
|
zi += zi16stepu;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
|
|
|
|
snext = (int) (sdivz * z) + sadjust;
|
|
|
|
if (snext > bbextents)
|
|
|
|
snext = bbextents;
|
|
|
|
else if (snext < 16)
|
|
|
|
snext = 16; // prevent round-off error on <0
|
|
|
|
// steps from
|
|
|
|
// from causing overstepping & running off the
|
|
|
|
// edge of the texture
|
|
|
|
|
|
|
|
tnext = (int) (tdivz * z) + tadjust;
|
|
|
|
if (tnext > bbextentt)
|
|
|
|
tnext = bbextentt;
|
|
|
|
else if (tnext < 16)
|
|
|
|
tnext = 16; // guard against round-off error on
|
|
|
|
// <0 steps
|
|
|
|
|
|
|
|
r_turb_sstep = (snext - r_turb_s) >> 4;
|
|
|
|
r_turb_tstep = (tnext - r_turb_t) >> 4;
|
|
|
|
} else {
|
|
|
|
// calculate s/z, t/z, zi->fixed s and t at last pixel in
|
2001-05-15 17:38:43 +00:00
|
|
|
// span (so can't step off polygon), clamp, calculate s and t
|
|
|
|
// steps across span by division, biasing steps low so we
|
|
|
|
// don't run off the texture
|
2001-02-19 21:15:25 +00:00
|
|
|
spancountminus1 = (float) (r_turb_spancount - 1);
|
|
|
|
sdivz += d_sdivzstepu * spancountminus1;
|
|
|
|
tdivz += d_tdivzstepu * spancountminus1;
|
|
|
|
zi += d_zistepu * spancountminus1;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
snext = (int) (sdivz * z) + sadjust;
|
|
|
|
if (snext > bbextents)
|
|
|
|
snext = bbextents;
|
|
|
|
else if (snext < 16)
|
2001-05-15 17:38:43 +00:00
|
|
|
snext = 16; // prevent round-off error on <0 steps
|
|
|
|
// from causing overstepping & running
|
|
|
|
// off the edge of the texture
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
tnext = (int) (tdivz * z) + tadjust;
|
|
|
|
if (tnext > bbextentt)
|
|
|
|
tnext = bbextentt;
|
|
|
|
else if (tnext < 16)
|
|
|
|
tnext = 16; // guard against round-off error on
|
|
|
|
// <0 steps
|
|
|
|
|
|
|
|
if (r_turb_spancount > 1) {
|
|
|
|
r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
|
|
|
|
r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r_turb_s = r_turb_s & ((CYCLE << 16) - 1);
|
|
|
|
r_turb_t = r_turb_t & ((CYCLE << 16) - 1);
|
|
|
|
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawTurbulent8Span ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
r_turb_s = snext;
|
|
|
|
r_turb_t = tnext;
|
|
|
|
|
|
|
|
} while (count > 0);
|
|
|
|
|
|
|
|
} while ((pspan = pspan->pnext) != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef USE_INTEL_ASM
|
|
|
|
void
|
2022-03-09 11:19:14 +00:00
|
|
|
D_DrawSpans8 (espan_t *pspan)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
int count, spancount;
|
2022-03-21 14:15:14 +00:00
|
|
|
byte *pbase, *pdest;
|
2001-02-19 21:15:25 +00:00
|
|
|
fixed16_t s, t, snext, tnext, sstep, tstep;
|
|
|
|
float sdivz, tdivz, zi, z, du, dv, spancountminus1;
|
|
|
|
float sdivz8stepu, tdivz8stepu, zi8stepu;
|
|
|
|
|
|
|
|
sstep = 0; // keep compiler happy
|
|
|
|
tstep = 0; // ditto
|
|
|
|
|
|
|
|
pbase = (unsigned char *) cacheblock;
|
|
|
|
|
|
|
|
sdivz8stepu = d_sdivzstepu * 8;
|
|
|
|
tdivz8stepu = d_tdivzstepu * 8;
|
|
|
|
zi8stepu = d_zistepu * 8;
|
|
|
|
|
|
|
|
do {
|
2022-03-24 03:22:27 +00:00
|
|
|
pdest = d_viewbuffer + (d_rowbytes * pspan->v) + pspan->u;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
count = pspan->count;
|
|
|
|
|
|
|
|
// calculate the initial s/z, t/z, 1/z, s, and t and clamp
|
|
|
|
du = (float) pspan->u;
|
|
|
|
dv = (float) pspan->v;
|
|
|
|
|
|
|
|
sdivz = d_sdivzorigin + dv * d_sdivzstepv + du * d_sdivzstepu;
|
|
|
|
tdivz = d_tdivzorigin + dv * d_tdivzstepv + du * d_tdivzstepu;
|
|
|
|
zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
|
|
|
|
s = (int) (sdivz * z) + sadjust;
|
|
|
|
if (s > bbextents)
|
|
|
|
s = bbextents;
|
|
|
|
else if (s < 0)
|
|
|
|
s = 0;
|
|
|
|
|
|
|
|
t = (int) (tdivz * z) + tadjust;
|
|
|
|
if (t > bbextentt)
|
|
|
|
t = bbextentt;
|
|
|
|
else if (t < 0)
|
|
|
|
t = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
// calculate s and t at the far end of the span
|
|
|
|
if (count >= 8)
|
|
|
|
spancount = 8;
|
|
|
|
else
|
|
|
|
spancount = count;
|
|
|
|
|
|
|
|
count -= spancount;
|
|
|
|
|
|
|
|
if (count) {
|
|
|
|
// calculate s/z, t/z, zi->fixed s and t at far end of span,
|
|
|
|
// calculate s and t steps across span by shifting
|
|
|
|
sdivz += sdivz8stepu;
|
|
|
|
tdivz += tdivz8stepu;
|
|
|
|
zi += zi8stepu;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
|
|
|
|
snext = (int) (sdivz * z) + sadjust;
|
|
|
|
if (snext > bbextents)
|
|
|
|
snext = bbextents;
|
|
|
|
else if (snext < 8)
|
|
|
|
snext = 8; // prevent round-off error on <0
|
|
|
|
// steps from
|
|
|
|
// from causing overstepping & running off the
|
|
|
|
// edge of the texture
|
|
|
|
|
|
|
|
tnext = (int) (tdivz * z) + tadjust;
|
|
|
|
if (tnext > bbextentt)
|
|
|
|
tnext = bbextentt;
|
|
|
|
else if (tnext < 8)
|
|
|
|
tnext = 8; // guard against round-off error on
|
|
|
|
// <0 steps
|
|
|
|
|
|
|
|
sstep = (snext - s) >> 3;
|
|
|
|
tstep = (tnext - t) >> 3;
|
|
|
|
} else {
|
2001-05-15 17:38:43 +00:00
|
|
|
// calculate s/z, t/z, zi->fixed s and t at last pixel in span
|
|
|
|
// (so can't step off polygon), clamp, calculate s and t steps
|
|
|
|
// across span by division, biasing steps low so we don't run
|
|
|
|
// off the texture
|
2001-02-19 21:15:25 +00:00
|
|
|
spancountminus1 = (float) (spancount - 1);
|
|
|
|
sdivz += d_sdivzstepu * spancountminus1;
|
|
|
|
tdivz += d_tdivzstepu * spancountminus1;
|
|
|
|
zi += d_zistepu * spancountminus1;
|
|
|
|
z = (float) 0x10000 / zi; // prescale to 16.16 fixed-point
|
|
|
|
snext = (int) (sdivz * z) + sadjust;
|
|
|
|
if (snext > bbextents)
|
|
|
|
snext = bbextents;
|
|
|
|
else if (snext < 8)
|
2001-05-15 17:38:43 +00:00
|
|
|
snext = 8; // prevent round-off error on <0 steps
|
|
|
|
// from from causing overstepping &
|
|
|
|
// running off the edge of the texture
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
tnext = (int) (tdivz * z) + tadjust;
|
|
|
|
if (tnext > bbextentt)
|
|
|
|
tnext = bbextentt;
|
|
|
|
else if (tnext < 8)
|
|
|
|
tnext = 8; // guard against round-off error on
|
|
|
|
// <0 steps
|
|
|
|
|
|
|
|
if (spancount > 1) {
|
|
|
|
sstep = (snext - s) / (spancount - 1);
|
|
|
|
tstep = (tnext - t) / (spancount - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
*pdest++ = *(pbase + (s >> 16) + (t >> 16) * cachewidth);
|
|
|
|
s += sstep;
|
|
|
|
t += tstep;
|
|
|
|
} while (--spancount > 0);
|
|
|
|
|
|
|
|
s = snext;
|
|
|
|
t = tnext;
|
|
|
|
|
|
|
|
} while (count > 0);
|
|
|
|
|
|
|
|
} while ((pspan = pspan->pnext) != NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef USE_INTEL_ASM
|
|
|
|
void
|
|
|
|
D_DrawZSpans (espan_t *pspan)
|
|
|
|
{
|
|
|
|
int count, doublecount, izistep;
|
|
|
|
int izi;
|
|
|
|
short *pdest;
|
|
|
|
unsigned int ltemp;
|
|
|
|
double zi;
|
|
|
|
float du, dv;
|
|
|
|
|
2001-08-29 02:16:17 +00:00
|
|
|
// FIXME: check for clamping/range problems
|
|
|
|
// we count on FP exceptions being turned off to avoid range problems
|
2001-02-19 21:15:25 +00:00
|
|
|
izistep = (int) (d_zistepu * 0x8000 * 0x10000);
|
|
|
|
|
|
|
|
do {
|
2022-03-21 14:11:09 +00:00
|
|
|
pdest = d_zbuffer + (d_zwidth * pspan->v) + pspan->u;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
count = pspan->count;
|
|
|
|
|
|
|
|
// calculate the initial 1/z
|
|
|
|
du = (float) pspan->u;
|
|
|
|
dv = (float) pspan->v;
|
|
|
|
|
|
|
|
zi = d_ziorigin + dv * d_zistepv + du * d_zistepu;
|
|
|
|
// we count on FP exceptions being turned off to avoid range problems
|
|
|
|
izi = (int) (zi * 0x8000 * 0x10000);
|
|
|
|
|
2007-04-11 22:03:36 +00:00
|
|
|
if ((intptr_t) pdest & 0x02) {
|
2001-02-19 21:15:25 +00:00
|
|
|
*pdest++ = (short) (izi >> 16);
|
|
|
|
izi += izistep;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((doublecount = count >> 1) > 0) {
|
|
|
|
do {
|
|
|
|
ltemp = izi >> 16;
|
|
|
|
izi += izistep;
|
|
|
|
ltemp |= izi & 0xFFFF0000;
|
|
|
|
izi += izistep;
|
|
|
|
*(int *) pdest = ltemp;
|
|
|
|
pdest += 2;
|
|
|
|
} while (--doublecount > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count & 1)
|
|
|
|
*pdest = (short) (izi >> 16);
|
|
|
|
|
|
|
|
} while ((pspan = pspan->pnext) != NULL);
|
|
|
|
}
|
|
|
|
#endif
|