Skip to content

Commit 10db6b4

Browse files
bkaradzic-microsoftbkaradzicCopilot
authored
Add OpenGLWindowsDevOnly graphics API for Windows (#1655)
Gate OpenGLES on Windows behind -DGRAPHICS_API=OpenGLWindowsDevOnly. CMake finds libEGL.dll and libGLESv2.dll from the Edge or Chrome installation via the App Paths registry key and copies them into the executable output directory at build time. Edge is tried first since it ships with Windows, followed by Chrome. --------- Co-authored-by: Branimir Karadzic <branimirkaradzic@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 5ac626c commit 10db6b4

4 files changed

Lines changed: 67 additions & 5 deletions

File tree

Apps/Playground/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ target_link_libraries(Playground
148148
add_custom_command(TARGET Playground POST_BUILD
149149
COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:Playground>>,copy,true> $<TARGET_RUNTIME_DLLS:Playground> $<TARGET_FILE_DIR:Playground> COMMAND_EXPAND_LISTS)
150150

151+
if(ANGLE_LIBEGL)
152+
add_custom_command(TARGET Playground POST_BUILD
153+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBEGL}" "$<TARGET_FILE_DIR:Playground>"
154+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBGLESV2}" "$<TARGET_FILE_DIR:Playground>"
155+
COMMENT "Copying ANGLE libraries to Playground output directory"
156+
)
157+
endif()
158+
151159
if (UNIX AND NOT APPLE AND NOT ANDROID)
152160
# Ubuntu mixes old experimental header and new runtime libraries
153161
# Resulting in crash at runtime for std::filesystem

Apps/UnitTests/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ add_test(NAME UnitTests COMMAND UnitTests)
7272
add_custom_command(TARGET UnitTests POST_BUILD
7373
COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:UnitTests>>,copy,true> $<TARGET_RUNTIME_DLLS:UnitTests> $<TARGET_FILE_DIR:UnitTests> COMMAND_EXPAND_LISTS)
7474

75+
if(ANGLE_LIBEGL)
76+
add_custom_command(TARGET UnitTests POST_BUILD
77+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBEGL}" "$<TARGET_FILE_DIR:UnitTests>"
78+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBGLESV2}" "$<TARGET_FILE_DIR:UnitTests>"
79+
COMMENT "Copying ANGLE libraries to UnitTests output directory"
80+
)
81+
endif()
82+
7583
foreach(ASSET ${BABYLONJS_ASSETS} ${BABYLONJS_MATERIALS_ASSETS} ${TEST_ASSETS})
7684
get_filename_component(ASSET_NAME "${ASSET}" NAME)
7785
add_custom_command(

CMakeLists.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ FetchContent_Declare(base-n
3535
EXCLUDE_FROM_ALL)
3636
FetchContent_Declare(bgfx.cmake
3737
GIT_REPOSITORY https://github.com/BabylonJS/bgfx.cmake.git
38-
GIT_TAG ccbe08cbef9e370d0b7a2a4023d424247a727624
38+
GIT_TAG 7499c2fe6b7f403381f397c04325450312f74c2e
3939
EXCLUDE_FROM_ALL)
4040
FetchContent_Declare(CMakeExtensions
4141
GIT_REPOSITORY https://github.com/BabylonJS/CMakeExtensions.git
42-
GIT_TAG 631780e42886e5f12bfd1a5568c7395f1d657f43
42+
GIT_TAG 631780e42886e5f12bfd1a5568c7395f1d657f43
4343
EXCLUDE_FROM_ALL)
4444
FetchContent_Declare(glslang
4545
GIT_REPOSITORY https://github.com/BabylonJS/glslang.git
@@ -202,13 +202,61 @@ elseif(UNIX)
202202
elseif(WIN32)
203203
if(NOT GRAPHICS_API)
204204
set(GRAPHICS_API D3D11)
205+
elseif(GRAPHICS_API STREQUAL "OpenGLWindowsDevOnly")
206+
# OpenGLES via ANGLE from a Chromium-based browser (dev-only).
207+
set(GRAPHICS_API OpenGL)
208+
set(BABYLON_NATIVE_OPENGLES_FROM_BROWSER ON)
205209
else()
206210
if(NOT GRAPHICS_API STREQUAL Vulkan AND NOT GRAPHICS_API STREQUAL D3D11 AND NOT GRAPHICS_API STREQUAL D3D12)
207211
message(FATAL_ERROR "Unrecognized/Unsupported render API: ${GRAPHICS_API}")
208212
endif()
209213
endif()
210214
endif()
211215

216+
# Find ANGLE libraries from Edge or Chrome when using OpenGLWindowsDevOnly.
217+
if(BABYLON_NATIVE_OPENGLES_FROM_BROWSER)
218+
foreach(_browser_exe "msedge.exe" "chrome.exe")
219+
if(ANGLE_LIBEGL)
220+
break()
221+
endif()
222+
foreach(_reg_root "HKLM" "HKCU")
223+
if(ANGLE_LIBEGL)
224+
break()
225+
endif()
226+
execute_process(
227+
COMMAND reg query "${_reg_root}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\${_browser_exe}" /ve
228+
OUTPUT_VARIABLE _reg_output
229+
ERROR_QUIET
230+
RESULT_VARIABLE _reg_result
231+
OUTPUT_STRIP_TRAILING_WHITESPACE
232+
)
233+
if(NOT _reg_result EQUAL 0)
234+
continue()
235+
endif()
236+
string(REGEX MATCH "REG_SZ[ \t]+([^\r\n]+)" _ "${_reg_output}")
237+
string(STRIP "${CMAKE_MATCH_1}" _browser_path)
238+
if(NOT _browser_path)
239+
continue()
240+
endif()
241+
cmake_path(GET _browser_path PARENT_PATH _browser_dir)
242+
file(GLOB _version_dirs LIST_DIRECTORIES true "${_browser_dir}/[0-9]*")
243+
list(SORT _version_dirs ORDER DESCENDING)
244+
foreach(_version_dir ${_version_dirs})
245+
if(IS_DIRECTORY "${_version_dir}" AND EXISTS "${_version_dir}/libEGL.dll")
246+
set(ANGLE_LIBEGL "${_version_dir}/libEGL.dll")
247+
set(ANGLE_LIBGLESV2 "${_version_dir}/libGLESv2.dll")
248+
message(STATUS "Found ANGLE libraries in: ${_version_dir}")
249+
break()
250+
endif()
251+
endforeach()
252+
endforeach()
253+
endforeach()
254+
255+
if(NOT ANGLE_LIBEGL)
256+
message(FATAL_ERROR "OpenGLWindowsDevOnly requires ANGLE libraries (libEGL.dll, libGLESv2.dll) from Edge or Chrome, but none were found.")
257+
endif()
258+
endif()
259+
212260
if(APPLE)
213261
set(BABYLON_NATIVE_PLATFORM_IMPL_EXT "mm")
214262
else()

Core/Graphics/Include/RendererType/OpenGL/Babylon/Graphics/RendererType.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#pragma once
22

3-
#include <EGL/egl.h>
4-
53
namespace Babylon::Graphics
64
{
7-
using DeviceT = EGLContext;
5+
using DeviceT = void*;
86
using TextureT = unsigned int;
97
using TextureFormatT = unsigned int;
108

0 commit comments

Comments
 (0)