Source/Contrib/TrackViewer/Drawing/BasicShapes.cs | 10 +++---- Source/Contrib/TrackViewer/Drawing/DrawColors.cs | 1 + Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs | 32 +++++++++++----------- .../Contrib/TrackViewer/Drawing/ShadowDrawArea.cs | 8 ++++-- Source/Contrib/TrackViewer/Program.cs | 7 +++++ Source/Contrib/TrackViewer/TrackViewer.cs | 15 ++++++---- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Source/Contrib/TrackViewer/Drawing/BasicShapes.cs b/Source/Contrib/TrackViewer/Drawing/BasicShapes.cs index 66ed10f94..68a18a29e 100644 --- a/Source/Contrib/TrackViewer/Drawing/BasicShapes.cs +++ b/Source/Contrib/TrackViewer/Drawing/BasicShapes.cs @@ -140,7 +140,7 @@ static Texture2D ColorScaledTexture(Texture2D texture, GraphicsDevice graphicsDe pixels[i] = ColorWithHighlights.Highlighted(pixels[i], offset); } - Texture2D outTexture = new Texture2D(graphicsDevice, texture.Width, texture.Height, true, SurfaceFormat.Color); + Texture2D outTexture = new Texture2D(graphicsDevice, texture.Width, texture.Height, false, SurfaceFormat.Color); outTexture.SetData(pixels); return outTexture; } @@ -154,7 +154,7 @@ static Texture2D ColorScaledTexture(Texture2D texture, GraphicsDevice graphicsDe private static Texture2D CreateCircleTexture(GraphicsDevice graphicsDevice, int outerRadius) { int radius = (outerRadius - 2)/2; // So circle doesn't go out of bounds - Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, true, SurfaceFormat.Color); + Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, false, SurfaceFormat.Color); Color[] data = new Color[outerRadius * outerRadius]; @@ -187,7 +187,7 @@ private static Texture2D CreateCircleTexture(GraphicsDevice graphicsDevice, int private static Texture2D CreateDiscTexture(GraphicsDevice graphicsDevice, int outerRadius) { int radius = (outerRadius - 1) / 2; - Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, true, SurfaceFormat.Color); + Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, false, SurfaceFormat.Color); Color[] data = new Color[outerRadius * outerRadius]; @@ -221,7 +221,7 @@ private static Texture2D CreateRingTexture(GraphicsDevice graphicsDevice, int ou { int radius = (outerRadius - 1) / 2; int innerRadius = (2 * radius) / 3; - Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, true, SurfaceFormat.Color); + Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, false, SurfaceFormat.Color); Color[] data = new Color[outerRadius * outerRadius]; @@ -257,7 +257,7 @@ private static Texture2D CreateCrossedRingTexture(GraphicsDevice graphicsDevice, int radius = (outerRadius - 1) / 2; int innerRadius = (3 * radius) / 4; int crossWidth = 5; - Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, true, SurfaceFormat.Color); + Texture2D texture = new Texture2D(graphicsDevice, outerRadius, outerRadius, false, SurfaceFormat.Color); Color[] data = new Color[outerRadius * outerRadius]; diff --git a/Source/Contrib/TrackViewer/Drawing/DrawColors.cs b/Source/Contrib/TrackViewer/Drawing/DrawColors.cs index 09256865f..8b35ecca0 100644 --- a/Source/Contrib/TrackViewer/Drawing/DrawColors.cs +++ b/Source/Contrib/TrackViewer/Drawing/DrawColors.cs @@ -20,6 +20,7 @@ using System.Text; using Microsoft.Xna.Framework; using ORTS.TrackViewer.UserInterface; +using Color = Microsoft.Xna.Framework.Color; namespace ORTS.TrackViewer.Drawing { diff --git a/Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs b/Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs index 54c565b52..cd794fc7b 100644 --- a/Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs +++ b/Source/Contrib/TrackViewer/Drawing/DrawTerrain.cs @@ -1,4 +1,4 @@ -// COPYRIGHT 2014, 2018 by the Open Rails project. +// COPYRIGHT 2014, 2018 by the Open Rails project. // // This file is part of Open Rails. // @@ -401,8 +401,13 @@ public void Draw(DrawArea drawArea) { UpdateCamera(drawArea); - device.SamplerStates[0].AddressU = TextureAddressMode.Wrap; - device.SamplerStates[0].AddressV = TextureAddressMode.Wrap; + device.SamplerStates[0] = new SamplerState + { + AddressU = TextureAddressMode.Wrap, + AddressV = TextureAddressMode.Wrap, + AddressW = TextureAddressMode.Wrap, + Filter = TextureFilter.Point + }; foreach (string textureName in vertexBuffers.Keys) { @@ -979,9 +984,10 @@ private static bool IsPowerOfTwo(int x) private Texture2D GetStableTextureFromRenderTarget(RenderTarget2D renderTarget) { - int width = renderTarget.Width; - int height = renderTarget.Height; - var scaledTexture = new Texture2D(device, width, height, true, SurfaceFormat.Color); + var renderedTexture = renderTarget; + int width = renderedTexture.Width; + int height = renderedTexture.Height; + var scaledTexture = new Texture2D(device, width, height, false, SurfaceFormat.Color); Color[] data = GetColorDataArray(width * height); renderTarget.GetData(data); scaledTexture.SetData(data); @@ -1015,16 +1021,10 @@ private static RenderTarget2D GetRenderTarget(int width, int height) private static RenderTarget2D GetNewRenderTarget(int width, int height) { //todo Handle situations where backbuffer is not large enough to support width and height - var renderTarget = new RenderTarget2D( - device, - width, - height, - true, - SurfaceFormat.Color, - device.PresentationParameters.DepthStencilFormat, - device.PresentationParameters.MultiSampleCount, - device.PresentationParameters.RenderTargetUsage - ); + PresentationParameters pp = device.PresentationParameters; + var renderTarget = + new RenderTarget2D(device, width, height, + false, SurfaceFormat.Color, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); return renderTarget; } diff --git a/Source/Contrib/TrackViewer/Drawing/ShadowDrawArea.cs b/Source/Contrib/TrackViewer/Drawing/ShadowDrawArea.cs index 92b6acb88..47eaeee77 100644 --- a/Source/Contrib/TrackViewer/Drawing/ShadowDrawArea.cs +++ b/Source/Contrib/TrackViewer/Drawing/ShadowDrawArea.cs @@ -1,4 +1,4 @@ -// COPYRIGHT 2014 by the Open Rails project. +// COPYRIGHT 2014 by the Open Rails project. // // This file is part of Open Rails. // @@ -186,8 +186,9 @@ private void SetRendertargetSizes() { shadowMapCombined.Dispose(); } + var pp = graphicsDevice.PresentationParameters; shadowRenderTargetCombined = new RenderTarget2D(graphicsDevice, Nouter * blockW, Nouter * blockH, false, SurfaceFormat.Color, - DepthFormat.Depth16, 0, RenderTargetUsage.PreserveContents); + pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); shadowDrawArea.SetScreenSize(0, 0, blockW, blockH); // create initial empty subtextures @@ -201,8 +202,9 @@ private void SetRendertargetSizes() { shadowMapsSingle[i].Dispose(); } + pp = graphicsDevice.PresentationParameters; shadowRenderTargetSingle[i] = new RenderTarget2D(graphicsDevice, 1 * blockW, 1 * blockH, false, SurfaceFormat.Color, - DepthFormat.Depth16, 0, RenderTargetUsage.PreserveContents); + pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.DiscardContents); shadowMapsSingle[i] = new Texture2D(graphicsDevice, 1, 1); } } diff --git a/Source/Contrib/TrackViewer/Program.cs b/Source/Contrib/TrackViewer/Program.cs index 07bf7b2d0..7fd2311ed 100644 --- a/Source/Contrib/TrackViewer/Program.cs +++ b/Source/Contrib/TrackViewer/Program.cs @@ -16,6 +16,7 @@ // along with Open Rails. If not, see . using System; using System.Diagnostics; +using System.IO; using System.Windows.Forms; @@ -29,6 +30,10 @@ static class Program [STAThread] // Needed for Windows Presentation Foundation (used for the menu) static void Main(string[] args) { + FileStream tvLogFile = File.Create("TrackViewerLog.txt"); + TextWriterTraceListener TVtraceListener = new TextWriterTraceListener(tvLogFile); + Trace.Listeners.Add(TVtraceListener); + Trace.WriteLine("TrackViewer Starting"); using (TrackViewer trackViewer = new TrackViewer(args)) { // code below is modified version from what is found in GameStateRunActivity.cs @@ -57,6 +62,8 @@ static void Main(string[] args) trackViewer.Exit(); } } + Trace.WriteLine("TrackViewer Ending"); + Trace.Flush(); } } } diff --git a/Source/Contrib/TrackViewer/TrackViewer.cs b/Source/Contrib/TrackViewer/TrackViewer.cs index 3b4e5fbd6..9f5cedfca 100644 --- a/Source/Contrib/TrackViewer/TrackViewer.cs +++ b/Source/Contrib/TrackViewer/TrackViewer.cs @@ -23,6 +23,8 @@ using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Color = Microsoft.Xna.Framework.Color; +using MessageBox = System.Windows.Forms.MessageBox; using System.Windows.Forms; using System.Reflection; @@ -155,8 +157,8 @@ public TrackViewer(string[] args) SetAliasing(); graphics.IsFullScreen = false; Window.AllowUserResizing = true; - Window.ClientSizeChanged += new System.EventHandler(Window_ClientSizeChanged); - + Window.ClientSizeChanged += new System.EventHandler(Window_ClientSizeChanged); + //we do not a very fast behaviour, but we do need to get all key presses IsFixedTimeStep = true; TargetElapsedTime = TimeSpan.FromSeconds(0.05); @@ -636,8 +638,9 @@ void Window_ClientSizeChanged(object sender, EventArgs e) { ScreenW = Window.ClientBounds.Width; ScreenH = Window.ClientBounds.Height; - if (ScreenW == 0 || ScreenH == 0) - { // if something went wrong during fast window switching, let's not continue + // if something went wrong during fast window switching, let's not continue + if (menuControl == null || statusBarControl == null || ScreenW == 0 || ScreenH == 0) + { return; } SetSubwindowSizes(); @@ -1133,8 +1136,8 @@ static void InitLogging() void CalculateFPS(GameTime gameTime) { - float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; - FrameRate.Update(elapsedTime, 1f / elapsedTime); + float elapsedRealTime = (float)gameTime.ElapsedGameTime.TotalSeconds; + FrameRate.Update(elapsedRealTime, 1f / elapsedRealTime); } #endregion