private CVReturn HandleDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { try { if (_paused) { return(CVReturn.Success); } if (GraphicsDevice != null) { if (_resized) { _resized = false; MainSwapchain.Resize(_width, _height); Resized?.Invoke(); } Rendering?.Invoke(); } } catch (Exception e) { Debug.WriteLine("Encountered an error while rendering: " + e); throw; } return(CVReturn.Success); }
public override bool CanDrawInCGLContext( OpenGL.CGLContext glContext, OpenGL.CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp) { return(_version != _dirtyVersion); }
private CVReturn HandleDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { if (_newRenderSize != null) { Callback.OnResize(Widget, new ResizeEventArgs(_newRenderSize.Value)); _newRenderSize = null; } Callback.OnDraw(Widget, EventArgs.Empty); return(CVReturn.Success); }
private CVReturn GetFrameForTime(CVTimeStamp outputTime) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool()) { // Update the animation BeginInvokeOnMainThread(DrawView); } return(CVReturn.Success); }
public CVReturn DisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects // ReSharper disable once UnusedVariable using (var pool = new NSAutoreleasePool()) { Device.BeginInvokeOnMainThread(() => SendSignals()); } return(CVReturn.Success); }
// Private Callback function for CVDisplayLink private CVReturn MyDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { //CVReturn result = GetFrameForTime (inOutputTime); CVReturn result = CVReturn.Error; // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool()) { // Update the animation RenderScene(); result = CVReturn.Success; } return(result); }
private CVReturn GetFrameForTime(CVTimeStamp outputTime) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool()) { // Update the animation double current = DateTime.Now.TimeOfDay.TotalMilliseconds; controller.Scene.advanceTimeBy((float)(current - controller.RenderTime)); controller.RenderTime = (float)current; BeginInvokeOnMainThread(DrawView); } return(CVReturn.Success); }
public void TryTranslateTimeValidTest() { TestRuntime.AssertNotVSTS(); TestRuntime.AssertSystemVersion(ApplePlatform.MacOSX, 12, 0); var outTime = new CVTimeStamp { Version = 0, Flags = (1L << 0) | (1L << 1), // kCVTimeStampVideoTimeValid | kCVTimeStampHostTimeValid }; using var displayLink = new CVDisplayLink(); // it has to be running else you will get a crash if (displayLink.Start() == 0) { displayLink.GetCurrentTime(out var timeStamp); Assert.True(displayLink.TryTranslateTime(timeStamp, ref outTime)); displayLink.Stop(); } }
// Private Callback function for CVDisplayLink static CVReturn DisplayLinkOutputCallback(IntPtr displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut, IntPtr displayLinkContext) { //CVReturn result = GetFrameForTime (inOutputTime); CVReturn result = CVReturn.Success; using (new NSAutoreleasePool()) { try { foreach (var view in _views) { view.Value.Draw(); } } catch (Exception e) { Console.Error.WriteLine(e); result = CVReturn.Error; } } return(result); }
private CVReturn GetFrameForTime (CVTimeStamp outputTime) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { // Update the animation BeginInvokeOnMainThread (DrawView); } return CVReturn.Success; }
public CVReturn MyDisplayLinkOutputCallback (CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { CVReturn result = GetFrameForTime (inOutputTime); return result; }
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) { } }
/* 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); }
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); }
public CVReturn DisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { Fire?.Invoke(); return(CVReturn.Success); }
public CVReturn MyDisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { CVReturn result = GetFrameForTime(inOutputTime); return(result); }
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 static CVReturn RequestDraw(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { NSApplication.SharedApplication.BeginInvokeOnMainThread(() => RequestDraw()); return(CVReturn.Success); }
CVReturn DisplayLinkOutputCallback(CVDisplayLink displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut) { Game.Instance.BeginInvokeOnMainThread(() => Game.Instance.EmitTick()); return(CVReturn.Success); }
public override bool CanDrawInCGLContext(CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, CVTimeStamp timeStamp) { if (!animate) { previousTime = 0.0; } return(animate); }
public override bool CanDrawInCGLContext (CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp) { if (!animate) previousTime = 0.0; return animate; }
public override void DrawInCGLContext(MonoMac.OpenGL.CGLContext glContext, CGLPixelFormat pixelFormat, double timeInterval, 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); }
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); }
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); }
public override void DrawInCGLContext(OpenGL.CGLContext glContext, OpenGL.CGLPixelFormat pixelFormat, double timeInterval, ref CVTimeStamp timeStamp) { _version = _dirtyVersion; _draw(); base.DrawInCGLContext(glContext, pixelFormat, timeInterval, ref timeStamp); }
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); }
private CVReturn GetFrameForTime (CVTimeStamp outputTime) { // There is no autorelease pool when this method is called because it will be called from a background thread // It's important to create one or you will leak objects using (NSAutoreleasePool pool = new NSAutoreleasePool ()) { // Update the animation double current = DateTime.Now.TimeOfDay.TotalMilliseconds; controller.Scene.advanceTimeBy ((float)(current - controller.RenderTime)); controller.RenderTime = (float)current; BeginInvokeOnMainThread (DrawView); } return CVReturn.Success; }