ref: f64250f9c3b1376064cd214c36064044c98b117e
parent: 047a4434851525bc448af3b5e3461b62605c8ed1
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Jan 8 10:36:41 EST 2024
move more stuff out of dvars
--- a/d_edge.c
+++ b/d_edge.c
@@ -32,8 +32,8 @@
int u, u2;
for(span = surf->spans; span; span=span->pnext){
- pdest = dvars.viewbuffer + span->v*dvars.width;
- pz = dvars.zbuffer + span->v*dvars.width;
+ pdest = dvars.fb + span->v*dvars.w;
+ pz = dvars.zb + span->v*dvars.w;
memset(pz, 0xfe, span->count*sizeof(*pz));
u2 = span->u + span->count - 1;
for(u = span->u; u <= u2; u++)
@@ -43,7 +43,7 @@
static void
-D_CalcGradients(int miplevel, msurface_t *pface, vec3_t transformed_modelorg, view_t *v)
+D_CalcGradients(int miplevel, msurface_t *pface, vec3_t transformed_modelorg, view_t *v, texvars_t *tv)
{
vec3_t p_temp1, p_saxis, p_taxis;
float mipscale;
@@ -51,34 +51,34 @@
mipscale = 1.0 / (float)(1 << miplevel);
- TransformVector (pface->texinfo->vecs[0], p_saxis, v);
- TransformVector (pface->texinfo->vecs[1], p_taxis, v);
+ TransformVector(pface->texinfo->vecs[0], p_saxis, v);
+ TransformVector(pface->texinfo->vecs[1], p_taxis, v);
t = xscaleinv * mipscale;
- dvars.sdivzstepu = p_saxis[0] * t;
- dvars.tdivzstepu = p_taxis[0] * t;
+ tv->s.divz.stepu = p_saxis[0] * t;
+ tv->t.divz.stepu = p_taxis[0] * t;
t = yscaleinv * mipscale;
- dvars.sdivzstepv = -p_saxis[1] * t;
- dvars.tdivzstepv = -p_taxis[1] * t;
+ tv->s.divz.stepv = -p_saxis[1] * t;
+ tv->t.divz.stepv = -p_taxis[1] * t;
- dvars.sdivzorigin = p_saxis[2] * mipscale - xcenter * dvars.sdivzstepu - ycenter * dvars.sdivzstepv;
- dvars.tdivzorigin = p_taxis[2] * mipscale - xcenter * dvars.tdivzstepu - ycenter * dvars.tdivzstepv;
+ tv->s.divz.origin = p_saxis[2] * mipscale - xcenter * tv->s.divz.stepu - ycenter * tv->s.divz.stepv;
+ tv->t.divz.origin = p_taxis[2] * mipscale - xcenter * tv->t.divz.stepu - ycenter * tv->t.divz.stepv;
- VectorScale (transformed_modelorg, mipscale, p_temp1);
+ VectorScale(transformed_modelorg, mipscale, p_temp1);
t = 0x10000*mipscale;
- dvars.sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
+ tv->s.adjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
((pface->texturemins[0] << 16) >> miplevel)
+ pface->texinfo->vecs[0][3]*t;
- dvars.tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
+ tv->t.adjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
((pface->texturemins[1] << 16) >> miplevel)
+ pface->texinfo->vecs[1][3]*t;
// -1 (-epsilon) so we never wander off the edge of the texture
- dvars.bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
- dvars.bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
+ tv->s.bbextent = ((pface->extents[0] << 16) >> miplevel) - 1;
+ tv->t.bbextent = ((pface->extents[1] << 16) >> miplevel) - 1;
}
void
@@ -89,6 +89,7 @@
msurface_t *pface;
int miplevel;
entity_t *e;
+ texvars_t t;
surf_t *s;
byte alpha;
bool blend;
@@ -116,9 +117,9 @@
blend = (s->flags & SURF_FENCE) || (r_drawflags & DRAW_BLEND);
- dvars.zistepu = s->d_zistepu;
- dvars.zistepv = s->d_zistepv;
- dvars.ziorigin = s->d_ziorigin;
+ t.z.stepu = s->d_zistepu;
+ t.z.stepv = s->d_zistepv;
+ t.z.origin = s->d_ziorigin;
if(insubmodel(s)){
VectorSubtract(v.org, e->origin, local_modelorg);
@@ -132,8 +133,10 @@
}else if(s->flags & SURF_DRAWBACKGROUND){
D_DrawSolidSurface(s, q1pal[(int)r_clearcolor.value & 0xFF]);
}else if(s->flags & SURF_DRAWTURB){
- D_CalcGradients(0, pface, transformed_modelorg, &v);
- D_DrawSpans(s->spans, pface->texinfo->texture->pixels, 64, alpha, SPAN_TURB);
+ t.p = pface->texinfo->texture->pixels;
+ t.w = 64;
+ D_CalcGradients(0, pface, transformed_modelorg, &v, &t);
+ D_DrawSpans(s->spans, &t, alpha, SPAN_TURB);
}else{
miplevel = D_MipLevelForScale(s->nearzi * scale_for_mip * pface->texinfo->mipadjust);
if(s->flags & SURF_FENCE)
@@ -140,8 +143,10 @@
miplevel = max(miplevel-1, 0);
pcurrentcache = D_CacheSurface(s->entity, pface, miplevel);
- D_CalcGradients(miplevel, pface, transformed_modelorg, &v);
- D_DrawSpans(s->spans, pcurrentcache->pixels, pcurrentcache->width, alpha,
+ t.p = pcurrentcache->pixels;
+ t.w = pcurrentcache->width;
+ D_CalcGradients(miplevel, pface, transformed_modelorg, &v, &t);
+ D_DrawSpans(s->spans, &t, alpha,
(alpha == 255 && s->flags & SURF_FENCE) ? SPAN_FENCE : (blend ? SPAN_BLEND : SPAN_SOLID)
);
}
--- a/d_init.c
+++ b/d_init.c
@@ -29,8 +29,8 @@
r_turb_turb = sintable + ((int)(cl.time*SPEED)&(CYCLE-1));
- dvars.viewbuffer = r_dowarp ? r_warpbuffer : vid.buffer;
- dvars.width = vid.width;
+ dvars.fb = r_dowarp ? r_warpbuffer : vid.buffer;
+ dvars.w = vid.width;
d_roverwrapped = false;
d_initial_rover = sc_rover;
--- a/d_local.h
+++ b/d_local.h
@@ -7,16 +7,30 @@
};
typedef struct {
- pixel_t *cacheblock;
- pixel_t *viewbuffer;
- uzint *zbuffer;
- unsigned width;
- unsigned cachewidth;
- fixed16_t sadjust, tadjust;
- fixed16_t bbextents, bbextentt;
- float sdivzstepu, tdivzstepu, zistepu;
- float sdivzstepv, tdivzstepv, zistepv;
- float sdivzorigin, tdivzorigin, ziorigin;
+ struct {
+ float stepu;
+ float stepv;
+ float origin;
+ }divz;
+ fixed16_t adjust;
+ fixed16_t bbextent;
+}tavars_t;
+
+typedef struct {
+ pixel_t *p;
+ unsigned w;
+ tavars_t s, t;
+ struct {
+ float stepu;
+ float stepv;
+ float origin;
+ }z;
+}texvars_t;
+
+typedef struct {
+ pixel_t *fb;
+ uzint *zb;
+ unsigned w;
}dvars_t;
typedef struct {
@@ -65,7 +79,7 @@
SPAN_TURB,
};
-void D_DrawSpans(espan_t *pspan, pixel_t *pbase, int width, byte alpha, int spanfunc);
+void D_DrawSpans(espan_t *pspan, texvars_t *t, byte alpha, int spanfunc);
void D_DrawSkyScans8 (espan_t *pspan);
--- a/d_modech.c
+++ b/d_modech.c
@@ -22,11 +22,11 @@
d_vrecty = r_refdef.vrect.y;
d_vrectright_particle = r_refdef.vrectright - d_pix_max;
d_vrectbottom_particle = r_refdef.vrectbottom - d_pix_max;
- dvars.width = vid.width;
+ dvars.w = vid.width;
for(i = 0; i < vid.height; i++){
- d_scantable[i] = i * dvars.width;
- zspantable[i] = dvars.zbuffer + i*dvars.width;
+ d_scantable[i] = i * dvars.w;
+ zspantable[i] = dvars.zb + i*dvars.w;
}
}
--- a/d_part.c
+++ b/d_part.c
@@ -35,8 +35,8 @@
return;
}
- pz = dvars.zbuffer + v*dvars.width + u;
- pdest = dvars.viewbuffer + d_scantable[v] + u;
+ pz = dvars.zb + v*dvars.w + u;
+ pdest = dvars.fb + d_scantable[v] + u;
izi = zi * 0x8000 * 0x10000;
zi = 1024.0 * d_pix_scale / Length(local);
@@ -45,7 +45,7 @@
pix = 1;
color = pparticle->color;
- for(count = pix; count; count--, pz += dvars.width, pdest += dvars.width){
+ for(count = pix; count; count--, pz += dvars.w, pdest += dvars.w){
for(i = 0; i < pix; i++){
if(pz[i] <= izi){
pz[i] = izi;
--- a/d_polyse.c
+++ b/d_polyse.c
@@ -123,9 +123,9 @@
pixel_t p = addlight(currententity, skintable[fv->t >> 16][fv->s >> 16], fv->l[0], fv->l[1], fv->l[2]);
int n = d_scantable[fv->v] + fv->u;
if(r_drawflags & DRAW_BLEND){
- dvars.viewbuffer[n] = blendalpha(p, dvars.viewbuffer[n], alpha);
+ dvars.fb[n] = blendalpha(p, dvars.fb[n], alpha);
}else{
- dvars.viewbuffer[n] = p;
+ dvars.fb[n] = p;
*zbuf = z;
}
}
@@ -311,9 +311,9 @@
pixel_t p = addlight(currententity, skintable[new.t >> 16][new.s >> 16], l[0], l[1], l[2]);
int n = d_scantable[new.v] + new.u;
if(r_drawflags & DRAW_BLEND){
- dvars.viewbuffer[n] = blendalpha(p, dvars.viewbuffer[n], alpha);
+ dvars.fb[n] = blendalpha(p, dvars.fb[n], alpha);
}else{
- dvars.viewbuffer[n] = p;
+ dvars.fb[n] = p;
*zbuf = z;
}
}
@@ -627,8 +627,8 @@
d_light[1] = plefttop->l[1];
d_light[2] = plefttop->l[2];
- d_pdest = dvars.viewbuffer + ystart * dvars.width + plefttop->u;
- d_pz = dvars.zbuffer + ystart * dvars.width + plefttop->u;
+ d_pdest = dvars.fb + ystart * dvars.w + plefttop->u;
+ d_pz = dvars.zb + ystart * dvars.w + plefttop->u;
if (initialleftheight == 1)
{
@@ -653,7 +653,7 @@
D_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
pleftbottom->u, pleftbottom->v);
- d_pdestbasestep = d_pzbasestep = dvars.width + ubasestep;
+ d_pdestbasestep = d_pzbasestep = dvars.w + ubasestep;
d_pzextrastep = d_pzbasestep + 1;
d_pdestextrastep = d_pdestbasestep + 1;
@@ -718,8 +718,8 @@
d_light[1] = plefttop->l[1];
d_light[2] = plefttop->l[2];
- d_pdest = dvars.viewbuffer + ystart * dvars.width + plefttop->u;
- d_pz = dvars.zbuffer + ystart * dvars.width + plefttop->u;
+ d_pdest = dvars.fb + ystart * dvars.w + plefttop->u;
+ d_pz = dvars.zb + ystart * dvars.w + plefttop->u;
if (height == 1)
{
@@ -742,7 +742,7 @@
D_PolysetSetUpForLineScan(plefttop->u, plefttop->v,
pleftbottom->u, pleftbottom->v);
- d_pzbasestep = d_pdestbasestep = dvars.width + ubasestep;
+ d_pzbasestep = d_pdestbasestep = dvars.w + ubasestep;
d_pdestextrastep = d_pdestbasestep + 1;
d_pzextrastep = d_pzbasestep + 1;
--- a/d_scan.c
+++ b/d_scan.c
@@ -28,7 +28,7 @@
hratio = h / (float)scr_vrect.height;
for(v = 0; v < scr_vrect.height+AMP2*2; v++)
- rowptr[v] = dvars.viewbuffer + (r_refdef.vrect.y * dvars.width) + (dvars.width * (int)((float)v * hratio * h / (h + AMP2 * 2)));
+ rowptr[v] = dvars.fb + (r_refdef.vrect.y * dvars.w) + (dvars.w * (int)((float)v * hratio * h / (h + AMP2 * 2)));
for(u = 0; u < scr_vrect.width+AMP2*2; u++)
column[u] = r_refdef.vrect.x + (int)((float)u * wratio * w / (w + AMP2 * 2));
@@ -63,13 +63,13 @@
if((int)(us*m) != 0 || (int)(vs*m) != 0)
return s;
s++;
- }while(m < (int)dvars.width);
+ }while(m < (int)dvars.w);
return s;
}
void
-D_DrawSpans(espan_t *pspan, pixel_t *pbase, int width, byte alpha, int spanfunc)
+D_DrawSpans(espan_t *pspan, texvars_t *tv, byte alpha, int spanfunc)
{
int count, spancount, izistep, spancountminus1, spanshift, spanmax;
pixel_t *pdest;
@@ -84,20 +84,20 @@
tstep = 0; // ditto
memset(&fog, 0, sizeof(fog));
- spanshift = D_DrawSpanGetMax(dvars.zistepu, dvars.zistepv);
+ spanshift = D_DrawSpanGetMax(tv->z.stepu, tv->z.stepv);
spanmax = 1 << spanshift;
- sdivzstepu = dvars.sdivzstepu * spanmax;
- tdivzstepu = dvars.tdivzstepu * spanmax;
- zistepu = dvars.zistepu * spanmax;
- izistep = (int)(dvars.zistepu * 0x8000 * 0x10000);
+ sdivzstepu = tv->s.divz.stepu * spanmax;
+ tdivzstepu = tv->t.divz.stepu * spanmax;
+ zistepu = tv->z.stepu * spanmax;
+ izistep = (int)(tv->z.stepu * 0x8000 * 0x10000);
fogenabled = isfogged();
do{
- pdest = dvars.viewbuffer + pspan->v*dvars.width + pspan->u;
- pz = dvars.zbuffer + pspan->v*dvars.width + pspan->u;
- zi = dvars.ziorigin + pspan->v*dvars.zistepv + pspan->u*dvars.zistepu;
+ pdest = dvars.fb + pspan->v*dvars.w + pspan->u;
+ pz = dvars.zb + pspan->v*dvars.w + pspan->u;
+ zi = tv->z.origin + pspan->v*tv->z.stepv + pspan->u*tv->z.stepu;
izi = zi * 0x8000 * 0x10000;
count = pspan->count;
@@ -105,15 +105,15 @@
du = pspan->u;
dv = pspan->v;
- sdivz = dvars.sdivzorigin + dv*dvars.sdivzstepv + du*dvars.sdivzstepu;
- tdivz = dvars.tdivzorigin + dv*dvars.tdivzstepv + du*dvars.tdivzstepu;
+ sdivz = tv->s.divz.origin + dv*tv->s.divz.stepv + du*tv->s.divz.stepu;
+ tdivz = tv->t.divz.origin + dv*tv->t.divz.stepv + du*tv->t.divz.stepu;
z = (float)(1<<16) / zi; // prescale to 16.16 fixed-point
- s = (int)(sdivz * z) + dvars.sadjust;
- s = clamp(s, 0, dvars.bbextents);
+ s = (int)(sdivz * z) + tv->s.adjust;
+ s = clamp(s, 0, tv->s.bbextent);
- t = (int)(tdivz * z) + dvars.tadjust;
- t = clamp(t, 0, dvars.bbextentt);
+ t = (int)(tdivz * z) + tv->t.adjust;
+ t = clamp(t, 0, tv->t.bbextent);
do{
// calculate s and t at the far end of the span
@@ -129,15 +129,15 @@
// prescale to 16.16 fixed-point
z = (float)(1<<16) / (zi + zistepu);
- snext = (int)(sdivz * z) + dvars.sadjust;
+ snext = (int)(sdivz * z) + tv->s.adjust;
// prevent round-off error on <0 steps from
// causing overstepping & running off the
// edge of the texture
- snext = clamp(snext, spanmax, dvars.bbextents);
+ snext = clamp(snext, spanmax, tv->s.bbextent);
- tnext = (int)(tdivz * z) + dvars.tadjust;
+ tnext = (int)(tdivz * z) + tv->t.adjust;
// guard against round-off error on <0 steps
- tnext = clamp(tnext, spanmax, dvars.bbextentt);
+ tnext = clamp(tnext, spanmax, tv->t.bbextent);
sstep = (snext - s) >> spanshift;
tstep = (tnext - t) >> spanshift;
@@ -147,19 +147,19 @@
// span by division, biasing steps low so we don't run off the
// texture
spancountminus1 = spancount - 1;
- sdivz += dvars.sdivzstepu * spancountminus1;
- tdivz += dvars.tdivzstepu * spancountminus1;
+ sdivz += tv->s.divz.stepu * spancountminus1;
+ tdivz += tv->t.divz.stepu * spancountminus1;
// prescale to 16.16 fixed-point
- z = (float)(1<<16) / (zi + dvars.zistepu * spancountminus1);
- snext = (int)(sdivz * z) + dvars.sadjust;
+ z = (float)(1<<16) / (zi + tv->z.stepu * spancountminus1);
+ snext = (int)(sdivz * z) + tv->s.adjust;
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
- snext = clamp(snext, spanmax, dvars.bbextents);
+ snext = clamp(snext, spanmax, tv->s.bbextent);
- tnext = (int)(tdivz * z) + dvars.tadjust;
+ tnext = (int)(tdivz * z) + tv->t.adjust;
// guard against round-off error on <0 steps
- tnext = clamp(tnext, spanmax, dvars.bbextentt);
+ tnext = clamp(tnext, spanmax, tv->t.bbextent);
if(spancount > 1){
sstep = (snext - s) / spancountminus1;
@@ -167,7 +167,7 @@
}
}
- pixel_t *pdest_ = pdest, *pbase_ = pbase;
+ pixel_t *pdest_ = pdest, *pbase = tv->p;
uzint *pz_ = pz;
fog_t *fog_ = &fog;
int spancount_ = spancount, izi_ = izi;
@@ -174,31 +174,31 @@
if(fogged){
switch(spanfunc){
case SPAN_SOLID:
- dospan_solid_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep, fog_);
+ dospan_solid_f1(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, pz_, izi_, izistep, fog_);
break;
case SPAN_TURB:
- dospan_turb_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep, fog_);
+ dospan_turb_f1(pdest_, pbase, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep, fog_);
break;
case SPAN_BLEND:
- dospan_blend_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, alpha, pz_, izi_, izistep, fog_);
+ dospan_blend_f1(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, alpha, pz_, izi_, izistep, fog_);
break;
case SPAN_FENCE:
- dospan_fence_f1(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep, fog_);
+ dospan_fence_f1(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, pz_, izi_, izistep, fog_);
break;
}
}else{
switch(spanfunc){
case SPAN_SOLID:
- dospan_solid(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep);
+ dospan_solid(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, pz_, izi_, izistep);
break;
case SPAN_TURB:
- dospan_turb(pdest_, pbase_, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep);
+ dospan_turb(pdest_, pbase, s, t, sstep, tstep, spancount_, alpha, pz_, izi_, izistep);
break;
case SPAN_BLEND:
- dospan_blend(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, alpha, pz_, izi_, izistep);
+ dospan_blend(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, alpha, pz_, izi_, izistep);
break;
case SPAN_FENCE:
- dospan_fence(pdest_, pbase_, s, t, sstep, tstep, spancount_, width, pz_, izi_, izistep);
+ dospan_fence(pdest_, pbase, s, t, sstep, tstep, spancount_, tv->w, pz_, izi_, izistep);
break;
}
}
--- a/d_sky.c
+++ b/d_sky.c
@@ -57,9 +57,9 @@
do
{
- pdest = dvars.viewbuffer + pspan->v*dvars.width + pspan->u;
+ pdest = dvars.fb + pspan->v*dvars.w + pspan->u;
count = pspan->count;
- pz = dvars.zbuffer + pspan->v*dvars.width + pspan->u;
+ pz = dvars.zb + pspan->v*dvars.w + pspan->u;
memset(pz, 0xff, count*sizeof(*pz));
// calculate the initial s & t
--- a/d_sprite.c
+++ b/d_sprite.c
@@ -10,7 +10,7 @@
=====================
*/
static void
-D_SpriteDrawSpans(sspan_t *pspan, byte alpha)
+D_SpriteDrawSpans(sspan_t *pspan, texvars_t *tv, byte alpha)
{
int count, spancount, izistep;
int izi;
@@ -23,24 +23,21 @@
sstep = 0; // keep compiler happy
tstep = 0; // ditto
- pbase = dvars.cacheblock;
+ pbase = tv->p;
- sdivz8stepu = dvars.sdivzstepu * 8;
- tdivz8stepu = dvars.tdivzstepu * 8;
- zi8stepu = dvars.zistepu * 8;
+ sdivz8stepu = tv->s.divz.stepu * 8;
+ tdivz8stepu = tv->t.divz.stepu * 8;
+ zi8stepu = tv->z.stepu * 8;
// we count on FP exceptions being turned off to avoid range problems
- izistep = (int)(dvars.zistepu * 0x8000 * 0x10000);
+ izistep = (int)(tv->z.stepu * 0x8000 * 0x10000);
- if(pspan->v < 0){
- fprintf(stderr, "%d %d %d %p\n", dvars.width, pspan->v, pspan->u, dvars.zbuffer + dvars.width * pspan->v + pspan->u);
- return;
- }
+ assert(pspan->v >= 0);
do
{
- pdest = dvars.viewbuffer + dvars.width * pspan->v + pspan->u;
- pz = dvars.zbuffer + dvars.width * pspan->v + pspan->u;
+ pdest = dvars.fb + dvars.w * pspan->v + pspan->u;
+ pz = dvars.zb + dvars.w * pspan->v + pspan->u;
count = pspan->count;
@@ -51,18 +48,18 @@
du = (float)pspan->u;
dv = (float)pspan->v;
- sdivz = dvars.sdivzorigin + dv*dvars.sdivzstepv + du*dvars.sdivzstepu;
- tdivz = dvars.tdivzorigin + dv*dvars.tdivzstepv + du*dvars.tdivzstepu;
- zi = dvars.ziorigin + dv*dvars.zistepv + du*dvars.zistepu;
+ sdivz = tv->s.divz.origin + dv*tv->s.divz.stepv + du*tv->s.divz.stepu;
+ tdivz = tv->t.divz.origin + dv*tv->t.divz.stepv + du*tv->t.divz.stepu;
+ zi = tv->z.origin + dv*tv->z.stepv + du*tv->z.stepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
// we count on FP exceptions being turned off to avoid range problems
izi = (int)(zi * 0x8000 * 0x10000);
- s = (int)(sdivz * z) + dvars.sadjust;
- s = clamp(s, 0, dvars.bbextents);
+ s = (int)(sdivz * z) + tv->s.adjust;
+ s = clamp(s, 0, tv->s.bbextent);
- t = (int)(tdivz * z) + dvars.tadjust;
- t = clamp(t, 0, dvars.bbextentt);
+ t = (int)(tdivz * z) + tv->t.adjust;
+ t = clamp(t, 0, tv->t.bbextent);
do
{
@@ -78,14 +75,14 @@
zi += zi8stepu;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
- snext = (int)(sdivz * z) + dvars.sadjust;
- snext = clamp(snext, 8, dvars.bbextents);
+ snext = (int)(sdivz * z) + tv->s.adjust;
+ snext = clamp(snext, 8, tv->s.bbextent);
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
- tnext = (int)(tdivz * z) + dvars.tadjust;
- tnext = clamp(tnext, 8, dvars.bbextentt); // guard against round-off error on <0 steps
+ tnext = (int)(tdivz * z) + tv->t.adjust;
+ tnext = clamp(tnext, 8, tv->t.bbextent); // guard against round-off error on <0 steps
sstep = (snext - s) >> 3;
tstep = (tnext - t) >> 3;
@@ -97,18 +94,18 @@
// span by division, biasing steps low so we don't run off the
// texture
spancountminus1 = (float)(spancount - 1);
- sdivz += dvars.sdivzstepu * spancountminus1;
- tdivz += dvars.tdivzstepu * spancountminus1;
- zi += dvars.zistepu * spancountminus1;
+ sdivz += tv->s.divz.stepu * spancountminus1;
+ tdivz += tv->t.divz.stepu * spancountminus1;
+ zi += tv->z.stepu * spancountminus1;
z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
- snext = (int)(sdivz * z) + dvars.sadjust;
- snext = clamp(snext, 8, dvars.bbextents);
+ snext = (int)(sdivz * z) + tv->s.adjust;
+ snext = clamp(snext, 8, tv->s.bbextent);
// prevent round-off error on <0 steps from
// from causing overstepping & running off the
// edge of the texture
- tnext = (int)(tdivz * z) + dvars.tadjust;
- tnext = clamp(tnext, 8, dvars.bbextentt); // guard against round-off error on <0 steps
+ tnext = (int)(tdivz * z) + tv->t.adjust;
+ tnext = clamp(tnext, 8, tv->t.bbextent); // guard against round-off error on <0 steps
if(spancount > 1){
sstep = (snext - s) / (spancount - 1);
@@ -118,7 +115,7 @@
do
{
- btemp = *(pbase + (s >> 16) + (t >> 16) * dvars.cachewidth);
+ btemp = *(pbase + (s >> 16) + (t >> 16) * tv->w);
if(opaque(btemp) && *pz <= izi){
if(r_drawflags & DRAW_BLEND){
*pdest = blendalpha(btemp, *pdest, alpha);
@@ -297,7 +294,7 @@
=====================
*/
static void
-D_SpriteCalculateGradients(view_t *v)
+D_SpriteCalculateGradients(view_t *v, texvars_t *tv)
{
vec3_t p_normal, p_saxis, p_taxis, p_temp1;
float distinv;
@@ -309,27 +306,27 @@
distinv = 1.0 / (-DotProduct (v->modelorg, r_spritedesc.vpn));
- dvars.sdivzstepu = p_saxis[0] * xscaleinv;
- dvars.tdivzstepu = p_taxis[0] * xscaleinv;
+ tv->s.divz.stepu = p_saxis[0] * xscaleinv;
+ tv->t.divz.stepu = p_taxis[0] * xscaleinv;
- dvars.sdivzstepv = -p_saxis[1] * yscaleinv;
- dvars.tdivzstepv = -p_taxis[1] * yscaleinv;
+ tv->s.divz.stepv = -p_saxis[1] * yscaleinv;
+ tv->t.divz.stepv = -p_taxis[1] * yscaleinv;
- dvars.zistepu = p_normal[0] * xscaleinv * distinv;
- dvars.zistepv = -p_normal[1] * yscaleinv * distinv;
+ tv->z.stepu = p_normal[0] * xscaleinv * distinv;
+ tv->z.stepv = -p_normal[1] * yscaleinv * distinv;
- dvars.sdivzorigin = p_saxis[2] - xcenter*dvars.sdivzstepu - ycenter*dvars.sdivzstepv;
- dvars.tdivzorigin = p_taxis[2] - xcenter*dvars.tdivzstepu - ycenter*dvars.tdivzstepv;
- dvars.ziorigin = p_normal[2]*distinv - xcenter*dvars.zistepu - ycenter*dvars.zistepv;
+ tv->s.divz.origin = p_saxis[2] - xcenter*tv->s.divz.stepu - ycenter*tv->s.divz.stepv;
+ tv->t.divz.origin = p_taxis[2] - xcenter*tv->t.divz.stepu - ycenter*tv->t.divz.stepv;
+ tv->z.origin = p_normal[2]*distinv - xcenter*tv->z.stepu - ycenter*tv->z.stepv;
TransformVector (v->modelorg, p_temp1, v);
- dvars.sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) - (-(dvars.cachewidth >> 1) << 16);
- dvars.tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) - (-(sprite_height >> 1) << 16);
+ tv->s.adjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) - (-(tv->w >> 1) << 16);
+ tv->t.adjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) - (-(sprite_height >> 1) << 16);
// -1 (-epsilon) so we never wander off the edge of the texture
- dvars.bbextents = (dvars.cachewidth << 16) - 1;
- dvars.bbextentt = (sprite_height << 16) - 1;
+ tv->s.bbextent = (tv->w << 16) - 1;
+ tv->t.bbextent = (sprite_height << 16) - 1;
}
@@ -345,6 +342,7 @@
float ymin, ymax;
emitpoint_t *pverts;
static sspan_t spans[MAXHEIGHT+1];
+ texvars_t tv;
sprite_spans = spans;
@@ -377,9 +375,9 @@
if (ymin >= ymax)
return; // doesn't cross any scans at all
- dvars.cachewidth = r_spritedesc.pspriteframe->width;
+ tv.w = r_spritedesc.pspriteframe->width;
+ tv.p = r_spritedesc.pspriteframe->pixels;
sprite_height = r_spritedesc.pspriteframe->height;
- dvars.cacheblock = &r_spritedesc.pspriteframe->pixels[0];
// copy the first vertex to the last vertex, so we don't have to deal with
// wrapping
@@ -387,8 +385,8 @@
pverts = r_spritedesc.pverts;
pverts[nump] = pverts[0];
- D_SpriteCalculateGradients(v);
+ D_SpriteCalculateGradients(v, &tv);
D_SpriteScanLeftEdge();
D_SpriteScanRightEdge();
- D_SpriteDrawSpans(sprite_spans, currententity->alpha);
+ D_SpriteDrawSpans(sprite_spans, &tv, currententity->alpha);
}
--- a/vid_plan9.c
+++ b/vid_plan9.c
@@ -36,17 +36,17 @@
vid.width = clamp(vid.width, 320, MAXWIDTH);
vid.height = clamp(vid.height, 240, MAXHEIGHT);
- if(dvars.zbuffer != nil)
+ if(dvars.zb != nil)
D_FlushCaches();
// alloc an extra line in case we want to wrap, and allocate the z-buffer
- hunkvbuf = vid.width * vid.height * sizeof(*dvars.zbuffer);
+ hunkvbuf = vid.width * vid.height * sizeof(*dvars.zb);
scachesz = D_SurfaceCacheForRes(vid.width, vid.height);
hunkvbuf += scachesz;
- if((dvars.zbuffer = realloc(dvars.zbuffer, hunkvbuf)) == nil)
+ if((dvars.zb = realloc(dvars.zb, hunkvbuf)) == nil)
sysfatal("%r");
- memset(dvars.zbuffer, 0, hunkvbuf);
- surfcache = (byte*)(dvars.zbuffer + vid.width * vid.height);
+ memset(dvars.zb, 0, hunkvbuf);
+ surfcache = (byte*)(dvars.zb + vid.width * vid.height);
D_InitCaches(surfcache, scachesz);
vid.aspect = (float)vid.height / (float)vid.width * (320.0/240.0);
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -86,16 +86,16 @@
vid.buffer = vidbuffer;
vid.conbuffer = vid.buffer;
- if(dvars.zbuffer != nil)
+ if(dvars.zb != nil)
D_FlushCaches();
// alloc an extra line in case we want to wrap, and allocate the z-buffer
- hunkvbuf = vid.width * vid.height * sizeof(*dvars.zbuffer);
+ hunkvbuf = vid.width * vid.height * sizeof(*dvars.zb);
scachesz = D_SurfaceCacheForRes(vid.width, vid.height);
hunkvbuf += scachesz;
- dvars.zbuffer = realloc(dvars.zbuffer, hunkvbuf);
- memset(dvars.zbuffer, 0, hunkvbuf);
- surfcache = (byte *)(dvars.zbuffer + vid.width * vid.height);
+ dvars.zb = realloc(dvars.zb, hunkvbuf);
+ memset(dvars.zb, 0, hunkvbuf);
+ surfcache = (byte *)(dvars.zb + vid.width * vid.height);
D_InitCaches(surfcache, scachesz);
vid.resized = false;
}