commandBuffer | 指定要执行的命令缓冲区。 |
安排自定义图形命令缓冲区的执行。
在调用 ScriptableRenderContext.ExecuteCommandBuffer 期间,ScriptableRenderContext 将 commandBuffer 参数注册到其自己的内部命令执行列表中。这些命令(包括存储在自定义 commandBuffer 中的命令)的实际执行发生在 ScriptableRenderContext.Submit 期间。
如果您的绘制调用依赖于您在 CommandBuffer 中指定的管线状态,请确保在其他 ScriptableRenderContext 方法(例如 DrawRenderers、DrawShadows)之前调用 ExecuteCommandBuffer。下面的代码示例说明了命令以错误顺序提交的情况;以及预期行为的情况
using UnityEngine; using UnityEngine.Rendering;
internal class ExecuteCommandBufferExample { // TODO: replace with actual settings ScriptableRenderContext scriptableRenderContext; DrawingSettings drawingSettings; CullingResults cullingResults = new CullingResults(); FilteringSettings filteringSettings = new FilteringSettings();
Matrix4x4 myViewMatrix = Matrix4x4.Scale(new Vector3(2f, 2f, 2f));
public void DrawRenderersExampleIncorrect() { CommandBuffer myCommandBuffer = new CommandBuffer();
myCommandBuffer.SetViewMatrix(myViewMatrix);
scriptableRenderContext.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings); // NO! When scriptableRenderContext submits the DrawRenderers command, it will not know about myViewMatrix :(
scriptableRenderContext.ExecuteCommandBuffer(myCommandBuffer); myCommandBuffer.Clear(); }
public void DrawRenderersExampleBetter() { CommandBuffer myCommandBuffer = new CommandBuffer();
myCommandBuffer.SetViewMatrix(myViewMatrix);
scriptableRenderContext.ExecuteCommandBuffer(myCommandBuffer); myCommandBuffer.Clear();
scriptableRenderContext.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings); // OK! During next scriptableRenderContext.Submit() call, scriptableRenderContext will set myViewMatrix *before* drawing the renderers. } }
其他资源:CommandBuffer。