Merge branch 'pr/101' into develop

This commit is contained in:
thefiddler 2014-04-24 13:45:17 +02:00
commit ef4cfbdd4b
27 changed files with 2677 additions and 29 deletions

View file

@ -16,7 +16,7 @@ namespace Examples.Tutorial
public class HelloGL3 : GameWindow
{
string vertexShaderSource = @"
#version 130
#version 140
precision highp float;
@ -37,7 +37,7 @@ void main(void)
}";
string fragmentShaderSource = @"
#version 130
#version 140
precision highp float;
@ -94,7 +94,7 @@ void main(void)
public HelloGL3()
: base(640, 480,
new GraphicsMode(), "OpenGL 3 Example", 0,
DisplayDevice.Default, 3, 0,
DisplayDevice.Default, 3, 2,
GraphicsContextFlags.ForwardCompatible | GraphicsContextFlags.Debug)
{ }

View file

@ -758,7 +758,6 @@
<Compile Include="Platform\SDL2\Sdl2Mouse.cs" />
<Compile Include="Platform\SDL2\Sdl2NativeWindow.cs" />
<Compile Include="Platform\SDL2\Sdl2WindowInfo.cs" />
<Compile Include="Platform\MacOS\Cgl.cs" />
<Compile Include="Platform\SDL2\Sdl2.cs" />
<Compile Include="Platform\Egl\EglSdl2PlatformFactory.cs" />
<Compile Include="Platform\SDL2\Sdl2JoystickDriver.cs" />
@ -803,6 +802,25 @@
<Compile Include="Input\HatPosition.cs" />
<Compile Include="Input\JoystickHatState.cs" />
<Compile Include="Input\KeyModifiers.cs" />
<Compile Include="Platform\MacOS\CocoaContext.cs" />
<Compile Include="Platform\MacOS\CocoaNativeWindow.cs" />
<Compile Include="Platform\MacOS\CocoaWindowInfo.cs" />
<Compile Include="Platform\MacOS\Cocoa\Cocoa.cs" />
<Compile Include="Platform\MacOS\Cocoa\Class.cs" />
<Compile Include="Platform\MacOS\Cocoa\Selector.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSApplication.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSApplicationActivationPolicy.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSBackingStore.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSWindowStyle.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSOpenGLPixelFormatAttribute.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSOpenGLProfile.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSOpenGLContextParameter.cs" />
<Compile Include="Platform\LegacyInputDriver.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSEventType.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSEventModifierMask.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSTrackingAreaOptions.cs" />
<Compile Include="Platform\MacOS\Cocoa\NSApplicationPresentationOptions.cs" />
<Compile Include="Platform\MacOS\CarbonBindings\Cgl.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
@ -832,4 +850,7 @@
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<Folder Include="Platform\MacOS\Cocoa\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,103 @@
#region License
//
// LegacyInputDriver.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using OpenTK.Input;
namespace OpenTK.Platform
{
// IInputDriver implementation to satisfy INativeWindow
// while reducing code duplication.
class LegacyInputDriver : IInputDriver
{
List<KeyboardDevice> dummy_keyboard_list = new List<KeyboardDevice>(1);
List<MouseDevice> dummy_mice_list = new List<MouseDevice>(1);
readonly LegacyJoystickDriver JoystickDriver = new LegacyJoystickDriver();
internal LegacyInputDriver()
{
dummy_mice_list.Add(new MouseDevice());
Mouse[0].Description = "Standard Mouse";
Mouse[0].NumberOfButtons = 3;
Mouse[0].NumberOfWheels = 1;
dummy_keyboard_list.Add(new KeyboardDevice());
Keyboard[0].Description = "Standard Keyboard";
Keyboard[0].NumberOfKeys = 101;
Keyboard[0].NumberOfLeds = 3;
Keyboard[0].NumberOfFunctionKeys = 12;
}
#region IInputDriver Members
public void Poll()
{
}
#endregion
#region IKeyboardDriver Members
public IList<KeyboardDevice> Keyboard
{
get { return dummy_keyboard_list; }
}
#endregion
#region IMouseDriver Members
public IList<MouseDevice> Mouse
{
get { return dummy_mice_list; }
}
#endregion
#region IJoystickDriver Members
public IList<JoystickDevice> Joysticks
{
get { return JoystickDriver.Joysticks; }
}
#endregion
#region IDisposable Members
public void Dispose()
{
}
#endregion
}
}

View file

