Skip to content

Commit

Permalink
Merge pull request #168 from Susko3/update-bindings
Browse files Browse the repository at this point in the history
Update bindings and fix bindgen script
  • Loading branch information
smoogipoo authored Oct 22, 2024
2 parents bfa2ad0 + 5ab6d58 commit ee98235
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 24 deletions.
4 changes: 4 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_events.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ public enum SDL_EventType
SDL_EVENT_CAMERA_DEVICE_DENIED,
SDL_EVENT_RENDER_TARGETS_RESET = 0x2000,
SDL_EVENT_RENDER_DEVICE_RESET,
SDL_EVENT_PRIVATE0 = 0x4000,
SDL_EVENT_PRIVATE1,
SDL_EVENT_PRIVATE2,
SDL_EVENT_PRIVATE3,
SDL_EVENT_POLL_SENTINEL = 0x7F00,
SDL_EVENT_USER = 0x8000,
SDL_EVENT_LAST = 0xFFFF,
Expand Down
32 changes: 16 additions & 16 deletions SDL3-CS/SDL3/ClangSharp/SDL_gpu.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,32 +1470,32 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 \"SDL.gpu.createtexture.d3d12.clear.stencil\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_CREATETEXTURE_D3D12_CLEAR_STENCIL_UINT8 => "SDL.gpu.createtexture.d3d12.clear.stencil"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOL \"SDL.gpu.device.create.debugmode\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOL => "SDL.gpu.device.create.debugmode"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN \"SDL.gpu.device.create.debugmode\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_DEBUGMODE_BOOLEAN => "SDL.gpu.device.create.debugmode"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOL \"SDL.gpu.device.create.preferlowpower\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOL => "SDL.gpu.device.create.preferlowpower"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN \"SDL.gpu.device.create.preferlowpower\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_PREFERLOWPOWER_BOOLEAN => "SDL.gpu.device.create.preferlowpower"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING \"SDL.gpu.device.create.name\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_NAME_STRING => "SDL.gpu.device.create.name"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOL \"SDL.gpu.device.create.shaders.private\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOL => "SDL.gpu.device.create.shaders.private"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN \"SDL.gpu.device.create.shaders.private\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_PRIVATE_BOOLEAN => "SDL.gpu.device.create.shaders.private"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOL \"SDL.gpu.device.create.shaders.spirv\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOL => "SDL.gpu.device.create.shaders.spirv"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN \"SDL.gpu.device.create.shaders.spirv\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_SPIRV_BOOLEAN => "SDL.gpu.device.create.shaders.spirv"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOL \"SDL.gpu.device.create.shaders.dxbc\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOL => "SDL.gpu.device.create.shaders.dxbc"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN \"SDL.gpu.device.create.shaders.dxbc\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXBC_BOOLEAN => "SDL.gpu.device.create.shaders.dxbc"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOL \"SDL.gpu.device.create.shaders.dxil\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOL => "SDL.gpu.device.create.shaders.dxil"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN \"SDL.gpu.device.create.shaders.dxil\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_DXIL_BOOLEAN => "SDL.gpu.device.create.shaders.dxil"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOL \"SDL.gpu.device.create.shaders.msl\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOL => "SDL.gpu.device.create.shaders.msl"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN \"SDL.gpu.device.create.shaders.msl\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_MSL_BOOLEAN => "SDL.gpu.device.create.shaders.msl"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOL \"SDL.gpu.device.create.shaders.metallib\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOL => "SDL.gpu.device.create.shaders.metallib"u8;
[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN \"SDL.gpu.device.create.shaders.metallib\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN => "SDL.gpu.device.create.shaders.metallib"u8;

[NativeTypeName("#define SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING \"SDL.gpu.device.create.d3d12.semantic\"")]
public static ReadOnlySpan<byte> SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING => "SDL.gpu.device.create.d3d12.semantic"u8;
Expand Down
6 changes: 6 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_hints.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_HINT_OPENGL_ES_DRIVER \"SDL_OPENGL_ES_DRIVER\"")]
public static ReadOnlySpan<byte> SDL_HINT_OPENGL_ES_DRIVER => "SDL_OPENGL_ES_DRIVER"u8;

[NativeTypeName("#define SDL_HINT_OPENVR_LIBRARY \"SDL_OPENVR_LIBRARY\"")]
public static ReadOnlySpan<byte> SDL_HINT_OPENVR_LIBRARY => "SDL_OPENVR_LIBRARY"u8;

[NativeTypeName("#define SDL_HINT_ORIENTATIONS \"SDL_ORIENTATIONS\"")]
public static ReadOnlySpan<byte> SDL_HINT_ORIENTATIONS => "SDL_ORIENTATIONS"u8;

Expand Down Expand Up @@ -586,6 +589,9 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_HINT_VIDEO_ALLOW_SCREENSAVER \"SDL_VIDEO_ALLOW_SCREENSAVER\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_ALLOW_SCREENSAVER => "SDL_VIDEO_ALLOW_SCREENSAVER"u8;

