Exemplo n.º 1
0
        public async Task ReadSimple_WmvVideo_Seek()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            ResourceLink videoLink = new AssemblyResourceLink(
                this.GetType().Assembly,
                "SeeingSharp.Tests.Rendering.Ressources.Videos",
                "DummyVideo.wmv");

            GDI.Bitmap bitmapFrame = null;
            using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(videoLink))
                using (MemoryMappedTexture32bpp actFrameBuffer = new MemoryMappedTexture32bpp(videoReader.FrameSize))
                {
                    videoReader.SetCurrentPosition(TimeSpan.FromSeconds(2.0));
                    videoReader.ReadFrame(actFrameBuffer);

                    actFrameBuffer.SetAllAlphaValuesToOne_ARGB();

                    using (bitmapFrame = GraphicsHelper.LoadBitmapFromMappedTexture(actFrameBuffer))
                    {
                        Assert.NotNull(bitmapFrame);
                        Assert.True(videoReader.CurrentPosition > TimeSpan.FromSeconds(1.9));
                        Assert.True(videoReader.CurrentPosition < TimeSpan.FromSeconds(2.1));
                        Assert.True(videoReader.Duration > TimeSpan.FromSeconds(3.9));
                        Assert.True(videoReader.Duration < TimeSpan.FromSeconds(4.1));
                        Assert.True(videoReader.IsSeekable);
                        Assert.True(
                            BitmapComparison.IsNearEqual(bitmapFrame, Properties.Resources.ReferenceImage_VideoFrameWmv_Seek));
                    }
                }
        }
Exemplo n.º 2
0
        public async Task Render_Skybox()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    // Create pallet geometry resource
                    PalletType pType      = new PalletType();
                    pType.ContentColor    = Color4.Transparent;
                    var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(pType));

                    // Create pallet object
                    GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                    palletObject.Color         = Color4.GreenColor;
                    palletObject.EnableShaderGeneratedBorder();
                    palletObject.BuildAnimationSequence()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                    .ApplyAndRewind();

                    var resSkyboxTexture = manipulator.AddTexture(new Uri("/SeeingSharp.Tests.Rendering;component/Ressources/Textures/Skybox.dds", UriKind.Relative));

                    // Create the skybox on a new layer
                    manipulator.AddLayer("Skybox");
                    SkyboxObject skyboxObject = new SkyboxObject(resSkyboxTexture);
                    manipulator.Add(skyboxObject, "Skybox");
                });

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

                screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_Skybox);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
        public async Task Postprocessing_EdgeDetect()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

                // Get and configure the camera
                PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                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 <EdgeDetectPostprocessEffectResource>(
                        () => new EdgeDetectPostprocessEffectResource()
                    {
                        Thickness = 10f
                    });

                    SceneLayer defaultLayer           = manipulator.GetLayer(Scene.DEFAULT_LAYER_NAME);
                    defaultLayer.PostprocessEffectKey = keyPostprocess;

                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(new PalletType()));

                    GenericObject newObject = manipulator.AddGeneric(geoResource);
                    newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newObject.Scaling       = new Vector3(2f, 2f, 2f);
                    newObject.Color         = Color4.RedColor;
                });

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

                screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_PostProcess_EdgeDetect);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 4
0
        public async Task Render3D_VideoTexture()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            ResourceLink videoLink = new AssemblyResourceLink(
                this.GetType().Assembly,
                "SeeingSharp.Tests.Rendering.Ressources.Videos",
                "DummyVideo.mp4");

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

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

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    var resVideoTexture = manipulator.AddResource <VideoThumbnailTextureResource>(
                        () => new VideoThumbnailTextureResource(videoLink, TimeSpan.FromMilliseconds(300.0)));
                    var resVideoMaterial = manipulator.AddSimpleColoredMaterial(resVideoTexture, addToAlpha: 1f);
                    var geoResource      = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(new PalletType(
                                                       palletMaterial: NamedOrGenericKey.Empty,
                                                       contentMaterial: resVideoMaterial)));

                    GenericObject newObject = manipulator.AddGeneric(geoResource);
                    newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newObject.Scaling       = new Vector3(2f, 2f, 2f);
                });

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

                screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_SimpleObject_VideoTexture);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 5
0
        public async Task Render_SimpleLine()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    WireObject wireObject = new WireObject();
                    wireObject.LineData   = new Line[] {
                        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)),
                    };
                    wireObject.LineColor = Color4.RedColor;
                    manipulator.Add(wireObject);
                });

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

                //screenshot.DumpToDesktop("Blub");

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_SimpleLine);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }
        }
