91 lines
2.5 KiB
C#
91 lines
2.5 KiB
C#
using StgSharp.Graphics;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace StgSharp
|
|
{
|
|
internal enum GraphicAPI : byte
|
|
{
|
|
GL,
|
|
DX,
|
|
VK
|
|
}
|
|
|
|
public static class Platform
|
|
{
|
|
|
|
internal static GraphicAPI API;
|
|
|
|
/// <summary>
|
|
/// Version of current StgSharp platform.
|
|
/// Main version represent in hundred's digit,
|
|
/// and sub version represent in ten's digit.
|
|
/// </summary>
|
|
public const long version = 430;
|
|
|
|
/// <summary>
|
|
/// Init an instance of OpenGL program,
|
|
/// This method should be called before other
|
|
/// graphic methods, after LoadGL method.
|
|
/// </summary>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void InitGL(int majorVersion, int minorVersion)
|
|
{
|
|
InternalIO.InternalInitGL(majorVersion, minorVersion);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Write a log message to log file, and mark the level of this message.
|
|
/// </summary>
|
|
/// <param name="message">A string contains information of how current evironment runs.</param>
|
|
/// <param name="logType">The severity of current message.</param>
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static void WriteLog(string message, LogType logType)
|
|
{
|
|
InternalIO.InternalWriteLog(message, logType);
|
|
}
|
|
|
|
internal static TDele ConvertAPI<TDele>(IntPtr funcPtr)
|
|
{
|
|
if (funcPtr == IntPtr.Zero)
|
|
{
|
|
throw new Exception("Failed to convert api, the function pointer is zero.");
|
|
}
|
|
try
|
|
{
|
|
return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
internal static Delegate ConvertAPI(IntPtr funcPtr, Type T)
|
|
{
|
|
|
|
if (funcPtr == IntPtr.Zero)
|
|
{
|
|
throw new Exception("Failed to convert api, the function pointer is zero.");
|
|
}
|
|
try
|
|
{
|
|
return Marshal.GetDelegateForFunctionPointer(funcPtr, T);
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|