I have metal objects in main and modal view controllers.
main UIViewController:
- (void)viewDidLoad
{
…
_mtlLayer = [CAMetalLayer new];
_mtlLayer.frame = self.view.layer.frame;
[self.view.layer addSublayer:_mtlLayer];
/* set the pointer to renderer */
…
/* method "draw" run "drawPrimitive" don't use "CADisplayLink" */
[_renderer draw];
}
modal view controller call method of main:
- (void)showModalController
{
DGAModalViewController *modal = [[DGAModalViewController alloc] init];
modal.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:modal animated:YES completion:nil];
}
The rendering visualization will output in the _imageView (UIImageView), which is added to the modal controller when it is initialized.
The _imageView is initialized with a frame, but does not yet have an image.
The image will be added later in the method viewDidLayoutSubviews, where _imageView gets CGImage from renderer.
Rendering is done in both the main and modal controllers using the same pipeline settings and the same command queue. Also, some data buffers are shared for rendering by both controllers.
Rendering occurs with different textures.
The main controller uses a triple buffering for animation.
If an animation was run in the presentingViewController before calling the modal controller, the _imageView is displayed well. Otherwise, the _imageView will fill all outlines with black.
If _imageView is replaced with CAMetalLayer, then it is enough to call [self.presentingViewController draw] (no CADisplayLink and RunLoop) after or before calling the modal controller so that its image is colored. Otherwise, it is also filled with black.
What prevents the image from being displayed correctly right away?




