Repository navigation
Build and run natively on macOS - #217
Merged
Merged
Conversation
The SDL build now compiles and runs on macOS (tested on Apple Silicon, macOS 26) against Homebrew's SDL2, libpng, jpeg-turbo, libvorbis and mad. - CMake: on Apple, link the OpenGL framework and find the Homebrew libraries with pkg-config; build with -ffp-contract=off, since Apple clang otherwise fuses multiply-adds on arm64 and rounds the physics differently from the x86 builds. - OpenGL headers come from <OpenGL/...>; GL functions are looked up with SDL_GL_GetProcAddress; gl_warp.c no longer needs <malloc.h>. - macOS gives this renderer a 2.1 context but resolves every GL function whatever the context, so the function-pointer checks passed and the #version 130/150 shaders failed to compile. Gate the GLSL alias path on GL 3 there, and only build the vertex-light texture/uniform buffers (GL 3.1) when that path is on (they were raising GL_INVALID_ENUM). - On 2.1, mipmaps fell back to legacy GL_GENERATE_MIPMAP, which crashes Apple's driver inside glCopyTexSubImage2D in R_UpdateWarpTextures as soon as a map with water loads. Use glGenerateMipmapEXT from EXT_framebuffer_object instead. - README: macOS build notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Hey Chris, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The SDL build now compiles and runs natively on macOS. It's tested on Apple Silicon (M1 Max, macOS 26) against Homebrew's SDL2, libpng, jpeg-turbo, libvorbis and mad. All changes outside CMake and the README are inside
#ifdef __APPLE__or only affect code paths that macOS reaches. The one exception is thegl_rlight.cgate, which can't change what other platforms build (see below).Changes
<OpenGL/gl.h>, GL functions are looked up withSDL_GL_GetProcAddress, andgl_warp.cno longer needs<malloc.h>.-ffp-contract=off. Apple clang otherwise fusesa*b+cinto FMA instructions on arm64, about 1,150 of them injoequake-gl. Those round differently from the x86 SSE builds, which matters for physics parity. With the flag there are none.2.1 Metal, GLSL 1.20), butSDL_GL_GetProcAddressresolves every GL function regardless of context version. The function-pointer checks inCheckGLSLExtensionstherefore passed, and the#version 130/150 compatibilityalias and world shaders failed to compile. On Apple the GLSL alias path is now gated on GL 3+, so the classic renderer draws models and world; the#version 110gamma shader still works.GL_TEXTURE_BUFFER/GL_UNIFORM_BUFFER, GL 3.1) are now only built whengl_glsl_alias_ableis set. The alias shader is their only reader. They were raisingGL_INVALID_ENUM(1280) on the 2.1 context.gl_glsl_alias_ablealready implies the old condition, so nothing changes there except with-noglslalias, where the unused buffers are no longer built.qglGenerateMipmapstays NULL, soGL_Upload32falls back to legacyGL_GENERATE_MIPMAP. Apple's GL-on-Metal then crashes insideglCopyTexSubImage2DinR_UpdateWarpTexturesas soon as a map with water loads:GL_BACK, inside the viewport. On Apple,CheckGenerateMipmapExtensionnow takesglGenerateMipmapEXTfromEXT_framebuffer_object. That matches what GL 3+ drivers do elsewhere: explicit mipmap generation, no legacy flag.Screenshots need #216 (a 64-bit JPEG bug that also affects Linux).
Testing
Built with the README steps (
cmake ..,make) from this branch:timedemo demo1: 969 frames at about 440 fps.cl_autodemo/keepdemo..dzplayback through a macOS build of kugelrund/dzip nameddzip-linux.Maybe as a follow-up: a macOS job in the auto-build workflow.
🤖 Generated with Claude Code