Skip to content

Commit a80269a

Browse files
committed
SamplerStates can only be set after the ShaderPasses.Current.Apply().
1 parent 0c860a3 commit a80269a

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
@@ -786,7 +786,6 @@ public bool LoadDayTexture ()
786786
public override void SetState(GraphicsDevice graphicsDevice, Material previousMaterial)
787787
{
788788
graphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
789-
graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
790789

791790
var shader = Viewer.MaterialManager.SceneryShader;
792791
var level9_3 = Viewer.Settings.IsDirectXFeatureLevelIncluded(ORTS.Settings.UserSettings.DirectXFeature.Level9_3);
@@ -886,8 +885,6 @@ public override void SetState(GraphicsDevice graphicsDevice, Material previousMa
886885
throw new InvalidDataException("Options has unexpected SceneryMaterialOptions.SpecularMask value.");
887886
}
888887

889-
graphicsDevice.SamplerStates[0] = GetShadowTextureAddressMode();
890-
891888
if (NightTexture != null && NightTexture != SharedMaterialManager.MissingTexture && (((Options & SceneryMaterialOptions.UndergroundTexture) != 0 &&
892889
(Viewer.MaterialManager.sunDirection.Y < -0.085f || Viewer.Camera.IsUnderground)) || Viewer.MaterialManager.sunDirection.Y < 0.0f - ((float)KeyLengthRemainder()) / 5000f))
893890
{
@@ -914,6 +911,10 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
914911
shader.SetMatrix(item.XNAMatrix, ref viewProj);
915912
shader.ZBias = item.RenderPrimitive.ZBias;
916913
ShaderPasses.Current.Apply();
914+
915+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
916+
graphicsDevice.SamplerStates[0] = GetShadowTextureAddressMode();
917+
917918
item.RenderPrimitive.Draw(graphicsDevice);
918919
}
919920
}
@@ -1056,8 +1057,9 @@ public override void Render(GraphicsDevice graphicsDevice, IEnumerable<RenderIte
10561057
{
10571058
var wvp = item.XNAMatrix * viewproj;
10581059
shader.SetData(ref wvp, item.Material.GetShadowTexture());
1059-
graphicsDevice.SamplerStates[0] = item.Material.GetShadowTextureAddressMode();
10601060
ShaderPasses.Current.Apply();
1061+
// SamplerStates can only be set after the ShaderPasses.Current.Apply().
1062+
graphicsDevice.SamplerStates[0] = item.Material.GetShadowTextureAddressMode();
10611063
item.RenderPrimitive.Draw(graphicsDevice);
10621064
}
10631065
}

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)