Skip to content

Add macOS support#14

Open
VjiaoBlack wants to merge 1 commit intoweigert:masterfrom
VjiaoBlack:macos-support
Open

Add macOS support#14
VjiaoBlack wants to merge 1 commit intoweigert:masterfrom
VjiaoBlack:macos-support

Conversation

@VjiaoBlack
Copy link
Copy Markdown

@VjiaoBlack VjiaoBlack commented Apr 5, 2026

Summary

  • Adds macOS (OpenGL 4.1 / Metal) compatibility while preserving the existing Linux fast path
  • All OpenGL 4.3/4.4 code is kept behind #ifndef TINYENGINE_OS_MAC guards — Linux builds are unchanged
  • Shaders downgraded from GLSL 430 to 410, which is a compatible subset (no behavioral change on 4.3+ drivers)

Changes

  • Makefile: detects Darwin via uname, sets clang++, -framework OpenGL, homebrew paths, -DTINYENGINE_OS_MAC
  • source/vertexpool.h: #ifdef TINYENGINE_OS_MAC fallbacks for:
    • glVertexAttribPointer instead of glVertexAttribFormat / glBindVertexBuffer (GL 4.3)
    • glBufferData + CPU buffer instead of glBufferStorage + persistent mapping (GL 4.4)
    • glDrawElementsBaseVertex loop instead of glMultiDrawElementsIndirect (GL 4.3)
  • Shaders: #version 430 core#version 410 core, removed const on local vars (Apple GLSL rejects this)
  • SimpleHydrology.cpp: fixed UB in version assert (strcmp instead of == on char[])

Prerequisites

TinyEngine must also be compiled with -DTINYENGINE_OS_MAC on macOS (its Makefile examples already do this).

Test plan

  • Verify Linux build is unchanged (no TINYENGINE_OS_MAC defined → original GL 4.3 path)
  • Verify macOS build compiles and runs with make all
  • Verify simulation runs correctly on macOS (press P to unpause)

🤖 Generated with Claude Code

macOS caps OpenGL at 4.1 via Metal translation, so GL 4.3/4.4 features
(persistent mapped buffers, multi-draw-indirect, vertex attrib binding)
are unavailable. This adds ifdef-guarded fallbacks for macOS while
keeping the fast path for Linux.

- Makefile: detect Darwin, use clang++, -framework OpenGL, homebrew paths
- vertexpool.h: GL 4.1 fallbacks behind TINYENGINE_OS_MAC
- Shaders: GLSL 430 -> 410 (subset-compatible, no effect on Linux)
- SimpleHydrology.cpp: fix UB in version assert (strcmp vs == on char[])

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@VjiaoBlack VjiaoBlack marked this pull request as ready for review April 5, 2026 07:25
@VjiaoBlack
Copy link
Copy Markdown
Author

tested on Mac!

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.

1 participant