diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2020-03-11 18:59:58 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2020-03-11 18:59:58 +0100 |
commit | b6388b5101d8187f746f91c89842e932a1d01cb6 (patch) | |
tree | 70bd9ba7012f5906db01b485ec8f58f5a4697240 /minilibx_beta/mlx_image.swift | |
parent | close but no cigar (diff) | |
parent | ca tue (diff) | |
download | 42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.gz 42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.bz2 42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.xz 42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.tar.zst 42-cub3d-b6388b5101d8187f746f91c89842e932a1d01cb6.zip |
get merged
Diffstat (limited to '')
-rw-r--r-- | minilibx_beta/mlx_image.swift | 48 | ||||
-rw-r--r-- | minilibx_beta/mlx_image.swiftdoc | bin | 0 -> 532 bytes | |||
-rw-r--r-- | minilibx_beta/mlx_image.swiftmodule | bin | 0 -> 32172 bytes |
3 files changed, 48 insertions, 0 deletions
diff --git a/minilibx_beta/mlx_image.swift b/minilibx_beta/mlx_image.swift new file mode 100644 index 0000000..7c1fa9b --- /dev/null +++ b/minilibx_beta/mlx_image.swift @@ -0,0 +1,48 @@ + + +import Metal + + +public class MlxImg +{ + public var texture: MTLTexture +/// var texture_buff: MTLBuffer + + public var texture_sizeline: Int + public var texture_data: UnsafeMutablePointer<UInt32> + public var texture_width: Int + public var texture_height: Int + + public var onGPU = 0 + + convenience public init(d device:MTLDevice, w width:Int, h height:Int) + { + self.init(d:device, w:width, h:height, t:0) + } + + public init(d device:MTLDevice, w width:Int, h height:Int, t target:Int) + { + texture_width = width + texture_height = height + texture_sizeline = width * 4 + texture_sizeline = 256 * (texture_sizeline / 256 + (texture_sizeline%256 >= 1 ? 1 : 0) ) + + let textureDesc = MTLTextureDescriptor() + textureDesc.width = texture_width + textureDesc.height = texture_height + textureDesc.usage = .shaderRead + if (target == 1) + { + textureDesc.usage = .renderTarget + textureDesc.storageMode = .private + } + textureDesc.pixelFormat = MTLPixelFormat.bgra8Unorm + let texture_buff = device.makeBuffer(length: texture_sizeline * height)! + texture = texture_buff.makeTexture(descriptor:textureDesc, offset:0, bytesPerRow:texture_sizeline)! + + let tmpptr = texture_buff.contents() + texture_data = tmpptr.assumingMemoryBound(to:UInt32.self) + } + + +}
\ No newline at end of file diff --git a/minilibx_beta/mlx_image.swiftdoc b/minilibx_beta/mlx_image.swiftdoc Binary files differnew file mode 100644 index 0000000..f13ee3f --- /dev/null +++ b/minilibx_beta/mlx_image.swiftdoc diff --git a/minilibx_beta/mlx_image.swiftmodule b/minilibx_beta/mlx_image.swiftmodule Binary files differnew file mode 100644 index 0000000..4d4ce55 --- /dev/null +++ b/minilibx_beta/mlx_image.swiftmodule |