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); }
public override bool CanDrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, CVTimeStamp timeStamp) { if (!animate) { previousTime = 0.0; } return(animate); }
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); }
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); }
internal static extern Error SetSurface(CGLContext context, int conId, int winId, int surfId);
internal static extern CGLPixelFormat GetPixelFormat(CGLContext context);
internal static Error SetSurface(CGLContext context, int conId, int winId, int surfId) => cglSetSurface(context, conId, winId, surfId);
internal static Error SetParameter(CGLContext context, int parameter, ref int value) => cglSetParameter(context, parameter, ref value);
internal static Error SetCurrentContext(CGLContext context) => cglSetCurrentContext(context);
internal static CGLPixelFormat GetPixelFormat(CGLContext context) => cglGetPixelFormat(context);
/* 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); }
internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
internal static extern Error FlushDrawable(CGLContext context);
internal static extern Error SetParameter(CGLContext context, int parameter, ref int value);
internal static extern Error DestroyContext(CGLContext context);
internal static extern Error SetCurrentContext(CGLContext context);
public override bool CanDrawInCGLContext (CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp) { if (!animate) previousTime = 0.0; return animate; }
internal static extern Error UpdateContext(CGLContext context);
public override void Release(CGLContext glContext) { this._ctx2?.Dispose(); this._ctx2 = null; base.Release(glContext); }
internal static extern CGLPixelFormat GetPixelFormat(CGLContext context);
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) { } }
internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
internal static Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context) => cglCreateContext(format, share, ref context);
internal static extern Error SetCurrentContext(CGLContext context);
internal static Error DestroyContext(CGLContext context) => cglDestroyContext(context);
internal static extern Error DestroyContext(CGLContext context);
internal static Error FlushDrawable(CGLContext context) => cglFlushDrawable(context);
internal static extern Error SetParameter(CGLContext context, int parameter, ref int value);
internal static Error UpdateContext(CGLContext context) => cglUpdateContext(context);
internal static extern Error FlushDrawable(CGLContext context);
public CVReturn SetCurrentDisplay(CGLContext cglContext, CGLPixelFormat cglPixelFormat) { return(CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(this.handle, cglContext.Handle, cglPixelFormat.Handle)); }
internal static extern Error SetSurface(CGLContext context, int conId, int winId, int surfId);
public override void Release(CGLContext glContext) { context.Dispose(); base.Release(glContext); }
internal static extern Error UpdateContext(CGLContext context);