Пример #1
0
        public void LoadExample(DemoBase demoBase)
        {
            _gfxViewRoot.MakeCurrent();


            GLPainterCore pcx       = _gfxViewRoot.GLPainterCore();
            GLPainter     glPainter = _gfxViewRoot.GetGLPainter();

            pcx.SmoothMode = SmoothMode.Smooth;//set anti-alias

            //create text printer for opengl
            demoBase.Init();
            _demoBase = demoBase;

            _demoUI = new DemoUI(demoBase, _myWidth, _myHeight);
            _demoUI.SetCanvasPainter(pcx, glPainter);
            //-----------------------------------------------
            //demoBase.SetEssentialGLHandlers(
            //    () => _glControl.SwapBuffers(),
            //    () => _glControl.GetEglDisplay(),
            //    () => _glControl.GetEglSurface()
            //);
            //-----------------------------------------------

            DemoBase.InvokeGLPainterReady(demoBase, pcx, glPainter);
            //Add to RenderTree
            _rootGfx.AddChild(_demoUI.GetPrimaryRenderElement());
        }
Пример #2
0
            public DemoUI(DemoBase exBase, int width, int height)
            {
                _width  = width;
                _height = height;

                _exampleBase = exBase;
            }
Пример #3
0
        public void LoadDemo(Mini.DemoBase demo)
        {
            _demo = demo;
            demo.Init();

            int max = Math.Max(_w, _h);

            demo.Width  = _w;
            demo.Height = _h;
            GLPainterContext pcx           = null;
            GLPainter        canvasPainter = null;

            //if demo not create canvas and painter
            //the we create for it
            //int max = Math.Max(w, h);
            //canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max);
            //canvasPainter = new GLCanvasPainter(canvas2d, max, max);

            //canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(w, h);
            pcx            = GLPainterContext.Create(max, max, _w, _h, true);
            pcx.OriginKind = PixelFarm.Drawing.RenderSurfaceOrientation.LeftBottom;
            canvasPainter  = new GLPainter();
            canvasPainter.BindToPainterContext(pcx);

            //create text printer for opengl
            //----------------------
            //1. win gdi based
            //var printer = new WinGdiFontPrinter(canvas2d, w, h);
            //canvasPainter.TextPrinter = printer;
            //----------------------
            //2. raw vxs
            //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter);
            //canvasPainter.TextPrinter = printer;
            //----------------------
            //3. agg texture based font texture
            //var printer = new AggFontPrinter(canvasPainter, w, h);
            //canvasPainter.TextPrinter = printer;
            //----------------------
            //4. texture atlas based font texture
            //------------
            //resolve request font
            //var printer = new GLBmpGlyphTextPrinter(canvasPainter, YourImplementation.BootStrapWinGdi.myFontLoader);
            //canvasPainter.TextPrinter = printer;

            if (_getTextPrinterDel != null)
            {
                _getTextPrinterDel(canvasPainter);
            }



            demo.SetEssentialGLHandlers(
                () => { },
                () => IntPtr.Zero,
                () => IntPtr.Zero);

            DemoBase.InvokeGLPainterReady(demo, pcx, canvasPainter);
            DemoBase.InvokePainterReady(demo, canvasPainter);
        }
