Skip to content

GLES3: Split EGL includes in platform_egl.h#115632

Draft
akien-mga wants to merge 1 commit intogodotengine:masterfrom
akien-mga:gles3-split-platform-egl
Draft

GLES3: Split EGL includes in platform_egl.h#115632
akien-mga wants to merge 1 commit intogodotengine:masterfrom
akien-mga:gles3-split-platform-egl

Conversation

@akien-mga
Copy link
Member

@akien-mga akien-mga commented Jan 30, 2026

EGL brings in platform-specific headers such as the dreaded windows.h, and platform_gl.h is used throughout drivers/gles3 for basic OpenGL types such as GLuint. We don't want windows.h pollution there.

Note for Android: EGL seems used explicitly only via rasterizer_gles3.cpp to enable GL debug printing, and some custom stuff in config.cpp.

Split from #115623, it helps solves an include order issue there.

Seems to work ok on Linux from a quick test, but this needs testing on Windows and macOS, with and without ANGLE.

@akien-mga akien-mga added this to the 4.x milestone Jan 30, 2026
@akien-mga akien-mga requested review from a team as code owners January 30, 2026 13:24
Comment on lines +40 to +43
#ifdef MACOS_ENABLED
// FIXME: macOS relies on GL being included at this stage for some reason.
#include "platform_gl.h"
#endif
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without including GL here, macOS build breaks: https://github.com/akien-mga/godot/actions/runs/21516923985/job/61997594479

clang++ -o platform/macos/display_server_macos.macos.editor.x86_64.o -c -std=gnu++17 -fno-exceptions -Wctor-dtor-privacy -Wnon-virtual-dtor -arch x86_64 -mmacosx-version-min=10.13 -ffp-contract=off -fobjc-arc -fvisibility=hidden -isysroot /Applications/Xcode_26.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk -msse4.2 -mpopcnt -fcolor-diagnostics -O2 -Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wshadow-field-in-constructor -Wshadow-uncaptured-local -Wno-ordered-compare-function-pointers -Wenum-conversion -Wimplicit-fallthrough -Werror -DTOOLS_ENABLED -DDEBUG_ENABLED -DNDEBUG -DENGINE_UPDATE_CHECK_ENABLED -DNO_EDITOR_SPLASH -DSTRICT_CHECKS -DACCESSKIT_ENABLED -DSDL_ENABLED -DMACOS_ENABLED -DUNIX_ENABLED -DCOREAUDIO_ENABLED -DCOREMIDI_ENABLED -DGLES3_ENABLED -DVULKAN_ENABLED -DRD_ENABLED -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -DMINIZIP_ENABLED -DBROTLI_ENABLED -DOVERRIDE_ENABLED -DOVERRIDE_PATH_ENABLED -DTHREADS_ENABLED -DCLIPPER2_ENABLED -DZSTD_STATIC_LINKING_ONLY -DVK_USE_PLATFORM_MACOS_MVK -DVK_USE_PLATFORM_METAL_EXT -DGLAD_ENABLED -DEGL_ENABLED -DTESTS_ENABLED -Ithirdparty/freetype/include -Ithirdparty/libpng -Ithirdparty/glad -Ithirdparty/vulkan -Ithirdparty/vulkan/include -Ithirdparty/zstd -Ithirdparty/zlib -Ithirdparty/clipper2/include -Ithirdparty/brotli/include -Ithirdparty/angle/include -Iplatform/macos -Iaccesskit-c-0.18.0/include -I. platform/macos/display_server_macos.mm
In file included from platform/macos/display_server_macos.mm:71:
In file included from ./drivers/gles3/rasterizer_gles3.h:35:
In file included from ./drivers/gles3/effects/copy_effects.h:35:
In file included from ./drivers/gles3/shaders/effects/copy.glsl.gen.h:35:
In file included from ./drivers/gles3/shader_gles3.h:43:
In file included from platform/macos/platform_gl.h:41:
Error: ./thirdparty/glad/glad/gl.h:38:4: error: OpenGL (gl.h) header already included (API: gl), remove previous include!
   38 |   #error OpenGL (gl.h) header already included (API: gl), remove previous include!
      |    ^
