OSX/Metal people: do you know of any guide how to create a simple window with a metal layer from code? I have a MTKView but it seems I cannot do things like while(running) { repaint(); } on it. Do I need it to event based? Can I fake it?(OSX noob here)
-
Show this thread
-
Replying to @joeldevahl
You’d normally want to draw in response to a CVDisplayLink callback (which MTKView uses internally on macOS), but you can also use the setNeedsDisplay/updateLayer mechanism to provoke drawing into a CAMetalLayer. Happy to discuss further on DM.
2 replies 0 retweets 1 like -
Replying to @warrenm @joeldevahl
As you observe, Cocoa generally wants to be event-driven, so you wouldn’t want to redraw in a tight loop because (1) you’ll starve the runloop event processing mechanism and (2) you’re going to wind up blocking in -[CAMetalLayer nextDrawable] if you try to run too far ahead.
1 reply 0 retweets 0 likes -
Replying to @warrenm
Right! I suspected I needed to go event driven somehow. But how do you usually implement a game loop with that? Trigger a new request for a draw when the last one finishes?
1 reply 0 retweets 0 likes
Perhaps. There are of course many, many ways to tackle synchronization, but in the simplest case, you’d run a CVDisplayLink at your target frame rate and kick off rendering from the callback.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.