@ -0,0 +1,143 @@
// #region License
//
// Cgl.cs
//
// Author:
// Stefanos A. <stapostol@gmail.com>
//
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// #endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.MacOS
{
using CGLPixelFormat = IntPtr;
using CGLContext = IntPtr;
static class Cgl
{
internal enum PixelFormatBool
{
None = 0,
AllRenderers = 1,
Doublebuffer = 5,
Stereo = 6,
AuxBuffers = 7,
MinimumPolicy = 51,
MaximumPolicy = 52,
Offscreen = 53,
AuxDepthStencil = 57,
ColorFloat = 58,
Multisample = 59,
Supersample = 60,
SampleALpha = 61,
SingleRenderer = 71,
NoRecovery = 72,
Accelerated = 73,
ClosestPolicy = 74,
BackingStore = 76,
Window = 80,
Compliant = 83,
PBuffer = 90,
RemotePBuffer = 91,
}
internal enum PixelFormatInt
{
ColorSize = 8,
AlphaSize = 11,
DepthSize = 12,
StencilSize = 13,
AccumSize = 14,
SampleBuffers = 55,
Samples = 56,
RendererID = 70,
DisplayMask = 84,
OpenGLProfile = 99,
VScreenCount = 128,
}
internal enum OpenGLProfileVersion
{
Legacy = 0x100,
Core3_2 = 0x3200,
}
internal enum ParameterNames
{
SwapInterval = 222,
}
internal enum Error
{
None = 0x000,
}
const string cgl = "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
const string cgs = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
[DllImport(cgl, EntryPoint = "CGLGetError")]
internal static extern Error GetError();
[DllImport(cgl, EntryPoint = "CGLErrorString")]
private static extern IntPtr CGLErrorString(Error code);
internal static string ErrorString(Error code)
{
return Marshal.PtrToStringAnsi(CGLErrorString(code));
}
[DllImport(cgl, EntryPoint = "CGLChoosePixelFormat")]
internal static extern Error ChoosePixelFormat(int []attribs, ref CGLPixelFormat format, ref int numPixelFormats);
[DllImport(cgl, EntryPoint = "CGLDescribePixelFormat")]
internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatInt attrib, out int value);
[DllImport(cgl, EntryPoint = "CGLDescribePixelFormat")]
internal static extern Error DescribePixelFormat(CGLPixelFormat pix, int pix_num, PixelFormatBool attrib, out bool value);
[DllImport(cgl, EntryPoint = "CGLGetPixelFormat")]
internal static extern CGLPixelFormat GetPixelFormat(CGLContext context);
[DllImport(cgl, EntryPoint = "CGLCreateContext")]
internal static extern Error CreateContext(CGLPixelFormat format, CGLContext share, ref CGLContext context);
[DllImport(cgl, EntryPoint = "CGLDestroyPixelFormat")]
internal static extern Error DestroyPixelFormat(CGLPixelFormat format);
[DllImport(cgl, EntryPoint = "CGLGetCurrentContext")]
internal static extern CGLContext GetCurrentContext();
[DllImport(cgl, EntryPoint = "CGLSetCurrentContext")]
internal static extern Error SetCurrentContext(CGLContext context);
[DllImport(cgl, EntryPoint = "CGLDestroyContext")]
internal static extern Error DestroyContext(CGLContext context);
[DllImport(cgl, EntryPoint = "CGLSetParameter")]
internal static extern Error SetParameter(CGLContext context, int parameter, ref int value);
[DllImport(cgl, EntryPoint = "CGLFlushDrawable")]
internal static extern Error FlushDrawable(CGLContext context);
[DllImport(cgl, EntryPoint = "CGLSetSurface")]
internal static extern Error SetSurface(CGLContext context, int conId, int winId, int surfId);
[DllImport(cgl, EntryPoint = "CGLUpdateContext")]
internal static extern Error UpdateContext(CGLContext context);
[DllImport(cgs, EntryPoint = "CGSMainConnectionID")]
internal static extern int MainConnectionID();
[DllImport(cgs, EntryPoint = "CGSGetSurfaceCount")]
internal static extern Error GetSurfaceCount(int conId, int winId, ref int count);
[DllImport(cgs, EntryPoint = "CGSGetSurfaceList")]
internal static extern Error GetSurfaceList(int conId, int winId, int count, ref int ids, ref int filled);
}
}

View file

@ -84,9 +84,18 @@ namespace OpenTK.Platform.MacOS.Carbon
[DllImport(appServices,EntryPoint="CGDisplayCapture")]
internal static extern CGDisplayErr DisplayCapture(IntPtr display);
[DllImport(appServices,EntryPoint="CGCaptureAllDisplays")]
internal static extern CGDisplayErr CaptureAllDisplays();
[DllImport(appServices,EntryPoint="CGShieldingWindowLevel")]
internal static extern uint ShieldingWindowLevel();
[DllImport(appServices,EntryPoint="CGDisplayRelease")]
internal static extern CGDisplayErr DisplayRelease(IntPtr display);
[DllImport(appServices,EntryPoint="CGReleaseAllDisplays")]
internal static extern CGDisplayErr DisplayReleaseAll();
[DllImport(appServices, EntryPoint = "CGDisplayAvailableModes")]
internal static extern IntPtr DisplayAvailableModes(IntPtr display);

View file

@ -1,16 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.MacOS
{
using CGLContextObj = IntPtr;
static class Cgl
{
const string lib = "/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
[DllImport(lib, EntryPoint = "CGLGetCurrentContext")]
public static extern CGLContextObj GetCurrentContext();
}
}

View file

@ -0,0 +1,91 @@
#region License
//
// Class.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
namespace OpenTK.Platform.MacOS
{
static class Class
{
[DllImport (Cocoa.LibObjC)]
extern static IntPtr class_getName(IntPtr handle);
[DllImport (Cocoa.LibObjC)]
extern static bool class_addMethod(IntPtr classHandle, IntPtr selector, IntPtr method, string types);
[DllImport (Cocoa.LibObjC)]
extern static IntPtr objc_getClass(string name);
[DllImport (Cocoa.LibObjC)]
extern static IntPtr objc_allocateClassPair(IntPtr parentClass, string name, int extraBytes);
[DllImport (Cocoa.LibObjC)]
extern static void objc_registerClassPair(IntPtr classToRegister);
public static IntPtr Get(string name)
{
var id = objc_getClass(name);
if (id == IntPtr.Zero)
{
throw new ArgumentException("Unknown class: " + name);
}
return id;
}
public static IntPtr AllocateClass(string className, string parentClass)
{
return objc_allocateClassPair(Get(parentClass), className, 0);
}
public static void RegisterClass(IntPtr handle)
{
objc_registerClassPair(handle);
}
static List<Delegate> storedDelegates = new List<Delegate>();
public static void RegisterMethod(IntPtr handle, Delegate d, string selector, string typeString)
{
// TypeString info:
// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html
IntPtr p = Marshal.GetFunctionPointerForDelegate(d);
bool r = class_addMethod(handle, Selector.Get(selector), p, typeString);
if (!r)
{
throw new ArgumentException("Could not register method " + d + " in class + " + class_getName(handle));
}
storedDelegates.Add(d); // Don't let the garbage collector eat our delegates.
}
}
}

View file

@ -0,0 +1,209 @@
#region License
//
// Cocoa.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System.Runtime.InteropServices;
using System;
using System.Drawing;
namespace OpenTK.Platform.MacOS
{
static class Cocoa
{
static readonly IntPtr selUTF8String = Selector.Get("UTF8String");
internal const string LibObjC = "/usr/lib/libobjc.dylib";
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, ulong ulong1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1, int int1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1, IntPtr intPtr2);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, IntPtr intPtr1, IntPtr intPtr2, IntPtr intPtr3);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, RectangleF rectangle1, int int1, int int2, bool bool1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, uint uint1, IntPtr intPtr1, IntPtr intPtr2, bool bool1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static IntPtr SendIntPtr(IntPtr receiver, IntPtr selector, RectangleF rectangle1, int int1, IntPtr intPtr1, IntPtr intPtr2);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static bool SendBool(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static bool SendBool(IntPtr receiver, IntPtr selector, int int1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, uint uint1);
[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, IntPtr intPtr1, IntPtr intPtr2);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, int int1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, bool bool1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, PointF point1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, RectangleF rect1, bool bool1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static int SendInt(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static uint SendUint(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static ushort SendUshort(IntPtr receiver, IntPtr selector);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static float SendFloat(IntPtr receiver, IntPtr selector);
[DllImport (LibObjC, EntryPoint="objc_msgSend")] // Not the _stret version, perhaps because a PointF fits in one register?
public extern static PointF SendPoint(IntPtr receiver, IntPtr selector);
[DllImport (LibObjC, EntryPoint="objc_msgSend_stret")]
extern static void SendRect(out System.Drawing.RectangleF retval, IntPtr receiver, IntPtr selector);
[DllImport (LibObjC, EntryPoint="objc_msgSend_stret")]
extern static void SendRect(out System.Drawing.RectangleF retval, IntPtr receiver, IntPtr selector, RectangleF rect1);
public static RectangleF SendRect(IntPtr receiver, IntPtr selector)
{
RectangleF r;
SendRect(out r, receiver, selector);
return r;
}
public static RectangleF SendRect(IntPtr receiver, IntPtr selector, RectangleF rect1)
{
RectangleF r;
SendRect(out r, receiver, selector, rect1);
return r;
}
public static IntPtr ToNSString(string str)
{
if (str == null)
return IntPtr.Zero;
unsafe
{
fixed (char* ptrFirstChar = str)
{
var handle = Cocoa.SendIntPtr(Class.Get("NSString"), Selector.Alloc);
handle = Cocoa.SendIntPtr(handle, Selector.Get("initWithCharacters:length:"), (IntPtr)ptrFirstChar, str.Length);
return handle;
}
}
}
public static string FromNSString(IntPtr handle)
{
return Marshal.PtrToStringAuto(SendIntPtr(handle, selUTF8String));
}
public static unsafe IntPtr ToNSImage(Image img)
{
using (System.IO.MemoryStream s = new System.IO.MemoryStream())
{
img.Save(s, System.Drawing.Imaging.ImageFormat.Png);
byte[] b = s.ToArray();
fixed (byte* pBytes = b)
{
IntPtr nsData = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSData"), Selector.Alloc),
Selector.Get("initWithBytes:length:"), (IntPtr)pBytes, b.Length),
Selector.Autorelease);
IntPtr nsImage = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSImage"), Selector.Alloc),
Selector.Get("initWithData:"), nsData),
Selector.Autorelease);
return nsImage;
}
}
}
public static IntPtr GetStringConstant(IntPtr handle, string symbol)
{
var indirect = NS.GetSymbol(handle, symbol);
if (indirect == IntPtr.Zero)
return IntPtr.Zero;
var actual = Marshal.ReadIntPtr(indirect);
if (actual == IntPtr.Zero)
return IntPtr.Zero;
return actual;
}
public static IntPtr AppKitLibrary;
public static IntPtr FoundationLibrary;
public static void Initialize()
{
if (AppKitLibrary != IntPtr.Zero)
{
return;
}
AppKitLibrary = NS.LoadLibrary("/System/Library/Frameworks/AppKit.framework/AppKit");
FoundationLibrary = NS.LoadLibrary("/System/Library/Frameworks/Foundation.framework/Foundation");
NSApplication.Initialize();
}
}
}

View file

@ -0,0 +1,68 @@
#region License
//
// NSApplication.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
using OpenTK.Platform.MacOS;
namespace OpenTK.Platform.MacOS
{
static class NSApplication
{
internal static IntPtr Handle;
internal static IntPtr AutoreleasePool;
internal static void Initialize()
{
// Create the NSAutoreleasePool
AutoreleasePool = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSAutoreleasePool"), Selector.Alloc), Selector.Init);
// Fetch the application handle
Handle = Cocoa.SendIntPtr(Class.Get("NSApplication"), Selector.Get("sharedApplication"));
// Setup the application
Cocoa.SendBool(Handle, Selector.Get("setActivationPolicy:"), (int)NSApplicationActivationPolicy.Regular);
Cocoa.SendVoid(Handle, Selector.Get("activateIgnoringOtherApps:"), true);
// Create the menu bar
var menubar = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenu"), Selector.Alloc),
Selector.Autorelease);
var menuItem = Cocoa.SendIntPtr(Cocoa.SendIntPtr(Class.Get("NSMenuItem"), Selector.Alloc),
Selector.Autorelease);
// Add menu item to bar, and bar to application
Cocoa.SendIntPtr(menubar, Selector.Get("addItem:"), menuItem);
Cocoa.SendIntPtr(Handle, Selector.Get("setMainMenu:"), menubar);
// Tell cocoa we're ready to run the application (usually called by [NSApp run]).
Cocoa.SendVoid(Handle, Selector.Get("finishLaunching"));
}
}
}

View file

@ -0,0 +1,38 @@
#region License
//
// NSApplicationActivationPolicy.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.MacOS
{
enum NSApplicationActivationPolicy
{
Regular,
Accessory,
Prohibited,
}
}

View file

@ -0,0 +1,48 @@
#region License
//
// NSApplicationPresentationOptions.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.MacOS
{
enum NSApplicationPresentationOptions
{
Default = 0,
AutoHideDock = 1,
HideDock = 2,
AutoHideMenuBar = 4,
HideMenuBar = 8,
DisableAppleMenu = 16,
DisableProcessSwitching = 32,
DisableForceQuit = 64,
DisableSessionTermination = 128,
DisableHideApplication = 256,
DisableMenuBarTransparency = 512,
FullScreen = 1024,
AutoHideToolbar = 2048,
}
}

