Параметры
commandBuffer | Указывает командный буфер для выполнения. |
Описание
Планирует выполнение пользовательского графического командного буфера.
Во время вызова ScriptableRenderContext.ExecuteCommandBuffer ScriptableRenderContext регистрирует параметр commandBuffer в своем внутреннем список команд для выполнения. Фактическое выполнение этих команд (включая команды, хранящиеся в пользовательском командном буфере) происходит во время ScriptableRenderContext.Submit.
Убедитесь, что вы вызываете ExecuteCommandBuffer перед другими методами ScriptableRenderContext (такими как DrawRenderers, DrawShadows), если ваши вызовы отрисовки зависят от состояния конвейера, указанного вами в CommandBuffer. Пример кода ниже иллюстрирует случай, когда команды отправляются в неправильном порядке; за которым следует случай, который ведет себя так, как ожидалось:
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.