Пример #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();
            }
        }
Пример #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();
            }
        }
Пример #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();
            }
        }
Пример #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();
            }
        }