Example #1
0
        public virtual void Render()
        {
            if (glContext == null)
            {
                PrepareGLContexts();
            }

            EAGLContext.SetCurrentContext(glContext);

            // create the surface
            if (renderTarget.Width == 0 || renderTarget.Height == 0)
            {
                renderTarget = SKGLDrawable.CreateRenderTarget();
            }
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw on the surface
                DrawInSurface(surface, renderTarget);
                SKDelegate?.DrawInSurface(surface, renderTarget);

                surface.Canvas.Flush();
            }

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

            // present the GL buffers
            glContext.PresentRenderBuffer((uint)RenderbufferTarget.Renderbuffer);
            EAGLContext.SetCurrentContext(null);
        }
Example #2
0
        public override void DrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
        {
            CGLContext.CurrentContext = glContext;

            if (context == null)
            {
                // get the bits for SkiaSharp
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);
            }

            // create the surface
            renderTarget        = SKGLDrawable.CreateRenderTarget();
            renderTarget.Width  = (int)(Bounds.Width * ContentsScale);
            renderTarget.Height = (int)(Bounds.Height * ContentsScale);
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw on the surface
                DrawInSurface(surface, renderTarget);
                SKDelegate?.DrawInSurface(surface, renderTarget);

                surface.Canvas.Flush();
            }

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

            base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp);
        }
Example #3
0
        public new void DrawInRect(GLKView view, CGRect rect)
        {
            if (designMode)
            {
                return;
            }

            if (context == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                context = GRContext.Create(GRBackend.OpenGL, glInterface);

                // get the initial details
                renderTarget = SKGLDrawable.CreateRenderTarget();
            }

            // set the dimensions as they might have changed
            renderTarget.Width  = (int)DrawableWidth;
            renderTarget.Height = (int)DrawableHeight;

            // create the surface
            using (var surface = SKSurface.Create(context, renderTarget))
            {
                // draw on the surface
                DrawInSurface(surface, renderTarget);

                surface.Canvas.Flush();
            }

            // flush the SkiaSharp contents to GL
            context.Flush();
        }
Example #4
0
        public override void PrepareOpenGL()
        {
            base.PrepareOpenGL();

            // create the context
            var glInterface = GRGlInterface.CreateNativeGlInterface();

            context = GRContext.Create(GRBackend.OpenGL, glInterface);

            renderTarget = SKGLDrawable.CreateRenderTarget();
        }
Example #5
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();
        }
Example #6
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (designMode)
            {
                e.Graphics.Clear(BackColor);
                return;
            }

            base.OnPaint(e);

            // create the contexts if not done already
            if (grContext == null)
            {
                var glInterface = GRGlInterface.CreateNativeGlInterface();
                grContext = GRContext.Create(GRBackend.OpenGL, glInterface);

                // get initial details
                renderTarget = SKGLDrawable.CreateRenderTarget();
            }

            // update to the latest dimensions
            renderTarget.Width  = Width;
            renderTarget.Height = Height;

            // create the surface
            using (var surface = SKSurface.Create(grContext, renderTarget))
            {
                // start drawing
                OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));

                surface.Canvas.Flush();
            }

            // update the control
            SwapBuffers();
        }