/Metal

Metal examples using C++

Primary LanguageC++MIT LicenseMIT

example workflow

Metal C++ examples

A collection of open source C++ examples for Metal

metal-cpp

These examples use a modified version of Metal-CPP originally 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.

Requirements

These samples are developed using C++20 and target the following platforms and os versions:

Platform OS Version
macOS 14.0+
iOS 17.0+
tvOS 17.0+

Building

These example applications use 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:

Ninja

   git clone https://github.com/MattGuerrette/Metal.git
   cd Metal
   mkdir cmake-build-debug
   cd cmake-build-debug
   cmake .. -GNinja
   cmake --build .

Xcode

   git clone https://github.com/MattGuerrette/Metal.git
   cd Metal
   mkdir cmake-build-xcode
   cd cmake-build-xcode
   cmake .. -GXcode -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=<Apple Developer ID>
   cmake --build .

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.

Table of Contents

Examples

Basics

Basic example for rendering a colored triangle using Metal

Rendering of multiple cube geometry instances

Showcases loading of KTX compressed textures in ASTC format into a MTLHeap and using Argument Buffers to bindlessly render multiple textures from GPU memory.