Skip to content

Commit ae9b906

Browse files
authored
Merge pull request #154 from ZehMatt/fix-matsys-config-update
Fix matsys config update
2 parents a21c753 + 205805e commit ae9b906

7 files changed

Lines changed: 26 additions & 12 deletions

File tree

‎Source.Common/MaterialSystem/ITextureInternal.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public static ReadOnlySpan<char> NormalizeTextureName(ReadOnlySpan<char> name, S
2727
void Bind(Sampler sampler, int frame);
2828
int GetTextureHandle(int frame, int textureChannel = 0);
2929
void OnRestore();
30+
void SetFilteringAndClampingMode(bool onlyLodValues = false);
3031
void Precache();
3132
bool SetRenderTarget(int rt, ITexture? depthTexture = null);
3233
void CopyFrameBufferToMe(int renderTargetID = 0, Rectangle? srcRect = null, Rectangle? dstRect = null);
@@ -77,6 +78,7 @@ public void Dispose() { }
7778
public void Bind(Sampler sampler, int frame) => throw new NotSupportedException();
7879
public int GetTextureHandle(int v) => throw new NotSupportedException();
7980
public void OnRestore() => throw new NotSupportedException();
81+
public void SetFilteringAndClampingMode(bool onlyLodValues = false) => throw new NotSupportedException();
8082
public void Precache() => throw new NotSupportedException();
8183
public bool SetRenderTarget(int rt, ITexture? depthTexture = null) => throw new NotSupportedException();
8284
public void GetReflectivity(out Vector3 reflectivity) => throw new NotSupportedException();

‎Source.Engine/MatSysInterface.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ static void mat_savechanges(in TokenizedCommand args) {
11421142
WriteMaterialSystemConfigToRegistry(MaterialSystemConfig);
11431143
}
11441144

1145-
static void UpdateMaterialSystemConfig() {
1145+
internal static void UpdateMaterialSystemConfig() {
11461146
if (host_state.WorldBrush != null && host_state.WorldBrush.LightData?.Length == 0)
11471147
mat_fullbright.SetValue(1);
11481148

‎Source.Engine/Render.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ public void LevelInit() {
330330
g_ShadowMgr.LevelInit(host_state.WorldBrush!.NumSurfaces);
331331
}
332332

333+
UpdateMaterialSystemConfig();
334+
333335
LoadWorldGeometry();
334336

335337
Surface_LevelInit();

‎Source.MaterialSystem/MaterialSystem.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ public class MaterialSystem : IMaterialSystemInternal, IShaderUtil
6262

6363
readonly static ConVar mat_vsync = new("mat_vsync", "0", 0, "Force sync to vertical retrace", 0, 1);
6464
readonly static ConVar mat_forcehardwaresync = new(IsPC() ? "1" : "0", 0);
65-
readonly static ConVar mat_trilinear = new("0", 0);
66-
readonly static ConVar mat_forceaniso = new("1", FCvar.Archive); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso
65+
readonly static ConVar mat_trilinear = new("1", 0);
66+
readonly static ConVar mat_forceaniso = new("16", FCvar.Archive); // 0 = Bilinear, 1 = Trilinear, 2+ = Aniso
6767
readonly static ConVar mat_filterlightmaps = new("1", 0);
6868
readonly static ConVar mat_filtertextures = new("1", 0);
6969
readonly static ConVar mat_mipmaptextures = new("1", 0);
@@ -303,23 +303,23 @@ public bool OverrideConfig(MaterialSystem_Config config, bool forceUpdate) {
303303
if (reloadMaterials)
304304
ReloadMaterials();
305305

306+
if (resetAnisotropy)
307+
ShaderAPI.SetAnisotropicLevel(config.ForceAnisotropicLevel);
308+
306309
if (redownloadTextures) {
307310
if (ShaderAPI.CanDownloadTextures()) {
308311
TextureSystem.RestoreRenderTargets();
309312
TextureSystem.RestoreNonRenderTargetTextures();
310313
}
311314
}
312315
else if (resetTextureFilter) {
313-
// TextureSystem.ResetTextureFilteringState();
316+
TextureSystem.ResetTextureFilteringState();
314317
}
315318

316319
// Recompute all state snapshots
317320
if (recomputeSnapshots)
318321
RecomputeAllStateSnapshots();
319322

320-
// if (resetAnisotropy)
321-
// ShaderAPI.SetAnisotropicLevel(config.ForceAnisotropicLevel);
322-
323323
// if (setStandardVertexShaderConstants)
324324
// ShaderAPI.SetStandardVertexShaderConstants(IMaterialSystem.OVERBRIGHT);
325325

‎Source.MaterialSystem/Texture.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ private void DownloadTexture(Rectangle rect, bool copyFromCurrent = false) {
328328
ActualDimensionLimit = DesiredDimensionLimit;
329329
}
330330

331-
private void SetFilteringAndClampingMode(bool onlyLodValues = false) {
331+
public void SetFilteringAndClampingMode(bool onlyLodValues = false) {
332332
if (!HasBeenAllocated())
333333
return;
334334

‎Source.MaterialSystem/TextureManager.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ internal void RestoreNonRenderTargetTextures() {
161161
RestoreTexture(tex.Value);
162162
}
163163

164+
internal void ResetTextureFilteringState() {
165+
foreach (var tex in TextureList)
166+
tex.Value.SetFilteringAndClampingMode();
167+
}
168+
164169
internal void AllocateStandardRenderTargets() {
165170
MaterialSystem.BeginRenderTargetAllocation();
166171
MaterialSystem.EndRenderTargetAllocation();

‎Source.ShaderAPI.Gl46/ShaderAPIGl46.cs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,7 +1757,7 @@ unsafe void ApplyForcedFilter(Sampler sampler, ShaderAPITextureHandle_t textureH
17571757
glSamplerParameteri(samplerObject, GL_TEXTURE_MIN_FILTER, mipped ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST);
17581758
break;
17591759
case 3:
1760-
glSamplerParameterf(samplerObject, GL_TEXTURE_MAX_ANISOTROPY, HardwareConfig.MaximumAnisotropicLevel());
1760+
glSamplerParameterf(samplerObject, GL_TEXTURE_MAX_ANISOTROPY, AnisotropicLevel);
17611761
glSamplerParameteri(samplerObject, GL_TEXTURE_MIN_FILTER, mipped ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR);
17621762
break;
17631763
default:
@@ -2640,7 +2640,7 @@ public void TexMinFilter(TexFilterMode mode) {
26402640
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
26412641
break;
26422642
case TexFilterMode.Anisotropic:
2643-
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY, HardwareConfig.MaximumAnisotropicLevel());
2643+
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY, AnisotropicLevel);
26442644
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
26452645
break;
26462646
default:
@@ -2670,7 +2670,7 @@ public void TexMagFilter(TexFilterMode mode) {
26702670
break;
26712671
case TexFilterMode.Anisotropic:
26722672
glTextureParameteri(GetModifyTexture(), GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2673-
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
2673+
glTextureParameterf(GetModifyTexture(), GL_TEXTURE_MAX_ANISOTROPY_EXT, AnisotropicLevel);
26742674
break;
26752675
default:
26762676
break;
@@ -3251,8 +3251,13 @@ public int SelectionMode(bool selectionMode) {
32513251
throw new NotImplementedException("Incomplete port of IShaderAPI");
32523252
}
32533253

3254+
int AnisotropicLevel = 1;
32543255
public void SetAnisotropicLevel(int anisotropyLevel) {
3255-
throw new NotImplementedException("Incomplete port of IShaderAPI");
3256+
int maxAnisotropy = HardwareConfig.MaximumAnisotropicLevel();
3257+
if (anisotropyLevel > maxAnisotropy || anisotropyLevel <= 1)
3258+
anisotropyLevel = Math.Max(2, Math.Min(8, maxAnisotropy / 4));
3259+
3260+
AnisotropicLevel = anisotropyLevel;
32563261
}
32573262

32583263
public void SetClipPlane(int index, ReadOnlySpan<float> plane) {

0 commit comments

Comments
 (0)