首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在金属中使用stride类似于openGL

在金属中使用stride类似于openGL
EN

Stack Overflow用户
提问于 2018-10-11 16:25:29
回答 1查看 304关注 0票数 0

我有一个缓冲区,顶点有一个步幅。如何在金属中指定这一点?我似乎找不到任何例子。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2018-10-11 22:57:55

请查看MTLRenderPipelineDescriptor的一部分MTLVertexBufferLayoutDescriptor。它有stride成员。

下面是以交错方式设置存储在一个顶点缓冲区中的三个顶点属性的示例。在end:vertexDescriptor.layouts[0].stride = 32;旁边设置stride

代码语言:javascript
复制
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;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52755519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档