Exemple #1
0
        internal static void DrawNodesToImage(out byte[] imageRawBytes, IList <Node> nodes, int width, int height)
        {
            MeshBuffer         meshBuffer        = new MeshBuffer();
            MeshList           meshList          = new MeshList();
            IPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer();

            using (var context = new RenderContextForTest(width, height))
            {
                //This must be called after the context is created, for creating textures when the OpenGL context is built.
                foreach (var node in nodes)
                {
                    node.Draw(primitiveRenderer, meshList);
                }

                //rebuild mesh buffer
                meshBuffer.Clear();
                meshBuffer.Init();
                meshBuffer.Build(meshList);

                //draw mesh buffer to screen
                context.Clear();
                context.DrawMeshes(meshBuffer);

                imageRawBytes = context.GetRenderedRawBytes();
            }
        }
Exemple #2
0
        internal static void DrawNodeToImage_NewPipeline(out byte[] imageRawBytes, Node node, int width, int height)
        {
            Application.EnableMSAA = false;

            MeshBuffer meshBuffer = new MeshBuffer();
            MeshList   meshList   = new MeshList();
            BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer();

            using (var context = new RenderContextForTest(width, height))
            {
                RenderContext renderContext = new RenderContext(geometryRenderer, meshList);
                //This must be called after the RenderContextForTest is created, for uploading textures to GPU via OpenGL.
                node.Render(renderContext);

                //rebuild mesh buffer
                meshBuffer.Clear();
                meshBuffer.Init();
                meshBuffer.Build(meshList);

                //draw mesh buffer to screen
                context.Clear();
                context.DrawMeshes(meshBuffer);

                imageRawBytes = context.GetRenderedRawBytes();
            }
        }
Exemple #3
0
        internal static void DrawNodeTreeToImage(out byte[] imageRawBytes, Node root, int width, int height, Rect clipRect)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }

            MeshBuffer meshBuffer = new MeshBuffer();
            MeshList   meshList   = new MeshList();
            BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer();

            using (var context = new RenderContextForTest(width, height))
            {
                if (root is Node rootNode)
                {
                    using (var dc = rootNode.RenderOpen())
                    {
                        dc.DrawBoxModel(rootNode.RuleSet, rootNode.Rect);
                    }
                }

                root.Foreach(visual =>
                {
                    if (!(visual is Node node))
                    {
                        return(true);
                    }

                    using (var dc = node.RenderOpen())
                    {
                        dc.DrawBoxModel(node.RuleSet, node.Rect);
                    }

                    return(true);
                });

                //This must be called after the context is created, for uploading textures to GPU via OpenGL.
                root.Render(new RenderContext(geometryRenderer, meshList));

                //rebuild mesh buffer
                meshBuffer.Clear();
                meshBuffer.Init();
                meshBuffer.Build(meshList);

                //draw mesh buffer to screen
                context.Clear();
                context.DrawMeshes(meshBuffer);

                imageRawBytes = context.GetRenderedRawBytes();
            }
        }
Exemple #4
0
        internal static void DrawNodeTreeToImage(out byte[] imageRawBytes, Node root, int width, int height, Rect clipRect)
        {
            MeshBuffer meshBuffer        = new MeshBuffer();
            MeshList   meshList          = new MeshList();
            var        primitiveRenderer = new BuiltinPrimitiveRenderer();

            using (var context = new RenderContextForTest(width, height))
            {
                //This must be called after the context is created, for uploading textures to GPU via OpenGL.
                root.Foreach(n => primitiveRenderer.Draw(n, clipRect, meshList));

                //rebuild mesh buffer
                meshBuffer.Clear();
                meshBuffer.Init();
                meshBuffer.Build(meshList);

                //draw mesh buffer to screen
                context.Clear();
                context.DrawMeshes(meshBuffer);

                imageRawBytes = context.GetRenderedRawBytes();
            }
        }
Exemple #5
0
        internal static void CheckExpectedImage(PathPrimitive primitive, int width, int height, string expectedImageFilePath)
        {
            byte[] imageRawBytes;
            using (var context = new RenderContextForTest(width, height))
            {
                BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer();
                var mesh = new Mesh();
                mesh.CommandBuffer.Add(DrawCommand.Default);
                primitiveRenderer.DrawPathPrimitive(mesh, primitive, Vector.Zero);

                context.Clear();
                context.DrawShapeMesh(mesh);

                imageRawBytes = context.GetRenderedRawBytes();
            }
            var image = Util.CreateImage(imageRawBytes, width, height, flip: true);

#if DEBUG
            var expectedImage = Util.LoadImage(expectedImageFilePath);
            Assert.True(Util.CompareImage(expectedImage, image));
#else
            Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath); //generate expected image
#endif
        }