Is it possible to render an MTKView in different color spaces? For example, if I want to render it in CMYK, is there a way to adjust the colors on every frame to that colorspace before presenting it on the screen, or is that something that needs to be handled in a shader?
Replies
MTKView has a colorspace property. And to paraphrase Apple documentation :
The default value is nil, indicating that the rendered content isn’t color-matched. If you set this to a different color space, Core Animation performs any necessary color transformations when compositing the view’s contents.
-
I'm not seeing this property on MTKView, is it for some reason not available when subclassing? So far I've only seen "(self.layer as? CAMetalLayer)?.colorspace" but that doesn't work when setting it to grayscale, and when using CMYK it turns everything to black/white.
-
Actually, when trying to compile "self.color = .genericGrayscale" I get an error that it's not available in Mac Catalyst. Is there any alternative method of achieving this for the iPad/Mac Catalyst?
-
You're right, the
colorspaceproperty seems to only be available on macOS...
Hi iPerKard, I would recommend switching to using CAMetalLayer for your use case. MTKView wraps a CAMetalLayer but does not expose all advanced features. CAMetalLayer gives you more control and allows you to set the colorspace property on both macOS and iOS.