Metal 4 support is required
A collection of open source C++ examples for Metal
These examples use a modified version of metal-cpp published by Apple. This modified version is maintained here: metal-cpp and includes some additional API bindings not yet supported by Apple, however it is actively updated with the latest fixes and additions from Apple as well.
These samples are developed using C++23 and target the following platforms and os versions:
| Platform | OS Version |
|---|---|
| macOS | 26.0+ |
| iOS | 26.0+ |
| tvOS | 26.0+ |
These example applications use Vcpkg, CMake and are actively developed using both CLion and Xcode
For those wanting to build the projects from a terminal invoking CMake directly or to generate the Xcode project files here are some example commands:
git clone --recursive https://github.com/MattGuerrette/Metal.git
cd Metal
cmake --preset macos-debug
cmake --build out/build/macos-debug
git clone --recursive https://github.com/MattGuerrette/Metal.git
cd Metal
cmake --preset macos -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=<Apple Developer ID>
cmake --build out/build/macos
For codesigning purposes, you will want to specify the development team ID as shown above to avoid needing to manually set the development team for each target project.
Basic example for rendering a colored triangle using Metal
Rendering of multiple cube geometry instances
Showcases loading of PNG textures using stb_image into a MTLHeap and using Argument Buffers to bindlessly render multiple textures from GPU memory.