aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2021-04-14 18:50:42 +0200
committerAndre Weissflog <floooh@gmail.com>2021-04-14 18:57:01 +0200
commit0c5bc3a7f08a507d85a83bfc0140665c9eb7cf50 (patch)
treea1bc059e62267d318add60bed2abbf28d934b6db
parent4adc53e0a44fb3ee16feea394a771bccb696209f (diff)
sokol_gfx.h Metal: handle currentDrawable == nil (fixes #504)
- presentDrawable is skipped if the drawable_cb returns nil - moved the completion handler block up into the first begin-pass of a frame, this should make a difference, but it's similar now to the Xcode Metal example project. - tested by returning nil from sapp_metal_get_renderpass_descriptor() and/or sapp_metal_get_drawable()
-rw-r--r--sokol_gfx.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/sokol_gfx.h b/sokol_gfx.h
index 9049ae27..acda3dc4 100644
--- a/sokol_gfx.h
+++ b/sokol_gfx.h
@@ -10578,6 +10578,11 @@ _SOKOL_PRIVATE void _sg_mtl_begin_pass(_sg_pass_t* pass, const sg_pass_action* a
/* block until the oldest frame in flight has finished */
dispatch_semaphore_wait(_sg.mtl.sem, DISPATCH_TIME_FOREVER);
_sg.mtl.cmd_buffer = [_sg.mtl.cmd_queue commandBufferWithUnretainedReferences];
+ [_sg.mtl.cmd_buffer addCompletedHandler:^(id<MTLCommandBuffer> cmd_buffer) {
+ // NOTE: this code is called on a different thread!
+ _SOKOL_UNUSED(cmd_buffer);
+ dispatch_semaphore_signal(_sg.mtl.sem);
+ }];
}
/* if this is first pass in frame, get uniform buffer base pointer */
@@ -10724,11 +10729,9 @@ _SOKOL_PRIVATE void _sg_mtl_commit(void) {
else {
cur_drawable = (__bridge id<MTLDrawable>) _sg.mtl.drawable_userdata_cb(_sg.mtl.user_data);
}
- [_sg.mtl.cmd_buffer presentDrawable:cur_drawable];
- [_sg.mtl.cmd_buffer addCompletedHandler:^(id<MTLCommandBuffer> cmd_buffer) {
- _SOKOL_UNUSED(cmd_buffer);
- dispatch_semaphore_signal(_sg.mtl.sem);
- }];
+ if (nil != cur_drawable) {
+ [_sg.mtl.cmd_buffer presentDrawable:cur_drawable];
+ }
[_sg.mtl.cmd_buffer commit];
/* garbage-collect resources pending for release */