From 9075129df06973a64440a86c5ed0f02a3b7856b5 Mon Sep 17 00:00:00 2001 From: thefiddler Date: Sun, 15 Jun 2014 14:30:23 +0200 Subject: [PATCH] [X11] Throw exception if GLX is not supported You cannot create an X11/OpenGL context without the GLX extension. OpenTK will now throw a `NotSupportedException` when this condition is encountered. In some cases, it may be possible to enable the EGL backend by passing `GraphicsContextFlags.Embedded` to the `GraphicsContext` constructor. --- Source/OpenTK/Platform/X11/X11GLContext.cs | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Source/OpenTK/Platform/X11/X11GLContext.cs b/Source/OpenTK/Platform/X11/X11GLContext.cs index ca77aebc..a600b8be 100644 --- a/Source/OpenTK/Platform/X11/X11GLContext.cs +++ b/Source/OpenTK/Platform/X11/X11GLContext.cs @@ -54,14 +54,34 @@ namespace OpenTK.Platform.X11 if (window == null) throw new ArgumentNullException("window"); + // Do not move this lower, as almost everything requires the Display + // property to be correctly set. + Display = ((X11WindowInfo)window).Display; + + // Check that GLX is supported. We cannot proceed to create + // an OpenGL context without the GLX extension. + int error_base; + int event_base; + int glx_major; + int glx_minor; + using (new XLock(Display)) + { + bool supported = Glx.QueryExtension(Display, out error_base, out event_base); + supported &= Glx.QueryVersion(Display, out glx_major, out glx_minor); + if (supported) + { + Debug.Print("[X11] GLX supported. Version is {0}.{1}", glx_major, glx_minor); + } + else + { + throw new NotSupportedException("[X11] GLX extension is not supported."); + } + } + Mode = ModeSelector.SelectGraphicsMode( mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo); - // Do not move this lower, as almost everything requires the Display - // property to be correctly set. - Display = ((X11WindowInfo)window).Display; - currentWindow = (X11WindowInfo)window; currentWindow.VisualInfo = SelectVisual(Mode, currentWindow);