3030
3131#include " egl_manager.h"
3232
33+ #include " drivers/gles3/rasterizer_gles3.h"
34+
3335#ifdef EGL_ENABLED
3436
3537#if defined(EGL_STATIC)
@@ -51,6 +53,16 @@ extern "C" EGLAPI EGLDisplay EGLAPIENTRY eglGetPlatformDisplayEXT(EGLenum platfo
5153#define GLAD_EGL_EXT_platform_base 0
5254#endif
5355
56+ #ifdef WINDOWS_ENABLED
57+ // Unofficial ANGLE extension: EGL_ANGLE_surface_orientation
58+ #ifndef EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE
59+ #define EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE 0x33A7
60+ #define EGL_SURFACE_ORIENTATION_ANGLE 0x33A8
61+ #define EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE 0x0001
62+ #define EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE 0x0002
63+ #endif
64+ #endif
65+
5466// Creates and caches a GLDisplay. Returns -1 on error.
5567int EGLManager::_get_gldisplay_id (void *p_display) {
5668 // Look for a cached GLDisplay.
@@ -115,6 +127,18 @@ int EGLManager::_get_gldisplay_id(void *p_display) {
115127 }
116128#endif
117129
130+ #ifdef WINDOWS_ENABLED
131+ String client_extensions_string = eglQueryString (new_gldisplay.egl_display , EGL_EXTENSIONS);
132+ if (eglGetError () == EGL_SUCCESS) {
133+ Vector<String> egl_extensions = client_extensions_string.split (" " );
134+
135+ if (egl_extensions.has (" EGL_ANGLE_surface_orientation" )) {
136+ new_gldisplay.has_EGL_ANGLE_surface_orientation = true ;
137+ print_verbose (" EGL: EGL_ANGLE_surface_orientation is supported." );
138+ }
139+ }
140+ #endif
141+
118142 displays.push_back (new_gldisplay);
119143
120144 // Return the new GLDisplay's ID.
@@ -237,8 +261,29 @@ Error EGLManager::window_create(DisplayServer::WindowID p_window_id, void *p_dis
237261 GLWindow &glwindow = windows[p_window_id];
238262 glwindow.gldisplay_id = gldisplay_id;
239263
264+ Vector<EGLAttrib> egl_attribs;
265+
266+ #ifdef WINDOWS_ENABLED
267+ if (gldisplay.has_EGL_ANGLE_surface_orientation ) {
268+ EGLint optimal_orientation;
269+ if (eglGetConfigAttrib (gldisplay.egl_display , gldisplay.egl_config , EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, &optimal_orientation)) {
270+ // We only need to support inverting Y for optimizing ANGLE on D3D11.
271+ if (optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(optimal_orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) {
272+ egl_attribs.push_back (EGL_SURFACE_ORIENTATION_ANGLE);
273+ egl_attribs.push_back (EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE);
274+ }
275+ } else {
276+ ERR_PRINT (vformat (" Failed to get EGL_OPTIMAL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X" , eglGetError ()));
277+ }
278+ }
279+
280+ if (!egl_attribs.is_empty ()) {
281+ egl_attribs.push_back (EGL_NONE);
282+ }
283+ #endif
284+
240285 if (GLAD_EGL_VERSION_1_5) {
241- glwindow.egl_surface = eglCreatePlatformWindowSurface (gldisplay.egl_display , gldisplay.egl_config , p_native_window, nullptr );
286+ glwindow.egl_surface = eglCreatePlatformWindowSurface (gldisplay.egl_display , gldisplay.egl_config , p_native_window, egl_attribs. ptr () );
242287 } else {
243288 EGLNativeWindowType *native_window_type = (EGLNativeWindowType *)p_native_window;
244289 glwindow.egl_surface = eglCreateWindowSurface (gldisplay.egl_display , gldisplay.egl_config , *native_window_type, nullptr );
@@ -250,6 +295,20 @@ Error EGLManager::window_create(DisplayServer::WindowID p_window_id, void *p_dis
250295
251296 glwindow.initialized = true ;
252297
298+ #ifdef WINDOWS_ENABLED
299+ if (gldisplay.has_EGL_ANGLE_surface_orientation ) {
300+ EGLint orientation;
301+ if (eglQuerySurface (gldisplay.egl_display , glwindow.egl_surface , EGL_SURFACE_ORIENTATION_ANGLE, &orientation)) {
302+ if (orientation & EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE && !(orientation & EGL_SURFACE_ORIENTATION_INVERT_X_ANGLE)) {
303+ glwindow.flipped_y = true ;
304+ print_verbose (" EGL: Using optimal surface orientation: Invert Y" );
305+ }
306+ } else {
307+ ERR_PRINT (vformat (" Failed to get EGL_SURFACE_ORIENTATION_ANGLE, error: 0x%08X" , eglGetError ()));
308+ }
309+ }
310+ #endif
311+
253312 window_make_current (p_window_id);
254313
255314 return OK;
@@ -316,6 +375,10 @@ void EGLManager::window_make_current(DisplayServer::WindowID p_window_id) {
316375 GLDisplay ¤t_display = displays[current_window->gldisplay_id ];
317376
318377 eglMakeCurrent (current_display.egl_display , current_window->egl_surface , current_window->egl_surface , current_display.egl_context );
378+
379+ #ifdef WINDOWS_ENABLED
380+ RasterizerGLES3::set_screen_flipped_y (glwindow.flipped_y );
381+ #endif
319382}
320383
321384void EGLManager::set_use_vsync (bool p_use) {
0 commit comments