mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-17 00:28:31 +09:00
[Feat] (WGL): add Windows host layer - drop-in opengl32.dll with WGL over EGLImpl, Win32 window backend plumbing for both backends, ANGLE loader path, and leak-at-exit process teardown
This commit is contained in:
@@ -313,7 +313,8 @@ namespace MobileGL {
|
||||
Android,
|
||||
X11,
|
||||
MetalLayer,
|
||||
// TODO: Wayland, Windows, etc.
|
||||
Win32, // Handle is an HWND
|
||||
// TODO: Wayland, etc.
|
||||
WindowBackendCount,
|
||||
Unknown = -1
|
||||
};
|
||||
|
||||
@@ -701,9 +701,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
if ((handle.Backend != WindowBackend::Android &&
|
||||
handle.Backend != WindowBackend::X11 &&
|
||||
handle.Backend != WindowBackend::MetalLayer) ||
|
||||
handle.Backend != WindowBackend::MetalLayer &&
|
||||
handle.Backend != WindowBackend::Win32) ||
|
||||
!handle.Handle) {
|
||||
MGLOG_E("DirectGLES backend only supports Android, X11, and CAMetalLayer native windows");
|
||||
MGLOG_E("DirectGLES backend only supports Android, X11, CAMetalLayer, and Win32 native windows");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4307,9 +4307,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
if (!ChooseConfigForSurface(surfaceBit, g_Config, window)) return false;
|
||||
|
||||
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
||||
// Negotiate the highest ES 3.x context. Version-strict EGL implementations
|
||||
// (ANGLE) return exactly the requested minor, and a bare CLIENT_VERSION 3
|
||||
// request yields a 3.0 context that lacks the 3.1/3.2 texture targets the
|
||||
// capability probes exercise; mobile drivers ignore the minor and hand out
|
||||
// their maximum either way.
|
||||
for (const EGLint minorVersion : {2, 1, 0}) {
|
||||
const EGLint contextAttribs[] = {EGL_CONTEXT_MAJOR_VERSION, 3,
|
||||
EGL_CONTEXT_MINOR_VERSION, minorVersion,
|
||||
EGL_NONE};
|
||||
g_Context = g_EGLFuncs.eglCreateContext(g_Display, g_Config, EGL_NO_CONTEXT, contextAttribs);
|
||||
if (g_Context != EGL_NO_CONTEXT) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
g_Context = g_EGLFuncs.eglCreateContext(g_Display, g_Config, EGL_NO_CONTEXT, contextAttribs);
|
||||
const EGLint legacyContextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
|
||||
g_Context = g_EGLFuncs.eglCreateContext(g_Display, g_Config, EGL_NO_CONTEXT, legacyContextAttribs);
|
||||
return g_Context != EGL_NO_CONTEXT;
|
||||
}
|
||||
|
||||
|
||||
@@ -397,8 +397,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
if (!handle.Handle || (handle.Backend != WindowBackend::Android &&
|
||||
handle.Backend != WindowBackend::X11 &&
|
||||
handle.Backend != WindowBackend::MetalLayer)) {
|
||||
MGLOG_E("DirectVulkan backend only supports Android, X11, and CAMetalLayer native windows");
|
||||
handle.Backend != WindowBackend::MetalLayer &&
|
||||
handle.Backend != WindowBackend::Win32)) {
|
||||
MGLOG_E("DirectVulkan backend only supports Android, X11, CAMetalLayer, and Win32 native windows");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7560,6 +7560,10 @@ void main() {
|
||||
MOBILEGL_ASSERT(hwnd, "HWND is null");
|
||||
|
||||
VkWin32SurfaceCreateInfoKHR sci{VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
|
||||
sci.hinstance = reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(hwnd, GWLP_HINSTANCE));
|
||||
if (!sci.hinstance) {
|
||||
sci.hinstance = GetModuleHandleW(nullptr);
|
||||
}
|
||||
sci.hwnd = hwnd;
|
||||
VK_VERIFY(vkCreateWin32SurfaceKHR(m_instance, &sci, nullptr, &m_surface), "vkCreateWin32SurfaceKHR failed");
|
||||
#elif defined VK_USE_PLATFORM_METAL_EXT
|
||||
|
||||
Reference in New Issue
Block a user