Exemplo n.º 6
0
        public async Task Render_SimpleObject_StackedGeometry()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                await memRenderTarget.AwaitRenderAsync();

                // Define scene
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    PalletType palType            = new PalletType();
                    palType.ContentHeight         = 0f;
                    StackedObjectType stackedType = new StackedObjectType(palType, 10);

                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(stackedType));

                    GenericObject newObject = manipulator.AddGeneric(geoResource);
                    newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                    newObject.Scaling       = new Vector3(2f, 2f, 2f);
                    newObject.TrySetInitialVisibility(memRenderTarget.RenderLoop.ViewInformation, true);
                });

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

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_SimpleObject_StackedGeometry);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 7
0
        public async Task LoadAndRender_ACTexturedObject()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                // Define scene
                SceneObject newObject = null;
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(ACFileLoader.ImportObjectType(new AssemblyResourceLink(
                                                                                     Assembly.GetExecutingAssembly(),
                                                                                     "SeeingSharp.Tests.Rendering.Ressources.Models",
                                                                                     "ModelTextured.ac"))));

                    newObject = manipulator.AddGeneric(geoResource);
                });

                await memRenderTarget.Scene.WaitUntilVisibleAsync(newObject, memRenderTarget.RenderLoop);

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

                //screenshot.DumpToDesktop(TEST_DUMMY_FILE_NAME);

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_TexturedObject);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 8
0
        public async Task ImportAndRender_ACShadedObject()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            IEnumerable <SceneObject> importedObjects = null;

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

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

                ResourceLink objSource = new AssemblyResourceLink(
                    typeof(ModelLoadingAndRenderingTests),
                    "Ressources.Models.ModelShaded.ac");
                importedObjects = await memRenderTarget.Scene.ImportAsync(objSource);

                // Wait until ac file is completely loaded
                await memRenderTarget.Scene.WaitUntilVisibleAsync(importedObjects, memRenderTarget.RenderLoop);

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

                //screenshot.DumpToDesktop(TEST_DUMMY_FILE_NAME);

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_ShadedObject);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
            Assert.NotNull(importedObjects);
            Assert.True(importedObjects.Count() == 1);
        }
Exemplo n.º 9
0
        public async Task Render_ClearedScreen()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_ClearedScreen);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 10
0
        public async Task ReadSimple_WmvVideo()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            ResourceLink videoLink = new AssemblyResourceLink(
                this.GetType().Assembly,
                "SeeingSharp.Tests.Rendering.Ressources.Videos",
                "DummyVideo.wmv");

            GDI.Bitmap bitmapFrame10 = null;
            using (FrameByFrameVideoReader videoReader = new FrameByFrameVideoReader(videoLink))
                using (MemoryMappedTexture32bpp actFrameBuffer = new MemoryMappedTexture32bpp(videoReader.FrameSize))
                {
                    int frameIndex = 0;
                    while (!videoReader.EndReached)
                    {
                        if (videoReader.ReadFrame(actFrameBuffer))
                        {
                            actFrameBuffer.SetAllAlphaValuesToOne_ARGB();

                            frameIndex++;
                            if (frameIndex != 10)
                            {
                                continue;
                            }

                            bitmapFrame10 = GraphicsHelper.LoadBitmapFromMappedTexture(actFrameBuffer);
                            break;
                        }
                    }

                    Assert.NotNull(bitmapFrame10);
                    Assert.True(videoReader.Duration > TimeSpan.FromSeconds(3.9));
                    Assert.True(videoReader.Duration < TimeSpan.FromSeconds(4.1));
                    Assert.True(videoReader.IsSeekable);
                    Assert.True(
                        BitmapComparison.IsNearEqual(bitmapFrame10, Properties.Resources.ReferenceImage_VideoFrameWmv));
                }
        }
Exemplo n.º 11
0
        public async Task LoadAndRender_StlFile()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

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

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

                // Import Fox model
                StlImportOptions importOptions = new StlImportOptions();
                importOptions.ResourceCoordinateSystem = CoordinateSystem.LeftHanded_UpZ;
                IEnumerable <SceneObject> loadedObjects = await memRenderTarget.Scene.ImportAsync(
                    new AssemblyResourceLink(
                        typeof(ModelLoadingAndRenderingTests),
                        "Ressources.Models.Fox.stl"),
                    importOptions);

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

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

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_ModelStl);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Exemplo n.º 12
0
        public async Task MemoryRenderTarget_2DInitError()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            GDI.Bitmap screenshot = null;
            using (UnitTestHelper.FailTestOnInternalExceptions())
                using (GraphicsCore.AutomatedTest_NewTestEnviornment())
                    using (GraphicsCore.AutomatedTest_ForceD2DInitError())
                    {
                        GraphicsCore.Initialize();
                        Assert.True(GraphicsCore.IsInitialized);
                        Assert.False(GraphicsCore.Current.DefaultDevice.Supports2D);

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

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

                                        // 2D rendering is made here
                                        Custom2DDrawingLayer d2dDrawingLayer = new Custom2DDrawingLayer((graphics) =>
                                        {
                                            RectangleF 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 <Direct2DTextureResource>(
                                                () => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                                            var resD2DMaterial = manipulator.AddSimpleColoredMaterial(resD2DTexture);
                                            var geoResource    = manipulator.AddResource <GeometryResource>(
                                                () => new GeometryResource(new PalletType(
                                                                               palletMaterial: NamedOrGenericKey.Empty,
                                                                               contentMaterial: resD2DMaterial)));

                                            GenericObject newObject = manipulator.AddGeneric(geoResource);
                                            newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                                            newObject.Scaling       = new Vector3(2f, 2f, 2f);
                                        });

                                        // Take screenshot
                                        await memRenderTarget.AwaitRenderAsync();

                                        screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

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

            // Calculate and check difference
            Assert.NotNull(screenshot);
            bool isNearEqual = BitmapComparison.IsNearEqual(
                screenshot, Properties.Resources.ReferenceImage_SimpleObject);

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