Render original lab and Jimmy with native Vulkan and SDL3 on .NET 10
This commit is contained in:
1 parent
3df20ac19a
commit
008c0e16da
41 files changed
+2125
-68
No files matched your search
@@ -0,0 +1,57 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GamePort.Platform;
|
||||
|
||||
internal static unsafe class Sdl
|
||||
{
|
||||
private const string Library="SDL3";
|
||||
static Sdl()
|
||||
{
|
||||
NativeLibrary.SetDllImportResolver(typeof(Sdl).Assembly, (name, assembly, path) =>
|
||||
{
|
||||
if(name!=Library)return 0;
|
||||
var filename=OperatingSystem.IsWindows()?"SDL3.dll":"libSDL3.so.0";
|
||||
foreach(var candidate in new[]{Path.Combine(AppContext.BaseDirectory,filename),Path.Combine(Directory.GetCurrentDirectory(),".tools/sdl/lib",filename),filename})
|
||||
if(NativeLibrary.TryLoad(candidate,out var handle))return handle;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
public const uint InitVideo=0x20, InitAudio=0x10;
|
||||
public const ulong WindowVulkan=0x10000000, WindowResizable=0x20, WindowHighPixelDensity=0x2000;
|
||||
public const uint Quit=0x100, KeyDown=0x300, KeyUp=0x301, WindowResized=0x206, WindowPixelSizeChanged=0x207, WindowFocusLost=0x20F;
|
||||
[StructLayout(LayoutKind.Explicit,Size=128)] public struct Event
|
||||
{
|
||||
[FieldOffset(0)]public uint Type;
|
||||
[FieldOffset(16)]public uint WindowId;
|
||||
[FieldOffset(24)]public uint Scancode;
|
||||
[FieldOffset(28)]public uint Key;
|
||||
[FieldOffset(36)]public byte Down;
|
||||
[FieldOffset(37)]public byte Repeat;
|
||||
}
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)] public static extern bool SDL_Init(uint flags);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] public static extern void SDL_Quit();
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] private static extern nint SDL_GetError();
|
||||
public static string Error=>Marshal.PtrToStringUTF8(SDL_GetError())??"SDL error";
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] public static extern nint SDL_CreateWindow([MarshalAs(UnmanagedType.LPUTF8Str)]string title,int w,int h,ulong flags);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_DestroyWindow(nint window);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_PollEvent(out Event e);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern byte** SDL_Vulkan_GetInstanceExtensions(out uint count);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_Vulkan_CreateSurface(nint window,nint instance,void* allocator,out ulong surface);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_GetWindowSizeInPixels(nint window,out int w,out int h);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetWindowFullscreen(nint window,[MarshalAs(UnmanagedType.I1)]bool fullscreen);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetWindowRelativeMouseMode(nint window,[MarshalAs(UnmanagedType.I1)]bool enabled);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_SetWindowSize(nint window,int width,int height);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_PushEvent(ref Event e);
|
||||
[StructLayout(LayoutKind.Sequential)]public struct AudioSpec {public uint Format;public int Channels;public int Frequency;}
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_InitSubSystem(uint flags);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_QuitSubSystem(uint flags);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_LoadWAV([MarshalAs(UnmanagedType.LPUTF8Str)]string path,out AudioSpec spec,out nint buffer,out uint length);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_free(nint buffer);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern nint SDL_OpenAudioDeviceStream(uint device,ref AudioSpec spec,nint callback,nint user);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_ResumeAudioStreamDevice(nint stream);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)] [return:MarshalAs(UnmanagedType.I1)]public static extern bool SDL_PutAudioStreamData(nint stream,nint buffer,int length);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern int SDL_GetAudioStreamQueued(nint stream);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_DestroyAudioStream(nint stream);
|
||||
[DllImport(Library,CallingConvention=CallingConvention.Cdecl)]public static extern void SDL_Delay(uint ms);
|
||||
}
|
||||
Reference in new issue
Block a user