daily update on 20240226 by nitload youmu

This commit is contained in:
YoumuLiu
2024-02-27 00:43:29 +08:00
parent a2241a5a58
commit 06e39f7a31
543 changed files with 230273 additions and 21423 deletions
+26 -20
View File
@@ -1,7 +1,8 @@
using StgSharp.Envitronment;
using StgSharp.Envitronment.Win32;
using StgSharp.Graphics;
using StgSharp.Math;
// using StgSharp.Envitronment;
// using StgSharp.Envitronment.Win32;
// using StgSharp.Graphics;
// using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -11,16 +12,18 @@ 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;
// using Windows.Win32.UI.WindowsAndMessaging;
// 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
@@ -32,7 +35,6 @@ namespace StgSharp
public static partial class Platform
{
internal static GraphicAPI API = default;
private static uint markCount = 0;
@@ -55,7 +57,7 @@ namespace StgSharp
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before other
/// This method should be called before other
/// graphic methods, after LoadGL method.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -89,7 +91,6 @@ namespace StgSharp
try
{
return Marshal.GetDelegateForFunctionPointer<TDele>(funcPtr);
}
catch (Exception)
{
@@ -99,7 +100,6 @@ namespace StgSharp
internal static Delegate ConvertAPI(IntPtr funcPtr, Type T)
{
if (funcPtr == IntPtr.Zero)
{
throw new Exception("Failed to convert api, the function pointer is zero.");
@@ -107,7 +107,6 @@ namespace StgSharp
try
{
return Marshal.GetDelegateForFunctionPointer(funcPtr, T);
}
catch (Exception)
{
@@ -118,13 +117,14 @@ namespace StgSharp
public static void Track(
object target,
string message,
bool isConsole,
[CallerFilePath] string filePath = "",
[CallerMemberName] string callerName = "",
[CallerLineNumber] int lineNumber = 0
)
{
string log = $"Tracked object: {nameof(target)}\n";
Type t = target.GetType();
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
FieldInfo[] fieldInfo = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
foreach (FieldInfo field in fieldInfo)
@@ -133,8 +133,14 @@ namespace StgSharp
}
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
log += $"Additional information:\n{message}\n";
InternalIO.InternalWriteLog(log, LogType.Info);
if (isConsole)
{
Console.WriteLine(log);
}
else
{
InternalIO.InternalWriteLog(log, LogType.Info);
}
}
}
}
}
@@ -1,199 +0,0 @@
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
@@ -1,279 +0,0 @@
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
@@ -1,31 +0,0 @@
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
@@ -1,78 +0,0 @@
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
@@ -5,6 +5,7 @@ CreateWindowEx
DefWindowProc
DescribePixelFormat
DestroyWindow
DispatchMessage
FreeLibrary
GetDC
GetEnhMetaFilePixelFormat
@@ -13,12 +14,16 @@ GetPixelFormat
GetProcAddress
LoadCursor
LoadLibrary
PeekMessage
PostQuitMessage
RegisterClass
RegisterClassA
ReleaseDC
SetPixelFormat
ShowWindow
SwapBuffers
TranslateMessage
UpdateWindow
wglGetProcAddress
wglCreateContext
wglCreateLayerContext
+19 -32
View File
@@ -1,8 +1,10 @@
using StgSharp.Geometries;
//using StgSharp.Envitronment.Win32;
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Logic;
using StgSharp.Math;
using StgSharp.Math.Linear;
using System;
using System.Diagnostics;
using System.IO;
@@ -12,17 +14,16 @@ using System.Text;
namespace StgSharp
{
public class StgSharpDemoForm : Form
{
Uniform<float, float, float> color;
ElementBuffer ebo;
Uniform<int> ourTexture;
Uniform<int> ourTexture2;
ShaderProgram shader;
Texture texture;
VertexArray vao;
VertexBuffer vbo;
private Uniform<float, float, float> color;
private ElementBuffer ebo;
private Uniform<int> ourTexture;
private Uniform<int> ourTexture2;
private ShaderProgram shader;
private Texture texture;
private VertexArray vao;
private VertexBuffer vbo;
public static unsafe void ProcessInput(IntPtr windowPtr)
{
@@ -54,7 +55,7 @@ namespace StgSharp
InternalIO.InternalWriteLog("\n\n\n", "Program start", LogType.Info);
Platform.InitGL(4, 6);
SetRenderThreads(1);
SetRenderThreads(2);
SetMetadata(800, 600, "Hello, STG#!", IntPtr.Zero, null);
MakeAsCurrentContext();
@@ -65,9 +66,7 @@ namespace StgSharp
{
gl.Viewport(0, 0, width, height);
};
this.LoadGLapi(null);
Console.WriteLine(gl);
shader = CreateShaderProgram();
var vertex = CreateShader(ShaderType.Vertex, 1);
@@ -77,8 +76,6 @@ namespace StgSharp
fragment.Compile(File.ReadAllText("Shader\\fragment.frag"));
fragment.AttachTo(0, shader);
Console.WriteLine(vertex);
shader.Link();
Triangle tri = new Triangle(
@@ -107,8 +104,6 @@ namespace StgSharp
ebo = CreateElementBuffer(1);
texture = CreateTexture(2);
Console.WriteLine(texture);
float[] texCoord = {
0.0f, 0.0f,
1.0f, 0.0f,
@@ -129,13 +124,9 @@ namespace StgSharp
gl.BindBuffer(BufferType.ARRAY_BUFFER, glHandle.Zero);
vao.BindNull();
/**/
Console.WriteLine(vao);
texture.Bind2D(0);
texture.Set2dWrapProperty(Wrap.Repeat, Wrap.Repeat);
texture.Set2dFilterProperty(Filter.Nearest, Filter.Nearest);
Console.WriteLine(texture);
texture.LoadTexture(0, "Shader\\Image1.png", null);
texture.Bind2D(1);
@@ -153,12 +144,10 @@ namespace StgSharp
ourTexture2 = shader.GetUniform<int>("ourTexture2");
gl.SetValue(ourTexture2, 1);
/**/
Console.WriteLine(this);
}
public override void Main(params object[] args)
{
ProcessInput(windowID);
gl.ClearColor(0.333f, 0.555f, 0.555f, 1.0f);
@@ -195,14 +184,17 @@ namespace StgSharp
internal static class Program
{
internal unsafe static void Main(string[] args)
internal static unsafe void Main(string[] args)
{
try
{
//Platform.TryCreatWindow();
/**/
StgSharpDemoForm demoForm = new StgSharpDemoForm();
demoForm.Init();
demoForm.Show();
/**/
}
catch (Exception ex)
{
@@ -212,13 +204,8 @@ namespace StgSharp
}
}
[DllImport(InternalIO.SSC_libname, EntryPoint = "printShaderCode",
CallingConvention = CallingConvention.Cdecl)]
internal extern unsafe static void PrintShader(byte** shadercode);
internal static extern unsafe void PrintShader(byte** shadercode);
}
}
}
+3 -2
View File
@@ -10,9 +10,9 @@
<PlatformTarget>x64</PlatformTarget>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<ErrorReport>prompt</ErrorReport>
<ErrorReport>none</ErrorReport>
<SignAssembly>False</SignAssembly>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<PackageLicenseExpression> MIT</PackageLicenseExpression>
<IncludeSymbols>False</IncludeSymbols>
<Platforms>AnyCPU;x64</Platforms>
@@ -65,6 +65,7 @@
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
</PropertyGroup>
<PropertyGroup Condition="'$(IsWindows)'=='true'">
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a2241a5a5816a9438c63e3ca3c69313e6f2e8f56")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
c10be108f46b065c19ec8e7bfe96ea5af08b76ca6ab3228bd84f4f2d953e88a9
bea7289cf9c9ffc94f6418fdb0687293420e5fbe9c96f4e035fac3a46f56ed6b
@@ -1,4 +1,6 @@
is_global = true
build_property.CsWin32InputMetadataPaths = C:\Users\Nitlo\.nuget\packages\microsoft.windows.sdk.win32metadata\55.0.45-preview\Windows.Win32.winmd|C:\Users\Nitlo\.nuget\packages\microsoft.windows.wdk.win32metadata\0.9.9-experimental\Windows.Wdk.winmd
build_property.CsWin32InputDocPaths = C:\Users\Nitlo\.nuget\packages\microsoft.windows.sdk.win32docs\0.1.42-alpha\apidocs.msgpack
build_property.TargetFramework = net6.0
build_property.TargetPlatformMinVersion =
build_property.UsingMicrosoftNETSdkWeb =
@@ -39,6 +39,11 @@
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
@@ -67,7 +72,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.100\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.200\\RuntimeIdentifierGraph.json"
}
}
}
@@ -7,7 +7,7 @@
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Nitlo\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.8.0</NuGetToolVersion>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.9.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\Nitlo\.nuget\packages\" />
@@ -252,6 +252,11 @@
"warnAsError": [
"NU1605"
]
},
"restoreAuditProperties": {
"enableAudit": "true",
"auditLevel": "low",
"auditMode": "direct"
}
},
"frameworks": {
@@ -280,7 +285,7 @@
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.100\\RuntimeIdentifierGraph.json"
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.200\\RuntimeIdentifierGraph.json"
}
}
}
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "84WrCu/hdh50wiBeP0zSAmXlJSxVZVcbmMrOYOkm8tQy5/+Tjvf2Dpa+41PoFKcm7+EFWGE+qB480ApAKjKwfg==",
"dgSpecHash": "J7sgaIGcdF2iHygmGHBxDeC+PAuoM5muyWGAosJVKtCkXtzNWIgvC6IteoRrnoZocQ1RRzxknA9Z4oYxKwu/ww==",
"success": true,
"projectFilePath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\源代码\\StgSharpDebug\\StgSharpDebug.csproj",
"expectedPackageFiles": [
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+a2241a5a5816a9438c63e3ca3c69313e6f2e8f56")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
9f92006774b8dcbe7ff116213c08f7040b5d19f4b0a547971f9e00de3873288c
2dfd7b0369d09bcc69dec88772b4d57803801aa4bccd89b3fbe73b3142b0ec2d
@@ -1 +1 @@
b7447d9f42f748768ec2587b88b8ed4bce54f8745553420be3c862e6a856c127
d3950cf43a4621e23b9ef30b3a756b05673c0e97f9577997adebeaad64313512
@@ -7,6 +7,11 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Debug\net6.0\StgSharpDebug.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Debug\net6.0\StgSharpDebug.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\bin\x64\Debug\net6.0\StgSharpDebug.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.sourcelink.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\StgSharpDebug.exe
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\Shader\awesomeface.png
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\Shader\fragment.frag
@@ -17,14 +22,7 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\StgSharpDebug.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\StgSharpDebug.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\Output\x64\Debug\net6.0\StgSharpDebug.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.sourcelink.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\refint\StgSharpDebug.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.pdb
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\StgSharpDebug.genruntimeconfig.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharpDebug\obj\x64\Debug\net6.0\ref\StgSharpDebug.dll
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/839156948261837c173ee878d930fc868fce223e/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/a2241a5a5816a9438c63e3ca3c69313e6f2e8f56/*"}}
File diff suppressed because one or more lines are too long