From 5457651676b49a40f87054447317ee0f2700cdbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olle=20H=C3=A5kansson?= Date: Sat, 19 Apr 2014 13:36:44 +0200 Subject: [PATCH] Fixed swap interval. --- Source/OpenTK/OpenTK.csproj | 1 + Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs | 3 ++ .../MacOS/Cocoa/NSOpenGLContextParameter.cs | 23 +++++++++++ Source/OpenTK/Platform/MacOS/CocoaContext.cs | 41 ++++++++----------- 4 files changed, 45 insertions(+), 23 deletions(-) create mode 100755 Source/OpenTK/Platform/MacOS/Cocoa/NSOpenGLContextParameter.cs diff --git a/Source/OpenTK/OpenTK.csproj b/Source/OpenTK/OpenTK.csproj index 7aac63a1..f52bd3ed 100644 --- a/Source/OpenTK/OpenTK.csproj +++ b/Source/OpenTK/OpenTK.csproj @@ -815,6 +815,7 @@ + diff --git a/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs b/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs index e4b07364..8cd64eeb 100644 --- a/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs +++ b/Source/OpenTK/Platform/MacOS/Cocoa/Cocoa.cs @@ -35,6 +35,9 @@ namespace OpenTK.Platform.MacOS [DllImport(LibObjC, EntryPoint="objc_msgSend")] public extern static void SendVoid(IntPtr receiver, IntPtr selector, IntPtr intPtr1); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] + public extern static void SendVoid(IntPtr receiver, IntPtr selector, IntPtr intPtr1, int int1); + [DllImport(LibObjC, EntryPoint="objc_msgSend")] public extern static void SendVoid(IntPtr receiver, IntPtr selector, int int1); diff --git a/Source/OpenTK/Platform/MacOS/Cocoa/NSOpenGLContextParameter.cs b/Source/OpenTK/Platform/MacOS/Cocoa/NSOpenGLContextParameter.cs new file mode 100755 index 00000000..d313646e --- /dev/null +++ b/Source/OpenTK/Platform/MacOS/Cocoa/NSOpenGLContextParameter.cs @@ -0,0 +1,23 @@ +using System; + +namespace OpenTK.Platform.MacOS +{ + enum NSOpenGLContextParameter + { + [Obsolete] SwapRectangle = 200, + [Obsolete] SwapRectangleEnable = 201, + [Obsolete] RasterizationEnable = 221, + SwapInterval = 222, + SurfaceOrder = 235, + SurfaceOpacity = 236, + [Obsolete] StateValidation = 301, + SurfaceBackingSize = 304, // Lion + [Obsolete] SurfaceSurfaceVolatile = 306, + ReclaimResources = 308, // Lion + CurrentRendererID = 309, // Lion + GpuVertexProcessing = 310, // Lion + GpuFragmentProcessing = 311, // Lion + HasDrawable = 314, // Lion + MpsSwapsInFlight = 315, // Lion + } +} diff --git a/Source/OpenTK/Platform/MacOS/CocoaContext.cs b/Source/OpenTK/Platform/MacOS/CocoaContext.cs index 5100e972..45b9f323 100644 --- a/Source/OpenTK/Platform/MacOS/CocoaContext.cs +++ b/Source/OpenTK/Platform/MacOS/CocoaContext.cs @@ -179,32 +179,29 @@ namespace OpenTK } } -// private unsafe void SetContextValue (int val, NSOpenGLContextParameter par) -// { -// int *p = &val; -// context.SetValues ((IntPtr)p, par); -// } -// -// private unsafe int GetContextValue (NSOpenGLContextParameter par) -// { -// int ret; -// int *p = &ret; -// context.GetValues ((IntPtr)p, par); -// -// return ret; -// } + private unsafe void SetContextValue (int val, NSOpenGLContextParameter par) + { + int* p = &val; + Cocoa.SendVoid(Handle.Handle, Selector.Get("setValues:forParameter:"), (IntPtr)p, (int)par); + } + + private unsafe int GetContextValue (NSOpenGLContextParameter par) + { + int ret; + int* p = &ret; + Cocoa.SendVoid(Handle.Handle, Selector.Get("getValues:forParameter:"), (IntPtr)p, (int)par); + return ret; + } public override int SwapInterval { get { - return 0; - //return GetContextValue(NSOpenGLContextParameter.SwapInterval); + return GetContextValue(NSOpenGLContextParameter.SwapInterval); } set { - - //SetContextValue(value, NSOpenGLContextParameter.SwapInterval); + SetContextValue(value, NSOpenGLContextParameter.SwapInterval); } } @@ -232,12 +229,10 @@ namespace OpenTK Debug.Print("Disposing of Cocoa context."); - Cocoa.SendIntPtr(NSOpenGLContext, Selector.Get("clearCurrentContext")); + Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext")); + Cocoa.SendVoid(currentContext, Selector.Get("clearDrawable")); + Cocoa.SendVoid(currentContext, Selector.Get("release")); -// NSOpenGLContext.ClearCurrentContext(); -// context.ClearDrawable(); -// context.Dispose(); -// context = null; Handle = ContextHandle.Zero; IsDisposed = true;