我正在尝试使用二维数组纹理在Metal中,通过查阅网络上的资料,我已经成功初始化了我的纹理数组。但是现在,在将纹理与myEncoder.setFragmentTexture(myTextureArray, index: myIndex)
绑定后,出现了一个错误,我无法继续。
Failed assertion `Fragment Function(basicFragment): incorrect type of
texture (MTLTextureType2DArray) bound at texture binding at index 0
(expect MTLTextureType2D) for texture[0].
我不知道在这里做错了什么,不幸的是谷歌也不知道。我想我需要调用一个特定的函数来绑定一个数组纹理,而不是用于绑定普通纹理的那个函数(setFragmentTexture
),或者我可能会神秘地将我的纹理类型设置为单个2D纹理,而不允许设置纹理数组?所以我的问题是:
如何适当地在Metal中绑定我的纹理数组?
编辑:
我的片段着色器:
fragment float4 basicFragment(VertexOut vertexOut [[ stage_in ]],
texture2d<float> texture [[ texture(0) ]],
sampler sampler2D [[ sampler(0) ]])
{
return texture.sample(sampler2D, vertexOut.texCoord, vertexOut.slice);
}