From b03d95c5c6ba63e15fe7aed7d3b5608e9dbfedc8 Mon Sep 17 00:00:00 2001 From: Jaime Passos Date: Tue, 27 Oct 2020 17:02:35 -0300 Subject: [PATCH] Bug fixes --- src/hardware/hw_main.c | 23 ++++++++++++++++++++--- src/hardware/hw_md2.c | 15 +++++---------- src/hardware/r_opengl/r_opengl.c | 10 ++++++++-- src/r_things.c | 10 +++++++--- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index fb8318e09..8a4274d68 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -722,6 +722,8 @@ FBITFIELD HWR_GetBlendModeFlag(INT32 ast) UINT8 HWR_GetTranstableAlpha(INT32 transtablenum) { + transtablenum = max(min(transtablenum, tr_trans90), 0); + switch (transtablenum) { case 0 : return 0xff; @@ -3787,7 +3789,12 @@ static void HWR_SplitSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(spr->mobj->blendmode); } else if (spr->mobj->frame & FF_TRANSMASK) - blend = HWR_SurfaceBlend(spr->mobj->blendmode, (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + { + INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + if (spr->mobj->blendmode == AST_TRANSLUCENT && trans >= NUMTRANSMAPS) + return; + blend = HWR_SurfaceBlend(spr->mobj->blendmode, trans, &Surf); + } else { // BP: i agree that is little better in environement but it don't @@ -4202,7 +4209,12 @@ static void HWR_DrawSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(spr->mobj->blendmode); } else if (spr->mobj->frame & FF_TRANSMASK) - blend = HWR_SurfaceBlend(spr->mobj->blendmode, (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + { + INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + if (spr->mobj->blendmode == AST_TRANSLUCENT && trans >= NUMTRANSMAPS) + return; + blend = HWR_SurfaceBlend(spr->mobj->blendmode, trans, &Surf); + } else { // BP: i agree that is little better in environement but it don't @@ -4317,7 +4329,12 @@ static inline void HWR_DrawPrecipitationSprite(gl_vissprite_t *spr) blend = HWR_GetBlendModeFlag(spr->mobj->blendmode); } else if (spr->mobj->frame & FF_TRANSMASK) - blend = HWR_SurfaceBlend(spr->mobj->blendmode, (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); + { + INT32 trans = (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT; + if (spr->mobj->blendmode == AST_TRANSLUCENT && trans >= NUMTRANSMAPS) + return; + blend = HWR_SurfaceBlend(spr->mobj->blendmode, trans, &Surf); + } else { // BP: i agree that is little better in environement but it don't diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 4358c5024..8ca38296a 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1316,21 +1316,16 @@ boolean HWR_DrawModel(gl_vissprite_t *spr) //if (tics > durs) //durs = tics; - if (spr->mobj->flags2 & MF2_SHADOW) - { - Surf.PolyColor.s.alpha = 0x40; - Surf.PolyFlags = HWR_GetBlendModeFlag(spr->mobj->blendmode); - } - else if (spr->mobj->frame & FF_TRANSMASK) + if (spr->mobj->frame & FF_TRANSMASK) Surf.PolyFlags = HWR_SurfaceBlend(spr->mobj->blendmode, (spr->mobj->frame & FF_TRANSMASK)>>FF_TRANSSHIFT, &Surf); else { - Surf.PolyColor.s.alpha = 0xFF; - Surf.PolyFlags = 0; + Surf.PolyColor.s.alpha = (spr->mobj->flags2 & MF2_SHADOW) ? 0x40 : 0xff; + Surf.PolyFlags = HWR_GetBlendModeFlag(spr->mobj->blendmode); } - // dont forget to enabled the depth test because we can't do this like - // before: polygons models are not sorted + // don't forget to enable the depth test because we can't do this + // like before: model polygons are not sorted // 1. load model+texture if not already loaded // 2. draw model with correct position, rotation,... diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index e3f7e714b..728c59f64 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2600,6 +2600,7 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 boolean useVBO = true; + FBITFIELD flags; int i; // Because otherwise, scaling the screen negatively vertically breaks the lighting @@ -2667,8 +2668,6 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 else pglColor4ubv((GLubyte*)&Surface->PolyColor.s); - SetBlend((poly.alpha < 1 ? Surface->PolyFlags : (PF_Masked|PF_Occlude))|PF_Modulated); - tint.red = byte2float[Surface->TintColor.s.red]; tint.green = byte2float[Surface->TintColor.s.green]; tint.blue = byte2float[Surface->TintColor.s.blue]; @@ -2679,6 +2678,13 @@ static void DrawModelEx(model_t *model, INT32 frameIndex, INT32 duration, INT32 fade.blue = byte2float[Surface->FadeColor.s.blue]; fade.alpha = byte2float[Surface->FadeColor.s.alpha]; + flags = (Surface->PolyFlags | PF_Modulated); + if (Surface->PolyFlags & (PF_Additive|PF_AdditiveSource|PF_Subtractive|PF_ReverseSubtract|PF_Multiplicative)) + flags |= PF_Occlude; + else if (Surface->PolyColor.s.alpha == 0xFF) + flags |= (PF_Occlude | PF_Masked); + + SetBlend(flags); Shader_Load(Surface, &poly, &tint, &fade); pglEnable(GL_CULL_FACE); diff --git a/src/r_things.c b/src/r_things.c index b85e4dfdc..916d2e891 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1802,7 +1802,11 @@ static void R_ProjectSprite(mobj_t *thing) if (oldthing->flags2 & MF2_SHADOW || thing->flags2 & MF2_SHADOW) // actually only the player should use this (temporary invisibility) trans = tr_trans80; // because now the translucency is set through FF_TRANSMASK else if (oldthing->frame & FF_TRANSMASK) + { trans = (oldthing->frame & FF_TRANSMASK) >> FF_TRANSSHIFT; + if (oldthing->blendmode == AST_TRANSLUCENT && trans >= NUMTRANSMAPS) + return; + } else trans = 0; @@ -1834,7 +1838,7 @@ static void R_ProjectSprite(mobj_t *thing) else trans += 3; - if (trans >= 9) + if (trans >= NUMTRANSMAPS) return; trans--; @@ -2007,8 +2011,8 @@ static void R_ProjectSprite(mobj_t *thing) vis->scale += FixedMul(scalestep, spriteyscale) * (vis->x1 - x1); } - if ((thing->blendmode != AST_COPY) && cv_translucency.value) - vis->transmap = R_GetBlendTable(thing->blendmode, trans); + if ((oldthing->blendmode != AST_COPY) && cv_translucency.value) + vis->transmap = R_GetBlendTable(oldthing->blendmode, trans); else vis->transmap = NULL;