void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget) { Xwt.Canvas view = null; IntPtr hwnd; EventHandler sizefunc = null; if (Xwt.Toolkit.CurrentEngine.Type == ToolkitType.Wpf) { hwnd = GetHwnd(widget.ParentWindow); } else { hwnd = GetHwndFromGtk(Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget)); if (hwnd == GetHwndFromGtk(widget.ParentWindow)) { view = new global::Xwt.Canvas() { ExpandHorizontal = true, ExpandVertical = true, HorizontalPlacement = WidgetPlacement.Fill, VerticalPlacement = WidgetPlacement.Fill, MinWidth = 1, MinHeight = 1, BackgroundColor = Xwt.Drawing.Colors.Black }; (widget as global::Xwt.Canvas).AddChild(view); var viewbackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(view) as Xwt.Backends.ICanvasBackend; var gtkview = viewbackend.GetType().GetPropertyValue(viewbackend, "Widget"); gtkview.GetType().SetPropertyValue(gtkview, "DoubleBuffered", false); hwnd = GetHwndFromGtk(viewbackend); Debug.Assert(hwnd != GetHwndFromGtk(widget.ParentWindow)); sizefunc = new EventHandler((s, a) => (widget as global::Xwt.Canvas).SetChildBounds(view, new Rectangle(Point.Zero, widget.Size))); (widget as global::Xwt.Canvas).BoundsChanged += sizefunc; sizefunc(null, EventArgs.Empty); } } IWindowInfo WindowInfo = null; IGraphicsContext gfxcontext = null; WindowInfo = Utilities.CreateWindowsWindowInfo(hwnd); gfxcontext = new global::OpenTK.Graphics.GraphicsContext(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8), WindowInfo, null, 3, 2, GraphicsContextFlags.Default); views[widget] = new viewinfo(WindowInfo, gfxcontext) { viewcanvas = view, sizefunc = sizefunc }; gfxcontext.MakeCurrent(WindowInfo); gfxcontext.LoadAll(); int major, minor; GL.GetInteger(GetPName.MajorVersion, out major); GL.GetInteger(GetPName.MinorVersion, out minor); Console.WriteLine($"OpenGL {major}.{minor}"); gfxcontext.MakeCurrent(null); }
void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget) { var o = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget); var wBackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget) as Xwt.Backends.IWidgetBackend; // var nsWindow = wBackend.NativeHandle;l; var nsView = (wBackend.NativeWidget as NSView); var ctx = new NSOpenGLContext(GetOpenGLPixelFormat(0), null); var error = viewwindow.layer.CGLEnable(ctx.CGLContext.Handle, 313); // enable multithread viewwindow view = null; // ctx.CGLContext.Lock(); // ctx.MakeCurrentContext(); Application.InvokeAsync(() => { view = new viewwindow(renderer, rendererimpl, widget, ViewPostion(widget, wBackend), ctx); nsView.AddSubview(view); Debug.Assert(!views.ContainsKey(widget)); views[widget] = new viewinfo() { orgview = nsView, /* backend = wBackend,*/ myview = view, widget = widget }; widget.BoundsChanged += sizechanged; }).Wait(); /* (this as IXwtRender).StartRender(renderer, widget); * view._ctx = new _GraphicsContext(); * (this as IXwtRender).EndRender(renderer, widget);*/ this.QueueOnUI(() => view.initdone.Set()); }
void IXwtRender.CreateForWidgetContext(IRenderer renderer, IRenderOwner rendererimpl, Canvas widget) { var wBackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget) as Xwt.Backends.ICanvasBackend; var gtkwidget = wBackend.GetType().GetPropertyValue(wBackend, "Widget"); gtkwidget.GetType().SetPropertyValue(gtkwidget, "DoubleBuffered", false); // var widget = wBackend.GetType().GetPropertyValue(wBackend, "Widget"); // widget.GetType().SetPropertyValue(widget, "DoubleBuffered", false); // var gdkwin = widget.GetType().GetPropertyValue(widget, "GdkWindow"); var h = GetHandle(wBackend); // (IntPtr)gdkwin.GetType().GetPropertyValue(gdkwin, "Handle"); IntPtr windowHandle = gdk_x11_drawable_get_xid(h); // wBackend.Widget.Handle IntPtr display2 = gdk_drawable_get_display(h); IntPtr display = gdk_x11_drawable_get_xdisplay(h); IntPtr screen = gdk_display_get_default_screen(display2); int screenn = gdk_screen_get_number(screen); IntPtr rootWindow = gdk_screen_get_root_window(screen); IntPtr visualInfo = IntPtr.Zero; XVisualInfo info = new XVisualInfo(); info.VisualID = IntPtr.Zero; int dummy; visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); // } /* else * { * visualInfo = GetVisualInfo(display); * }*/ var wBackendMain = Xwt.Toolkit.CurrentEngine.GetSafeBackend(widget.ParentWindow) as Xwt.Backends.IWindowFrameBackend; var winmain = wBackendMain.GetType().GetPropertyValue(wBackendMain, "Window"); var gdkwinmain = winmain.GetType().GetPropertyValue(winmain, "GdkWindow"); var hmain = (IntPtr)gdkwinmain.GetType().GetPropertyValue(gdkwinmain, "Handle"); Canvas view = null; EventHandler sizefunc = null; if (h == hmain) { view = new global::Xwt.Canvas() { ExpandHorizontal = true, ExpandVertical = true, HorizontalPlacement = WidgetPlacement.Fill, VerticalPlacement = WidgetPlacement.Fill, MinWidth = 1, MinHeight = 1, BackgroundColor = Xwt.Drawing.Colors.Black }; widget.AddChild(view); var viewbackend = Xwt.Toolkit.CurrentEngine.GetSafeBackend(view) as Xwt.Backends.ICanvasBackend; var gtkview = viewbackend.GetType().GetPropertyValue(viewbackend, "Widget"); gtkview.GetType().SetPropertyValue(gtkview, "DoubleBuffered", false); var hwnd = GetHandle(viewbackend); Debug.Assert(hwnd != hmain); sizefunc = new EventHandler((s, a) => widget.SetChildBounds(view, new Rectangle(Point.Zero, widget.Size))); widget.BoundsChanged += sizefunc; sizefunc(null, EventArgs.Empty); windowHandle = gdk_x11_drawable_get_xid(hwnd); } var WindowInfo = Utilities.CreateX11WindowInfo(display, screenn, windowHandle, rootWindow, visualInfo); XFree(visualInfo); var gfxcontext = new OpenTK.Graphics.GraphicsContext(new GraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 8), WindowInfo, 3, 3, GraphicsContextFlags.Default); views[widget] = new viewinfo(WindowInfo, gfxcontext, (gfxcontext as IGraphicsContextInternal).Context) { view = view, sizefunc = sizefunc }; gfxcontext.MakeCurrent(WindowInfo); gfxcontext.LoadAll(); int major, minor; GL.GetInteger(GetPName.MajorVersion, out major); GL.GetInteger(GetPName.MinorVersion, out minor); Console.WriteLine("OpenGL {0}.{1}", major, minor); gfxcontext.MakeCurrent(null); }