如何使用 C++/WinRT 和 ANGLE 创建 EGLSurface? [英] How to create EGLSurface using C++/WinRT and ANGLE?

查看:25
本文介绍了如何使用 C++/WinRT 和 ANGLE 创建 EGLSurface?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ANGLE 项目的 Microsoft 分支 来访问 Universal 中的 OpenGLWindows 应用程序.此外,我使用 C++/WinRT 绑定 尽可能多地使用标准 C++ 进行编码.

我从 ANGLE 项目中的一个示例开始,尝试将 C++/CX 代码转换为 C++/WinRT 代码,但我未能找到创建 EGL Surface 的部分的解决方案:

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

在 C++/CX 中,他们使用以下代码,但我必须承认,我不明白他们如何从带有 CoreWindow 的 PropertySet 到 EGLNativeWindowType(在本例中为 HWND)以及如何将其转换为 C++/WinRT 代码:

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

<小时>

当天真地将代码转换为 C++/WinRT 约定时,reinterpret_cast 会给出无效转换"错误(从 IInspectable 到 EGLNativeWindowType).

为了完整起见,window 参数是一个 Windows::UI::Core::CoreWindow.

实际上 this 对类似问题的回答提供了很多很好的信息,我会进一步调查.>

在阅读了之前编辑中链接到的答案并查看了 ANGLE 源代码中的正确位置后,我发现我的困惑是由特定于 ANGLE 的 Windows 端的实现细节引起的.该函数并不期待传统意义上的 HWND 句柄,而更像是伪装成 HWND 的设置字典.此外,reinterpret_cast 错误是由于我试图将对象强制转换为指针,愚蠢的我..

解决方案

EGLNativeWindowType在ANGLE中定义如下:

#if !defined(WINAPI_FAMILY) ||(WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)/* Windows 桌面 */typedef HWND EGLNativeWindowType;#else/* Windows 应用商店 */#include typedef IInspectable* EGLNativeWindowType;#万一

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

我试图将 PropertySet 指针转换为 winrt::Windows::Foundation::IInspectable 指针,该函数的实现在使用 UWP 时需要该指针.这不是 ANGLE 实现所期望的 C++/CX IInspectable 类型.所以我不得不直接转换为 EGLNativeWindowType:

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

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

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

I'm using the Microsoft branch of the ANGLE project to have access to OpenGL in a Universal Windows application. Also I use the C++/WinRT binding to code as much in standard C++ as possible.

I started from one of the examples in the ANGLE project and tried to convert the C++/CX code to C++/WinRT code, but I fail to find a solution for the part where I create an EGL Surface:

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

In the C++/CX they use the following code, but I must admit, I don't get how they get from the PropertySet with a CoreWindow to the EGLNativeWindowType (in this case HWND) and how to translate this to C++/WinRT code:

PropertySet^ surfaceCreationProperties = ref new PropertySet();
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), window);

mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties), surfaceAttributes);


EDIT: When naively converting the code to C++/WinRT conventions, the reinterpret_cast gives an 'invalid cast' error (from IInspectable to EGLNativeWindowType).

EDIT: Just for completeness, the window argument is a Windows::UI::Core::CoreWindow.

EDIT: Actually this answer to a similar question gives a lot of good info, I will investigate further.

EDIT: After reading the answer linked to in the previous edit and looking at the right places in the source code of ANGLE, I found out that my confusion is caused by an implementation detail specific to the Windows side of ANGLE. The function is not expecting an HWND handle in the traditional sense, but more like a dictionary of settings disguised as an HWND. Also the reinterpret_cast error is due to the fact that I tried to cast an object to a pointer, silly me..

解决方案

EGLNativeWindowType is defined as follows in ANGLE:

#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

So when using C++/WinRT types in a Universal Windows application, I must be careful not to mix those types with C++/CX types used by other code.

I was trying to cast the PropertySet pointer, that this implementation of the function expects when using UWP, to an winrt::Windows::Foundation::IInspectable pointer. This is not the C++/CX IInspectable type that the ANGLE implementation expects. So I had to directly cast to EGLNativeWindowType:

PropertySet surfaceProperties;
surfaceProperties.Insert(EGLNativeWindowTypeProperty, window);
EGLNativeWindowType win = reinterpret_cast<EGLNativeWindowType>(&surfaceProperties);

mEGLSurface = eglCreateWindowSurface(mEGLDisplay, config, win, surfaceAttributes);

This is one of the caveats when trying to use standard C++ in an UWP environment. See this answers on sharing C++/WinRT with C++/CX code:

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

这篇关于如何使用 C++/WinRT 和 ANGLE 创建 EGLSurface?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