Пример #4
0
        public void LoadDemo(Mini.DemoBase demo)
        {
            this.demo = demo;
            demo.Init();

            int max = Math.Max(w, h);

            demo.Width  = w;
            demo.Height = h;
            GLRenderSurface glsx;
            GLPainter       canvasPainter;

            demo.BuildCustomDemoGLContext(out glsx, out canvasPainter);
            if (glsx == null)
            {
                //if demo not create canvas and painter
                //the we create for it
                //int max = Math.Max(w, h);
                //canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(max, max);
                //canvasPainter = new GLCanvasPainter(canvas2d, max, max);

                //canvas2d = PixelFarm.Drawing.GLES2.GLES2Platform.CreateCanvasGL2d(w, h);
                glsx          = PixelFarm.Drawing.GLES2.GLES2Platform.CreateGLRenderSurface(max, max, w, h);
                canvasPainter = new GLPainter(glsx);

                //create text printer for opengl
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(canvas2d, w, h);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //2. raw vxs
                //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //3. agg texture based font texture
                //var printer = new AggFontPrinter(canvasPainter, w, h);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //4. texture atlas based font texture
                //------------
                //resolve request font
                //var printer = new GLBmpGlyphTextPrinter(canvasPainter, YourImplementation.BootStrapWinGdi.myFontLoader);
                //canvasPainter.TextPrinter = printer;

                if (_getTextPrinterDel != null)
                {
                    _getTextPrinterDel(canvasPainter);
                }
            }

            demo.SetEssentialGLHandlers(
                () => { },
                () => IntPtr.Zero,
                () => IntPtr.Zero);

            DemoBase.InvokeGLContextReady(demo, glsx, canvasPainter);
            DemoBase.InvokePainterReady(demo, canvasPainter);
        }
Пример #5
0
 public void LoadDemo(DemoBase demo)
 {
     _demo = demo;
     if (_painter != null)
     {
         DemoBase.InvokePainterReady(_demo, _painter);
     }
 }
Пример #6
0
 public void LoadExample(DemoBase exBase)
 {
     this.exampleBase = exBase;
     if (painter != null)
     {
         DemoBase.InvokePainterReady(exBase, painter);
     }
     //exBase.RequestNewGfx2d += () => this.bitmapBackBuffer.CreateNewGraphic2D();
 }
Пример #7
0
        public void LoadExample(ExampleAndDesc exAndDesc, DemoBase exBase)
        {
            _exampleBase = exBase;
            this.Text    = exAndDesc.ToString();
            //-------------------------------------------
            //description:
            if (!string.IsNullOrEmpty(exAndDesc.Description))
            {
                TextBox tt = new TextBox();
                tt.Width      = this.flowLayoutPanel1.Width - 5;
                tt.Text       = exAndDesc.Description;
                tt.Multiline  = true;
                tt.ScrollBars = ScrollBars.Vertical;
                tt.Height     = 250;
                tt.BackColor  = Color.Gainsboro;
                tt.Font       = new Font("tahoma", 10);
                this.flowLayoutPanel1.Controls.Add(tt);
            }
            //-------------------------------------------
            _allConfigs.Clear();

            _mainConfigs                    = new ExampleConfigs();
            _mainConfigs._configList        = exAndDesc.GetConfigList();
            _mainConfigs._exampleActionList = exAndDesc.GetActionList();
            _allConfigs.Add(_mainConfigs);

            CreateConfigPresentation(_exampleBase, _mainConfigs, this.flowLayoutPanel1);

            ////--------------------
            var _groupConfigs = exAndDesc.GetGroupConfigList();

            if (_groupConfigs != null)
            {
                int j = _groupConfigs.Count;
                for (int i = 0; i < j; ++i)
                {
                    ExampleGroupConfigDesc groupConfig = _groupConfigs[i];
                    object groupOwner = groupConfig.OwnerProperty.GetGetMethod().Invoke(_exampleBase, null);

                    var subConfig = new ExampleConfigs();

                    subConfig._configList        = groupConfig._configList;
                    subConfig._exampleActionList = groupConfig._configActionList;
                    _allConfigs.Add(subConfig);
                    //
                    Panel subPanel = new Panel();
                    subPanel.Width  = flowLayoutPanel1.Width;
                    subPanel.Height = 300;//example
                    flowLayoutPanel1.Controls.Add(subPanel);

                    CreateConfigPresentation(groupOwner, subConfig, subPanel);
                }
            }
        }
Пример #8
0
        static DemoBase InitDemo(ExampleAndDesc exampleAndDesc)
        {
            DemoBase exBase = Activator.CreateInstance(exampleAndDesc.Type) as DemoBase;

            if (exBase == null)
            {
                return(null);
            }
            exBase.Init();
            return(exBase);
        }
