sdl-metal-cpp-example icon indicating copy to clipboard operation
sdl-metal-cpp-example copied to clipboard

Use Metal's C++ interface to draw a triangle in a SDL window

sdl-metal-cpp-example

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's CAMetalLayer. 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 calls retain() and release() 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-created NSObject, which presumably has its reference count set to 1, use the function make_owned(), which creates a new shared_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.