티스토리 뷰

iOS/Metal

Metal: Metal Resources

0zerohyun 2022. 1. 7. 15:30

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함