mirror of
https://github.com/Ryujinx/GLWidget.git
synced 2024-12-22 14:25:31 +00:00
fix context creation on nvidia, 1.0.4-pre4
This commit is contained in:
parent
39bbaf3c6b
commit
f04d3b0d46
1067
GLWidget/GLWidget.cs
1067
GLWidget/GLWidget.cs
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Description>GLWigdet for GTKSharp, using Opentk.</Description>
|
||||
<Version>1.0.4-pre1</Version>
|
||||
<Version>1.0.4-pre4</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.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"/>
|
||||
<PackageReference Include="GtkSharp" Version="3.22.25.56" />
|
||||
<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>
|
51
GLWidget/OpenTK/GameWindowFlags.cs
Normal file
51
GLWidget/OpenTK/GameWindowFlags.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
//
|
||||
// The Open Toolkit Library License
|
||||
//
|
||||
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights to
|
||||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
// the Software, and to permit persons to whom the Software is furnished to do
|
||||
// so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines bitwise combianations of GameWindow construction options.
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum GameWindowFlags
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates default construction options.
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the GameWindow should cover the whole screen.
|
||||
/// </summary>
|
||||
Fullscreen = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the GameWindow should be a fixed window.
|
||||
/// </summary>
|
||||
FixedWindow = 2,
|
||||
}
|
||||
}
|
|
@ -111,8 +111,26 @@ namespace OpenTK.Platform.Windows
|
|||
internal static readonly int WindowInfoSize;
|
||||
}
|
||||
|
||||
|
||||
internal static class Functions
|
||||
{
|
||||
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern ushort RegisterClass(ref WindowClass window_class);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern ushort RegisterClassEx(ref ExtendedWindowClass window_class);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern short UnregisterClass([MarshalAs(UnmanagedType.LPTStr)] LPCTSTR className, IntPtr instance);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
internal static extern short UnregisterClass(IntPtr className, IntPtr instance);
|
||||
|
||||
[DllImport("User32.dll", CharSet = CharSet.Unicode)]
|
||||
public extern static IntPtr DefWindowProc(HWND hWnd, WindowMessage msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -134,6 +152,49 @@ namespace OpenTK.Platform.Windows
|
|||
[DllImport("gdi32.dll")]
|
||||
internal static extern int ChoosePixelFormat(IntPtr dc, ref PixelFormatDescriptor pfd);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
internal static extern IntPtr CreateWindowEx(
|
||||
ExtendedWindowStyle ExStyle,
|
||||
[MarshalAs(UnmanagedType.LPTStr)] string className,
|
||||
[MarshalAs(UnmanagedType.LPTStr)] string windowName,
|
||||
WindowStyle Style,
|
||||
int X, int Y,
|
||||
int Width, int Height,
|
||||
IntPtr HandleToParentWindow,
|
||||
IntPtr Menu,
|
||||
IntPtr Instance,
|
||||
IntPtr Param);
|
||||
/*
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
internal static extern int CreateWindowEx(
|
||||
[In]ExtendedWindowStyle ExStyle,
|
||||
[In]IntPtr ClassName,
|
||||
[In]IntPtr WindowName,
|
||||
[In]WindowStyle Style,
|
||||
[In]int X, [In]int Y,
|
||||
[In]int Width, [In]int Height,
|
||||
[In]IntPtr HandleToParentWindow,
|
||||
[In]IntPtr Menu,
|
||||
[In]IntPtr Instance,
|
||||
[In]IntPtr Param);
|
||||
*/
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
internal static extern IntPtr CreateWindowEx(
|
||||
ExtendedWindowStyle ExStyle,
|
||||
IntPtr ClassAtom,
|
||||
IntPtr WindowName,
|
||||
WindowStyle Style,
|
||||
int X, int Y,
|
||||
int Width, int Height,
|
||||
IntPtr HandleToParentWindow,
|
||||
IntPtr Menu,
|
||||
IntPtr Instance,
|
||||
IntPtr Param);
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool DestroyWindow(IntPtr windowHandle);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
internal static extern int DescribePixelFormat(IntPtr deviceContext, int pixel, int pfdSize, ref PixelFormatDescriptor pixelFormat);
|
||||
|
||||
|
@ -214,6 +275,7 @@ namespace OpenTK.Platform.Windows
|
|||
public delegate void TimerProc(HWND hwnd, WindowMessage uMsg, UINT_PTR idEvent, DWORD dwTime);
|
||||
}
|
||||
|
||||
|
||||
internal static class Constants
|
||||
{
|
||||
// Found in winuser.h
|
||||
|
@ -655,6 +717,7 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// \internal
|
||||
/// <summary>
|
||||
/// Contains window information.
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
private bool vsync_supported;
|
||||
private bool vsync_tear_supported;
|
||||
|
||||
private bool focused;
|
||||
private readonly WinGraphicsMode ModeSelector;
|
||||
|
||||
// We need to create a temp context in order to load
|
||||
|
@ -96,6 +96,74 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private IntPtr WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
IntPtr? result = null;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WindowMessage.ACTIVATE:
|
||||
HandleActivate(handle, message, wParam, lParam);
|
||||
break;
|
||||
case WindowMessage.CREATE:
|
||||
HandleCreate(handle, message, wParam, lParam);
|
||||
break;
|
||||
|
||||
case WindowMessage.CLOSE:
|
||||
HandleClose(handle, message, wParam, lParam);
|
||||
return IntPtr.Zero;
|
||||
|
||||
case WindowMessage.DESTROY:
|
||||
HandleDestroy(handle, message, wParam, lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.HasValue)
|
||||
{
|
||||
return result.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Functions.DefWindowProc(handle, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleCreate(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
}
|
||||
|
||||
private void HandleClose(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
System.ComponentModel.CancelEventArgs e = new System.ComponentModel.CancelEventArgs();
|
||||
}
|
||||
|
||||
private void HandleDestroy(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
}
|
||||
|
||||
private void HandleActivate(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam)
|
||||
{
|
||||
// See http://msdn.microsoft.com/en-us/library/ms646274(VS.85).aspx (WM_ACTIVATE notification):
|
||||
// wParam: The low-order word specifies whether the window is being activated or deactivated.
|
||||
bool new_focused_state = false;
|
||||
if (IntPtr.Size == 4)
|
||||
{
|
||||
focused = (wParam.ToInt32() & 0xFFFF) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
focused = (wParam.ToInt64() & 0xFFFF) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly IntPtr ClassName = Marshal.StringToHGlobalAuto(Guid.NewGuid().ToString());
|
||||
|
||||
private readonly IntPtr Instance = GetModuleHandle(typeof(WinGLContext).Module.Name);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
internal static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPTStr)] string module_name);
|
||||
|
||||
public WinGLContext(GraphicsMode format, WinWindowInfo window, IGraphicsContext sharedContext,
|
||||
int major, int minor, GraphicsContextFlags flags)
|
||||
{
|
||||
|
@ -114,13 +182,26 @@ namespace OpenTK.Platform.Windows
|
|||
}
|
||||
|
||||
IntPtr current_context = Wgl.GetCurrentContext();
|
||||
|
||||
ExtendedWindowClass wc = new ExtendedWindowClass();
|
||||
wc.Size = ExtendedWindowClass.SizeInBytes;
|
||||
wc.Style = ClassStyle.OwnDC;
|
||||
wc.Instance = Instance;
|
||||
wc.WndProc = WindowProcedure;
|
||||
wc.ClassName = ClassName;
|
||||
|
||||
ushort atom = Functions.RegisterClassEx(ref wc);
|
||||
|
||||
IntPtr window_name = Marshal.StringToHGlobalAuto("temp");
|
||||
var temp_window = Functions.CreateWindowEx(ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow, ClassName, window_name, WindowStyle.OverlappedWindow | WindowStyle.ClipChildren, 0, 0, 10, 10, IntPtr.Zero, IntPtr.Zero,Instance, IntPtr.Zero);
|
||||
var error = Marshal.GetLastWin32Error();
|
||||
TemporaryContext temp_context = null;
|
||||
try
|
||||
{
|
||||
if (current_context == IntPtr.Zero)
|
||||
{
|
||||
// Create temporary context to load WGL extensions
|
||||
temp_context = new TemporaryContext(window.Handle);
|
||||
temp_context = new TemporaryContext(temp_window);
|
||||
current_context = Wgl.GetCurrentContext();
|
||||
if (current_context != IntPtr.Zero && current_context == temp_context.Context.Handle)
|
||||
{
|
||||
|
@ -198,6 +279,13 @@ namespace OpenTK.Platform.Windows
|
|||
temp_context.Dispose();
|
||||
temp_context = null;
|
||||
}
|
||||
if (temp_window != null)
|
||||
{
|
||||
error = Marshal.GetLastWin32Error();
|
||||
Functions.DestroyWindow(temp_window);
|
||||
Functions.UnregisterClass(ClassName, Instance);
|
||||
error = Marshal.GetLastWin32Error();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,9 +484,7 @@ namespace OpenTK.Platform.Windows
|
|||
|
||||
Debug.WriteLine(mode.Index.ToString());
|
||||
|
||||
var index = Functions.ChoosePixelFormat(window.DeviceContext, ref pfd);
|
||||
|
||||
if (!Functions.SetPixelFormat(window.DeviceContext, index, ref pfd))
|
||||
if (!Functions.SetPixelFormat(window.DeviceContext, (int)mode.Index.Value, ref pfd))
|
||||
{
|
||||
throw new GraphicsContextException(String.Format(
|
||||
"Requested GraphicsMode not available. SetPixelFormat error: {0}",
|
||||
|
|
|
@ -60,6 +60,7 @@ namespace OpenTK.Platform.Windows
|
|||
ColorFormat accum, int buffers, bool stereo)
|
||||
{
|
||||
GraphicsMode mode = new GraphicsMode(color, depth, stencil, samples, accum, buffers, stereo);
|
||||
|
||||
GraphicsMode created_mode = ChoosePixelFormatARB(Device, mode);
|
||||
|
||||
// If ChoosePixelFormatARB failed, iterate through all acceleration types in turn (ICD, MCD, None)
|
||||
|
|
21
GLWidget/OpenTK/WindowBorder.cs
Normal file
21
GLWidget/OpenTK/WindowBorder.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates available window borders.
|
||||
/// </summary>
|
||||
public enum WindowBorder
|
||||
{
|
||||
/// <summary>
|
||||
/// The window has a resizable border. A window with a resizable border can be resized by the user or programmatically.
|
||||
/// </summary>
|
||||
Resizable = 0,
|
||||
/// <summary>
|
||||
/// The window has a fixed border. A window with a fixed border can only be resized programmatically.
|
||||
/// </summary>
|
||||
Fixed,
|
||||
/// <summary>
|
||||
/// The window does not have a border. A window with a hidden border can only be resized programmatically.
|
||||
/// </summary>
|
||||
Hidden
|
||||
}
|
||||
}
|
93
GLWidget/OpenTK/WindowIcon.cs
Normal file
93
GLWidget/OpenTK/WindowIcon.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
//
|
||||
// WindowIcon.cs
|
||||
//
|
||||
// Author:
|
||||
// Stefanos A. <stapostol@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2006-2014 Stefanos Apostolopoulos
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores a window icon. A window icon is defined
|
||||
/// as a 2-dimensional buffer of RGBA values.
|
||||
/// </summary>
|
||||
public class WindowIcon
|
||||
{
|
||||
/// \internal
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="OpenTK.WindowIcon"/> class.
|
||||
/// </summary>
|
||||
internal protected WindowIcon()
|
||||
{
|
||||
}
|
||||
|
||||
private WindowIcon(int width, int height)
|
||||
{
|
||||
if (width < 0 || width > 256 || height < 0 || height > 256)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
this.Width = width;
|
||||
this.Height = height;
|
||||
}
|
||||
|
||||
internal WindowIcon(int width, int height, byte[] data)
|
||||
: this(width, height)
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
if (data.Length < Width * Height * 4)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
internal WindowIcon(int width, int height, IntPtr data)
|
||||
: this(width, height)
|
||||
{
|
||||
if (data == IntPtr.Zero)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
}
|
||||
|
||||
// We assume that width and height are correctly set.
|
||||
// If they are not, we will read garbage and probably
|
||||
// crash.
|
||||
this.Data = new byte[width * height * 4];
|
||||
Marshal.Copy(data, this.Data, 0, this.Data.Length);
|
||||
}
|
||||
|
||||
internal byte[] Data { get; }
|
||||
internal int Width { get; }
|
||||
internal int Height { get; }
|
||||
}
|
||||
}
|
||||
|
31
GLWidget/OpenTK/WindowState.cs
Normal file
31
GLWidget/OpenTK/WindowState.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
|
||||
namespace OpenTK
|
||||
{
|
||||
/// <summary>
|
||||
/// Enumerates available window states.
|
||||
/// </summary>
|
||||
public enum WindowState
|
||||
{
|
||||
/// <summary>
|
||||
/// The window is in its normal state.
|
||||
/// </summary>
|
||||
Normal = 0,
|
||||
/// <summary>
|
||||
/// The window is minimized to the taskbar (also known as 'iconified').
|
||||
/// </summary>
|
||||
Minimized,
|
||||
/// <summary>
|
||||
/// The window covers the whole working area, which includes the desktop but not the taskbar and/or panels.
|
||||
/// </summary>
|
||||
Maximized,
|
||||
/// <summary>
|
||||
/// The window covers the whole screen, including all taskbars and/or panels.
|
||||
/// </summary>
|
||||
Fullscreen
|
||||
}
|
||||
}
|
|
@ -10,8 +10,9 @@ namespace GLWidgetTestGTK3
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// GTKBindingHelper.InitXThreads();
|
||||
// GTK
|
||||
// GTKBindingHelper.InitXThreads();
|
||||
// GTK
|
||||
GTKBindingHelper.InitializeGlBindings();
|
||||
Application.Init();
|
||||
MainWindow win = MainWindow.Create();
|
||||
win.Show();
|
||||
|
|
|
@ -93,8 +93,15 @@ namespace GLWidgetTestGTK3.World
|
|||
int projectionShaderVariableHandle = GL.GetUniformLocation(ShaderProgramID, "ModelViewProjection");
|
||||
GL.UniformMatrix4(projectionShaderVariableHandle, false, ref modelViewProjection);
|
||||
|
||||
// Draw the model
|
||||
GL.DrawArrays(BeginMode.Triangles, 0, Mesh.GetVertexCount());
|
||||
// Draw the model
|
||||
try
|
||||
{
|
||||
GL.DrawArrays(PrimitiveType.Triangles, 0, Mesh.GetVertexCount());
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Release the attribute arrays
|
||||
GL.DisableVertexAttribArray(0);
|
||||
|
|
Loading…
Reference in a new issue