Yes! Apple now provide an official Metal C++ wrapper.
This download also provides C++ wrappers for some Foundation and QuartzCore classes as well, however it's not obvious how you are supposed to integrate the C++ classes into an app using MetalKit, which is what you are likely to be using these days...
EDIT: Having tried it, I would not recommend it. Having converted my small Objective-C++ project over to using it this evening it did not work and it was not obvious why (crashes in sendMessage
).
It's also much more work to manage the reference counting than using Objective-C++ where you use id<MTLWhatever>
and ARC does the work for you.
As far as converting from an Objective-C object to a C++ object, it's a simple bridging-cast:
// In MyClass.cppMyClass::~MyClass(){ if (_buffer != nullptr) _buffer->release();}void MyClass::setBuffer(MTL::Buffer* buffer){ if (_buffer != nullptr) _buffer->release(); _buffer = buffer->retain();}// In SomeClass.mmid<MTLBuffer> inBuf = ...;myClass.setBuffer((__bridge MTL::Buffer*)inBuf);