Пример #1
0
        protected override void OnRenderFrame(Rect rect)
        {
            // clear everything
            Gles.glClear(Gles.GL_COLOR_BUFFER_BIT | Gles.GL_DEPTH_BUFFER_BIT | Gles.GL_STENCIL_BUFFER_BIT);

            // create the SkiaSharp context
            if (context == null)
            {
                glInterface = GRGlInterface.CreateNativeAngleInterface();
                context     = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // manage the drawing surface
            if (renderTarget == null || surface == null || renderTarget.Width != (int)rect.Width || renderTarget.Height != (int)rect.Height)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                renderTarget = SKGLDrawable.CreateRenderTarget((int)rect.Width, (int)rect.Height);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888));
            }

            // update the control
            surface.Canvas.Flush();
            context.Flush();
        }
Пример #2
0
        protected override void OnRenderFrame(Rect rect)
        {
            base.OnRenderFrame(rect);

            if (designMode)
            {
                return;
            }

            if (!isVisible)
            {
                return;
            }

            // create the SkiaSharp context
            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeAngleInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);

                renderTarget = SKGLDrawable.CreateRenderTarget();
            }

            // set the size
            renderTarget.Width  = (int)rect.Width;
            renderTarget.Height = (int)rect.Height;

            // create the surface
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw to the SkiaSharp surface
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                // flush the canvas
                surface.Canvas.Flush();
            }

            // flush the SkiaSharp context to the GL context
            context.Flush();
        }