public async Task Render_SimpleText_SimpleSingleColor()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var solidBrush = new SolidBrushResource(Color4.RedColor))
                using (var textFormat = new TextFormatResource("Arial", 70))
                    using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                    {
                        // Perform rendering
                        memRenderTarget.ClearColor = Color4.CornflowerBlue;
                        await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                        {
                            // 2D rendering is made here
                            graphics.DrawText(
                                $"Just a dummy text ;){Environment.NewLine}Just a dummy text ;)",
                                textFormat,
                                new RectangleF(10, 10, 512, 512),
                                solidBrush);
                        });

                        await memRenderTarget.AwaitRenderAsync();

                        // Take screenshot
                        var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                        // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                        // Calculate and check difference
                        var diff = BitmapComparison.CalculatePercentageDifference(
                            screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleText_SingleColor.png"));
                        Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                    }
        }
        public async Task Postprocessing_Focus()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var keyPostprocess = manipulator.AddResource(
                        _ => new FocusPostprocessEffectResource(false, 0f));

                    var defaultLayer = manipulator.GetLayer(Scene.DEFAULT_LAYER_NAME);
                    var focusLayer   = manipulator.AddLayer("Focus");
                    focusLayer.PostprocessEffectKey = keyPostprocess;

                    var resGeometry = manipulator.AddResource(
                        _ => new GeometryResource(new CubeGeometryFactory()));
                    var resMaterial = manipulator.AddStandardMaterialResource();

                    var frontMesh      = manipulator.AddMeshObject(resGeometry, defaultLayer.Name, resMaterial);
                    frontMesh.Color    = Color4.BlueColor;
                    frontMesh.Scaling  = new Vector3(1f, 0.5f, 0.5f);
                    frontMesh.Position = new Vector3(0.5f, 2f, -3f);

                    var backMesh           = manipulator.AddMeshObject(resGeometry, defaultLayer.Name, resMaterial);
                    backMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 3f, 0f);
                    backMesh.Scaling       = new Vector3(2f, 2f, 2f);
                    backMesh.Color         = Color4.RedColor;

                    var focusMesh = manipulator.AddMeshObject(resGeometry, focusLayer.Name, resMaterial);
                    focusMesh.TransformSourceObject = backMesh;
                    focusMesh.TransformationType    = SpacialTransformationType.TakeFromOtherObject;
                    focusMesh.Color = Color4.RedColor;
                });

                await memRenderTarget.AwaitRenderAsync();

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("Postprocessing", "PostProcess_Focus.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
        public async Task Render_SimpleBitmap_WithTransparency()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var solidBrush = new SolidBrushResource(Color4.LightGray))
                using (var bitmap = new StandardBitmapResource(new AssemblyResourceLink(this.GetType(), "Resources.Bitmaps.Logo.png")))
                    using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                    {
                        // Perform rendering
                        memRenderTarget.ClearColor = Color4.CornflowerBlue;

                        await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                        {
                            // 2D rendering is made here
                            graphics.FillRectangle(graphics.ScreenBounds, solidBrush);
                            graphics.DrawBitmap(bitmap, new Vector2(100f, 100f));
                        });

                        await memRenderTarget.AwaitRenderAsync();

                        // Take screenshot
                        var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                        // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                        // Calculate and check difference
                        var diff = BitmapComparison.CalculatePercentageDifference(
                            screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleBitmap_Transparency.png"));
                        Assert.IsTrue(diff < 0.02, "Difference to reference image is to big!");
                    }
        }
        public async Task Render_SimpleGeometry_Ellipse()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var solidBrush = new SolidBrushResource(Color4.LightGray))
                using (var solidBrushBorder = new SolidBrushResource(Color4.Gray))
                    using (var ellipseGeometry = new EllipseGeometryResource(new Vector2(512, 512), 400f, 300f))
                        using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                        {
                            // Perform rendering
                            memRenderTarget.ClearColor = Color4.CornflowerBlue;

                            await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                            {
                                // 2D rendering is made here
                                graphics.DrawGeometry(ellipseGeometry, solidBrushBorder, 3f);
                                graphics.FillGeometry(ellipseGeometry, solidBrush);
                            });

                            await memRenderTarget.AwaitRenderAsync();

                            // Take screenshot
                            var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                            // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                            // Calculate and check difference
                            var diff = BitmapComparison.CalculatePercentageDifference(
                                screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleGeometry2D_Ellipse.png"));
                            Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                        }
        }
        public async Task Render_SimpleObject_D2D_Texture()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var solidBrush = new SolidBrushResource(Color4.Gray))
                using (var textFormat = new TextFormatResource("Arial", 36))
                    using (var textBrush = new SolidBrushResource(Color4.RedColor))
                        using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                        {
                            memRenderTarget.ClearColor = Color4.CornflowerBlue;

                            // Get and configure the camera
                            var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                            camera.Position = new Vector3(0f, 5f, -7f);
                            camera.Target   = new Vector3(0f, 0f, 0f);
                            camera.UpdateCamera();

                            // 2D rendering is made here
                            var d2dDrawingLayer = new Custom2DDrawingLayer(graphics =>
                            {
                                var d2dRectangle = new RectangleF(10, 10, 236, 236);
                                graphics.Clear(Color4.LightBlue);
                                graphics.FillRoundedRectangle(
                                    d2dRectangle, 30, 30,
                                    solidBrush);

                                d2dRectangle.Inflate(-10, -10);
                                graphics.DrawText("Hello Direct2D!", textFormat, d2dRectangle, textBrush);
                            });

                            // Define scene
                            await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                            {
                                var resD2DTexture = manipulator.AddResource(
                                    _ => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                                var resD2DMaterial = manipulator.AddStandardMaterialResource(resD2DTexture);
                                var geoResource    = manipulator.AddResource(
                                    _ => new GeometryResource(new CubeGeometryFactory()));

                                var newMesh           = manipulator.AddMeshObject(geoResource, resD2DMaterial);
                                newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                                newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                            });

                            await memRenderTarget.AwaitRenderAsync();

                            // Take screenshot
                            var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                            //TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                            // Calculate and check difference
                            var isNearEqual = BitmapComparison.IsNearEqual(
                                screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleObject_D2DTexture.png"));
                            Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
                        }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
        public async Task Render_SimpleRoundedRect_Filled_Solid()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var solidBrush = new SolidBrushResource(Color4.Gray))
                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    // Perform rendering
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;
                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                    {
                        // 2D rendering is made here
                        graphics.FillRoundedRectangle(
                            new RectangleF(10, 10, 512, 512), 30, 30,
                            solidBrush);
                    });

                    await memRenderTarget.AwaitRenderAsync();

                    // Take screenshot
                    var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                    // Calculate and check difference
                    var diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleRoundedRectFilled.png"));
                    Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                }
        }
        public async Task Render_SimpleRoundedRect_Filled_Over3D()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            var brushColor = Color4.Gray;

            brushColor.ChangeAlphaTo(0.5f);

            using (var solidBrush = new SolidBrushResource(brushColor))
                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                    // Get and configure the camera
                    var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                    camera.Position = new Vector3(0f, 5f, -5f);
                    camera.Target   = new Vector3(0f, 1f, 0f);
                    camera.UpdateCamera();

                    // Define scene
                    await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                    {
                        // Define object
                        var resGeometry = manipulator.AddResource(
                            _ => new GeometryResource(new CubeGeometryFactory()));
                        var resMaterial = manipulator.AddResource(
                            _ => new StandardMaterialResource(enableShaderGeneratedBorder: true));

                        var newMesh           = manipulator.AddMeshObject(resGeometry, resMaterial);
                        newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                        newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                        newMesh.Color         = Color4.Goldenrod;
                    });

                    // Define 2D overlay
                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                    {
                        // 2D rendering is made here
                        graphics.FillRoundedRectangle(
                            new RectangleF(10, 10, 512, 512), 30, 30,
                            solidBrush);
                    });

                    await memRenderTarget.AwaitRenderAsync();

                    // Take screenshot
                    var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                    // Calculate and check difference
                    var diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "RoundedRectOver3D.png"));
                    Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
 public void BitmapComparison_Negative_BlackWhite()
 {
     using (var leftBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "WhiteScreen.png"))
         using (var rightBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "BlackScreen.png"))
         {
             var comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.IsTrue(EngineMath.EqualsWithTolerance(comparisonResult, 1.0f));
         }
 }
 public void BitmapComparison_Positive()
 {
     using (var leftBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "FlatShadedObject.png"))
         using (var rightBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "FlatShadedObject.png"))
         {
             Assert.IsTrue(
                 EngineMath.EqualsWithTolerance(BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap), 0f));
         }
 }
