mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 06:15:29 +00:00
* Platform/X11/X11GLContext.cs: Added workaround for buggy Amd linux drivers. Added "None" to context attributes, as specified by the specs.
This commit is contained in:
parent
94b70b7bb7
commit
c7b9c7f0c5
|
@ -10,7 +10,6 @@ using System.Text;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using OpenTK.Graphics.OpenGL;
|
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
|
||||||
namespace OpenTK.Platform.X11
|
namespace OpenTK.Platform.X11
|
||||||
|
@ -59,7 +58,7 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
if (!glx_loaded)
|
if (!glx_loaded)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Loading GLX extensions.");
|
Debug.WriteLine("Creating temporary context to load GLX extensions.");
|
||||||
|
|
||||||
// Create a temporary context to obtain the necessary function pointers.
|
// Create a temporary context to obtain the necessary function pointers.
|
||||||
XVisualInfo visual = currentWindow.VisualInfo;
|
XVisualInfo visual = currentWindow.VisualInfo;
|
||||||
|
@ -71,7 +70,7 @@ namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
Glx.LoadAll();
|
Glx.LoadAll();
|
||||||
Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
|
Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
|
||||||
Glx.DestroyContext(currentWindow.Display, ctx);
|
//Glx.DestroyContext(currentWindow.Display, ctx);
|
||||||
glx_loaded = true;
|
glx_loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -79,9 +78,12 @@ namespace OpenTK.Platform.X11
|
||||||
// Try using the new context creation method. If it fails, fall back to the old one.
|
// Try using the new context creation method. If it fails, fall back to the old one.
|
||||||
// For each of these methods, we try two times to create a context:
|
// For each of these methods, we try two times to create a context:
|
||||||
// one with the "direct" flag intact, the other with the flag inversed.
|
// one with the "direct" flag intact, the other with the flag inversed.
|
||||||
if (Glx.Delegates.glXCreateContextAttribsARB != null)
|
// HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
|
||||||
|
// GLX_ARB_create_context, including hideous input lag, no vsync and other. Use legacy context
|
||||||
|
// creation if the user doesn't request a 3.0+ context.
|
||||||
|
if ((major * 10 + minor >= 30) && Glx.Delegates.glXCreateContextAttribsARB != null)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Using GLX_ARB_create_context...");
|
Debug.Write("Using GLX_ARB_create_context... ");
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
|
@ -102,13 +104,22 @@ namespace OpenTK.Platform.X11
|
||||||
attributes.Add((int)ArbCreateContext.Flags);
|
attributes.Add((int)ArbCreateContext.Flags);
|
||||||
attributes.Add((int)flags);
|
attributes.Add((int)flags);
|
||||||
}
|
}
|
||||||
|
attributes.Add(0);
|
||||||
|
|
||||||
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
||||||
shareHandle.Handle, direct, attributes.ToArray()));
|
shareHandle.Handle, direct, attributes.ToArray()));
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (context == ContextHandle.Zero)
|
||||||
|
{
|
||||||
|
Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
|
||||||
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
context = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
|
||||||
shareHandle.Handle, !direct, attributes.ToArray()));
|
shareHandle.Handle, !direct, attributes.ToArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context == ContextHandle.Zero)
|
||||||
|
Debug.WriteLine("failed.");
|
||||||
|
else
|
||||||
|
Debug.WriteLine("success!");
|
||||||
|
|
||||||
Functions.XFree((IntPtr)fbconfigs);
|
Functions.XFree((IntPtr)fbconfigs);
|
||||||
}
|
}
|
||||||
|
@ -117,19 +128,25 @@ namespace OpenTK.Platform.X11
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (context == ContextHandle.Zero)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Using legacy context creation.");
|
Debug.Write("Using legacy context creation... ");
|
||||||
|
|
||||||
XVisualInfo info = currentWindow.VisualInfo; // Cannot pass a Property by reference.
|
XVisualInfo info = currentWindow.VisualInfo; // Cannot pass a Property by reference.
|
||||||
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));
|
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));
|
||||||
|
|
||||||
if (context == ContextHandle.Zero)
|
if (context == ContextHandle.Zero)
|
||||||
|
{
|
||||||
|
Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
|
||||||
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
|
context = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context != ContextHandle.Zero)
|
if (context != ContextHandle.Zero)
|
||||||
Debug.Print("Success! (id: {0})", context);
|
Debug.Print("Context created (id: {0}).", context);
|
||||||
else
|
else
|
||||||
throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
|
throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
|
||||||
|
|
||||||
|
if (!Glx.IsDirect(currentWindow.Display, context.Handle))
|
||||||
|
Debug.Print("Warning: Context is not direct.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -229,15 +246,15 @@ namespace OpenTK.Platform.X11
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return vsync_supported && vsync_interval > 0;
|
return vsync_supported && vsync_interval != 0;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (vsync_supported)
|
if (vsync_supported)
|
||||||
{
|
{
|
||||||
int error_code = Glx.Sgi.SwapInterval(value ? 1 : 0);
|
ErrorCode error_code = Glx.Sgi.SwapInterval(value ? 1 : 0);
|
||||||
if (error_code != 0)
|
if (error_code != X11.ErrorCode.NO_ERROR)
|
||||||
throw new GraphicsException(String.Format("Could not set vsync, error code: {0}", error_code));
|
Debug.Print("VSync = {0} failed, error code: {1}.", value, error_code);
|
||||||
vsync_interval = value ? 1 : 0;
|
vsync_interval = value ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,8 +309,8 @@ namespace OpenTK.Platform.X11
|
||||||
GL.LoadAll();
|
GL.LoadAll();
|
||||||
Glu.LoadAll();
|
Glu.LoadAll();
|
||||||
Glx.LoadAll();
|
Glx.LoadAll();
|
||||||
vsync_supported = this.SupportsExtension(currentWindow, "SGI_swap_control") &&
|
vsync_supported = this.GetAddress("glXSwapIntervalSGI") != IntPtr.Zero;
|
||||||
this.GetAddress("glXSwapControlSGI") != IntPtr.Zero;
|
Debug.Print("Context supports vsync: {0}.", vsync_supported);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue