Skip to content

Commit 7a9dfec

Browse files
[Dependencies] Update SDL3-CS;
[Rendering] Enable Shader Draw Parameters Vulkan extension;
1 parent da85660 commit 7a9dfec

File tree

12 files changed

+173
-42
lines changed

12 files changed

+173
-42
lines changed

Dependencies/SDL3-CS/SDL/Audio/audio/PInvoke.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public static partial class SDL
175175
/// <code>extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);</code>
176176
/// <summary>
177177
/// Get the human-readable name of a specific audio device.
178+
/// <para><b>WARNING</b>: this function will work with <see cref="AudioDeviceDefaultPlayback"/>
179+
/// and <see cref="AudioDeviceDefaultRecording"/>, returning the current default
180+
/// physical devices' names. However, as the default device may change at any
181+
/// time, it is likely better to show a generic name to the user, like "System
182+
/// default audio device" or perhaps "default [currently %s]". Do not store
183+
/// this name to disk to reidentify the device in a later run of the program,
184+
/// as the default might change in general, and the string will be the name of
185+
/// a specific device and not the abstract system default.</para>
178186
/// </summary>
179187
/// <param name="devid">the instance ID of the device to query.</param>
180188
/// <returns>the name of the audio device, or <c>null</c> on failure; call

Dependencies/SDL3-CS/SDL/Basics/hints/Hints.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -641,21 +641,6 @@ public static class Hints
641641
/// <remarks>This hint should be set before creating a window.</remarks>
642642
/// <since>This hint is available since SDL 3.2.0</since>
643643
public const string EmscriptenKeyboardElement = "SDL_EMSCRIPTEN_KEYBOARD_ELEMENT";
644-
645-
646-
/// <summary>
647-
/// Dictate that newly-created windows will fill the whole browser window.
648-
/// <para>The canvas element fills the entire document. Resize events will be
649-
/// generated as the browser window is resized, as that will adjust the canvas
650-
/// size as well. The canvas will cover anything else on the page, including
651-
/// any controls provided by Emscripten in its generated HTML file. Often times
652-
/// this is desirable for a browser-based game, but it means several things
653-
/// that we expect of an SDL window on other platforms might not work as
654-
/// expected, such as minimum window sizes and aspect ratios.</para>
655-
/// <para>This hint overrides <see cref="Props.WindowCreateEMScriptenFillDocumentBoolean"/>
656-
/// properties when creating an SDL window.</para>
657-
/// </summary>
658-
public const string EmscriptenFillDocument = "SDL_EMSCRIPTEN_FILL_DOCUMENT";
659644

660645
/// <summary>
661646
/// <para>A variable that controls whether the on-screen keyboard should be shown
@@ -2221,6 +2206,21 @@ public static class Hints
22212206
/// <since>This hint is available since SDL 3.2.0</since>
22222207
public const string MouseDefaultSystemCursor = "SDL_MOUSE_DEFAULT_SYSTEM_CURSOR";
22232208

2209+
/// <summary>
2210+
/// <para>A variable setting whether we should scale cursors by the current display
2211+
/// scale.</para>
2212+
/// <para>The variable can be set to the following values:</para>
2213+
/// <list type="bullet">
2214+
/// <item><c>"0"</c>: Cursors will not change size based on the display content scale.
2215+
/// (default)</item>
2216+
/// <item><c>"1"</c>: Cursors will automatically match the display content scale (e.g. a
2217+
/// 2x sized cursor will be used when the window is on a monitor with 200%
2218+
/// scale). This is currently implemented on Windows and Wayland.</item>
2219+
/// </list>
2220+
/// </summary>
2221+
/// <remarks>This hint needs to be set before creating cursors.</remarks>
2222+
/// <since>This hint is available since SDL 3.4.0.</since>
2223+
public const string MouseDPIScaleCursors = "SDL_MOUSE_DPI_SCALE_CURSORS";
22242224

22252225
/// <summary>
22262226
/// <para>A variable controlling whether warping a hidden mouse cursor will activate