[NativeTypeName("#define SDL_HINT_VIDEO_DISPLAY_PRIORITY \"SDL_VIDEO_DISPLAY_PRIORITY\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_DISPLAY_PRIORITY => "SDL_VIDEO_DISPLAY_PRIORITY"u8;

[NativeTypeName("#define SDL_HINT_VIDEO_DOUBLE_BUFFER \"SDL_VIDEO_DOUBLE_BUFFER\"")]
public static ReadOnlySpan<byte> SDL_HINT_VIDEO_DOUBLE_BUFFER => "SDL_VIDEO_DOUBLE_BUFFER"u8;

Expand Down
7 changes: 7 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_render.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,10 @@ public static unsafe partial class SDL3
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_GetRenderVSync(SDL_Renderer* renderer, int* vsync);

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_RenderDebugText(SDL_Renderer* renderer, float x, float y, [NativeTypeName("const char *")] byte* str);

[NativeTypeName("#define SDL_SOFTWARE_RENDERER \"software\"")]
public static ReadOnlySpan<byte> SDL_SOFTWARE_RENDERER => "software"u8;

Expand Down Expand Up @@ -654,5 +658,8 @@ public static unsafe partial class SDL3

[NativeTypeName("#define SDL_RENDERER_VSYNC_ADAPTIVE (-1)")]
public const int SDL_RENDERER_VSYNC_ADAPTIVE = (-1);

[NativeTypeName("#define SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE 8")]
public const int SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE = 8;
}
}
12 changes: 12 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_system.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ 3. This notice may not be removed or altered from any source distribution.

namespace SDL
{
public enum SDL_Sandbox
{
SDL_SANDBOX_NONE = 0,
SDL_SANDBOX_UNKNOWN_CONTAINER,
SDL_SANDBOX_FLATPAK,
SDL_SANDBOX_SNAP,
SDL_SANDBOX_MACOS,
}

public static unsafe partial class SDL3
{
[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
Expand All @@ -41,6 +50,9 @@ public static unsafe partial class SDL3
[return: NativeTypeName("bool")]
public static extern SDLBool SDL_IsTV();

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern SDL_Sandbox SDL_GetSandbox();

[DllImport("SDL3", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void SDL_OnApplicationWillTerminate();

Expand Down
3 changes: 3 additions & 0 deletions SDL3-CS/SDL3/ClangSharp/SDL_video.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,9 @@ public static unsafe partial class SDL3
[NativeTypeName("#define SDL_PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER \"SDL.window.cocoa.metal_view_tag\"")]
public static ReadOnlySpan<byte> SDL_PROP_WINDOW_COCOA_METAL_VIEW_TAG_NUMBER => "SDL.window.cocoa.metal_view_tag"u8;

[NativeTypeName("#define SDL_PROP_WINDOW_OPENVR_OVERLAY_ID \"SDL.window.openvr.overlay_id\"")]
public static ReadOnlySpan<byte> SDL_PROP_WINDOW_OPENVR_OVERLAY_ID => "SDL.window.openvr.overlay_id"u8;

[NativeTypeName("#define SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER \"SDL.window.vivante.display\"")]
public static ReadOnlySpan<byte> SDL_PROP_WINDOW_VIVANTE_DISPLAY_POINTER => "SDL.window.vivante.display"u8;

Expand Down
16 changes: 8 additions & 8 deletions SDL3-CS/generate_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,30 +288,30 @@ def run_clangsharp(command, header: Header):
return header.output_file()


# regex for ClangSharp-generated SDL functions
generated_function_regex = re.compile(r"public static extern \w+\** (SDL_\w+)\(")
# regex for ClangSharp-generated SDL functions and enums
generated_symbol_regex = re.compile(r"public (enum|static extern \w+\**) (SDL_\w+)")


def get_generated_functions(file):
def get_generated_symbols(file):
with open(file, "r", encoding="utf-8") as f:
for match in generated_function_regex.finditer(f.read()):
yield match.group(1)
for match in generated_symbol_regex.finditer(f.read()):
yield match.group(2)


def generate_platform_specific_headers(sdl_api, header: Header, platforms):
all_functions = list(all_funcs_from_header(sdl_api, header))

print(f"💠 {header} platform agnostic")
platform_agnostic_cs = run_clangsharp(base_command, header)
platform_agnostic_functions = list(get_generated_functions(platform_agnostic_cs))
platform_agnostic_symbols = list(get_generated_symbols(platform_agnostic_cs))
output_files = [platform_agnostic_cs]

for (defines, suffix, platform_name) in platforms:
command = base_command + ["--define-macro"] + defines

if platform_agnostic_functions:
if platform_agnostic_symbols:
command.append("--exclude")
command.extend(platform_agnostic_functions)
command.extend(platform_agnostic_symbols)

if all_functions:
command.append("--with-attribute")
Expand Down

0 comments on commit ee98235

Please sign in to comment.