可视化如何使用C /Winrt和Angle创建EGLSURFACE

visual How to create EGLSurface using C++/WinRT and ANGLE?

本文关键字:Angle 创建 EGLSURFACE Winrt 何使用 可视化      更新时间:2023-10-16

我正在使用角度项目的Microsoft分支,以便在通用Windows应用程序中访问OpenGL。另外,我在标准C 中使用C /WinRT绑定到代码。

我是从"角度"项目中的一个示例开始的,并尝试将C /CX代码转换为C /WinRT代码,但是我找不到我创建EGL Surface的零件的解决方案:

mEGLSurface = eglCreateWindowSurface(mEGLDisplay, config, /*WHERE IS MY HWND?*/, NULL);

在C /CX中,他们使用以下代码,但是我必须承认,我不知道它们是如何从corewindow到eGlnativeWindowType(在这种情况下为hwnd)从propertyset获得的,以及如何将其翻译成C /WinRT代码:

PropertySet^ surfaceCreationProperties = ref new PropertySet();
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), window);
mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties), surfaceAttributes);

编辑:当天真地将代码转换为C /Winrt约定时,Reinterpret_cast给出了"无效的铸件"错误(从iinspectable到eglnativewindowtype)。

编辑:仅出于完整性,window参数是Windows :: UI :: Core :: CoreWindow。

编辑:实际上,对类似问题的答案给出了很多好的信息,我将进一步研究。

编辑:在阅读了上一个编辑中链接的答案并在"角度源代码"中查看正确的位置后,我发现我的混乱是由特定于斜角的Windows端的实现详细信息引起的。该功能在传统意义上并不是期望有HWND的手柄,而是更像是伪装成HWND的设置字典。另外,reinterpret_cast错误是由于我试图将对象施放给指针,愚蠢的我。

eglnativeWindowType定义如下:

#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) /* Windows Desktop */
typedef HWND    EGLNativeWindowType;
#else /* Windows Store */
#include <inspectable.h>
typedef IInspectable* EGLNativeWindowType;
#endif

因此,在通用Windows应用程序中使用C /WinRT类型时,我必须小心不要将这些类型与其他代码使用的C /CX类型混合。

我试图施放PropertySet指针,该功能的实现期望在使用UWP时,将其用于WinRT :: Windows :: Foundation :: foundation :: iinspectable Pointer。这不是Angle实现期望的C /CX IINSPOCT类型。因此

PropertySet surfaceProperties;
surfaceProperties.Insert(EGLNativeWindowTypeProperty, window);
EGLNativeWindowType win = reinterpret_cast<EGLNativeWindowType>(&surfaceProperties);
mEGLSurface = eglCreateWindowSurface(mEGLDisplay, config, win, surfaceAttributes);

这是尝试在UWP环境中使用标准C 的警告之一。请参阅有关与C /CX代码共享C /WinRT的答案:

https://stackoverflow.com/a/397775875/1891866

winrt'PropertySet与CX'PropertySet不兼容。

这对我有用:

PropertySet surfaceCreationProperties;
surfaceCreationProperties.Insert(EGLNativeWindowTypeProperty, panel);
EGLNativeWindowType win = static_cast<EGLNativeWindowType>(winrt::get_abi(surfaceCreationProperties));
surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, win, surfaceAttributes);