79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
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
|