Skip to content

[2.0] SDL windowing and input #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3246c9d
Initial commit of the SDL windowing backend
Perksey Aug 10, 2020
59e3953
Event processing
Perksey Aug 11, 2020
03b05d3
Base implementation of windowing
Perksey Aug 12, 2020
0259fdc
Initialize window-only flags as well
Perksey Aug 12, 2020
7048b37
Rearrange SdlView a bit
Perksey Aug 12, 2020
b3c9da7
SDL input groundwork
Perksey Aug 12, 2020
f956b25
SDL input backend
Perksey Aug 13, 2020
8d13e29
Fix a bug with 0 FPS (as fast as possible), reformat code
Perksey Aug 13, 2020
0d09671
Fix a bug with raw mouse motion
Perksey Aug 14, 2020
f10a939
Apply suggestions from code review
Perksey Aug 16, 2020
8bb7ae5
Update src/Windowing/Silk.NET.Windowing.Sdl/SdlWindow.cs
Perksey Aug 16, 2020
f2502b2
InternalsVisibleTo into csproj
Perksey Aug 16, 2020
802e8c7
Update src/Input/Silk.NET.Input.Sdl/SdlCursor.cs
Perksey Aug 16, 2020
5abd955
Pull up. Pull up. Terrain. Terrain.
Perksey Aug 16, 2020
1edaa2a
Merge remote-tracking branch 'origin/feature/sdl-windowing' into feat…
Perksey Aug 16, 2020
8f7fa6c
Rename the backing member for Speed
Perksey Aug 16, 2020
25d9f93
SDL remarks
Perksey Aug 16, 2020
41a0316
New interop is merged!!!!
Perksey Aug 16, 2020
bf5f3c8
Regenerate bindings
Perksey Aug 16, 2020
b693ea5
Fix some Vulkan-related stuff
Perksey Aug 16, 2020
eb07c8c
Fix some errors
Perksey Aug 16, 2020
14dce3a
Some SilkTouch fixes
Perksey Aug 16, 2020
0125a22
Correctly Marshal String returns
HurricanKai Aug 16, 2020
207e512
Merge remote-tracking branch 'origin/feature/sdl-windowing' into feat…
Perksey Aug 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions Silk.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch", "src\C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SDL", "src\Windowing\Silk.NET.SDL\Silk.NET.SDL.csproj", "{F16EDD0F-5ABE-4B25-98EE-8397E55B5CBA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Windowing.Sdl", "src\Windowing\Silk.NET.Windowing.Sdl\Silk.NET.Windowing.Sdl.csproj", "{FF526329-094A-4B25-ABC5-750D62E48101}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Input.Sdl", "src\Input\Silk.NET.Input.Sdl\Silk.NET.Input.Sdl.csproj", "{377A7D9A-2691-4683-AB81-03B1642B3A78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1823,6 +1827,30 @@ Global
{F16EDD0F-5ABE-4B25-98EE-8397E55B5CBA}.Release|x64.Build.0 = Release|Any CPU
{F16EDD0F-5ABE-4B25-98EE-8397E55B5CBA}.Release|x86.ActiveCfg = Release|Any CPU
{F16EDD0F-5ABE-4B25-98EE-8397E55B5CBA}.Release|x86.Build.0 = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|x64.ActiveCfg = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|x64.Build.0 = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|x86.ActiveCfg = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Debug|x86.Build.0 = Debug|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|Any CPU.Build.0 = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|x64.ActiveCfg = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|x64.Build.0 = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|x86.ActiveCfg = Release|Any CPU
{FF526329-094A-4B25-ABC5-750D62E48101}.Release|x86.Build.0 = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|x64.ActiveCfg = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|x64.Build.0 = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|x86.ActiveCfg = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Debug|x86.Build.0 = Debug|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|Any CPU.ActiveCfg = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|Any CPU.Build.0 = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|x64.ActiveCfg = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|x64.Build.0 = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|x86.ActiveCfg = Release|Any CPU
{377A7D9A-2691-4683-AB81-03B1642B3A78}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
Expand Down Expand Up @@ -1958,6 +1986,8 @@ Global
{00D8F04F-2063-4F4E-B793-0F9DCF2BCFA9} = {23324041-2076-477C-A4BF-B385B8066C6C}
{6B703607-0D63-4A25-BB6A-EC1FBBD77A8C} = {0651C5EF-50AA-4598-8D9C-8F210ADD8490}
{F16EDD0F-5ABE-4B25-98EE-8397E55B5CBA} = {23324041-2076-477C-A4BF-B385B8066C6C}
{FF526329-094A-4B25-ABC5-750D62E48101} = {23324041-2076-477C-A4BF-B385B8066C6C}
{377A7D9A-2691-4683-AB81-03B1642B3A78} = {FA9D1C95-5585-4DEC-B226-1447A486C376}
EndGlobalSection
EndGlobalSection
EndGlobal
Binary file modified build/cache/cl.json.gz
Binary file not shown.
Binary file modified build/cache/gl.json.gz
Binary file not shown.
Binary file modified build/cache/glcore.json.gz
Binary file not shown.
Binary file modified build/cache/gles2.json.gz
Binary file not shown.
Binary file modified build/cache/openxr.json.gz
Binary file not shown.
Binary file modified build/cache/sdl.json.gz
Binary file not shown.
Binary file modified build/cache/vulkan.json.gz
Binary file not shown.
21 changes: 14 additions & 7 deletions generator.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@
{
"profileName": "SDL",
"sources": [
"build/submodules/SDL-mirror/include/SDL.h"
"build/submodules/SDL-mirror/include/SDL.h",
"build/submodules/SDL-mirror/include/SDL_vulkan.h"
],
"mode": "Clang",
"cacheDir": "build/cache",
Expand Down Expand Up @@ -550,10 +551,13 @@
"build/submodules/SDL-mirror/include/*.h"
],
"classes": {
"SDL.h": "[Core]SDL"
"SDL.h": "[Core]Sdl",
"SDL_vulkan.h": "[Core]Sdl"
}
},
"exclude": [
"VkSurfaceKHR",
"VkInstance"
],
"rename": {
"__AnonymousEnum_SDL_shape_L80_C9": "WindowShapeModeVal",
Expand All @@ -569,7 +573,8 @@
},
"bakery": {
"profileNames": [
"SDL"
"SDL",
"SDL_vulkan"
]
},
"output": {
Expand All @@ -581,11 +586,11 @@
"namespace": "Silk.NET.SDL",
"extensionsNamespace": "Silk.NET.SDL.Extensions",
"nameContainer": {
"linux-x64": "libSDL2-2.0.so.0",
"linux-x64": "libSDL2-2.0.so",
"win-x64": "SDL2.dll",
"win-x86": "SDL2.dll",
"osx-x64": "libSDL2-2.0.0.dylib",
"android": "libSDL2-2.0.so.0",
"osx-x64": "libSDL2-2.0.dylib",
"android": "libSDL2-2.0.so",
"iOS": "__Internal",
"className": "SDLLibraryNameContainer"
},
Expand All @@ -594,7 +599,9 @@
"$typemapPrecedesInjections": "true",
"WindowShapeMode": "WindowShapeModeVal",
"SDL_bool": "SdlBool",
"SDL_RWops": "RWops"
"SDL_RWops": "RWops",
"VkInstance": "Silk.NET.Core.Native.VkHandle",
"VkSurfaceKHR": "Silk.NET.Core.Native.VkNonDispatchableHandle"
},
{
"$include.commonTypeMap": "build/csharp_typemap.json"
Expand Down
6 changes: 5 additions & 1 deletion src/Core/Silk.NET.BuildTools/Cpp/Clang.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ void VisitDecls(IEnumerable<Decl> decls)
{
foreach (var decl in decls)
{
if (task.ClangOpts.Traverse.Length == 0)
if (decl.Location.IsFromMainFile)
{
Visit(decl);
}
else if (task.ClangOpts.Traverse.Length == 0)
{
if (!decl.Location.IsFromMainFile)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.Core/Contexts/IVkSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IVkSurface
/// <param name="allocator">A custom Vulkan allocator. Can be omitted by passing null.</param>
/// <typeparam name="T">Allocator type</typeparam>
/// <returns>A handle to the Vulkan surface created</returns>
unsafe VkHandle Create<T>(VkHandle instance, T* allocator) where T : unmanaged;
unsafe VkNonDispatchableHandle Create<T>(VkHandle instance, T* allocator) where T : unmanaged;

/// <summary>
/// Get the extensions required for Vulkan to work on this platform.
Expand Down
58 changes: 58 additions & 0 deletions src/Core/Silk.NET.Core/Miscellaneous/PlatformException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;

namespace Silk.NET.Core
{
/// <summary>
/// An exception thrown when an underlying native platform fails to complete an operation due to an error.
/// </summary>
public class PlatformException : Exception
{
private const string DefaultMessage =
"The operation could not be completed due to an error in an underlying native platform.";
/// <summary>
/// Creates an instance of this exception with the default message.
/// </summary>
public PlatformException() : base(DefaultMessage)
{
}

/// <summary>
/// Creates an instance of this exception with the given message.
/// </summary>
/// <param name="msg">The message.</param>
public PlatformException(string msg) : base(msg)
{
}

/// <summary>
/// Creates an instance of this exception with the given inner exception.
/// </summary>
/// <param name="innerException">The inner exception.</param>
public PlatformException(Exception innerException) : base(DefaultMessage, innerException)
{
}

/// <summary>
/// Creates an instance of this exception with the given message and inner exception.
/// </summary>
/// <param name="msg">The message.</param>
/// <param name="innerException">The inner exception.</param>
public PlatformException(string msg, Exception innerException) : base(msg, innerException)
{
}

/// <summary>
/// Creates an instance of this exception with the given message and inner exceptions.
/// </summary>
/// <param name="msg">The message.</param>
/// <param name="inner">The inner exceptions.</param>
public PlatformException(string msg, params Exception[] inner) : base(msg, new AggregateException(inner))
{
}
}
}
34 changes: 34 additions & 0 deletions src/Core/Silk.NET.Core/Native/VkNonDispatchableHandle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// This file is part of Silk.NET.
//
// You may modify and distribute Silk.NET under the terms
// of the MIT license. See the LICENSE file for details.

using System;
using System.Runtime.InteropServices;

namespace Silk.NET.Core.Native
{
/// <summary>
/// A handle to a Vulkan object.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct VkNonDispatchableHandle
{
/// <summary>
/// The actual value of the Vulkan handle.
/// </summary>
public ulong Handle;

/// <summary>
/// Initializes a new instance of the <see cref="VkNonDispatchableHandle" /> struct.
/// </summary>
/// <param name="handle">
/// The native Vulkan handle.
/// This is NOT a pointer to a field containing the handle, this is the actual handle itself.
/// </param>
public VkNonDispatchableHandle(ulong handle)
{
Handle = handle;
}
}
}
2 changes: 1 addition & 1 deletion src/Core/Silk.NET.SilkTouch/NativeApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void Execute(SourceGeneratorContext context)

var name = $"{receiverClassDeclaration.Identifier.Text}.{receiverClassDeclaration.GetHashCode()}.gen";
context.AddSource(name, SourceText.From(s, Encoding.UTF8));
File.WriteAllText(name, s);
// File.WriteAllText(name, s);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/Core/Silk.NET.SilkTouch/Silk.NET.SilkTouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
</PropertyGroup>

<PropertyGroup>
<RestoreAdditionalProjectSources>https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json ;$(RestoreAdditionalProjectSources)</RestoreAdditionalProjectSources>
<RestoreAdditionalProjectSources>
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json;
https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json;
$(RestoreAdditionalProjectSources)
</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.7.0-4.20351.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.7.0-6.20412.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" PrivateAssets="all" />
<Compile Include="..\Silk.NET.Core\Native\NativeApiAttribute.cs" />
</ItemGroup>
Expand Down
56 changes: 55 additions & 1 deletion src/Core/Silk.NET.SilkTouch/StringMarshaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,62 @@ private static void StringMarshaller(ref MarshalContext ctx, Action next)
}
}

var marshalReturn = !ctx.ReturnsVoid && SymbolEqualityComparer.Default.Equals(ctx.ReturnLoadType, @string);
var returnName = $"smo{ctx.Slot}res";
var returnMarshalAs = ctx.ReturnMarshalOptions?.MarshalAs ?? UnmanagedType.LPStr;
if (marshalReturn)
{
ctx.DeclareVariable(@string, returnName);
ctx.ReturnLoadType = ctx.Compilation.CreatePointerTypeSymbol
(
returnMarshalAs switch
{
UnmanagedType.BStr => ctx.Compilation.GetSpecialType(SpecialType.System_Char),
UnmanagedType.LPWStr => ctx.Compilation.GetSpecialType(SpecialType.System_Char),
UnmanagedType.LPStr => ctx.Compilation.GetSpecialType(SpecialType.System_Byte),
UnmanagedType.LPTStr => ctx.Compilation.GetSpecialType(SpecialType.System_Byte),
}
);
}
next();


if (marshalReturn)
{
ctx.CurrentStatements = ctx.CurrentStatements.Append
(
ExpressionStatement
(
AssignmentExpression
(
SyntaxKind.SimpleAssignmentExpression, IdentifierName(returnName),
InvocationExpression
(
_stringFromPtr[returnMarshalAs],
ArgumentList
(
SingletonSeparatedList
(
Argument
(
CastExpression
(
IdentifierName
(
ctx.Compilation.GetSpecialType
(SpecialType.System_IntPtr)
.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
), ctx.ResultExpression
)
)
)
)
)
)
)
);
ctx.ResultExpression = IdentifierName(returnName);
}

for (var index = 0; index < ctx.ParameterExpressions.Length; index++)
{
if (b[index]) continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Silk.NET/Silk.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Input\Silk.NET.Input\Silk.NET.Input.csproj" />
<ProjectReference Include="..\..\OpenAL\Silk.NET.OpenAL\Silk.NET.OpenAL.csproj" />
<ProjectReference Include="..\..\OpenGL\Silk.NET.OpenGL\Silk.NET.OpenGL.csproj" />
<ProjectReference Include="..\..\Vulkan\Silk.NET.Vulkan\Silk.NET.Vulkan.csproj" />
<!-- Include KHR because you need KHR_surface in pretty much all cases -->
<ProjectReference Include="..\..\Vulkan\Extensions\Silk.NET.Vulkan.Extensions.KHR\Silk.NET.Vulkan.Extensions.KHR.csproj" />
<ProjectReference Include="..\..\Windowing\Silk.NET.GLFW\Silk.NET.GLFW.csproj" />
<ProjectReference Include="..\..\Windowing\Silk.NET.Windowing.Common\Silk.NET.Windowing.Common.csproj" />
<ProjectReference Include="..\..\Windowing\Silk.NET.Windowing\Silk.NET.Windowing.csproj" />
<ProjectReference Include="..\..\Input\Silk.NET.Input\Silk.NET.Input.csproj" />
<ProjectReference Include="..\Silk.NET.Core\Silk.NET.Core.csproj" />
</ItemGroup>

Expand Down
Loading