From 33d0193e7fd7f69f3e8fe3b7af0b691a877fa00f Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 15 Jan 2008 10:31:03 +0000 Subject: [PATCH] Refactored context creation to be done inside the *GLNative classes, instead of the GameWindow class. Should refactor in the next version. --- Source/OpenTK/GameWindow.cs | 8 ++++---- Source/OpenTK/Platform/INativeGLWindow.cs | 2 +- Source/OpenTK/Platform/Windows/WinGLNative.cs | 7 +++++-- Source/OpenTK/Platform/X11/X11GLNative.cs | 12 +++++------- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 5aaeeb7d..ef1564b2 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -327,7 +327,7 @@ namespace OpenTK { try { - glWindow.CreateWindow(mode, Context); + glWindow.CreateWindow(mode, out glContext); } catch (ApplicationException expt) { @@ -379,9 +379,9 @@ namespace OpenTK { if (!Exists) { - glWindow.CreateWindow(mode, glContext); - glContext = new GLContext(mode, glWindow.WindowInfo); - glContext.CreateContext(); + // TODO: This is a hack - reslove in 0.3.15 once and for all! + // GLContext is created inside the CreateWindow call. + glWindow.CreateWindow(mode, out glContext); this.Title = title; } else diff --git a/Source/OpenTK/Platform/INativeGLWindow.cs b/Source/OpenTK/Platform/INativeGLWindow.cs index 3cb6fed4..9ef4f0d0 100644 --- a/Source/OpenTK/Platform/INativeGLWindow.cs +++ b/Source/OpenTK/Platform/INativeGLWindow.cs @@ -17,7 +17,7 @@ namespace OpenTK.Platform /// interface INativeGLWindow : IResizable, IDisposable { - void CreateWindow(DisplayMode mode, GLContext context); + void CreateWindow(DisplayMode mode, out GLContext context); void DestroyWindow(); void ProcessEvents(); void PointToClient(ref System.Drawing.Point p); diff --git a/Source/OpenTK/Platform/Windows/WinGLNative.cs b/Source/OpenTK/Platform/Windows/WinGLNative.cs index c1b6cb3d..7b60107b 100644 --- a/Source/OpenTK/Platform/Windows/WinGLNative.cs +++ b/Source/OpenTK/Platform/Windows/WinGLNative.cs @@ -277,9 +277,9 @@ namespace OpenTK.Platform.Windows #endregion - #region public void CreateWindow(DisplayMode mode, GLContext context) + #region public void CreateWindow(DisplayMode mode, out GLContext context) - public void CreateWindow(DisplayMode windowMode, GLContext context) + public void CreateWindow(DisplayMode windowMode, out GLContext context) { Debug.Print("Creating native window with mode: {0}", windowMode.ToString()); Debug.Indent(); @@ -336,6 +336,9 @@ namespace OpenTK.Platform.Windows Functions.SetWindowPos(this.Handle, WindowPlacementOptions.TOP, Left, Top, cp.Width, cp.Height, SetWindowPosFlags.SHOWWINDOW); + context = new GLContext(mode, window); + context.CreateContext(); + Debug.Unindent(); } diff --git a/Source/OpenTK/Platform/X11/X11GLNative.cs b/Source/OpenTK/Platform/X11/X11GLNative.cs index 71dd324a..a68c7885 100644 --- a/Source/OpenTK/Platform/X11/X11GLNative.cs +++ b/Source/OpenTK/Platform/X11/X11GLNative.cs @@ -334,7 +334,7 @@ namespace OpenTK.Platform.X11 #endregion - #region public void CreateWindow(DisplayMode mode, GLContext glContext) + #region public void CreateWindow(DisplayMode mode, out GLContext glContext) /// /// Opens a new render window with the given DisplayMode. @@ -347,7 +347,7 @@ namespace OpenTK.Platform.X11 /// Colormap creation is currently disabled. /// /// - public void CreateWindow(DisplayMode mode, GLContext glContext) + public void CreateWindow(DisplayMode mode, out GLContext glContext) { if (exists) throw new ApplicationException("Render window already exists!"); @@ -355,8 +355,8 @@ namespace OpenTK.Platform.X11 Debug.Print("Creating GameWindow with mode: {0}", mode != null ? mode.ToString() : "default"); Debug.Indent(); - //glContext = new X11GLContext(mode, window); - //glContext.PrepareContext(window); + glContext = new GLContext(mode, window); + (glContext as IGLContextCreationHack).SelectDisplayMode(mode, window); window.VisualInfo = ((glContext as IGLContextInternal).Info as X11.WindowInfo).VisualInfo; //window.VisualInfo = Marshal.PtrToStructure(Glx.ChooseVisual(window.Display, window.Screen, @@ -412,9 +412,7 @@ namespace OpenTK.Platform.X11 Debug.Print("done! (id: {0})", window.Handle); - //(glContext.Info as X11.WindowInfo).Handle = window.Handle; - //glContext.CreateContext(true, null); - //glContext.MakeCurrent(); + (glContext as IGLContextCreationHack).SetWindowHandle(window.Handle); API.MapRaised(window.Display, window.Handle); mapped = true;