Skip to content

Commit

Permalink
Update packages and use own SDL3 bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkoleci committed Aug 27, 2024
1 parent 22b93b2 commit 9095412
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<PropertyGroup Condition=" '$(_AlimerTargetPlatformIsWinUI)' == 'True' ">
<SupportedOSPlatformVersion>10.0.19043.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion>10.0.19043.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion>10.0.22621.35-preview</WindowsSdkPackageVersion>
<WindowsSdkPackageVersion>10.0.22621.38</WindowsSdkPackageVersion>

<Platforms>x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x64;win-arm64</RuntimeIdentifiers>
Expand Down
18 changes: 9 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<Project>
<!-- Package versions for package references across all projects -->
<PropertyGroup>
<VorticeWin32Version>2.2.5</VorticeWin32Version>
<VorticeWin32Version>2.2.6</VorticeWin32Version>
<TerraFXWindowsVersion>10.0.26100</TerraFXWindowsVersion>
<ImGuiVersion>2.0.1</ImGuiVersion>
<ImGuiVersion>2.1.1</ImGuiVersion>
<SkiaSharpVersion>3.0.0-preview.4.1</SkiaSharpVersion>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.2.2" />
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.3.0" />

<!-- Platform specific -->
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.6.240701003-experimental2" />
<PackageVersion Include="Microsoft.Graphics.Win2D" Version="1.2.1-experimental1" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.6.240821007-preview2" />
<PackageVersion Include="Microsoft.Graphics.Win2D" Version="1.2.1-experimental2" />

<!-- Engine -->
<PackageVersion Include="Vortice.Mathematics" Version="1.8.0" />
<PackageVersion Include="Vortice.Mathematics" Version="1.9.2" />
<PackageVersion Include="Vortice.Win32.Graphics.Dxgi" Version="$(VorticeWin32Version)" />
<PackageVersion Include="Vortice.Win32.Graphics.Direct3D11" Version="$(VorticeWin32Version)" />
<PackageVersion Include="Vortice.Win32.Graphics.Direct3D12" Version="$(VorticeWin32Version)" />
<PackageVersion Include="XenoAtom.Collections" Version="1.1.0" />
<PackageVersion Include="ppy.SDL3-CS" Version="2024.731.0" />
<PackageVersion Include="Alimer.Bindings.SDL" Version="3.7.2" />
<PackageVersion Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
<PackageVersion Include="StbImageSharp" Version="2.27.14" />
<PackageVersion Include="Alimer.Bindings.WebGPU" Version="1.4.3" />
<PackageVersion Include="TerraFX.Interop.Windows" Version="$(TerraFXWindowsVersion)" />
<PackageVersion Include="TerraFX.Interop.D3D12MemoryAllocator" Version="2.0.1.5" />
<PackageVersion Include="Vortice.Vulkan" Version="1.9.5" />
<PackageVersion Include="JoltPhysicsSharp" Version="2.5.10" />
<PackageVersion Include="JoltPhysicsSharp" Version="2.7.1" />
<PackageVersion Include="DotRecast.Recast" Version="2024.3.1" />

<PackageVersion Include="Hexa.NET.ImGui" Version="$(ImGuiVersion)" />
Expand All @@ -36,7 +36,7 @@
<PackageVersion Include="Hexa.NET.ImPlot" Version="$(ImGuiVersion)" />

<!-- Asset Pipeline -->
<PackageVersion Include="Vortice.Dxc.Native" Version="1.0.1" />
<PackageVersion Include="Vortice.Dxc.Native" Version="1.0.2" />
<PackageVersion Include="Vortice.Win32.Graphics.Direct3D.Dxc" Version="$(VorticeWin32Version)" />
<PackageVersion Include="SkiaSharp" Version="$(SkiaSharpVersion)" />
<PackageVersion Include="SkiaSharp.HarfBuzz" Version="$(SkiaSharpVersion)" />
Expand Down
4 changes: 2 additions & 2 deletions samples/Alimer.Samples/Graphics/DrawMeshSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public DrawMeshSample(IServiceRegistry services, Window mainWindow)
MeshImporter meshImporter = new();
MeshAsset meshAsset = meshImporter.Import(Path.Combine(meshesPath, "DamagedHelmet.glb"), Services).Result;

