OpenGL rebuild project start!

This commit is contained in:
Nitload
2023-04-29 03:06:32 +08:00
parent 7dba067146
commit 4dd3f4f6d1
263 changed files with 51374 additions and 1522 deletions
@@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Graphic.GL
{
/// <summary>
/// Provides a common foundation for all flat API bindings and implements the extension loading interface.
/// </summary>
public abstract class BindingsBase
{
/// <summary>
/// Constructs a new BindingsBase instance.
/// </summary>
public BindingsBase()
{
}
/// <summary>
/// Marshals a pointer to a null-terminated byte array to a new <c>System.String</c>.
/// This method supports OpenTK and is not intended to be called by user code.
/// </summary>
/// <param name="ptr">A pointer to a null-terminated byte array.</param>
/// <returns>
/// A <c>System.String</c> with the data from <paramref name="ptr"/>.
/// </returns>
protected static string MarshalPtrToString(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
{
throw new ArgumentException("ptr");
}
unsafe
{
sbyte* str = (sbyte*)ptr;
int len = 0;
while (*str != 0)
{
++len;
++str;
}
return new string((sbyte*)ptr, 0, len, Encoding.UTF8);
}
}
/// <summary>
/// Marshal a <c>System.String</c> to unmanaged memory.
/// The resulting string is encoded in UTF8 and must be freed
/// with <c>FreeStringPtr</c>.
/// </summary>
/// <param name="str">The <c>System.String</c> to marshal.</param>
/// <returns>
/// An unmanaged pointer containing the marshalled string.
/// This pointer must be freed with <c>FreeStringPtr</c>
/// </returns>
protected static IntPtr MarshalStringToPtr(string str)
{
if (string.IsNullOrEmpty(str))
{
return IntPtr.Zero;
}
// Allocate a buffer big enough to hold the marshalled string.
// GetMaxByteCount() appears to allocate space for the final NUL
// character, but allocate an extra one just in case (who knows
// what old Mono version would do here.)
int max_count = Encoding.UTF8.GetMaxByteCount(str.Length) + 1;
IntPtr ptr = Marshal.AllocHGlobal(max_count);
if (ptr == IntPtr.Zero)
{
throw new OutOfMemoryException();
}
// Pin the managed string and convert it to UTF8 using
// the pointer overload of System.Encoding.UTF8.GetBytes().
unsafe
{
fixed (char* pstr = str)
{
int actual_count = Encoding.UTF8.GetBytes(pstr, str.Length, (byte*)ptr, max_count);
Marshal.WriteByte(ptr, actual_count, 0); // Append '\0' at the end of the string
return ptr;
}
}
}
/// <summary>
/// Frees a marshalled string that allocated by <c>MarshalStringToPtr</c>.
/// </summary>
/// <param name="ptr">An unmanaged pointer allocated with <c>MarshalStringToPtr</c></param>
protected static void FreeStringPtr(IntPtr ptr)
{
Marshal.FreeHGlobal(ptr);
}
/// <summary>
/// Marshals a <c>System.String</c> array to unmanaged memory by calling
/// Marshal.AllocHGlobal for each element.
/// </summary>
/// <returns>An unmanaged pointer to an array of null-terminated strings</returns>
/// <param name="str_array">The string array to marshal.</param>
protected static IntPtr MarshalStringArrayToPtr(string[] str_array)
{
IntPtr ptr = IntPtr.Zero;
if (str_array != null && str_array.Length != 0)
{
ptr = Marshal.AllocHGlobal(str_array.Length * IntPtr.Size);
if (ptr == IntPtr.Zero)
{
throw new OutOfMemoryException();
}
int i = 0;
try
{
for (i = 0; i < str_array.Length; i++)
{
IntPtr str = MarshalStringToPtr(str_array[i]);
Marshal.WriteIntPtr(ptr, i * IntPtr.Size, str);
}
}
catch (OutOfMemoryException)
{
for (i = i - 1; i >= 0; --i)
{
Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size));
}
Marshal.FreeHGlobal(ptr);
throw;
}
}
return ptr;
}
/// <summary>
/// Frees a marshalled string that allocated by <c>MarshalStringArrayToPtr</c>.
/// </summary>
/// <param name="ptr">An unmanaged pointer allocated with <c>MarshalStringArrayToPtr</c></param>
/// <param name="length">The length of the string array.</param>
protected static void FreeStringArrayPtr(IntPtr ptr, int length)
{
for (int i = 0; i < length; i++)
{
Marshal.FreeHGlobal(Marshal.ReadIntPtr(ptr, i * IntPtr.Size));
}
Marshal.FreeHGlobal(ptr);
}
private protected static void InitializeDummyEntryPoints(IntPtr[] entryPoints)
{
var ptr = Marshal.GetFunctionPointerForDelegate(UninitializedDelegate);
for (var i = 0; i < entryPoints.Length; i++)
{
entryPoints[i] = ptr;
}
}
private static readonly Action UninitializedDelegate = Uninitialized;
private static void Uninitialized()
{
throw new InvalidOperationException("You need to initialize the OpenGL binding first by calling LoadBindings() or creating a compatible OpenGL window.");
}
}
}
+16
View File
@@ -0,0 +1,16 @@
using System;
namespace StgSharp.Graphic.GL
{
/// <summary>
/// A delegate used to receive debug information.
/// </summary>
/// <param name="source">The source of the callback.</param>
/// <param name="type">The type of the callback.</param>
/// <param name="id">The ID of the callback.</param>
/// <param name="severity">The severity of the callback.</param>
/// <param name="length">The length of the callback message.</param>
/// <param name="message">A pointer to the callback message.</param>
/// <param name="userParam">A user supplied pointer that will be passed on each callback.</param>
public delegate void DebugProc(DebugSource source, DebugType type, int id, DebugSeverity severity, int length, IntPtr message, IntPtr userParam);
}
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphic.GL
{
public struct CombinerPortionNV { }
public struct DebugProcAmd { }
public struct DebugProcArb { }
public struct DebugProcKhr { }
public struct ElementPointerTypeATI { }
public struct FragmentLightParameterSGIX { }
public struct IglooFunctionSelectSGIX { }
public struct IndexFunctionEXT { }
public struct MapTypeNV { }
public struct MatrixIndexPointerTypeARB { }
public struct ProgramFormat { }
public struct ProgramStringProperty { }
public struct ProgramTarget { }
public struct ReplacementCodeTypeSUN { }
public struct SecondaryColorPointerTypeIBM { }
public struct Struct_cl_context { }
public struct Struct_cl_event { }
public struct VertexShaderWriteMaskEXT { }
public struct VertexWeightPointerTypeEXT { }
public struct WeightPointerTypeARB { }
}
@@ -0,0 +1,33 @@
using System.Runtime.InteropServices;
namespace StgSharp.Graphic.GL
{
/// <summary>
/// Contains the library name of OpenGL.
/// </summary>
internal class LibraryNameContainer
{
/// <inheritdoc />
public static string Linux => "libGL.so";
/// <inheritdoc />
public static string MacOS => "/System/Library/Frameworks/OpenGL.framework/OpenGL";
/// <inheritdoc />
public static string Android => "libGL.so";
/// <inheritdoc />
public static string IOS => "/System/Library/Frameworks/OpenGL.framework/OpenGL";
/// <inheritdoc />
public static string Windows => "opengl32.dll";
public static string GetLibraryNameForCurrentPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) return Linux;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return Windows;
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return MacOS;
else return "unknown platform";
}
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff