From 5bf806e478a9e87de885db86266d10533172e555 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 24 Mar 2016 16:16:45 +0100 Subject: [PATCH] - renamed some fixed point stuff in the texture composition code. --- src/p_3dmidtex.cpp | 6 +++--- src/textures/bitmap.cpp | 12 ++++++------ src/textures/bitmap.h | 24 ++++++++++++++++-------- src/textures/multipatchtexture.cpp | 14 +++++++------- src/textures/textures.h | 4 +++- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/p_3dmidtex.cpp b/src/p_3dmidtex.cpp index ffeb32e6f1..b86e46e2d6 100644 --- a/src/p_3dmidtex.cpp +++ b/src/p_3dmidtex.cpp @@ -230,12 +230,12 @@ bool P_GetMidTexturePosition(const line_t *line, int sideno, fixed_t *ptextop, f FTexture * tex= TexMan(texnum); if (!tex) return false; - fixed_t totalscale = abs(FixedMul(side->GetTextureYScale(side_t::mid), tex->yScale)); + double totalscale = fabs(FIXED2DBL(side->GetTextureYScale(side_t::mid)) * tex->GetScaleY()); fixed_t y_offset = side->GetTextureYOffset(side_t::mid); fixed_t textureheight = tex->GetScaledHeight(totalscale) << FRACBITS; - if (totalscale != FRACUNIT && !tex->bWorldPanning) + if (totalscale != 1. && !tex->bWorldPanning) { - y_offset = FixedDiv(y_offset, totalscale); + y_offset = fixed_t(y_offset * totalscale); } if(line->flags & ML_DONTPEGBOTTOM) diff --git a/src/textures/bitmap.cpp b/src/textures/bitmap.cpp index 346ffd65eb..7873e35cb6 100644 --- a/src/textures/bitmap.cpp +++ b/src/textures/bitmap.cpp @@ -146,9 +146,9 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in a = TSrc::A(pin, tr, tg, tb); if (TBlend::ProcessAlpha0() || a) { - r = (TSrc::R(pin)*inf->blendcolor[0])>>FRACBITS; - g = (TSrc::G(pin)*inf->blendcolor[1])>>FRACBITS; - b = (TSrc::B(pin)*inf->blendcolor[2])>>FRACBITS; + r = (TSrc::R(pin)*inf->blendcolor[0])>>BLENDBITS; + g = (TSrc::G(pin)*inf->blendcolor[1])>>BLENDBITS; + b = (TSrc::B(pin)*inf->blendcolor[2])>>BLENDBITS; TBlend::OpC(pout[TDest::RED], r, a, inf); TBlend::OpC(pout[TDest::GREEN], g, a, inf); @@ -167,9 +167,9 @@ void iCopyColors(BYTE *pout, const BYTE *pin, int count, int step, FCopyInfo *in a = TSrc::A(pin, tr, tg, tb); if (TBlend::ProcessAlpha0() || a) { - r = (TSrc::R(pin)*inf->blendcolor[3] + inf->blendcolor[0]) >> FRACBITS; - g = (TSrc::G(pin)*inf->blendcolor[3] + inf->blendcolor[1]) >> FRACBITS; - b = (TSrc::B(pin)*inf->blendcolor[3] + inf->blendcolor[2]) >> FRACBITS; + r = (TSrc::R(pin)*inf->blendcolor[3] + inf->blendcolor[0]) >> BLENDBITS; + g = (TSrc::G(pin)*inf->blendcolor[3] + inf->blendcolor[1]) >> BLENDBITS; + b = (TSrc::B(pin)*inf->blendcolor[3] + inf->blendcolor[2]) >> BLENDBITS; TBlend::OpC(pout[TDest::RED], r, a, inf); TBlend::OpC(pout[TDest::GREEN], g, a, inf); diff --git a/src/textures/bitmap.h b/src/textures/bitmap.h index 8519c8b800..27d3c0b4ba 100644 --- a/src/textures/bitmap.h +++ b/src/textures/bitmap.h @@ -48,6 +48,14 @@ struct FClipRect bool Intersect(int ix, int iy, int iw, int ih); }; +typedef int blend_t; + +enum +{ + BLENDBITS = 16, + BLENDUNIT = (1<alpha) >> FRACBITS; } + static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = (s*i->alpha) >> BLENDBITS; } static __forceinline bool ProcessAlpha0() { return false; } }; @@ -380,28 +388,28 @@ struct bOverlay struct bBlend { - static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (d*i->invalpha + s*i->alpha) >> FRACBITS; } + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = (d*i->invalpha + s*i->alpha) >> BLENDBITS; } static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; struct bAdd { - static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MIN((d*FRACUNIT + s*i->alpha) >> FRACBITS, 255); } + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MIN((d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 255); } static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; struct bSubtract { - static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX((d*FRACUNIT - s*i->alpha) >> FRACBITS, 0); } + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX((d*BLENDUNIT - s*i->alpha) >> BLENDBITS, 0); } static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; struct bReverseSubtract { - static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX((-d*FRACUNIT + s*i->alpha) >> FRACBITS, 0); } + static __forceinline void OpC(BYTE &d, BYTE s, BYTE a, FCopyInfo *i) { d = MAX((-d*BLENDUNIT + s*i->alpha) >> BLENDBITS, 0); } static __forceinline void OpA(BYTE &d, BYTE s, FCopyInfo *i) { d = s; } static __forceinline bool ProcessAlpha0() { return false; } }; diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index 5a9b8d4913..31af81a56b 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -180,7 +180,7 @@ protected: FRemapTable *Translation; PalEntry Blend; FTexture *Texture; - fixed_t Alpha; + blend_t Alpha; TexPart(); }; @@ -593,7 +593,7 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rota memset (&info, 0, sizeof(info)); info.alpha = Parts[i].Alpha; - info.invalpha = OPAQUE - info.alpha; + info.invalpha = BLENDUNIT - info.alpha; info.op = ECopyOp(Parts[i].op); PalEntry b = Parts[i].Blend; if (b.a == 0 && b != BLEND_NONE) @@ -604,14 +604,14 @@ int FMultiPatchTexture::CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rota { if (b.a == 255) { - info.blendcolor[0] = b.r * FRACUNIT / 255; - info.blendcolor[1] = b.g * FRACUNIT / 255; - info.blendcolor[2] = b.b * FRACUNIT / 255; + info.blendcolor[0] = b.r * BLENDUNIT / 255; + info.blendcolor[1] = b.g * BLENDUNIT / 255; + info.blendcolor[2] = b.b * BLENDUNIT / 255; info.blend = BLEND_MODULATE; } else { - fixed_t blendalpha = b.a * FRACUNIT / 255; + blend_t blendalpha = b.a * BLENDUNIT / 255; info.blendcolor[0] = b.r * blendalpha; info.blendcolor[1] = b.g * blendalpha; info.blendcolor[2] = b.b * blendalpha; @@ -1165,7 +1165,7 @@ void FMultiPatchTexture::ParsePatch(FScanner &sc, TexPart & part, bool silent, i else if (sc.Compare("alpha")) { sc.MustGetFloat(); - part.Alpha = clamp(FLOAT2FIXED(sc.Float), 0, OPAQUE); + part.Alpha = clamp(int(sc.Float / BLENDUNIT), 0, BLENDUNIT); // bComplex is not set because it is only needed when the style is not OP_COPY. } else if (sc.Compare("style")) diff --git a/src/textures/textures.h b/src/textures/textures.h index 13f5b0eabc..0057214d60 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -2,6 +2,7 @@ #define __TEXTURES_H #include "doomtype.h" +#include "m_fixed.h" class FBitmap; struct FRemapTable; @@ -204,9 +205,10 @@ public: int GetScaledWidth () { int foo = (Width << 17) / xScale; return (foo >> 1) + (foo & 1); } int GetScaledHeight () { int foo = (Height << 17) / yScale; return (foo >> 1) + (foo & 1); } - int GetScaledHeight(fixed_t scale) { int foo = (Height << 17) / scale; return (foo >> 1) + (foo & 1); } + int GetScaledHeight(double scale) { return GetScaledHeight(FLOAT2FIXED(scale)); } double GetScaledWidthDouble () { return (Width * 65536.) / xScale; } double GetScaledHeightDouble () { return (Height * 65536.) / yScale; } + double GetScaleY() const { return FIXED2DBL(yScale); } int GetScaledLeftOffset () { int foo = (LeftOffset << 17) / xScale; return (foo >> 1) + (foo & 1); } int GetScaledTopOffset () { int foo = (TopOffset << 17) / yScale; return (foo >> 1) + (foo & 1); }