Skip to content

Commit

Permalink
- better handling of texture clamp state.
Browse files Browse the repository at this point in the history
Free combination of clamping with all texture modes still missing in GLES and Softpoly renderers!
  • Loading branch information
coelckers committed Sep 19, 2021
1 parent 3acc5a2 commit a0043ec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/common/rendering/gles/gles_renderstate.cpp
Expand Up @@ -127,7 +127,8 @@ bool FGLRenderState::ApplyShader()

ShaderFlavourData flavour;

flavour.textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode);
flavour.textureMode = (mTextureMode == TM_NORMAL && mTempTM == TM_OPAQUE ? TM_OPAQUE : mTextureMode) & 0xff;
if (mTextureClamp && flavour.textureMode == TM_NORMAL) flavour.textureMode = 5; // fixme. Clamp can now be combined with all modes.

if (flavour.textureMode == -1)
flavour.textureMode = 0;
Expand Down
11 changes: 9 additions & 2 deletions src/common/rendering/hwrenderer/data/hw_renderstate.h
Expand Up @@ -219,6 +219,7 @@ class FRenderState
int mLightIndex;
int mSpecialEffect;
int mTextureMode;
int mTextureClamp;
int mTextureModeFlags;
int mSoftLight;
float mLightParms[4];
Expand Down Expand Up @@ -259,6 +260,7 @@ class FRenderState
mFogColor = 0xffffffff;
mStreamData.uFogColor = mFogColor;
mTextureMode = -1;
mTextureClamp = 0;
mTextureModeFlags = 0;
mStreamData.uDesaturationFactor = 0.0f;
mAlphaThreshold = 0.5f;
Expand Down Expand Up @@ -344,12 +346,18 @@ class FRenderState
mStreamData.uDesaturationFactor = 0.0f;
}

void SetTextureClamp(bool on)
{
if (on) mTextureClamp = TM_CLAMPY;
else mTextureClamp = 0;
}

void SetTextureMode(int mode)
{
mTextureMode = mode;
}

void SetTextureMode(FRenderStyle style, bool clampy = false)
void SetTextureMode(FRenderStyle style)
{
if (style.Flags & STYLEF_RedIsAlpha)
{
Expand All @@ -363,7 +371,6 @@ class FRenderState
{
SetTextureMode(TM_INVERSE);
}
if (clampy) mTextureMode |= TM_CLAMPY;
}

int GetTextureMode()
Expand Down
7 changes: 5 additions & 2 deletions src/common/rendering/polyrenderer/drawers/screen_shader.cpp
Expand Up @@ -380,7 +380,11 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread)
{
auto constants = thread->PushConstants;

switch (constants->uTextureMode)
if (constants->uTextureMode == TM_CLAMPY)
{
FuncNormal_ClampY(x0, x1, thread);
}
else switch (constants->uTextureMode & 0xff)
{
default:
case TM_NORMAL:
Expand All @@ -389,7 +393,6 @@ static void ProcessMaterial(int x0, int x1, PolyTriangleThreadData* thread)
case TM_OPAQUE: FuncNormal_Opaque(x0, x1, thread); break;
case TM_INVERSE: FuncNormal_Inverse(x0, x1, thread); break;
case TM_ALPHATEXTURE: FuncNormal_AlphaTexture(x0, x1, thread); break;
case TM_CLAMPY: FuncNormal_ClampY(x0, x1, thread); break;
case TM_INVERTOPAQUE: FuncNormal_InvertOpaque(x0, x1, thread); break;
}

Expand Down
4 changes: 3 additions & 1 deletion src/rendering/hwrenderer/scene/hw_decal.cpp
Expand Up @@ -61,7 +61,7 @@ void HWDecal::DrawDecal(HWDrawInfo *di, FRenderState &state)
state.SetObjectColor(DecalColor);

state.SetLightIndex(dynlightindex);
state.SetTextureMode(decal->RenderStyle, true);
state.SetTextureMode(decal->RenderStyle);
state.SetRenderStyle(decal->RenderStyle);
state.SetMaterial(texture, UF_Sprite, 0, CLAMP_XY, decal->Translation, -1);

Expand Down Expand Up @@ -129,6 +129,7 @@ void HWDrawInfo::DrawDecals(FRenderState &state, TArray<HWDecal *> &decals)
{
side_t *wall = nullptr;
state.SetDepthMask(false);
state.SetTextureClamp(true);
state.SetDepthBias(-1, -128);
for (auto gldecal : decals)
{
Expand All @@ -151,6 +152,7 @@ void HWDrawInfo::DrawDecals(FRenderState &state, TArray<HWDecal *> &decals)
state.ClearDepthBias();
state.SetTextureMode(TM_NORMAL);
state.SetDepthMask(true);
state.SetTextureClamp(false);
}

//==========================================================================
Expand Down
3 changes: 2 additions & 1 deletion src/rendering/hwrenderer/scene/hw_walls.cpp
Expand Up @@ -210,7 +210,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)

if (flags & HWWall::HWF_CLAMPY && (type == RENDERWALL_M2S || type == RENDERWALL_M2SNF))
{
state.SetTextureMode(tmode | TM_CLAMPY);
state.SetTextureClamp(true);
}

if (type == RENDERWALL_M2SNF)
Expand Down Expand Up @@ -300,6 +300,7 @@ void HWWall::RenderTexturedWall(HWDrawInfo *di, FRenderState &state, int rflags)
state.SetObjectColor2(0);
state.SetAddColor(0);
state.SetTextureMode(tmode);
state.SetTextureClamp(false);
state.EnableGlow(false);
state.EnableGradient(false);
state.ApplyTextureManipulation(nullptr);
Expand Down

0 comments on commit a0043ec

Please sign in to comment.