当我绘制时我的代码可以工作MTLTexture
with rgba32Float
像素格式,我可以采取CVPixelBuffer
出来了。
But FlutterTexture
需要bgra8Unorm
格式。我不想转换CVPixelBuffer
由于性能开销。
所以我试图渲染MTLTexture
with bgra8Unorm
像素格式,但以下片段着色器代码将无法编译:
fragment vector_uchar4 fragmentShader2(Vertex interpolated [[stage_in]]) {
return 0xFFFFFFFF;
}
有错误:Invalid return type 'vector_uchar4' for fragment function
我尝试将其替换为uint
类型,但它因错误而崩溃:
Fatal error: 'try!' expression unexpectedly raised an error:
Error Domain=AGXMetalA11 Code=3
"output of type uint is not compatible with a MTLPixelFormatBGRA8Unorm color attachement."
UserInfo={NSLocalizedDescription=output of type uint is not compatible with a MTLPixelFormatBGRA8Unorm color attachement.}
如果我使用vector_float4
or vector_half4
返回类型我的纹理和缓冲区为空。
我必须使用哪种返回类型bgra8Unorm
像素格式并获得非空图像?金属有可能吗?
我在第30页找到了答案金属着色语言规范 https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf
最后这段代码按预期绘制图像:
fragment float4 fragmentShader2(Vertex interpolated [[stage_in]]) {
// ...
rgba8unorm<float4> rgba;
rgba = float4(color.r, color.g, color.b, 1.0);
return rgba;
}
如果有人可以解释幕后发生的事情,我真的不想浪费赏金。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)