diff --git a/src/hwrenderer/textures/hw_material.cpp b/src/hwrenderer/textures/hw_material.cpp index 48d313d95a..303c3e83a0 100644 --- a/src/hwrenderer/textures/hw_material.cpp +++ b/src/hwrenderer/textures/hw_material.cpp @@ -128,70 +128,6 @@ void IHardwareTexture::Resize(int swidth, int sheight, int width, int height, un } } -//=========================================================================== -// -// -// -//=========================================================================== - -float FTexCoordInfo::RowOffset(float rowoffset) const -{ - float tscale = fabs(mTempScale.Y); - float scale = fabs(mScale.Y); - - if (tscale == 1.f) - { - if (scale == 1.f || mWorldPanning) return rowoffset; - else return rowoffset / scale; - } - else - { - if (mWorldPanning) return rowoffset / tscale; - else return rowoffset / scale; - } -} - -//=========================================================================== -// -// -// -//=========================================================================== - -float FTexCoordInfo::TextureOffset(float textureoffset) const -{ - float tscale = fabs(mTempScale.X); - float scale = fabs(mScale.X); - if (tscale == 1.f) - { - if (scale == 1.f || mWorldPanning) return textureoffset; - else return textureoffset / scale; - } - else - { - if (mWorldPanning) return textureoffset / tscale; - else return textureoffset / scale; - } -} - -//=========================================================================== -// -// Returns the size for which texture offset coordinates are used. -// -//=========================================================================== - -float FTexCoordInfo::TextureAdjustWidth() const -{ - if (mWorldPanning) - { - float tscale = fabs(mTempScale.X); - if (tscale == 1.f) return (float)mRenderWidth; - else return mWidth / fabs(tscale); - } - else return (float)mWidth; -} - - - //=========================================================================== // // @@ -522,50 +458,6 @@ void FMaterial::PrecacheList(SpriteHits &translations) while(it.NextPair(pair)) screen->PrecacheMaterial(this, pair->Key); } -//=========================================================================== -// -// Retrieve texture coordinate info for per-wall scaling -// -//=========================================================================== - -void FMaterial::GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const -{ - if (x == 1.f) - { - tci->mRenderWidth = mRenderWidth; - tci->mScale.X = (float)tex->Scale.X; - tci->mTempScale.X = 1.f; - } - else - { - float scale_x = x * (float)tex->Scale.X; - tci->mRenderWidth = xs_CeilToInt(mWidth / scale_x); - tci->mScale.X = scale_x; - tci->mTempScale.X = x; - } - - if (y == 1.f) - { - tci->mRenderHeight = mRenderHeight; - tci->mScale.Y = (float)tex->Scale.Y; - tci->mTempScale.Y = 1.f; - } - else - { - float scale_y = y * (float)tex->Scale.Y; - tci->mRenderHeight = xs_CeilToInt(mHeight / scale_y); - tci->mScale.Y = scale_y; - tci->mTempScale.Y = y; - } - if (tex->bHasCanvas) - { - tci->mScale.Y = -tci->mScale.Y; - tci->mRenderHeight = -tci->mRenderHeight; - } - tci->mWorldPanning = tex->bWorldPanning; - tci->mWidth = mWidth; -} - //=========================================================================== // // diff --git a/src/hwrenderer/textures/hw_material.h b/src/hwrenderer/textures/hw_material.h index 4274426290..581368b55b 100644 --- a/src/hwrenderer/textures/hw_material.h +++ b/src/hwrenderer/textures/hw_material.h @@ -25,23 +25,6 @@ enum }; - -struct FTexCoordInfo -{ - int mRenderWidth; - int mRenderHeight; - int mWidth; - FVector2 mScale; - FVector2 mTempScale; - bool mWorldPanning; - - float FloatToTexU(float v) const { return v / mRenderWidth; } - float FloatToTexV(float v) const { return v / mRenderHeight; } - float RowOffset(float ofs) const; - float TextureOffset(float ofs) const; - float TextureAdjustWidth() const; -}; - //=========================================================================== // // this is the material class for OpenGL. @@ -130,7 +113,10 @@ public: *r = mSpriteRect; } - void GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const; + void GetTexCoordInfo(FTexCoordInfo *tci, float x, float y) const + { + tci->GetFromTexture(tex, x, y); + } void GetTexCoordInfo(FTexCoordInfo *tci, side_t *side, int texpos) const { diff --git a/src/p_3dmidtex.cpp b/src/p_3dmidtex.cpp index 0a4c5507de..7a2363be67 100644 --- a/src/p_3dmidtex.cpp +++ b/src/p_3dmidtex.cpp @@ -232,13 +232,12 @@ bool P_GetMidTexturePosition(const line_t *line, int sideno, double *ptextop, do FTexture * tex= TexMan(texnum); if (!tex) return false; - double totalscale = fabs(side->GetTextureYScale(side_t::mid)) * tex->GetScaleY(); - double y_offset = side->GetTextureYOffset(side_t::mid); - double textureheight = tex->GetHeight() / totalscale; - if (totalscale != 1. && !tex->bWorldPanning) - { - y_offset /= totalscale; - } + FTexCoordInfo tci; + + // We only need the vertical positioning info here. + tci.GetFromTexture(tex, 1., (float)side->GetTextureYScale(side_t::mid)); + double y_offset = tci.RowOffset((float)side->GetTextureYOffset(side_t::mid)); + double textureheight = tci.mRenderHeight; if(line->flags & ML_DONTPEGBOTTOM) { diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 047a9b2055..75b7e5e7d2 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -1543,3 +1543,119 @@ CCMD (printspans) #endif +//=========================================================================== +// +// Coordinate helper. +// The only reason this is even needed is that many years ago someone +// was convinced that having per-texel panning on walls was a good idea. +// If it wasn't for this relatively useless feature the entire positioning +// code for wall textures could be a lot simpler. +// +//=========================================================================== + +//=========================================================================== +// +// +// +//=========================================================================== + +float FTexCoordInfo::RowOffset(float rowoffset) const +{ + float tscale = fabs(mTempScale.Y); + float scale = fabs(mScale.Y); + + if (tscale == 1.f) + { + if (scale == 1.f || mWorldPanning) return rowoffset; + else return rowoffset / scale; + } + else + { + if (mWorldPanning) return rowoffset / tscale; + else return rowoffset / scale; + } +} + +//=========================================================================== +// +// +// +//=========================================================================== + +float FTexCoordInfo::TextureOffset(float textureoffset) const +{ + float tscale = fabs(mTempScale.X); + float scale = fabs(mScale.X); + if (tscale == 1.f) + { + if (scale == 1.f || mWorldPanning) return textureoffset; + else return textureoffset / scale; + } + else + { + if (mWorldPanning) return textureoffset / tscale; + else return textureoffset / scale; + } +} + +//=========================================================================== +// +// Returns the size for which texture offset coordinates are used. +// +//=========================================================================== + +float FTexCoordInfo::TextureAdjustWidth() const +{ + if (mWorldPanning) + { + float tscale = fabs(mTempScale.X); + if (tscale == 1.f) return (float)mRenderWidth; + else return mWidth / fabs(tscale); + } + else return (float)mWidth; +} + + +//=========================================================================== +// +// Retrieve texture coordinate info for per-wall scaling +// +//=========================================================================== + +void FTexCoordInfo::GetFromTexture(FTexture *tex, float x, float y) +{ + if (x == 1.f) + { + mRenderWidth = tex->GetScaledWidth(); + mScale.X = (float)tex->Scale.X; + mTempScale.X = 1.f; + } + else + { + float scale_x = x * (float)tex->Scale.X; + mRenderWidth = xs_CeilToInt(tex->GetWidth() / scale_x); + mScale.X = scale_x; + mTempScale.X = x; + } + + if (y == 1.f) + { + mRenderHeight = tex->GetScaledHeight(); + mScale.Y = (float)tex->Scale.Y; + mTempScale.Y = 1.f; + } + else + { + float scale_y = y * (float)tex->Scale.Y; + mRenderHeight = xs_CeilToInt(tex->GetHeight() / scale_y); + mScale.Y = scale_y; + mTempScale.Y = y; + } + if (tex->bHasCanvas) + { + mScale.Y = -mScale.Y; + mRenderHeight = -mRenderHeight; + } + mWorldPanning = tex->bWorldPanning; + mWidth = tex->GetWidth(); +} diff --git a/src/textures/textures.h b/src/textures/textures.h index d064441d1d..fc70ef1229 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -211,6 +211,7 @@ enum FTextureFormat : uint32_t TEX_Count }; + // Base texture class class FTexture { @@ -802,6 +803,24 @@ public: extern FTextureManager TexMan; +struct FTexCoordInfo +{ + int mRenderWidth; + int mRenderHeight; + int mWidth; + FVector2 mScale; + FVector2 mTempScale; + bool mWorldPanning; + + float FloatToTexU(float v) const { return v / mRenderWidth; } + float FloatToTexV(float v) const { return v / mRenderHeight; } + float RowOffset(float ofs) const; + float TextureOffset(float ofs) const; + float TextureAdjustWidth() const; + void GetFromTexture(FTexture *tex, float x, float y); +}; + + #endif