Пример #9
0
        public void Close()
        {
            _demoBase.CloseDemo();
            _demoBase = null;

            if (_surfaceViewport != null)
            {
                _surfaceViewport.Close();
                _surfaceViewport = null;
            }
            _rootGfx = null;
        }
Пример #10
0
        public void LoadExample(ExampleAndDesc exAndDesc)
        {
            DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase;

            if (exBase == null)
            {
                return;
            }

            this.Text = exAndDesc.ToString();
            //----------------------------------------------------------------------------
            this.exampleBase = exBase;
            exampleBase.Init();
        }
Пример #11
0
        void listBox1_DoubleClick(object sender, EventArgs e)
        {
            //load sample form
            ExampleAndDesc exAndDesc = this.listBox1.SelectedItem as ExampleAndDesc;

            if (exAndDesc != null)
            {
                DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase;
                if (exBase == null)
                {
                    return;
                }
                exBase.Init();
                //FormTestBed1 testBed = new FormTestBed1();
                //testBed.WindowState = FormWindowState.Maximized;
                //testBed.Show();
                //testBed.LoadExample(exAndDesc);
            }
        }
Пример #12
0
        public void LoadExample(ExampleAndDesc exAndDesc)
        {
            DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase;

            if (exBase == null)
            {
                return;
            }

            this.exampleBase = exBase;
            exampleBase.Init();
            this.softAggControl2.LoadExample(exampleBase);
            this.Text = exAndDesc.ToString();
            //-------------------------------------------
            //description:
            if (!string.IsNullOrEmpty(exAndDesc.Description))
            {
                TextBox tt = new TextBox();
                tt.Width      = this.flowLayoutPanel1.Width - 5;
                tt.Text       = exAndDesc.Description;
                tt.Multiline  = true;
                tt.ScrollBars = ScrollBars.Vertical;
                tt.Height     = 250;
                tt.BackColor  = Color.Gainsboro;
                tt.Font       = new Font("tahoma", 10);
                this.flowLayoutPanel1.Controls.Add(tt);
            }
            //-------------------------------------------
            this.configList = exAndDesc.GetConfigList();
            if (configList != null)
            {
                int j = configList.Count;
                for (int i = 0; i < j; ++i)
                {
                    ExampleConfigDesc config = configList[i];
                    switch (config.PresentaionHint)
                    {
                    case DemoConfigPresentaionHint.CheckBox:
                    {
                        CheckBox checkBox = new CheckBox();
                        checkBox.Text  = config.Name;
                        checkBox.Width = 400;
                        bool currentValue = (bool)config.InvokeGet(exampleBase);
                        checkBox.Checked         = currentValue;
                        checkBox.CheckedChanged += (s, e) =>
                        {
                            config.InvokeSet(exBase, checkBox.Checked);
                            InvalidateSampleViewPort();
                        };
                        this.flowLayoutPanel1.Controls.Add(checkBox);
                    }
                    break;

                    case DemoConfigPresentaionHint.SlideBarDiscrete:
                    {
                        Label descLabel = new Label();
                        descLabel.Width = 400;
                        this.flowLayoutPanel1.Controls.Add(descLabel);
                        var        originalConfig = config.OriginalConfigAttribute;
                        HScrollBar hscrollBar     = new HScrollBar();
                        hscrollBar.Width       = flowLayoutPanel1.Width;
                        hscrollBar.Minimum     = originalConfig.MinValue;
                        hscrollBar.Maximum     = originalConfig.MaxValue + 10;
                        hscrollBar.SmallChange = 1;
                        //current value
                        int value = (int)config.InvokeGet(exampleBase);
                        hscrollBar.Value = value;
                        //-------------
                        descLabel.Text           = config.Name + ":" + hscrollBar.Value;
                        hscrollBar.ValueChanged += (s, e) =>
                        {
                            config.InvokeSet(exampleBase, hscrollBar.Value);
                            descLabel.Text = config.Name + ":" + hscrollBar.Value;
                            InvalidateSampleViewPort();
                        };
                        this.flowLayoutPanel1.Controls.Add(hscrollBar);
                    }
                    break;

                    case DemoConfigPresentaionHint.SlideBarContinuous_R4:
                    {
                        Label descLabel = new Label();
                        descLabel.Width = 400;
                        this.flowLayoutPanel1.Controls.Add(descLabel);
                        var        originalConfig = config.OriginalConfigAttribute;
                        HScrollBar hscrollBar     = new HScrollBar();
                        //100 => for scale factor

                        hscrollBar.Width       = flowLayoutPanel1.Width;
                        hscrollBar.Minimum     = originalConfig.MinValue * 100;
                        hscrollBar.Maximum     = (originalConfig.MaxValue * 100) + 10;
                        hscrollBar.SmallChange = 1;
                        //current value

                        float doubleValue = ((float)config.InvokeGet(exampleBase) * 100);
                        hscrollBar.Value = (int)doubleValue;
                        //-------------
                        descLabel.Text           = config.Name + ":" + ((float)hscrollBar.Value / 100d).ToString();
                        hscrollBar.ValueChanged += (s, e) =>
                        {
                            float value = (float)(hscrollBar.Value / 100f);
                            config.InvokeSet(exampleBase, value);
                            descLabel.Text = config.Name + ":" + value.ToString();
                            InvalidateSampleViewPort();
                        };
                        this.flowLayoutPanel1.Controls.Add(hscrollBar);
                    }
                    break;

                    case DemoConfigPresentaionHint.SlideBarContinuous_R8:
                    {
                        Label descLabel = new Label();
                        descLabel.Width = 400;
                        this.flowLayoutPanel1.Controls.Add(descLabel);
                        var        originalConfig = config.OriginalConfigAttribute;
                        HScrollBar hscrollBar     = new HScrollBar();
                        //100 => for scale factor

                        hscrollBar.Width       = flowLayoutPanel1.Width;
                        hscrollBar.Minimum     = originalConfig.MinValue * 100;
                        hscrollBar.Maximum     = (originalConfig.MaxValue * 100) + 10;
                        hscrollBar.SmallChange = 1;
                        //current value

                        double doubleValue = ((double)config.InvokeGet(exampleBase) * 100);
                        hscrollBar.Value = (int)doubleValue;
                        //-------------
                        descLabel.Text           = config.Name + ":" + ((double)hscrollBar.Value / 100d).ToString();
                        hscrollBar.ValueChanged += (s, e) =>
                        {
                            double value = (double)hscrollBar.Value / 100d;
                            config.InvokeSet(exampleBase, value);
                            descLabel.Text = config.Name + ":" + value.ToString();
                            InvalidateSampleViewPort();
                        };
                        this.flowLayoutPanel1.Controls.Add(hscrollBar);
                    }
                    break;

                    case DemoConfigPresentaionHint.OptionBoxes:
                    {
                        List <ExampleConfigValue> optionFields = config.GetOptionFields();
                        FlowLayoutPanel           panelOption  = new FlowLayoutPanel();
                        int totalHeight = 0;
                        int m           = optionFields.Count;
                        //current value
                        int currentValue = (int)config.InvokeGet(exampleBase);
                        for (int n = 0; n < m; ++n)
                        {
                            ExampleConfigValue ofield = optionFields[n];
                            RadioButton        radio  = new RadioButton();
                            panelOption.Controls.Add(radio);
                            radio.Text    = ofield.Name;
                            radio.Width   = 400;
                            radio.Checked = ofield.ValueAsInt32 == currentValue;
                            radio.Click  += (s, e) =>
                            {
                                if (radio.Checked)
                                {
                                    ofield.InvokeSet(this.exampleBase);
                                    InvalidateSampleViewPort();
                                }
                            };
                            totalHeight += radio.Height + 10;
                        }



                        panelOption.Height        = totalHeight;
                        panelOption.FlowDirection = FlowDirection.TopDown;
                        this.flowLayoutPanel1.Controls.Add(panelOption);
                    }
                    break;

                    case DemoConfigPresentaionHint.TextBox:
                    {
                        Label descLabel = new Label();
                        descLabel.Width = 400;
                        descLabel.Text  = config.Name;
                        this.flowLayoutPanel1.Controls.Add(descLabel);
                        TextBox textBox = new TextBox();
                        textBox.Width = 400;
                        this.flowLayoutPanel1.Controls.Add(textBox);
                    }
                    break;
                    }
                }
            }
        }
Пример #13
0
 public DemoUI(DemoBase demobase, int width, int height)
 {
     _width    = width;
     _height   = height;
     _demoBase = demobase;
 }
Пример #14
0
 public void Dispose()
 {
     _painter = null;
     _demo    = null;
 }
Пример #15
0
        void lstExample_DoubleClick(object sender, EventArgs e)
        {
            //load sample form
            if (!(this.lstExamples.SelectedItem is ExampleAndDesc exAndDesc))
            {
                return; //early exit
            }
            //
            DemoBase demo = InitDemo(exAndDesc);

            if (demo == null)
            {
                return;
            }


            FormTestBed formTestBed = new FormTestBed();

            formTestBed.WindowState = FormWindowState.Maximized;

            RenderBackendChoice selItem = (RenderBackendChoice)lstBackEndRenderer.SelectedItem;
            CpuBlitAppModule    cpuBlitContextWinForm = null;

            switch (selItem)
            {
            case RenderBackendChoice.PureAgg:
            {
                LayoutFarm.UI.FormCanvasHelper.CreateCanvasControlOnExistingControl(
                    formTestBed.GetLandingControl(),
                    0, 0, 800, 600,
                    LayoutFarm.UI.InnerViewportKind.PureAgg,
                    out LayoutFarm.UI.GraphicsViewRoot surfaceViewport
                    );
                formTestBed.SetUISurfaceViewportControl(surfaceViewport);
                formTestBed.Show();

                cpuBlitContextWinForm = new CpuBlitAppModule();
                cpuBlitContextWinForm.BindSurface(surfaceViewport);
                cpuBlitContextWinForm.LoadExample(demo);

                demo.RequestGraphicRefresh += (s, e1) => cpuBlitContextWinForm.InvalidateUI();

                formTestBed.FormClosed += (s1, e1) => cpuBlitContextWinForm.Close();
                formTestBed.LoadExample(exAndDesc, demo);
            }
            break;

            case RenderBackendChoice.GdiPlus:
            {
                LayoutFarm.UI.FormCanvasHelper.CreateCanvasControlOnExistingControl(
                    formTestBed.GetLandingControl(),
                    0, 0, 800, 600,
                    LayoutFarm.UI.InnerViewportKind.GdiPlus,
                    out LayoutFarm.UI.GraphicsViewRoot surfaceViewport
                    );
                formTestBed.SetUISurfaceViewportControl(surfaceViewport);

                cpuBlitContextWinForm = new CpuBlitAppModule();
                cpuBlitContextWinForm.BindSurface(surfaceViewport);
                cpuBlitContextWinForm.LoadExample(demo);
                formTestBed.FormClosed += (s1, e1) => cpuBlitContextWinForm.Close();



                formTestBed.LoadExample(exAndDesc, demo);
                formTestBed.Show();
            }
            break;

            case RenderBackendChoice.OpenGLES:     //gles 2 and 3
            {
                //--------------------------------------------
                LayoutFarm.UI.FormCanvasHelper.CreateCanvasControlOnExistingControl(
                    formTestBed.GetLandingControl(),
                    0, 0, 800, 600,
                    LayoutFarm.UI.InnerViewportKind.GLES,
                    out LayoutFarm.UI.GraphicsViewRoot surfaceViewport
                    );

                formTestBed.SetUISurfaceViewportControl(surfaceViewport);
                GLESAppModule appModule = new GLESAppModule();
                appModule.BindSurface(surfaceViewport);
                appModule.LoadExample(demo);
                formTestBed.FormClosing += (s2, e2) => appModule.Close();

                formTestBed.LoadExample(exAndDesc, demo);
                formTestBed.Show();
            }
            break;

            case RenderBackendChoice.AggOnGLES:
            case RenderBackendChoice.GdiPlusOnGLES:
            {
                LayoutFarm.UI.FormCanvasHelper.CreateCanvasControlOnExistingControl(
                    formTestBed.GetLandingControl(),
                    0, 0, 800, 600,
                    LayoutFarm.UI.InnerViewportKind.AggOnGLES,
                    out LayoutFarm.UI.GraphicsViewRoot surfaceViewport
                    );
                formTestBed.SetUISurfaceViewportControl(surfaceViewport);
                //

                CpuBlitOnGLESAppModule appModule = new CpuBlitOnGLESAppModule();
                appModule.WithGdiPlusDrawBoard = (selItem == RenderBackendChoice.GdiPlusOnGLES);        //**
                appModule.BindSurface(surfaceViewport);
                appModule.LoadExample(demo);

                formTestBed.FormClosing += (s2, e2) => appModule.Close();
                formTestBed.LoadExample(exAndDesc, demo);
                formTestBed.Show();
            }
            break;

#if SKIA_ENABLE
            case RenderBackendChoice.SkiaMemoryBackend:
            {
                TestSkia1.FormSkia1 formSkia = new TestSkia1.FormSkia1();
                formSkia.SelectBackend(TestSkia1.FormSkia1.SkiaBackend.Memory);
                formSkia.Show();
                formSkia.LoadExample(exAndDesc);
            }
            break;

            case RenderBackendChoice.SkiaGLBackend:
            {
                TestSkia1.FormSkia1 formSkia = new TestSkia1.FormSkia1();
                formSkia.SelectBackend(TestSkia1.FormSkia1.SkiaBackend.GLES);
                formSkia.Show();
                formSkia.LoadExample(exAndDesc);
            }
            break;
#endif
            default:
                throw new NotSupportedException();
            }
        }
