private void InitializeGraphicsBackend() { switch (Backend) { case GraphicsBackend.Metal: GraphicsDevice = GraphicsDevice.CreateMetal(GraphicsDeviceOptions); break; case GraphicsBackend.Vulkan: GraphicsDevice = GraphicsDevice.CreateVulkan(GraphicsDeviceOptions); break; case GraphicsBackend.Direct3D11: GraphicsDevice = GraphicsDevice.CreateD3D11(GraphicsDeviceOptions); break; case GraphicsBackend.OpenGL: Handler.UpdateWindowInfo(OpenTKGraphicsMode); var glInfo = new OpenGLPlatformInfo( VeldridGL.GetGLContextHandle(), VeldridGL.GetProcAddress, (c) => OpenTKGraphicsContext.MakeCurrent(Handler.WindowInfo), VeldridGL.GetCurrentContext, VeldridGL.ClearCurrentContext, VeldridGL.DeleteContext, VeldridGL.SwapBuffers, VeldridGL.SetVSync, VeldridGL.SetSwapchainFramebuffer, Handler.ResizeSwapchain); GraphicsDevice = GraphicsDevice.CreateOpenGL( GraphicsDeviceOptions, glInfo, (uint)RenderWidth, (uint)RenderHeight); break; default: string message; if (!Enum.IsDefined(typeof(GraphicsBackend), Backend)) { message = "Unrecognized backend!"; } else { message = "Specified backend not supported on this platform!"; } throw new ArgumentException(message); } Swapchain = Handler.CreateSwapchain(); OnVeldridInitialized(EventArgs.Empty); }
protected virtual void OnWindowInfoUpdated(EventArgs e) { if (Backend != GraphicsBackend.OpenGL) { return; } if (OpenTKGraphicsContext == null) { OpenTKGraphicsContext = new GraphicsContext( OpenTKGraphicsMode, Handler.WindowInfo, 3, 3, GraphicsContextFlags.ForwardCompatible); } else { OpenTKGraphicsContext.Update(Handler.WindowInfo); } OpenTKGraphicsContext.MakeCurrent(Handler.WindowInfo); }