示例#10
0
 public void BitmapComparison_Positive()
 {
     using (GDI.Bitmap leftBitmap = Properties.Resources.FlatShadedObject)
         using (GDI.Bitmap rightBitmap = Properties.Resources.FlatShadedObject)
         {
             Assert.True(
                 BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap) == 0f);
         }
 }
示例#11
0
 public void BitmapComparison_Negative_BlackWhite()
 {
     using (GDI.Bitmap leftBitmap = Properties.Resources.WhiteScreen)
         using (GDI.Bitmap rightBitmap = Properties.Resources.BlackScreen)
         {
             float comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.True(comparisonResult == 1.0f);
         }
 }
 public void BitmapComparison_Negative_Smaller()
 {
     using (var leftBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "FlatShadedObject.png"))
         using (var rightBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "FlatShadedObject_Smaller.png"))
         {
             var comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.IsTrue(comparisonResult > 0.1);
             Assert.IsTrue(comparisonResult < 0.4);
         }
 }
示例#13
0
 public void BitmapComparison_Negative_Without_Model()
 {
     using (GDI.Bitmap leftBitmap = Properties.Resources.ClearedScreen)
         using (GDI.Bitmap rightBitmap = Properties.Resources.FlatShadedObject)
         {
             float comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.True(comparisonResult > 0.25f);
             Assert.True(comparisonResult < 0.6f);
         }
 }
