In my old tutorial , working with Metal
I have:
var labColorBuffer:MTLBuffer!
labColorBuffer = self.device.makeBuffer(length: 4 * MemoryLayout<Float>.size, options: [])
labColorBuffer.label = "labColors"
to update the date, I had these settings:
let pData = labColorBuffer.contents()
let vData = UnsafeMutablePointer<Float>(pData)
vData[0] = 0.250
vData[1] = 0.250
vData[2] = 0.250
vData[3] = 0.250
Now in my new version:
let pData = labColorBuffer.contents() // returns UnsafeMutableRawPointer
you better do it this way
let pData = labColorBuffer.contents()
pData.initializeMemory(as: Float.self, count: 0, to: 0.250)
pData.initializeMemory(as: Float.self, count: 1, to: 0.250)
pData.initializeMemory(as: Float.self, count: 2, to: 0.250)
pData.initializeMemory(as: Float.self, count: 3, to: 0.250)
or this :
func initRawABCD() -> UnsafeMutableRawPointer {
let intPtr = UnsafeMutablePointer<Float>.allocate(capacity: 4)
intPtr[0] = 0.250 /
intPtr[1] = 0.250 /
intPtr[2] = 0.250 /
intPtr[3] = 0.250 /
return UnsafeMutableRawPointer(intPtr)
}
labColorBuffer = self.device.makeBuffer(bytes: initRawABCD(), length: MemoryLayout<Float>.size(ofValue: 4), options: [])
also you need deinitialize ?
thanks for your cooperation