티스토리 뷰

Metal Resources
- MTLBuffer : 모든 데이터 타입을 포함하 ㄹ수 있는 unformatted 메모리 할당
- MTLTexture : formatted 이미지 데이터 할당
Argument Table
Shader Parameters와 Resources 사이의 매핑 (Encoder와 Shader 사이의 연결)
- Buffers
- Textures
- Sampler states
Buffer
Buffer 생성
makeBuffer(length:options:)
makeBuffer(bytes:length:options:)
makeBuffer(bytesNoCopy:length:options:deallocator:)
MTLVertexDescriptor
vertexDescriptor.attributes[0].offset = 0
vertexDescriptor.attributes[0].format = .float3 // position
vertexDescriptor.attributes[1].offset = 12
// Vertex normal
vertexDescriptor.attributes[1].format = MTLVertexFormat.float3
vertexDescriptor.layouts[0].stride = 24
let pipelineStateDescriptor = MTLRenderPipelineDescriptor()
pipelineStateDescriptor.vertexDescriptor = vertexDescriptor
Texture
Texture 생성
newTextureWithDescriptor
makeTextureView(pixelFormat:)
newTextureWithDescriptor:offset:bytesPerRow
MTKTextureLoader로 이미지 데이터 로드
if let textureUrl = NSURL(string: fileLocation) {
let textureLoader = MTKTextureLoader(device: device)
do {
diffuseTexture = try textureLoader.newTextureWithContentsOfURL(textureUrl, options: nil)
} catch _ {
print("diffuseTexture assignment failed")
}
}
Texture 카피
func getBytes(_ pixelBytes: UnsafeMutableRawPointer,
bytesPerRow: Int,
from region: MTLRegion,
mipmapLevel level: Int)
func replace(region: MTLRegion,
mipmapLevel level: Int,
slice: Int,
withBytes pixelBytes: UnsafeRawPointer,
bytesPerRow: Int,
bytesPerImage: Int)
MTLBlitCommandEncoder
한 위치에서 다른 위치로 데이터 복사
func copy(from sourceBuffer: MTLBuffer,
sourceOffset: Int,
to destinationBuffer: MTLBuffer,
destinationOffset: Int,
size: Int)
func copy(from sourceBuffer: MTLBuffer,
sourceOffset: Int,
sourceBytesPerRow: Int,
sourceBytesPerImage: Int,
sourceSize: MTLSize,
to destinationTexture: MTLTexture,
destinationSlice: Int,
destinationLevel: Int,
destinationOrigin: MTLOrigin)
'iOS > Metal' 카테고리의 다른 글
Metal 좌표계 (0) | 2022.01.26 |
---|---|
Metal: Texturing and Sampling (0) | 2022.01.07 |
Metal: MetalKit (0) | 2022.01.07 |
Metal: Shader (0) | 2022.01.07 |
Metal: MTLTexture to CIImage 변경 시 rgb값 그대로 가져오기 (0) | 2022.01.06 |