Error: ./thirdparty/glad/glad/gl.h:40:9: error: '__gl_h_' macro redefined [-Werror,-Wmacro-redefined]
   40 | #define __gl_h_ 1
      |         ^
/Applications/Xcode_26.0.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2:9: note: previous definition is here
    2 | #define __gl_h_
      |         ^

I don't know why, but it doesn't happen on Windows and Linux, so I suspect it's pointing at some bad include order for GL stuff in platform/macos.

#include "core/templates/local_vector.h"
#include "servers/display/display_server.h"

// EGL includes platform-specific headers, so should come last.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem to make a difference if first or last here, but I think the correct practice is to put it last?

Comment on lines +81 to +90
#if defined(EGL_ENABLED) || defined(ANDROID_ENABLED)
// We include EGL below to get a debug callback, but EGL is not
// available on iOS or the web.
#define EGL_DEBUG_CALLBACK

#ifdef _WIN32
#define strcpy strcpy_s
#endif

#include "platform_egl.h"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored this a bit as the previous logic was to conditionally use EGL for debug callbacks on desktop platforms (EGL_ENABLED) and Android (doesn't define it, but it's an EGL platform).

And the strcpy isn't compiler but stdlib specific on Windows AFAIK, and only needed when using the EGL debug callback.

@akien-mga
Copy link
Member Author

akien-mga commented Jan 30, 2026

So Windows + ANGLE fails linking (both with MSVC and MinGW), and I'm not really sure why:

