mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-03 18:58:15 +00:00
Avoid reference to System.Windows.Forms.
Pass a concrete GraphicsMode to the context constructor in SelectPixelFormatARB to avoid NRE.
This commit is contained in:
parent
206a6530a4
commit
d08438785e
|
@ -45,6 +45,7 @@ namespace OpenTK.Platform.Windows
|
||||||
|
|
||||||
// To avoid recursion when calling GraphicsMode.Default
|
// To avoid recursion when calling GraphicsMode.Default
|
||||||
bool creating;
|
bool creating;
|
||||||
|
static readonly object SyncRoot = new object();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -61,22 +62,26 @@ namespace OpenTK.Platform.Windows
|
||||||
public GraphicsMode SelectGraphicsMode(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
|
public GraphicsMode SelectGraphicsMode(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
|
||||||
int buffers, bool stereo)
|
int buffers, bool stereo)
|
||||||
{
|
{
|
||||||
GraphicsMode mode = null;
|
lock (SyncRoot)
|
||||||
if (!creating)
|
|
||||||
{
|
{
|
||||||
try
|
GraphicsMode mode = null;
|
||||||
|
if (!creating)
|
||||||
{
|
{
|
||||||
creating = true;
|
creating = true;
|
||||||
mode = SelectGraphicsModeARB(color, depth, stencil, samples, accum, buffers, stereo);
|
try
|
||||||
}
|
{
|
||||||
finally
|
mode = SelectGraphicsModeARB(color, depth, stencil, samples, accum, buffers, stereo);
|
||||||
{
|
}
|
||||||
creating = false;
|
finally
|
||||||
|
{
|
||||||
|
if (mode == null)
|
||||||
|
mode = SelectGraphicsModePFD(color, depth, stencil, samples, accum, buffers, stereo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
creating = false;
|
||||||
|
return mode;
|
||||||
}
|
}
|
||||||
if (mode == null)
|
|
||||||
mode = SelectGraphicsModePFD(color, depth, stencil, samples, accum, buffers, stereo);
|
|
||||||
return mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -88,13 +93,13 @@ namespace OpenTK.Platform.Windows
|
||||||
GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
|
GraphicsMode SelectGraphicsModePFD(ColorDepth color, int depth, int stencil, int samples, ColorDepth accum,
|
||||||
int buffers, bool stereo)
|
int buffers, bool stereo)
|
||||||
{
|
{
|
||||||
using (Control native_window = new Control())
|
using (INativeWindow native_window = new NativeWindow())
|
||||||
using (WinWindowInfo window = new WinWindowInfo(native_window.Handle, null))
|
|
||||||
{
|
{
|
||||||
|
WinWindowInfo window = native_window.WindowInfo as WinWindowInfo;
|
||||||
IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext;
|
IntPtr deviceContext = ((WinWindowInfo)window).DeviceContext;
|
||||||
Debug.WriteLine(String.Format("Device context: {0}", deviceContext));
|
Debug.WriteLine(String.Format("Device context: {0}", deviceContext));
|
||||||
|
|
||||||
Debug.Write("Selecting pixel format... ");
|
Debug.Write("Selecting pixel format (PFD)... ");
|
||||||
PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor();
|
PixelFormatDescriptor pixelFormat = new PixelFormatDescriptor();
|
||||||
pixelFormat.Size = API.PixelFormatDescriptorSize;
|
pixelFormat.Size = API.PixelFormatDescriptorSize;
|
||||||
pixelFormat.Version = API.PixelFormatDescriptorVersion;
|
pixelFormat.Version = API.PixelFormatDescriptorVersion;
|
||||||
|
@ -155,7 +160,9 @@ namespace OpenTK.Platform.Windows
|
||||||
int buffers, bool stereo)
|
int buffers, bool stereo)
|
||||||
{
|
{
|
||||||
using (INativeWindow native_window = new NativeWindow())
|
using (INativeWindow native_window = new NativeWindow())
|
||||||
using (IGraphicsContext context = new GraphicsContext(new GraphicsMode(new ColorFormat(), 0, 0, 0, new ColorFormat(), 2, false), native_window.WindowInfo, 1, 0, GraphicsContextFlags.Default))
|
using (IGraphicsContext context = new WinGLContext(
|
||||||
|
new GraphicsMode(new IntPtr(2), new ColorFormat(), 0, 0, 0, new ColorFormat(), 2, false),
|
||||||
|
(WinWindowInfo)native_window.WindowInfo, null, 1, 0, GraphicsContextFlags.Default))
|
||||||
{
|
{
|
||||||
WinWindowInfo window = (WinWindowInfo)native_window.WindowInfo;
|
WinWindowInfo window = (WinWindowInfo)native_window.WindowInfo;
|
||||||
|
|
||||||
|
@ -269,4 +276,3 @@ namespace OpenTK.Platform.Windows
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue