From 8c9aa2588c3d0261cf9ed29d9a0b05b505bbcd85 Mon Sep 17 00:00:00 2001 From: mittorn Date: Wed, 3 Apr 2019 22:55:46 +0700 Subject: [PATCH] ref_soft: Fix studio rendermodes, add additive brush rendermode --- r_edge.c | 3 + r_scan.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++++++++ r_studio.c | 1 + 3 files changed, 198 insertions(+) diff --git a/r_edge.c b/r_edge.c index e20d3908..eec6f19f 100644 --- a/r_edge.c +++ b/r_edge.c @@ -985,6 +985,7 @@ qboolean alphaspans; void D_AlphaSpans16 (espan_t *pspan); +void D_AddSpans16 (espan_t *pspan); void D_BlendSpans16 (espan_t *pspan, int alpha ); void TurbulentZ8 (espan_t *pspan, int alpha ); /* @@ -1072,6 +1073,8 @@ void D_AlphaSurf (surf_t *s) if( RI.currententity->curstate.rendermode == kRenderTransAlpha ) D_AlphaSpans16(s->spans); + else if( RI.currententity->curstate.rendermode == kRenderTransAdd ) + D_AddSpans16(s->spans); else D_BlendSpans16(s->spans, RI.currententity->curstate.renderamt * 7 / 255 ); } diff --git a/r_scan.c b/r_scan.c index 8a31b90e..77d151ed 100644 --- a/r_scan.c +++ b/r_scan.c @@ -1134,6 +1134,200 @@ void D_BlendSpans16 (espan_t *pspan, int alpha) } while ((pspan = pspan->pnext) != NULL); } + + +/* +============= +D_DrawSpans16 + + FIXME: actually make this subdivide by 16 instead of 8!!! +============= +*/ +void D_AddSpans16 (espan_t *pspan) +{ + int count, spancount; + pixel_t *pbase, *pdest; + fixed16_t s, t, snext, tnext, sstep, tstep; + float sdivz, tdivz, zi, z, du, dv, spancountminus1; + float sdivz8stepu, tdivz8stepu, zi8stepu; + int izi, izistep; + short *pz; + + sstep = 0; // keep compiler happy + tstep = 0; // ditto + + pbase = (unsigned char *)cacheblock; + + sdivz8stepu = d_sdivzstepu * 8; + tdivz8stepu = d_tdivzstepu * 8; + zi8stepu = d_zistepu * 8; + izistep = (int)(d_zistepu * 0x8000 * 0x10000); + + do + { + pdest = (d_viewbuffer + + (r_screenwidth * pspan->v) + pspan->u); + pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u; + + 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; + izi = (int)(zi * 0x8000 * 0x10000); + 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 + { + // 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 + 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) + 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 + + if (spancount > 1) + { + sstep = (snext - s) / (spancount - 1); + tstep = (tnext - t) / (spancount - 1); + } + } + + + // Drawing phrase + if (sw_texfilt->value == 0.0f) + { + do + { + if (*pz <= (izi >> 16)) + { + pixel_t btemp; + + btemp = *(pbase + (s >> 16) + (t >> 16) * cachewidth); + + btemp = BLEND_ADD( btemp, *pdest); + *pdest = btemp; + //*pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; + } while (--spancount > 0); + } + else if (sw_texfilt->value == 1.0f) + { + do + { + int idiths = s; + int iditht = t; + + int X = (pspan->u + spancount) & 1; + int Y = (pspan->v)&1; + if (*pz <= (izi >> 16)) + { + pixel_t btemp; + + //Using the kernel + idiths += kernel[X][Y][0]; + iditht += kernel[X][Y][1]; + + idiths = idiths >> 16; + idiths = idiths ? idiths -1 : idiths; + + + iditht = iditht >> 16; + iditht = iditht ? iditht -1 : iditht; + + btemp = *(pbase + idiths + iditht * cachewidth); + + btemp = BLEND_ADD( btemp, *pdest); + *pdest = btemp; + //*pz = izi >> 16; + } + pdest++; + pz++; + izi += izistep; + s += sstep; + t += tstep; + } while (--spancount > 0); + } + + + } while (count > 0); + + } while ((pspan = pspan->pnext) != NULL); +} + #endif diff --git a/r_studio.c b/r_studio.c index 64b653ea..584acbe2 100644 --- a/r_studio.c +++ b/r_studio.c @@ -2786,6 +2786,7 @@ set rendermode for studiomodel */ void GL_StudioSetRenderMode( int rendermode ) { + GL_SetRenderMode( rendermode ); #if 0 switch( rendermode ) {