git.iko.soy/metal-metaballs
on master help sign in
Sent most of the rendering work into an async queue.
commit175f901279a59a5e5bd114a5150d6b24f2c3e2d5 authorvinivendra <vinivendra@gmail.com> dateWed 10 Feb 2016, 16:44 (11 years ago) parentaeab9fc
1 file changed+13−9
PixelImage/MetalMetaballRenderer.swift+13−9
PixelImage/MetalMetaballRenderer.swift+13−9
@@ -1,5 +1,3 @@
1−// TODO: Refactor update into 2 calls: metalRendering() and textureToImage()
2−// TODO: Use async dispatch to free up main queue
31// TODO: Use two textures/images to alternate the 2 calls (like OpenGL double buffers)
42
53// TODO: Make graphics have edges only according to graph (instead of being a complete graph)
@@ -36,18 +34,24 @@ class MetalMetaballRenderer: MetaballRenderer {
3634 func updateTargetView() {
3735 let metaballs = dataSource.metaballs
3836
39− // Re-alloc buffers if frame has changed
37+ // Re-alloc buffers if the size has changed
4038 if previousSize != targetView.size {
4139 previousSize = targetView.size
4240 updateFrame()
4341 }
4442
45− // Render graphics to metal texture
46− renderToRenderingTexture(metaballs: metaballs)
47− // Transform metal texture into image
48− let uiimage = image(texture: renderingTexture)
49− // Send image to view
50− targetView.image = uiimage
43+ dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)) { () -> Void in
44+
45+ // Render graphics to metal texture
46+ self.renderToRenderingTexture(metaballs: metaballs)
47+ // Transform metal texture into image
48+ let uiimage = self.image(texture: self.renderingTexture)
49+
50+ dispatch_async(dispatch_get_main_queue(), { () -> Void in
51+ // Send image to view
52+ self.targetView.image = uiimage
53+ })
54+ }
5155 }
5256
5357 func renderToRenderingTexture(metaballs metaballs: [Metaball]) {