/// <inheritdoc /> public nint GetProcAddress(string proc, int?slot = default) { var ret = _glfw.GetProcAddress(proc); Glfw.ThrowExceptions(); if (ret == 0) { Throw(proc); } return(ret);
/// <summary> /// Creates a new instance of the GlfwProvider class. /// </summary> static GlfwProvider() { GLFW = new Lazy <Glfw> ( () => { var glfw = Glfw.GetApi(); glfw.Init(); glfw.SetErrorCallback(Glfw.ErrorCallback); return(glfw); } ); }
/// <summary> /// Unloads the loaded <see cref="GLFW" /> interface implementation. /// </summary> public static void Unload() { GLFW.Value.Terminate(); GLFW = new Lazy <Glfw> ( () => { var glfw = Glfw.GetApi(); glfw.Init(); glfw.SetErrorCallback(Glfw.ErrorCallback); return(glfw); } ); }
public unsafe GlfwNativeWindow(Glfw api, WindowHandle *window) : this() { Kind |= NativeWindowFlags.Glfw; Glfw = (nint)window; var getHwnd = api.Context.GetProcAddress("glfwGetWin32Window"); if (getHwnd != default) { var hwnd = ((delegate * unmanaged[Cdecl] < WindowHandle *, nint >)getHwnd)(window); Kind |= NativeWindowFlags.Win32; Win32 = (hwnd, Win32GetDC(hwnd), Win32GetWindowLongPtr(hwnd, GwlpHInstance)); return; } var getCocoaId = api.Context.GetProcAddress("glfwGetCocoaWindow"); if (getCocoaId != default) { Kind |= NativeWindowFlags.Cocoa; Cocoa = (nint)((delegate * unmanaged[Cdecl] < WindowHandle *, void * >)getCocoaId)(window); return; } var getX11Display = api.Context.GetProcAddress("glfwGetX11Display"); var getX11Window = api.Context.GetProcAddress("glfwGetX11Window"); if (getX11Display != default && getX11Window != default) { Kind |= NativeWindowFlags.X11; X11 = ((nint)((delegate * unmanaged[Cdecl] < void * >)getX11Display)(), ((delegate * unmanaged[Cdecl] < WindowHandle *, nuint >)getX11Window)(window)); return; } var getWaylandDisplay = api.Context.GetProcAddress("glfwGetWaylandDisplay"); var getWaylandWindow = api.Context.GetProcAddress("glfwGetWaylandWindow"); if (getWaylandDisplay != default && getWaylandWindow != default) { Kind |= NativeWindowFlags.Wayland; Wayland = ((nint)((delegate * unmanaged[Cdecl] < void * >)getWaylandDisplay)(), (nint)((delegate * unmanaged[Cdecl] < WindowHandle *, void * >)getWaylandWindow)(window)); } }
/// <summary> /// Creates a new instance of the GlfwProvider class. /// </summary> static GlfwProvider() { ThreadDispatcher = new Dispatcher(); GLFW = new Lazy <Glfw>(() => { if (ThreadDispatcher == null) { ThreadDispatcher = new Dispatcher(); } var glfw = Glfw.GetApi(); ThreadDispatcher.Invoke(() => { glfw.Init(); glfw.SetErrorCallback(Glfw.ErrorCallback); }); return(glfw); }); }
/// <summary> /// Creates a new instance of the GlfwProvider class. /// </summary> static unsafe GlfwProvider() { GLFW = new Lazy <Glfw> ( () => { var glfw = Glfw.GetApi(); if (!glfw.Init()) { var code = glfw.GetError(out byte *pDesc); var len = new ReadOnlySpan <byte>(pDesc, int.MaxValue).IndexOf((byte)'\0'); var desc = len <= 0 ? "Unknown" : System.Text.Encoding.UTF8.GetString(pDesc, len); throw new GlfwException($"GLFW Init failed, {code}: {desc}"); } glfw.SetErrorCallback(Glfw.ErrorCallback); return(glfw); } ); }
/// <summary> /// Creates a GlfwContext using the given API instance and window handle. /// </summary> /// <param name="glfw">The GLFW API instance to use.</param> /// <param name="window">The window handle to source context info from.</param> public unsafe GlfwContext(Glfw glfw, WindowHandle *window) { _window = window; _glfw = glfw; }
/// <summary> /// Creates a GlfwContext using the given API instance and window handle. /// </summary> /// <param name="glfw">The GLFW API instance to use.</param> /// <param name="window">The window handle to source context info from.</param> /// <param name="source">A <see cref="IGLContextSource"/> to associate this context to, if any.</param> public unsafe GlfwContext(Glfw glfw, WindowHandle *window, IGLContextSource?source = null) { _window = window; _glfw = glfw; Source = source; }