x86_64-w64-mingw32-g++ -o bin\godot.windows.template_release.x86_64.exe -Wl,--subsystem,windows -static -Wl,--stack,8388608 -s -O3 -Wl,--entry=ShimMainCRTStartup platform\windows\cpu_feature_validation.windows.template_release.x86_64.o platform\windows\os_windows.windows.template_release.x86_64.o platform\windows\display_server_windows.windows.template_release.x86_64.o platform\windows\key_mapping_windows.windows.template_release.x86_64.o platform\windows\tts_windows.windows.template_release.x86_64.o platform\windows\windows_terminal_logger.windows.template_release.x86_64.o platform\windows\windows_utils.windows.template_release.x86_64.o platform\windows\native_menu_windows.windows.template_release.x86_64.o platform\windows\gl_manager_windows_native.windows.template_release.x86_64.o platform\windows\gl_manager_windows_angle.windows.template_release.x86_64.o platform\windows\wgl_detect_version.windows.template_release.x86_64.o platform\windows\rendering_context_driver_vulkan_windows.windows.template_release.x86_64.o platform\windows\drop_target_windows.windows.template_release.x86_64.o platform\windows\godot_windows.windows.template_release.x86_64.o platform\windows\crash_handler_windows_signal.windows.template_release.x86_64.o platform\windows\godot_res_template.windows.template_release.x86_64.o platform\windows\libuiautomationcore.x86_64.a -Laccesskit-c-0.18.0\lib\windows\x86_64\mingw\static -Lbin\obj\platform\windows -Lplatform\windows -LC:\Users\runneradmin\AppData\Local\Godot\build_deps\mesa-x86_64-gcc\bin -L. main\libmain.windows.template_release.x86_64.a tests\libtests.windows.template_release.x86_64.a modules\libmodules.windows.template_release.x86_64.a modules\libmodule_text_server_adv.windows.template_release.x86_64.a modules\libmodule_text_server_fb.windows.template_release.x86_64.a modules\libmodule_fbx.windows.template_release.x86_64.a modules\libmodule_gltf.windows.template_release.x86_64.a modules\libmodule_ktx.windows.template_release.x86_64.a modules\libmodule_svg.windows.template_release.x86_64.a modules\libmodule_theora.windows.template_release.x86_64.a modules\libmodule_vorbis.windows.template_release.x86_64.a modules\libmodule_astcenc.windows.template_release.x86_64.a modules\libmodule_basis_universal.windows.template_release.x86_64.a modules\libmodule_bcdec.windows.template_release.x86_64.a modules\libmodule_bmp.windows.template_release.x86_64.a modules\libmodule_camera.windows.template_release.x86_64.a modules\libmodule_csg.windows.template_release.x86_64.a modules\libmodule_dds.windows.template_release.x86_64.a modules\libmodule_enet.windows.template_release.x86_64.a modules\libmodule_etcpak.windows.template_release.x86_64.a modules\libmodule_gdscript.windows.template_release.x86_64.a modules\libmodule_glslang.windows.template_release.x86_64.a modules\libmodule_godot_physics_2d.windows.template_release.x86_64.a modules\libmodule_godot_physics_3d.windows.template_release.x86_64.a modules\libmodule_gridmap.windows.template_release.x86_64.a modules\libmodule_hdr.windows.template_release.x86_64.a modules\libmodule_interactive_music.windows.template_release.x86_64.a modules\libmodule_jolt_physics.windows.template_release.x86_64.a modules\libmodule_jpg.windows.template_release.x86_64.a modules\libmodule_jsonrpc.windows.template_release.x86_64.a modules\libmodule_mbedtls.windows.template_release.x86_64.a modules\libmodule_meshoptimizer.windows.template_release.x86_64.a modules\libmodule_mobile_vr.windows.template_release.x86_64.a modules\libmodule_mp3.windows.template_release.x86_64.a modules\libmodule_multiplayer.windows.template_release.x86_64.a modules\libmodule_navigation_2d.windows.template_release.x86_64.a modules\libmodule_navigation_3d.windows.template_release.x86_64.a modules\libmodule_noise.windows.template_release.x86_64.a modules\libmodule_ogg.windows.template_release.x86_64.a modules\libmodule_openxr.windows.template_release.x86_64.a modules\libmodule_raycast.windows.template_release.x86_64.a modules\libmodule_regex.windows.template_release.x86_64.a modules\libmodule_tga.windows.template_release.x86_64.a modules\libmodule_tinyexr.windows.template_release.x86_64.a modules\libmodule_upnp.windows.template_release.x86_64.a modules\libmodule_vhacd.windows.template_release.x86_64.a modules\libmodule_webp.windows.template_release.x86_64.a modules\libmodule_webrtc.windows.template_release.x86_64.a modules\libmodule_websocket.windows.template_release.x86_64.a modules\libmodule_webxr.windows.template_release.x86_64.a modules\libmodule_zip.windows.template_release.x86_64.a platform\libplatform.windows.template_release.x86_64.a drivers\libdrivers.windows.template_release.x86_64.a scene\libscene.windows.template_release.x86_64.a servers\libservers.windows.template_release.x86_64.a core\libcore.windows.template_release.x86_64.a modules\freetype\libfreetype_builtin.windows.template_release.x86_64.a modules\msdfgen\libmsdfgen_builtin.windows.template_release.x86_64.a modules\text_server_adv\libharfbuzz_builtin.windows.template_release.x86_64.a modules\text_server_adv\libgraphite_builtin.windows.template_release.x86_64.a modules\text_server_adv\libicu_builtin.windows.template_release.x86_64.a -lmingw32 -ldsound -lole32 -ld3d9 -lwinmm -lgdi32 -liphlpapi -lshell32 -lshlwapi -lshcore -lwsock32 -lws2_32 -lkernel32 -loleaut32 -lsapi -ldinput8 -ldxguid -lksuser -limm32 -lbcrypt -lcrypt32 -lavrt -luuid -ldwmapi -ldwrite -lwbemuuid -lntdll -lhid -laccesskit -luiautomationcore.x86_64 -lruntimeobject -lpropsys -loleaut32 -luser32 -luserenv -lntdll -ldxgi -ldxguid -lNIR.windows.x86_64 -lversion -lEGL.windows.x86_64 -lGLES.windows.x86_64 -lANGLE.windows.x86_64 -ldxgi -ld3d9 -ld3d11 -lpsapi
ERROR: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: drivers\gles3/rasterizer_gles3.windows.template_release.x86_64.o:rasterizer_gles3.cpp:(.text+0x1a3): undefined reference to `__imp_eglGetProcAddress'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: drivers\gles3/rasterizer_gles3.windows.template_release.x86_64.o:rasterizer_gles3.cpp:(.text+0x224b): undefined reference to `__imp_eglGetProcAddress'