View file

@ -0,0 +1,38 @@
#region License
//
// NSBackingStore.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.MacOS
{
enum NSBackingStore
{
Retained,
Nonretained,
Buffered,
}
}

View file

@ -0,0 +1,47 @@
#region License
//
// NSEventModifierMask.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK.Platform.MacOS
{
[Flags]
enum NSEventModifierMask : uint
{
AlphaShiftKeyMask = 65536U,
ShiftKeyMask = 131072U,
ControlKeyMask = 262144U,
AlternateKeyMask = 524288U,
CommandKeyMask = 1048576U,
NumericPadKeyMask = 2097152U,
HelpKeyMask = 4194304U,
FunctionKeyMask = 8388608U,
DeviceIndependentModifierFlagsMask = 4294901760U,
}
}

View file

@ -0,0 +1,66 @@
#region License
//
// NSEventType.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.MacOS
{
enum NSEventType
{
LeftMouseDown = 1,
LeftMouseUp = 2,
RightMouseDown = 3,
RightMouseUp = 4,
MouseMoved = 5,
LeftMouseDragged = 6,
RightMouseDragged = 7,
MouseEntered = 8,
MouseExited = 9,
KeyDown = 10,
KeyUp = 11,
FlagsChanged = 12,
AppKitDefined = 13,
SystemDefined = 14,
ApplicationDefined = 15,
Periodic = 16,
CursorUpdate = 17,
Rotate = 18,
BeginGesture = 19,
EndGesture = 20,
ScrollWheel = 22,
TabletPoint = 23,
TabletProximity = 24,
OtherMouseDown = 25,
OtherMouseUp = 26,
OtherMouseDragged = 27,
Gesture = 29,
Magnify = 30,
Swipe = 31,
SmartMagnify = 32,
QuickLook = 33,
}
}

View file

@ -0,0 +1,52 @@
#region License
//
// NSOpenGLContextParameter.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
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
}
}

View file

@ -0,0 +1,76 @@
#region License
//
// NSOpenGLPixelFormatAttribute.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK.Platform.MacOS
{
enum NSOpenGLPixelFormatAttribute
{
AllRenderers = 1,
TrippleBuffer = 3, // Lion
DoubleBuffer = 5,
Stereo = 6,
AuxBuffers = 7,
ColorSize = 8,
AlphaSize = 11,
DepthSize = 12,
StencilSize = 13,
AccumSize = 14,
MinimumPolicy = 51,
MaximumPolicy = 52,
OffScreen = 53,
FullScreen = 54,
SampleBuffers = 55,
Samples = 56,
AuxDepthStencil = 57,
ColorFloat = 58,
Multisample = 59,
Supersample = 60,
SampleAlpha = 61,
RendererID = 70,
SingleRenderer = 71,
NoRecovery = 72,
Accelerated = 73,
ClosestPolicy = 74,
[Obsolete] Robust = 75,
BackingStore = 76,
[Obsolete] MPSafe = 78,
Window = 80,
[Obsolete] MultiScreen = 81,
Compliant = 83,
ScreenMask = 84,
PixelBuffer = 90,
RemotePixelBuffer = 91,
AllowOfflineRenderers = 96,
AcceleratedCompute = 97,
OpenGLProfile = 99, // Lion
VirtualScreenCount = 128,
}
}

View file

@ -0,0 +1,37 @@
#region License
//
// NSOpenGLProfile.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
namespace OpenTK.Platform.MacOS
{
enum NSOpenGLProfile
{
VersionLegacy = 4096,
Version3_2Core = 12800,
}
}

View file

@ -0,0 +1,48 @@
#region License
//
// NSTrackingAreaOptions.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK.Platform.MacOS
{
[Flags]
enum NSTrackingAreaOptions
{
MouseEnteredAndExited = 1,
MouseMoved = 2,
CursorUpdate = 4,
ActiveWhenFirstResponder = 16,
ActiveInKeyWindow = 32,
ActiveInActiveApp = 64,
ActiveAlways = 128,
AssumeInside = 256,
InVisibleRect = 512,
EnabledDuringMouseDrag = 1024,
}
}

View file

@ -0,0 +1,51 @@
#region License
//
// NSWindowStyle.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
namespace OpenTK.Platform.MacOS
{
[Flags]
enum NSWindowStyle
{
Borderless = 0,
Titled = 1,
Closable = 2,
Miniaturizable = 4,
Resizable = 8,
Utility = 16,
DocModal = 64,
NonactivatingPanel = 128,
TexturedBackground = 256,
Unscaled = 2048,
UnifiedTitleAndToolbar = 4096,
Hud = 8192,
FullScreenWindow = 16384,
}
}

