Skip to content

Commit 0bd60d8

Browse files
committed
Add SDL_stdinc bindings (for SDL_free...)
2 parents 910fc7c + b693082 commit 0bd60d8

23 files changed

+17801
-2303
lines changed

eng/silktouch/sdl/SDL3/generate.rsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ SDL_memmove
99
SDL_memset
1010
SDL_BeginThreadFunction
1111
SDL_EndThreadFunction
12+
SDL_fabsf
13+
SDL_size_add_check_overflow_builtin
14+
SDL_size_mul_check_overflow_builtin
1215
--file
1316
sdl-SDL.h
1417
--methodClassName
@@ -61,6 +64,7 @@ Silk.NET.SDL
6164
../../../submodules/sdl/include/SDL3/SDL_render.h
6265
../../../submodules/sdl/include/SDL3/SDL_scancode.h
6366
../../../submodules/sdl/include/SDL3/SDL_sensor.h
67+
../../../submodules/sdl/include/SDL3/SDL_stdinc.h
6468
../../../submodules/sdl/include/SDL3/SDL_storage.h
6569
../../../submodules/sdl/include/SDL3/SDL_surface.h
6670
../../../submodules/sdl/include/SDL3/SDL_system.h

sources/Playground/Program.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@
55
using Silk.NET.OpenGL;
66
using Silk.NET.SDL;
77

8-
var ec = Sdl.Init(uint.MaxValue);
9-
if (ec is not 0)
8+
if (!Sdl.Init(uint.MaxValue))
109
{
11-
throw new Exception(
12-
$"failed to init (error code: {(Errorcode)ec} {ec}): {(string)Sdl.GetError()}"
13-
);
10+
throw new Exception($"failed to init: {(string)Sdl.GetError()}");
1411
}
1512

1613
var window = Sdl.CreateWindow(
1714
"Hello Window!",
1815
1000,
1916
800,
20-
Sdl.WindowOpengl | Sdl.WindowHighPixelDensity
17+
Sdl.WindowOpengl | Sdl.WindowHighPixelDensity | Sdl.WindowResizable
2118
);
2219
if (window == nullptr)
2320
{
@@ -40,12 +37,12 @@
4037

4138
var context = new SdlContext(
4239
window,
43-
new KeyValuePair<GLattr, int>(GLattr.ContextMajorVersion, 3),
44-
new KeyValuePair<GLattr, int>(GLattr.ContextMinorVersion, 3),
45-
new KeyValuePair<GLattr, int>(GLattr.ContextProfileMask, (int)GLprofile.Core),
46-
new KeyValuePair<GLattr, int>(
47-
GLattr.ContextFlags,
48-
(int)(GLcontextFlag.ForwardCompatibleFlag | GLcontextFlag.DebugFlag)
40+
new KeyValuePair<GLAttr, int>(GLAttr.ContextMajorVersion, 3),
41+
new KeyValuePair<GLAttr, int>(GLAttr.ContextMinorVersion, 3),
42+
new KeyValuePair<GLAttr, int>(GLAttr.ContextProfileMask, Sdl.GlContextProfileCore),
43+
new KeyValuePair<GLAttr, int>(
44+
GLAttr.ContextFlags,
45+
Sdl.GlContextForwardCompatibleFlag | Sdl.GlContextDebugFlag
4946
)
5047
);
5148
GL.ThisThread.MakeCurrent(GL.Create(context));
@@ -101,9 +98,13 @@ void main()
10198
Event @event = default;
10299
while (true)
103100
{
104-
if (Sdl.PollEvent(@event.AsRef()) && @event.Type == (int)EventType.Quit)
101+
if (Sdl.PollEvent(@event.AsRef()))
105102
{
106-
break;
103+
Console.WriteLine((EventType)@event.Type);
104+
if (@event.Type == (int)EventType.Quit)
105+
{
106+
break;
107+
}
107108
}
108109

109110
if (@event.Window.Type == EventType.WindowDisplayScaleChanged)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public readonly unsafe partial struct EnvironmentHandle
12+
{
13+
public readonly void* Handle;
14+
15+
public bool Equals(EnvironmentHandle other) => Handle == other.Handle;
16+
17+
public override bool Equals(object? obj) => obj is EnvironmentHandle other && Equals(other);
18+
19+
public override int GetHashCode() => HashCode.Combine((nuint)Handle);
20+
21+
public static bool operator ==(EnvironmentHandle left, EnvironmentHandle right) =>
22+
left.Equals(right);
23+
24+
public static bool operator !=(EnvironmentHandle left, EnvironmentHandle right) =>
25+
!left.Equals(right);
26+
27+
public bool Equals(NullPtr _) => Handle is null;
28+
29+
public static bool operator ==(EnvironmentHandle left, NullPtr right) => left.Equals(right);
30+
31+
public static bool operator !=(EnvironmentHandle left, NullPtr right) => !left.Equals(right);
32+
33+
public static implicit operator EnvironmentHandle(NullPtr _) => default;
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public readonly unsafe partial struct IconvDataTHandle
12+
{
13+
public readonly void* Handle;
14+
15+
public bool Equals(IconvDataTHandle other) => Handle == other.Handle;
16+
17+
public override bool Equals(object? obj) => obj is IconvDataTHandle other && Equals(other);
18+
19+
public override int GetHashCode() => HashCode.Combine((nuint)Handle);
20+
21+
public static bool operator ==(IconvDataTHandle left, IconvDataTHandle right) =>
22+
left.Equals(right);
23+
24+
public static bool operator !=(IconvDataTHandle left, IconvDataTHandle right) =>
25+
!left.Equals(right);
26+
27+
public bool Equals(NullPtr _) => Handle is null;
28+
29+
public static bool operator ==(IconvDataTHandle left, NullPtr right) => left.Equals(right);
30+
31+
public static bool operator !=(IconvDataTHandle left, NullPtr right) => !left.Equals(right);
32+
33+
public static implicit operator IconvDataTHandle(NullPtr _) => default;
34+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.InteropServices;
7+
8+
namespace Silk.NET.SDL;
9+
10+
public unsafe partial struct AlignmentTest
11+
{
12+
[NativeTypeName("Uint8")]
13+
public byte A;
14+
public void* B;
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public readonly unsafe struct CallocFunc : IDisposable
12+
{
13+
private readonly void* Pointer;
14+
public delegate* unmanaged<nuint, nuint, void*> Handle =>
15+
(delegate* unmanaged<nuint, nuint, void*>)Pointer;
16+
17+
public CallocFunc(delegate* unmanaged<nuint, nuint, void*> ptr) => Pointer = ptr;
18+
19+
public CallocFunc(CallocFuncDelegate proc) => Pointer = SilkMarshal.DelegateToPtr(proc);
20+
21+
public void Dispose() => SilkMarshal.Free(Pointer);
22+
23+
public static implicit operator CallocFunc(delegate* unmanaged<nuint, nuint, void*> pfn) =>
24+
new(pfn);
25+
26+
public static implicit operator delegate* unmanaged<nuint, nuint, void*>(CallocFunc pfn) =>
27+
(delegate* unmanaged<nuint, nuint, void*>)pfn.Pointer;
28+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public unsafe delegate void* CallocFuncDelegate(nuint arg0, nuint arg1);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public readonly unsafe struct CompareCallback : IDisposable
12+
{
13+
private readonly void* Pointer;
14+
public delegate* unmanaged<void*, void*, int> Handle =>
15+
(delegate* unmanaged<void*, void*, int>)Pointer;
16+
17+
public CompareCallback(delegate* unmanaged<void*, void*, int> ptr) => Pointer = ptr;
18+
19+
public CompareCallback(CompareCallbackDelegate proc) =>
20+
Pointer = SilkMarshal.DelegateToPtr(proc);
21+
22+
public void Dispose() => SilkMarshal.Free(Pointer);
23+
24+
public static implicit operator CompareCallback(delegate* unmanaged<void*, void*, int> pfn) =>
25+
new(pfn);
26+
27+
public static implicit operator delegate* unmanaged<void*, void*, int>(CompareCallback pfn) =>
28+
(delegate* unmanaged<void*, void*, int>)pfn.Pointer;
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// Ported from SDL.h and corresponding dependencies of SDL3.
4+
// Original source is Copyright (C) 1997-2024 Sam Lantinga. Licensed under the zlib license.
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using System.Runtime.InteropServices;
8+
9+
namespace Silk.NET.SDL;
10+
11+
public unsafe delegate int CompareCallbackDelegate(void* arg0, void* arg1);

0 commit comments

Comments
 (0)