software transtable rewrite, sw additive support for sprites/blob particles/line particles (no models yet), AddBlend/Trans functions need optimization

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@1174 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
TimeServ 2005-07-29 01:12:09 +00:00
parent c5c278da85
commit ea9c3b0360
15 changed files with 437 additions and 946 deletions

View file

@ -81,8 +81,8 @@ static double cost[7] = {1.000000, 0.623490, -0.222521, -0.900969, -0.900969, -0
#define crand() (rand()%32767/16383.5f-1) #define crand() (rand()%32767/16383.5f-1)
void D_DrawParticleTrans (particle_t *pparticle); void D_DrawParticleTrans (particle_t *pparticle, int blendmode);
void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest); void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest, int blendmode);
void P_ReadPointFile_f (void); void P_ReadPointFile_f (void);
@ -176,7 +176,7 @@ typedef struct part_type_s {
float timelimit; float timelimit;
enum {PT_NORMAL, PT_SPARK, PT_SPARKFAN, PT_TEXTUREDSPARK, PT_BEAM, PT_DECAL} type; enum {PT_NORMAL, PT_SPARK, PT_SPARKFAN, PT_TEXTUREDSPARK, PT_BEAM, PT_DECAL} type;
enum {BM_MERGE, BM_ADD, BM_SUBTRACT} blendmode; blendmode_t blendmode;
float rotationstartmin, rotationstartrand; float rotationstartmin, rotationstartrand;
float rotationmin, rotationrand; float rotationmin, rotationrand;
@ -1946,7 +1946,7 @@ int P_RunParticleEffectType (vec3_t org, vec3_t dir, float count, int typenum)
p->alpha = ptype->alpha-p->die*(ptype->alpha/ptype->die)*ptype->alphachange; p->alpha = ptype->alpha-p->die*(ptype->alpha/ptype->die)*ptype->alphachange;
else else
p->alpha = ptype->alpha; p->alpha = ptype->alpha;
p->color = 0; // p->color = 0;
p->nextemit = particletime + ptype->emitstart - p->die; p->nextemit = particletime + ptype->emitstart - p->die;
if (ptype->emittime < 0) if (ptype->emittime < 0)
p->trailstate = NULL; p->trailstate = NULL;
@ -2630,7 +2630,7 @@ int P_ParticleTrail (vec3_t startpos, vec3_t end, int type, trailstate_t **tsk)
p->alpha = ptype->alpha-p->die*(ptype->alpha/ptype->die)*ptype->alphachange; p->alpha = ptype->alpha-p->die*(ptype->alpha/ptype->die)*ptype->alphachange;
else else
p->alpha = ptype->alpha; p->alpha = ptype->alpha;
p->color = 0; // p->color = 0;
// if (ptype->spawnmode == SM_TRACER) // if (ptype->spawnmode == SM_TRACER)
if (ptype->spawnparam1) if (ptype->spawnparam1)
@ -3448,7 +3448,7 @@ void SWD_DrawParticleSpark(particle_t *p, part_type_t *type)
VectorMA(p->org, -2.5/(speed), p->vel, dest); VectorMA(p->org, -2.5/(speed), p->vel, dest);
} }
D_DrawSparkTrans(p, src, dest); D_DrawSparkTrans(p, src, dest, type->blendmode);
} }
void SWD_DrawParticleBlob(particle_t *p, part_type_t *type) void SWD_DrawParticleBlob(particle_t *p, part_type_t *type)
{ {
@ -3469,7 +3469,7 @@ void SWD_DrawParticleBlob(particle_t *p, part_type_t *type)
else if (b > 255) else if (b > 255)
b = 255; b = 255;
p->color = GetPalette(r, g, b); p->color = GetPalette(r, g, b);
D_DrawParticleTrans(p); D_DrawParticleTrans(p, type->blendmode);
} }
void SWD_DrawParticleBeam(beamseg_t *beam, part_type_t *type) void SWD_DrawParticleBeam(beamseg_t *beam, part_type_t *type)
{ {
@ -3505,7 +3505,7 @@ void SWD_DrawParticleBeam(beamseg_t *beam, part_type_t *type)
else if (b > 255) else if (b > 255)
b = 255; b = 255;
p->color = GetPalette(r, g, b); p->color = GetPalette(r, g, b);
D_DrawSparkTrans(p, p->org, q->org ); D_DrawSparkTrans(p, p->org, q->org, type->blendmode);
} }
#endif #endif

View file

@ -367,7 +367,6 @@ extern cvar_t gl_finish;
extern cvar_t gl_max_size; extern cvar_t gl_max_size;
extern cvar_t gl_playermip; extern cvar_t gl_playermip;
extern cvar_t r_palconvbits;
extern cvar_t r_palconvwrite; extern cvar_t r_palconvwrite;
extern cvar_t r_lightmap_saturation; extern cvar_t r_lightmap_saturation;

View file

@ -184,10 +184,6 @@ cvar_t r_drawflat = {"r_drawflat","0", NULL, CVAR_SEMICHEAT};
cvar_t r_wallcolour = {"r_wallcolour","0 0 1"}; cvar_t r_wallcolour = {"r_wallcolour","0 0 1"};
cvar_t r_floorcolour = {"r_floorcolour","0.5 0.5 1"}; cvar_t r_floorcolour = {"r_floorcolour","0.5 0.5 1"};
cvar_t r_transtables = {"r_transtables","2"};
cvar_t r_transtablehalf = {"r_transtablehalf", "1"};
cvar_t r_transtablewrite = {"r_transtablewrite", "1"};
cvar_t r_palconvbits = {"r_palconvbits", "565"};
cvar_t r_palconvwrite = {"r_palconvwrite", "1"}; cvar_t r_palconvwrite = {"r_palconvwrite", "1"};
cvar_t r_lightmap_saturation = {"r_lightmap_saturation", "1"}; cvar_t r_lightmap_saturation = {"r_lightmap_saturation", "1"};
@ -362,10 +358,6 @@ void SWRenderer_Init(void)
Cvar_Register (&r_ambient, SWRENDEREROPTIONS); Cvar_Register (&r_ambient, SWRENDEREROPTIONS);
Cvar_Register (&r_reportsurfout, SWRENDEREROPTIONS); Cvar_Register (&r_reportsurfout, SWRENDEREROPTIONS);
Cvar_Register (&r_transtables, SWRENDEREROPTIONS);
Cvar_Register (&r_transtablewrite, SWRENDEREROPTIONS);
Cvar_Register (&r_transtablehalf, SWRENDEREROPTIONS);
Cvar_Register (&r_palconvbits, SWRENDEREROPTIONS);
Cvar_Register (&r_palconvwrite, SWRENDEREROPTIONS); Cvar_Register (&r_palconvwrite, SWRENDEREROPTIONS);
} }
#endif #endif

View file