Пример #16
0
 public void LoadExample(DemoBase exBase)
 {
     this.exampleBase        = exBase;
     exBase.RequestNewGfx2d += () => this.bitmapBackBuffer.CreateNewGraphic2D();
 }
Пример #17
0
 public void LoadExample(DemoBase exBase)
 {
     _demoUI = new DemoUI(exBase, _myWidth, _myHeight);
     _rootGfx.AddChild(_demoUI.GetPrimaryRenderElement(_surfaceViewport.RootGfx));
 }
Пример #18
0
 public static void InvokeGLContextReady(DemoBase demo, GLRenderSurface glsx, GLPainter painter)
 {
     demo._painter = painter;
     demo.OnGLSurfaceReady(glsx, painter);
     demo.OnReadyForInitGLShaderProgram();
 }
Пример #19
0
        void listBox1_DoubleClick(object sender, EventArgs e)
        {
            //load sample form
            ExampleAndDesc exAndDesc = this.listBox1.SelectedItem as ExampleAndDesc;

            if (exAndDesc == null)
            {
                return; //early exit
            }
            //
            //
            switch ((RenderBackendChoice)lstBackEndRenderer.SelectedItem)
            {
            case RenderBackendChoice.PureAgg:
            {
                FormTestBed testBed = new FormTestBed();
                testBed.WindowState      = FormWindowState.Maximized;
                testBed.UseGdiPlusOutput = false;
                testBed.UseGdiAntiAlias  = chkGdiAntiAlias.Checked;
                testBed.Show();
                testBed.LoadExample(exAndDesc);
            }
            break;

            case RenderBackendChoice.GdiPlus:
            {
                FormTestBed testBed = new FormTestBed();
                testBed.WindowState      = FormWindowState.Maximized;
                testBed.UseGdiPlusOutput = true;
                testBed.UseGdiAntiAlias  = chkGdiAntiAlias.Checked;
                testBed.Show();
                testBed.LoadExample(exAndDesc);
            }
            break;

            case RenderBackendChoice.OpenGLES2:
            {
                //create demo
                DemoBase exBase = Activator.CreateInstance(exAndDesc.Type) as DemoBase;
                if (exBase == null)
                {
                    return;
                }

                //create form
                FormGLTest formGLTest = new FormGLTest();
                formGLTest.Text = exAndDesc.ToString();
                formGLTest.Show();
                //----------------------
                //get target control that used to present the example
                OpenTK.MyGLControl control = formGLTest.InitMiniGLControl(800, 600);

                {
                    GLDemoContextWinForm glbaseDemo = new GLDemoContextWinForm();
                    glbaseDemo.LoadGLControl(control);
                    glbaseDemo.LoadSample(exBase);
                    //----------------------
                    formGLTest.FormClosing += (s2, e2) =>
                    {
                        glbaseDemo.CloseDemo();
                    };
                }
                //{
                //    //test another example
                //    DemoBase exBase2 = Activator.CreateInstance(exAndDesc.Type) as DemoBase;
                //    OpenTK.MyGLControl control2 = formGLTest.InitMiniGLControl2(400, 300);
                //    GLDemoContextWinForm glbaseDemo = new GLDemoContextWinForm();
                //    glbaseDemo.LoadGLControl(control2);
                //    glbaseDemo.LoadSample(exBase2);
                //    //----------------------
                //    formGLTest.FormClosing += (s2, e2) =>
                //    {
                //        glbaseDemo.CloseDemo();
                //    };
                //}


                formGLTest.WindowState = FormWindowState.Maximized;
            }
            break;

#if SKIA_ENABLE
            case RenderBackendChoice.SkiaMemoryBackend:
            {
                TestSkia1.FormSkia1 formSkia = new TestSkia1.FormSkia1();
                formSkia.SelectBackend(TestSkia1.FormSkia1.SkiaBackend.Memory);
                formSkia.Show();
                formSkia.LoadExample(exAndDesc);
            }
            break;

            case RenderBackendChoice.SkiaGLBackend:
            {
                TestSkia1.FormSkia1 formSkia = new TestSkia1.FormSkia1();
                formSkia.SelectBackend(TestSkia1.FormSkia1.SkiaBackend.GLES);
                formSkia.Show();
                formSkia.LoadExample(exAndDesc);
            }
            break;
#endif
            default:
                throw new NotSupportedException();
            }
        }
