问题描述
我目前正在为游戏制作简单的UI,绘制每个按钮需要使用2个管线状态(每个都使用相同的顶点着色器).一种是使用静态颜色片段着色器绘制边框的线条,另一种是使用波纹渐变绘制按钮的内部.我想知道是否需要两种不同的渲染命令编码器,每条管道一个,或者是否可以执行以下操作:
I'm currently making simple UI for a game, and to draw each of the buttons I need to use 2 pipeline states (same vertex shader for each). One to draw a line strip for the border, with a static color fragment shader, and one to draw the inside of the button with a rippling gradient. I'm wondering if I need two different render command encoders, one per pipeline, or if I can do the following:
let encoder = command.makeRenderCommandEncoder(descriptor: renderPassDesc)
encoder.setRenderPipelineState(stateWithStaticFragmentShader)
// encode some buffers and draw line-strips
encoder.setRenderPipelineState(stateWithGradientFragmentShader)
// encode some buffers and draw button background
encoder.endEncoding()
推荐答案
是的,您可以在一个渲染命令编码器中使用多个管道状态.这就是setRenderPipelineState()
方法存在的原因,而不是管道状态成为渲染过程描述符的一部分的原因.渲染过程描述符中的属性仅在创建渲染命令编码器时读取,并且在该编码器的生命周期内无法更改.在编码器上可以独立设置的任何内容都可以在其使用期限内进行更改.
Yes, you can use multiple pipeline states in one render command encoder. That's precisely why the setRenderPipelineState()
method exists, rather than the pipeline state being part of the render pass descriptor. The properties in the render pass descriptor are only read at the time of the creation of the render command encoder and can't be changed during the lifetime of that encoder. Anything which is independently settable on the encoder can be changed during its lifetime.
这篇关于我可以在一个MTLRenderCommandEncoder中使用多个MTLRenderPipelineStates吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!