From d4112a6e9544887b53cc822b39d84db5cb76d655 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 11:21:10 +0200 Subject: [PATCH 01/27] Add OpenTK.GLWidget as a friend assembly, allowing it to access internals. --- src/OpenTK/Properties/AssemblyInfo.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OpenTK/Properties/AssemblyInfo.cs b/src/OpenTK/Properties/AssemblyInfo.cs index f0d6b897..5246aeff 100644 --- a/src/OpenTK/Properties/AssemblyInfo.cs +++ b/src/OpenTK/Properties/AssemblyInfo.cs @@ -1,6 +1,7 @@ // using System; using System.Reflection; +using System.Runtime.CompilerServices; [assembly: AssemblyTitleAttribute("OpenTK")] [assembly: AssemblyProductAttribute("OpenTK")] @@ -9,6 +10,9 @@ using System.Reflection; [assembly: AssemblyFileVersionAttribute("3.0.0")] [assembly: CLSCompliantAttribute(true)] [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] + +[assembly: InternalsVisibleTo("OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8")] + namespace System { internal static class AssemblyVersionInformation { internal const System.String AssemblyTitle = "OpenTK"; From d677aef6c392ec05890de1de31da2228f350f49e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 11:21:22 +0200 Subject: [PATCH 02/27] Inherit from GLArea instead of DrawingArea. --- src/OpenTK.GLWidget/GLWidget.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 5abababc..53d31897 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -7,6 +7,7 @@ using OpenTK.Platform; using Gtk; using OpenTK.OSX; +using OpenTK.Platform.X11; using OpenTK.Win; using OpenTK.X11; @@ -17,7 +18,7 @@ namespace OpenTK /// [CLSCompliant(false)] [ToolboxItem(true)] - public class GLWidget: DrawingArea + public class GLWidget: GLArea { private static int _GraphicsContextCount; @@ -386,6 +387,7 @@ namespace OpenTK } // GraphicsContext + _GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags); _GraphicsContext.MakeCurrent(_WindowInfo); From 456d7cde37b3a62b28dec1b526f5c765af691613 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 11:51:11 +0200 Subject: [PATCH 03/27] Initialize an OpenTK::GraphicsContext from the foreign GDK context. --- src/OpenTK.GLWidget/GLWidget.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 53d31897..db1833e0 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -386,9 +386,14 @@ namespace OpenTK _WindowInfo = XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle); } - // GraphicsContext + // Make the GDK GL context current + Context.MakeCurrent(); - _GraphicsContext = new GraphicsContext(graphicsMode, _WindowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags); + // Create an OpenTK graphics context using the GdkGLContext as a foreign context + // Since the GDK context is already created and has been made current, we can retrieve its handle. + var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()(); + + _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, GlVersionMajor, GlVersionMinor, GraphicsContextFlags); _GraphicsContext.MakeCurrent(_WindowInfo); if (GraphicsContext.ShareContexts) From c485327da55c177d89fa6c5c2fc7474829449544 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 11:52:50 +0200 Subject: [PATCH 04/27] Remove GLVersion properties, and use the underlying GLArea implementation. --- src/OpenTK.GLWidget/GLWidget.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index db1833e0..f5ae5920 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -64,16 +64,6 @@ namespace OpenTK /// public bool Stereo { get; set; } - /// - /// The major version of OpenGL to use. - /// - public int GlVersionMajor { get; set; } - - /// - /// The minor version of OpenGL to use. - /// - public int GlVersionMinor { get; set; } - /// /// The set for this widget. /// @@ -114,8 +104,7 @@ namespace OpenTK Samples = graphicsMode.Samples; Stereo = graphicsMode.Stereo; - GlVersionMajor = glVersionMajor; - GlVersionMinor = glVersionMinor; + SetRequiredVersion(glVersionMajor, glVersionMinor); GraphicsContextFlags = graphicsContextFlags; } @@ -393,7 +382,8 @@ namespace OpenTK // Since the GDK context is already created and has been made current, we can retrieve its handle. var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()(); - _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, GlVersionMajor, GlVersionMinor, GraphicsContextFlags); + GetRequiredVersion(out int glVersionMajor, out int glVersionMinor); + _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags); _GraphicsContext.MakeCurrent(_WindowInfo); if (GraphicsContext.ShareContexts) From e879b731454de8f286069bf0313cc028e8e7be06 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:37:28 +0200 Subject: [PATCH 05/27] Add buffer flag selection. --- src/OpenTK.GLWidget/GLWidget.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index f5ae5920..62e74f8d 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -1,7 +1,7 @@ using System; using System.Threading; using System.ComponentModel; - +using Gdk; using OpenTK.Graphics; using OpenTK.Platform; @@ -104,8 +104,24 @@ namespace OpenTK Samples = graphicsMode.Samples; Stereo = graphicsMode.Stereo; - SetRequiredVersion(glVersionMajor, glVersionMinor); GraphicsContextFlags = graphicsContextFlags; + + SetRequiredVersion(glVersionMajor, glVersionMinor); + + if (graphicsMode.Depth > 0) + { + HasDepthBuffer = true; + } + + if (graphicsMode.Stencil > 0) + { + HasStencilBuffer = true; + } + + if (graphicsMode.ColorFormat.Alpha > 0) + { + HasAlpha = true; + } } /// From 649cce05f7fdf5c4147c4f66dc8730da80b6cf64 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:38:49 +0200 Subject: [PATCH 06/27] Remove manual visual selection from the X11 initialization. --- src/OpenTK.GLWidget/GLWidget.cs | 2 +- .../X11/XWindowInfoInitializer.cs | 110 +----------------- 2 files changed, 3 insertions(+), 109 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 62e74f8d..dbae8dae 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -388,7 +388,7 @@ namespace OpenTK } else { - _WindowInfo = XWindowInfoInitializer.Initialize(graphicsMode, this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle); + _WindowInfo = XWindowInfoInitializer.Initialize(this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle); } // Make the GDK GL context current diff --git a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs index 74b86d54..2c047893 100644 --- a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs +++ b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs @@ -19,19 +19,15 @@ namespace OpenTK.X11 #else const string UnixLibGdkName = "libgdk-x11-2.0.so.0"; #endif - private const string UnixLibX11Name = "libX11.so.6"; - private const string UnixLibGLName = "libGL.so.1"; - /// /// Initializes an under the X11 platform. /// - /// /// /// /// /// /// - public static IWindowInfo Initialize(GraphicsMode mode, IntPtr displayHandle, int screenNumber, IntPtr gdkWindowHandle, IntPtr gdkRootWindowHandle) + public static IWindowInfo Initialize(IntPtr displayHandle, int screenNumber, IntPtr gdkWindowHandle, IntPtr gdkRootWindowHandle) { IntPtr display = gdk_x11_display_get_xdisplay(displayHandle); @@ -43,110 +39,11 @@ namespace OpenTK.X11 IntPtr rootWindowXid = gdk_x11_drawable_get_xid(gdkRootWindowHandle); #endif - IntPtr visualInfo; - if (mode.Index.HasValue) - { - XVisualInfo info = new XVisualInfo - { - VisualID = mode.Index.Value - }; - - int dummy; - visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy); - } - else - { - visualInfo = GetVisualInfo(mode, display, screenNumber); - } - - IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, visualInfo); - XFree(visualInfo); + IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, IntPtr.Zero); return retval; } - private static IntPtr XGetVisualInfo(IntPtr display, XVisualInfoMask infoMask, ref XVisualInfo template, out int nitems) - { - return XGetVisualInfoInternal(display, (IntPtr)(int)infoMask, ref template, out nitems); - } - - private static IntPtr GetVisualInfo(GraphicsMode mode, IntPtr display, int screenNumber) - { - try - { - int[] attributes = CreateAttributeList(mode).ToArray(); - return glXChooseVisual(display, screenNumber, attributes); - } - catch (DllNotFoundException e) - { - throw new DllNotFoundException("OpenGL dll not found!", e); - } - catch (EntryPointNotFoundException enf) - { - throw new EntryPointNotFoundException("Glx entry point not found!", enf); - } - } - - private static List CreateAttributeList(GraphicsMode mode) - { - List attributeList = new List(24); - - attributeList.Add((int)GLXAttribute.RGBA); - - if (mode.Buffers > 1) - { - attributeList.Add((int)GLXAttribute.DOUBLEBUFFER); - } - - if (mode.Stereo) - { - attributeList.Add((int)GLXAttribute.STEREO); - } - - attributeList.Add((int)GLXAttribute.RED_SIZE); - attributeList.Add(mode.ColorFormat.Red / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.GREEN_SIZE); - attributeList.Add(mode.ColorFormat.Green / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.BLUE_SIZE); - attributeList.Add(mode.ColorFormat.Blue / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.ALPHA_SIZE); - attributeList.Add(mode.ColorFormat.Alpha / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.DEPTH_SIZE); - attributeList.Add(mode.Depth); - - attributeList.Add((int)GLXAttribute.STENCIL_SIZE); - attributeList.Add(mode.Stencil); - - //attributeList.Add(GLX_AUX_BUFFERS); - //attributeList.Add(Buffers); - - attributeList.Add((int)GLXAttribute.ACCUM_RED_SIZE); - attributeList.Add(mode.AccumulatorFormat.Red / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.ACCUM_GREEN_SIZE); - attributeList.Add(mode.AccumulatorFormat.Green / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.ACCUM_BLUE_SIZE); - attributeList.Add(mode.AccumulatorFormat.Blue / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.ACCUM_ALPHA_SIZE); - attributeList.Add(mode.AccumulatorFormat.Alpha / 4); // TODO support 16-bit - - attributeList.Add((int)GLXAttribute.NONE); - - return attributeList; - } - - [DllImport(UnixLibX11Name, EntryPoint = "XGetVisualInfo")] - private static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr infoMask, ref XVisualInfo template, out int nitems); - - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibX11Name)] - private static extern void XFree(IntPtr handle); - #if GTK3 /// Returns the X resource (window or pixmap) belonging to a GdkWindow. /// XID gdk_x11_window_get_xid(GdkWindow *drawable); @@ -168,8 +65,5 @@ namespace OpenTK.X11 /// The X Display of the GdkDisplay. [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay); - - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGLName)] - private static extern IntPtr glXChooseVisual(IntPtr display, int screen, int[] attr); } } \ No newline at end of file From 6a40207b9fa230b0d212f81efb2e6e15e4aa4533 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:39:47 +0200 Subject: [PATCH 07/27] Remove properties that are no longer relevant or used. --- src/OpenTK.GLWidget/GLWidget.cs | 67 --------------------------------- 1 file changed, 67 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index dbae8dae..2bc1dd9b 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -28,42 +28,6 @@ namespace OpenTK private IWindowInfo _WindowInfo; private bool _Initialized = false; - /// - /// Use a single buffer versus a double buffer. - /// - [Browsable(true)] - public bool SingleBuffer { get; set; } - - /// - /// Color Buffer Bits-Per-Pixel - /// - public int ColorBPP { get; set; } - - /// - /// Accumulation Buffer Bits-Per-Pixel - /// - public int AccumulatorBPP { get; set; } - - /// - /// Depth Buffer Bits-Per-Pixel - /// - public int DepthBPP { get; set; } - - /// - /// Stencil Buffer Bits-Per-Pixel - /// - public int StencilBPP { get; set; } - - /// - /// Number of samples - /// - public int Samples { get; set; } - - /// - /// Indicates if steropic renderering is enabled - /// - public bool Stereo { get; set; } - /// /// The set for this widget. /// @@ -96,14 +60,6 @@ namespace OpenTK { this.DoubleBuffered = false; - SingleBuffer = graphicsMode.Buffers == 1; - ColorBPP = graphicsMode.ColorFormat.BitsPerPixel; - AccumulatorBPP = graphicsMode.AccumulatorFormat.BitsPerPixel; - DepthBPP = graphicsMode.Depth; - StencilBPP = graphicsMode.Stencil; - Samples = graphicsMode.Samples; - Stereo = graphicsMode.Stereo; - GraphicsContextFlags = graphicsContextFlags; SetRequiredVersion(glVersionMajor, glVersionMinor); @@ -335,29 +291,6 @@ namespace OpenTK { _Initialized = true; - // If this looks uninitialized... initialize. - if (ColorBPP == 0) - { - ColorBPP = 32; - - if (DepthBPP == 0) - { - DepthBPP = 16; - } - } - - ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP); - - ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP); - - int buffers = 2; - if (SingleBuffer) - { - buffers--; - } - - GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo); - if (Configuration.RunningOnWindows) { Console.WriteLine("OpenTK running on windows"); From e9f27ff6301e48a417598068c7fb5baa2cea21ed Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:40:21 +0200 Subject: [PATCH 08/27] Remove duplicate RenderFrame event (GLArea has one already). --- src/OpenTK.GLWidget/GLWidget.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 2bc1dd9b..079541f4 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -193,22 +193,6 @@ namespace OpenTK } } - /// - /// Called when this needs to render a frame. - /// - public event EventHandler RenderFrame; - - /// - /// Invokes the event. - /// - protected virtual void OnRenderFrame() - { - if (RenderFrame != null) - { - RenderFrame(this, EventArgs.Empty); - } - } - /// /// Called when this is being disposed. /// @@ -255,9 +239,6 @@ namespace OpenTK #else bool result = base.OnExposeEvent(evnt); #endif - - OnRenderFrame(); - #if !GTK3 evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? #endif From 6d4bb3059686509a9106b9e9f5e6b030406050fd Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:41:23 +0200 Subject: [PATCH 09/27] Remove redundant MakeCurrent call, the base OnDrawn already does this. --- src/OpenTK.GLWidget/GLWidget.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 079541f4..d389f322 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -229,11 +229,6 @@ namespace OpenTK { Initialize(); } - else - { - _GraphicsContext.MakeCurrent(_WindowInfo); - } - #if GTK3 var result = base.OnDrawn(cr); #else From 9dd03dd7696b2d9cee4045e6f97fb5559e98919f Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:41:36 +0200 Subject: [PATCH 10/27] Remove redundant SwapBuffers call, the base OnDrawn already does this. --- src/OpenTK.GLWidget/GLWidget.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index d389f322..41c6b44c 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -237,9 +237,6 @@ namespace OpenTK #if !GTK3 evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? #endif - - _GraphicsContext.SwapBuffers(); - return result; } From ed126403b376eed298f5fbc7e64ea122cb041c9b Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:42:28 +0200 Subject: [PATCH 11/27] Use GLArea MakeCurrent method. --- src/OpenTK.GLWidget/GLWidget.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 41c6b44c..be9772fe 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -298,7 +298,7 @@ namespace OpenTK } // Make the GDK GL context current - Context.MakeCurrent(); + MakeCurrent(); // Create an OpenTK graphics context using the GdkGLContext as a foreign context // Since the GDK context is already created and has been made current, we can retrieve its handle. @@ -306,7 +306,8 @@ namespace OpenTK GetRequiredVersion(out int glVersionMajor, out int glVersionMinor); _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags); - _GraphicsContext.MakeCurrent(_WindowInfo); + + MakeCurrent(); if (GraphicsContext.ShareContexts) { From eb317df44ca9fd3eec2871066c502dd688efdd85 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:42:57 +0200 Subject: [PATCH 12/27] Use GLArea MakeCurrent method in disposal as well. --- src/OpenTK.GLWidget/GLWidget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index be9772fe..c89f9e2f 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -131,7 +131,7 @@ namespace OpenTK #endif if (disposing) { - _GraphicsContext.MakeCurrent(_WindowInfo); + MakeCurrent(); OnShuttingDown(); if (GraphicsContext.ShareContexts && (Interlocked.Decrement(ref _GraphicsContextCount) == 0)) { From 4089de86a5d4b3ecb82d7c52bd14f10a528b59bf Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:44:47 +0200 Subject: [PATCH 13/27] Remove redundant MakeCurrent call. --- src/OpenTK.GLWidget/GLWidget.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index c89f9e2f..87903b79 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -307,8 +307,6 @@ namespace OpenTK GetRequiredVersion(out int glVersionMajor, out int glVersionMinor); _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags); - MakeCurrent(); - if (GraphicsContext.ShareContexts) { Interlocked.Increment(ref _GraphicsContextCount); From e6e2764c55c109f42b1a1cd11a095aac63ab2a36 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 12:57:28 +0200 Subject: [PATCH 14/27] Add explanatory comment. --- src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs index 2c047893..cc9ec9fe 100644 --- a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs +++ b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs @@ -39,6 +39,7 @@ namespace OpenTK.X11 IntPtr rootWindowXid = gdk_x11_drawable_get_xid(gdkRootWindowHandle); #endif + // No visual needs to be passed here, since we're piggybacking on the GdkGLContext from the base GLArea IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, IntPtr.Zero); return retval; From 67a96699176d594d9e742ff56ca60d5e4b7ebca2 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 16:57:46 +0200 Subject: [PATCH 15/27] Bump language version to 7.0. --- src/OpenTK.GLWidget/OpenTK.GLWidget.csproj | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj index 6e771eba..aeda128c 100644 --- a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj +++ b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj @@ -42,7 +42,7 @@ v4.5 true - 6 + 7 true ..\..\stylecop.ruleset @@ -120,8 +120,7 @@ - + ..\..\packages\gtk-sharp3\lib\net40\cairo-sharp.dll From 82f0d4a5fd6f41c4c3087a8ca0a07e1ec0a885d2 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 18:14:32 +0200 Subject: [PATCH 16/27] Add InternalsVisibleTo override in build script. --- build.fsx | 20 +++++++++++++------- src/OpenTK/Properties/AssemblyInfo.cs | 5 ++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/build.fsx b/build.fsx index b153c0fb..1dd12ce4 100644 --- a/build.fsx +++ b/build.fsx @@ -99,13 +99,19 @@ Target "AssemblyInfo" (fun _ -> projectName.Split('.').[0] else projectName - [ Attribute.Title (projectName) - Attribute.Product project - Attribute.Description summary - Attribute.Version release.AssemblyVersion - Attribute.FileVersion release.AssemblyVersion - Attribute.CLSCompliant true - Attribute.Copyright copyright ] + let baseAttributes = + [ Attribute.Title (projectName) + Attribute.Product project + Attribute.Description summary + Attribute.Version release.AssemblyVersion + Attribute.FileVersion release.AssemblyVersion + Attribute.CLSCompliant true + Attribute.Copyright copyright + ] + if projectName = "OpenTK" then + baseAttributes @ [Attribute.InternalsVisibleTo "OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8"] + else + baseAttributes let getProjectDetails projectPath = let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath) diff --git a/src/OpenTK/Properties/AssemblyInfo.cs b/src/OpenTK/Properties/AssemblyInfo.cs index 5246aeff..045ffa41 100644 --- a/src/OpenTK/Properties/AssemblyInfo.cs +++ b/src/OpenTK/Properties/AssemblyInfo.cs @@ -10,9 +10,7 @@ using System.Runtime.CompilerServices; [assembly: AssemblyFileVersionAttribute("3.0.0")] [assembly: CLSCompliantAttribute(true)] [assembly: AssemblyCopyrightAttribute("Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library.")] - -[assembly: InternalsVisibleTo("OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8")] - +[assembly: InternalsVisibleToAttribute("OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8")] namespace System { internal static class AssemblyVersionInformation { internal const System.String AssemblyTitle = "OpenTK"; @@ -22,5 +20,6 @@ namespace System { internal const System.String AssemblyFileVersion = "3.0.0"; internal const System.Boolean CLSCompliant = true; internal const System.String AssemblyCopyright = "Copyright (c) 2006 - 2016 Stefanos Apostolopoulos for the Open Toolkit library."; + internal const System.String InternalsVisibleTo = "OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8"; } } From 5df8f47d185c753a8fdad7aa6c9779b907c52b50 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Fri, 15 Sep 2017 18:33:31 +0200 Subject: [PATCH 17/27] Bump AppVeyor image to 2017 to support C# 7.0 language features --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 92796ce4..28f1f89c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,4 @@ +image: Visual Studio 2017 init: - git config --global core.autocrlf input build_script: From 29863f13da3875de91204ec2a2b356ffd537a651 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sat, 16 Sep 2017 16:20:00 +0200 Subject: [PATCH 18/27] Removed redundant WindowInfo initializer. --- src/OpenTK.GLWidget/GLWidget.cs | 66 +---------------- .../OSX/OSXWindowInfoInitializer.cs | 38 ---------- src/OpenTK.GLWidget/OpenTK.GLWidget.csproj | 3 - .../Win/WinWindowsInfoInitializer.cs | 43 ------------ .../X11/XWindowInfoInitializer.cs | 70 ------------------- 5 files changed, 2 insertions(+), 218 deletions(-) delete mode 100644 src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs delete mode 100644 src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs delete mode 100644 src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 87903b79..6b11da02 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -1,15 +1,8 @@ using System; using System.Threading; using System.ComponentModel; -using Gdk; using OpenTK.Graphics; -using OpenTK.Platform; - using Gtk; -using OpenTK.OSX; -using OpenTK.Platform.X11; -using OpenTK.Win; -using OpenTK.X11; namespace OpenTK { @@ -25,7 +18,6 @@ namespace OpenTK private static bool _SharedContextInitialized = false; private IGraphicsContext _GraphicsContext; - private IWindowInfo _WindowInfo; private bool _Initialized = false; /// @@ -240,23 +232,6 @@ namespace OpenTK return result; } - /// - /// Called whenever the widget is resized. - /// - /// - /// - protected override bool OnConfigureEvent(Gdk.EventConfigure evnt) - { - bool result = base.OnConfigureEvent(evnt); - - if (_GraphicsContext != null) - { - _GraphicsContext.Update(_WindowInfo); - } - - return result; - } - /// /// Initializes the with its given values and creates a . /// @@ -264,48 +239,11 @@ namespace OpenTK { _Initialized = true; - if (Configuration.RunningOnWindows) - { - Console.WriteLine("OpenTK running on windows"); - } - else if (Configuration.RunningOnMacOS) - { - Console.WriteLine("OpenTK running on OSX"); - } - else - { - Console.WriteLine("OpenTK running on X11"); - } - -#if GTK3 - IntPtr widgetWindowHandle = this.Window.Handle; -#else - IntPtr widgetWindowHandle = this.GdkWindow.Handle; -#endif - - // IWindowInfo - if (Configuration.RunningOnWindows) - { - _WindowInfo = WinWindowsInfoInitializer.Initialize(widgetWindowHandle); - } - else if (Configuration.RunningOnMacOS) - { - _WindowInfo = OSXWindowInfoInitializer.Initialize(widgetWindowHandle); - } - else - { - _WindowInfo = XWindowInfoInitializer.Initialize(this.Display.Handle, this.Screen.Number, widgetWindowHandle, this.Screen.RootWindow.Handle); - } - // Make the GDK GL context current MakeCurrent(); - // Create an OpenTK graphics context using the GdkGLContext as a foreign context - // Since the GDK context is already created and has been made current, we can retrieve its handle. - var gdkContextHandle = Factory.Default.CreateGetCurrentGraphicsContext()(); - - GetRequiredVersion(out int glVersionMajor, out int glVersionMinor); - _GraphicsContext = new GraphicsContext(gdkContextHandle, _WindowInfo, null, glVersionMajor, glVersionMinor, GraphicsContextFlags); + // Create a dummy context that will grab the GdkGLContext that is current on the thread + _GraphicsContext = new GraphicsContext(ContextHandle.Zero, null); if (GraphicsContext.ShareContexts) { diff --git a/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs b/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs deleted file mode 100644 index cfdba748..00000000 --- a/src/OpenTK.GLWidget/OSX/OSXWindowInfoInitializer.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Platform; - -namespace OpenTK.OSX -{ - /// - /// Handler class for initializing objects under the OSX platform for both GTK2 and - /// GTK3. - /// - public static class OSXWindowInfoInitializer - { -#if GTK3 - private const string OSXLibGdkName = "libgdk-3.dylib"; -#else - const string OSXLibGdkName = "libgdk-quartz-2.0.0.dylib"; -#endif - - /// - /// Initializes an under the OSX platform. - /// - /// - public static IWindowInfo Initialize(IntPtr gdkWindowHandle) - { - IntPtr windowHandle = gdk_quartz_window_get_nswindow(gdkWindowHandle); - IntPtr viewHandle = gdk_quartz_window_get_nsview(gdkWindowHandle); - - return Utilities.CreateMacOSWindowInfo(windowHandle, viewHandle); - } - - [SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)] - private static extern IntPtr gdk_quartz_window_get_nswindow(IntPtr handle); - - [SuppressUnmanagedCodeSecurity, DllImport(OSXLibGdkName)] - private static extern IntPtr gdk_quartz_window_get_nsview(IntPtr handle); - } -} \ No newline at end of file diff --git a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj index aeda128c..c82f52bd 100644 --- a/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj +++ b/src/OpenTK.GLWidget/OpenTK.GLWidget.csproj @@ -98,13 +98,10 @@ - Code - - diff --git a/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs b/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs deleted file mode 100644 index 95303104..00000000 --- a/src/OpenTK.GLWidget/Win/WinWindowsInfoInitializer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Platform; - -namespace OpenTK.Win -{ - /// - /// Handler class for initializing objects under the Windows platform for both GTK2 and - /// GTK3. - /// - public static class WinWindowsInfoInitializer - { -#if GTK3 - private const string WinLibGDKName = "libgdk-3-0.dll"; -#else - private const string WinLibGDKName = "libgdk-win32-2.0-0.dll"; -#endif - - /// - /// Initializes an under the Windows platform. - /// - /// - public static IWindowInfo Initialize(IntPtr gdkWindowHandle) - { -#if GTK3 - IntPtr windowHandle = gdk_win32_window_get_handle(gdkWindowHandle); -#else - IntPtr windowHandle = gdk_win32_drawable_get_handle(gdkWindowHandle); -#endif - return Utilities.CreateWindowsWindowInfo(windowHandle); - } - -#if GTK3 - [SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gdk_win32_window_get_handle(IntPtr w); -#else - [SuppressUnmanagedCodeSecurity, DllImport(WinLibGDKName, CallingConvention = CallingConvention.Cdecl)] - static extern IntPtr gdk_win32_drawable_get_handle(IntPtr d); -#endif - - } -} \ No newline at end of file diff --git a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs b/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs deleted file mode 100644 index cc9ec9fe..00000000 --- a/src/OpenTK.GLWidget/X11/XWindowInfoInitializer.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Security; -using OpenTK.Graphics; -using OpenTK.Platform; -using OpenTK.Platform.X11; - -namespace OpenTK.X11 -{ - /// - /// Handler class for initializing objects under the X11 platform for both GTK2 and GTK3. - /// - public static class XWindowInfoInitializer - { - -#if GTK3 - private const string UnixLibGdkName = "libgdk-3.so.0"; -#else - const string UnixLibGdkName = "libgdk-x11-2.0.so.0"; -#endif - /// - /// Initializes an under the X11 platform. - /// - /// - /// - /// - /// - /// - public static IWindowInfo Initialize(IntPtr displayHandle, int screenNumber, IntPtr gdkWindowHandle, IntPtr gdkRootWindowHandle) - { - IntPtr display = gdk_x11_display_get_xdisplay(displayHandle); - -#if GTK3 - IntPtr windowXid = gdk_x11_window_get_xid(gdkWindowHandle); - IntPtr rootWindowXid = gdk_x11_window_get_xid(gdkRootWindowHandle); -#else - IntPtr windowXid = gdk_x11_drawable_get_xid(gdkWindowHandle); - IntPtr rootWindowXid = gdk_x11_drawable_get_xid(gdkRootWindowHandle); -#endif - - // No visual needs to be passed here, since we're piggybacking on the GdkGLContext from the base GLArea - IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screenNumber, windowXid, rootWindowXid, IntPtr.Zero); - - return retval; - } - -#if GTK3 - /// Returns the X resource (window or pixmap) belonging to a GdkWindow. - /// XID gdk_x11_window_get_xid(GdkWindow *drawable); - /// The GdkDrawable. - /// The ID of window's X resource. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - private static extern IntPtr gdk_x11_window_get_xid(IntPtr gdkDisplay); -#else - /// Returns the X resource (window or pixmap) belonging to a GdkDrawable. - /// XID gdk_x11_drawable_get_xid(GdkDrawable *drawable); - /// The GdkDrawable. - /// The ID of drawable's X resource. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - static extern IntPtr gdk_x11_drawable_get_xid(IntPtr gdkDisplay); -#endif - /// Returns the X display of a GdkDisplay. - /// Display* gdk_x11_display_get_xdisplay(GdkDisplay *display); - /// The GdkDrawable. - /// The X Display of the GdkDisplay. - [SuppressUnmanagedCodeSecurity, DllImport(UnixLibGdkName)] - private static extern IntPtr gdk_x11_display_get_xdisplay(IntPtr gdkDisplay); - } -} \ No newline at end of file From b1f90c380e6b915b5a4bdf3614e9260bbc67cd38 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:06:50 +0200 Subject: [PATCH 19/27] Add builtin frame time measurement. GLArea automatically synchronizes to GDK's refresh rate, which may lead to incorrect frame time measurements if it's not correctly measured. This property is guaranteed to always contain the actual live frame delta of the previous frame in render functions. --- src/OpenTK.GLWidget/GLWidget.cs | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 6b11da02..54b6bd78 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.ComponentModel; +using Gdk; using OpenTK.Graphics; using Gtk; @@ -20,6 +21,16 @@ namespace OpenTK private IGraphicsContext _GraphicsContext; private bool _Initialized = false; + /// + /// The previous frame time reported by GTK. + /// + private double? PreviousFrameTime; + + /// + /// Gets the time taken to render the last frame (in seconds). + /// + public double DeltaTime { get; private set; } + /// /// The set for this widget. /// @@ -54,6 +65,7 @@ namespace OpenTK GraphicsContextFlags = graphicsContextFlags; + AddTickCallback(UpdateFrameTime); SetRequiredVersion(glVersionMajor, glVersionMinor); if (graphicsMode.Depth > 0) @@ -72,6 +84,31 @@ namespace OpenTK } } + /// + /// Updates the time delta with a new value from the last frame. + /// + /// The sending widget. + /// The relevant frame clock. + /// true if the callback should be called again; otherwise, false. + private bool UpdateFrameTime(Widget widget, FrameClock frameClock) + { + var frameTimeµSeconds = frameClock.FrameTime; + + if (!PreviousFrameTime.HasValue) + { + PreviousFrameTime = frameTimeµSeconds; + + return true; + } + + var frameTimeSeconds = (frameTimeµSeconds - PreviousFrameTime) / 10e6; + + DeltaTime = (float)frameTimeSeconds; + PreviousFrameTime = frameTimeµSeconds; + + return true; + } + /// /// Destructs this object. /// From d3f5a87809676c50e325193029ec7cd91a49d7bf Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:11:58 +0200 Subject: [PATCH 20/27] Override context creation in GLArea. This allows forward compatible and debug contexts to be created, and provides more descriptive exceptions in the case where the context cannot be created with the requested settings. --- src/OpenTK.GLWidget/GLWidget.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 54b6bd78..afe0ffe7 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -109,6 +109,22 @@ namespace OpenTK return true; } + + /// + protected override GLContext OnCreateContext() + { + var gdkGLContext = Window.CreateGlContext(); + + GetRequiredVersion(out var major, out var minor); + gdkGLContext.SetRequiredVersion(major, minor); + + gdkGLContext.DebugEnabled = GraphicsContextFlags.HasFlag(GraphicsContextFlags.Debug); + gdkGLContext.ForwardCompatible = GraphicsContextFlags.HasFlag(GraphicsContextFlags.ForwardCompatible); + + gdkGLContext.Realize(); + return gdkGLContext; + } + /// /// Destructs this object. /// From 72dedf5018b04604eb8b4c72d3f0e39972bb58b3 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:13:00 +0200 Subject: [PATCH 21/27] Revert addition of InternalsVisibleTo attribute for the OpenTK assembly. --- build.fsx | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/build.fsx b/build.fsx index 1dd12ce4..530bb12a 100644 --- a/build.fsx +++ b/build.fsx @@ -99,19 +99,14 @@ Target "AssemblyInfo" (fun _ -> projectName.Split('.').[0] else projectName - let baseAttributes = - [ Attribute.Title (projectName) - Attribute.Product project - Attribute.Description summary - Attribute.Version release.AssemblyVersion - Attribute.FileVersion release.AssemblyVersion - Attribute.CLSCompliant true - Attribute.Copyright copyright - ] - if projectName = "OpenTK" then - baseAttributes @ [Attribute.InternalsVisibleTo "OpenTK.GLWidget, PublicKey=0024000004800000940000000602000000240000525341310004000011000000a3e05aafb87f71fb8fd02b512707f289c12341de98c6ce2ec1494b71c20cb2032cbd65d091b447df3ec772257efb9fa3591201937890e067da1d29a339948a12b29c2847a787cc9fbef2a3bf78267026e85f36aab827228df4bb580e3ae0599ade036f0a97a0e6982f5406d98d114455f332350f6d8369db655e9c3e7976c2c8"] - else - baseAttributes + [ Attribute.Title (projectName) + Attribute.Product project + Attribute.Description summary + Attribute.Version release.AssemblyVersion + Attribute.FileVersion release.AssemblyVersion + Attribute.CLSCompliant true + Attribute.Copyright copyright + ] let getProjectDetails projectPath = let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath) From 6e40aebeb3cfc0e8d52b11c2c8eee03b775d2fbc Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:14:15 +0200 Subject: [PATCH 22/27] Remove GTK2 code. GLArea is only properly supported for GTK >= 3.16. --- src/OpenTK.GLWidget/GLWidget.cs | 41 +-------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index afe0ffe7..dc59efa1 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -144,36 +144,12 @@ namespace OpenTK base.Destroy(); } -#if !GTK3 - /// - /// Disposes the current object, releasing any native resources it was using. - /// - /// - public override void Dispose() - { - GC.SuppressFinalize(this); - Dispose(true); - - base.Dispose(); - } -#endif - -#if GTK3 /// /// Disposes the current object, releasing any native resources it was using. /// /// protected override void Dispose(bool disposing) { - base.Dispose(disposing); -#else - /// - /// Disposes the current object, releasing any native resources it was using. - /// - /// - public virtual void Dispose(bool disposing) - { -#endif if (disposing) { MakeCurrent(); @@ -254,34 +230,19 @@ namespace OpenTK } } -#if GTK3 /// /// Called when the widget needs to be (fully or partially) redrawn. /// /// /// protected override bool OnDrawn(Cairo.Context cr) -#else - /// - /// Called when the widget is exposed. - /// - /// - /// - protected override bool OnExposeEvent(Gdk.EventExpose evnt) -#endif { if (!_Initialized) { Initialize(); } -#if GTK3 + var result = base.OnDrawn(cr); -#else - bool result = base.OnExposeEvent(evnt); -#endif -#if !GTK3 - evnt.Window.Display.Sync(); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync? -#endif return result; } From 2caeaf40e187fecca108911312a2c03521437111 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:14:39 +0200 Subject: [PATCH 23/27] Correct field naming. --- src/OpenTK.GLWidget/GLWidget.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index dc59efa1..b72c512f 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -24,7 +24,7 @@ namespace OpenTK /// /// The previous frame time reported by GTK. /// - private double? PreviousFrameTime; + private double? _PreviousFrameTime; /// /// Gets the time taken to render the last frame (in seconds). @@ -94,17 +94,17 @@ namespace OpenTK { var frameTimeµSeconds = frameClock.FrameTime; - if (!PreviousFrameTime.HasValue) + if (!_PreviousFrameTime.HasValue) { - PreviousFrameTime = frameTimeµSeconds; + _PreviousFrameTime = frameTimeµSeconds; return true; } - var frameTimeSeconds = (frameTimeµSeconds - PreviousFrameTime) / 10e6; + var frameTimeSeconds = (frameTimeµSeconds - _PreviousFrameTime) / 10e6; DeltaTime = (float)frameTimeSeconds; - PreviousFrameTime = frameTimeµSeconds; + _PreviousFrameTime = frameTimeµSeconds; return true; } From cbae16b7a12fe97dae8aca2f6c0da2b8b5e0cabb Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:14:53 +0200 Subject: [PATCH 24/27] Correct formatting. --- src/OpenTK.GLWidget/GLWidget.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index b72c512f..1e292e10 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -12,9 +12,8 @@ namespace OpenTK /// [CLSCompliant(false)] [ToolboxItem(true)] - public class GLWidget: GLArea + public class GLWidget : GLArea { - private static int _GraphicsContextCount; private static bool _SharedContextInitialized = false; From c8ca1f33df27b53c172214f9a7a17f837c96e1b4 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:15:26 +0200 Subject: [PATCH 25/27] Remove obsolete and redundant double buffering assignment. --- src/OpenTK.GLWidget/GLWidget.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index 1e292e10..da6e580e 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -60,8 +60,6 @@ namespace OpenTK /// public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags graphicsContextFlags) { - this.DoubleBuffered = false; - GraphicsContextFlags = graphicsContextFlags; AddTickCallback(UpdateFrameTime); From 881b7553d992da58c2963ed2b4b1b2a286d96291 Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:16:45 +0200 Subject: [PATCH 26/27] Enable error checking for debug contexts. --- src/OpenTK.GLWidget/GLWidget.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index da6e580e..a31b3dad 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -256,6 +256,11 @@ namespace OpenTK // Create a dummy context that will grab the GdkGLContext that is current on the thread _GraphicsContext = new GraphicsContext(ContextHandle.Zero, null); + if (GraphicsContextFlags.HasFlag(GraphicsContextFlags.Debug)) + { + _GraphicsContext.ErrorChecking = true; + } + if (GraphicsContext.ShareContexts) { Interlocked.Increment(ref _GraphicsContextCount); From 9768febfabd19b1348a975c0f06e316f7127b70e Mon Sep 17 00:00:00 2001 From: Jarl Gullberg Date: Sun, 1 Oct 2017 20:35:04 +0200 Subject: [PATCH 27/27] Rename GraphicsContextFlags to ContextFlags and remove the setter. --- src/OpenTK.GLWidget/GLWidget.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenTK.GLWidget/GLWidget.cs b/src/OpenTK.GLWidget/GLWidget.cs index a31b3dad..49e45f90 100644 --- a/src/OpenTK.GLWidget/GLWidget.cs +++ b/src/OpenTK.GLWidget/GLWidget.cs @@ -31,9 +31,9 @@ namespace OpenTK public double DeltaTime { get; private set; } /// - /// The set for this widget. + /// The set for this widget. /// - public GraphicsContextFlags GraphicsContextFlags { get; set; } + public GraphicsContextFlags ContextFlags { get; } /// /// Initializes a new instance of the class. @@ -55,12 +55,12 @@ namespace OpenTK /// The which the widget should be constructed with. /// The major OpenGL version to attempt to initialize. /// The minor OpenGL version to attempt to initialize. - /// + /// /// Any flags which should be used during initialization of the . /// - public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags graphicsContextFlags) + public GLWidget(GraphicsMode graphicsMode, int glVersionMajor, int glVersionMinor, GraphicsContextFlags contextFlags) { - GraphicsContextFlags = graphicsContextFlags; + ContextFlags = contextFlags; AddTickCallback(UpdateFrameTime); SetRequiredVersion(glVersionMajor, glVersionMinor); @@ -115,8 +115,8 @@ namespace OpenTK GetRequiredVersion(out var major, out var minor); gdkGLContext.SetRequiredVersion(major, minor); - gdkGLContext.DebugEnabled = GraphicsContextFlags.HasFlag(GraphicsContextFlags.Debug); - gdkGLContext.ForwardCompatible = GraphicsContextFlags.HasFlag(GraphicsContextFlags.ForwardCompatible); + gdkGLContext.DebugEnabled = ContextFlags.HasFlag(GraphicsContextFlags.Debug); + gdkGLContext.ForwardCompatible = ContextFlags.HasFlag(GraphicsContextFlags.ForwardCompatible); gdkGLContext.Realize(); return gdkGLContext; @@ -256,7 +256,7 @@ namespace OpenTK // Create a dummy context that will grab the GdkGLContext that is current on the thread _GraphicsContext = new GraphicsContext(ContextHandle.Zero, null); - if (GraphicsContextFlags.HasFlag(GraphicsContextFlags.Debug)) + if (ContextFlags.HasFlag(GraphicsContextFlags.Debug)) { _GraphicsContext.ErrorChecking = true; }