示例#14
0
 public void BitmapComparison_Negative_Inversed_Image()
 {
     using (GDI.Bitmap leftBitmap = Properties.Resources.FlatShadedObject)
         using (GDI.Bitmap rightBitmap = Properties.Resources.FlatShadedObject_Negative)
         {
             float comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.True(comparisonResult > 0.9f);
             Assert.True(comparisonResult <= 1.0f);
         }
 }
 public void BitmapComparison_Negative_Without_Model()
 {
     using (var leftBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "ClearedScreen.png"))
         using (var rightBitmap = TestUtilities.LoadBitmapFromResource("BitmapComparison", "FlatShadedObject.png"))
         {
             var comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.IsTrue(comparisonResult > 0.25f);
             Assert.IsTrue(comparisonResult < 0.6f);
         }
 }
示例#16
0
 public void BitmapComparison_Negative_Enlighted()
 {
     using (GDI.Bitmap leftBitmap = Properties.Resources.FlatShadedObject)
         using (GDI.Bitmap rightBitmap = Properties.Resources.FlatShadedObject_Enlighted)
         {
             float comparisonResult = BitmapComparison.CalculatePercentageDifference(leftBitmap, rightBitmap);
             Assert.True(comparisonResult > 0.1);
             Assert.True(comparisonResult < 0.4);
         }
 }
示例#17
0
        public async Task Render_SimpleLine()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var wireObject = new WireObject
                    {
                        LineData = new[]
                        {
                            new Line(
                                new Vector3(-0.5f, 0f, -0.5f),
                                new Vector3(0.5f, 0f, -0.5f)),
                            new Line(
                                new Vector3(0.5f, 0f, -0.5f),
                                new Vector3(0.5f, 0f, 0.5f)),
                            new Line(
                                new Vector3(0.5f, 0f, 0.5f),
                                new Vector3(-0.5f, 0f, 0.5f)),
                            new Line(
                                new Vector3(-0.5f, 0f, 0.5f),
                                new Vector3(-0.5f, 0f, -0.5f))
                        },
                        Color = Color4.RedColor
                    };


                    manipulator.AddObject(wireObject);
                });

                await memRenderTarget.AwaitRenderAsync();

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("Drawing3D", "SimpleLine.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }
        }
示例#18
0
        public async Task QueryInfo_FromSimpleMesh()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                Mesh?newMesh = null;
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var resGeometry = manipulator.AddResource(
                        _ => new GeometryResource(new CubeGeometryFactory()));
                    var resMaterial = manipulator.AddStandardMaterialResource();

                    newMesh = manipulator.AddMeshObject(resGeometry, resMaterial);
                    newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                    newMesh.Color         = Color4.RedColor;
                    newMesh.TrySetInitialVisibility(memRenderTarget.RenderLoop.ViewInformation, true);
                });

                await memRenderTarget.AwaitRenderAsync();

                // Query some information from the mesh
                var renderingChunkCount = newMesh !.TryGetRenderingChunkCount(memRenderTarget.Device !);
                var geoResource         = newMesh.TryGetGeometryResource(memRenderTarget.Device !);
                var materialResources   = newMesh.TryGetMaterialResources(memRenderTarget.Device !);

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("Drawing3D", "SimpleObject.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");

                // Check info from mesh
                Assert.IsTrue(renderingChunkCount == 1, "Invalid count of rendering chunks");
                Assert.IsTrue(geoResource != null, "Can not query GeometryResource");
                Assert.IsTrue(materialResources is { Length: 1 }, "Can not query MaterialResource");