View file

@ -0,0 +1,47 @@
#region License
//
// Selector.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Runtime.InteropServices;
namespace OpenTK.Platform.MacOS
{
static class Selector
{
// Frequently used selectors
public static readonly IntPtr Init = Selector.Get("init");
public static readonly IntPtr InitWithCoder = Selector.Get("initWithCoder:");
public static readonly IntPtr Alloc = Selector.Get("alloc");
public static readonly IntPtr Release = Selector.Get("release");
public static readonly IntPtr Autorelease = Selector.Get("autorelease");
[DllImport ("/usr/lib/libobjc.dylib", EntryPoint="sel_registerName")]
public extern static IntPtr Get(string name);
}
}

View file

@ -0,0 +1,308 @@
#region License
//
// CocoaContext.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using OpenTK.Platform;
using OpenTK.Graphics;
using OpenTK.Platform.MacOS;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace OpenTK
{
class CocoaContext : DesktopGraphicsContext
{
private CocoaWindowInfo cocoaWindow;
private IntPtr shareContextRef;
static readonly IntPtr NSOpenGLContext = Class.Get("NSOpenGLContext");
static readonly IntPtr selCurrentContext = Selector.Get("currentContext");
static readonly IntPtr selFlushBuffer = Selector.Get("flushBuffer");
static readonly IntPtr selMakeCurrentContext = Selector.Get("makeCurrentContext");
static readonly IntPtr selUpdate = Selector.Get("update");
static CocoaContext()
{
Cocoa.Initialize();
}
public CocoaContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, int majorVersion, int minorVersion)
{
Debug.Print("Context Type: {0}", shareContext);
Debug.Print("Window info: {0}", window);
cocoaWindow = (CocoaWindowInfo)window;
if (shareContext is CocoaContext)
shareContextRef = ((CocoaContext)shareContext).Handle.Handle;
if (shareContext is GraphicsContext)
{
ContextHandle shareHandle = shareContext != null ? (shareContext as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
shareContextRef = shareHandle.Handle;
}
if (shareContextRef == IntPtr.Zero)
{
Debug.Print("No context sharing will take place.");
}
CreateContext(mode, cocoaWindow, shareContextRef, majorVersion, minorVersion, true);
}
public CocoaContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, int majorVersion, int minorVersion)
{
if (handle == ContextHandle.Zero)
throw new ArgumentException("handle");
if (window == null)
throw new ArgumentNullException("window");
Handle = handle;
cocoaWindow = (CocoaWindowInfo)window;
}
private void AddPixelAttrib(List<NSOpenGLPixelFormatAttribute> attributes, NSOpenGLPixelFormatAttribute attribute)
{
Debug.Print(attribute.ToString());
attributes.Add(attribute);
}
private void AddPixelAttrib(List<NSOpenGLPixelFormatAttribute> attributes, NSOpenGLPixelFormatAttribute attribute, int value)
{
Debug.Print("{0} : {1}", attribute, value);
attributes.Add(attribute);
attributes.Add((NSOpenGLPixelFormatAttribute)value);
}
private void CreateContext(GraphicsMode mode, CocoaWindowInfo cocoaWindow, IntPtr shareContextRef, int majorVersion, int minorVersion, bool fullscreen)
{
// Prepare attributes
List<NSOpenGLPixelFormatAttribute> attributes = new List<NSOpenGLPixelFormatAttribute>();
var profile = NSOpenGLProfile.VersionLegacy;
if (majorVersion > 3 || (majorVersion == 3 && minorVersion >= 2))
{
profile = NSOpenGLProfile.Version3_2Core;
Debug.Print("Running the OpenGL core profile.");
}
else
{
Debug.Print("Running the legacy OpenGL profile. Start with version major=3, minor=2 or later for the 3.2 profile.");
}
Debug.Print("NSGL pixel format attributes:");
Debug.Indent();
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.OpenGLProfile, (int)profile);
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DoubleBuffer);
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Accelerated);
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.ColorSize, mode.ColorFormat.BitsPerPixel);
if (mode.Depth > 0)
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.DepthSize, mode.Depth);
if (mode.Stencil > 0)
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.StencilSize, mode.Stencil);
if (mode.AccumulatorFormat.BitsPerPixel > 0)
{
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.AccumSize, mode.AccumulatorFormat.BitsPerPixel);
}
if (mode.Samples > 1)
{
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.SampleBuffers, 1);
AddPixelAttrib(attributes, NSOpenGLPixelFormatAttribute.Samples, mode.Samples);
}
AddPixelAttrib(attributes, (NSOpenGLPixelFormatAttribute)0);
Debug.Unindent();
Debug.Write("Attribute array: ");
for (int i = 0; i < attributes.Count; i++)
Debug.Write(attributes[i].ToString() + " ");
Debug.WriteLine("");
// Create pixel format
var pixelFormat = Cocoa.SendIntPtr(Class.Get("NSOpenGLPixelFormat"), Selector.Alloc);
unsafe
{
fixed (NSOpenGLPixelFormatAttribute* ptr = attributes.ToArray())
{
pixelFormat = Cocoa.SendIntPtr(pixelFormat, Selector.Get("initWithAttributes:"), (IntPtr)ptr);
}
}
// Create context
var context = Cocoa.SendIntPtr(NSOpenGLContext, Selector.Alloc);
context = Cocoa.SendIntPtr(context, Selector.Get("initWithFormat:shareContext:"), pixelFormat, shareContextRef);
// Release pixel format
Cocoa.SendVoid(pixelFormat, Selector.Release);
pixelFormat = IntPtr.Zero;
// Attach the view
Cocoa.SendVoid(context, Selector.Get("setView:"), cocoaWindow.ViewHandle);
Cocoa.SendVoid(cocoaWindow.ViewHandle, Selector.Get("setWantsBestResolutionOpenGLSurface:"), true);
// Finalize
Handle = new ContextHandle(context);
Mode = GetGraphicsMode(context);
Update(cocoaWindow);
MakeCurrent(cocoaWindow);
}
private GraphicsMode GetGraphicsMode(IntPtr context)
{
IntPtr cgl_context = Cocoa.SendIntPtr(context, Selector.Get("CGLContextObj"));
IntPtr cgl_format = Cgl.GetPixelFormat(cgl_context);
int id = 0; // CGL does not support the concept of a pixel format id
int color, depth, stencil, samples, accum;
bool doublebuffer, stereo;
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatInt.ColorSize, out color);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatInt.DepthSize, out depth);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatInt.StencilSize, out stencil);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatInt.Samples, out samples);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatInt.AccumSize, out accum);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatBool.Doublebuffer, out doublebuffer);
Cgl.DescribePixelFormat(cgl_format, 0, Cgl.PixelFormatBool.Stereo, out stereo);
return new GraphicsMode((IntPtr)id, color, depth, stencil, samples, accum, doublebuffer ? 2 : 1, stereo);
}
public override void SwapBuffers()
{
Cocoa.SendVoid(Handle.Handle, selFlushBuffer);
}
public override void MakeCurrent(IWindowInfo window)
{
Cocoa.SendVoid(Handle.Handle, selMakeCurrentContext);
}
public override bool IsCurrent
{
get
{
return Handle.Handle == CurrentContext;
}
}
public static IntPtr CurrentContext
{
get
{
return Cocoa.SendIntPtr(NSOpenGLContext, selCurrentContext);
}
}
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 GetContextValue(NSOpenGLContextParameter.SwapInterval);
}
set
{
SetContextValue(value, NSOpenGLContextParameter.SwapInterval);
}
}
public override void Update(IWindowInfo window)
{
Cocoa.SendVoid(Handle.Handle, selUpdate);
}
#region IDisposable Members
~CocoaContext()
{
Dispose(false);
}
public override void Dispose()
{
Dispose(true);
}
void Dispose(bool disposing)
{
if (IsDisposed || Handle.Handle == IntPtr.Zero)
return;
Debug.Print("Disposing of Cocoa context.");
Cocoa.SendVoid(NSOpenGLContext, Selector.Get("clearCurrentContext"));
Cocoa.SendVoid(Handle.Handle, Selector.Get("clearDrawable"));
Cocoa.SendVoid(Handle.Handle, Selector.Get("release"));
Handle = ContextHandle.Zero;
IsDisposed = true;
}
#endregion
#region IGraphicsContextInternal Members
public override IntPtr GetAddress(string function)
{
return NS.GetAddress(function);
}
public override IntPtr GetAddress(IntPtr function)
{
return NS.GetAddress(function);
}
#endregion
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,114 @@
#region License
//
// CocoaWindowInfo.cs
//
// Author:
// Olle Håkansson <ollhak@gmail.com>
//
// Copyright (c) 2014 Olle Håkansson
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace OpenTK.Platform.MacOS
{
/// \internal
/// <summary>
/// Describes a Cocoa window.
/// </summary>
sealed class CocoaWindowInfo : IWindowInfo
{
IntPtr nsWindowRef;
bool disposed = false;
#region Constructors
/// <summary>
/// Constructs a new instance with the specified parameters.
/// </summary>
/// <param name="nsWindowRef">A valid NSView reference.</param>
public CocoaWindowInfo(IntPtr nsWindowRef)
{
this.nsWindowRef = nsWindowRef;
}
#endregion
#region Public Members
/// <summary>
/// Gets the window reference for this instance.
/// </summary>
public IntPtr Handle { get { return nsWindowRef; } }
/// <summary>
/// Gets the view reference for this instance.
/// </summary>
public IntPtr ViewHandle
{
get
{
return CocoaNativeWindow.GetView(nsWindowRef);
}
}
/// <summary>Returns a System.String that represents the current window.</summary>
/// <returns>A System.String that represents the current window.</returns>
public override string ToString()
{
return String.Format("MacOS.CocoaWindowInfo: NSWindow {0}", nsWindowRef);
}
#endregion
#region IDisposable Members
public void Dispose()
{
Dispose(true);
}
void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
}
disposed = true;
}
~CocoaWindowInfo()
{
Dispose(false);
}
#endregion
}
}