Span<VertexPositionNormalTexture> vertices = new VertexPositionNormalTexture[meshAsset.Data.VertexCount];
Span<VertexPositionNormalTexture> vertices = stackalloc VertexPositionNormalTexture[meshAsset.Data!.VertexCount];
for (int i = 0; i < meshAsset.Data.VertexCount; i++)
{
vertices[i] = new VertexPositionNormalTexture(meshAsset.Data.Positions[i], meshAsset.Data.Normals[i], meshAsset.Data.Texcoords[i]);
Expand All @@ -56,7 +56,7 @@ public DrawMeshSample(IServiceRegistry services, Window mainWindow)
//_indexBuffer = ToDispose(GraphicsDevice.CreateBuffer(data.Indices, BufferUsage.Index));
_vertexBuffer = ToDispose(GraphicsDevice.CreateBuffer(vertices, BufferUsage.Vertex));
_indexBuffer = ToDispose(GraphicsDevice.CreateBuffer(meshAsset.Data.Indices!.AsSpan(), BufferUsage.Index));
_indexCount = (uint)meshAsset.Data.Indices.Length;
_indexCount = (uint)meshAsset.Data!.Indices.Length;

_constantBuffer = ToDispose(GraphicsDevice.CreateBuffer((ulong)sizeof(Matrix4x4), BufferUsage.Constant, CpuAccessMode.Write));

Expand Down
2 changes: 1 addition & 1 deletion samples/Alimer.Samples/GraphicsSampleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected GraphicsBuffer CreateBuffer<T>(List<T> initialData,
return GraphicsDevice.CreateBuffer(dataSpan, usage, cpuAccess);
}

protected Stream OpenEmbeddedAssetStream(string name) => typeof(GraphicsSampleBase).Assembly!.GetManifestResourceStream(name);
protected Stream OpenEmbeddedAssetStream(string name) => typeof(GraphicsSampleBase).Assembly!.GetManifestResourceStream(name)!;
protected byte[] ReadEmbeddedAssetBytes(string name)
{
using Stream stream = OpenEmbeddedAssetStream(name);
Expand Down
2 changes: 1 addition & 1 deletion src/Alimer.Applications/Alimer.Applications.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(_AlimerNoTargetPlatform)' == 'True' ">
<PackageReference Include="ppy.SDL3-CS" />
<PackageReference Include="Alimer.Bindings.SDL" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/Alimer.Applications/Platforms/Standard/SDLClipboard.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using static SDL.SDL3;
using static SDL3.SDL3;

namespace Alimer.Input;

partial class ClipboardImplementation : IClipboard
{
public bool HasText => SDL_HasClipboardText() == SDL_TRUE;
public bool HasText => SDL_HasClipboardText();

public Task<string?> GetTextAsync()
{
Expand Down
25 changes: 11 additions & 14 deletions src/Alimer.Applications/Platforms/Standard/SDLPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.

using Alimer.Input;
using static SDL.SDL3;
using SDL;
using static SDL3.SDL3;
using SDL3;
using System.Runtime.InteropServices;
using static SDL.SDL_EventType;
using System.Runtime.CompilerServices;

namespace Alimer;
Expand All @@ -24,7 +23,7 @@ public SDLPlatform()
{
//SDL_LogSetPriority(SDL_LogCategory.Error, SDL_LogPriority.Debug);
//SDL_LogSetPriority(SDL_LogCategory.SDL_LOG_CATEGORY_ERROR, SDL_LogPriority.SDL_LOG_PRIORITY_DEBUG);
SDL_SetLogOutputFunction(&OnLog, IntPtr.Zero);
SDL_SetLogOutputFunction(OnLog);

int version = SDL_GetVersion();
string? revision = SDL_GetRevision();
Expand All @@ -34,15 +33,15 @@ public SDLPlatform()
SDL_VERSIONNUM_MICRO(version));

// Init SDL3
if (SDL_Init(SDL_InitFlags.SDL_INIT_VIDEO | SDL_InitFlags.SDL_INIT_TIMER | SDL_InitFlags.SDL_INIT_GAMEPAD) != 0)
if (SDL_Init(SDL_InitFlags.Video | SDL_InitFlags.Timer | SDL_InitFlags.Gamepad) != 0)
{
Log.Error($"Unable to initialize SDL: {SDL_GetError()}");
throw new Exception("");
}

Log.Info($@"SDL3 Initialized
SDL3 Version: {SDL_VERSIONNUM_MAJOR(version)}.{SDL_VERSIONNUM_MINOR(version)}.{SDL_VERSIONNUM_MICRO(version)}
SDL3 Revision: {SDL3.SDL_GetRevision()}"
SDL3 Revision: {SDL_GetRevision()}"
);

_input = new SDLInput(this);
Expand Down Expand Up @@ -104,7 +103,7 @@ private void PollEvents()

do
{
eventsRead = SDL_PeepEvents(_events, SDL_EventAction.SDL_GETEVENT, SDL_EventType.SDL_EVENT_FIRST, SDL_EventType.SDL_EVENT_LAST);
eventsRead = SDL_PeepEvents(_events, SDL_EventAction.GetEvent, SDL_EventType.First, SDL_EventType.Last);
for (int i = 0; i < eventsRead; i++)
{
HandleSDLEvent(_events[i]);
Expand All @@ -114,22 +113,22 @@ private void PollEvents()

private void HandleSDLEvent(SDL_Event evt)
{
if (evt.Type >= SDL_EventType.SDL_EVENT_DISPLAY_FIRST && evt.Type <= SDL_EventType.SDL_EVENT_DISPLAY_LAST)
if (evt.type >= SDL_EventType.DisplayFirst && evt.type <= SDL_EventType.DisplayLast)
{
HandleDisplayEvent(evt.display);
return;
}

if (evt.Type >= SDL_EventType.SDL_EVENT_WINDOW_FIRST && evt.Type <= SDL_EventType.SDL_EVENT_WINDOW_LAST)
if (evt.type >= SDL_EventType.WindowFirst && evt.type <= SDL_EventType.WindowLast)
{
HandleWindowEvent(in evt.window);
return;
}

switch (evt.type)
{
case (uint)SDL_EVENT_QUIT:
case (uint)SDL_EVENT_TERMINATING:
case SDL_EventType.Quit:
case SDL_EventType.Terminating:
_exitRequested = true;
break;
}
Expand All @@ -154,10 +153,8 @@ internal void WindowClosed(SDL_WindowID windowID)
_idLookup.Remove(windowID);
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
private static void OnLog(IntPtr _, SDL_LogCategory category, SDL_LogPriority priority, byte* messagePtr)
private static void OnLog(SDL_LogCategory category, SDL_LogPriority priority, string? message)
{
string? message = PtrToStringUTF8(messagePtr);
Log.Info($"SDL: {message}");
}
}
35 changes: 16 additions & 19 deletions src/Alimer.Applications/Platforms/Standard/SDLWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
using Vortice.Mathematics;
using Alimer.Graphics;
using System.Runtime.InteropServices;
using static SDL.SDL3;
using static SDL.SDL_EventType;
using SDL;
using static SDL3.SDL3;
using SDL3;

namespace Alimer;

Expand All @@ -17,44 +16,43 @@ internal unsafe class SDLWindow : Window
private bool _minimized;
private bool _isFullscreen;

public readonly SDL_Window* SDLWindowHandle;
public readonly SDL_Window SDLWindowHandle;
public readonly SDL_WindowID Id;

public SDLWindow(SDLPlatform platform, WindowFlags flags)
{
_platform = platform;

SDL_WindowFlags sdlWindowFlags = SDL_WindowFlags.SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL_WindowFlags.SDL_WINDOW_VULKAN;
SDL_WindowFlags sdlWindowFlags = SDL_WindowFlags.HighPixelDensity | SDL_WindowFlags.Hidden | SDL_WindowFlags.Vulkan;

if ((flags & WindowFlags.Borderless) != 0)
sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_BORDERLESS;
sdlWindowFlags |= SDL_WindowFlags.Borderless;

if ((flags & WindowFlags.Resizable) != 0)
sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
sdlWindowFlags |= SDL_WindowFlags.Resizable;

if ((flags & WindowFlags.Fullscreen) != 0)
{
sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
sdlWindowFlags |= SDL_WindowFlags.Fullscreen;
_isFullscreen = true;
}

if ((flags & WindowFlags.Maximized) != 0)
{
sdlWindowFlags |= SDL_WindowFlags.SDL_WINDOW_MAXIMIZED;
sdlWindowFlags |= SDL_WindowFlags.Maximized;
}

_title = "Alimer";
SDLWindowHandle = SDL_CreateWindow((Utf8String)_title, 1200, 800, sdlWindowFlags);
if (SDLWindowHandle == null)
SDLWindowHandle = SDL_CreateWindow(_title, 1200, 800, sdlWindowFlags);
if (SDLWindowHandle.IsNull)
{
Log.Error($"SDL_CreateWindow Failed: {SDL_GetError()}");
return;
}

Id = SDL_GetWindowID(SDLWindowHandle);
SDL_SetWindowPosition(SDLWindowHandle, (int)SDL_WINDOWPOS_CENTERED, (int)SDL_WINDOWPOS_CENTERED);
int width, height;
SDL_GetWindowSizeInPixels(SDLWindowHandle, &width, &height);
SDL_SetWindowPosition(SDLWindowHandle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_GetWindowSizeInPixels(SDLWindowHandle, out int width, out int height);
_clientSize = new(width, height);

// Native handle
Expand Down Expand Up @@ -116,7 +114,7 @@ public override bool IsFullscreen
if (_isFullscreen != value)
{
_isFullscreen = value;
SDL_SetWindowFullscreen(SDLWindowHandle, value ? SDL_TRUE : SDL_FALSE);
SDL_SetWindowFullscreen(SDLWindowHandle, value);
}
}
}
Expand All @@ -126,8 +124,7 @@ public override Int2 Position
{
get
{
int x, y;
_ = SDL_GetWindowPosition(SDLWindowHandle, &x, &y);
_ = SDL_GetWindowPosition(SDLWindowHandle, out int x, out int y);
return new Int2(x, y);
}
set
Expand All @@ -150,12 +147,12 @@ public override Int2 Position

public void Show()
{
SDL_ShowWindow(SDLWindowHandle);
_ = SDL_ShowWindow(SDLWindowHandle);
}

protected override void SetTitle(string title)
{
SDL_SetWindowTitle(SDLWindowHandle, title);
_ = SDL_SetWindowTitle(SDLWindowHandle, title);
}

public void HandleEvent(in SDL_WindowEvent evt)
Expand Down
7 changes: 6 additions & 1 deletion src/Alimer.Physics/PhysicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ public override void Update(AppTime time)
[ModuleInitializer]
public static void Initialize()
{
if (Foundation.Init() == false)
if (Foundation.Init(false) == false)
{
throw new InvalidOperationException("[JoltPhysics] Failed to initialize Foundation");
}

Foundation.SetTraceHandler((message) =>
{
Log.Trace(message);
});

#if DEBUG
Foundation.SetAssertFailureHandler((inExpression, inMessage, inFile, inLine) =>
{
Expand Down
14 changes: 7 additions & 7 deletions src/Alimer.Physics/RigidBodyComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public MotionType MotionType
return;

_motionType = value;
if (Handle != null)
if (Handle.IsNotNull)
{
Handle.MotionType = value.ToJolt();
}
Expand Down Expand Up @@ -58,7 +58,7 @@ public float Mass
_mass = value;

// TODO: Update Jolt mass?
if(Handle != null)
if(Handle.IsNotNull)
{
}
}
Expand All @@ -68,28 +68,28 @@ public override Matrix4x4 PhysicsWorldTransform
{
get
{
if (Handle is null)
if (Handle.IsNull)
return Matrix4x4.Identity;

return Handle.GetWorldTransform();
}
set
{
// TODO: Update Jolt WorldTransform?
if (Handle != null)
if (Handle.IsNotNull)
{
}
}
}

internal Body? Handle { get; private set; }
internal Body Handle;
internal BodyID BodyID { get; private set; }

protected override void OnAttach()
{
base.OnAttach();

if (Handle != null)
if (Handle.IsNotNull)
{
Simulation!.BodyInterface.DestroyBody(Handle.ID);
}
Expand All @@ -113,7 +113,7 @@ protected override void OnAttach()

// Add it to the world
bodyInterface.AddBody(Handle, (MotionType == MotionType.Static) ? Activation.DontActivate : Activation.Activate);
Simulation.RigidBodies.Add(BodyID, this);
Simulation.RigidBodies.Add(BodyID, this);
}

protected override void OnDetach()
Expand Down
4 changes: 2 additions & 2 deletions src/Alimer.Rendering/MeshData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Alimer.Rendering;

public sealed class MeshData
public struct MeshData
{
public MeshData()
{
Expand All @@ -17,7 +17,7 @@ public MeshData()
/// </summary>
public int VertexCount { get; set; }

public Vector3[] Positions { get; set; } = [];
public required Vector3[] Positions { get; set; }
public Vector3[]? Normals { get; set; }
public Vector3[]? Tangents { get; set; }
public Vector2[]? Texcoords { get; set; }
Expand Down
Loading

0 comments on commit 9095412

Please sign in to comment.