Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
MVP OpenGL bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Perksey committed Nov 12, 2023
1 parent 8fbed2b commit a29abfb
Show file tree
Hide file tree
Showing 24 changed files with 28,862 additions and 28,062 deletions.
7 changes: 7 additions & 0 deletions SilkX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.Maths.Benchmarks", "eng\benchmarks\Silk.NET.Maths.Benchmarks\Silk.NET.Maths.Benchmarks.csproj", "{AF6C70ED-D6A8-4C57-8DB3-EAFF94396049}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.OpenGL", "sources\OpenGL\Silk.NET.OpenGL.csproj", "{9625C977-25BE-48F3-9B6F-BC94B8B799A6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -116,6 +118,10 @@ Global
{AF6C70ED-D6A8-4C57-8DB3-EAFF94396049}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF6C70ED-D6A8-4C57-8DB3-EAFF94396049}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF6C70ED-D6A8-4C57-8DB3-EAFF94396049}.Release|Any CPU.Build.0 = Release|Any CPU
{9625C977-25BE-48F3-9B6F-BC94B8B799A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9625C977-25BE-48F3-9B6F-BC94B8B799A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9625C977-25BE-48F3-9B6F-BC94B8B799A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9625C977-25BE-48F3-9B6F-BC94B8B799A6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -131,6 +137,7 @@ Global
{01683C11-4721-43AB-B53C-15EBE935B48F} = {A5578D12-9E77-4647-8C22-0DBD17760BFF}
{B681E21A-47A2-4635-96EE-60D8D63FBEA9} = {475AEF7B-0154-4989-AF82-97E3A95A96AF}
{AF6C70ED-D6A8-4C57-8DB3-EAFF94396049} = {B681E21A-47A2-4635-96EE-60D8D63FBEA9}
{9625C977-25BE-48F3-9B6F-BC94B8B799A6} = {DD29EA8F-B1A6-45AA-8D2E-B38DA56D9EF6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {78D2CF6A-60A1-43E3-837B-00B73C9DA384}
Expand Down
2 changes: 2 additions & 0 deletions eng/silktouch/opengl/remap.rsp
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
--remap
__GLsync=GLsync
_cl_context=void
_cl_event=void
198 changes: 146 additions & 52 deletions sources/Core/Pointers/PointerExtensions.cs

Large diffs are not rendered by default.

113 changes: 84 additions & 29 deletions sources/Core/Pointers/Ptr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public Ptr(void* ptr)
/// </summary>
/// <param name="index"></param>
/// <returns>the offset pointer value</returns>
public ref byte this[nuint index] => ref Unsafe.AsRef<byte>(((nuint)Native + (index)).ToPointer());
public ref byte this[nuint index] =>
ref Unsafe.AsRef<byte>(((nuint)Native + (index)).ToPointer());

/// <summary>
/// Gets the underlying pointer.
Expand All @@ -41,7 +42,9 @@ public Ptr(void* ptr)
/// <remarks>
/// This function allows a <see cref="Ptr"/> to be used in a <c>fixed</c> statement.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public ref byte GetPinnableReference() => ref Handle;

/// <summary>
Expand All @@ -50,25 +53,33 @@ public Ptr(void* ptr)
/// <param name="length">the span length</param>
/// <typeparam name="T"></typeparam>
/// <returns>the span</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public Span<T> AsSpan<T>(int length) where T : unmanaged => new(Native, length);
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public Span<T> AsSpan<T>(int length)
where T : unmanaged => new(Native, length);

/// <summary>
/// Creates an array with the given length for this pointer
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="length"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public T[] ToArray<T>(int length) where T : unmanaged => AsSpan<T>(length).ToArray();
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public T[] ToArray<T>(int length)
where T : unmanaged => AsSpan<T>(length).ToArray();

/// <summary>
/// Determines whether a pointer and reference are equal
/// </summary>
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and reference are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(Ptr lh, Ref rh) => lh.Native == (void*)rh;

/// <summary>
Expand All @@ -77,7 +88,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and reference are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(Ptr lh, Ref rh) => lh.Native != (void*)rh;

/// <summary>
Expand All @@ -86,7 +99,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and reference are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(Ref lh, Ptr rh) => (void*)lh == rh.Native;

/// <summary>
Expand All @@ -95,7 +110,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and reference are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(Ref lh, Ptr rh) => (void*)lh != rh.Native;

/// <summary>
Expand All @@ -104,7 +121,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the two pointers are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(Ptr lh, void* rh) => lh.Native == rh;

/// <summary>
Expand All @@ -113,7 +132,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the two pointers are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(Ptr lh, void* rh) => lh.Native != rh;

/// <summary>
Expand All @@ -122,7 +143,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the two pointers are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(void* lh, Ptr rh) => lh == rh.Native;

/// <summary>
Expand All @@ -131,7 +154,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the two pointers are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(void* lh, Ptr rh) => lh != rh.Native;

/// <summary>
Expand All @@ -140,7 +165,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and nullptr are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(Ptr lh, NullPtr rh) => lh.Native == null;

/// <summary>
Expand All @@ -149,7 +176,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and nullptr are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(Ptr lh, NullPtr rh) => lh.Native != null;

/// <summary>
Expand All @@ -158,7 +187,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and nullptr are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(NullPtr lh, Ptr rh) => null == rh.Native;

/// <summary>
Expand All @@ -167,56 +198,72 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>whether the pointer and nullptr are not equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(NullPtr lh, Ptr rh) => null != rh.Native;

/// <summary>
/// Creates a <see cref="Ptr"/> from a native pointer
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static implicit operator Ptr(void* ptr) => new(ptr);

/// <summary>
/// Creates a native pointer from a <see cref="Ptr"/>
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static implicit operator void*(Ptr ptr) => ptr.Native;

/// <summary>
/// Creates a <see cref="Ref"/> from a <see cref="Ptr"/>
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static implicit operator Ref(Ptr ptr) => ptr;

/// <summary>
/// Creates a <see cref="Ptr"/> from a <see cref="Ref"/>
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static explicit operator Ptr(Ref ptr) => (void*)ptr;

/// <summary>
/// Reads this pointer as a null terminated string
/// </summary>
/// <returns>null-terminated string</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public string ReadToString() => SilkMarshal.NativeToString(ref Handle) ?? string.Empty;

/// <summary>
/// Creates a string from a <see cref="Ptr"/>
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static explicit operator string(Ptr ptr) => ptr.ReadToString();

/// <summary>
/// Creates a null ptr
/// </summary>
/// <param name="ptr"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static implicit operator Ptr(NullPtr ptr) => new(null);

/// <summary>
Expand All @@ -225,7 +272,9 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>Whether the two pointers are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator ==(Ptr lh, Ptr rh) => lh.Native == rh.Native;

/// <summary>
Expand All @@ -234,15 +283,21 @@ public Ptr(void* ptr)
/// <param name="lh"></param>
/// <param name="rh"></param>
/// <returns>Whether the two pointers are equal</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public static bool operator !=(Ptr lh, Ptr rh) => lh.Native != rh.Native;

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override bool Equals([NotNullWhen(true)] object? obj) => base.Equals(obj);

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
[MethodImpl(
MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization
)]
public override int GetHashCode() => base.GetHashCode();
}
}
Loading

0 comments on commit a29abfb

Please sign in to comment.