mirror of
https://github.com/Ryujinx/GLWidget.git
synced 2024-12-22 19:45:38 +00:00
v1.0.4-pre1 fix context creation on macosx, fix view size on macosx
This commit is contained in:
parent
88af339c0b
commit
39bbaf3c6b
|
@ -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);
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -276,7 +281,14 @@ namespace OpenTK
|
|||
|
||||
public override void MakeCurrent(IWindowInfo window)
|
||||
{
|
||||
Cocoa.SendVoid(Handle.Handle, selMakeCurrentContext);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -306,60 +306,63 @@ namespace OpenTK.Platform.X11
|
|||
|
||||
public override void MakeCurrent(IWindowInfo window)
|
||||
{
|
||||
if (window == currentWindow && IsCurrent)
|
||||
using (new XLock(Display))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (window != null && ((X11WindowInfo)window).Display != Display)
|
||||
{
|
||||
throw new InvalidOperationException("MakeCurrent() may only be called on windows originating from the same display that spawned this GL context.");
|
||||
}
|
||||
|
||||
if (window == null)
|
||||
{
|
||||
Debug.Write(String.Format("Releasing context {0} from thread {1} (Display: {2})... ",
|
||||
Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display));
|
||||
|
||||
bool result;
|
||||
result = Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero);
|
||||
if (result)
|
||||
if (window == currentWindow && IsCurrent)
|
||||
{
|
||||
currentWindow = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Print("{0}", result ? "done!" : "failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
X11WindowInfo w = (X11WindowInfo)window;
|
||||
bool result;
|
||||
|
||||
Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
|
||||
Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display, w.Screen, w.Handle));
|
||||
|
||||
if (Display == IntPtr.Zero || w.Handle == IntPtr.Zero || Handle == ContextHandle.Zero)
|
||||
if (window != null && ((X11WindowInfo)window).Display != Display)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid display, window or context.");
|
||||
throw new InvalidOperationException("MakeCurrent() may only be called on windows originating from the same display that spawned this GL context.");
|
||||
}
|
||||
|
||||
result = Glx.MakeCurrent(Display, w.Handle, Handle);
|
||||
if (result)
|
||||
if (window == null)
|
||||
{
|
||||
currentWindow = w;
|
||||
}
|
||||
Debug.Write(String.Format("Releasing context {0} from thread {1} (Display: {2})... ",
|
||||
Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display));
|
||||
|
||||
if (!result)
|
||||
{
|
||||
throw new GraphicsContextException("Failed to make context current.");
|
||||
bool result;
|
||||
result = Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero);
|
||||
if (result)
|
||||
{
|
||||
currentWindow = null;
|
||||
}
|
||||
|
||||
Debug.Print("{0}", result ? "done!" : "failed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("done!");
|
||||
}
|
||||
}
|
||||
X11WindowInfo w = (X11WindowInfo)window;
|
||||
bool result;
|
||||
|
||||
currentWindow = (X11WindowInfo)window;
|
||||
Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
|
||||
Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display, w.Screen, w.Handle));
|
||||
|
||||
if (Display == IntPtr.Zero || w.Handle == IntPtr.Zero || Handle == ContextHandle.Zero)
|
||||
{
|
||||
throw new InvalidOperationException("Invalid display, window or context.");
|
||||
}
|
||||
|
||||
result = Glx.MakeCurrent(Display, w.Handle, Handle);
|
||||
if (result)
|
||||
{
|
||||
currentWindow = w;
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
throw new GraphicsContextException("Failed to make context current.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine("done!");
|
||||
}
|
||||
}
|
||||
|
||||
currentWindow = (X11WindowInfo)window;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsCurrent
|
||||
|
|
|
@ -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" />
|
||||
|
|
|
@ -298,7 +298,9 @@ namespace GLWidgetTestGTK3
|
|||
{
|
||||
var version = GL.GetString(StringName.Version);
|
||||
|
||||
this.Scene = new Scene();
|
||||
var framebufferStatus = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
|
||||
|
||||
this.Scene = new Scene();
|
||||
|
||||
// Create the cube actor
|
||||
Actor cubeActor = new Actor(new Mesh(FloatArrayToVertexList(Shapes.UnindexedCube)));
|
||||
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue