Skip to content

Commit fcba3c7

Browse files
authored
Merge pull request #580 from pzgulyas/samplerstates
SamplerStates can only be set after the ShaderPasses.Current.Apply().
2 parents b00b918 + a80269a commit fcba3c7

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

Source/RunActivity/Viewer3D/Forest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
426426

427427
// Enable alpha blending for everything: this allows distance scenery to appear smoothly.
428428
graphicsDevice.BlendState = BlendState.NonPremultiplied;
429-
graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
430429
}
431430

432431
public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderItem> renderItems, ref Matrix XNAViewMatrix, ref Matrix XNAProjectionMatrix)
@@ -443,6 +442,10 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
443442
shader.SetMatrix(item.XNAMatrix, ref viewproj);
444443
shader.ZBias = item.RenderPrimitive.ZBias;
445444
ShaderPasses.Current.Apply();
445+
446+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
447+
graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
448+
446449
item.RenderPrimitive.Draw(graphicsDevice);
447450
}
448451
}

Source/RunActivity/Viewer3D/Materials.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,6 @@ public bool LoadDayTexture ()
789789
public override void SetState(GraphicsDevice graphicsDevice, Material previousMaterial)
790790
{
791791
graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
792-
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
793792

794793
var shader = Viewer.MaterialManager.SceneryShader;
795794
var level9_3 = Viewer.Settings.IsDirectXFeatureLevelIncluded(ORTS.Settings.UserSettings.DirectXFeature.Level9_3);
@@ -889,8 +888,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
889888
throw new InvalidDataException("Options has unexpected SceneryMaterialOptions.SpecularMask value.");
890889
}
891890

892-
graphicsDevice.SamplerStates[0] = GetShadowTextureAddressMode();
893-
894891
if (NightTexture != null && NightTexture != SharedMaterialManager.MissingTexture && (((Options & SceneryMaterialOptions.UndergroundTexture) != 0 &&
895892
(Viewer.MaterialManager.sunDirection.Y < -0.085f || Viewer.Camera.IsUnderground)) || Viewer.MaterialManager.sunDirection.Y < 0.0f - ((float)KeyLengthRemainder()) / 5000f))
896893
{
@@ -917,6 +914,10 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
917914
shader.SetMatrix(item.XNAMatrix, ref viewProj);
918915
shader.ZBias = item.RenderPrimitive.ZBias;
919916
ShaderPasses.Current.Apply();
917+
918+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
919+
graphicsDevice.SamplerStates[0] = GetShadowTextureAddressMode();
920+
920921
item.RenderPrimitive.Draw(graphicsDevice);
921922
}
922923
}
@@ -1059,8 +1060,9 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
10591060
{
10601061
var wvp = item.XNAMatrix * viewproj;
10611062
shader.SetData(ref wvp, item.Material.GetShadowTexture());
1062-
graphicsDevice.SamplerStates[0] = item.Material.GetShadowTextureAddressMode();
10631063
ShaderPasses.Current.Apply();
1064+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
1065+
graphicsDevice.SamplerStates[0] = item.Material.GetShadowTextureAddressMode();
10641066
item.RenderPrimitive.Draw(graphicsDevice);
10651067
}
10661068
}

Source/RunActivity/Viewer3D/Terrain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
524524
shader.OverlayTexture = PatchTextureOverlay;
525525
shader.OverlayScale = OverlayScale;
526526

527-
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
528527
graphicsDevice.BlendState = BlendState.NonPremultiplied;
529528
}
530529

@@ -541,6 +540,8 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
541540
shader.SetMatrix(item.XNAMatrix, ref viewproj);
542541
shader.ZBias = item.RenderPrimitive.ZBias;
543542
ShaderPasses.Current.Apply();
543+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
544+
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
544545
item.RenderPrimitive.Draw(graphicsDevice);
545546
}
546547
}

Source/RunActivity/Viewer3D/Transfers.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
171171
shader.ImageTexture = Texture;
172172
shader.ReferenceAlpha = 10;
173173

174-
graphicsDevice.SamplerStates[0] = TransferSamplerState;
175174
graphicsDevice.BlendState = BlendState.NonPremultiplied;
176175
graphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
177176
}
@@ -190,6 +189,8 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
190189
shader.SetMatrix(item.XNAMatrix, ref viewproj);
191190
shader.ZBias = item.RenderPrimitive.ZBias;
192191
ShaderPasses.Current.Apply();
192+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
193+
graphicsDevice.SamplerStates[0] = TransferSamplerState;
193194
item.RenderPrimitive.Draw(graphicsDevice);
194195
}
195196
}

Source/RunActivity/Viewer3D/Water.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
179179
shader.ImageTexture = WaterTexture;
180180
shader.ReferenceAlpha = 10;
181181

182-
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
183182
graphicsDevice.BlendState = BlendState.NonPremultiplied;
184183
}
185184

@@ -196,6 +195,8 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
196195
shader.SetMatrix(item.XNAMatrix, ref viewproj);
197196
shader.ZBias = item.RenderPrimitive.ZBias;
198197
ShaderPasses.Current.Apply();
198+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
199+
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
199200
item.RenderPrimitive.Draw(graphicsDevice);
200201
}
201202
}

0 commit comments

Comments
 (0)