Exemple #1
0
 protected override void OnClosing()
 {
     //make current before clear GL resource
     _windowControl.MakeCurrent();
     if (_openGLViewport != null)
     {
         _openGLViewport.Close();
     }
     if (_windowControl != null)
     {
         _windowControl.Dispose();
     }
 }
        public void BindSurface(LayoutFarm.UI.GraphicsViewRoot surfaceViewport)
        {
            _myWidth  = 800;
            _myHeight = 600;

            _surfaceViewport = surfaceViewport;
            _rootGfx         = surfaceViewport.RootGfx;
            //----------------------

            _nativeWindow = surfaceViewport.MyNativeWindow;
            _nativeWindow.MakeCurrent();
        }
 public void MakeCurrent()
 {
     _viewport.MakeCurrent();
 }
        public void InitRootGraphics(RootGraphic rootgfx,
                                     ITopWindowEventRoot topWinEventRoot,
                                     InnerViewportKind innerViewportKind,
                                     IGpuOpenGLSurfaceView nativeWindow,
                                     AbstractTopWindowBridge bridge)
        {
            //create a proper bridge****
            _rootgfx           = rootgfx;
            _topWinEventRoot   = topWinEventRoot;
            _innerViewportKind = innerViewportKind;
            _viewport          = nativeWindow;
            _winBridge         = bridge;

            nativeWindow.SetSize(rootgfx.Width, rootgfx.Height);

            switch (innerViewportKind)
            {
            case InnerViewportKind.GdiPlusOnGLES:
            case InnerViewportKind.AggOnGLES:
            case InnerViewportKind.GLES:
            {
                _winBridge.OnHostControlLoaded();
                try
                {
                    nativeWindow.MakeCurrent();
                }
                catch (Exception ex)
                {
                }
                int w = nativeWindow.Width;
                int h = nativeWindow.Height;

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

                _pcx       = PixelFarm.DrawingGL.GLPainterCore.Create(max, max, w, h, true);
                _glPainter = new GLPainter();
                _glPainter.BindToPainterCore(_pcx);


                if (PixelFarm.Drawing.GLES2.GLES2Platform.TextService != null)
                {
                    var printer = new GLBitmapGlyphTextPrinter(_glPainter, PixelFarm.Drawing.GLES2.GLES2Platform.TextService);

                    _glPainter.TextPrinter = printer;
                }
                else
                {
                    //warn....!
                }

                //canvasPainter.SmoothingMode = PixelFarm.Drawing.SmoothingMode.HighQuality;
                //----------------------
                //1. win gdi based
                //var printer = new WinGdiFontPrinter(canvas2d, view.Width, view.Height);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //2. raw vxs
                //var printer = new PixelFarm.Drawing.Fonts.VxsTextPrinter(canvasPainter);
                //canvasPainter.TextPrinter = printer;
                //----------------------
                //3. agg texture based font texture
                //_glPainter.TextPrinter = new CpuBlitTextSpanPrinter2(_glPainter, 400, 50, PixelFarm.Drawing.GLES2.GLES2Platform.TextService);

                //TODO: review this again!
                //3
                var drawboard = new PixelFarm.Drawing.GLES2.MyGLDrawBoard(_glPainter);
                _glPainter.SetDrawboard(drawboard);
                _drawboard = drawboard;

                //{
                //in mixed mode
                //GDI+ on GLES, Agg on GLES we provide a software rendering layer too
                PixelFarm.Drawing.DrawBoard cpuDrawBoard = null;        // CreateSoftwareDrawBoard(view.Width, view.Height, innerViewportKind);
                drawboard.SetCpuBlitDrawBoardCreator(() => cpuDrawBoard ?? (cpuDrawBoard = CreateSoftwareDrawBoard(w, h, innerViewportKind)));
                //}
                ((OpenGL.MyTopWindowBridgeOpenGL)_winBridge).SetCanvas(drawboard);
            }
            break;
            }
        }
        public void LoadExample(DemoBase demoBase)
        {
            _nativeWindow.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()

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

            _bridgeUI.CreatePrimaryRenderElement(pcx, glPainter, _rootGfx);
            //-----------------------------------------------


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

            genEvListener.MouseDown += (s, e) =>
            {
                _demoBase.MouseDown(e.X, e.Y, e.Buttons == UIMouseButtons.Right);
                _bridgeUI.InvalidateGraphics();
            };
            genEvListener.MouseMove += (s, e) =>
            {
                if (e.IsDragging)
                {
                    _bridgeUI.InvalidateGraphics();
                    _demoBase.MouseDrag(e.X, e.Y);
                    _bridgeUI.InvalidateGraphics();
                }
            };
            genEvListener.MouseUp += (s, e) =>
            {
                _demoBase.MouseUp(e.X, e.Y);
            };
            //-----------------------------------------------
            _bridgeUI.AttachExternalEventListener(genEvListener);
        }