/* void Win_DidChangeScreen(object sender, EventArgs e) * { * } * * * void Win_DidMiniaturize(object sender, EventArgs e) * { * } * * * void Win_DidExpose(object sender, EventArgs e) * { * } * * * void Win_DidChangeScreenProfile(object sender, EventArgs e) * { * } * * * void Win_DidChangeBackingProperties(object sender, EventArgs e) * { * } * * * void Win_DidChangeValue(string obj) * { * } * public override void ViewDidHide() * { * base.ViewDidHide(); * } * public override void ViewDidUnhide() * { * base.ViewDidUnhide(); * }*/ internal void EndRender() { /* if (object.ReferenceEquals(Thread.CurrentThread, this.mainthread)) * {*/ Debug.Assert(FrameFactory.getcurrentfunc().Handle == this.openglctx.CGLContext.Handle); NSOpenGLContext.ClearCurrentContext(); if (Thread.CurrentThread == typeof(Application).GetProperty("UIThread", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, new object[0]) as Thread) { this.openglctx.CGLContext.Unlock(); } /* } * else * { * layer.CGLSetCurrentContext(IntPtr.Zero); * }*/ }
public viewwindow(IRenderer render, IRenderOwner renderer, Widget widget, CGRect frame, NSOpenGLContext ctx) : base(frame) { this.mainthread = Thread.CurrentThread; this.render = render; this.renderer = renderer; this.window = widget; base.WantsBestResolutionOpenGLSurface = true; this.WantsLayer = true; this.openglctx = ctx; Trace.Assert(this.openglctx != null, "no NSOpenGLContext context"); // this.openglctx.CGLContext.Handle this.openglctx.CGLContext.Lock(); try { this.openglctx.MakeCurrentContext(); this._ctx = new _GraphicsContext(); // created from active content } catch { throw; } finally { NSOpenGLContext.ClearCurrentContext(); this.openglctx.CGLContext.Unlock(); } /* var wBackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget.ParentWindow) as Xwt.Backends.IWindowFrameBackend; * var win = wBackend.Window as NSWindow; * * while (win.ParentWindow != null) * { * win = win.ParentWindow; * } * // win.DidChangeValue+= Win_DidChangeValue; * win.DidChangeBackingProperties+= Win_DidChangeBackingProperties; * win.DidChangeScreenProfile+= Win_DidChangeScreenProfile; * win.DidExpose+= Win_DidExpose; * win.DidMiniaturize+= Win_DidMiniaturize; * win.DidChangeScreen+= Win_DidChangeScreen;*/ }
public override NSOpenGLContext GetOpenGLContext(NSOpenGLPixelFormat pixelFormat) { this._ctx2?.Dispose(); this._ctx2 = null; var r = new NSOpenGLContext(pixelFormat /*GetOpenGLPixelFormat(0)*/, this.owner.openglctx); if (r != null) { var error = CGLEnable(r.CGLContext.Handle, 313); // Trace.Assert(r.CGLContext.Handle != this.owner.openglctx.CGLContext.Handle); { r.CGLContext.Lock(); r.MakeCurrentContext(); this._ctx2 = new _GraphicsContext(); // register active context handle NSOpenGLContext.ClearCurrentContext(); r.CGLContext.Unlock(); } return(r); } return(null); }
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) { } }