From 931d5fc06ee8f6f3b8d9f1d130ee992e6f532929 Mon Sep 17 00:00:00 2001 From: Mary Date: Sat, 14 Aug 2021 09:10:25 +0200 Subject: [PATCH 1/7] Add multiple missing pointer overloads THis adds some missing overloads that Ryujinx uses. Changelog: - Add a new overload of SDL_MixAudioFormat to allow passing raw pointers as dest and src (useful for usage with SDL_AudioSpec's callback). - Add a new overload of SDL_OpenAudioDevice to allow passing null for the device parameter. - Add a new overload of SDL_Vulkan_GetInstanceExtensions to allow passing null for the pName parameter. --- src/SDL2.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/SDL2.cs b/src/SDL2.cs index d2df222..a3a1c3d 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -2277,6 +2277,17 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_Vulkan_UnloadLibrary(); + /* window refers to an SDL_Window*, pNames to a const char**. + * Only available in 2.0.6 or higher. + * This overload allows for IntPtr.Zero (null) to be passed for pNames. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern SDL_bool SDL_Vulkan_GetInstanceExtensions( + IntPtr window, + out uint pCount, + IntPtr pNames + ); + /* window refers to an SDL_Window*, pNames to a const char**. * Only available in 2.0.6 or higher. */ @@ -7777,6 +7788,17 @@ namespace SDL2 int volume ); + /* format refers to an SDL_AudioFormat */ + /* This overload allows raw pointers to be passed for dst and src. */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void SDL_MixAudioFormat( + IntPtr dst, + IntPtr src, + ushort format, + uint len, + int volume + ); + /* format refers to an SDL_AudioFormat */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MixAudioFormat( @@ -7801,6 +7823,17 @@ namespace SDL2 IntPtr obtained ); + /* uint refers to an SDL_AudioDeviceID */ + /* This overload allows for IntPtr.Zero (null) to be passed for device. */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern unsafe uint SDL_OpenAudioDevice( + IntPtr device, + int iscapture, + ref SDL_AudioSpec desired, + out SDL_AudioSpec obtained, + int allowed_changes + ); + /* uint refers to an SDL_AudioDeviceID */ [DllImport(nativeLibName, EntryPoint = "SDL_OpenAudioDevice", CallingConvention = CallingConvention.Cdecl)] private static extern unsafe uint INTERNAL_SDL_OpenAudioDevice( From 904eed3cb04319c4e3e360360943e39080f80d7b Mon Sep 17 00:00:00 2001 From: Esme Date: Mon, 16 Aug 2021 13:28:18 -0500 Subject: [PATCH 2/7] Fix typo in version comment --- src/SDL2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index a3a1c3d..1148d9a 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -8048,7 +8048,7 @@ namespace SDL2 /* renderer refers to an SDL_Renderer* * IntPtr refers to an ID3D11Device* - * Only available in 2.0.18 or higher. + * Only available in 2.0.16 or higher. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_RenderGetD3D11Device(IntPtr renderer); From 5df88baf4ba31d4a4841e4cc0ddfab4c5769c321 Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Tue, 2 Nov 2021 15:13:10 -0400 Subject: [PATCH 3/7] Add missing EntryPoint for SDL_AndroidShowToast --- src/SDL2.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 1148d9a..42d4fdf 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -8137,7 +8137,7 @@ namespace SDL2 } /* Only available in 2.0.16 or higher. */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + [DllImport(nativeLibName, EntryPoint = "SDL_AndroidShowToast", CallingConvention = CallingConvention.Cdecl)] private static unsafe extern int INTERNAL_SDL_AndroidShowToast( byte* message, int duration, From ec5e8d835787c75593f7c48cb3f3f6ba05743d39 Mon Sep 17 00:00:00 2001 From: s341507 <70201129+s341507@users.noreply.github.com> Date: Wed, 3 Nov 2021 11:23:38 +0100 Subject: [PATCH 4/7] Fixed field type of ctouchpad and csensor in SDL_Event. --- src/SDL2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 42d4fdf..27bfecd 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -5092,9 +5092,9 @@ namespace SDL2 [FieldOffset(0)] public SDL_ControllerDeviceEvent cdevice; [FieldOffset(0)] - public SDL_ControllerDeviceEvent ctouchpad; + public SDL_ControllerTouchpadEvent ctouchpad; [FieldOffset(0)] - public SDL_ControllerDeviceEvent csensor; + public SDL_ControllerSensorEvent csensor; [FieldOffset(0)] public SDL_AudioDeviceEvent adevice; [FieldOffset(0)] From db935863bbc24e24e0f2965a16c408800f67fd7d Mon Sep 17 00:00:00 2001 From: Jeremy Sayers Date: Sun, 14 Nov 2021 09:22:47 -0500 Subject: [PATCH 5/7] Add TTF_GetError and TTF_SetError Adding some missing functions to SDL2_ttf that are just wrappers of the `SDL_GetError` and `SDL_SetError` as per the SDL_ttf header: ``` /* We'll use SDL for reporting errors */ #define TTF_SetError SDL_SetError #define TTF_GetError SDL_GetError ``` --- src/SDL2_ttf.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/SDL2_ttf.cs b/src/SDL2_ttf.cs index ba91c7f..4bbadb8 100644 --- a/src/SDL2_ttf.cs +++ b/src/SDL2_ttf.cs @@ -754,6 +754,16 @@ namespace SDL2 ushort ch ); + public static string TTF_GetError() + { + return SDL.SDL_GetError(); + } + + public static void TTF_SetError(string fmtAndArglist) + { + SDL.SDL_SetError(fmtAndArglist); + } + #endregion } } From 4e9088b49de46ea8b4285948cfe69875ac4c2290 Mon Sep 17 00:00:00 2001 From: Jeremy Sayers Date: Sun, 14 Nov 2021 12:50:39 -0500 Subject: [PATCH 6/7] Add Mix_GetError, Mix_SetError, Mix_ClearError Adding `Mix_GetError`, `Mix_SetError`, `Mix_ClearError` as per the SDL_mixer header file: /* We'll use SDL for reporting errors */ #define Mix_SetError SDL_SetError #define Mix_GetError SDL_GetError #define Mix_ClearError SDL_ClearError --- src/SDL2_mixer.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/SDL2_mixer.cs b/src/SDL2_mixer.cs index e98c91d..69b128b 100644 --- a/src/SDL2_mixer.cs +++ b/src/SDL2_mixer.cs @@ -646,6 +646,21 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void Mix_CloseAudio(); + public static string Mix_GetError() + { + return SDL.SDL_GetError(); + } + + public static void Mix_SetError(string fmtAndArglist) + { + SDL.SDL_SetError(fmtAndArglist); + } + + public static void Mix_ClearError() + { + SDL.SDL_ClearError(); + } + #endregion } } From 80841ecef08e03631aa0694ba318cbbc18fab41c Mon Sep 17 00:00:00 2001 From: Caleb Cornett Date: Fri, 19 Nov 2021 13:59:41 -0500 Subject: [PATCH 7/7] Update for 2.0.18 --- src/SDL2.cs | 236 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 4 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 27bfecd..adb0ebe 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -711,6 +711,24 @@ namespace SDL2 public const string SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR = "SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"; + /* Only available in 2.0.18 or higher. */ + public const string SDL_HINT_VIDEO_EGL_ALLOW_TRANSPARENCY = + "SDL_VIDEO_EGL_ALLOW_TRANSPARENCY"; + public const string SDL_HINT_APP_NAME = + "SDL_APP_NAME"; + public const string SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME = + "SDL_SCREENSAVER_INHIBIT_ACTIVITY_NAME"; + public const string SDL_HINT_IME_SHOW_UI = + "SDL_IME_SHOW_UI"; + public const string SDL_HINT_WINDOW_NO_ACTIVATION_WHEN_SHOWN = + "SDL_WINDOW_NO_ACTIVATION_WHEN_SHOWN"; + public const string SDL_HINT_POLL_SENTINEL = + "SDL_POLL_SENTINEL"; + public const string SDL_HINT_JOYSTICK_DEVICE = + "SDL_JOYSTICK_DEVICE"; + public const string SDL_HINT_LINUX_JOYSTICK_CLASSIC = + "SDL_LINUX_JOYSTICK_CLASSIC"; + public enum SDL_HintPriority { SDL_HINT_DEFAULT, @@ -1284,7 +1302,7 @@ namespace SDL2 */ public const int SDL_MAJOR_VERSION = 2; public const int SDL_MINOR_VERSION = 0; - public const int SDL_PATCHLEVEL = 16; + public const int SDL_PATCHLEVEL = 18; public static readonly int SDL_COMPILEDVERSION = SDL_VERSIONNUM( SDL_MAJOR_VERSION, @@ -1401,7 +1419,10 @@ namespace SDL2 SDL_WINDOWEVENT_CLOSE, /* Only available in 2.0.5 or higher. */ SDL_WINDOWEVENT_TAKE_FOCUS, - SDL_WINDOWEVENT_HIT_TEST + SDL_WINDOWEVENT_HIT_TEST, + /* Only available in 2.0.18 or higher. */ + SDL_WINDOWEVENT_ICCPROF_CHANGED, + SDL_WINDOWEVENT_DISPLAY_CHANGED } public enum SDL_DisplayEventID : byte @@ -1727,6 +1748,17 @@ namespace SDL2 out SDL_DisplayMode mode ); + /* IntPtr refers to a void* + * window refers to an SDL_Window* + * mode refers to a size_t* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SDL_GetWindowICCProfile( + IntPtr window, + out IntPtr mode + ); + /* window refers to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern uint SDL_GetWindowFlags(IntPtr window); @@ -2192,6 +2224,35 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_GetGrabbedWindow(); + /* window refers to an SDL_Window* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_SetWindowMouseRect( + IntPtr window, + ref SDL_Rect rect + ); + + /* window refers to an SDL_Window* + * rect refers to an SDL_Rect* + * This overload allows for IntPtr.Zero (null) to be passed for rect. + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_SetWindowMouseRect( + IntPtr window, + IntPtr rect + ); + + /* window refers to an SDL_Window* + * IntPtr refers to an SDL_Rect* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SDL_GetWindowMouseRect( + IntPtr window + ); + /* window refers to an SDL_Window* * Only available in 2.0.16 or higher. */ @@ -2408,6 +2469,15 @@ namespace SDL2 SDL_ScaleModeBest } + /* Only available in 2.0.18 or higher. */ + [StructLayout(LayoutKind.Sequential)] + public struct SDL_Vertex + { + public SDL_FPoint position; + public SDL_Color color; + public SDL_FPoint tex_coord; + } + /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_CreateRenderer( @@ -2476,6 +2546,22 @@ namespace SDL2 out SDL_ScaleMode scaleMode ); + /* texture refers to an SDL_Texture* + * userdata refers to a void* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_SetTextureUserData( + IntPtr texture, + IntPtr userdata + ); + + /* IntPtr refers to a void*, texture refers to an SDL_Texture* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern IntPtr SDL_GetTextureUserData(IntPtr texture); + /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDrawColor( @@ -3031,6 +3117,41 @@ namespace SDL2 SDL_RendererFlip flip ); + /* renderer refers to an SDL_Renderer* + * texture refers to an SDL_Texture* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_RenderGeometry( + IntPtr renderer, + IntPtr texture, + [In] SDL_Vertex[] vertices, + int num_vertices, + [In] int[] indices, + int num_indices + ); + + /* renderer refers to an SDL_Renderer* + * texture refers to an SDL_Texture* + * indices refers to a void* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_RenderGeometryRaw( + IntPtr renderer, + IntPtr texture, + [In] float[] xy, + int xy_stride, + [In] int[] color, + int color_stride, + [In] float[] uv, + int uv_stride, + int num_vertices, + IntPtr indices, + int num_indices, + int size_indices + ); + /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPointF( @@ -3138,6 +3259,30 @@ namespace SDL2 out float scaleY ); + /* renderer refers to an SDL_Renderer* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void SDL_RenderWindowToLogical( + IntPtr renderer, + int windowX, + int windowY, + out float logicalX, + out float logicalY + ); + + /* renderer refers to an SDL_Renderer* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern void SDL_RenderLogicalToWindow( + IntPtr renderer, + float logicalX, + float logicalY, + out int windowX, + out int windowY + ); + /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderGetViewport( @@ -3331,6 +3476,12 @@ namespace SDL2 IntPtr renderer ); + /* renderer refers to an SDL_Renderer* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_RenderSetVSync(IntPtr renderer, int vsync); + /* renderer refers to an SDL_Renderer* * Only available in 2.0.4 or higher. */ @@ -4639,6 +4790,10 @@ namespace SDL2 /* Only available in SDL 2.0.4 or higher. */ SDL_RENDER_DEVICE_RESET, + /* Internal events */ + /* Only available in 2.0.18 or higher. */ + SDL_POLLSENTINEL = 0x7F00, + /* Events SDL_USEREVENT through SDL_LASTEVENT are for * your use, and should be allocated with * SDL_RegisterEvents() @@ -4786,6 +4941,8 @@ namespace SDL2 public Int32 x; /* amount scrolled horizontally */ public Int32 y; /* amount scrolled vertically */ public UInt32 direction; /* Set to one of the SDL_MOUSEWHEEL_* defines */ + public float preciseX; /* Requires >= 2.0.18 */ + public float preciseY; /* Requires >= 2.0.18 */ } // Ignore private members used for padding in this struct @@ -5832,13 +5989,15 @@ namespace SDL2 KMOD_NUM = 0x1000, KMOD_CAPS = 0x2000, KMOD_MODE = 0x4000, - KMOD_RESERVED = 0x8000, + KMOD_SCROLL = 0x8000, /* These are defines in the SDL headers */ KMOD_CTRL = (KMOD_LCTRL | KMOD_RCTRL), KMOD_SHIFT = (KMOD_LSHIFT | KMOD_RSHIFT), KMOD_ALT = (KMOD_LALT | KMOD_RALT), - KMOD_GUI = (KMOD_LGUI | KMOD_RGUI) + KMOD_GUI = (KMOD_LGUI | KMOD_RGUI), + + KMOD_RESERVED = KMOD_SCROLL } #endregion @@ -6534,6 +6693,18 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_JoystickHasLED(IntPtr joystick); + /* IntPtr refers to an SDL_Joystick*. + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern SDL_bool SDL_JoystickHasRumble(IntPtr joystick); + + /* IntPtr refers to an SDL_Joystick*. + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern SDL_bool SDL_JoystickHasRumbleTriggers(IntPtr joystick); + /* IntPtr refers to an SDL_Joystick*. * Only available in 2.0.14 or higher. */ @@ -6975,6 +7146,40 @@ namespace SDL2 IntPtr gamecontroller ); + /* gamecontroller refers to an SDL_GameController* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetAppleSFSymbolsNameForButton", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr INTERNAL_SDL_GameControllerGetAppleSFSymbolsNameForButton( + IntPtr gamecontroller, + SDL_GameControllerButton button + ); + public static string SDL_GameControllerGetAppleSFSymbolsNameForButton( + IntPtr gamecontroller, + SDL_GameControllerButton button + ) { + return UTF8_ToManaged( + INTERNAL_SDL_GameControllerGetAppleSFSymbolsNameForButton(gamecontroller, button) + ); + } + + /* gamecontroller refers to an SDL_GameController* + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetAppleSFSymbolsNameForAxis", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr INTERNAL_SDL_GameControllerGetAppleSFSymbolsNameForAxis( + IntPtr gamecontroller, + SDL_GameControllerAxis axis + ); + public static string SDL_GameControllerGetAppleSFSymbolsNameForAxis( + IntPtr gamecontroller, + SDL_GameControllerAxis axis + ) { + return UTF8_ToManaged( + INTERNAL_SDL_GameControllerGetAppleSFSymbolsNameForAxis(gamecontroller, axis) + ); + } + /* int refers to an SDL_JoystickID, IntPtr to an SDL_GameController*. * Only available in 2.0.4 or higher. */ @@ -7020,6 +7225,22 @@ namespace SDL2 IntPtr gamecontroller ); + /* gamecontroller refers to an SDL_GameController*. + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern SDL_bool SDL_GameControllerHasRumble( + IntPtr gamecontroller + ); + + /* gamecontroller refers to an SDL_GameController*. + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern SDL_bool SDL_GameControllerHasRumbleTriggers( + IntPtr gamecontroller + ); + /* gamecontroller refers to an SDL_GameController*. * Only available in 2.0.14 or higher. */ @@ -7994,6 +8215,12 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt32 SDL_GetTicks(); + /* Returns the milliseconds that have passed since SDL was initialized + * Only available in 2.0.18 or higher. + */ + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern UInt64 SDL_GetTicks64(); + /* Get the current value of the high resolution counter */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern UInt64 SDL_GetPerformanceCounter(); @@ -8255,6 +8482,7 @@ namespace SDL2 public IntPtr shell_surface; // Refers to a wl_shell_surface* public IntPtr egl_window; // Refers to an egl_window*, requires >= 2.0.16 public IntPtr xdg_surface; // Refers to an xdg_surface*, requires >= 2.0.16 + public IntPtr xdg_toplevel; // Referes to an xdg_toplevel*, requires >= 2.0.18 } [StructLayout(LayoutKind.Sequential)]