示例#19
0
        public async Task Render_SimpleRoundedRect_Filled_LinearGradient()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var gradientBrush = new LinearGradientBrushResource(
                       new Vector2(0f, 0f),
                       new Vector2(512f, 0f),
                       new[]
            {
                new GradientStop {
                    Color = Color4.Gray, Position = 0f
                },
                new GradientStop {
                    Color = Color4.White, Position = 0.6f
                },
                new GradientStop {
                    Color = Color4.Black, Position = 1f
                }
            },
                       ExtendMode.Mirror))
                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    // Perform rendering
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                    {
                        // 2D rendering is made here
                        graphics.FillRoundedRectangle(
                            new RectangleF(10, 10, 900, 900), 30, 30,
                            gradientBrush);
                    });

                    await memRenderTarget.AwaitRenderAsync();

                    // Take screenshot
                    var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                    // Calculate and check difference
                    var diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleRoundedRectFilled_LinearGradient.png"));
                    Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                }
        }
示例#20
0
        public async Task Render_SimpleObject()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(0f, 5f, -7f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var resGeometry = manipulator.AddResource(
                        _ => new GeometryResource(new CubeGeometryFactory()));
                    var resMaterial = manipulator.AddStandardMaterialResource();

                    var newMesh           = manipulator.AddMeshObject(resGeometry, resMaterial);
                    newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                    newMesh.Color         = Color4.RedColor;
                    newMesh.TrySetInitialVisibility(memRenderTarget.RenderLoop.ViewInformation, true);
                });

                await memRenderTarget.AwaitRenderAsync();

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("Drawing3D", "SimpleObject.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
        public async Task LoadAndRender_ACShadedObject()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(-1.5f, 3f, -1.5f);
                camera.Target   = new Vector3(1f, -1f, 1f);
                camera.UpdateCamera();

                // Define scene
                SceneSpacialObject?newMesh = null;
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var resGeometry = manipulator.AddResource(
                        _ => new GeometryResource(ACFileLoader.ImportGeometry(
                                                      TestUtilities.CreateResourceLink("Models", "ModelShaded.ac"))));
                    var resMaterial = manipulator.AddStandardMaterialResource();

                    newMesh         = manipulator.AddMeshObject(resGeometry, resMaterial);
                    newMesh.Scaling = new Vector3(0.5f, 0.5f, 0.5f);
                });

                await memRenderTarget.Scene.WaitUntilVisibleAsync(newMesh !, memRenderTarget.RenderLoop);

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("GeometryLoadingAndRendering", "ShadedObject.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
示例#22
0
        public async Task Render_SimpleBitmap_Animated()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var bitmap = new StandardBitmapResource(
                       new AssemblyResourceLink(this.GetType(), "Resources.Bitmaps.Boom.png"),
                       8, 8))
                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    // Perform rendering
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                    {
                        // 2D rendering is made here
                        for (var loop = 0; loop < 8; loop++)
                        {
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 10f), frameIndex: 7);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 100f), frameIndex: 15);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 200f), frameIndex: 23);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 300f), frameIndex: 31);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 400f), frameIndex: 39);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 500f), frameIndex: 47);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 600f), frameIndex: 55);
                            graphics.DrawBitmap(bitmap, new Vector2(100f * loop, 700f), frameIndex: 63);
                        }
                    });

                    //await AsyncResourceLoader.Current.WaitForAllFinishedAsync();
                    await memRenderTarget.AwaitRenderAsync();

                    // Take screenshot
                    var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                    // Calculate and check difference
                    var diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleBitmap_Animated.png"));
                    Assert.IsTrue(diff < 0.02, "Difference to reference image is to big!");
                }
        }
        public async Task LoadAndRender_StlFile()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(-4f, 4f, -4f);
                camera.Target   = new Vector3(2f, 0f, 2f);
                camera.UpdateCamera();

                // Import Fox model
                var importOptions = new StlImportOptions
                {
                    ResourceCoordinateSystem = CoordinateSystem.LeftHanded_UpZ,
                    FitToCube = false
                };

                var loadedObjects = await memRenderTarget.Scene.ImportAsync(
                    TestUtilities.CreateResourceLink("Models", "Fox.stl"),
                    importOptions);

                // Wait for it to be visible
                await memRenderTarget.Scene.WaitUntilVisibleAsync(loadedObjects, memRenderTarget.RenderLoop);

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("ModelLoadingAndRendering", "ModelStl.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
示例#24
0
        public async Task Render_DebugLayer()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var debugLayer = new DebugDrawingLayer())
                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                {
                    // Perform rendering
                    memRenderTarget.ClearColor = Color4.CornflowerBlue;
                    await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(debugLayer);

                    await memRenderTarget.AwaitRenderAsync();

                    // Take screenshot
                    var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                    // Calculate and check difference
                    var diff = BitmapComparison.CalculatePercentageDifference(
                        screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "DebugDrawingLayer.png"));
                    Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                }
        }
