Animation rendering updates

This commit is contained in:
Ali
2022-02-11 23:49:58 +04:00
parent c8bc4b7f12
commit 05a0d399dd
6 changed files with 228 additions and 217 deletions

View File

@@ -131,17 +131,12 @@ final class Texture {
}
}
func readDirect(width: Int, height: Int, bytesPerRow: Int, read: (UnsafeMutableRawPointer, Int) -> Void) {
func readDirect(width: Int, height: Int, bytesPerRow: Int, read: (UnsafeMutableRawPointer?) -> UnsafeRawPointer) {
if let directBuffer = self.directBuffer, width == self.width, height == self.height, bytesPerRow == directBuffer.bytesPerRow {
read(directBuffer.buffer.contents(), directBuffer.buffer.length)
let _ = read(directBuffer.buffer.contents())
} else {
var tempData = Data(count: height * bytesPerRow)
tempData.withUnsafeMutableBytes { bytes in
read(bytes.baseAddress!, height * bytesPerRow)
let region = MTLRegion(origin: MTLOrigin(x: 0, y: 0, z: 0), size: MTLSize(width: width, height: height, depth: 1))
self.texture.replace(region: region, mipmapLevel: 0, withBytes: bytes.baseAddress!, bytesPerRow: bytesPerRow)
}
let region = MTLRegion(origin: MTLOrigin(x: 0, y: 0, z: 0), size: MTLSize(width: width, height: height, depth: 1))
self.texture.replace(region: region, mipmapLevel: 0, withBytes: read(nil), bytesPerRow: bytesPerRow)
}
}
}