Permalink
Browse files

Merge pull request #135 from thefiddler/xquartz

XQuartz support (X11 on Mac)
  • Loading branch information...
2 parents bc555ef + e39e4fb commit f889835dd51cb1b700459dd5f525e5f28b171d74 @thefiddler thefiddler committed Jun 17, 2014
@@ -11,7 +11,15 @@
<dllmap os="osx" dll="openal32.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="alut.dll" target="/System/Library/Frameworks/OpenAL.framework/OpenAL" />
<dllmap os="osx" dll="libGLES.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
+ <dllmap os="osx" dll="libGLESv1_CM.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="libGLESv2.dll" target="/System/Library/Frameworks/OpenGLES.framework/OpenGLES" />
<dllmap os="osx" dll="opencl.dll" target="/System/Library/Frameworks/OpenCL.framework/OpenCL"/>
<dllmap os="osx" dll="SDL2.dll" target="libSDL2.dylib"/>
+ <!-- XQuartz compatibility (X11 on Mac) -->
+ <dllmap os="osx" dll="libGL.so.1" target="/usr/X11/lib/libGL.dylib"/>
+ <dllmap os="osx" dll="libX11" target="/usr/X11/lib/libX11.dylib"/>
+ <dllmap os="osx" dll="libXcursor.so.1" target="/usr/X11/lib/libXcursor.dylib"/>
+ <dllmap os="osx" dll="libXi" target="/usr/X11/lib/libXi.dylib"/>
+ <dllmap os="osx" dll="libXinerama" target="/usr/X11/lib/libXinerama.dylib"/>
+ <dllmap os="osx" dll="libXrandr.so.2" target="/usr/X11/lib/libXrandr.dylib"/>
</configuration>
@@ -53,9 +53,9 @@ static Factory()
// Create regular platform backend
if (Configuration.RunningOnSdl2) Default = new SDL2.Sdl2Factory();
+ else if (Configuration.RunningOnX11) Default = new X11.X11Factory();
else if (Configuration.RunningOnWindows) Default = new Windows.WinFactory();
else if (Configuration.RunningOnMacOS) Default = new MacOS.MacOSFactory();
- else if (Configuration.RunningOnX11) Default = new X11.X11Factory();
else Default = new UnsupportedPlatform();
// Create embedded platform backend for EGL / OpenGL ES.
@@ -70,9 +70,9 @@ static Factory()
}
else if (Egl.Egl.IsSupported)
{
- if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory();
+ if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory();
+ else if (Configuration.RunningOnWindows) Embedded = new Egl.EglWinPlatformFactory();
else if (Configuration.RunningOnMacOS) Embedded = new Egl.EglMacPlatformFactory();
- else if (Configuration.RunningOnX11) Embedded = new Egl.EglX11PlatformFactory();
else Embedded = new UnsupportedPlatform();
}
else
@@ -344,9 +344,9 @@ internal static bool SupportsFunction(string name)
[DllImport(Library, EntryPoint = "glXQueryDrawable")]
public static extern ErrorCode QueryDrawable(IntPtr dpy, IntPtr drawable, GLXAttribute attribute, out int value);
-
+
[DllImport(Library, EntryPoint = "glXQueryExtension")]
- public static extern bool QueryExtension(IntPtr dpy, ref int errorBase, ref int eventBase);
+ public static extern bool QueryExtension(IntPtr dpy, out int errorBase, out int eventBase);
[DllImport(Library, EntryPoint = "glXQueryExtensionsString")]
static extern IntPtr QueryExtensionsStringInternal(IntPtr dpy, int screen);
@@ -356,6 +356,9 @@ public static string QueryExtensionsString(IntPtr dpy, int screen)
return Marshal.PtrToStringAnsi(QueryExtensionsStringInternal(dpy, screen));
}
+ [DllImport(Library, EntryPoint = "glXQueryVersion")]
+ public static extern bool QueryVersion(IntPtr dpy, out int major, out int minor);
+
[DllImport(Library, EntryPoint = "glXCreateContext")]
public static extern IntPtr CreateContext(IntPtr dpy, IntPtr vis, IntPtr shareList, bool direct);
@@ -54,14 +54,34 @@ static X11GLContext()
if (window == null)
throw new ArgumentNullException("window");
+ // Do not move this lower, as almost everything requires the Display
+ // property to be correctly set.
+ Display = ((X11WindowInfo)window).Display;
+
+ // Check that GLX is supported. We cannot proceed to create
+ // an OpenGL context without the GLX extension.
+ int error_base;
+ int event_base;
+ int glx_major;
+ int glx_minor;
+ using (new XLock(Display))
+ {
+ bool supported = Glx.QueryExtension(Display, out error_base, out event_base);
+ supported &= Glx.QueryVersion(Display, out glx_major, out glx_minor);
+ if (supported)
+ {
+ Debug.Print("[X11] GLX supported. Version is {0}.{1}", glx_major, glx_minor);
+ }
+ else
+ {
+ throw new NotSupportedException("[X11] GLX extension is not supported.");
+ }
+ }
+
Mode = ModeSelector.SelectGraphicsMode(
mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
- // Do not move this lower, as almost everything requires the Display
- // property to be correctly set.
- Display = ((X11WindowInfo)window).Display;
-
currentWindow = (X11WindowInfo)window;
currentWindow.VisualInfo = SelectVisual(Mode, currentWindow);
@@ -42,14 +42,14 @@ struct X11JoyDetails
public JoystickState State;
}
+ // Note: despite what the name says, this class is Linux-specific.
sealed class X11Joystick : IJoystickDriver2
{
#region Fields
readonly object sync = new object();
- readonly FileSystemWatcher watcher = new FileSystemWatcher(JoystickPath);
- readonly FileSystemWatcher watcher_legacy = new FileSystemWatcher(JoystickPathLegacy);
+ readonly FileSystemWatcher watcher = new FileSystemWatcher();
readonly Dictionary<int, int> index_to_stick = new Dictionary<int, int>();
List<JoystickDevice<X11JoyDetails>> sticks = new List<JoystickDevice<X11JoyDetails>>();
@@ -62,43 +62,38 @@ sealed class X11Joystick : IJoystickDriver2
public X11Joystick()
{
- watcher.Created += JoystickAdded;
- watcher.Deleted += JoystickRemoved;
- watcher.EnableRaisingEvents = true;
+ string path =
+ Directory.Exists(JoystickPath) ? JoystickPath :
+ Directory.Exists(JoystickPathLegacy) ? JoystickPathLegacy :
+ String.Empty;
- watcher_legacy.Created += JoystickAdded;
- watcher_legacy.Deleted += JoystickRemoved;
- watcher_legacy.EnableRaisingEvents = true;
+ if (!String.IsNullOrEmpty(path))
+ {
+ watcher.Path = path;
+
+ watcher.Created += JoystickAdded;
+ watcher.Deleted += JoystickRemoved;
+ watcher.EnableRaisingEvents = true;
- OpenJoysticks();
+ OpenJoysticks(path);
+ }
}
#endregion
#region Private Members
- void OpenJoysticks()
+ void OpenJoysticks(string path)
{
lock (sync)
{
- foreach (string file in Directory.GetFiles(JoystickPath))
- {
- JoystickDevice<X11JoyDetails> stick = OpenJoystick(file);
- if (stick != null)
- {
- //stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
- //number, stick.Axis.Count, stick.Button.Count, JoystickPath);
- sticks.Add(stick);
- }
- }
-
- foreach (string file in Directory.GetFiles(JoystickPathLegacy))
+ foreach (string file in Directory.GetFiles(path))
{
JoystickDevice<X11JoyDetails> stick = OpenJoystick(file);
if (stick != null)
{
//stick.Description = String.Format("USB Joystick {0} ({1} axes, {2} buttons, {3}{0})",
- //number, stick.Axis.Count, stick.Button.Count, JoystickPathLegacy);
+ //number, stick.Axis.Count, stick.Button.Count, path);
sticks.Add(stick);
}
}
@@ -447,6 +442,7 @@ void Dispose(bool manual)
{
}
+ watcher.Dispose();
foreach (JoystickDevice<X11JoyDetails> js in sticks)
{
CloseJoystick(js);

0 comments on commit f889835

Please sign in to comment.