v1.0.4-pre1 fix context creation on macosx, fix view size on macosx

This commit is contained in:
Emmanuel 2020-09-16 15:31:39 +00:00
parent 88af339c0b
commit 39bbaf3c6b
11 changed files with 126 additions and 64 deletions

View file

@ -60,6 +60,7 @@ namespace OpenTK
private IWindowInfo _windowInfo;
private bool _initialized;
private int swapInterval = 0;
private bool _resize;
#endregion
@ -141,6 +142,13 @@ namespace OpenTK
GLVersionMajor = glVersionMajor;
GLVersionMinor = glVersionMinor;
GraphicsContextFlags = graphicsContextFlags;
this.ConfigureEvent += GLWidget_ConfigureEvent;
}
private void GLWidget_ConfigureEvent(object o, ConfigureEventArgs args)
{
Resize = true;
}
~GLWidget()
@ -155,7 +163,6 @@ namespace OpenTK
public void ClearCurrent()
{
Gdk.GLContext.ClearCurrent();
GraphicsContext.MakeCurrent(null);
}
@ -222,10 +229,11 @@ namespace OpenTK
protected virtual void OnRenderFrame()
{
if (RenderFrame != null)
if (_resize)
{
RenderFrame(this, EventArgs.Empty);
Update();
}
RenderFrame?.Invoke(this, EventArgs.Empty);
}
// Called when this GLWidget is being Disposed
@ -240,10 +248,6 @@ namespace OpenTK
}
#endregion
// Called when a widget is realized. (window handles and such are valid)
// protected override void OnRealized() { base.OnRealized(); }
// Called when the widget needs to be (fully or partially) redrawn.
protected override bool OnDrawn(Cairo.Context cr)
@ -251,20 +255,23 @@ namespace OpenTK
if (!_initialized)
Initialize();
else if (!IsRenderHandler)
{
MakeCurrent();
OnRenderFrame();
ClearCurrent();
}
return true;
}
// Called on Resize
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
public void Update()
{
if (GraphicsContext != null)
{
GraphicsContext.Update(WindowInfo);
}
GraphicsContext.Width = AllocatedWidth;
GraphicsContext.Height = AllocatedHeight;
return true;
GraphicsContext?.Update(WindowInfo);
_resize = false;
}
private void Initialize()
@ -296,7 +303,7 @@ namespace OpenTK
buffers--;
}
GraphicsMode graphicsMode = GraphicsMode.Default;//new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);
this.Window.EnsureNative();
@ -558,6 +565,7 @@ namespace OpenTK
public IGraphicsContext GraphicsContext { get => _graphicsContext; set => _graphicsContext = value; }
public IWindowInfo WindowInfo { get => _windowInfo; set => _windowInfo = value; }
public bool Resize { get => _resize; set => _resize = value; }
[DllImport(UnixLibX11Name, EntryPoint = "XGetVisualInfo")]
private static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);

View file

@ -1,16 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>GLWigdet for GTKSharp, using Opentk.</Description>
<Version>1.0.3.2</Version>
<Version>1.0.4-pre1</Version>
<RepositoryUrl>https://github.com/Ryujinx/GLWidget</RepositoryUrl>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56"/>
<PackageReference Include="OpenTK.Graphics" Version="4.0.0-pre9.4"/>
<PackageReference Include="OpenTK.Windowing.Common" Version="4.0.0-pre9.4"/>
<PackageReference Include="OpenTK.Graphics" Version="4.0.0-pre9.6"/>
<PackageReference Include="OpenTK.Windowing.Common" Version="4.0.0-pre9.6"/>
<PackageReference Include="System.Drawing.Common" Version="4.7.0"/>
<PackageReference Include="MonoMac.NetStandard" Version="0.0.4"/>
</ItemGroup>
</Project>

View file

@ -486,6 +486,8 @@ namespace OpenTK.Graphics
/// <param name="window"></param>
public void Update(IWindowInfo window)
{
implementation.Width = Width;
implementation.Height = Height;
implementation.Update(window);
}
@ -536,6 +538,9 @@ namespace OpenTK.Graphics
get { return (implementation as IGraphicsContext).GraphicsMode; }
}
public int Width { get; set; }
public int Height { get; set; }
/// <summary>
/// Retrieves the implementation-defined address of an OpenGL function.
/// </summary>

View file

@ -79,6 +79,10 @@ namespace OpenTK.Graphics
public ContextHandle Context { get { return Handle; } }
public int Width { get; set; }
public int Height{ get; set; }
// This function is no longer used.
// The GraphicsContext facade will
// always call the IntPtr overload.

View file

@ -63,6 +63,8 @@ namespace OpenTK.Graphics
/// <para>This method only affects the debug version of OpenTK.dll.</para>
/// </remarks>
bool ErrorChecking { get; set; }
int Width { get; set; }
int Height { get; set; }
/// <summary>
/// Loads all OpenGL entry points. Requires this instance to be current on the calling thread.

View file

@ -125,6 +125,9 @@ namespace OpenTK.Platform.MacOS
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, NSRect rect1, IntPtr intPtr1);
[DllImport(LibObjC, EntryPoint = "objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, NSSize size1);
[DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static int SendInt(IntPtr receiver, IntPtr selector);

View file

@ -32,6 +32,7 @@ using OpenTK.Platform.MacOS;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using MonoMac;
namespace OpenTK
{
@ -44,6 +45,7 @@ namespace OpenTK
private static readonly IntPtr selCurrentContext = Selector.Get("currentContext");
private static readonly IntPtr selFlushBuffer = Selector.Get("flushBuffer");
private static readonly IntPtr selMakeCurrentContext = Selector.Get("makeCurrentContext");
private static readonly IntPtr selClearCurrentContext = Selector.Get("clearCurrentContext");
private static readonly IntPtr selUpdate = Selector.Get("update");
private static readonly IntPtr opengl = NS.AddImage(
@ -98,6 +100,7 @@ namespace OpenTK
Handle = handle;
cocoaWindow = (CocoaWindowInfo)window;
Cocoa.SendVoid(cocoaWindow.ViewHandle, Selector.Get("setAutoresizingMask:"), (uint)(MonoMac.AppKit.NSViewResizingMask.HeightSizable | MonoMac.AppKit.NSViewResizingMask.WidthSizable));
}
private void AddPixelAttrib(List<NSOpenGLPixelFormatAttribute> attributes, NSOpenGLPixelFormatAttribute attribute)
@ -148,6 +151,8 @@ namespace OpenTK
Handle = new ContextHandle(context);
Mode = GetGraphicsMode(context);
Cocoa.SendVoid(cocoaWindow.ViewHandle, Selector.Get("setAutoresizingMask:"), (uint)(MonoMac.AppKit.NSViewResizingMask.HeightSizable | MonoMac.AppKit.NSViewResizingMask.WidthSizable));
Update(cocoaWindow);
}
@ -275,9 +280,16 @@ namespace OpenTK
}
public override void MakeCurrent(IWindowInfo window)
{
if (window == null)
{
Cocoa.SendVoid(NSOpenGLContext, selClearCurrentContext);
}
else
{
Cocoa.SendVoid(Handle.Handle, selMakeCurrentContext);
}
}
public override bool IsCurrent
{
@ -328,6 +340,20 @@ namespace OpenTK
public override void Update(IWindowInfo window)
{
var cocoaWindow = (CocoaWindowInfo)window;
if (Width > 0 && Height > 0)
{
GLib.Idle.Add(new GLib.IdleHandler(() =>
{
var previous = MonoMac.AppKit.NSApplication.CheckForIllegalCrossThreadCalls;
MonoMac.AppKit.NSApplication.CheckForIllegalCrossThreadCalls = false;
var view = new MonoMac.AppKit.NSView(cocoaWindow.ViewHandle);
view.SetFrameSize(new MonoMac.CoreGraphics.CGSize(Width, Height));
MonoMac.AppKit.NSApplication.CheckForIllegalCrossThreadCalls = previous;
return false;
}));
}
Cocoa.SendVoid(Handle.Handle, selUpdate);
}

View file

@ -305,6 +305,8 @@ namespace OpenTK.Platform.X11
}
public override void MakeCurrent(IWindowInfo window)
{
using (new XLock(Display))
{
if (window == currentWindow && IsCurrent)
{
@ -361,6 +363,7 @@ namespace OpenTK.Platform.X11
currentWindow = (X11WindowInfo)window;
}
}
public override bool IsCurrent
{

View file

@ -16,7 +16,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56" />
<PackageReference Include="OpenTK" Version="4.0.0-pre9.4" />
<PackageReference Include="OpenTK" Version="4.0.0-pre9.6" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="interfaces\MainWindow.glade" />

View file

@ -298,6 +298,8 @@ namespace GLWidgetTestGTK3
{
var version = GL.GetString(StringName.Version);
var framebufferStatus = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
this.Scene = new Scene();
// Create the cube actor
@ -362,6 +364,11 @@ namespace GLWidgetTestGTK3
{
MainGLWidget.MakeCurrent();
if (MainGLWidget.Resize)
{
MainGLWidget.Update();
}
// Make sure the viewport is accurate for the current widget size on screen
int widgetWidth = this.GLWidgetAlignment.AllocatedWidth;
int widgetHeight = this.GLWidgetAlignment.AllocatedHeight;

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkWindow" id="MainWindow">
@ -190,5 +190,8 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</object>
</interface>