我有一个用 C++ 调用 EGL 的程序。我想在 C# 中进行相同的调用,但 C# 中似乎没有等效的概念。
当执行上下文进入 C++ EGL 代码时,我收到读/写访问被拒绝错误。
这是我尝试将 C++ 程序转换为 C# 的代码:
PropertySet^ surfaceCreationProperties = ref new PropertySet();
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), somethingOtherThanAWindow);
mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties), surfaceAttributes));
我有一个 C# 类,它将 C# EGL 调用转换为 C++ 调用。我相信 C++ 是非托管的,尽管我不知道如何确定地告诉你。
C# 类如下所示:
public static IntPtr CreateWindowSurface(IntPtr dpy, IntPtr config, IntPtr win, int[] attrib_list)
{
IntPtr retValue;
unsafe {
fixed (int* p_attrib_list = attrib_list)
{
retValue = Delegates.peglCreateWindowSurface(dpy, config, win, p_attrib_list);
}
}
return (retValue);
}
更多该代码可以在这里看到:https://github.com/luca-piccioni/OpenGL.Net/blob/master/OpenGL.Net/Egl.VERSION_1_0.cs#L751 https://github.com/luca-piccioni/OpenGL.Net/blob/master/OpenGL.Net/Egl.VERSION_1_0.cs#L751
你可能会注意到这个方法有一个IntPtr win
-- 这就是我要经过的地方PropertySet
。通常我相信这将是System.Windows.Forms.Control
,但在 C++ EGL 代码中进行了一些检查,看看它是否是,或者是否是一个PropertySet
.
被调用的C++方法是这样的:
EGLSurface EGLAPIENTRY CreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
更多内容可以在这里看到:https://github.com/Microsoft/angle/blob/ms-holographic-experimental/src/libGLESv2/entry_points_egl.cpp#L241 https://github.com/Microsoft/angle/blob/ms-holographic-experimental/src/libGLESv2/entry_points_egl.cpp#L241
正如您所看到的,C++ 方法需要 EGLNativeWindowType。我不太确定 IInspectable 和 PropertSet 之间的关系是什么 - 可以强制转换这似乎很奇怪。
EGLNativeWindowType 具有以下类型定义:
typedef HWND EGLNativeWindowType;
这意味着它必须是某种窗口句柄。我不明白 PropertySet 如何成为窗口句柄。
我怀疑主要问题在于选择正确的对象类型以传递给 C# EGL 实现。 PropertySet 看起来可能是正确的选择,但reinterpret_cast 确实让我失望。
有人能引导我完成这个吗?