Dependencies/SDL3-CS/SDL/GPU/gpu/GPUVulkanOptions.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static partial class SDL
3232
/// <para>When no such structure is provided, SDL will use Vulkan API version 1.0 and
3333
/// a minimal set of features. The requested API version influences how the
3434
/// feature_list is processed by SDL. When requesting API version 1.0, the
35-
/// feature_list is ignored. Only the vulkan_10_phyisical_device_features and
35+
/// feature_list is ignored. Only the vulkan_10_physical_device_features and
3636
/// the extension lists are used. When requesting API version 1.1, the
3737
/// feature_list is scanned for feature structures introduced in Vulkan 1.1.
3838
/// When requesting Vulkan 1.2 or higher, the feature_list is additionally
@@ -42,6 +42,8 @@ public static partial class SDL
4242
/// </summary>
4343
/// <since>This struct is available since SDL 3.4.0.</since>
4444
/// <seealso cref="SetGPUViewport"/>
45+
/// <seealso cref="SDL.PointerToStringArray(System.IntPtr)"/>
46+
/// <seealso cref="SDL.StringArrayToPointer"/>
4547
[StructLayout(LayoutKind.Sequential)]
4648
public struct GPUVulkanOptions
4749
{
@@ -65,23 +67,19 @@ public struct GPUVulkanOptions
6567
/// </summary>
6668
public uint DeviceExtensionCount;
6769

68-
private IntPtr device_extension_names;
69-
7070
/// <summary>
71-
/// Number of additional instance extensions to require.
71+
/// Pointer to a list of additional device extensions to require.
7272
/// </summary>
73-
public uint InstanceExtensionCount;
73+
public IntPtr DeviceExtensionNames;
7474

75-
private IntPtr instance_extension_names;
76-
7775
/// <summary>
78-
/// Pointer to a list of additional device extensions to require.
76+
/// Number of additional instance extensions to require.
7977
/// </summary>
80-
public string[] DeviceExtensionNames => PointerToStringArray(device_extension_names)!;
78+
public uint InstanceExtensionCount;
8179

8280
/// <summary>
8381
/// Pointer to a list of additional instance extensions to require.
8482
/// </summary>
85-
public string[] InstanceExtensionNames => PointerToStringArray(instance_extension_names)!;
83+
public IntPtr InstanceExtensionNames;
8684
}
8785
}

Dependencies/SDL3-CS/SDL/GPU/gpu/PInvoke.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public partial class SDL
157157
/// provide your own fallback renderer (for example, an OpenGL renderer) this
158158
/// property can be set to true. Defaults to false.</item>
159159
/// <item><see cref="Props.GPUDeviceCreateVulkanOptionsPointer"/>: a pointer to an
160-
/// SDL_GPUVulkanOptions structure to be processed during device creation.
160+
/// <see cref="GPUVulkanOptions"/> structure to be processed during device creation.
161161
/// This allows configuring a variety of Vulkan-specific options such as
162162
/// increasing the API version and opting into extensions aside from the
163163
/// minimal set SDL requires.</item>
@@ -647,8 +647,9 @@ public static string GetGPUDriver(int index)
647647
/// <summary>
648648
/// <para>Inserts an arbitrary string label into the command buffer callstream.</para>
649649
/// <para>Useful for debugging.</para>
650-
/// <para>On Direct3D 12, using <see cref="InsertGPUDebugLabel"/> will cause validation errors
651-
/// unless you have WinPixEventRuntime.dll in your PATH. See
650+
/// <para>On Direct3D 12, using <see cref="InsertGPUDebugLabel"/> requires
651+
/// WinPixEventRuntime.dll to be in your PATH or in the same directory as your
652+
/// executable. See
652653
/// [here](https://devblogs.microsoft.com/pix/winpixeventruntime/)
653654
/// for instructions on how to obtain it.</para>
654655
/// </summary>
@@ -666,8 +667,8 @@ public static string GetGPUDriver(int index)
666667
/// callstream in a graphics debugging tool.</para>
667668
/// <para>Each call to <see cref="PushGPUDebugGroup"/> must have a corresponding call to
668669
/// <see cref="PopGPUDebugGroup"/>.</para>
669-
/// <para>On Direct3D 12, using <see cref="PushGPUDebugGroup"/> will cause validation errors
670-
/// unless you have WinPixEventRuntime.dll in your PATH. See
670+
/// <para>On Direct3D 12, using <see cref="PushGPUDebugGroup"/> requires WinPixEventRuntime.dll
671+
/// to be in your PATH or in the same directory as your executable. See
671672
/// [here](https://devblogs.microsoft.com/pix/winpixeventruntime/)
672673
/// for instructions on how to obtain it.</para>
673674
/// <para>On some backends (e.g. Metal), pushing a debug group during a
@@ -686,6 +687,10 @@ public static string GetGPUDriver(int index)
686687
/// <code>extern SDL_DECLSPEC void SDLCALL SDL_PopGPUDebugGroup(SDL_GPUCommandBuffer *command_buffer);</code>
687688
/// <summary>
688689
/// Ends the most-recently pushed debug group.
690+
/// <para>On Direct3D 12, using <see cref="PopGPUDebugGroup"/> requires WinPixEventRuntime.dll
691+
/// to be in your PATH or in the same directory as your executable. See
692+
/// [here](https://devblogs.microsoft.com/pix/winpixeventruntime/)
693+
/// for instructions on how to obtain it.</para>
689694
/// </summary>
690695
/// <param name="commandBuffer">a command buffer.</param>
691696
/// <since>This function is available since SDL 3.2.0</since>

