opentk / GLWpfControl

A fast native control for OpenTK 4.x + 3.x on WPF.
MIT License
194 stars 48 forks source link

More graceful way to see if OpenGL is supported or not #112

Open MikaelStalvik opened 1 year ago

MikaelStalvik commented 1 year ago

When trying to initialize the GLWpfControl on a device (VirtualBox for example) which does not support OpenGL, a hard exception is thrown: "OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: WGL: The driver does not appear to support OpenGL"

Stack trace OpenTK.Windowing.GraphicsLibraryFramework.GLFWException: WGL: The driver does not appear to support OpenGL at OpenTK.Windowing.Desktop.GLFWProvider.<>c.<.cctor>b__10_0(ErrorCode errorCode, String description) at OpenTK.Windowing.GraphicsLibraryFramework.GLFWNative.glfwCreateWindow(Int32 width, Int32 height, Byte* title, Monitor* monitor, Window* share) at OpenTK.Windowing.GraphicsLibraryFramework.GLFW.CreateWindow(Int32 width, Int32 height, String title, Monitor* monitor, Window* share) at OpenTK.Windowing.Desktop.NativeWindow..ctor(NativeWindowSettings settings) at OpenTK.Wpf.DxGlContext.GetOrCreateSharedOpenGLContext(GLWpfControlSettings settings) at OpenTK.Wpf.DxGlContext..ctor(GLWpfControlSettings settings) at OpenTK.Wpf.GLWpfControlRenderer..ctor(GLWpfControlSettings settings) at OpenTK.Wpf.GLWpfControl.Start(GLWpfControlSettings settings) at MyApp.UserControls.ShaderUserControl.InitControl()

Feature request Could it be possible to add a method that can check if OpenGL is supported or not, which can be invoked prior to the GLWpfControl.Start call to more gracefully handle devices that does not support OpenGL?

NogginBops commented 1 year ago

Generally there isn't really a good way to check in advance if OpenGL is supported for a particular combination of OpenGL versions and profile flags other than just trying to create an OpenGL window.

So to create a way to probe for OpenGL in advance would basically involve creating a window and seeing if it works or not. This could add some startup time, but might be considered acceptable if the application requires it.

I'm guessing it's hard to catch the exception in Start()? I'm not too well versed in Wpf so I'm not sure where the preferred place to check for these kinds of initialization errors is.