Esempio n. 1
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);
        }
Esempio n. 2
0
 public override bool CanDrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, CVTimeStamp timeStamp)
 {
     if (!animate)
     {
         previousTime = 0.0;
     }
     return(animate);
 }
Esempio n. 3
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);
            }

            // manage the drawing surface
            var surfaceWidth  = (int)(Bounds.Width * ContentsScale);
            var surfaceHeight = (int)(Bounds.Height * ContentsScale);

            if (renderTarget == null || surface == null || renderTarget.Width != surfaceWidth || renderTarget.Height != surfaceHeight)
            {
                // create or update the dimensions
                renderTarget?.Dispose();
                Gles.glGetIntegerv(Gles.GL_FRAMEBUFFER_BINDING, out var framebuffer);
                Gles.glGetIntegerv(Gles.GL_STENCIL_BITS, out var stencil);
                Gles.glGetIntegerv(Gles.GL_SAMPLES, out var samples);
                var maxSamples = context.GetMaxSurfaceSampleCount(colorType);
                if (samples > maxSamples)
                {
                    samples = maxSamples;
                }
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget(surfaceWidth, surfaceHeight, samples, stencil, glInfo);

                // create the surface
                surface?.Dispose();
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
            }

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

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

            base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp);
        }
        private void SetupDisplayLink()
        {
            // Create a display link capable of being used with all active displays
            displayLink = new CVDisplayLink();

            // Set the renderer output callback function
            displayLink.SetOutputCallback(MyDisplayLinkOutputCallback);

            // Set the display link for the current renderer
            CGLContext     cglContext     = openGLContext.CGLContext;
            CGLPixelFormat cglPixelFormat = PixelFormat.CGLPixelFormat;

            displayLink.SetCurrentDisplay(cglContext, cglPixelFormat);
        }
Esempio n. 5
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);
            }

            // manage the drawing surface
            var surfaceWidth  = (int)(Bounds.Width * ContentsScale);
            var surfaceHeight = (int)(Bounds.Height * ContentsScale);

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

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

            using (new SKAutoCanvasRestore(surface.Canvas, true))
            {
                // start drawing
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, GRSurfaceOrigin.BottomLeft, SKColorType.Rgba8888);
                OnPaintSurface(e);
#pragma warning disable CS0618 // Type or member is obsolete
                DrawInSurface(e.Surface, e.RenderTarget);
                SKDelegate?.DrawInSurface(e.Surface, e.RenderTarget);
#pragma warning restore CS0618 // Type or member is obsolete
            }

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

            base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp);
        }
Esempio n. 6
0
 internal static extern Error SetSurface(CGLContext context, int conId, int winId, int surfId);
Esempio n. 7
0
 internal static extern CGLPixelFormat GetPixelFormat(CGLContext context);
Esempio n. 8
0
 internal static Error SetSurface(CGLContext context, int conId, int winId, int surfId) => cglSetSurface(context, conId, winId, surfId);
Esempio n. 9
0
 internal static Error SetParameter(CGLContext context, int parameter, ref int value) => cglSetParameter(context, parameter, ref value);
Esempio n. 10
0
 internal static Error SetCurrentContext(CGLContext context) => cglSetCurrentContext(context);
Esempio n. 11
0
 internal static CGLPixelFormat GetPixelFormat(CGLContext context) => cglGetPixelFormat(context);
Esempio n. 12
0
 /*  class openglonscreen : NSOpenGLContext
  * {
  *    public openglonscreen(NSOpenGLPixelFormat format, NSOpenGLContext shareContext)
  *        : base(format,shareContext)
  *    {
  *
  *    }
  *    protected override void Dispose(bool disposing)
  *    {
  *        base.Dispose(disposing);
  *    }
  * }*/
 public override bool CanDrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
 {
     //   lastupdate = DateTime.Now.Ticks;
     return((this.View as viewwindow).initdone.WaitOne(0, false));//.CanDrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp);
 }
Esempio n. 13
0
 internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
Esempio n. 14
0
 internal static extern Error FlushDrawable(CGLContext context);
Esempio n. 15
0
 internal static extern Error SetParameter(CGLContext context, int parameter, ref int value);