View file

@ -43,7 +43,7 @@ namespace OpenTK.Platform.MacOS
public override INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
{
return new CarbonGLNative(x, y, width, height, title, mode, options, device);
return new CocoaNativeWindow(x, y, width, height, title, mode, options, device);
}
public override IDisplayDeviceDriver CreateDisplayDeviceDriver()
@ -53,19 +53,19 @@ namespace OpenTK.Platform.MacOS
public override IGraphicsContext CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{
return new AglContext(mode, window, shareContext);
return new CocoaContext(mode, window, shareContext, major, minor);
}
public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
{
return new AglContext(handle, window, shareContext);
return new CocoaContext(handle, window, shareContext, major, minor);
}
public override GraphicsContext.GetCurrentContextDelegate CreateGetCurrentGraphicsContext()
{
return (GraphicsContext.GetCurrentContextDelegate)delegate
{
return new ContextHandle(Cgl.GetCurrentContext());
return new ContextHandle(CocoaContext.CurrentContext);
};
}

View file

@ -48,6 +48,12 @@ namespace OpenTK.Platform.MacOS
static extern IntPtr NSLookupAndBindSymbol(IntPtr s);
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
[DllImport(Library)]
private static extern IntPtr dlopen(String fileName, int flags);
[DllImport(Library)]
private static extern int dlclose(IntPtr handle);
[DllImport (Library)]
private static extern IntPtr dlsym (IntPtr handle, string symbol);
public static IntPtr GetAddress(string function)
{
@ -87,6 +93,22 @@ namespace OpenTK.Platform.MacOS
}
return symbol;
}
public static IntPtr GetSymbol(IntPtr handle, string symbol)
{
return dlsym(handle, symbol);
}
public static IntPtr LoadLibrary(string fileName)
{
const int RTLD_NOW = 2;
return dlopen(fileName, RTLD_NOW);
}
public static void FreeLibrary(IntPtr handle)
{
dlclose(handle);
}
}
}

View file

@ -161,10 +161,10 @@ namespace OpenTK.Platform.MacOS
if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel && System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
{
if (displaysCaptured.Contains(display) == false)
{
CG.DisplayCapture(display);
}
// if (displaysCaptured.Contains(display) == false)
// {
// CG.DisplayCapture(display);
// }
Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);
@ -186,7 +186,7 @@ namespace OpenTK.Platform.MacOS
Debug.Print("Restoring resolution.");
CG.DisplaySwitchToMode(display, storedModes[display]);
CG.DisplayRelease(display);
//CG.DisplayRelease(display);
displaysCaptured.Remove(display);
return true;

View file

@ -293,6 +293,20 @@ namespace OpenTK.Platform
#endregion
#region CreateMacOSWindowInfo
/// <summary>
/// Creates an IWindowInfo instance for the Mac OS X platform.
/// </summary>
/// <param name="windowHandle">The handle of the NSWindow.</param>
/// <returns>A new IWindowInfo instance.</returns>
public static IWindowInfo CreateMacOSWindowInfo(IntPtr windowHandle)
{
return new OpenTK.Platform.MacOS.CocoaWindowInfo(windowHandle);
}
#endregion
#region CreateDummyWindowInfo
/// <summary>