[X11] Correct Glx.*.SwapInterval definitions

Improved error checking means we are no longer crashing when
SwapInterval is not available.
This commit is contained in:
thefiddler 2014-05-12 14:50:03 +02:00
parent 88905cb6aa
commit 4e8786f123
2 changed files with 41 additions and 34 deletions

View file

@ -134,6 +134,8 @@ namespace OpenTK.Platform.X11
LEVEL = 3, LEVEL = 3,
CONFIG_CAVEAT = 0x20, CONFIG_CAVEAT = 0x20,
RENDER_TYPE_SGIX = 0x8011, RENDER_TYPE_SGIX = 0x8011,
SWAP_INTERVAL_EXT = 0x20F1,
MAX_SWAP_INTERVAL_EXT = 0x20F2,
} }
enum GLXHyperpipeAttrib : int enum GLXHyperpipeAttrib : int
@ -270,19 +272,15 @@ namespace OpenTK.Platform.X11
0x67, 0x6c, 0x58, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x73, 0x41, 0x52, 0x42, 0, 0x67, 0x6c, 0x58, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x73, 0x41, 0x52, 0x42, 0,
// glXSwapIntervalEXT // glXSwapIntervalEXT
0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x45, 0x58, 0x54, 0, 0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x45, 0x58, 0x54, 0,
// glXGetSwapIntervalEXT
0x67, 0x6c, 0x58, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x45, 0x58, 0x54, 0,
// glXSwapIntervalMESA // glXSwapIntervalMESA
0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x45, 0x53, 0x41, 0, 0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x45, 0x53, 0x41, 0,
// glXGetSwapIntervalMESA // glXGetSwapIntervalMESA
0x67, 0x6c, 0x58, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x45, 0x53, 0x41, 0, 0x67, 0x6c, 0x58, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x45, 0x53, 0x41, 0,
// glXSwapIntervalSGI // glXSwapIntervalSGI
0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x53, 0x47, 0x49, 0, 0x67, 0x6c, 0x58, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x53, 0x47, 0x49, 0,
// glXGetSwapIntervalSGI
0x67, 0x6c, 0x58, 0x47, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x53, 0x47, 0x49, 0,
}; };
static readonly int[] EntryPointOffsets = new int[7]; static readonly int[] EntryPointOffsets = new int[5];
static IntPtr[] EntryPoints = new IntPtr[7]; static IntPtr[] EntryPoints = new IntPtr[5];
internal Glx() internal Glx()
{ {
@ -322,8 +320,6 @@ namespace OpenTK.Platform.X11
{ {
for (int i = 0; i < _EntryPointsInstance.Length; i++) for (int i = 0; i < _EntryPointsInstance.Length; i++)
{ {
System.Diagnostics.Debug.WriteLine(Marshal.PtrToStringAnsi(
new IntPtr(name + _EntryPointNameOffsetsInstance[i])));
_EntryPointsInstance[i] = Arb.GetProcAddress( _EntryPointsInstance[i] = Arb.GetProcAddress(
new IntPtr(name + _EntryPointNameOffsetsInstance[i])); new IntPtr(name + _EntryPointNameOffsetsInstance[i]));
} }
@ -346,6 +342,9 @@ namespace OpenTK.Platform.X11
[DllImport(Library, EntryPoint = "glXIsDirect")] [DllImport(Library, EntryPoint = "glXIsDirect")]
public static extern bool IsDirect(IntPtr dpy, IntPtr context); public static extern bool IsDirect(IntPtr dpy, IntPtr context);
[DllImport(Library, EntryPoint = "glXQueryDrawable")]
public static extern ErrorCode QueryDrawable(IntPtr dpy, IntPtr drawable, GLXAttribute attribute, out int value);
[DllImport(Library, EntryPoint = "glXQueryExtension")] [DllImport(Library, EntryPoint = "glXQueryExtension")]
public static extern bool QueryExtension(IntPtr dpy, ref int errorBase, ref int eventBase); public static extern bool QueryExtension(IntPtr dpy, ref int errorBase, ref int eventBase);
@ -461,13 +460,7 @@ namespace OpenTK.Platform.X11
public partial class Ext public partial class Ext
{ {
[AutoGenerated(EntryPoint = "glXSwapIntervalEXT")] [AutoGenerated(EntryPoint = "glXSwapIntervalEXT")]
public static ErrorCode SwapInterval(int interval) public static ErrorCode SwapInterval(IntPtr display, IntPtr drawable, int interval)
{
throw new NotImplementedException();
}
[AutoGenerated(EntryPoint = "glXGetSwapIntervalEXT")]
public static int GetSwapInterval()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -495,12 +488,6 @@ namespace OpenTK.Platform.X11
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
[AutoGenerated(EntryPoint = "glXGetSwapIntervalSGI")]
public static int GetSwapInterval()
{
throw new NotImplementedException();
}
} }
[Slot(0)] [Slot(0)]
@ -508,22 +495,16 @@ namespace OpenTK.Platform.X11
internal unsafe static extern IntPtr glXCreateContextAttribsARB(IntPtr display, IntPtr fbconfig, IntPtr share_context, bool direct, int* attribs); internal unsafe static extern IntPtr glXCreateContextAttribsARB(IntPtr display, IntPtr fbconfig, IntPtr share_context, bool direct, int* attribs);
[Slot(1)] [Slot(1)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern ErrorCode glXSwapIntervalEXT(int interval); internal static extern ErrorCode glXSwapIntervalEXT(IntPtr display, IntPtr drawable, int interval);
[Slot(2)] [Slot(2)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int glXGetSwapIntervalEXT(); internal static extern ErrorCode glXSwapIntervalMESA(int interval);
[Slot(3)] [Slot(3)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern ErrorCode glXSwapIntervalMESA(int interval); internal static extern int glXGetSwapIntervalMESA();
[Slot(4)] [Slot(4)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)] [DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int glXGetSwapIntervalMESA();
[Slot(5)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern ErrorCode glXSwapIntervalSGI(int interval); internal static extern ErrorCode glXSwapIntervalSGI(int interval);
[Slot(6)]
[DllImport(Library, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
internal static extern int glXGetSwapIntervalSGI();
#endregion #endregion
} }

View file

@ -363,20 +363,40 @@ namespace OpenTK.Platform.X11
{ {
get get
{ {
if (currentWindow == null)
{
Debug.Print("Context must be current");
throw new InvalidOperationException();
}
using (new XLock(display)) using (new XLock(display))
{ {
if (vsync_ext_supported) if (vsync_ext_supported)
return Glx.Ext.GetSwapInterval(); {
int value;
Glx.QueryDrawable(Display, currentWindow.Handle, GLXAttribute.SWAP_INTERVAL_EXT, out value);
return value;
}
else if (vsync_mesa_supported) else if (vsync_mesa_supported)
{
return Glx.Mesa.GetSwapInterval(); return Glx.Mesa.GetSwapInterval();
}
else if (vsync_sgi_supported) else if (vsync_sgi_supported)
{
return sgi_swap_interval; return sgi_swap_interval;
else }
return 0; return 0;
} }
} }
set set
{ {
if (currentWindow == null)
{
Debug.Print("Context must be current");
throw new InvalidOperationException();
}
if (value < 0 && !vsync_tear_supported) if (value < 0 && !vsync_tear_supported)
{ {
value = 1; value = 1;
@ -386,12 +406,18 @@ namespace OpenTK.Platform.X11
using (new XLock(Display)) using (new XLock(Display))
{ {
if (vsync_ext_supported) if (vsync_ext_supported)
error_code = Glx.Ext.SwapInterval(value); {
Glx.Ext.SwapInterval(Display, currentWindow.Handle, value);
}
else if (vsync_mesa_supported) else if (vsync_mesa_supported)
{
error_code = Glx.Mesa.SwapInterval(value); error_code = Glx.Mesa.SwapInterval(value);
}
else if (vsync_sgi_supported) else if (vsync_sgi_supported)
{
error_code = Glx.Sgi.SwapInterval(value); error_code = Glx.Sgi.SwapInterval(value);
} }
}
if (error_code == X11.ErrorCode.NO_ERROR) if (error_code == X11.ErrorCode.NO_ERROR)
sgi_swap_interval = value; sgi_swap_interval = value;