Пример #20
0
 public static void InvokeGLPainterReady(DemoBase demo, GLPainterContext pcx, GLPainter painter)
 {
     demo.OnGLPainterReady(painter);
     demo.OnReadyForInitGLShaderProgram();
 }
Пример #21
0
 public static void InvokePainterReady(DemoBase demo, Painter painter)
 {
     demo.OnPainterReady(painter);
 }
Пример #22
0
        public void LoadExample(DemoBase demoBase)
        {
            _glControl.MakeCurrent();

            _demoBase = demoBase;
            demoBase.Init();

            if (WithGdiPlusDrawBoard)
            {
                _bridgeUI = new GdiOnGLESUIElement(_myWidth, _myHeight);
            }
            else
            {
                //pure agg's cpu blit
                _bridgeUI = new CpuBlitGLESUIElement(_myWidth, _myHeight);
            }
            //
            _bridgeUI.SetUpdateCpuBlitSurfaceDelegate((p, updateArea) => _demoBase.Draw(p));

            DemoBase.InvokePainterReady(_demoBase, _bridgeUI.GetAggPainter());
            //
            //use existing GLRenderSurface and GLPainter
            //see=>UISurfaceViewportControl.InitRootGraphics()

            GLPainterContext pcx       = _surfaceViewport.GetGLRenderSurface();
            GLPainter        glPainter = _surfaceViewport.GetGLPainter();

            _bridgeUI.CreatePrimaryRenderElement(pcx, glPainter, _rootGfx);
            //-----------------------------------------------
            demoBase.SetEssentialGLHandlers(
                () => _glControl.SwapBuffers(),
                () => _glControl.GetEglDisplay(),
                () => _glControl.GetEglSurface()
                );
            //-----------------------------------------------
            DemoBase.InvokeGLPainterReady(demoBase, pcx, glPainter);
            //Add to RenderTree
            _rootGfx.AddChild(_bridgeUI.GetPrimaryRenderElement(_rootGfx));
            //-----------------------------------------------
            //***
            GeneralEventListener genEvListener = new GeneralEventListener();

            genEvListener.MouseDown += e =>
            {
                _demoBase.MouseDown(e.X, e.Y, e.Button == UIMouseButtons.Right);
                _bridgeUI.InvalidateGraphics();
            };
            genEvListener.MouseMove += e =>
            {
                if (e.IsDragging)
                {
                    _bridgeUI.InvalidateGraphics();
                    _demoBase.MouseDrag(e.X, e.Y);
                    _bridgeUI.InvalidateGraphics();
                }
            };
            genEvListener.MouseUp += e =>
            {
                _demoBase.MouseUp(e.X, e.Y);
            };
            //-----------------------------------------------
            _bridgeUI.AttachExternalEventListener(genEvListener);
        }
