public override void Draw(GameTime gameTime) { if (overlayMessages.Count == 0) { return; } if (fastTextRenderer == null) { fastTextRenderer = new FastTextRenderer { DebugSpriteFont = Content.Load <Texture>("XenkoDebugSpriteFont"), TextColor = TextColor }.Initialize(Game.GraphicsContext); } if (overlayMessages.Count == 0) { return; } // TODO GRAPHICS REFACTOR where to get command list from? Game.GraphicsContext.CommandList.SetRenderTargetAndViewport(null, Game.GraphicsDevice.Presenter.BackBuffer); var currentColor = overlayMessages.Peek().TextColor; fastTextRenderer.Begin(Game.GraphicsContext); foreach (var msg in overlayMessages) { if (msg.TextColor != currentColor) { currentColor = msg.TextColor; fastTextRenderer.End(Game.GraphicsContext); fastTextRenderer.TextColor = currentColor; fastTextRenderer.Begin(Game.GraphicsContext); } fastTextRenderer.DrawString(Game.GraphicsContext, msg.Message, msg.Position.X, msg.Position.Y); } fastTextRenderer.End(Game.GraphicsContext); }
/// <inheritdoc/> public override void Draw(GameTime gameTime) { // copy those values before fast text render not to influence the game stats drawCallsCount = GraphicsDevice.FrameDrawCalls; trianglesCount = GraphicsDevice.FrameTriangleCount; if (dumpTiming.ElapsedMilliseconds > RefreshTime && FilteringMode == GameProfilingResults.GpuEvents) { dumpTiming.Restart(); renderTargetSize = new Size2(Game.GraphicsContext.CommandList.RenderTarget.Width, Game.GraphicsContext.CommandList.RenderTarget.Height); if (stringBuilderTask == null || stringBuilderTask.IsCompleted) { stringBuilderTask = new Task(UpdateProfilingStrings); stringBuilderTask.Start(); } } viewportHeight = Game.GraphicsContext.CommandList.Viewport.Height; if (fastTextRenderer == null) { fastTextRenderer = new FastTextRenderer(Game.GraphicsContext) { DebugSpriteFont = Content.Load <Texture>("StrideDebugSpriteFont"), TextColor = TextColor, }; } // TODO GRAPHICS REFACTOR where to get command list from? Game.GraphicsContext.CommandList.SetRenderTargetAndViewport(null, Game.GraphicsDevice.Presenter.BackBuffer); fastTextRenderer.Begin(Game.GraphicsContext); lock (stringLock) { var currentHeight = textDrawStartOffset.Y; fastTextRenderer.DrawString(Game.GraphicsContext, fpsStatString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; if (FilteringMode == GameProfilingResults.CpuEvents) { fastTextRenderer.DrawString(Game.GraphicsContext, gcMemoryString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; fastTextRenderer.DrawString(Game.GraphicsContext, gcCollectionsString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; } else if (FilteringMode == GameProfilingResults.GpuEvents) { fastTextRenderer.DrawString(Game.GraphicsContext, gpuGeneralInfoString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; fastTextRenderer.DrawString(Game.GraphicsContext, gpuInfoString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; } if (FilteringMode != GameProfilingResults.Fps) { fastTextRenderer.DrawString(Game.GraphicsContext, profilersString, textDrawStartOffset.X, currentHeight); } } fastTextRenderer.End(Game.GraphicsContext); }
/// <inheritdoc/> public override void Draw(GameTime gameTime) { // Where to render the result? var renderTarget = RenderTarget ?? Game.GraphicsDevice.Presenter.BackBuffer; // Copy those values before fast text render not to influence the game stats drawCallsCount = GraphicsDevice.FrameDrawCalls; trianglesCount = GraphicsDevice.FrameTriangleCount; if (dumpTiming.ElapsedMilliseconds > RefreshTime && FilteringMode == GameProfilingResults.GpuEvents) { dumpTiming.Restart(); renderTargetSize = new Size2(renderTarget.Width, renderTarget.Height); if (stringBuilderTask is null || stringBuilderTask.IsCompleted) { stringBuilderTask = new Task(UpdateProfilingStrings); stringBuilderTask.Start(); } } var renderContext = RenderContext.GetShared(Services); var renderDrawContext = renderContext.GetThreadContext(); if (fastTextRenderer is null) { fastTextRenderer = new FastTextRenderer(renderDrawContext.GraphicsContext) { DebugSpriteFont = Content.Load <Texture>("StrideDebugSpriteFont"), TextColor = TextColor, }; } using (renderDrawContext.PushRenderTargetsAndRestore()) { renderDrawContext.CommandList.SetRenderTargetAndViewport(null, renderTarget); viewportHeight = renderDrawContext.CommandList.Viewport.Height; fastTextRenderer.Begin(renderDrawContext.GraphicsContext); lock (stringLock) { var currentHeight = textDrawStartOffset.Y; fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, fpsStatString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; if (FilteringMode == GameProfilingResults.CpuEvents) { fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, gcMemoryString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, gcCollectionsString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; } else if (FilteringMode == GameProfilingResults.GpuEvents) { fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, gpuGeneralInfoString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, gpuInfoString, textDrawStartOffset.X, currentHeight); currentHeight += TopRowHeight; } if (FilteringMode != GameProfilingResults.Fps) { fastTextRenderer.DrawString(renderDrawContext.GraphicsContext, profilersString, textDrawStartOffset.X, currentHeight); } } fastTextRenderer.End(renderDrawContext.GraphicsContext); } }