Skip to content

Build and run natively on macOS - #217

Merged
j0zzz merged 1 commit into
j0zzz:masterfrom
christopherlongden:macos-build
Oct 4, 2026
Merged

j0zzz merged 1 commit into
j0zzz:masterfrom
christopherlongden:macos-build

Conversation

@christopherlongden

Copy link
Copy Markdown
Contributor

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 the gl_rlight.c gate, which can't change what other platforms build (see below).

Changes

  • Build: On Apple, CMake links the OpenGL framework and finds the Homebrew libraries through pkg-config. GL headers come from <OpenGL/gl.h>, GL functions are looked up with SDL_GL_GetProcAddress, and gl_warp.c no longer needs <malloc.h>.
  • Physics: The macOS build uses -ffp-contract=off. Apple clang otherwise fuses a*b+c into FMA instructions on arm64, about 1,150 of them in joequake-gl. Those round differently from the x86 SSE builds, which matters for physics parity. With the flag there are none.
  • GLSL on a 2.1 context: macOS gives this renderer an OpenGL 2.1 context (2.1 Metal, GLSL 1.20), but SDL_GL_GetProcAddress resolves every GL function regardless of context version. The function-pointer checks in CheckGLSLExtensions therefore passed, and the #version 130/150 compatibility alias 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 110 gamma shader still works.
    • The vertex-light texture and uniform buffers (GL_TEXTURE_BUFFER/GL_UNIFORM_BUFFER, GL 3.1) are now only built when gl_glsl_alias_able is set. The alias shader is their only reader. They were raising GL_INVALID_ENUM (1280) on the 2.1 context.
    • On other platforms gl_glsl_alias_able already implies the old condition, so nothing changes there except with -noglslalias, where the unused buffers are no longer built.
  • Crash when water loads: On 2.1, qglGenerateMipmap stays NULL, so GL_Upload32 falls back to legacy GL_GENERATE_MIPMAP. Apple's GL-on-Metal then crashes inside glCopyTexSubImage2D in R_UpdateWarpTextures as soon as a map with water loads:
    EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x1e0
    GLEngine     glCopyTexSubImage2D_Exec
    joequake-gl  R_UpdateWarpTextures   gl_warp.c:404
    joequake-gl  R_SetupFrame           gl_rmain.c:3948
    
    Just before the copy, the texture state was valid: the 512×512 warp texture bound on unit 0, reading GL_BACK, inside the viewport. On Apple, CheckGenerateMipmapExtension now takes glGenerateMipmapEXT from EXT_framebuffer_object. That matches what GL 3+ drivers do elsewhere: explicit mipmap generation, no legacy flag.
  • README: macOS build notes.

Screenshots need #216 (a 64-bit JPEG bug that also affects Linux).

Testing

Built with the README steps (cmake .., make) from this branch:

  • Windowed and desktop-fullscreen (3840×1620 @ 100 Hz) on E1M1, with no GL errors and no shader compile failures.
  • timedemo demo1: 969 frames at about 440 fps.
  • Demo recording and cl_autodemo/keepdemo.
  • .dz playback through a macOS build of kugelrund/dzip named dzip-linux.
  • Background music from mp3.

Maybe as a follow-up: a macOS job in the auto-build workflow.

🤖 Generated with Claude Code

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>
@j0zzz
j0zzz merged commit d264d6d into j0zzz:master Oct 4, 2026
@j0zzz

j0zzz commented Oct 4, 2026

Copy link
Copy Markdown
Owner

Hey Chris,
Wow, I have not expected to receive a PR from you :) Good to see old folks like you still follow Quake speedrunning.
Also, thanks a lot for the add-on. Even though I'm not sure how many Mac users are there to speedrun Quake (on the discord I can't recall anybody requesting Mac support ever), any addition is highly welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants