-
Hi There! I am trying to compile and link raylib against Google's ANGLE so I can get better performance on Mac M1 Chips. With OpenGL being deprecated and being about 10 times slower than Metal on M1 Macs, the improved support for ANGLE, essentially giving raylib a Metal Backend is exciting! System
Folder Structure (up to 2 levels) λ ~/code/projects/raylib-cmake-starter/ angle* tree -L 2
.
├── CMakeLists.txt
├── README.md
├── bootstrap.sh
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── CPackConfig.cmake
│ ├── CPackSourceConfig.cmake
│ ├── Makefile
│ ├── cmake_install.cmake
│ ├── raylib-starter
│ └── vendor
├── build.sh
├── build_with_angle.sh
├── run.sh
├── src
│ └── main.cpp
└── vendor
├── angle
└── raylib (All paths relative to root project directory unless absolute)
CMakeFiles.txt and output cmake_minimum_required(VERSION 3.16)
project(raylib-starter)
set(CMAKE_CXX_STANDARD 14)
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
# Set raylib and ANGLE include and library paths
set(RAYLIB_INCLUDE_DIR vendor/raylib/src)
set(RAYLIB_LIBRARY_DIR vendor/raylib/src)
set(ANGLE_INCLUDE_DIR vendor/angle/include)
set(ANGLE_LIBRARY_DIR vendor/angle/out/Release)
# Replace <path_to_angle_repository> with the actual path to your cloned ANGLE repository
target_include_directories(${PROJECT_NAME} PRIVATE
${RAYLIB_INCLUDE_DIR}
${ANGLE_INCLUDE_DIR}
)
# Find the raylib and ANGLE libraries
find_library(RAYLIB_LIBRARY libraylib.a PATHS ${RAYLIB_LIBRARY_DIR})
find_library(ANGLE_GLESv2_LIBRARY libGLESv2.dylib PATHS ${ANGLE_LIBRARY_DIR})
find_library(ANGLE_EGL_LIBRARY libEGL.dylib PATHS ${ANGLE_LIBRARY_DIR})
# Link required system frameworks for macOS
find_library(COCOA_LIBRARY Cocoa)
find_library(OPENGL_LIBRARY OpenGL)
find_library(IOKIT_LIBRARY IOKit)
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
find_library(CORE_VIDEO_LIBRARY CoreVideo)
target_link_libraries(${PROJECT_NAME}
# Link raylib static library
${RAYLIB_LIBRARY}
# Link ANGLE libraries
${ANGLE_GLESv2_LIBRARY}
${ANGLE_EGL_LIBRARY}
# Link macOS system frameworks
${OPENGL_LIBRARY}
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${CORE_FOUNDATION_LIBRARY}
${CORE_VIDEO_LIBRARY}
) It compiles fine, but raylib gives a black screen:
However in version of my cmake_minimum_required(VERSION 3.16)
project(raylib-starter)
set(CMAKE_CXX_STANDARD 14)
file(GLOB_RECURSE SOURCES "src/*.cpp")
add_executable(${PROJECT_NAME} ${SOURCES})
# Set raylib and ANGLE include and library paths
set(RAYLIB_INCLUDE_DIR vendor/raylib/src)
set(RAYLIB_LIBRARY_DIR vendor/raylib/src)
set(ANGLE_INCLUDE_DIR vendor/angle/include)
set(ANGLE_LIBRARY_DIR vendor/angle/out/Release)
# Replace <path_to_angle_repository> with the actual path to your cloned ANGLE repository
target_include_directories(${PROJECT_NAME} PRIVATE
${RAYLIB_INCLUDE_DIR}
${ANGLE_INCLUDE_DIR}
)
# Find the raylib and ANGLE libraries
find_library(RAYLIB_LIBRARY libraylib.a PATHS ${RAYLIB_LIBRARY_DIR})
find_library(ANGLE_GLESv2_LIBRARY libGLESv2.dylib PATHS ${ANGLE_LIBRARY_DIR})
find_library(ANGLE_EGL_LIBRARY libEGL.dylib PATHS ${ANGLE_LIBRARY_DIR})
# Link required system frameworks for macOS
find_library(COCOA_LIBRARY Cocoa)
# find_library(OPENGL_LIBRARY OpenGL)
find_library(IOKIT_LIBRARY IOKit)
find_library(CORE_FOUNDATION_LIBRARY CoreFoundation)
find_library(CORE_VIDEO_LIBRARY CoreVideo)
target_link_libraries(${PROJECT_NAME}
# Link raylib static library
${RAYLIB_LIBRARY}
# Link ANGLE libraries
${ANGLE_GLESv2_LIBRARY}
${ANGLE_EGL_LIBRARY}
# Link macOS system frameworks
# ${OPENGL_LIBRARY}
${COCOA_LIBRARY}
${IOKIT_LIBRARY}
${CORE_FOUNDATION_LIBRARY}
${CORE_VIDEO_LIBRARY}
)
I get the following errors: [ 50%] Linking CXX executable raylib-starter
Undefined symbols for architecture arm64:
"_glClearDepth", referenced from:
_rlglInit in libraylib.a(rcore.c.o)
"_glGetTexImage", referenced from:
_rlReadTexturePixels in libraylib.a(rcore.c.o)
"_glPolygonMode", referenced from:
_rlEnableWireMode in libraylib.a(rcore.c.o)
_rlDisableWireMode in libraylib.a(rcore.c.o)
ld: symbol(s) not found for architecture arm64 Would appreciate it if anyone has anyone has any thoughts on this or knows how to get raylib working with ANGLE! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 19 replies
-
@grplyler Did you manage to get it working? ANGLE support has been added recently and it's still quitte experimental, not sure if anyone has tried it with macOS M1 CPU just yet. Please, if you investigated it, let me know your progress! |
Beta Was this translation helpful? Give feedback.
-
last time I looked at Angle on Linux I failed to even get it to compile, so well done, I look forward to the write up so I can have another go! |
Beta Was this translation helpful? Give feedback.
-
Eyeing that iOS Metal translation that ANGLE seems to provide like 🕵️♀️🕵️🕵️♂️ |
Beta Was this translation helpful? Give feedback.
-
Nice. It can be merged into raylib and officially add support for macOS and iOS. |
Beta Was this translation helpful? Give feedback.
-
Writeup on how to do this is out! Also got the source code at https://github.com/grplyler/raylib-articles if we want to collab, @Peter0x44 on adding it to the Raylib wiki. Medium post: https://medium.com/@grplyler/building-and-linking-googles-angle-with-raylib-on-macos-67b07cd380a3 |
Beta Was this translation helpful? Give feedback.
-
@grplyler thanks for the article and research! I tried the one-line command you showed in the article. It compiles successfully, but I am not sure it's using the ANGLE in the end. This is the one-line command I am using to compile: I think the issue is that it doesn't choose the ANGLE library and defaults to openGL. I tried to add Log:
I would appreciate any help, thanks! |
Beta Was this translation helpful? Give feedback.
-
@andrei-zgirvaci Those are only cmake valid options. You need to define |
Beta Was this translation helpful? Give feedback.
-
I just tested ANGLE on Linux with my Go bindings. I used the
I also had to symlink As for performance, it is actually a little better with plain OpenGL, around 2500FPS, with ANGLE it is around 2300, on intel GPU:
And every time I close the window there is a segfault, that is on X11:
|
Beta Was this translation helpful? Give feedback.
Update: After a few black screens, thanks to raylibs trace logs, I did manage to get it working on a small 2D project for work and went from about ~3000 FPS (optimized build without ANGLE) to ~7300 FPS with ANGLE!
Without ANGLE (optimized build)
With ANGLE (optimized build, dylib, 2021 Apple M1 Pro, 10 CPU Cores, 10 GPU Cores)
Raylib Debug Tracing with ANGLE