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 IWindowInfo _windowInfo;
private bool _initialized; private bool _initialized;
private int swapInterval = 0; private int swapInterval = 0;
private bool _resize;
#endregion #endregion
@ -141,6 +142,13 @@ namespace OpenTK
GLVersionMajor = glVersionMajor; GLVersionMajor = glVersionMajor;
GLVersionMinor = glVersionMinor; GLVersionMinor = glVersionMinor;
GraphicsContextFlags = graphicsContextFlags; GraphicsContextFlags = graphicsContextFlags;
this.ConfigureEvent += GLWidget_ConfigureEvent;
}
private void GLWidget_ConfigureEvent(object o, ConfigureEventArgs args)
{
Resize = true;
} }
~GLWidget() ~GLWidget()
@ -155,7 +163,6 @@ namespace OpenTK
public void ClearCurrent() public void ClearCurrent()
{ {
Gdk.GLContext.ClearCurrent();
GraphicsContext.MakeCurrent(null); GraphicsContext.MakeCurrent(null);
} }
@ -222,10 +229,11 @@ namespace OpenTK
protected virtual void OnRenderFrame() 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 // Called when this GLWidget is being Disposed
@ -240,10 +248,6 @@ namespace OpenTK
} }
#endregion #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. // Called when the widget needs to be (fully or partially) redrawn.
protected override bool OnDrawn(Cairo.Context cr) protected override bool OnDrawn(Cairo.Context cr)
@ -251,20 +255,23 @@ namespace OpenTK
if (!_initialized) if (!_initialized)
Initialize(); Initialize();
else if (!IsRenderHandler) else if (!IsRenderHandler)
{
MakeCurrent(); MakeCurrent();
OnRenderFrame();
ClearCurrent();
}
return true; return true;
} }
// Called on Resize public void Update()
protected override bool OnConfigureEvent(Gdk.EventConfigure evnt)
{ {
if (GraphicsContext != null) GraphicsContext.Width = AllocatedWidth;
{ GraphicsContext.Height = AllocatedHeight;
GraphicsContext.Update(WindowInfo);
}
return true; GraphicsContext?.Update(WindowInfo);
_resize = false;
} }
private void Initialize() private void Initialize()
@ -296,7 +303,7 @@ namespace OpenTK
buffers--; 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(); this.Window.EnsureNative();
@ -558,6 +565,7 @@ namespace OpenTK
public IGraphicsContext GraphicsContext { get => _graphicsContext; set => _graphicsContext = value; } public IGraphicsContext GraphicsContext { get => _graphicsContext; set => _graphicsContext = value; }
public IWindowInfo WindowInfo { get => _windowInfo; set => _windowInfo = value; } public IWindowInfo WindowInfo { get => _windowInfo; set => _windowInfo = value; }
public bool Resize { get => _resize; set => _resize = value; }
[DllImport(UnixLibX11Name, EntryPoint = "XGetVisualInfo")] [DllImport(UnixLibX11Name, EntryPoint = "XGetVisualInfo")]
private static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems); 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"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>GLWigdet for GTKSharp, using Opentk.</Description> <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> <RepositoryUrl>https://github.com/Ryujinx/GLWidget</RepositoryUrl>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56"/> <PackageReference Include="GtkSharp" Version="3.22.25.56"/>
<PackageReference Include="OpenTK.Graphics" 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.4"/> <PackageReference Include="OpenTK.Windowing.Common" Version="4.0.0-pre9.6"/>
<PackageReference Include="System.Drawing.Common" Version="4.7.0"/> <PackageReference Include="System.Drawing.Common" Version="4.7.0"/>
<PackageReference Include="MonoMac.NetStandard" Version="0.0.4"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

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

View file

@ -79,6 +79,10 @@ namespace OpenTK.Graphics
public ContextHandle Context { get { return Handle; } } public ContextHandle Context { get { return Handle; } }
public int Width { get; set; }
public int Height{ get; set; }
// This function is no longer used. // This function is no longer used.
// The GraphicsContext facade will // The GraphicsContext facade will
// always call the IntPtr overload. // 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> /// <para>This method only affects the debug version of OpenTK.dll.</para>
/// </remarks> /// </remarks>
bool ErrorChecking { get; set; } bool ErrorChecking { get; set; }
int Width { get; set; }
int Height { get; set; }
/// <summary> /// <summary>
/// Loads all OpenGL entry points. Requires this instance to be current on the calling thread. /// 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")] [DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static void SendVoid(IntPtr receiver, IntPtr selector, NSRect rect1, IntPtr intPtr1); 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")] [DllImport(LibObjC, EntryPoint="objc_msgSend")]
public extern static int SendInt(IntPtr receiver, IntPtr selector); public extern static int SendInt(IntPtr receiver, IntPtr selector);

View file

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

View file

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

View file

@ -16,7 +16,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.56" /> <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>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="interfaces\MainWindow.glade" /> <EmbeddedResource Include="interfaces\MainWindow.glade" />

View file

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

View file

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