Пример #23
0
        public void LoadSample(DemoBase demobase)
        {
            this.demobase = demobase;
            //1.
            //note:when we init,
            //no glcanvas/ painter are created
            demobase.Init();
            //-----------------------------------------------
            //2. check if demo will create canvas/painter context
            //or let this GLDemoContext create for it

            hh1 = glControl.Handle; //ensure that contrl handler is created
            glControl.MakeCurrent();

            demobase.BuildCustomDemoGLContext(out this._glsx, out this.canvasPainter);
            //
            if (this._glsx == null)
            {
                //if demo not create canvas and painter
                //the we create for it
                int max = Math.Max(glControl.Width, glControl.Height);
                _glsx            = PixelFarm.Drawing.GLES2.GLES2Platform.CreateGLRenderSurface(max, max, glControl.Width, glControl.Height);
                _glsx.SmoothMode = SmoothMode.Smooth;//set anti-alias
                canvasPainter    = new GLPainter(_glsx);
                //create text printer for opengl
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(_glsx, glControl.Width, glControl.Height);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //2. raw vxs
                //var openFontStore = new Typography.TextServices.OpenFontStore();
                //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter,openFontStore);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //3. agg texture based font texture

                //var printer = new AggTextSpanPrinter(canvasPainter, glControl.Width, 30);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //4. texture atlas based font texture
                //------------
                //resolve request font
                var printer = new GLBitmapGlyphTextPrinter(canvasPainter, PixelFarm.Drawing.GLES2.GLES2Platform.TextService);
                canvasPainter.TextPrinter = printer;

                //var openFontStore = new Typography.TextServices.OpenFontStore();
                //var printer = new GLBmpGlyphTextPrinter(canvasPainter, openFontStore);
                //canvasPainter.TextPrinter = printer;
            }

            //-----------------------------------------------
            demobase.SetEssentialGLHandlers(
                () => this.glControl.SwapBuffers(),
                () => this.glControl.GetEglDisplay(),
                () => this.glControl.GetEglSurface()
                );
            //-----------------------------------------------
            this.glControl.SetGLPaintHandler((s, e) =>
            {
                demobase.InvokeGLPaint();
            });
            DemoBase.InvokeGLContextReady(demobase, this._glsx, this.canvasPainter);
            DemoBase.InvokePainterReady(demobase, this.canvasPainter);
        }