|
1 | 1 | /* |
2 | | - Copyright (C) 2024 DeSmuME team |
| 2 | + Copyright (C) 2024-2025 DeSmuME team |
3 | 3 |
|
4 | 4 | This file is free software: you can redistribute it and/or modify |
5 | 5 | it under the terms of the GNU General Public License as published by |
@@ -45,21 +45,73 @@ static bool __egl_initOpenGL(const int requestedAPI, const int requestedProfile, |
45 | 45 |
|
46 | 46 | EGLint eglMajorVersion; |
47 | 47 | EGLint eglMinorVersion; |
48 | | - |
| 48 | + EGLBoolean didDisplayInitialize = EGL_FALSE; |
49 | 49 | EGLAttrib displayAttr[] = {EGL_NONE}; |
| 50 | + |
| 51 | + // Try to initialize EGL on a Wayland display first, which should be available on most |
| 52 | + // modern platforms. |
50 | 53 | currDisplay = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_EXT, EGL_DEFAULT_DISPLAY, displayAttr); |
51 | | - if(currDisplay == EGL_NO_DISPLAY) |
| 54 | + if (currDisplay != EGL_NO_DISPLAY) |
| 55 | + { |
| 56 | + didDisplayInitialize = eglInitialize(currDisplay, &eglMajorVersion, &eglMinorVersion); |
| 57 | + if (didDisplayInitialize == GL_TRUE) |
| 58 | + { |
| 59 | + puts("EGL: Successfully initialized with Wayland."); |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + // Try to initialize EGL for XCB next, which should be available for modern X11 platforms. |
| 64 | + if (didDisplayInitialize == GL_FALSE) |
| 65 | + { |
52 | 66 | currDisplay = eglGetPlatformDisplay(EGL_PLATFORM_XCB_EXT, EGL_DEFAULT_DISPLAY, displayAttr); |
53 | | - if(currDisplay == EGL_NO_DISPLAY) |
| 67 | + if (currDisplay != EGL_NO_DISPLAY) |
| 68 | + { |
| 69 | + didDisplayInitialize = eglInitialize(currDisplay, &eglMajorVersion, &eglMinorVersion); |
| 70 | + if (didDisplayInitialize == GL_TRUE) |
| 71 | + { |
| 72 | + puts("EGL: Successfully initialized with XCB."); |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + // If for some reason XCB didn't work, try to initialize EGL on whatever X11 is available. |
| 78 | + if (didDisplayInitialize == GL_FALSE) |
| 79 | + { |
| 80 | + currDisplay = eglGetPlatformDisplay(EGL_PLATFORM_X11_EXT, EGL_DEFAULT_DISPLAY, displayAttr); |
| 81 | + if (currDisplay != EGL_NO_DISPLAY) |
| 82 | + { |
| 83 | + didDisplayInitialize = eglInitialize(currDisplay, &eglMajorVersion, &eglMinorVersion); |
| 84 | + if (didDisplayInitialize == GL_TRUE) |
| 85 | + { |
| 86 | + puts("EGL: Successfully initialized with generic X11."); |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + // For ancient platforms that don't support eglGetPlatformDisplay(), an EGL v1.5 function, |
| 92 | + // try calling the generic eglGetDisplay() function as a last resort since it is compatible |
| 93 | + // with older versions of EGL. |
| 94 | + if (didDisplayInitialize == GL_FALSE) |
| 95 | + { |
54 | 96 | currDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
55 | | - if(currDisplay == EGL_NO_DISPLAY) |
| 97 | + if (currDisplay != EGL_NO_DISPLAY) |
| 98 | + { |
| 99 | + didDisplayInitialize = eglInitialize(currDisplay, &eglMajorVersion, &eglMinorVersion); |
| 100 | + if (didDisplayInitialize == GL_TRUE) |
| 101 | + { |
| 102 | + puts("EGL: Successfully initialized with a generic display."); |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + if (currDisplay == EGL_NO_DISPLAY) |
56 | 108 | { |
57 | | - puts("EGL: failed to obtain display handle"); |
| 109 | + puts("EGL: Could not acquire a display handle to initialize EGL."); |
58 | 110 | return false; |
59 | 111 | } |
60 | | - if (eglInitialize(currDisplay, &eglMajorVersion, &eglMinorVersion) == EGL_FALSE) |
| 112 | + else if (didDisplayInitialize == GL_FALSE) |
61 | 113 | { |
62 | | - puts("EGL: eglInitialize failed"); |
| 114 | + puts("EGL: Could not initialize EGL with the acquired display handle."); |
63 | 115 | return false; |
64 | 116 | } |
65 | 117 |
|
|
0 commit comments