나는 iOS/OSX 용 메탈을 배우기 시작했고, 나는 레이 웬델 리치 (Ray Wenderlich) 튜토리얼 (https://www.raywenderlich.com/146414/metal-tutorial-swift-3-part-1-getting-started)을 따라 시작했다. 이 자습서는 잘 작동하지만 MTLVertexAttributeDescriptors에 대한 언급이 없습니다.MTLVertexAttributeDescriptors가 필요합니까? 왜 그들이 필요합니까?
이제 내 자신의 앱을 개발하고 있는데 이상한 결함이 생기고 MTLVertexAttributeDescriptors를 사용하지 않는다는 사실이 문제와 관련이 있는지 궁금해하고 있습니다.
그들은 어떤 차이가 있습니까? 다양한 버텍스 구조를 가진 다양한 쉐이더를 만들 수 있었고 이런 것들을 전혀 알지 못했습니다.
셰이더에서 사용하기 위해 꼭지점 구성 요소의 레이아웃을 설명하는 데 사용하는 것으로 알고 있습니다. 예를 들어 셰이더는이 구조체를 정점에 사용할 수 있으며, 아래 기능의 정점 설명자에 설정됩니다.
typedef struct
{
float3 position [[attribute(T_VertexAttributePosition)]];
float2 texCoord [[attribute(T_VertexAttributeTexcoord)]];
} Vertex;
class func buildMetalVertexDescriptor() -> MTLVertexDescriptor {
let mtlVertexDescriptor = MTLVertexDescriptor()
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].format = MTLVertexFormat.float3
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].offset = 0
mtlVertexDescriptor.attributes[T_VertexAttribute.position.rawValue].bufferIndex = T_BufferIndex.meshPositions.rawValue
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].format = MTLVertexFormat.float2
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].offset = 0
mtlVertexDescriptor.attributes[T_VertexAttribute.texcoord.rawValue].bufferIndex = T_BufferIndex.meshGenerics.rawValue
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stride = 12
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stepRate = 1
mtlVertexDescriptor.layouts[T_BufferIndex.meshPositions.rawValue].stepFunction = MTLVertexStepFunction.perVertex
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stride = 8
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stepRate = 1
mtlVertexDescriptor.layouts[T_BufferIndex.meshGenerics.rawValue].stepFunction = MTLVertexStepFunction.perVertex
return mtlVertexDescriptor
}
그러나 심지어 MTLVertexDescriptor 설치없이
는 쉐이더 이미 배열 정점의 정점 버퍼 위치/TEXCOORD 요소를 액세스 할 수있다. 정점 버퍼를 설정하는 것만으로 셰이더는 모든 구성 요소에 액세스 할 수 있습니다. 그러면 디스크립터는 어떤 점에서 좋은 점이 있습니까?
감사합니다. [[stage_in]] 구문과 [[buffer]] 구문의 차이점에 대해 궁금합니다. 불행히도 이것은 또한 꼭지점 기술자의 부족이 아마도 글리치가 발생하지 않는다는 것을 의미합니다. – bsabiston