mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-23 19:15:36 +00:00
Delay VisualInfo construction (fixes #17)
In OpenTK 1.1, GraphicsMode queries the platform for a mode id lazily. By delaying VisualInfo selection until the GraphicsContext is constructed we ensure that a concrete GraphicsMode is selected and ready for use.
This commit is contained in:
parent
19d9beb6a4
commit
61f334f3f5
|
@ -63,6 +63,10 @@ namespace OpenTK
|
||||||
GraphicsMode mode;
|
GraphicsMode mode;
|
||||||
IWindowInfo window_info;
|
IWindowInfo window_info;
|
||||||
IntPtr display;
|
IntPtr display;
|
||||||
|
IntPtr rootWindow;
|
||||||
|
|
||||||
|
// Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
|
||||||
|
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -77,16 +81,24 @@ namespace OpenTK
|
||||||
|
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
// Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
|
|
||||||
Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
|
|
||||||
if (xplatui == null) throw new PlatformNotSupportedException(
|
if (xplatui == null) throw new PlatformNotSupportedException(
|
||||||
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
"System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
|
||||||
|
|
||||||
// get the required handles from the X11 API.
|
// get the required handles from the X11 API.
|
||||||
display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
|
||||||
IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
|
||||||
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
|
||||||
|
|
||||||
|
window_info = Utilities.CreateX11WindowInfo(display, screen, control.Handle, rootWindow, IntPtr.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IGLControl Members
|
||||||
|
|
||||||
|
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
||||||
|
{
|
||||||
|
GraphicsContext context = new GraphicsContext(mode, this.WindowInfo, major, minor, flags);
|
||||||
|
mode = context.GraphicsMode;
|
||||||
|
|
||||||
// get the XVisualInfo for this GraphicsMode
|
// get the XVisualInfo for this GraphicsMode
|
||||||
XVisualInfo info = new XVisualInfo();
|
XVisualInfo info = new XVisualInfo();
|
||||||
info.VisualID = mode.Index.Value;
|
info.VisualID = mode.Index.Value;
|
||||||
|
@ -98,14 +110,7 @@ namespace OpenTK
|
||||||
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
|
SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
|
||||||
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
|
SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
|
||||||
|
|
||||||
window_info = Utilities.CreateX11WindowInfo(display, screen, control.Handle, rootWindow, infoPtr);
|
return context;
|
||||||
}
|
|
||||||
|
|
||||||
#region IGLControl Members
|
|
||||||
|
|
||||||
public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
|
|
||||||
{
|
|
||||||
return new GraphicsContext(mode, this.WindowInfo, major, minor, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
|
|
|
@ -212,7 +212,10 @@ namespace OpenTK.Platform
|
||||||
window.Screen = screen;
|
window.Screen = screen;
|
||||||
window.Handle = windowHandle;
|
window.Handle = windowHandle;
|
||||||
window.RootWindow = rootWindow;
|
window.RootWindow = rootWindow;
|
||||||
window.VisualInfo = (X11.XVisualInfo)Marshal.PtrToStructure(visualInfo, typeof(X11.XVisualInfo));
|
if (visualInfo != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
window.VisualInfo = (X11.XVisualInfo)Marshal.PtrToStructure(visualInfo, typeof(X11.XVisualInfo));
|
||||||
|
}
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue