当我MTLTexture
使用rgba32Float
像素格式绘制代码时,我的代码可以工作,然后可以将其CVPixelBuffer
取出。
但是FlutterTexture
需要bgra8Unorm
格式。CVPixelBuffer
由于性能开销,我不想进行转换。
因此,我尝试MTLTexture
使用bgra8Unorm
像素格式进行渲染,但是以下片段着色器代码无法编译:
fragment vector_uchar4 fragmentShader2(Vertex interpolated [[stage_in]]) {
return 0xFFFFFFFF;
}
错误:Invalid return type 'vector_uchar4' for fragment function
我尝试用uint
type替换它,但是由于错误而崩溃:
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
或vector_half4
返回类型,则我的纹理和缓冲区为空。
我必须将哪种返回类型用于bgra8Unorm
像素格式并获取非空图像?金属有可能吗?
我已经在“金属底纹语言”规范的第30页上找到了答案
最后,此代码按预期绘制图像:
fragment float4 fragmentShader2(Vertex interpolated [[stage_in]]) {
// ...
rgba8unorm<float4> rgba;
rgba = float4(color.r, color.g, color.b, 1.0);
return rgba;
}
如果有人可以解释幕后发生的事情,我真的很想不浪费金钱。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句