[英]How to create EGLSurface using C++/WinRT and ANGLE?
我正在使用ANGLE項目的Microsoft分支來訪問通用Windows應用程序中的OpenGL。 另外,我使用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<IInspectable*>(surfaceCreationProperties), surfaceAttributes);
編輯:天真地將代碼轉換為C ++ / WinRT約定時,reinterpret_cast給出了“無效的轉換”錯誤(從IInspectable到EGLNativeWindowType)。
編輯:為了完整起見, window
參數是Windows :: UI :: Core :: CoreWindow。
編輯:其實這個類似問題的答案提供了很多很好的信息,我將進一步調查。
編輯:在閱讀上一個編輯中鏈接到的答案並查看ANGLE源代碼中的正確位置后,我發現我的困惑是由ANGLE的Windows方面的實現細節引起的。 該功能不希望使用傳統意義上的HWND句柄,而更像是偽裝成HWND的設置字典。 同樣,reinterpret_cast錯誤是由於我試圖將對象強制轉換為指針,這很愚蠢。
EGLNativeWindowType在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
因此,在通用Windows應用程序中使用C ++ / WinRT類型時,我必須小心不要將這些類型與其他代碼使用的C ++ / CX類型混合使用。
我試圖將PropertySet指針(該功能的實現在使用UWP時)轉換為winrt :: Windows :: Foundation :: IInspectable指針。 這不是ANGLE實現所期望的C ++ / CX IInspectable類型。 所以我必須直接轉換為EGLNativeWindowType:
PropertySet surfaceProperties;
surfaceProperties.Insert(EGLNativeWindowTypeProperty, window);
EGLNativeWindowType win = reinterpret_cast<EGLNativeWindowType>(&surfaceProperties);
mEGLSurface = eglCreateWindowSurface(mEGLDisplay, config, win, surfaceAttributes);
這是在UWP環境中嘗試使用標准C ++時的警告之一。 在與C ++ / CX代碼共享C ++ / WinRT時,請參閱以下答案:
還有與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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.