internal static void CheckRectangle(Brush brush, Pen pen, Rect rectangle,
                                                int width, int height,
                                                [CallerMemberName] string methodName = "unknown")
            {
                Application.EnableMSAA = false;

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

                byte[] bytes;

                using (var context = new RenderContextForTest(width, height))
                {
                    renderer.OnBeforeRead();
                    renderer.DrawRectangle(brush, pen, rectangle);//This must be called after the RenderContextForTest is created, for uploading textures to GPU via OpenGL.
                    renderer.OnAfterRead(meshList);

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

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

                    bytes = context.GetRenderedRawBytes();
                }

                Util.CheckExpectedImage(bytes, width, height, $"{RootDir}{nameof(DrawRectangle)}\\{methodName}.png");
            }
示例#2
0
        internal static void DrawNodesToImage(out byte[] imageRawBytes, IList <Node> nodes, int width, int height)
        {
            MeshBuffer        meshBuffer       = new MeshBuffer();
            MeshList          meshList         = new MeshList();
            IGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer();

            using (var context = new RenderContextForTest(width, height))
            {
                //This must be called after the context is created, for uploading textures to GPU via OpenGL.
                foreach (var node in nodes)
                {
                    node.Draw(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();
            }
        }
示例#3
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();
            }
        }
示例#4
0
文件: Util.cs 项目: peter-819/ImGui
        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();
            }
        }
示例#5
0
文件: Util.cs 项目: peter-819/ImGui
        public static byte[] DrawAsOpenGLPixelBytes(FormattedText formattedText,
                                                    Brush brush, int width, int height, Rect clipRect)
        {
            BuiltinGeometryRenderer renderer = new BuiltinGeometryRenderer();

            renderer.PushClipRect(clipRect);
            renderer.OnBeforeRead();
            renderer.DrawEllipse(null, new Pen(Color.DarkSeaGreen, 1),
                                 formattedText.OriginPoint, 2, 2);
            renderer.DrawLine(new Pen(Color.Gray, 1), formattedText.OriginPoint,
                              formattedText.OriginPoint + new Vector(width, 0));
            renderer.DrawText(brush, formattedText);
            var mesh     = renderer.ShapeMesh;
            var textMesh = renderer.TextMesh;
            var bytes    = Util.DrawAsOpenGLPixelBytes(mesh, textMesh, width, height);

            return(bytes);
        }
示例#6
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 BuiltinGeometryRenderer();

            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();
            }
        }
示例#7
0
文件: Util.cs 项目: peter-819/ImGui
        internal static void DrawDrawingVisualToImage(out byte[] imageRawBytes,
                                                      int width, int height, DrawingVisual drawingVisual)
        {
            //convert geometries inside the drawingVisual's content to meshes stored in a MeshList with a BuiltinGeometryRenderer
            MeshList meshList = new MeshList();

            using BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer();
            RenderContext renderContext = new RenderContext(geometryRenderer, meshList);

            drawingVisual.RenderContent(renderContext);

            //merge meshes in the MeshList to a MeshBuffer
            MeshBuffer meshBuffer = new MeshBuffer();

            meshBuffer.Clear();
            meshBuffer.Init();
            meshBuffer.Build(meshList);

            //created a mesh IRenderer
            Application.Init();
            var window = Application.PlatformContext.CreateWindow(Point.Zero, new Size(100, 100),
                                                                  WindowTypes.Hidden);
            var renderer = Application.PlatformContext.CreateRenderer() as Win32OpenGLRenderer;//TEMP HACK

            Debug.Assert(renderer != null, nameof(renderer) + " != null");
            renderer.Init(window.Pointer, window.ClientSize);

            //clear the canvas and draw mesh in the MeshBuffer with the mesh renderer
            renderer.Clear(Color.White);
            renderer.StartDrawMeshToImage(width, height);
            imageRawBytes = renderer.DrawMeshToImage(width, height, meshBuffer.ShapeMesh, OpenGLMaterial.shapeMaterial);
            renderer.EndDrawMeshToImage();

            //clear native resources: window and IRenderer
            renderer.ShutDown();
            window.Close();
        }
示例#8
0
            public void ShowAnimateNode()
            {
                //FIXME make this test automatable

                Application.IsRunningInUnitTest = true;
                Application.InitSysDependencies();

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

                var primitiveRenderer = new BuiltinGeometryRenderer();

                Node node = new Node(1);

                node.Geometry = new PathGeometry();

                var window = new Win32Window();

                window.Init(new Point(100, 100), new Size(800, 600), WindowTypes.Regular);

                var renderer = new Win32OpenGLRenderer();

                renderer.Init(window.Pointer, window.ClientSize);

                window.Show();

                var A = new Point(200, 200);
                var B = new Point(600, 200);
                var C = new Point(400, 400);

                while (true)
                {
                    Time.OnFrameBegin();
                    Keyboard.Instance.OnFrameBegin();

                    window.MainLoop(() =>
                    {
                        if (Keyboard.Instance.KeyDown(Key.Escape))
                        {
                            Application.Quit();
                        }

                        var normal = (Time.time % 1000) / 1000f * 2 - 1;
                        var rad    = normal * Math.PI;
                        var A_     = A + 50 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad));
                        rad       += Math.PI * 0.333;
                        var B_     = B + 30 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad));
                        rad       += Math.PI * 0.666;
                        var C_     = C + 70 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad));

                        var d = node.Geometry as PathGeometry;
                        d.PathClear();
                        d.PathMoveTo(A_);
                        d.PathLineTo(B_);
                        d.PathLineTo(C_);
                        d.PathStroke(2, Color.Blue);

                        //update nodes
                        if (node.ActiveInTree)//this is actually always true
                        {
                            node.Draw(primitiveRenderer, meshList);
                        }

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

                        //draw mesh buffer to screen
                        renderer.Clear(Color.FrameBg);
                        renderer.DrawMeshes((int)window.ClientSize.Width, (int)window.ClientSize.Height,
                                            (shapeMesh: meshBuffer.ShapeMesh, imageMesh: meshBuffer.ImageMesh, meshBuffer.TextMesh));
                        renderer.SwapBuffers();
                    });

                    if (Application.RequestQuit)
                    {
                        break;
                    }

                    Keyboard.Instance.OnFrameEnd();
                    Time.OnFrameEnd();
                }
            }