1.0.3pre1

This commit is contained in:
Emmanuel 2020-09-08 08:36:51 +00:00
parent d573036187
commit 4435d1a5da
3 changed files with 104 additions and 13 deletions

View file

@ -174,6 +174,7 @@ namespace OpenTK
private int _error;
private IGraphicsContext _context;
private GLContext _gdkGlContext;
public bool ForwardCompatible { get; }
public DeviceContext DeviceContext { get => _deviceContext; set => _deviceContext = value; }
@ -209,10 +210,12 @@ namespace OpenTK
{
OnShuttingDown();
DeviceContext.DeleteContext(_graphicsContext);
DeviceContext?.DeleteContext(_graphicsContext);
DeviceContext.Dispose();
}
DeviceContext?.Dispose();
_gdkGlContext?.Dispose();
}
}
#endregion
@ -271,7 +274,7 @@ namespace OpenTK
public void Swapbuffers()
{
DeviceContext?.SwapBuffers();
_context?.SwapBuffers();
}
public void MakeCurrent()
@ -285,9 +288,15 @@ namespace OpenTK
public void ClearCurrent()
{
//Gdk.GLContext.ClearCurrent();
DeviceContext?.MakeCurrent(IntPtr.Zero);
}
if (GTKBindingHelper.CurrentPlatform == OSPlatform.Windows)
{
DeviceContext?.MakeCurrent(IntPtr.Zero);
}
else
{
Gdk.GLContext.ClearCurrent();
}
}
private void CreateContext()
{
@ -404,20 +413,42 @@ namespace OpenTK
#endregion
}
private void Initialize()
private void CreateGdkGlContext()
{
_gdkGlContext = Window.CreateGlContext();
_gdkGlContext.SetRequiredVersion(GLVersionMajor, GLVersionMinor);
_gdkGlContext.ForwardCompatible = ForwardCompatible;
_gdkGlContext.SetUseEs(0);
_gdkGlContext.Realize();
_gdkGlContext.MakeCurrent();
}
private void Initialize()
{
ClearCurrent();
Khronos.KhronosApi.LogEnabled = true;
Wgl.ErrorHandling = Wgl.ErrorHandlingMode.Normal;
Window.EnsureNative();
CreateDeviceContext(ControlPixelFormat);
if (GTKBindingHelper.CurrentPlatform == OSPlatform.Windows)
{
CreateDeviceContext(ControlPixelFormat);
CreateContext();
CreateContext();
DeviceContext.MakeCurrent(_graphicsContext);
DeviceContext.MakeCurrent(_graphicsContext);
}
else {
GraphicsContext.Display = Display.Handle;
CreateGdkGlContext();
}
_context = GraphicsContext.GetCurrentContext(Window.Handle);

View file

@ -67,7 +67,7 @@ namespace OpenTK
}
else if(CurrentPlatform == OSPlatform.OSX)
{
var osxAddr = !IsGlxRequired ? GetProcAddressOSX(procName) : GetProcAddressGlx(procName);
var osxAddr = GetProcAddressOSX(procName);
if (osxAddr != IntPtr.Zero)
{
Loaded = true;
@ -242,6 +242,22 @@ namespace OpenTK
[DllImport(OSXLibrary, EntryPoint = "NSAddressOfSymbol")]
public static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
[DllImport(OSXLibrary)]
public extern static int CGLSetCurrentContext(IntPtr ctx);
[DllImport(OSXLibrary)]
public extern static IntPtr CGLGetCurrentContext();
[DllImport(OSXLibrary)]
public extern static void CGLReleaseContext(IntPtr ctx);
[DllImport(OSXLibrary)]
public extern static int CGLFlushDrawable(IntPtr ctx);
[DllImport(OSXLibrary)]
internal static extern int CGLDestroyContext(IntPtr ctx);
[DllImport(OSXLibrary)]
internal static extern int CGLSetParameter(IntPtr ctx, int parameter, ref int value);
[DllImport(GlxLibrary, EntryPoint = "glXGetCurrentContext")]
public static extern IntPtr glXGetCurrentContext();

View file

@ -54,6 +54,10 @@ namespace OpenTK
}
return GlxGraphicsContext.GetCurrent(handle, Display);
}
else if (currentPlatform == OSPlatform.OSX)
{
return CglGraphicsContext.GetCurrent();
}
return null;
}
@ -157,4 +161,44 @@ namespace OpenTK
UnsafeNativeMethods.glXSwapIntervalEXT(interval);
}
}
public class CglGraphicsContext : GraphicsContext
{
private IntPtr _windowHandle;
public static CglGraphicsContext GetCurrent()
{
var gc = UnsafeNativeMethods.CGLGetCurrentContext();
return new CglGraphicsContext(gc);
}
public CglGraphicsContext(IntPtr graphicsContext)
{
_graphicsContext = graphicsContext;
}
private IntPtr _graphicsContext;
private IntPtr _display;
public override void MakeCurrent()
{
UnsafeNativeMethods.CGLSetCurrentContext(_graphicsContext);
}
public override void SwapBuffers()
{
UnsafeNativeMethods.CGLFlushDrawable(_graphicsContext);
}
public override void ClearCurrent()
{
UnsafeNativeMethods.CGLSetCurrentContext(IntPtr.Zero);
}
public override void SwapInterval(int interval)
{
UnsafeNativeMethods.CGLSetParameter(_graphicsContext, 222 , ref interval);
}
}
}