@ -175,4 +175,6 @@ void P_EmitSkyEffectTris(struct model_s *mod, struct msurface_s *fa);
// trailstate functions // trailstate functions
void P_DelinkTrailstate(trailstate_t **tsk); void P_DelinkTrailstate(trailstate_t **tsk);
typedef enum { BM_MERGE, BM_ADD, BM_SUBTRACT } blendmode_t;
#endif #endif

View file

@ -46,8 +46,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// particle_t structure // particle_t structure
// !!! if this is changed, it must be changed in d_iface.h too !!! // !!! if this is changed, it must be changed in d_iface.h too !!!
// driver-usable fields // driver-usable fields
#define pt_org 0 #define pt_org 8
#define pt_color 12 #define pt_color 20
// drivers never touch the following fields // drivers never touch the following fields
/*#define pt_next 16 /*#define pt_next 16
#define pt_vel 20 #define pt_vel 20

View file

@ -117,37 +117,19 @@ extern float d_scalemip[3];
extern void (*d_drawspans) (espan_t *pspan); extern void (*d_drawspans) (espan_t *pspan);
#ifdef PEXT_TRANS #ifdef PEXT_TRANS
typedef qbyte tlookup[256][256]; #define PAL555_SIZE 32*32*32
typedef qbyte tlookupp[256]; #define TRANS_LEVELS 65
extern tlookup *t_lookup; #define TRANS_MAX (TRANS_LEVELS - 1)
extern tlookupp *t_curlookupp;
extern int t_numtables;
extern int t_numtablesinv;//65546/numtables
extern int t_state;
#define TT_REVERSE 0x1 // reverse table points #define TRANS_UPPER_CAP (TRANS_MAX / (TRANS_LEVELS + 0.0))
#define TT_ZERO 0x2 // zero alpha #define TRANS_LOWER_CAP (1.0 / TRANS_LEVELS)
#define TT_ONE 0x4 // full alpha
#define TT_USEHALF 0x8 // using half transtables
// cvar defines for transtable
extern cvar_t r_transtablewrite;
extern cvar_t r_transtables;
extern cvar_t r_transtablehalf;
void D_InitTrans(void); void D_InitTrans(void);
#define Trans(p, p2) (t_curlookupp[p][p2])
// void Set_TransLevelI(int level); // void Set_TransLevelI(int level);
void Set_TransLevelF(float level); void D_SetTransLevel(float level, blendmode_t blend);
extern qbyte _fastcall Trans(qbyte p, qbyte p2);
extern qbyte _fastcall AddBlend(qbyte p, qbyte p2);
extern qbyte *palxxxto8;
extern int palmask[3];
extern int palshift[3];
extern qbyte *pal555to8;
#endif #endif

View file

@ -359,169 +359,14 @@ void D_DrawParticle32 (particle_t *pparticle)
} }
} }
#define draw(x, y) x=Trans(x,(int)y) #define draw(x, y) x=Trans(x,y)
#define rdraw(x, y) x=Trans((int)y,x) #define addblend(x, y) x=AddBlend(x,y)
void D_DrawParticleReverseTrans (particle_t *pparticle) void D_DrawParticleTrans (particle_t *pparticle, blendmode_t blendmode)
{
vec3_t local, transformed;
float zi;
qbyte *pdest;
short *pz;
int i, izi, pix, count, u, v;
// transform point
VectorSubtract (pparticle->org, r_origin, local);
transformed[0] = DotProduct(local, r_pright);
transformed[1] = DotProduct(local, r_pup);
transformed[2] = DotProduct(local, r_ppn);
if (transformed[2] < PARTICLE_Z_CLIP)
return;
// project the point
// FIXME: preadjust xcenter and ycenter
zi = 1.0 / transformed[2];
u = (int)(xcenter + zi * transformed[0] + 0.5);
v = (int)(ycenter - zi * transformed[1] + 0.5);
if ((v > d_vrectbottom_particle) ||
(u > d_vrectright_particle) ||
(v < d_vrecty) ||
(u < d_vrectx))
{
return;
}
pz = d_pzbuffer + (d_zwidth * v) + u;
izi = (int)(zi * 0x8000);
pix = ((int)(izi*pparticle->scale)) >> d_pix_shift;
if (pix < d_pix_min)
pix = d_pix_min;
else if (pix > d_pix_max)
pix = d_pix_max;
u -= pix/2;
v -= pix/2;
if (u < 0) u = 0;
if (v < 0) v = 0;
pdest = d_viewbuffer + d_scantable[v] + u;
switch (pix)
{
case 1:
count = 1 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
rdraw(pdest[0], pparticle->color);
}
}
break;
case 2:
count = 2 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
rdraw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
rdraw(pdest[1], pparticle->color);
}
}
break;
case 3:
count = 3 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
rdraw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
rdraw(pdest[1], pparticle->color);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
rdraw(pdest[2], pparticle->color);
}
}
break;
case 4:
count = 4 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
rdraw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
rdraw(pdest[1], pparticle->color);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
rdraw(pdest[2], pparticle->color);
}
if (pz[3] <= izi)
{
// pz[3] = izi;
rdraw(pdest[3], pparticle->color);
}
}
break;
default:
count = pix << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
for (i=0 ; i<pix ; i++)
{
if (pz[i] <= izi)
{
// pz[i] = izi;
rdraw(pdest[i], pparticle->color);
}
}
}
break;
}
}
void D_DrawParticleTrans (particle_t *pparticle)
{ {
vec3_t local, transformed; vec3_t local, transformed;
float zi; float zi;
qbyte *pdest; qbyte *pdest;
qbyte pcolor;
short *pz; short *pz;
int i, izi, pix, count, u, v; int i, izi, pix, count, u, v;
@ -536,22 +381,18 @@ void D_DrawParticleTrans (particle_t *pparticle)
return; return;
} }
Set_TransLevelF(pparticle->alpha); if (pparticle->alpha < TRANS_LOWER_CAP)
if (t_state & TT_ZERO)
return; return;
if (t_state & TT_ONE) if (pparticle->alpha > TRANS_UPPER_CAP && blendmode == BM_MERGE)
{ {
D_DrawParticle(pparticle); D_DrawParticle(pparticle);
return; return;
} }
if (t_state & TT_REVERSE) D_SetTransLevel(pparticle->alpha, blendmode);
{
D_DrawParticleReverseTrans(pparticle); pcolor = pparticle->color;
return;
}
// transform point // transform point
VectorSubtract (pparticle->org, r_origin, local); VectorSubtract (pparticle->org, r_origin, local);
@ -593,111 +434,223 @@ void D_DrawParticleTrans (particle_t *pparticle)
if (v < 0) v = 0; if (v < 0) v = 0;
pdest = d_viewbuffer + d_scantable[v] + u; pdest = d_viewbuffer + d_scantable[v] + u;
switch (pix) if (blendmode == BM_ADD) // additive drawing
{ {
case 1: switch (pix)
count = 1 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{ {
if (pz[0] <= izi) case 1:
count = 1 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{ {
// pz[0] = izi; if (pz[0] <= izi)
draw(pdest[0], pparticle->color);
}
}
break;
case 2:
count = 2 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pparticle->color);
}
}
break;
case 3:
count = 3 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pparticle->color);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
draw(pdest[2], pparticle->color);
}
}
break;
case 4:
count = 4 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pparticle->color);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pparticle->color);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
draw(pdest[2], pparticle->color);
}
if (pz[3] <= izi)
{
// pz[3] = izi;
draw(pdest[3], pparticle->color);
}
}
break;
default:
count = pix << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
for (i=0 ; i<pix ; i++)
{
if (pz[i] <= izi)
{ {
// pz[i] = izi; // pz[0] = izi;
draw(pdest[i], pparticle->color); addblend(pdest[0], pcolor);
} }
} }
break;
case 2:
count = 2 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
addblend(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
addblend(pdest[1], pcolor);
}
}
break;
case 3:
count = 3 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
addblend(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
addblend(pdest[1], pcolor);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
addblend(pdest[2], pcolor);
}
}
break;
case 4:
count = 4 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
addblend(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
addblend(pdest[1], pcolor);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
addblend(pdest[2], pcolor);
}
if (pz[3] <= izi)
{
// pz[3] = izi;
addblend(pdest[3], pcolor);
}
}
break;
default:
count = pix << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
for (i=0 ; i<pix ; i++)
{
if (pz[i] <= izi)
{
// pz[i] = izi;
addblend(pdest[i], pcolor);
}
}
}
break;
}
}
else // merge drawing
{
switch (pix)
{
case 1:
count = 1 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pcolor);
}
}
break;
case 2:
count = 2 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pcolor);
}
}
break;
case 3:
count = 3 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pcolor);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
draw(pdest[2], pcolor);
}
}
break;
case 4:
count = 4 << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
if (pz[0] <= izi)
{
// pz[0] = izi;
draw(pdest[0], pcolor);
}
if (pz[1] <= izi)
{
// pz[1] = izi;
draw(pdest[1], pcolor);
}
if (pz[2] <= izi)
{
// pz[2] = izi;
draw(pdest[2], pcolor);
}
if (pz[3] <= izi)
{
// pz[3] = izi;
draw(pdest[3], pcolor);
}
}
break;
default:
count = pix << d_y_aspect_shift;
for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
{
for (i=0 ; i<pix ; i++)
{
if (pz[i] <= izi)
{
// pz[i] = izi;
draw(pdest[i], pcolor);
}
}
}
break;
} }
break;
} }
} }
@ -895,7 +848,7 @@ void D_DrawSparkTrans16 (particle_t *pparticle, vec3_t src, vec3_t dest) //draw
} while (count--); } while (count--);
} }
void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a line in 3d space, 8bpp void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest, blendmode_t blendmode) //draw a line in 3d space, 8bpp
{ {
qbyte *pdest; qbyte *pdest;
short *pz; short *pz;
@ -918,10 +871,7 @@ void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a
return; return;
} }
Set_TransLevelF(pparticle->alpha); D_SetTransLevel(pparticle->alpha, blendmode);
if (t_state & TT_ZERO)
return;
D_2dPos(src, &u1, &v1, &z1); D_2dPos(src, &u1, &v1, &z1);
D_2dPos(dest, &u2, &v2, &z2); D_2dPos(dest, &u2, &v2, &z2);
@ -961,13 +911,11 @@ void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a
u1 = u1<<16; u1 = u1<<16;
v1 = v1<<16; v1 = v1<<16;
z1 = z1<<16; z1 = z1<<16;
{ du /= count;
du /= count; dv /= count;
dv /= count; dz /= count;
dz /= count;
}
if (t_state & TT_ONE) if (blendmode == BM_ADD) // additive
{ {
do do
{ {
@ -975,8 +923,9 @@ void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a
if (*pz <= z1>>16) if (*pz <= z1>>16)
{ {
// *pz = z1>>16;
pdest = d_viewbuffer + d_scantable[v1>>16] + (u1>>16); pdest = d_viewbuffer + d_scantable[v1>>16] + (u1>>16);
*pdest = pparticle->color; addblend(*pdest, (qbyte)pparticle->color);
} }
u1 += du; u1 += du;
@ -984,7 +933,7 @@ void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a
z1 += dz; z1 += dz;
} while (count--); } while (count--);
} }
else if (t_state & TT_REVERSE) else // merge blend
{ {
do do
{ {
@ -992,26 +941,9 @@ void D_DrawSparkTrans (particle_t *pparticle, vec3_t src, vec3_t dest) //draw a
if (*pz <= z1>>16) if (*pz <= z1>>16)
{ {
// *pz = z1>>16;
pdest = d_viewbuffer + d_scantable[v1>>16] + (u1>>16); pdest = d_viewbuffer + d_scantable[v1>>16] + (u1>>16);
rdraw(*pdest, pparticle->color); draw(*pdest, (qbyte)pparticle->color);
}
u1 += du;
v1 += dv;
z1 += dz;
} while (count--);
}
else
{
do
{
pz = d_pzbuffer + (d_zwidth * (v1>>16)) + (u1>>16);
if (*pz <= z1>>16)
{
// *pz = z1>>16;
pdest = d_viewbuffer + d_scantable[v1>>16] + (u1>>16);
draw(*pdest, pparticle->color);
} }
u1 += du; u1 += du;

View file

@ -249,83 +249,6 @@ void D_PolysetDrawFinalVerts32 (finalvert_t *fv, int numverts)
} }
} }
void D_PolysetRecursiveTriangleReverseTrans (int *lp1, int *lp2, int *lp3)
{
int *temp;
int d;
int new[6];
int z;
short *zbuf;
d = lp2[0] - lp1[0];
if (d < -1 || d > 1)
goto split;
d = lp2[1] - lp1[1];
if (d < -1 || d > 1)
goto split;
d = lp3[0] - lp2[0];
if (d < -1 || d > 1)
goto split2;
d = lp3[1] - lp2[1];
if (d < -1 || d > 1)
goto split2;
d = lp1[0] - lp3[0];
if (d < -1 || d > 1)
goto split3;
d = lp1[1] - lp3[1];
if (d < -1 || d > 1)
{
split3:
temp = lp1;
lp1 = lp3;
lp3 = lp2;
lp2 = temp;
goto split;
}
return; // entire tri is filled
split2:
temp = lp1;
lp1 = lp2;
lp2 = lp3;
lp3 = temp;
split:
// split this edge
new[0] = (lp1[0] + lp2[0]) >> 1;
new[1] = (lp1[1] + lp2[1]) >> 1;
new[2] = (lp1[2] + lp2[2]) >> 1;
new[3] = (lp1[3] + lp2[3]) >> 1;
new[5] = (lp1[5] + lp2[5]) >> 1;
// draw the point if splitting a leading edge
if (lp2[1] > lp1[1])
goto nodraw;
if ((lp2[1] == lp1[1]) && (lp2[0] < lp1[0]))
goto nodraw;
z = new[5]>>16;
zbuf = zspantable[new[1]] + new[0];
if (z >= *zbuf)
{
int pix;
*zbuf = z;
pix = d_pcolormap[skintable[new[3]>>16][new[2]>>16]];
d_viewbuffer[d_scantable[new[1]] + new[0]] = Trans(pix, d_viewbuffer[d_scantable[new[1]] + new[0]]);
}
nodraw:
// recursively continue
D_PolysetRecursiveTriangleReverseTrans (lp3, lp1, new);
D_PolysetRecursiveTriangleReverseTrans (lp3, new, lp2);
}
void D_PolysetRecursiveTriangleTrans (int *lp1, int *lp2, int *lp3) void D_PolysetRecursiveTriangleTrans (int *lp1, int *lp2, int *lp3)
{ {
int *temp; int *temp;
@ -564,73 +487,6 @@ nodraw:
D_PolysetRecursiveTriangle16 (lp3, new, lp2); D_PolysetRecursiveTriangle16 (lp3, new, lp2);
} }
void D_PolysetDrawSpans8ReverseTrans (spanpackage_t *pspanpackage)
{
int lcount;
qbyte *lpdest;
qbyte *lptex;
int lsfrac, ltfrac;
int llight;
int lzi;
short *lpz;
if (d_aspancount<0)
return;
do
{
lcount = d_aspancount - pspanpackage->count;
errorterm += erroradjustup;
if (errorterm >= 0)
{
d_aspancount += d_countextrastep;
errorterm -= erroradjustdown;
}
else
{
d_aspancount += ubasestep;
}
if (lcount)
{
lpdest = pspanpackage->pdest;
lptex = pspanpackage->ptex;
lpz = pspanpackage->pz;
lsfrac = pspanpackage->sfrac;
ltfrac = pspanpackage->tfrac;
llight = pspanpackage->light;
lzi = pspanpackage->zi;
do
{
if ((lzi >> 16) >= *lpz)
{
*lpdest = Trans(((qbyte *)acolormap)[*lptex + (llight & 0xFF00)], *lpdest);
// gel mapping *lpdest = gelmap[*lpdest];
*lpz = lzi >> 16;
}
lpdest++;
lzi += r_zistepx;
lpz++;
llight += r_lstepx;
lptex += a_ststepxwhole;
lsfrac += a_sstepxfrac;
lptex += lsfrac >> 16;
lsfrac &= 0xFFFF;
ltfrac += a_tstepxfrac;
if (ltfrac & 0x10000)
{
lptex += r_affinetridesc.skinwidth;
ltfrac &= 0xFFFF;
}
} while (--lcount);
}
pspanpackage++;
} while (pspanpackage->count != -999999);
}
void D_PolysetDrawSpans8Trans (spanpackage_t *pspanpackage) void D_PolysetDrawSpans8Trans (spanpackage_t *pspanpackage)
{ {
int lcount; int lcount;
@ -641,15 +497,6 @@ void D_PolysetDrawSpans8Trans (spanpackage_t *pspanpackage)
int lzi; int lzi;
short *lpz; short *lpz;
if (t_state & TT_REVERSE)
{
if (t_state & TT_ONE)
D_PolysetDrawSpans8C(pspanpackage);
else
D_PolysetDrawSpans8ReverseTrans(pspanpackage);
return;
}
if (d_aspancount<0) if (d_aspancount<0)
return; return;
@ -1133,7 +980,12 @@ void D_RasterizeAliasPolySmoothC (void)
else if (r_pixbytes == 2) else if (r_pixbytes == 2)
D_PolysetDrawSpans16 (a_spans); D_PolysetDrawSpans16 (a_spans);
else else
D_PolysetDrawSpans8Trans (a_spans); {
if (transbackfac)
D_PolysetDrawSpans8Trans (a_spans);
else
D_PolysetDrawSpans8C (a_spans);
}
// scan out the bottom part of the right edge, if it exists // scan out the bottom part of the right edge, if it exists
if (pedgetable->numrightedges == 2) if (pedgetable->numrightedges == 2)
@ -1167,7 +1019,12 @@ void D_RasterizeAliasPolySmoothC (void)
else if (r_pixbytes == 2) else if (r_pixbytes == 2)
D_PolysetDrawSpans16 (pstart); D_PolysetDrawSpans16 (pstart);
else else
D_PolysetDrawSpans8Trans (pstart); {
if (transbackfac)
D_PolysetDrawSpans8Trans (pstart);
else
D_PolysetDrawSpans8C (pstart);
}
} }
} }
@ -1303,16 +1160,8 @@ void D_DrawSubdivC (void)
#ifdef PEXT_TRANS #ifdef PEXT_TRANS
if (r_pixbytes == 4) if (r_pixbytes == 4)
drawfnc = D_PolysetRecursiveTriangle32Trans; drawfnc = D_PolysetRecursiveTriangle32Trans;
else if (!(t_state & TT_ONE)) else if (r_pixbytes == 1)
{ drawfnc = D_PolysetRecursiveTriangleTrans;
if (t_state & TT_ZERO)
return;
if (t_state & TT_REVERSE)
drawfnc = D_PolysetRecursiveTriangleReverseTrans;
else
drawfnc = D_PolysetRecursiveTriangleTrans;
}
else else
#endif #endif
drawfnc = D_PolysetRecursiveTriangleC; drawfnc = D_PolysetRecursiveTriangleC;

View file

@ -636,7 +636,7 @@ void D_DrawSpans8_Smooth (espan_t *pspan)
} }
do do
{ {
#if 1 #if 0
#define mins (s>>16) #define mins (s>>16)
#define mint (t>>16) #define mint (t>>16)
#define pix *(pbase + (mins) + (mint) * cachewidth) #define pix *(pbase + (mins) + (mint) * cachewidth)

View file

@ -503,7 +503,10 @@ NextSpan:
} }
#ifdef PEXT_TRANS #ifdef PEXT_TRANS
void D_SpriteDrawSpansReverseTrans (sspan_t *pspan) // Additive version of SpriteDrawSpansTrans
// 1 line change but due to the loop a seperate
// copy is a better idea
void D_SpriteDrawSpansAdditive (sspan_t *pspan)
{ {
int count, spancount, izistep; int count, spancount, izistep;
int izi; int izi;
@ -635,7 +638,7 @@ void D_SpriteDrawSpansReverseTrans (sspan_t *pspan)
if (*pz <= (izi >> 16)) if (*pz <= (izi >> 16))
{ {
*pz = izi >> 16; *pz = izi >> 16;
*pdest = Trans(btemp, *pdest); *pdest = AddBlend(*pdest, btemp);
} }
} }
@ -1067,15 +1070,20 @@ void D_DrawSprite (void)
D_SpriteDrawSpans16 (sprite_spans); D_SpriteDrawSpans16 (sprite_spans);
else //1 else //1
{ {
Set_TransLevelF(currententity->alpha); if (currententity->alpha > TRANS_LOWER_CAP)
if (t_state & TT_ONE)
D_SpriteDrawSpans (sprite_spans);
else if (!(t_state & TT_ZERO))
{ {
if (t_state & TT_REVERSE) if (currententity->flags & Q2RF_ADDATIVE)
D_SpriteDrawSpansReverseTrans (sprite_spans); {
D_SetTransLevel(currententity->alpha, BM_ADD);
D_SpriteDrawSpansAdditive (sprite_spans);
}
else if (currententity->alpha > TRANS_UPPER_CAP)
D_SpriteDrawSpans (sprite_spans);
else else
{
D_SetTransLevel(currententity->alpha, BM_MERGE);
D_SpriteDrawSpansTrans (sprite_spans); D_SpriteDrawSpansTrans (sprite_spans);
}
} }
} }
#endif #endif

View file

@ -6,221 +6,53 @@
#include "r_local.h" #include "r_local.h"
void MakeVideoPalette(void); void MakeVideoPalette(void);
int t_numtables; void MakeSwizzledPalette(void);
qbyte p1multitable[] = {1, 99, 49, 97, 48, 19, 47, 93, 23, 91, 9, 89, 22, 87, 43, 17, 21, 83, 41, 81, 4, 79, 39, 77, 19, 3, 37, 73, 18, 71, 7, 69, 17, 67, 33, 13, 16, 63, 31, 61, 3, 59, 29, 57, 14, 11, 27, 53, 13, 51, 1, 49, 12, 47, 23, 9, 11, 43, 21, 41, 2, 39, 19, 37, 9, 7, 17, 33, 8, 31, 3, 29, 7, 27, 13, 1, 6, 23, 11, 21, 1, 19, 9, 17, 4, 3, 7, 13, 3, 11, 1, 9, 2, 7, 3, 1, 1, 3, 1, 1, 0}; int *srctable;
qbyte p2multitable[] = {0, 1, 1, 3, 2, 1, 3, 7, 2, 9, 1, 11, 3, 13, 7, 3, 4, 17, 9, 19, 1, 21, 11, 23, 6, 1, 13, 27, 7, 29, 3, 31, 8, 33, 17, 7, 9, 37, 19, 39, 2, 41, 21, 43, 11, 9, 23, 47, 12, 49, 1, 51, 13, 53, 27, 11, 14, 57, 29, 59, 3, 61, 31, 63, 16, 13, 33, 67, 17, 69, 7, 71, 18, 73, 37, 3, 19, 77, 39, 79, 4, 81, 41, 83, 21, 17, 43, 87, 22, 89, 9, 91, 23, 93, 47, 19, 24, 97, 49, 99, 1}; int *dsttable;
tlookup *t_lookup; qbyte *pal555to8;
tlookupp *t_curlookupp;
int t_curtable;
int t_numtables; int swzpal[TRANS_LEVELS][256];
int t_numtablesinv;//numtables/65546
int t_state;
#define palette host_basepal #define palette host_basepal
#define _abs(x) ((x)*(x)) #define _abs(x) ((x)*(x))
void R_ReverseTable(int table)
{
int p, p2, temp;
for (p = 0; p < 256; p++)
for (p2 = p+1; p2 < 256; p2++)
{
temp = (t_lookup[table])[p][p2];
(t_lookup[table])[p][p2] = (t_lookup[table])[p2][p];
(t_lookup[table])[p2][p] = temp;
}
}
void R_CalcTransTable(int table, int level)
{
FILE * f;
int p;
int p2;
int r, g, b, j;
int i;
unsigned char *pa;
int m, rvr;
int dif, curdif;
qbyte p1multi;
qbyte p2multi;
qbyte pixdivide;
p1multi = p1multitable[level];
p2multi = p2multitable[level];
pixdivide = p1multi + p2multi;
if (level > 99) // trivial generate for p2
{
for (p = 0; p < 256; p++)
for (p2 = 0; p2 < 256; p2++)
(t_lookup[table])[p][p2] = p2;
return;
}
if (level < 1) // trivial generate for p
{
for (p = 0; p < 256; p++)
for (p2 = 0; p2 < 256; p2++)
(t_lookup[table])[p][p2] = p;
return;
}
if (level > 50)
{
level = 100 - level;
rvr = 1;
}
else
rvr = 0;
COM_FOpenFile (va("tables/ttable%i.dat", (int) level) , &f); //we can ignore the filesize return value
if (f)
{
if (fread (t_lookup[table], 256, 256, f) == 256)
{
if (rvr)
R_ReverseTable(table);
fclose(f);
return;
}
fclose(f);
}
Con_Printf("Generating transtable %i%%\n", level);
for (p = 0; p < 256; p++)
{
j = p*3;
for (p2 = 0; p2 < 256; p2++)
{
dif = 0x7fffffff;
m=0;
i = p2*3;
r = (palette[j+0] * p1multi + palette[i+0] * p2multi) / pixdivide;
g = (palette[j+1] * p1multi + palette[i+1] * p2multi) / pixdivide;
b = (palette[j+2] * p1multi + palette[i+2] * p2multi) / pixdivide;
for (i = 0,pa=palette; i < 256-16; i++,pa+=3)
{
curdif = _abs(r - pa[0]) + _abs(g - pa[1]) + _abs(b - pa[2]);
if (curdif <= 0) //force 0
{
m = i;
break;
}
if (curdif < dif)
{
dif = curdif;
m = i;
}
}
(t_lookup[table])[p][p2] = m;
}
}
if (r_transtablewrite.value)
{
COM_CreatePath(va("%s/tables/", com_gamedir));
#if 1
f = fopen (va("%s/tables/ttable%i.dat", com_gamedir, (int) level), "wb");
if (f)
{
if (fwrite (t_lookup[table], 256, 256, f) != 256)
{
Con_Printf("Couldn't write data to \"tables/ttable%i.dat\"\n", (int) level);
fclose(f);
if (rvr)
R_ReverseTable(table); // make sure it gets reversed if needed
return;
}
fclose(f);
}
else
Con_Printf("Couldn't write data to \"tables/ttable%i.dat\"\n", (int) level);
#else
COM_WriteFile(va("tables/ttable%i.dat", (int)level, t_lookup[table], 256*256);
#endif
}
if (rvr) // just reverse it here instead of having to do reversed writes
R_ReverseTable(table);
}
void D_InitTrans(void) void D_InitTrans(void)
{ {
int i; // create pal555to8 and swizzled palette
int table;
if (t_lookup)
BZ_Free(t_lookup);
//no trans palette yet..
Con_SafePrintf("Making/loading transparency lookup tables\nPlease wait...\n");
MakeVideoPalette(); MakeVideoPalette();
MakeSwizzledPalette();
t_numtables = 5; srctable = swzpal[0];
dsttable = swzpal[TRANS_MAX];
i = r_transtables.value;
if (i > 0 && i < 50) // might need a max bound sanity check here
{
t_numtables = i;
}
if ((i = COM_CheckParm("-ttables")) != 0)
{
t_numtables = Q_atoi(com_argv[i+1]);
if (t_numtables < 1)
t_numtables = 1;
if (t_numtables > 50)
t_numtables = 50;
}
t_numtablesinv = ((float)65536/t_numtables)+1;//65546/numtables
t_state = TT_ZERO;
t_curtable=0;
//t_lookup = Hunk_AllocName(sizeof(tlookup)*t_numtables, "Transtables");
t_lookup = BZ_Malloc(sizeof(tlookup)*t_numtables);
t_curlookupp = t_lookup[t_curtable];
if (r_transtablehalf.value)
{
t_state = TT_ZERO|TT_USEHALF;
for (table = 0; table < t_numtables; table++)
R_CalcTransTable(table, (int)floor(((table+1)/(float)(t_numtables*2+1))*100 + 0.5));
}
else
{
if (t_numtables == 1)
R_CalcTransTable(0, 50);
else if (t_numtables == 2)
{
R_CalcTransTable(0, 33);
R_CalcTransTable(1, 67);
}
else
{
for (table = 0; table < t_numtables; table++)
R_CalcTransTable(table, (int)floor(100/((float)(t_numtables-1)/table) + 0.5));
}
}
Con_Printf("Done\n");
} }
#ifndef Trans #if 0
byte _fastcall Trans(byte p, byte p2) #define Trans(p, p2) (t_curlookupp[p][p2])
#else
// TODO: INLINE THESE FUNCTIONS
qbyte _fastcall Trans(qbyte p, qbyte p2)
{ {
return t_curlookupp[p][p2]; int x;
x = (srctable[p] + dsttable[p2]) | 0x01F07C1F;
return pal555to8[x & (x >> 15)];
} }
#endif #endif
qbyte _fastcall AddBlend(qbyte p, qbyte p2)
{
int x, y;
x = (srctable[p] + dsttable[p2]);
y = x & 0x40100400; // overflow bits
x = (x | 0x01F07C1F) & 0x3FFFFFFF;
y = y - (y >> 5);
x = x | y;
return pal555to8[x & (x >> 15)];
}
/* /*
void Set_TransLevelI(int level) void Set_TransLevelI(int level)
{ {
@ -229,219 +61,112 @@ void Set_TransLevelI(int level)
} }
*/ */
void Set_TransLevelF(float level) //MUST be between 0 and 1 void D_SetTransLevel(float level, blendmode_t blend) //MUST be between 0 and 1
{ {
if (level>1) int ilvl;
level = 1;
if (t_state & TT_USEHALF) // cap and set level
{ ilvl = (bound(0, level, 1) * (TRANS_MAX + 0.99));
t_state = TT_ZERO;
t_curtable = floor(level*(t_numtables*2+1) + 0.5);
if (t_curtable > t_numtables)
{
t_curtable = (t_numtables*2+1)-t_curtable;
t_state = TT_REVERSE|TT_ONE;
}
if (t_curtable > 0) // set blending tables
{ switch (blend)
t_state &= ~(TT_ZERO|TT_ONE);
t_curlookupp = t_lookup[t_curtable-1];
}
t_state |= TT_USEHALF;
}
else if (t_numtables == 1)
{ {
if (level < 0.33) case BM_ADD:
t_state = TT_ZERO; dsttable = swzpal[ilvl];
else if (level > 0.67) srctable = swzpal[TRANS_MAX];
t_state = TT_ONE; break;
else default:
t_state = 0; dsttable = swzpal[ilvl];
} srctable = swzpal[TRANS_MAX - ilvl];
else if (t_numtables == 2)
{
if (level > 0.75)
t_state = TT_ONE;
else if (level > 0.50)
{
t_state = 0;
t_curtable = 1;
t_curlookupp = t_lookup[t_curtable];
}
else if (level > 0.25)
{
t_state = 0;
t_curtable = 0;
t_curlookupp = t_lookup[t_curtable];
}
else
t_state = TT_ZERO;
}
else
{
t_curtable = level*t_numtables;
if (t_curtable >= t_numtables)
t_state = TT_ONE;
else if (t_curtable <= 0)
t_state = TT_ZERO;
else
{
t_state = 0;
t_curlookupp = t_lookup[t_curtable];
}
} }
} }
qbyte *palxxxto8;
int palmask[3];
int palshift[3];
#define _abs(x) ((x)*(x))
qbyte FindIndexFromRGB(int red, int green, int blue)
{
int i, best=15;
int bestdif=256*256*256, curdif;
extern qbyte *host_basepal;
qbyte *pa;
pa = host_basepal;
for (i = 0; i < 256; i++, pa+=3)
{
curdif = _abs(red - pa[0]) + _abs(green - pa[1]) + _abs(blue - pa[2]);
if (curdif < bestdif)
{
if (curdif<1)
return i;
bestdif = curdif;
best = i;
}
}
return best;
}
#define FindPallete(r,g,b) palxxxto8[((r&palmask[0])>>palshift[0]) | ((g&palmask[1])<<palshift[1]) | ((b&palmask[2])<<palshift[2])] #define FindPalette(r,g,b) pal555to8[((r&0xF8)>>3)|((g&0xF8)<<2)|((b&0xF8)<<7)]
//#define FindPallete(r,g,b) (pal777to8[r>>1][g>>1][b>>1])
qbyte GetPalette(int red, int green, int blue) qbyte GetPalette(int red, int green, int blue)
{ {
if (palxxxto8) //fast precalculated method if (pal555to8) //fast precalculated method
return FindPallete(red,green,blue); return FindPalette(red,green,blue);
else //slow, horrible method. else //slow, horrible method.
{ return FindIndexFromRGB(red, green, blue);
int i, best=15;
int bestdif=256*256*256, curdif;
extern qbyte *host_basepal;
qbyte *pa;
#define _abs(x) ((x)*(x))
pa = host_basepal;
for (i = 0; i < 256; i++, pa+=3)
{
curdif = _abs(red - pa[0]) + _abs(green - pa[1]) + _abs(blue - pa[2]);
if (curdif < bestdif)
{
if (curdif<1)
return i;
bestdif = curdif;
best = i;
}
}
return best;
}
} }
void MakeVideoPalette(void) void MakeVideoPalette(void)
{ {
// pal77 *temp;
qbyte *temp;
int r, g, b;
int rs, gs, bs, size;
int rstep, gstep, bstep;
int gshift, bshift;
FILE *f; FILE *f;
char filename[11]; int r, g, b;
if (strlen(r_palconvbits.string) != 3) // allocate memory
{ if (!pal555to8)
// r5g6b5 is default pal555to8 = BZ_Malloc(PAL555_SIZE);
rs = 5; // pal555to8 = Hunk_AllocName(PAL555_SIZE, "RGB data");
gs = 6;
bs = 5;
}
else
{
// convert to int
rs = r_palconvbits.string[0] - '0';
gs = r_palconvbits.string[1] - '0';
bs = r_palconvbits.string[2] - '0';
// limit to 4-8 (can't have 3 because the forumla breaks) // load in previously created table
if (rs < 4) COM_FOpenFile ("pal555.pal", &f);
rs = 4;
else if (rs > 8)
rs = 8;
if (gs < 4)
gs = 4;
else if (gs > 8)
gs = 8;
if (bs < 4)
bs = 4;
else if (bs > 8)
bs = 8;
}
Q_strcpy(filename, "rgb000.pal");
filename[3] = rs + '0';
filename[4] = gs + '0';
filename[5] = bs + '0';
palshift[0] = 1<<rs;
palshift[1] = 1<<gs;
palshift[2] = 1<<bs;
size = palshift[0]*palshift[1]*palshift[2];
gshift = rs;
bshift = rs+gs;
rs = 8-rs;
gs = 8-gs;
bs = 8-bs;
rstep = 1<<rs;
gstep = 1<<gs;
bstep = 1<<bs;
palmask[0] = 0xff ^ (rstep - 1);
palmask[1] = 0xff ^ (gstep - 1);
palmask[2] = 0xff ^ (bstep - 1);
palxxxto8 = Hunk_AllocName(size, "RGB data");
if (!palxxxto8)
BZ_Free(palxxxto8);
palxxxto8 = NULL;
temp = BZ_Malloc(size);
COM_FOpenFile (filename, &f);
if (f) if (f)
{ {
fread(temp, 1, size, f); //cached fread(pal555to8, 1, PAL555_SIZE, f); //cached
fclose(f); fclose(f);
palxxxto8 = temp;
// update shifts
palshift[0] = rs;
palshift[1] = (8 - palshift[0]) - gs;
palshift[2] = palshift[1] + (8 - bs);
return; return;
} }
rstep >>= 1; // create palette conversion table
gstep >>= 1; for (b = 0; b < 32; b++)
bstep >>= 1; for (g = 0; g < 32; g++)
for (r = 0; r < 32; r++)
for (r = palshift[0] - 1; r >= 0; r--) pal555to8[r | (g << 5) | (b << 10)] =
for (g = palshift[1] - 1; g >= 0; g--) FindIndexFromRGB(r<<3|r>>2, g<<3|g>>2, b<<3|b>>2);
for (b = palshift[2] - 1; b >= 0; b--)
{
temp[r+(g<<gshift)+(b<<bshift)] = GetPalette((r<<rs)+rstep, (g<<gs)+gstep, (b<<bs)+bstep);
}
palxxxto8 = temp;
// update shifts
palshift[0] = rs;
palshift[1] = (8 - palshift[0]) - gs;
palshift[2] = palshift[1] + (8 - bs);
// write palette conversion table
if (r_palconvwrite.value) if (r_palconvwrite.value)
COM_WriteFile(filename, palxxxto8, size); COM_WriteFile("pal555.pal", pal555to8, PAL555_SIZE);
} }
void MakeSwizzledPalette(void)
{
int idx, lvl;
qbyte *pa;
// create swizzled palettes
for (lvl = 0; lvl < TRANS_LEVELS; lvl++)
{
pa = host_basepal;
for (idx = 0; idx < 256; idx++)
{
// create a b10r10g10 table for each alpha level
// may need some hacking due to the tendancy of
// identity merges becoming darker
swzpal[lvl][idx] = ( (pa[0] * lvl) >> 4 ) << 10; // red
swzpal[lvl][idx] |= ( (pa[1] * lvl) >> 4 ); // green
swzpal[lvl][idx] |= ( (pa[2] * lvl) >> 4 ) << 20; // blue
swzpal[lvl][idx] = swzpal[lvl][idx] & 0x3feffbff;
pa += 3;
}
}
}
void MediaSW_ShowFrame8bit(qbyte *framedata, int inwidth, int inheight, qbyte *palette) void MediaSW_ShowFrame8bit(qbyte *framedata, int inwidth, int inheight, qbyte *palette)
{ {
@ -466,13 +191,13 @@ void MediaSW_ShowFrame8bit(qbyte *framedata, int inwidth, int inheight, qbyte *p
fstep = (inwidth<<16)/vid.conwidth; fstep = (inwidth<<16)/vid.conwidth;
for (x=0 ; x<vid.conwidth ; x+=4) for (x=0 ; x<vid.conwidth ; x+=4)
{ {
dest[x] = FindPallete(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]); dest[x] = FindPalette(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]);
f += fstep; f += fstep;
dest[x+1] = FindPallete(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]); dest[x+1] = FindPalette(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]);
f += fstep; f += fstep;
dest[x+2] = FindPallete(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]); dest[x+2] = FindPalette(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]);
f += fstep; f += fstep;
dest[x+3] = FindPallete(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]); dest[x+3] = FindPalette(palette[src[(f>>16)]*3], palette[src[(f>>16)]*3+1], palette[src[(f>>16)]*3+2]);
f += fstep; f += fstep;
} }
} }
@ -570,13 +295,13 @@ void MediaSW_ShowFrameRGBA_32(qbyte *framedata, int inwidth, int inheight) //top
fstep = ((inwidth)*0x10000)/vid.conwidth; fstep = ((inwidth)*0x10000)/vid.conwidth;
for (x=0 ; x<vid.conwidth ; x+=4) for (x=0 ; x<vid.conwidth ; x+=4)
{ {
dest[x] = FindPallete(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]); dest[x] = FindPalette(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]);
f += fstep; f += fstep;
dest[x+1] = FindPallete(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]); dest[x+1] = FindPalette(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]);
f += fstep; f += fstep;
dest[x+2] = FindPallete(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]); dest[x+2] = FindPalette(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]);
f += fstep; f += fstep;
dest[x+3] = FindPallete(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]); dest[x+3] = FindPalette(src[(f>>16)*4], src[(f>>16)*4+1], src[(f>>16)*4+2]);
f += fstep; f += fstep;
} }
} }
@ -670,13 +395,13 @@ void MediaSW_ShowFrameBGR_24_Flip(qbyte *framedata, int inwidth, int inheight) /
fstep = ((inwidth)*0x10000)/vid.conwidth; fstep = ((inwidth)*0x10000)/vid.conwidth;
for (x=0 ; x<vid.conwidth ; x+=4) for (x=0 ; x<vid.conwidth ; x+=4)
{ {
dest[x] = FindPallete(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]); dest[x] = FindPalette(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]);
f += fstep; f += fstep;
dest[x+1] = FindPallete(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]); dest[x+1] = FindPalette(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]);
f += fstep; f += fstep;
dest[x+2] = FindPallete(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]); dest[x+2] = FindPalette(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]);
f += fstep; f += fstep;
dest[x+3] = FindPallete(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]); dest[x+3] = FindPalette(src[(f>>16)*3+2], src[(f>>16)*3+1], src[(f>>16)*3]);
f += fstep; f += fstep;
} }
} }

View file

@ -320,11 +320,10 @@ void R_AliasPreparePoints (void)
else else
{ {
#if id386 #if id386
if (t_state & TT_ONE) drawfnc = D_PolysetDrawAsm;
drawfnc = D_PolysetDrawAsm; #else
else drawfnc = D_PolysetDrawC;
#endif #endif
drawfnc = D_PolysetDrawC;
} }
for (i=0 ; i<r_anumverts ; i++, fv++, av++, r_apnewverts++, r_apoldverts++) for (i=0 ; i<r_anumverts ; i++, fv++, av++, r_apnewverts++, r_apoldverts++)
@ -874,9 +873,26 @@ void R_AliasDrawModel (alight_t *plighting)
extern qbyte transfactor; extern qbyte transfactor;
extern qbyte transbackfac; extern qbyte transbackfac;
Set_TransLevelF(currententity->alpha); if (r_pixbytes == 1)
if (t_state & TT_ZERO) {
return; if (currententity->alpha < TRANS_LOWER_CAP)
return;
if (currententity->alpha > TRANS_UPPER_CAP)
{
transbackfac = 0;
}
else
{
D_SetTransLevel(currententity->alpha, BM_MERGE);
transbackfac = 1;
}
}
else
{
transfactor = currententity->alpha*255;
transbackfac = 255 - transfactor;
}
r_amodels_drawn++; r_amodels_drawn++;
@ -893,9 +909,6 @@ void R_AliasDrawModel (alight_t *plighting)
R_AliasSetupLighting (plighting); R_AliasSetupLighting (plighting);
R_AliasSetupFrame (); R_AliasSetupFrame ();
transfactor = currententity->alpha*255;
transbackfac = 255 - transfactor;
if (!currententity->colormap) if (!currententity->colormap)
currententity->colormap = vid.colormap; currententity->colormap = vid.colormap;
// Sys_Error ("R_AliasDrawModel: !currententity->colormap"); // Sys_Error ("R_AliasDrawModel: !currententity->colormap");

View file

@ -1703,6 +1703,7 @@ void R_16DrawSpanletAlphaTest( void ) //16 bit rendering only
} while (--s_spanletvars.spancount > 0); } while (--s_spanletvars.spancount > 0);
} }
#if 0
void R_8DrawSpanletBlended( void ) //8 bit FIXME void R_8DrawSpanletBlended( void ) //8 bit FIXME
{ {
unsigned btemp; unsigned btemp;
@ -1731,6 +1732,7 @@ void R_8DrawSpanletBlended( void ) //8 bit FIXME
s_spanletvars.t += s_spanletvars.tstep; s_spanletvars.t += s_spanletvars.tstep;
} while (--s_spanletvars.spancount > 0); } while (--s_spanletvars.spancount > 0);
} }
#endif
void R_32DrawSpanletAlphaTest( void ) void R_32DrawSpanletAlphaTest( void )
{ {

View file

@ -652,7 +652,7 @@ void SWR_DrawBeam(entity_t *e)
for (; len>=0; len--) for (; len>=0; len--)
{ {
VectorAdd(o1, dir, o2); VectorAdd(o1, dir, o2);
D_DrawSparkTrans (&p, o1, o2); D_DrawSparkTrans (&p, o1, o2, 0);
VectorCopy(o2, o1); VectorCopy(o2, o1);
} }
} }

View file

@ -652,8 +652,8 @@ void SWDraw_Character (int x, int y, unsigned int num)
} }
} }
#define FindPallete(r,g,b) palxxxto8[((r&palmask[0])>>palshift[0]) | ((g&palmask[1])<<palshift[1]) | ((b&palmask[2])<<palshift[2])] #define FindPalette(r,g,b) pal555to8[((r&0xF8)>>3)|((g&0xF8)<<2)|((b&0xF8)<<7)]
#define colourmask(p,r,g,b) FindPallete(host_basepal[p*3]*r, host_basepal[p*3+1]*g, host_basepal[p*3+2]*b) #define colourmask(p,r,g,b) FindPalette(host_basepal[p*3]*r, host_basepal[p*3+1]*g, host_basepal[p*3+2]*b)
#define draw(p) colourmask(p, (int)consolecolours[colour].r, (int)consolecolours[colour].g, (int)consolecolours[colour].b) #define draw(p) colourmask(p, (int)consolecolours[colour].r, (int)consolecolours[colour].g, (int)consolecolours[colour].b)
void SWDraw_ColouredCharacter (int x, int y, unsigned int num) void SWDraw_ColouredCharacter (int x, int y, unsigned int num)
{ {
@ -2374,11 +2374,7 @@ void SWDraw_FadeScreen (void)
VID_LockBuffer (); VID_LockBuffer ();
} }
#if 0
void SWDraw_Box(int x1, int y1, int x2, int y2, int paletteindex, float alpha) void SWDraw_Box(int x1, int y1, int x2, int y2, int paletteindex, float alpha)
{ {
int x; int x;
@ -2391,8 +2387,8 @@ void SWDraw_Box(int x1, int y1, int x2, int y2, int paletteindex, float alpha)
unsigned uc; unsigned uc;
int u, v; int u, v;
Set_TransLevelF(alpha); D_SetTransLevel(alpha, BM_MERGE);
if (t_state & TT_ZERO) if (alpha < TRANS_LOWER_CAP)
return; return;
if (x1 < x2) if (x1 < x2)
@ -2427,20 +2423,10 @@ void SWDraw_Box(int x1, int y1, int x2, int y2, int paletteindex, float alpha)
if (r_pixbytes == 1) if (r_pixbytes == 1)
{ {
if (t_state & TT_ONE) dest = vid.buffer + y*vid.rowbytes + x;
{ for (v=0 ; v<h ; v++, dest += vid.rowbytes)
dest = vid.buffer + y*vid.rowbytes + x; for (u=0 ; u<w ; u++)
for (v=0 ; v<h ; v++, dest += vid.rowbytes) dest[u] = Trans(dest[u], paletteindex);
for (u=0 ; u<w ; u++)
dest[u] = paletteindex;
}
else
{
dest = vid.buffer + y*vid.rowbytes + x;
for (v=0 ; v<h ; v++, dest += vid.rowbytes)
for (u=0 ; u<w ; u++)
dest[u] = Trans(dest[u], paletteindex);
}
} }
else if (r_pixbytes == 4) else if (r_pixbytes == 4)
{ {
@ -2452,6 +2438,7 @@ void SWDraw_Box(int x1, int y1, int x2, int y2, int paletteindex, float alpha)
puidest[u] = uc; puidest[u] = uc;
} }
} }
#endif
//============================================================================= //=============================================================================