Dependencies/SDL3-CS/SDL/Input Events/mouse/PInvoke.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ public static partial class SDL
386386
/// <para>If this function is passed a surface with alternate representations added
387387
/// with <see cref="AddSurfaceAlternateImage"/>, the surface will be interpreted as the
388388
/// content to be used for 100% display scale, and the alternate
389-
/// representations will be used for high DPI situations. For example, if the
390-
/// original surface is 32x32, then on a 2x macOS display or 200% display scale
391-
/// on Windows, a 64x64 version of the image will be used, if available. If a
389+
/// representations will be used for high DPI situations if
390+
/// <see cref="Hints.MouseDPIScaleCursors"/> is enabled. For example, if the original
391+
/// surface is 32x32, then on a 2x macOS display or 200% display scale on
392+
/// Windows, a 64x64 version of the image will be used, if available. If a
392393
/// matching version of the image isn't available, the closest larger size
393394
/// image will be downscaled to the appropriate size and be used instead, if
394395
/// available. Otherwise, the closest smaller image will be upscaled and be

Dependencies/SDL3-CS/SDL/SDL.cs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#endregion
2323

2424
using System.ComponentModel;
25+
using System.Diagnostics.CodeAnalysis;
2526
using System.Runtime.InteropServices;
2627

2728
namespace SDL3;
@@ -55,7 +56,7 @@ public static partial class SDL
5556
/// <seealso cref="PointerToStringArray(nint)"/>
5657
/// <seealso cref="PointerToStringArray(nint, int)"/>
5758
/// <seealso cref="PointerToStructureArray{T}"/>
58-
public static T? PointerToStructure<T>(IntPtr pointer) where T : struct
59+
public static T? PointerToStructure<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(IntPtr pointer) where T : struct
5960
{
6061
return pointer == IntPtr.Zero ? null : Marshal.PtrToStructure<T>(pointer);
6162
}
@@ -145,7 +146,7 @@ public static IntPtr StructureToPointer<T>(T? structure) where T : struct
145146
/// <seealso cref="PointerToStructureArray{T}"/>
146147
public static IntPtr StructureArrayToPointer<T>(T[] array) where T : struct
147148
{
148-
if (array == null || array.Length == 0) return IntPtr.Zero;
149+
if (array.Length == 0) return IntPtr.Zero;
149150

150151
var sizeOfT = Marshal.SizeOf<T>();
151152
var unmanagedPointer = Marshal.AllocHGlobal(sizeOfT * array.Length);
@@ -351,6 +352,15 @@ public static IntPtr StringToPointer(string? str)
351352
Marshal.Copy(utf8Bytes, 0, unmanagedPointer, utf8Bytes.Length);
352353
return unmanagedPointer;
353354
}
355+
356+
357+
/// <summary>
358+
/// Converts a unmanaged pointer to an UTF-8 string
359+
/// </summary>
360+
public static string? PointerToString(IntPtr pointer)
361+
{
362+
return Marshal.PtrToStringUTF8(pointer);
363+
}
354364

355365

356366
/// <summary>
@@ -387,7 +397,7 @@ public static IntPtr StringToPointer(string? str)
387397
/// <seealso cref="PointerToPointerArray"/>
388398
/// <seealso cref="PointerToStringArray(nint)"/>
389399
/// <seealso cref="PointerToStringArray(nint, int)"/>
390-
public static unsafe T[]? PointerToStructureArray<T>(IntPtr pointer, int count) where T : struct
400+
public static unsafe T[]? PointerToStructureArray<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(IntPtr pointer, int count) where T : struct
391401
{
392402
if (pointer == IntPtr.Zero || count < 0) return null;
393403

@@ -405,14 +415,61 @@ public static IntPtr StringToPointer(string? str)
405415
for (var i = 0; i < count; i++)
406416
{
407417
var elementPtr = Marshal.ReadIntPtr(pointer, i * sizePtr);
408-
array[i] = Marshal.PtrToStructure<T>(elementPtr)!;
418+
array[i] = Marshal.PtrToStructure<T>(elementPtr);
409419
}
410420
}
411421

412422
return array;
413423
}
414424

415425

426+
/// <summary>
427+
/// Allocates unmanaged memory for an array of UTF-8 string pointers (char*).
428+
/// Each string is converted via <see cref="StringToPointer(string?)"/>.
429+
/// — The array is terminated with a trailing <see cref="IntPtr.Zero"/>.
430+
/// </summary>
431+
/// <param name="array">
432+
/// — The managed array of strings. Can be <c>null</c> or empty.
433+
/// </param>
434+
/// <returns>
435+
/// — A pointer to unmanaged memory containing an array of <see cref="IntPtr"/> pointers,
436+
/// — each pointing to a UTF-8 null-terminated string.
437+
/// — Returns <see cref="IntPtr.Zero"/> for <c>null</c> or empty arrays.
438+
/// </returns>
439+
/// <remarks>
440+
/// The caller is responsible for freeing all allocated memory:
441+
/// 1. Free each individual string pointer using <see cref="Marshal.FreeHGlobal"/>.
442+
/// 2. Free the returned array pointer using <see cref="Marshal.FreeHGlobal"/>.
443+
/// Failure to do so will cause memory leaks.
444+
/// </remarks>
445+
public static IntPtr StringArrayToPointer(string[]? array)
446+
{
447+
unsafe
448+
{
449+
if (array == null || array.Length == 0)
450+
return IntPtr.Zero;
451+
452+
var total = array.Length + 1;
453+
var size = IntPtr.Size * total;
454+
455+
var blockPtr = Marshal.AllocHGlobal(size);
456+
457+
var zeroInit = new Span<byte>((void*)blockPtr, size);
458+
zeroInit.Clear();
459+
460+
for (var i = 0; i < array.Length; i++)
461+
{
462+
var strPtr = StringToPointer(array[i]);
463+
Marshal.WriteIntPtr(blockPtr, i * IntPtr.Size, strPtr);
464+
}
465+
466+
Marshal.WriteIntPtr(blockPtr, array.Length * IntPtr.Size, IntPtr.Zero);
467+
468+
return blockPtr;
469+
}
470+
}
471+
472+
416473
/// <summary>
417474
/// Indicates that a method is a <c>#define</c> macro.
418475
/// </summary>

Dependencies/SDL3-CS/SDL/Video/surface/PInvoke.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ public static partial class SDL
113113
/// left edge of the image, if this surface is being used as a cursor.</item>
114114
/// <item><see cref="Props.SurfaceHotspotYNumber"/>: the hotspot pixel offset from the
115115
/// top edge of the image, if this surface is being used as a cursor.</item>
116+
/// <item><see cref="Props.SurfaceRotationFloat"/>: the number of degrees a surface's data
117+
/// is meant to be rotated clockwise to make the image right-side up. Default
118+
/// 0. This is used by the camera API, if a mobile device is oriented
119+
/// differently than what its camera provides (i.e. - the camera always
120+
/// provides portrait images but the phone is being held in landscape
121+
/// orientation). Since SDL 3.4.0.</item>
116122
/// </list>
117123
/// </summary>
118124
/// <param name="surface">the <see cref="Surface"/> structure to query.</param>
@@ -863,6 +869,13 @@ public static partial class SDL
863869
/// <para>When the rotation isn't a multiple of 90 degrees, the resulting surface is
864870
/// larger than the original, with the background filled in with the colorkey,
865871
/// if available, or RGBA 255/255/255/0 if not.</para>
872+
/// <para>If <c>surface</c> has the <see cref="Props.SurfaceRotationFloat"/> property set on it,
873+
/// the new copy will have the adjusted value set: if the rotation property is
874+
/// 90 and <c>angle</c> was 30, the new surface will have a property value of 60
875+
/// (that is: to be upright vs gravity, this surface needs to rotate 60 more
876+
/// degrees). However, note that further rotations on the new surface in this
877+
/// example will produce unexpected results, since the image will have resized
878+
/// and padded to accommodate the not-90 degree angle.</para>
866879
/// </summary>
867880
/// <param name="surface">the surface to rotate.</param>
868881
/// <param name="angle">the rotation angle, in degrees.</param>

Dependencies/SDL3-CS/SDL/Video/surface/Props.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ public static partial class Props
3232
public const string SurfaceTonemapOperatorString = "SDL.surface.tonemap";
3333
public const string SurfaceHotspotXNumber = "SDL.surface.hotspot.x";
3434
public const string SurfaceHotspotYNumber = "SDL.surface.hotspot.y";
35+
public const string SurfaceRotationFloat = "SDL.surface.rotation";
3536
}
3637
}

Dependencies/SDL3-CS/SDL/Video/video/PInvoke.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,6 @@ public static partial bool GetClosestFullscreenDisplayMode(uint displayID, int w
10751075
/// <list type="bullet">
10761076
/// <item><see cref="Props.WindowEMScriptenCanvasIdString"/>: the id the canvas element
10771077
/// will have</item>
1078-
/// <item><see cref="Props.WindowEMScriptenFillDocumentBoolean"/>: true if the canvas is
1079-
/// set to consume the entire browser window, bypassing some SDL window
1080-
/// functionality.</item>
10811078
/// <item><see cref="Props.WindowEMScriptenKeyboardElementString"/>: the keyboard
10821079
/// element that associates keyboard events to this window</item>
10831080
/// </list>
@@ -1105,6 +1102,7 @@ public static partial bool GetClosestFullscreenDisplayMode(uint displayID, int w
11051102
/// <seealso cref="MinimizeWindow"/>
11061103
/// <seealso cref="SetWindowFullscreen"/>
11071104
/// <seealso cref="SetWindowMouseGrab"/>
1105+
/// <seealso cref="SetWindowFillDocument"/>
11081106
/// <seealso cref="ShowWindow"/>
11091107
[LibraryImport(SDLLibrary, EntryPoint = "SDL_GetWindowFlags"), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
11101108
public static partial WindowFlags GetWindowFlags(IntPtr window);
@@ -1554,6 +1552,32 @@ public static string GetWindowTitle(IntPtr window)
15541552
public static partial bool SetWindowAlwaysOnTop(IntPtr window, [MarshalAs(UnmanagedType.I1)] bool onTop);
15551553

15561554

1555+
/// <code>extern SDL_DECLSPEC bool SDLCALL SDL_SetWindowFillDocument(SDL_Window *window, bool fill);</code>
1556+
/// <summary>
1557+
/// <para>Set the window to fill the current document space (Emscripten only).</para>
1558+
/// <para>This will add or remove the window's <see cref="WindowFlags.WindowFillDocument"/> flag.</para>
1559+
/// <para>Currently this flag only applies to the Emscripten target.</para>
1560+
/// <para>When enabled, the canvas element fills the entire document. Resize events
1561+
/// will be generated as the browser window is resized, as that will adjust the
1562+
/// canvas size as well. The canvas will cover anything else on the page,
1563+
/// including any controls provided by Emscripten in its generated HTML file
1564+
/// (in fact, any elements on the page that aren't the canvas will be moved
1565+
/// into a hidden <c>div</c> element).</para>
1566+
/// /// <para>Often times this is desirable for a browser-based game, but it means
1567+
/// several things that we expect of an SDL window on other platforms might not
1568+
/// work as expected, such as minimum window sizes and aspect ratios.</para>
1569+
/// </summary>
1570+
/// <param name="window">the window of which to change the fill-document state.</param>
1571+
/// <param name="fill">true to set the window to fill the document, false to disable.</param>
1572+
/// <returns>true on success or false on failure; call <see cref="GetError"/> for more
1573+
/// information.</returns>
1574+
/// <threadsafety>This function should only be called on the main thread.</threadsafety>
1575+
/// <since>This function is available since SDL 3.4.0.</since>
1576+
[LibraryImport(SDLLibrary, EntryPoint = "SDL_SetWindowFillDocument"), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
1577+
[return: MarshalAs(UnmanagedType.I1)]
1578+
public static partial bool SetWindowFillDocument(IntPtr window, [MarshalAs(UnmanagedType.I1)] bool fill);
1579+
1580+
15571581
/// <code>extern SDL_DECLSPEC bool SDLCALL SDL_ShowWindow(SDL_Window *window);</code>
15581582
/// <summary>
15591583
/// Show a window.

0 commit comments

Comments
 (0)