git.iko.soy/metal-metaballs
on master help sign in
Refactored function sugnatures to support using two contexts.
82d0808vinivendra
PixelImage/MetalMetaballRenderer.swift+4−5
@@ -1,4 +1,3 @@
1−// TODO: Create compute context to contain texture and imageBuffer
2// TOOD: Use two compute contexts and double recursion
1// TOOD: Use two compute contexts and double recursion
3
2
4// TODO: Make graphics have edges only according to graph (instead of being a complete graph)
3// TODO: Make graphics have edges only according to graph (instead of being a complete graph)
@@ -60,10 +59,10 @@ class MetalMetaballRenderer: MetaballRenderer {
60 dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)) { () -> Void in
59 dispatch_async(dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)) { () -> Void in
61
60
62 // Render graphics to metal texture
61 // Render graphics to metal texture
63− self.renderToRenderingTexture()
62+ self.renderToContext(shouldUsePrimaryContext: true)
64
63
65 // Transform metal texture into image
64 // Transform metal texture into image
66− let uiimage = self.createImageFromTexture()
65+ let uiimage = self.createImageFromContext(shouldUsePrimaryContext: true)
67
66
68 dispatch_async(dispatch_get_main_queue(), { () -> Void in
67 dispatch_async(dispatch_get_main_queue(), { () -> Void in
69 // Send image to view
68 // Send image to view
@@ -78,7 +77,7 @@ class MetalMetaballRenderer: MetaballRenderer {
78 }
77 }
79 }
78 }
80
79
81− func renderToRenderingTexture() {
80+ func renderToContext(shouldUsePrimaryContext shouldUsePrimaryContext: Bool) {
82 let width = Int(targetView.width)
81 let width = Int(targetView.width)
83 let height = Int(targetView.height)
82 let height = Int(targetView.height)
84
83
@@ -122,7 +121,7 @@ class MetalMetaballRenderer: MetaballRenderer {
122 }
121 }
123 }
122 }
124
123
125− func createImageFromTexture() -> UIImage {
124+ func createImageFromContext(shouldUsePrimaryContext shouldUsePrimaryContext: Bool) -> UIImage {
126 let texture = computeContext.texture
125 let texture = computeContext.texture
127
126
128 // Get image info
127 // Get image info