196 lines
13 KiB
C#
196 lines
13 KiB
C#
using StgSharp.Controlling;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace StgSharp.Graphics
|
|
{
|
|
public static unsafe partial class Graphic
|
|
{
|
|
|
|
internal static void ConvertAPI<TDele>(IntPtr funcPtr, TDele dele)
|
|
{
|
|
if (funcPtr == IntPtr.Zero)
|
|
{
|
|
InternalIO.InternalWriteLog(
|
|
$"Failed to convert {nameof(funcPtr)} to {nameof(dele)}, the function pointer is zero.",
|
|
LogType.Error);
|
|
return;
|
|
}
|
|
if (dele != null)
|
|
{
|
|
InternalIO.InternalWriteLog(
|
|
$"Failed to convert {nameof(funcPtr)} to {nameof(dele)}, the delegate is not null.",
|
|
LogType.Error);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
dele = Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
|
|
InternalIO.InternalWriteLog($"Successfully lod glfw api {typeof(TDele)}", LogType.Info);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
InternalIO.InternalWriteLog(
|
|
$"Failed to convert {nameof(funcPtr)} to {nameof(dele)}, the runtime throws an exception:\n" +
|
|
$"{ex.Message}",
|
|
LogType.Error);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Init an instance of OpenGL program,
|
|
/// This method should be called before other
|
|
/// graphic methods, after LoadGL method.
|
|
/// </summary>
|
|
public static void InitGL(int majorVersion, int minorVersion)
|
|
{
|
|
|
|
if (InternalIO.glfw_Init == null)
|
|
{
|
|
IntPtr ptr1 = Marshal.AllocHGlobal(sizeof(GLFWapi));
|
|
GLFWapi* glfw = (GLFWapi*)ptr1;
|
|
//GLFWapi* ptr = (GLFWapi*)InternalIO.InternalInitGL(majorVersion, minorVersion, glfw);
|
|
IntPtr packptr = InternalIO.InternalInitGL(majorVersion, minorVersion, glfw);
|
|
glfwpack pack = Marshal.PtrToStructure<glfwpack>(packptr);
|
|
|
|
|
|
#if DEBUG
|
|
#endif
|
|
InternalIO.glfw_CreateWindow = pack.glfw_CreateWindow;
|
|
/*
|
|
{
|
|
ConvertAPI(pack.Init, InternalIO.glfw_Init);
|
|
ConvertAPI(pack.Terminate, InternalIO.glfw_Terminate);
|
|
ConvertAPI(pack.InitHint, InternalIO.glfw_InitHint);
|
|
ConvertAPI(pack.GetVersion, InternalIO.glfw_GetVersion);
|
|
ConvertAPI(pack.GetVersionString, InternalIO.glfw_GetVersionString);
|
|
ConvertAPI(pack.GetError, InternalIO.glfw_GetError);
|
|
ConvertAPI(pack.SetErrorCallback, InternalIO.glfw_SetErrorCallback);
|
|
ConvertAPI(pack.GetMonitors, InternalIO.glfw_GetMonitors);
|
|
ConvertAPI(pack.GetPrimaryMonitor, InternalIO.glfw_GetPrimaryMonitor);
|
|
ConvertAPI(pack.GetMonitorPos, InternalIO.glfw_GetMonitorPos);
|
|
ConvertAPI(pack.GetMonitorWorkarea, InternalIO.glfw_GetMonitorWorkarea);
|
|
ConvertAPI(pack.GetMonitorPhysicalSize, InternalIO.glfw_GetMonitorPhysicalSize);
|
|
ConvertAPI(pack.GetMonitorContentScale, InternalIO.glfw_GetMonitorContentScale);
|
|
ConvertAPI(pack.GetMonitorName, InternalIO.glfw_GetMonitorName);
|
|
ConvertAPI(pack.SetMonitorUserPointer, InternalIO.glfw_SetMonitorUserPointer);
|
|
ConvertAPI(pack.GetMonitorUserPointer, InternalIO.glfw_GetMonitorUserPointer);
|
|
ConvertAPI(pack.SetMonitorCallback, InternalIO.glfw_SetMonitorCallback);
|
|
ConvertAPI(pack.GetVideoModes, InternalIO.glfw_GetVideoModes);
|
|
ConvertAPI(pack.GetVideoMode, InternalIO.glfw_GetVideoMode);
|
|
ConvertAPI(pack.SetGamma, InternalIO.glfw_SetGamma);
|
|
ConvertAPI(pack.GetGammaRamp, InternalIO.glfw_GetGammaRamp);
|
|
ConvertAPI(pack.SetGammaRamp, InternalIO.glfw_SetGammaRamp);
|
|
ConvertAPI(pack.DefaultWindowHints, InternalIO.glfw_DefaultWindowHints);
|
|
ConvertAPI(pack.WindowHint, InternalIO.glfw_WindowHint);
|
|
ConvertAPI(pack.WindowHintString, InternalIO.glfw_WindowHintString);
|
|
ConvertAPI(pack.CreateWindow, InternalIO.glfw_CreateWindow);
|
|
ConvertAPI(pack.DestroyWindow, InternalIO.glfw_DestroyWindow);
|
|
ConvertAPI(pack.WindowShouldClose, InternalIO.glfw_WindowShouldClose);
|
|
ConvertAPI(pack.SetWindowShouldClose, InternalIO.glfw_SetWindowShouldClose);
|
|
ConvertAPI(pack.SetWindowTitle, InternalIO.glfw_SetWindowTitle);
|
|
ConvertAPI(pack.SetWindowIcon, InternalIO.glfw_SetWindowIcon);
|
|
ConvertAPI(pack.GetWindowPos, InternalIO.glfw_GetWindowPos);
|
|
ConvertAPI(pack.SetWindowPos, InternalIO.glfw_SetWindowPos);
|
|
ConvertAPI(pack.GetWindowSize, InternalIO.glfw_GetWindowSize);
|
|
ConvertAPI(pack.SetWindowSizeLimits, InternalIO.glfw_SetWindowSizeLimits);
|
|
ConvertAPI(pack.SetWindowAspectRatio, InternalIO.glfw_SetWindowAspectRatio);
|
|
ConvertAPI(pack.SetWindowSize, InternalIO.glfw_SetWindowSize);
|
|
ConvertAPI(pack.GetFramebufferSize, InternalIO.glfw_GetFramebufferSize);
|
|
ConvertAPI(pack.GetWindowFrameSize, InternalIO.glfw_GetWindowFrameSize);
|
|
ConvertAPI(pack.GetWindowContentScale, InternalIO.glfw_GetWindowContentScale);
|
|
ConvertAPI(pack.GetWindowOpacity, InternalIO.glfw_GetWindowOpacity);
|
|
ConvertAPI(pack.SetWindowOpacity, InternalIO.glfw_SetWindowOpacity);
|
|
ConvertAPI(pack.IconifyWindow, InternalIO.glfw_IconifyWindow);
|
|
ConvertAPI(pack.RestoreWindow, InternalIO.glfw_RestoreWindow);
|
|
ConvertAPI(pack.MaximizeWindow, InternalIO.glfw_MaximizeWindow);
|
|
ConvertAPI(pack.ShowWindow, InternalIO.glfw_ShowWindow);
|
|
ConvertAPI(pack.HideWindow, InternalIO.glfw_HideWindow);
|
|
ConvertAPI(pack.FocusWindow, InternalIO.glfw_FocusWindow);
|
|
ConvertAPI(pack.RequestWindowAttention, InternalIO.glfw_RequestWindowAttention);
|
|
ConvertAPI(pack.GetWindowMonitor, InternalIO.glfw_GetWindowMonitor);
|
|
ConvertAPI(pack.SetWindowMonitor, InternalIO.glfw_SetWindowMonitor);
|
|
ConvertAPI(pack.GetWindowAttrib, InternalIO.glfw_GetWindowAttrib);
|
|
ConvertAPI(pack.SetWindowAttrib, InternalIO.glfw_SetWindowAttrib);
|
|
ConvertAPI(pack.SetWindowUserPointer, InternalIO.glfw_SetWindowUserPointer);
|
|
ConvertAPI(pack.GetWindowUserPointer, InternalIO.glfw_GetWindowUserPointer);
|
|
ConvertAPI(pack.SetWindowPosCallback, InternalIO.glfw_SetWindowPosCallback);
|
|
ConvertAPI(pack.SetWindowSizeCallback, InternalIO.glfw_SetWindowSizeCallback);
|
|
ConvertAPI(pack.SetWindowCloseCallback, InternalIO.glfw_SetWindowCloseCallback);
|
|
ConvertAPI(pack.SetWindowRefreshCallback, InternalIO.glfw_SetWindowRefreshCallback);
|
|
ConvertAPI(pack.SetWindowFocusCallback, InternalIO.glfw_SetWindowFocusCallback);
|
|
ConvertAPI(pack.SetWindowIconifyCallback, InternalIO.glfw_SetWindowIconifyCallback);
|
|
ConvertAPI(pack.SetWindowMaximizeCallback, InternalIO.glfw_SetWindowMaximizeCallback);
|
|
ConvertAPI(pack.SetFramebufferSizeCallback, InternalIO.glfw_SetFramebufferSizeCallback);
|
|
ConvertAPI(pack.SetWindowContentScaleCallback, InternalIO.glfw_SetWindowContentScaleCallback);
|
|
ConvertAPI(pack.PollEvents, InternalIO.glfw_PollEvents);
|
|
ConvertAPI(pack.WaitEvents, InternalIO.glfw_WaitEvents);
|
|
ConvertAPI(pack.WaitEventsTimeout, InternalIO.glfw_WaitEventsTimeout);
|
|
ConvertAPI(pack.PostEmptyEvent, InternalIO.glfw_PostEmptyEvent);
|
|
ConvertAPI(pack.GetInputMode, InternalIO.glfw_GetInputMode);
|
|
ConvertAPI(pack.SetInputMode, InternalIO.glfw_SetInputMode);
|
|
ConvertAPI(pack.RawMouseMotionSupported, InternalIO.glfw_RawMouseMotionSupported);
|
|
ConvertAPI(pack.GetKeyName, InternalIO.glfw_GetKeyName);
|
|
ConvertAPI(pack.GetKeyScancode, InternalIO.glfw_GetKeyScancode);
|
|
ConvertAPI(pack.GetKey, InternalIO.glfw_GetKey);
|
|
ConvertAPI(pack.GetMouseButton, InternalIO.glfw_GetMouseButton);
|
|
ConvertAPI(pack.GetCursorPos, InternalIO.glfw_GetCursorPos);
|
|
ConvertAPI(pack.SetCursorPos, InternalIO.glfw_SetCursorPos);
|
|
ConvertAPI(pack.CreateCursor, InternalIO.glfw_CreateCursor);
|
|
ConvertAPI(pack.CreateStandardCursor, InternalIO.glfw_CreateStandardCursor);
|
|
ConvertAPI(pack.DestroyCursor, InternalIO.glfw_DestroyCursor);
|
|
ConvertAPI(pack.SetCursor, InternalIO.glfw_SetCursor);
|
|
ConvertAPI(pack.SetKeyCallback, InternalIO.glfw_SetKeyCallback);
|
|
ConvertAPI(pack.SetCharCallback, InternalIO.glfw_SetCharCallback);
|
|
ConvertAPI(pack.SetCharModsCallback, InternalIO.glfw_SetCharModsCallback);
|
|
ConvertAPI(pack.SetMouseButtonCallback, InternalIO.glfw_SetMouseButtonCallback);
|
|
ConvertAPI(pack.SetCursorPosCallback, InternalIO.glfw_SetCursorPosCallback);
|
|
ConvertAPI(pack.SetCursorEnterCallback, InternalIO.glfw_SetCursorEnterCallback);
|
|
ConvertAPI(pack.SetScrollCallback, InternalIO.glfw_SetScrollCallback);
|
|
ConvertAPI(pack.SetDropCallback, InternalIO.glfw_SetDropCallback);
|
|
ConvertAPI(pack.JoystickPresent, InternalIO.glfw_JoystickPresent);
|
|
ConvertAPI(pack.GetJoystickAxes, InternalIO.glfw_GetJoystickAxes);
|
|
ConvertAPI(pack.GetJoystickButtons, InternalIO.glfw_GetJoystickButtons);
|
|
ConvertAPI(pack.GetJoystickHats, InternalIO.glfw_GetJoystickHats);
|
|
ConvertAPI(pack.GetJoystickName, InternalIO.glfw_GetJoystickName);
|
|
ConvertAPI(pack.GetJoystickGUID, InternalIO.glfw_GetJoystickGUID);
|
|
ConvertAPI(pack.SetJoystickUserPointer, InternalIO.glfw_SetJoystickUserPointer);
|
|
ConvertAPI(pack.GetJoystickUserPointer, InternalIO.glfw_GetJoystickUserPointer);
|
|
ConvertAPI(pack.JoystickIsGamepad, InternalIO.glfw_JoystickIsGamepad);
|
|
ConvertAPI(pack.SetJoystickCallback, InternalIO.glfw_SetJoystickCallback);
|
|
ConvertAPI(pack.UpdateGamepadMappings, InternalIO.glfw_UpdateGamepadMappings);
|
|
ConvertAPI(pack.GetGamepadName, InternalIO.glfw_GetGamepadName);
|
|
ConvertAPI(pack.GetGamepadState, InternalIO.glfw_GetGamepadState);
|
|
ConvertAPI(pack.SetClipboardString, InternalIO.glfw_SetClipboardString);
|
|
ConvertAPI(pack.GetClipboardString, InternalIO.glfw_GetClipboardString);
|
|
ConvertAPI(pack.GetTime, InternalIO.glfw_GetTime);
|
|
ConvertAPI(pack.SetTime, InternalIO.glfw_SetTime);
|
|
ConvertAPI(pack.GetTimerValue, InternalIO.glfw_GetTimerValue);
|
|
ConvertAPI(pack.GetTimerFrequency, InternalIO.glfw_GetTimerFrequency);
|
|
ConvertAPI(pack.MakeContextCurrent, InternalIO.glfw_MakeContextCurrent);
|
|
ConvertAPI(pack.GetCurrentContext, InternalIO.glfw_GetCurrentContext);
|
|
ConvertAPI(pack.SwapBuffers, InternalIO.glfw_SwapBuffers);
|
|
ConvertAPI(pack.SwapInterval, InternalIO.glfw_SwapInterval);
|
|
ConvertAPI(pack.ExtensionSupported, InternalIO.glfw_ExtensionSupported);
|
|
ConvertAPI(pack.GetProcAddress, InternalIO.glfw_GetProcAddress);
|
|
ConvertAPI(pack.VulkanSupported, InternalIO.glfw_VulkanSupported);
|
|
ConvertAPI(pack.GetRequiredInstanceExtensions, InternalIO.glfw_GetRequiredInstanceExtensions);
|
|
//ConvertAPI(pack.GetInstanceProcAddress, InternalIO.glfw_GetInstanceProcAddress);
|
|
//ConvertAPI(pack.GetPhysicalDevicePresentationSupport, InternalIO.glfw_GetPhysicalDevicePresentationSupport);
|
|
//ConvertAPI(pack.CreateWindowSurface, InternalIO.glfw_CreateWindowSurface);
|
|
}
|
|
*/
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("Do not init GL twice");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|