我有一个缓冲区,顶点有一个跨步。如何在金属中指定?我似乎找不到任何例子。 谢谢!
答案 0 :(得分:1)
签出MTLVertexBufferLayoutDescriptor,它是MTLRenderPipelineDescriptor的一部分。它具有stride
成员。
以下是以交错方式设置存储在一个顶点缓冲区中的三个顶点属性的示例。 stride
设置在末尾:vertexDescriptor.layouts[0].stride = 32;
MTLRenderPipelineDescriptor *pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
MTLVertexDescriptor *vertexDescriptor = [MTLVertexDescriptor vertexDescriptor];
vertexDescriptor.attributes[0].offset = 0;
vertexDescriptor.attributes[0].format = MTLVertexFormatFloat3; // position
vertexDescriptor.attributes[0].bufferIndex = 0;
vertexDescriptor.attributes[1].offset = 12;
vertexDescriptor.attributes[1].format = MTLVertexFormatFloat3; // normal
vertexDescriptor.attributes[1].bufferIndex = 0;
vertexDescriptor.attributes[2].offset = 24;
vertexDescriptor.attributes[2].format = MTLVertexFormatFloat2; // texCoords
vertexDescriptor.attributes[2].bufferIndex = 0;
vertexDescriptor.layouts[0].stepRate = 1;
vertexDescriptor.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
vertexDescriptor.layouts[0].stride = 32;
pipelineDescriptor.vertexDescriptor = vertexDescriptor;