Quantcast
Channel: User trojanfoe - Stack Overflow
Viewing all articles
Browse latest Browse all 208

Answer by trojanfoe for Is there any possibility of using C++ directly with Metal API

$
0
0

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);

Viewing all articles
Browse latest Browse all 208

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>