示例#25
0
        public async Task Render_ClearedScreen()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                // Perform rendering
                memRenderTarget.ClearColor = Color4.CornflowerBlue;
                await memRenderTarget.AwaitRenderAsync();

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("Drawing3D", "ClearedScreen.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
示例#26
0
        public async Task MemoryRenderTarget_2DInitError()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            // Ensure that any async disposal is  done before we create a new GraphicsCore
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();
            await GraphicsCore.Current.MainLoop !.WaitForNextPassedLoopAsync();

            GDI.Bitmap?screenshot = null;
            using (TestUtilities.FailTestOnInternalExceptions())
                using (GraphicsCore.AutomatedTest_NewTestEnvironment())
                {
                    await GraphicsCore.Loader
                    .ConfigureLoading(settings => settings.ThrowD2DInitDeviceError = true)
                    .LoadAsync();

                    Assert.IsTrue(GraphicsCore.IsLoaded);
                    Assert.IsFalse(GraphicsCore.Current.DefaultDevice !.Supports2D);

                    using (var solidBrush = new SolidBrushResource(Color4.Gray))
                        using (var textFormat = new TextFormatResource("Arial", 36))
                            using (var textBrush = new SolidBrushResource(Color4.RedColor))

                                using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                                {
                                    memRenderTarget.ClearColor = Color4.CornflowerBlue;

                                    // Get and configure the camera
                                    var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                                    camera.Position = new Vector3(0f, 5f, -7f);
                                    camera.Target   = new Vector3(0f, 0f, 0f);
                                    camera.UpdateCamera();

                                    // 2D rendering is made here
                                    var d2dDrawingLayer = new Custom2DDrawingLayer(graphics =>
                                    {
                                        var d2dRectangle = new GDI.RectangleF(10, 10, 236, 236);
                                        graphics.Clear(Color4.LightBlue);
                                        graphics.FillRoundedRectangle(
                                            d2dRectangle, 30, 30,
                                            solidBrush);

                                        d2dRectangle.Inflate(-10, -10);
                                        graphics.DrawText("Hello Direct2D!", textFormat, d2dRectangle, textBrush);
                                    });

                                    // Define scene
                                    await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                                    {
                                        var resD2DTexture = manipulator.AddResource(
                                            _ => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                                        var resD2DMaterial = manipulator.AddStandardMaterialResource(resD2DTexture);
                                        var resGeometry    = manipulator.AddResource(
                                            _ => new GeometryResource(new CubeGeometryFactory()));

                                        var newMesh           = manipulator.AddMeshObject(resGeometry, resD2DMaterial);
                                        newMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                                        newMesh.Scaling       = new Vector3(2f, 2f, 2f);
                                    });

                                    // Take screenshot
                                    await memRenderTarget.AwaitRenderAsync();

                                    screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                                    // TestUtilities.DumpToDesktop(screenshot, "Blub.png");
                                }
                }

            // Calculate and check difference
            Assert.IsNotNull(screenshot);
            var isNearEqual = BitmapComparison.IsNearEqual(
                screenshot, TestUtilities.LoadBitmapFromResource("ErrorHandling", "SimpleObject.png"));

            Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
        }