I have a Metal texture, I want to access its data from Swift by making it a float4 array (so that I can access each pixel 4 color components).
I discovered this method
extension UnsafeMutableRawPointer {
func toArray(to type: T.Type, capacity count: Int) -> [T]{
let pointer = bindMemory(to: type, capacity: count)
return Array(UnsafeBufferPointer(start: pointer, count: count))
}
}
var array = [1,2,3,4,5]
let ponter = UnsafeMutableRawPointer(mutating: array)
print(ponter.toArray(to: Int.self, capacity: array.count))