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);
        }
示例#2
0
        public override CGLPixelFormat CopyCGLPixelFormatForDisplayMask(uint mask)
        {
            // make sure to add a null value
            var attribs = new object [] {
                CGLPixelFormatAttribute.Accelerated,
                CGLPixelFormatAttribute.DoubleBuffer,
                CGLPixelFormatAttribute.ColorSize, 24,
                CGLPixelFormatAttribute.DepthSize, 16
            };

            CGLPixelFormat pixelFormat = new CGLPixelFormat(attribs);

            return(pixelFormat);
        }
示例#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);
                var glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());
                renderTarget = new GRBackendRenderTarget(surfaceWidth, surfaceHeight, context.GetMaxSurfaceSampleCount(colorType), 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);
        }
示例#4
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);
        }
示例#5
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);
 }
示例#6
0
 public override bool CanDrawInCGLContext (CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
 {
         if (!animate)
                 previousTime = 0.0;
         return animate;
 }
示例#7
0
 public override void DrawInCGLContext (OpenGL.CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp)
 {
         GL.ClearColor (NSColor.Clear.UsingColorSpace (NSColorSpace.CalibratedRGB));
         GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
         GL.Enable (EnableCap.DepthTest);
         GL.Hint (HintTarget.LineSmoothHint, HintMode.Nicest);
         GL.Hint (HintTarget.PolygonSmoothHint, HintMode.Nicest);
         if (previousTime == 0)
                 previousTime = timeInterval;
         rotation += 15.0 * (timeInterval - previousTime);
         GL.LoadIdentity ();
         double comp = 1 / Math.Sqrt (3.0);
         GL.Rotate (rotation, comp, comp, comp);
         
         drawCube ();
         
         GL.Flush ();
         previousTime = timeInterval;
         GL.Disable (EnableCap.DepthTest);
         GL.Hint (HintTarget.LineSmoothHint, HintMode.DontCare);
         GL.Hint (HintTarget.PolygonSmoothHint, HintMode.DontCare);
         
         
 }
示例#8
0
 internal static Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context) => cglCreateContext(format, share, ref context);
示例#9
0
 internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatBool attrib, out bool value);
示例#10
0
文件: Cgl.cs 项目: zanzo420/opentk
 internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
示例#11
0
 internal static Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatInt attrib, out int value) => cglDescribePixelFormatInt(pix, pix_num, attrib, out value);
示例#12
0
文件: Cgl.cs 项目: zanzo420/opentk
 internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatInt attrib, out int value);
示例#13
0
文件: Cgl.cs 项目: zanzo420/opentk
 internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatBool attrib, out bool value);
示例#14
0
文件: Cgl.cs 项目: zanzo420/opentk
 internal static extern Error ChoosePixelFormat(int [] attribs, ref CGLPixelFormat format, ref int numPixelFormats);
示例#15
0
 internal static extern Error DestroyPixelFormat(CGLPixelFormat format);
示例#16
0
 internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
示例#17
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)
                    {
                    }
                }
示例#18
0
文件: Cgl.cs 项目: zanzo420/opentk
 internal static extern Error DestroyPixelFormat(CGLPixelFormat format);
示例#19
0
 internal static Error ChoosePixelFormat(int[] attribs, ref CGLPixelFormat format, ref int numPixelFormats) => cglChoosePixelFormat(attribs, ref format, ref numPixelFormats);
示例#20
0
 public CVReturn SetCurrentDisplay(CGLContext cglContext, CGLPixelFormat cglPixelFormat)
 {
     return(CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(this.handle, cglContext.Handle, cglPixelFormat.Handle));
 }
示例#21
0
 internal static Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatBool attrib, out bool value) => cglDescribePixelFormatBool(pix, pix_num, attrib, out value);
示例#22
0
 internal static extern Error ChoosePixelFormat(int []attribs, ref CGLPixelFormat format, ref int numPixelFormats);
示例#23
0
 internal static Error DestroyPixelFormat(CGLPixelFormat format) => cglDestroyPixelFormat(format);
示例#24
0
 internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatInt attrib, out int value);
示例#25
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.Create();
                context = GRContext.CreateGl(glInterface);
            }

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

            if (renderTarget == null || lastSize != newSize || !renderTarget.IsValid)
            {
                // create or update the dimensions
                lastSize = newSize;

                // read the info from the buffer
                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;
                }
                glInfo = new GRGlFramebufferInfo((uint)framebuffer, colorType.ToGlSizedFormat());

                // destroy the old surface
                surface?.Dispose();
                surface = null;
                canvas  = null;

                // re-create the render target
                renderTarget?.Dispose();
                renderTarget = new GRBackendRenderTarget(newSize.Width, newSize.Height, samples, stencil, glInfo);
            }

            // create the surface
            if (surface == null)
            {
                surface = SKSurface.Create(context, renderTarget, surfaceOrigin, colorType);
                canvas  = surface.Canvas;
            }

            using (new SKAutoCanvasRestore(canvas, true))
            {
                // start drawing
#pragma warning disable CS0618 // Type or member is obsolete
                var e = new SKPaintGLSurfaceEventArgs(surface, renderTarget, surfaceOrigin, colorType, glInfo);
                OnPaintSurface(e);
                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
            canvas.Flush();
            context.Flush();

            base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp);
        }
示例#26
0
                public override CGLPixelFormat CopyCGLPixelFormatForDisplayMask (uint mask)
                {
                        // make sure to add a null value
                        var attribs = new object [] { 
							CGLPixelFormatAttribute.Accelerated, 
							CGLPixelFormatAttribute.DoubleBuffer, 
							CGLPixelFormatAttribute.ColorSize, 24, 
							CGLPixelFormatAttribute.DepthSize, 16 };
                        
                        CGLPixelFormat pixelFormat = new CGLPixelFormat (attribs);
                        return pixelFormat;
                }