This project is an example of using the Metal API's C++ interface to draw a triangle. The project uses SDL 2 to create the window.
I've added a few things to Apple's C++ bindings:
-
CAMetalLayer.hpp provides a C++ binding for Core Animation'sCAMetalLayer
. Note that the included example uses this extension, and will therefore not work with the upstream version of 'metal-cpp'.Apple has since added this.
-
shared_ptr.hpp is an implementation of the standard C++
shared_ptr
that callsretain()
andrelease()
to manage the lifetime of the object.Assigning a
NSObject
, or passing it into the constructor, will always increase the object's reference count. To manage the lifetime of a newly-createdNSObject
, which presumably has its reference count set to 1, use the functionmake_owned()
, which creates a newshared_ptr
without increasing the object's reference count.Apple has since added
NS::SharedPtr
, but I'm leaving mine in since it resembles the standard C++shared_ptr
.