Esempio n. 16
0
 internal static extern Error DestroyContext(CGLContext context);
Esempio n. 17
0
 internal static extern Error SetCurrentContext(CGLContext context);
Esempio n. 18
0
 public override bool CanDrawInCGLContext (CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
 {
         if (!animate)
                 previousTime = 0.0;
         return animate;
 }
Esempio n. 19
0
 internal static extern Error UpdateContext(CGLContext context);
Esempio n. 20
0
 public override void Release(CGLContext glContext)
 {
     this._ctx2?.Dispose();
     this._ctx2 = null;
     base.Release(glContext);
 }
Esempio n. 21
0
 internal static extern CGLPixelFormat GetPixelFormat(CGLContext context);
Esempio n. 22
0
                public override void DrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
                {
                    try
                    {
                        long now = DateTime.Now.Ticks;

                        /*     if (lastupdate != -1 && lastupdate - now > 1000000)
                         *   {
                         *       // this.owner.renderer.SkipRender(lastupdate - now-400000);
                         *   }
                         *
                         *   Interlocked.Exchange(ref lastupdate, DateTime.Now.Ticks);
                         *   var now = DateTime.Now.Ticks;*/

                        long time;

                        if (lastupdate == -1)
                        {
                            time          = lastupdate = this.timebase;
                            this.timebase = now - this.timebase;
                            //      Log.Verbose($"viewtime={0} first");
                        }
                        else
                        {
                            time = now - this.timebase;

                            if ((time - lastupdate) > 25000000)
                            {
                                this.timebase = now - lastupdate;
                                time          = lastupdate;
                                Log.Verbose($"viewtime={time} reset");
                            }
                        }
                        //       Log.Verbose($"viewtime={time}");

                        lastupdate = time;
                        if (this.owner.renderer.preparerender(null, time, false))
                        {
                            //  lock (this.owner)
                            {
                                using (this.owner.render.GetDrawLock(true))
                                {
                                    this.OpenGLContext.CGLContext.Lock();
                                    this.OpenGLContext.MakeCurrentContext();

                                    try
                                    {
                                        var r = new rectangle(0, 0, Convert.ToInt32(this.owner.Bounds.Width), Convert.ToInt32(this.owner.Bounds.Height));

                                        GL.Viewport(r.x, r.y, r.width, r.height);

                                        this.owner.renderer.render(null, time, r);
                                    }
                                    catch (Exception e)
                                    {
                                        //    Log.LogException(e);
                                    }

                                    this.OpenGLContext.FlushBuffer();
                                    NSOpenGLContext.ClearCurrentContext();
                                    this.OpenGLContext.CGLContext.Unlock();
                                }
                            }
                        }
                        //         Log.Verbose($"viewtime-done={time}");
                    }
                    catch (Exception e)
                    {
                    }
                }
Esempio n. 23
0
 internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
Esempio n. 24
0
 internal static Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context) => cglCreateContext(format, share, ref context);
Esempio n. 25
0
 internal static extern Error SetCurrentContext(CGLContext context);
Esempio n. 26
0
 internal static Error DestroyContext(CGLContext context) => cglDestroyContext(context);
Esempio n. 27
0
 internal static extern Error DestroyContext(CGLContext context);
Esempio n. 28
0
 internal static Error FlushDrawable(CGLContext context) => cglFlushDrawable(context);
Esempio n. 29
0
 internal static extern Error SetParameter(CGLContext context, int parameter, ref int value);
Esempio n. 30
0
 internal static Error UpdateContext(CGLContext context) => cglUpdateContext(context);
Esempio n. 31
0
 internal static extern Error FlushDrawable(CGLContext context);
Esempio n. 32
0
 public CVReturn SetCurrentDisplay(CGLContext cglContext, CGLPixelFormat cglPixelFormat)
 {
     return(CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(this.handle, cglContext.Handle, cglPixelFormat.Handle));
 }
Esempio n. 33
0
 internal static extern Error SetSurface(CGLContext context, int conId, int winId, int surfId);
Esempio n. 34
0
        public override void Release(CGLContext glContext)
        {
            context.Dispose();

            base.Release(glContext);
        }
Esempio n. 35
0
 internal static extern Error UpdateContext(CGLContext context);