daily update on 20240213 by nitload youmu. 逐步弃用GLFW,正在使用wgl重写glfw底层,相关实现转移到C#实现,SSC彻底变成线性代数计算器。
This commit is contained in:
@@ -1,13 +1,26 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Envitronment;
|
||||
using StgSharp.Envitronment.Win32;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Math;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
|
||||
#if Windows
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Graphics.OpenGL;
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
using Windows.Win32.UI;
|
||||
#endif
|
||||
namespace StgSharp
|
||||
{
|
||||
internal enum GraphicAPI : byte
|
||||
@@ -17,10 +30,21 @@ namespace StgSharp
|
||||
VK
|
||||
}
|
||||
|
||||
public static class Platform
|
||||
public static partial class Platform
|
||||
{
|
||||
|
||||
internal static GraphicAPI API;
|
||||
internal static GraphicAPI API = default;
|
||||
|
||||
private static uint markCount = 0;
|
||||
|
||||
public static void Mark(bool needConsole)
|
||||
{
|
||||
markCount++;
|
||||
if (needConsole)
|
||||
{
|
||||
Console.WriteLine(markCount);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Version of current StgSharp platform.
|
||||
@@ -37,6 +61,11 @@ namespace StgSharp
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void InitGL(int majorVersion, int minorVersion)
|
||||
{
|
||||
if (API != default)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
InternalIO.InternalInitGL(majorVersion, minorVersion);
|
||||
}
|
||||
|
||||
@@ -86,5 +115,26 @@ namespace StgSharp
|
||||
}
|
||||
}
|
||||
|
||||
public static void Track(
|
||||
object target,
|
||||
string message,
|
||||
[CallerFilePath] string filePath = "",
|
||||
[CallerMemberName] string callerName = "",
|
||||
[CallerLineNumber] int lineNumber = 0
|
||||
)
|
||||
{
|
||||
string log = $"Tracked object: {nameof(target)}\n";
|
||||
Type t = target.GetType();
|
||||
FieldInfo[] fieldInfo = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
|
||||
foreach (FieldInfo field in fieldInfo)
|
||||
{
|
||||
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
|
||||
}
|
||||
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
|
||||
log += $"Additional information:\n{message}\n";
|
||||
InternalIO.InternalWriteLog(log, LogType.Info);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Win32.Foundation;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
using StgSharpDebug.Environment;
|
||||
using StgSharp.Math;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if Windows
|
||||
#pragma warning disable CA1416 // 验证平台兼容性
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using StgSharp.Envitronment.Win32;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Graphics.OpenGL;
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
using Windows.Win32.UI.WindowsAndMessaging;
|
||||
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
public unsafe static partial class Platform
|
||||
{
|
||||
|
||||
internal static unsafe void CreatDummyContext()
|
||||
{
|
||||
string winclass_name = "Dummy_WGL_context";
|
||||
WNDCLASSW window_class = new WNDCLASSW()
|
||||
{
|
||||
style = WNDCLASS_STYLES.CS_HREDRAW | WNDCLASS_STYLES.CS_VREDRAW | WNDCLASS_STYLES.CS_OWNDC,
|
||||
lpfnWndProc = PInvoke.DefWindowProc,
|
||||
hInstance = new HINSTANCE(PInvoke.GetModuleHandle("").DangerousGetHandle()),
|
||||
lpszClassName = new PCWSTR((char*)Marshal.StringToHGlobalUni(winclass_name))
|
||||
};
|
||||
|
||||
if (PInvoke.RegisterClass(window_class) != 0)
|
||||
{
|
||||
throw new Exception("Failed in registing OpenGL window.");
|
||||
}
|
||||
|
||||
HWND h = PInvoke.CreateWindowEx(
|
||||
Windows.Win32.UI.WindowsAndMessaging.WINDOW_EX_STYLE.WS_EX_LTRREADING,
|
||||
winclass_name,
|
||||
"Dummy OpenGL window",
|
||||
Windows.Win32.UI.WindowsAndMessaging.WINDOW_STYLE.WS_OVERLAPPED,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
default,
|
||||
default,
|
||||
new LibHandle(window_class.hInstance.Value, false),
|
||||
default
|
||||
);
|
||||
if (h == default)
|
||||
{
|
||||
throw new Exception("Failed in registing OpenGL window.");
|
||||
}
|
||||
HDC hdc = PInvoke.GetDC(h);
|
||||
|
||||
PIXELFORMATDESCRIPTOR pfd = new PIXELFORMATDESCRIPTOR();
|
||||
pfd.nSize = (ushort)Marshal.SizeOf(pfd);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_FLAGS.PFD_DRAW_TO_WINDOW | PFD_FLAGS.PFD_SUPPORT_OPENGL
|
||||
| PFD_FLAGS.PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_PIXEL_TYPE.PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.iLayerType = PFD_LAYER_TYPE.PFD_MAIN_PLANE;
|
||||
|
||||
int pixelFormat = PInvoke.ChoosePixelFormat(hdc, &pfd);
|
||||
|
||||
if (pixelFormat == 0)
|
||||
{
|
||||
throw new Exception("Failed in registing OpenGL window.");
|
||||
}
|
||||
if (PInvoke.SetPixelFormat(hdc, pixelFormat, &pfd))
|
||||
{
|
||||
throw new Exception("Failed in registing OpenGL window.");
|
||||
}
|
||||
HGLRC hglrc = PInvoke.wglCreateContext(hdc);
|
||||
|
||||
PInvoke.wglMakeCurrent(hdc, hglrc);
|
||||
|
||||
wglEx.LoadWGLex();
|
||||
|
||||
PInvoke.wglMakeCurrent(hdc, HGLRC.Null);
|
||||
PInvoke.wglDeleteContext(hglrc);
|
||||
PInvoke.ReleaseDC(h, hdc);
|
||||
PInvoke.DestroyWindow(h);
|
||||
|
||||
}
|
||||
|
||||
internal static unsafe HGLRC InitGL(HDC realHDC)
|
||||
{
|
||||
CreatDummyContext();
|
||||
|
||||
int[] pixelFormatAttribute = new int[] {
|
||||
WGLconst.DRAW_TO_WINDOW_ARB, 1,
|
||||
WGLconst.SUPPORT_OPENGL_ARB, 1,
|
||||
WGLconst.DOUBLE_BUFFER_ARB, 1,
|
||||
WGLconst.ACCELERATION_ARB, WGLconst.FULL_ACCELERATION_ARB,
|
||||
WGLconst.PIXEL_TYPE_ARB, WGLconst.TYPE_RGBA_ARB,
|
||||
WGLconst.COLOR_BITS_ARB, 32,
|
||||
WGLconst.DEPTH_BITS_ARB, 24,
|
||||
WGLconst.STENCIL_BITS_ARB,8
|
||||
};
|
||||
|
||||
int piFormat;
|
||||
uint length;
|
||||
|
||||
wglEx.glChoosePixelFormatARB(new DeviceContextHandle(realHDC), pixelFormatAttribute, out piFormat, out length);
|
||||
if (length == 0)
|
||||
{
|
||||
throw new Exception("Failed in creating OpenGL core profile.");
|
||||
}
|
||||
PIXELFORMATDESCRIPTOR pfd = default;
|
||||
PInvoke.DescribePixelFormat(realHDC, piFormat, (uint)Marshal.SizeOf(pfd), &pfd);
|
||||
if (PInvoke.SetPixelFormat(realHDC, piFormat, in pfd))
|
||||
{
|
||||
throw new Exception("Failed in creating OpenGL core profile.");
|
||||
}
|
||||
int[] glVersionAttribute = new int[] {
|
||||
WGLconst.CONTEXT_MAJOR_VERSION_ARB,4,
|
||||
WGLconst.CONTEXT_MINOR_VERSION_ARB,6,
|
||||
WGLconst.CONTEXT_PROFILE_MASK_ARB, WGLconst.CONTEXT_CORE_PROFILE_BIT_ARB
|
||||
};
|
||||
|
||||
HGLRC coreGL = new(wglEx.wglCreateContextAttribsARB(
|
||||
new DeviceContextHandle(realHDC), GlRenderContextHandle.Null, glVersionAttribute).Value);
|
||||
if (coreGL.Value == IntPtr.Zero)
|
||||
{
|
||||
throw new Exception("Failed in creating OpenGL core profile.");
|
||||
}
|
||||
|
||||
return coreGL;
|
||||
|
||||
}
|
||||
|
||||
internal static unsafe LRESULT window_callback(
|
||||
HWND window, uint msg, WPARAM wparam, LPARAM lparam)
|
||||
{
|
||||
LRESULT ret = new LRESULT(0);
|
||||
switch (msg)
|
||||
{
|
||||
case 0x0010: break;
|
||||
case 0x0002:
|
||||
PInvoke.PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
ret = PInvoke.DefWindowProc(window, msg, wparam, lparam);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
internal static unsafe IntPtr CreateForm(HINSTANCE inst)
|
||||
{
|
||||
string formName = "Hello Stg#!";
|
||||
|
||||
WNDCLASSW window_class = new WNDCLASSW()
|
||||
{
|
||||
style = WNDCLASS_STYLES.CS_VREDRAW | WNDCLASS_STYLES.CS_HREDRAW | WNDCLASS_STYLES.CS_OWNDC,
|
||||
lpfnWndProc = window_callback,
|
||||
hInstance = inst,
|
||||
hCursor = new HCURSOR(PInvoke.LoadCursor(default, "IDC_ARROW").DangerousGetHandle()),
|
||||
hbrBackground = HBRUSH.Null,
|
||||
lpszClassName = new PCWSTR((char*)Marshal.StringToHGlobalUni(formName))
|
||||
};
|
||||
|
||||
if (PInvoke.RegisterClass(in window_class) == 0)
|
||||
{
|
||||
throw new Exception("Failed to create window instace.");
|
||||
}
|
||||
|
||||
RECT rect = default;
|
||||
rect.right = 1024;
|
||||
rect.bottom = 576;
|
||||
|
||||
uint window_style = WGLconst.WS_OVERLAPPEDWINDOW;
|
||||
PInvoke.AdjustWindowRect(ref rect, (WINDOW_STYLE)window_style, false);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma warning restore CA1416 // 验证平台兼容性
|
||||
#endif
|
||||
@@ -0,0 +1,279 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
||||
|
||||
#if Windows
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Graphics.OpenGL;
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
|
||||
namespace StgSharp.Envitronment.Win32
|
||||
{
|
||||
public readonly partial struct DeviceContextHandle
|
||||
: IEquatable<DeviceContextHandle>
|
||||
{
|
||||
internal readonly IntPtr Value;
|
||||
|
||||
internal DeviceContextHandle(nint value) => this.Value = value;
|
||||
|
||||
public static explicit operator DeviceContextHandle(IntPtr value) => new DeviceContextHandle(value);
|
||||
|
||||
public static implicit operator IntPtr(DeviceContextHandle value) => value.Value;
|
||||
public static bool operator !=(DeviceContextHandle left, DeviceContextHandle right) => !(left == right);
|
||||
|
||||
public static bool operator ==(DeviceContextHandle left, DeviceContextHandle right) => left.Value == right.Value;
|
||||
public bool Equals(DeviceContextHandle other) => this.Value == other.Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is DeviceContextHandle other && this.Equals(other);
|
||||
|
||||
public override int GetHashCode() => this.Value.GetHashCode();
|
||||
|
||||
public override string ToString() => $"0x{this.Value:x}";
|
||||
}
|
||||
|
||||
public readonly partial struct GlRenderContextHandle
|
||||
: IEquatable<GlRenderContextHandle>
|
||||
{
|
||||
internal readonly IntPtr Value;
|
||||
|
||||
internal GlRenderContextHandle(IntPtr value) => this.Value = value;
|
||||
|
||||
internal static GlRenderContextHandle Null => default;
|
||||
|
||||
internal bool IsNull => Value == default;
|
||||
|
||||
public static explicit operator GlRenderContextHandle(IntPtr value) => new GlRenderContextHandle(value);
|
||||
|
||||
public static implicit operator IntPtr(GlRenderContextHandle value) => value.Value;
|
||||
public static bool operator !=(GlRenderContextHandle left, GlRenderContextHandle right) => !(left == right);
|
||||
|
||||
public static bool operator ==(GlRenderContextHandle left, GlRenderContextHandle right) => left.Value == right.Value;
|
||||
public bool Equals(GlRenderContextHandle other) => this.Value == other.Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is GlRenderContextHandle other && this.Equals(other);
|
||||
|
||||
public override int GetHashCode() => this.Value.GetHashCode();
|
||||
|
||||
public override string ToString() => $"0x{this.Value:x}";
|
||||
}
|
||||
|
||||
public struct WGLconst
|
||||
{
|
||||
#region Attribute
|
||||
public const int ACCELERATION_ARB = 0x2003;
|
||||
public const int ACCUM_ALPHA_BITS_ARB = 0x2021;
|
||||
public const int ACCUM_BITS_ARB = 0x201D;
|
||||
public const int ACCUM_BLUE_BITS_ARB = 0x2020;
|
||||
public const int ACCUM_GREEN_BITS_ARB = 0x201F;
|
||||
public const int ACCUM_RED_BITS_ARB = 0x201E;
|
||||
public const int ALPHA_BITS_ARB = 0x201B;
|
||||
public const int ALPHA_SHIFT_ARB = 0x201C;
|
||||
public const int AUX_BUFFERS_ARB = 0x2024;
|
||||
public const int BLUE_BITS_ARB = 0x2019;
|
||||
public const int BLUE_SHIFT_ARB = 0x201A;
|
||||
public const int COLOR_BITS_ARB = 0x2014;
|
||||
public const int DEPTH_BITS_ARB = 0x2022;
|
||||
public const int DOUBLE_BUFFER_ARB = 0x2011;
|
||||
public const int DRAW_TO_BITMAP_ARB = 0x2002;
|
||||
public const int DRAW_TO_WINDOW_ARB = 0x2001;
|
||||
public const int FULL_ACCELERATION_ARB = 0x2027;
|
||||
public const int GENERIC_ACCELERATION_ARB = 0x2026;
|
||||
public const int GREEN_BITS_ARB = 0x2017;
|
||||
public const int GREEN_SHIFT_ARB = 0x2018;
|
||||
public const int NEED_PALETTE_ARB = 0x2004;
|
||||
public const int NEED_SYSTEM_PALETTE_ARB = 0x2005;
|
||||
public const int NO_ACCELERATION_ARB = 0x2025;
|
||||
public const int NUMBER_OVERLAYS_ARB = 0x2008;
|
||||
public const int NUMBER_PIXEL_FORMATS_ARB = 0x2000;
|
||||
public const int NUMBER_UNDERLAYS_ARB = 0x2009;
|
||||
public const int PIXEL_TYPE_ARB = 0x2013;
|
||||
public const int RED_BITS_ARB = 0x2015;
|
||||
public const int RED_SHIFT_ARB = 0x2016;
|
||||
public const int SHARE_ACCUM_ARB = 0x200E;
|
||||
public const int SHARE_DEPTH_ARB = 0x200C;
|
||||
public const int SHARE_STENCIL_ARB = 0x200D;
|
||||
public const int STENCIL_BITS_ARB = 0x2023;
|
||||
public const int STEREO_ARB = 0x2012;
|
||||
public const int SUPPORT_GDI_ARB = 0x200F;
|
||||
public const int SUPPORT_OPENGL_ARB = 0x2010;
|
||||
public const int SWAP_COPY_ARB = 0x2029;
|
||||
public const int SWAP_EXCHANGE_ARB = 0x2028;
|
||||
public const int SWAP_LAYER_BUFFERS_ARB = 0x2006;
|
||||
public const int SWAP_METHOD_ARB = 0x2007;
|
||||
public const int SWAP_UNDEFINED_ARB = 0x202A;
|
||||
public const int TRANSPARENT_ALPHA_VALUE_ARB = 0x203A;
|
||||
public const int TRANSPARENT_ARB = 0x200A;
|
||||
public const int TRANSPARENT_BLUE_VALUE_ARB = 0x2039;
|
||||
public const int TRANSPARENT_GREEN_VALUE_ARB = 0x2038;
|
||||
public const int TRANSPARENT_INDEX_VALUE_ARB = 0x203B;
|
||||
public const int TRANSPARENT_RED_VALUE_ARB = 0x2037;
|
||||
public const int TYPE_COLORINDEX_ARB = 0x202C;
|
||||
public const int TYPE_RGBA_ARB = 0x202B;
|
||||
#endregion
|
||||
#region context
|
||||
|
||||
public const int CONTEXT_MAJOR_VERSION_ARB = 0x2091;
|
||||
public const int CONTEXT_MINOR_VERSION_ARB = 0x2092;
|
||||
public const int CONTEXT_LAYER_PLANE_ARB = 0x2093;
|
||||
public const int CONTEXT_FLAGS_ARB = 0x2094;
|
||||
public const int CONTEXT_PROFILE_MASK_ARB = 0x9126;
|
||||
public const int CONTEXT_DEBUG_BIT_ARB = 0x0001;
|
||||
public const int CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
|
||||
public const int CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
|
||||
public const int CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
|
||||
public const int ERROR_INVALID_VERSION_ARB = 0x2095;
|
||||
public const int ERROR_INVALID_PROFILE_ARB = 0x2096;
|
||||
|
||||
#endregion
|
||||
#region
|
||||
|
||||
public const uint WS_OVERLAPPED = 0x00000000;
|
||||
public const uint WS_POPUP = 0x80000000;
|
||||
public const uint WS_CHILD = 0x40000000;
|
||||
public const uint WS_MINIMIZE = 0x20000000;
|
||||
public const uint WS_VISIBLE = 0x10000000;
|
||||
public const uint WS_DISABLED = 0x08000000;
|
||||
public const uint WS_CLIPSIBLINGS = 0x04000000;
|
||||
public const uint WS_CLIPCHILDREN = 0x02000000;
|
||||
public const uint WS_MAXIMIZE = 0x01000000;
|
||||
public const uint WS_CAPTION = 0x00C00000; /* WS_BORDER | WS_DLGFRAME */
|
||||
public const uint WS_BORDER = 0x00800000;
|
||||
public const uint WS_DLGFRAME = 0x00400000;
|
||||
public const uint WS_VSCROLL = 0x00200000;
|
||||
public const uint WS_HSCROLL = 0x00100000;
|
||||
public const uint WS_SYSMENU = 0x00080000;
|
||||
public const uint WS_THICKFRAME = 0x00040000;
|
||||
public const uint WS_GROUP = 0x00020000;
|
||||
public const uint WS_TABSTOP = 0x00010000;
|
||||
public const uint WS_MINIMIZEBOX = 0x00020000;
|
||||
public const uint WS_MAXIMIZEBOX = 0x00010000;
|
||||
|
||||
public const uint WS_OVERLAPPEDWINDOW = WS_OVERLAPPED |
|
||||
WS_CAPTION |
|
||||
WS_SYSMENU |
|
||||
WS_THICKFRAME |
|
||||
WS_MINIMIZEBOX |
|
||||
WS_MAXIMIZEBOX;
|
||||
|
||||
#endregion
|
||||
}
|
||||
public readonly partial struct WindowHandle
|
||||
: IEquatable<WindowHandle>
|
||||
{
|
||||
internal readonly IntPtr Value;
|
||||
|
||||
internal WindowHandle(IntPtr value) => this.Value = value;
|
||||
|
||||
internal static WindowHandle Null => default;
|
||||
|
||||
internal bool IsNull => Value == default;
|
||||
|
||||
public static explicit operator WindowHandle(IntPtr value) => new WindowHandle(value);
|
||||
|
||||
public static implicit operator IntPtr(WindowHandle value) => value.Value;
|
||||
public static bool operator !=(WindowHandle left, WindowHandle right) => !(left == right);
|
||||
|
||||
public static bool operator ==(WindowHandle left, WindowHandle right) => left.Value == right.Value;
|
||||
public bool Equals(WindowHandle other) => this.Value == other.Value;
|
||||
|
||||
public override bool Equals(object obj) => obj is WindowHandle other && this.Equals(other);
|
||||
|
||||
public override int GetHashCode() => this.Value.GetHashCode();
|
||||
|
||||
public override string ToString() => $"0x{this.Value:x}";
|
||||
|
||||
//public static implicit operator HANDLE(WindowHandle value) => new HANDLE(value.Value);
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public class PixelFormatDescriptor
|
||||
{
|
||||
// 定义类的成员变量,使用与 C/C++ 中相同的数据类型
|
||||
public ushort nSize;
|
||||
public ushort nVersion;
|
||||
public uint dwFlags;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte iPixelType;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cColorBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cRedBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cRedShift;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cGreenBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cGreenShift;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cBlueBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cBlueShift;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAlphaBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAlphaShift;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAccumBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAccumRedBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAccumGreenBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAccumBlueBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAccumAlphaBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cDepthBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cStencilBits;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte cAuxBuffers;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte iLayerType;
|
||||
[MarshalAs(UnmanagedType.U1)]
|
||||
public byte bReserved;
|
||||
public uint dwLayerMask;
|
||||
public uint dwVisibleMask;
|
||||
public uint dwDamageMask;
|
||||
|
||||
// 定义一个构造函数,用于设置类的成员变量的默认值
|
||||
public PixelFormatDescriptor()
|
||||
{
|
||||
nSize = (ushort)Marshal.SizeOf(this); // 设置 nSize 为类的大小
|
||||
nVersion = 1; // 设置 nVersion 为 1
|
||||
dwFlags = 0; // 设置 dwFlags 为 0
|
||||
iPixelType = 0; // 设置 iPixelType 为 0
|
||||
cColorBits = 0; // 设置 cColorBits 为 0
|
||||
cRedBits = 0; // 设置 cRedBits 为 0
|
||||
cRedShift = 0; // 设置 cRedShift 为 0
|
||||
cGreenBits = 0; // 设置 cGreenBits 为 0
|
||||
cGreenShift = 0; // 设置 cGreenShift 为 0
|
||||
cBlueBits = 0; // 设置 cBlueBits 为 0
|
||||
cBlueShift = 0; // 设置 cBlueShift 为 0
|
||||
cAlphaBits = 0; // 设置 cAlphaBits 为 0
|
||||
cAlphaShift = 0; // 设置 cAlphaShift 为 0
|
||||
cAccumBits = 0; // 设置 cAccumBits 为 0
|
||||
cAccumRedBits = 0; // 设置 cAccumRedBits 为 0
|
||||
cAccumGreenBits = 0; // 设置 cAccumGreenBits 为 0
|
||||
cAccumBlueBits = 0; // 设置 cAccumBlueBits 为 0
|
||||
cAccumAlphaBits = 0; // 设置 cAccumAlphaBits 为 0
|
||||
cDepthBits = 0; // 设置 cDepthBits 为 0
|
||||
cStencilBits = 0; // 设置 cStencilBits 为 0
|
||||
cAuxBuffers = 0; // 设置 cAuxBuffers 为 0
|
||||
iLayerType = 0; // 设置 iLayerType 为 0
|
||||
bReserved = 0; // 设置 bReserved 为 0
|
||||
dwLayerMask = 0; // 设置 dwLayerMask 为 0
|
||||
dwVisibleMask = 0; // 设置 dwVisibleMask 为 0
|
||||
dwDamageMask = 0; // 设置 dwDamageMask 为 0
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Windows.Win32.Foundation;
|
||||
|
||||
|
||||
#if Windows
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Graphics.OpenGL;
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
|
||||
namespace StgSharp.Envitronment.Win32
|
||||
{
|
||||
public class WGL
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static GlRenderContextHandle CreateContext(DeviceContextHandle param0)
|
||||
{
|
||||
return new(PInvoke.wglCreateContext(new HDC(param0.Value)).Value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,78 @@
|
||||
using StgSharp.Envitronment.Win32;
|
||||
using StgSharp.Graphics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if Windows
|
||||
#pragma warning disable CA1416
|
||||
|
||||
using Windows.Win32.Graphics.Gdi;
|
||||
using Windows.Win32.Graphics.OpenGL;
|
||||
|
||||
|
||||
namespace StgSharpDebug.Environment
|
||||
{
|
||||
public static unsafe class wglEx
|
||||
{
|
||||
|
||||
private static delegate* unmanaged[Stdcall]<HDC, int*, float*, uint, int*, uint*, bool> wglChoosePixelFormatARBpointer;
|
||||
private static delegate* unmanaged[Stdcall]<HDC, HGLRC, int*, HGLRC> wglCreateContextAttribsARBpointer;
|
||||
|
||||
public static unsafe bool glChoosePixelFormatARB(
|
||||
DeviceContextHandle hdc,
|
||||
int[] pixelIntAttributeList,
|
||||
out int piFormats,
|
||||
out uint piFormatCount)
|
||||
{
|
||||
if ((ulong)wglChoosePixelFormatARBpointer < 10)
|
||||
{
|
||||
piFormats = 0;
|
||||
piFormatCount = 0;
|
||||
return false;
|
||||
}
|
||||
pixelIntAttributeList = pixelIntAttributeList.Concat([0]).ToArray();
|
||||
int pf;
|
||||
uint nf;
|
||||
fixed (int* pial = pixelIntAttributeList)
|
||||
{
|
||||
bool ret = wglChoosePixelFormatARBpointer(new HDC(hdc.Value), pial, (float*)0, 1, &pf, &nf);
|
||||
piFormats = pf;
|
||||
piFormatCount = nf;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe GlRenderContextHandle wglCreateContextAttribsARB(
|
||||
DeviceContextHandle hdc,
|
||||
GlRenderContextHandle hglrc,
|
||||
int[] pixelFormat)
|
||||
{
|
||||
if ((ulong)wglCreateContextAttribsARBpointer < 10)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
HGLRC h, h_share = new HGLRC(hglrc.Value);
|
||||
HDC h_dc = new HDC(hdc.Value);
|
||||
fixed (int* format = pixelFormat)
|
||||
{
|
||||
h = wglCreateContextAttribsARBpointer(h_dc, h_share, format);
|
||||
return new GlRenderContextHandle(h);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void LoadWGLex()
|
||||
{
|
||||
wglChoosePixelFormatARBpointer = (delegate* unmanaged[Stdcall]<HDC, int*, float*, uint, int*, uint*, bool>)glManager.LoadGLfunc("wglChoosePixelFormatARB");
|
||||
wglCreateContextAttribsARBpointer = (delegate* unmanaged[Stdcall]<HDC, HGLRC, int*, HGLRC>)glManager.LoadGLfunc("wglCreateContextAttribsARB");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#pragma warning restore CA1416 // 验证平台兼容性
|
||||
#endif
|
||||
Reference in New Issue
Block a user