如果我在Metal / Swift中运行以下顶点着色器,我会在屏幕上看到一个漂亮的矩形:
vertex Vertex vertexShader(uint k [[ vertex_id ]],
device float2* position [[buffer(1)]]){
Vertex output;
float2 pos = position[k];
output.position = float4(pos,0,1);
return output;
};
//position [0.0, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.5]
//indexList [0, 1, 2, 2, 1, 3]
现在,如果我运行以下操作,我会看到一个空白屏幕:
vertex Vertex vertexShader(uint k [[ vertex_id ]],
device float3* position [[buffer(1)]]){
Vertex output;
float3 pos = position[k];
output.position = float4(pos,1);
return output;
};
//position [0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.0]
//indexList [0, 1, 2, 2, 1, 3]
在我看来,这些应该产生相同的结果。我错过了什么?
答案 0 :(得分:1)
您在应用代码中填写与索引1相关联的缓冲区到底是怎么回事?
我怀疑你只是提供一系列花车。好吧,float3
没有打包。它的布局与3 float
不同。有填充。它的大小实际上与float4
或4 float
s相同。
最简单的解决方法可能是将position
声明为指向packed_float3
的指针。