Rendering small CIImage centered in MTKView
This is most curious. If you use the "new" CIRenderDestination
API instead of context.render(…)
it actually works:
let destination = CIRenderDestination(width: Int(view.drawableSize.width),
height: Int(view.drawableSize.height),
pixelFormat: view.colorPixelFormat,
commandBuffer: buffer,
mtlTextureProvider: { () -> MTLTexture in
return drawable.texture
})
try! self.context.startTask(toRender: centered, to: destination)
I don't know why, but context.render(…)
doesn't seem to respect the translation of the image or the given bounds. Maybe someone else knows more...
Confusion About CIContext, OpenGL and Metal (SWIFT). Does CIContext use CPU or GPU by default?
I started making this a comment, but I think since WWDC'18 this works best as an answer. I'll edit as others more an expert than I comment, and am willing to delete the entire answer if that's the proper thing to do.
You are on the right track - utilize the GPU when you can and it's a good fit. CoreImage and Metal, while "low-level" technologies that "usually" use the GPU, can use the CPU if that is desired. CoreGraphics? It renders things using the CPU.
Images. A UIImage
and a CGImage
are actual images. A CIImage
however, isn't. The best way to think of it is a "recipe" for an image.
I typically - for now, I'll explain in a moment - stick to CoreImage, CIFilters
, CIImages, and GLKViews
when working with filters. Using a GLKView against a CIImage means using OpenGL
and a single CIContext
and EAGLContext
. It offers almost as good performance as using MetalKit
or MTKViews
.
As for using UIKit
and it's UIImage
and UIImageView
, I only do when needed - saving/sharing/uploading, whatever. Stick to the GPU until then.
....
Here's where it starts getting complicated.
Metal is an Apple proprietary API. Since they own the hardware - including the CPU and GPU - they've optimized it for them. It's "pipeline" is somewhat different than OpenGL. Nothing major, just different.
Until WWDC'18, using GLKit
, including GLKView
, was fine. But all things OpenGL were depricated, and Apple is moving things to Metal. While the performance gain (for now) isn't that great, you may be best off for something new to use MTKView, Metal, and CIContext`.
Look at the answer @matt gave here for a nice way to use MTKViews.
Related Topics
Bypass Code Signing with Xcode 6
Why Is a Https Nsurlsession Connection Only Challenged Once Per Domain
How to Get Index(Of:) to Return Multiple Indices
How to Localize Label Strings in iOS for a Beginner
How to Create Scrollable Table in Skspritekit
iOS Facebook Sdk 3.1 Retrieve Friend Birthday Returning Null
Add Custom Cordova Plugin to Ibm Worklight 6.1
Odd Property Declaration Syntax Containing Angular Brackets <>
Ciimage Display Mtkview VS Glkview Performance
Ble Device Keep Connect with iPhone When Application Terminate
Using Uisheetpresentationcontroller in Swiftui
Uiapplicationlaunchoptionsremotenotificationkey Not Getting Userinfo
Download PDF and Save to the "Files" in Iphone, Not to the App Data, Swift
Storing [Nsnull Null] Values in Nsuserdefaults, from JSON Serialization, Causes Unwanted Exceptions
Convert Spelled Out Number to Number