Add Xlib support

This commit is contained in:
ReinUsesLisp 2018-07-30 03:50:23 -03:00
parent 50cd75fe35
commit 521661451e
11 changed files with 82 additions and 47 deletions

View file

@ -41,8 +41,6 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OpenTK.Tests.Generators", "
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTK.Standard", "src\OpenTK\OpenTK.Standard.csproj", "{67F02FD3-8F7F-4D89-8551-359993271CA3}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTK.Standard", "src\OpenTK\OpenTK.Standard.csproj", "{67F02FD3-8F7F-4D89-8551-359993271CA3}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VkTest", "VkTest\VkTest.csproj", "{B0F33C2F-B9BD-4E55-85E3-6C1760D39DE9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vk.generator", "src\vk.generator\vk.generator.csproj", "{3766DF33-E28B-402D-9EE1-975C2AFB5EAF}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vk.generator", "src\vk.generator\vk.generator.csproj", "{3766DF33-E28B-402D-9EE1-975C2AFB5EAF}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vk.rewrite", "src\vk.rewrite\vk.rewrite.csproj", "{3E9B1C4D-BCB4-418A-A94E-DD164A19C6A2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "vk.rewrite", "src\vk.rewrite\vk.rewrite.csproj", "{3E9B1C4D-BCB4-418A-A94E-DD164A19C6A2}"
@ -97,10 +95,6 @@ Global
{67F02FD3-8F7F-4D89-8551-359993271CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU {67F02FD3-8F7F-4D89-8551-359993271CA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67F02FD3-8F7F-4D89-8551-359993271CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU {67F02FD3-8F7F-4D89-8551-359993271CA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67F02FD3-8F7F-4D89-8551-359993271CA3}.Release|Any CPU.Build.0 = Release|Any CPU {67F02FD3-8F7F-4D89-8551-359993271CA3}.Release|Any CPU.Build.0 = Release|Any CPU
{B0F33C2F-B9BD-4E55-85E3-6C1760D39DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0F33C2F-B9BD-4E55-85E3-6C1760D39DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0F33C2F-B9BD-4E55-85E3-6C1760D39DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0F33C2F-B9BD-4E55-85E3-6C1760D39DE9}.Release|Any CPU.Build.0 = Release|Any CPU
{3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Debug|Any CPU.Build.0 = Debug|Any CPU {3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Release|Any CPU.ActiveCfg = Release|Any CPU {3766DF33-E28B-402D-9EE1-975C2AFB5EAF}.Release|Any CPU.ActiveCfg = Release|Any CPU

View file

@ -164,7 +164,7 @@ namespace OpenTK
return t != null; return t != null;
} }
#if SDL2 #if SDL2
private static bool DetectSdl2() private static bool DetectSdl2()
{ {
bool supported = false; bool supported = false;
@ -221,7 +221,12 @@ namespace OpenTK
return supported; return supported;
} }
#endif #else
private static bool DetectSdl2()
{
return false;
}
#endif
private static void DetectUnix(out bool unix, out bool linux, out bool macos) private static void DetectUnix(out bool unix, out bool linux, out bool macos)
{ {
@ -298,7 +303,7 @@ namespace OpenTK
initialized = true; initialized = true;
#endif #endif
Debug.Print("Detected configuration: {0} / {1}", Debug.Print("Detected configuration: {0} / {1}",
RunningOnWindows ? "Windows" : RunningOnLinux ? "Linux" : RunningOnMacOS ? "MacOS" : RunningOnWindows ? "Windows" : RunningOnLinux ? "Linux" : RunningOnMacOS ? "MacOS" :
runningOnUnix ? "Unix" : RunningOnX11 ? "X11" : "Unknown Platform", runningOnUnix ? "Unix" : RunningOnX11 ? "X11" : "Unknown Platform",
RunningOnMono ? "Mono" : ".Net"); RunningOnMono ? "Mono" : ".Net");

View file

@ -9,12 +9,26 @@ namespace OpenTK.Graphics.Vulkan
{ {
private static NativeLibrary s_nativeLib; private static NativeLibrary s_nativeLib;
static VK() static public void LoadFunctions()
{ {
s_nativeLib = LoadNativeLibrary(); if (s_nativeLib == null)
{
s_nativeLib = LoadNativeLibrary();
}
LoadFunctionPointers(); LoadFunctionPointers();
} }
public static IntPtr LoadFunctionPointer(string functionName)
{
if (s_nativeLib == null)
{
s_nativeLib = LoadNativeLibrary();
}
return s_nativeLib.LoadFunctionPointer(functionName);
}
private static NativeLibrary LoadNativeLibrary() private static NativeLibrary LoadNativeLibrary()
{ {
return NativeLibrary.Load(GetVulkanName()); return NativeLibrary.Load(GetVulkanName());

View file

@ -4,14 +4,14 @@ using System.Text;
namespace OpenTK.Graphics.Vulkan namespace OpenTK.Graphics.Vulkan
{ {
public unsafe class FixedUtf8String : IDisposable public unsafe class NativeString : IDisposable
{ {
private GCHandle _handle; private GCHandle _handle;
private uint _numBytes; private uint _numBytes;
public byte* StringPtr => (byte*)_handle.AddrOfPinnedObject().ToPointer(); public byte* StringPtr => (byte*)_handle.AddrOfPinnedObject().ToPointer();
public FixedUtf8String(string s) public NativeString(string s)
{ {
if (s == null) if (s == null)
{ {
@ -46,9 +46,9 @@ namespace OpenTK.Graphics.Vulkan
_handle.Free(); _handle.Free();
} }
public static implicit operator byte* (FixedUtf8String utf8String) => utf8String.StringPtr; public static implicit operator byte* (NativeString utf8String) => utf8String.StringPtr;
public static implicit operator IntPtr (FixedUtf8String utf8String) => new IntPtr(utf8String.StringPtr); public static implicit operator IntPtr (NativeString utf8String) => new IntPtr(utf8String.StringPtr);
public static implicit operator FixedUtf8String(string s) => new FixedUtf8String(s); public static implicit operator NativeString(string s) => new NativeString(s);
public static implicit operator string(FixedUtf8String utf8String) => utf8String.GetString(); public static implicit operator string(NativeString utf8String) => utf8String.GetString();
} }
} }

View file

@ -1,14 +0,0 @@
namespace OpenTK.Graphics.Vulkan
{
public static class Strings
{
public static FixedUtf8String VK_KHR_SURFACE_EXTENSION_NAME = "VK_KHR_surface";
public static FixedUtf8String VK_KHR_WIN32_SURFACE_EXTENSION_NAME = "VK_KHR_win32_surface";
public static FixedUtf8String VK_KHR_XCB_SURFACE_EXTENSION_NAME = "VK_KHR_xcb_surface";
public static FixedUtf8String VK_KHR_XLIB_SURFACE_EXTENSION_NAME = "VK_KHR_xlib_surface";
public static FixedUtf8String VK_KHR_SWAPCHAIN_EXTENSION_NAME = "VK_KHR_swapchain";
public static FixedUtf8String VK_EXT_DEBUG_REPORT_EXTENSION_NAME = "VK_EXT_debug_report";
public static FixedUtf8String StandardValidationLayeName = "VK_LAYER_LUNARG_standard_validation";
public static FixedUtf8String main = "main";
}
}

View file

@ -0,0 +1,14 @@
namespace OpenTK.Graphics.Vulkan
{
public static class VulkanStrings
{
public static NativeString VK_KHR_SURFACE_EXTENSION_NAME = "VK_KHR_surface";
public static NativeString VK_KHR_WIN32_SURFACE_EXTENSION_NAME = "VK_KHR_win32_surface";
public static NativeString VK_KHR_XCB_SURFACE_EXTENSION_NAME = "VK_KHR_xcb_surface";
public static NativeString VK_KHR_XLIB_SURFACE_EXTENSION_NAME = "VK_KHR_xlib_surface";
public static NativeString VK_KHR_SWAPCHAIN_EXTENSION_NAME = "VK_KHR_swapchain";
public static NativeString VK_EXT_DEBUG_REPORT_EXTENSION_NAME = "VK_EXT_debug_report";
public static NativeString StandardValidationLayerName = "VK_LAYER_LUNARG_standard_validation";
public static NativeString main = "main";
}
}

View file

@ -1,10 +1,10 @@
namespace OpenTK.Graphics.Vulkan namespace OpenTK.Graphics.Vulkan
{ {
public struct Version public struct VulkanVersion
{ {
private readonly uint value; private readonly uint value;
public Version(uint major, uint minor, uint patch) public VulkanVersion(uint major, uint minor, uint patch)
{ {
value = major << 22 | minor << 12 | patch; value = major << 22 | minor << 12 | patch;
} }
@ -15,7 +15,7 @@
public uint Patch => (value >> 22) & 0xfff; public uint Patch => (value >> 22) & 0xfff;
public static implicit operator uint(Version version) public static implicit operator uint(VulkanVersion version)
{ {
return version.value; return version.value;
} }

View file

@ -50,7 +50,7 @@ namespace OpenTK
private bool events; private bool events;
private bool previous_cursor_visible = true; private bool previous_cursor_visible = true;
public VkResult CreateVulkanSurface(VkInstance instance, out VkSurfaceKHR surface) public unsafe VkResult CreateVulkanSurface(VkInstance instance, out VkSurfaceKHR surface)
{ {
IPlatformFactory factory = Factory.Default; IPlatformFactory factory = Factory.Default;
@ -62,9 +62,24 @@ namespace OpenTK
return VK.CreateWin32SurfaceKHR(instance, ref createInfo, IntPtr.Zero, out surface); return VK.CreateWin32SurfaceKHR(instance, ref createInfo, IntPtr.Zero, out surface);
} }
else if (implementation is Platform.X11.X11GLNative x11)
{
Platform.X11.X11WindowInfo info = x11.WindowInfo as Platform.X11.X11WindowInfo;
Graphics.Vulkan.Xlib.Window window = new Graphics.Vulkan.Xlib.Window();
window.Value = info.WindowHandle;
VkXlibSurfaceCreateInfoKHR createInfo = VkXlibSurfaceCreateInfoKHR.New();
createInfo.dpy = (Graphics.Vulkan.Xlib.Display*)info.Display;
createInfo.window = window;
return VK.CreateXlibSurfaceKHR(instance, &createInfo, IntPtr.Zero, out surface);
}
else else
{ {
throw new NotImplementedException(); //If someone knows how to create a MoltenVK surface, please add it here
throw new NotImplementedException(implementation.ToString());
} }
} }
@ -72,11 +87,15 @@ namespace OpenTK
{ {
if (implementation is Platform.Windows.WinGLNative win) if (implementation is Platform.Windows.WinGLNative win)
{ {
return new IntPtr[] { Strings.VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; return new IntPtr[] { VulkanStrings.VK_KHR_WIN32_SURFACE_EXTENSION_NAME };
}
else if (implementation is Platform.X11.X11GLNative x11)
{
return new IntPtr[] { VulkanStrings.VK_KHR_XLIB_SURFACE_EXTENSION_NAME };
} }
else else
{ {
throw new NotImplementedException(); throw new NotImplementedException(implementation.ToString());
} }
} }

View file

@ -3,7 +3,7 @@
<AssemblyName>OpenTK</AssemblyName> <AssemblyName>OpenTK</AssemblyName>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>OpenTK</RootNamespace> <RootNamespace>OpenTK</RootNamespace>
<DefineConstants>$(DefineConstants);WIN32;CARBON;X11;SDL2;OPENGL;OPENGLES;MINIMAL</DefineConstants> <DefineConstants>$(DefineConstants);WIN32;CARBON;X11;OPENGL;OPENGLES;MINIMAL</DefineConstants>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
@ -68,8 +68,8 @@
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.2</Version> <Version>1.1.7</Version>
<Description>The Open Toolkit library (OpenTK) is an advanced, low-level C# wrapper for OpenGL, OpenGL ES and OpenAL. <Description>The Open Toolkit library (OpenTK) is an advanced, low-level C# wrapper for OpenGL, OpenGL ES, OpenAL and Vulkan.
It is suitable for games, scientific visualizations and projects that require 3d graphics, audio or compute functionality. It is suitable for games, scientific visualizations and projects that require 3d graphics, audio or compute functionality.
Features Features
@ -83,7 +83,9 @@ This version can be found at https://github.com/emmauss/opentk</Description>
<Authors>emmaus</Authors> <Authors>emmaus</Authors>
<Company>emmaus</Company> <Company>emmaus</Company>
<Product>OpenTK</Product> <Product>OpenTK</Product>
<PackageProjectUrl>https://github.com/emmauss/opentk</PackageProjectUrl> <PackageProjectUrl>https://github.com/Ryujinx/Opentk</PackageProjectUrl>
<AssemblyVersion>1.1.7.0</AssemblyVersion>
<FileVersion>1.1.7.0</FileVersion>
</PropertyGroup> </PropertyGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="$(OutputPath)..\..\..\..\Generator.Rewrite\bin\Debug\Rewrite.exe --assembly $(OutputPath)OpenTK.dll --signing-key ..\..\OpenTK.snk -debug -netstandard" Condition="$(OS) == 'Windows_NT' and $(Configuration) == 'Debug'" /> <Exec Command="$(OutputPath)..\..\..\..\Generator.Rewrite\bin\Debug\Rewrite.exe --assembly $(OutputPath)OpenTK.dll --signing-key ..\..\OpenTK.snk -debug -netstandard" Condition="$(OS) == 'Windows_NT' and $(Configuration) == 'Debug'" />

View file

@ -46,8 +46,9 @@ namespace OpenTK.Platform
Toolkit.Init(); Toolkit.Init();
// Create regular platform backend // Create regular platform backend
if (false) { }
#if SDL2 #if SDL2
if (Configuration.RunningOnSdl2) else if (Configuration.RunningOnSdl2)
{ {
Default = new SDL2.Sdl2Factory(); Default = new SDL2.Sdl2Factory();
} }

View file

@ -692,10 +692,10 @@ namespace OpenTK.Platform.X11
public int backing_store; public int backing_store;
public IntPtr backing_planes; public IntPtr backing_planes;
public IntPtr backing_pixel; public IntPtr backing_pixel;
public bool save_under; public int save_under;
public IntPtr event_mask; public IntPtr event_mask;
public IntPtr do_not_propagate_mask; public IntPtr do_not_propagate_mask;
public bool override_redirect; public int override_redirect;
public IntPtr colormap; public IntPtr colormap;
public IntPtr cursor; public IntPtr cursor;
} }
@ -719,7 +719,7 @@ namespace OpenTK.Platform.X11
public IntPtr backing_pixel; public IntPtr backing_pixel;
public byte save_under; public byte save_under;
public IntPtr colormap; public IntPtr colormap;
public bool map_installed; public int map_installed;
public MapState map_state; public MapState map_state;
public IntPtr all_event_masks; public IntPtr all_event_masks;
public IntPtr your_event_mask; public IntPtr your_event_mask;