From 2cc221998c9efd20a0d1acbdfd9d99b94387af97 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 11 Jan 2008 20:23:41 +0000 Subject: [PATCH] Hacks to get the visual before creating a context. --- Source/OpenTK/Platform/X11/X11GLContext.cs | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/Source/OpenTK/Platform/X11/X11GLContext.cs b/Source/OpenTK/Platform/X11/X11GLContext.cs index 45168354..e46a5035 100644 --- a/Source/OpenTK/Platform/X11/X11GLContext.cs +++ b/Source/OpenTK/Platform/X11/X11GLContext.cs @@ -18,7 +18,7 @@ namespace OpenTK.Platform.X11 /// Provides methods to create and control an opengl context on the X11 platform. /// This class supports OpenTK, and is not intended for use by OpenTK programs. /// - internal sealed class X11GLContext : IGLContext + internal sealed class X11GLContext : IGLContext, IGLContextCreationHack { private IntPtr context; private DisplayMode mode; @@ -29,21 +29,25 @@ namespace OpenTK.Platform.X11 #region --- Constructors --- - public X11GLContext(DisplayMode mode, IWindowInfo info) - { - if (info == null) - throw new ArgumentNullException("IWindowInfo cannot be null."); - - this.windowInfo = new WindowInfo(info); - this.mode = mode; - this.ChooseContext(); - } + /// + /// Constructs a new X11GLContext object. + /// + public X11GLContext() { } #endregion - #region private void ChooseContext() + #region --- IGLContextCreationHack Members --- - private void ChooseContext() + #region bool IGLContextCreationHack.SelectDisplayMode(DisplayMode mode, IWindowInfo info) + + /// + /// HACK! This function will be removed in 0.3.15 + /// Checks if the specified OpenTK.Platform.DisplayMode is available, and selects it if it is. + /// + /// The OpenTK.Platform.DisplayMode to select. + /// The OpenTK.Platform.IWindowInfo that describes the display to use. Note: a window handle is not necessary for this function! + /// True if the DisplayMode is available, false otherwise. + bool IGLContextCreationHack.SelectDisplayMode(DisplayMode mode, IWindowInfo info) { List visualAttributes = new List(); @@ -86,15 +90,21 @@ namespace OpenTK.Platform.X11 visual = Glx.ChooseVisual(windowInfo.Display, windowInfo.Screen, visualAttributes.ToArray()); if (visual == IntPtr.Zero) - { - throw new ApplicationException("Could not create requested DisplayMode."); - } + return false; else { windowInfo.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(visual, typeof(XVisualInfo)); Debug.Print("Chose visual {0}", windowInfo.VisualInfo.ToString()); } + return true; + } + + #endregion + + void IGLContextCreationHack.SetWindowHandle(IntPtr handle) + { + this.windowInfo.Handle = handle; } #endregion