Even this minimal change fails:

diff --git a/drivers/egl/egl_manager.h b/drivers/egl/egl_manager.h
index 7fe5f916cc..164b7ad738 100644
--- a/drivers/egl/egl_manager.h
+++ b/drivers/egl/egl_manager.h
@@ -33,6 +33,7 @@
 #ifdef EGL_ENABLED
 
 // These must come first to avoid windows.h mess.
+#include "platform_egl.h"
 #include "platform_gl.h"
 
 #include "core/templates/local_vector.h"
diff --git a/drivers/gles3/rasterizer_gles3.cpp b/drivers/gles3/rasterizer_gles3.cpp
index 1df41493d5..971ae64bfc 100644
--- a/drivers/gles3/rasterizer_gles3.cpp
+++ b/drivers/gles3/rasterizer_gles3.cpp
@@ -82,6 +82,7 @@
 #define CAN_DEBUG
 #endif
 
+#include "platform_egl.h"
 #include "platform_gl.h"
 
 #if defined(MINGW_ENABLED) || defined(_MSC_VER)
diff --git a/platform/windows/platform_egl.h b/platform/windows/platform_egl.h
new file mode 100644
index 0000000000..48584878a2
--- /dev/null
+++ b/platform/windows/platform_egl.h
@@ -0,0 +1,10 @@
+#pragma once
+
+#ifdef EGL_STATIC
+#define KHRONOS_STATIC 1
+#include "thirdparty/angle/include/EGL/egl.h"
+#include "thirdparty/angle/include/EGL/eglext.h"
+#undef KHRONOS_STATIC
+#else
+#include "thirdparty/glad/glad/egl.h"
+#endif
diff --git a/platform/windows/platform_gl.h b/platform/windows/platform_gl.h
index 3d4a05c0db..3dd1257cea 100644
--- a/platform/windows/platform_gl.h
+++ b/platform/windows/platform_gl.h
@@ -38,13 +38,4 @@
 #define GLES_API_ENABLED // Allow using GLES (ANGLE).
 #endif
 
-#ifdef EGL_STATIC
-#define KHRONOS_STATIC 1
-#include "thirdparty/angle/include/EGL/egl.h"
-#include "thirdparty/angle/include/EGL/eglext.h"
-#undef KHRONOS_STATIC
-#else
-#include "thirdparty/glad/glad/egl.h"
-#endif
-
 #include "thirdparty/glad/glad/gl.h"

So I guess with ANGLE we have to include ANGLE EGL whenever we include GL too?
Maybe we should use ANGLE GL instead of GLAD in this case?

@akien-mga akien-mga marked this pull request as draft January 30, 2026 14:17
@bruvzg
Copy link
Member

bruvzg commented Feb 20, 2026

So I guess with ANGLE we have to include ANGLE EGL whenever we include GL too?

ANGLE should not include any headers, but we are using modified GLAD, to be capable of loading both GL and EGL, and all of these changes are in glad/gl.h and glad/gl.cpp which is loading GetProcAddress, so likely the cause of linking errors.

@akien-mga akien-mga force-pushed the gles3-split-platform-egl branch from 30a8b3e to c9680d4 Compare February 23, 2026 22:17
EGL brings in platform-specific headers such as the dreaded `windows.h`,
and `platform_gl.h` is used throughout `drivers/gles3` for basic OpenGL
types such as `GLuint`. We don't want `windows.h` pollution there.

Note for Android: EGL seems used explicitly only via `rasterizer_gles3.cpp`
to enable GL debug printing, and some custom stuff in `config.cpp`.
@akien-mga akien-mga force-pushed the gles3-split-platform-egl branch from c9680d4 to 8c11f4d Compare March 2, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants