public RenderPipelineWorld(IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IGraphicsFactory graphicsFactory, IAssert assert) { _renderUtilities = renderUtilities; _assert = assert; _texture = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.Player"); _invertPostProcess = graphicsFactory.CreateInvertPostProcessingRenderPass(); _blurPostProcess = graphicsFactory.CreateBlurPostProcessingRenderPass(); _customPostProcess = graphicsFactory.CreateCustomPostProcessingRenderPass("effect.MakeRed"); _captureInlinePostProcess = graphicsFactory.CreateCaptureInlinePostProcessingRenderPass(); _captureInlinePostProcess.RenderPipelineStateAvailable = d => { #if MANUAL_TEST #elif RECORDING using (var writer = new StreamWriter("output" + _frame + ".png")) { d.SaveAsPng(writer.BaseStream, Width, Height); } #else var baseStream = typeof(RenderPipelineWorld).Assembly.GetManifestResourceStream( "Protogame.Tests.Expected.RenderPipeline.output" + _frame + ".png"); var baseBytes = new byte[baseStream.Length]; baseStream.Read(baseBytes, 0, baseBytes.Length); var memoryStream = new MemoryStream(); d.SaveAsPng(memoryStream, Width, Height); var memoryBytes = new byte[memoryStream.Position]; memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.Read(memoryBytes, 0, memoryBytes.Length); memoryStream.Dispose(); baseStream.Dispose(); _assert.Equal(baseBytes, memoryBytes); #endif #if MANUAL_TEST _manualTest++; if (_manualTest % 60 == 0) { _frame++; } #else _frame++; #endif }; this.Entities = new List <IEntity>(); }
public RenderPipelineWorld( IAssetManager assetManager, I2DRenderUtilities renderUtilities, IGraphicsFactory graphicsFactory, IAssert assert, ITestAttachment testAttachment, IRenderTargetBackBufferUtilities renderTargetBackBufferUtilities, IGraphicsBlit graphicsBlit) { _renderUtilities = renderUtilities; _assert = assert; _testAttachment = testAttachment; _texture = assetManager.Get <TextureAsset>("texture.Player"); _invertPostProcess = graphicsFactory.CreateInvertPostProcessingRenderPass(); _blurPostProcess = graphicsFactory.CreateBlurPostProcessingRenderPass(); _customPostProcess = graphicsFactory.CreateCustomPostProcessingRenderPass("effect.MakeRed"); _captureInlinePostProcess = graphicsFactory.CreateCaptureInlinePostProcessingRenderPass(); _renderTargetBackBufferUtilities = renderTargetBackBufferUtilities; _graphicsBlit = graphicsBlit; _captureInlinePostProcess.RenderPipelineStateAvailable = (gameContext, renderContext, previousPass, d) => { if (!_isValidRun) { return; } _renderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_renderTarget, renderContext, SurfaceFormat.Color, DepthFormat.None, 1); // Blit to the capture target. _graphicsBlit.Blit(renderContext, d, _renderTarget); #if MANUAL_TEST #elif RECORDING using (var writer = new StreamWriter("output" + _frame + ".png")) { _renderTarget.SaveAsPng(writer.BaseStream, Width, Height); } #else var baseStream = typeof(RenderPipelineWorld).Assembly.GetManifestResourceStream( "Protogame.Tests.Expected.RenderPipeline.output" + _frame + ".png"); _assert.NotNull(baseStream); var memoryStream = new MemoryStream(); _renderTarget.SaveAsPng(memoryStream, Width, Height); // ReSharper disable once AssignNullToNotNullAttribute var expected = new Bitmap(baseStream); var actual = new Bitmap(memoryStream); _assert.Equal(expected.Height, actual.Height); _assert.Equal(expected.Width, actual.Width); var totalPixelValues = 0L; var incorrectPixelValues = 0L; for (var x = 0; x < expected.Width; x++) { for (var y = 0; y < expected.Height; y++) { var expectedPixel = expected.GetPixel(x, y); var actualPixel = actual.GetPixel(x, y); totalPixelValues += 255 * 4; if (expectedPixel != actualPixel) { var diffA = System.Math.Abs((int)actualPixel.A - (int)expectedPixel.A); var diffR = System.Math.Abs((int)actualPixel.R - (int)expectedPixel.R); var diffG = System.Math.Abs((int)actualPixel.G - (int)expectedPixel.G); var diffB = System.Math.Abs((int)actualPixel.B - (int)expectedPixel.B); incorrectPixelValues += (diffA + diffR + diffG + diffB); } } } var percentage = (100 - ((incorrectPixelValues / (double)totalPixelValues) * 100f)); var combination = _combinations[_frame % _combinations.Count]; _testAttachment.Attach("name-" + combination.Id, combination.Name); _testAttachment.Attach("expected-" + combination.Id, baseStream); _testAttachment.Attach("actual-" + combination.Id, memoryStream); _testAttachment.Attach("threshold-" + combination.Id, 99.9); _testAttachment.Attach("measured-" + combination.Id, percentage); if (percentage <= 99.9f) { combination.FailureMessage = "The actual rendered image did not match the expected image close enough (99.9%)."; } //memoryStream.Dispose(); //baseStream.Dispose(); #endif #if MANUAL_TEST _manualTest++; if (_manualTest % 60 == 0) { _frame++; } #else _frame++; #endif }; this.Entities = new List <IEntity>(); }