Table of Contents

资源绑定

高级 程序员

在使用效果绘制顶点时,着色器期望某些资源可用,包括:

  • 纹理和缓冲区
  • 采样器
  • 常量缓冲区

自动资源绑定

@'Stride.Rendering.EffectInstance' 类负责从已加载的效果中枚举这些资源以及绑定它们的细节。

它暴露了 @'Stride.Graphics.RootSignature',该对象必须作为管线状态设置; 它还允许基于 @'Stride.Rendering.ParameterCollection' 填充常量缓冲区并绑定资源。

**代码:**使用 EffectInstance

// 创建 EffectInstance 并用它设置管线
var effectInstance = new EffectInstance(EffectSystem.LoadEffect("MyEffect").WaitForResult());
pipelineStateDescription.EffectBytecode = effectInstance.Effect.Bytecode;
pipelineStateDescription.RootSignature = effectInstance.RootSignature;

// 更新常量缓冲区并绑定资源
effectInstance.Apply(context.GraphicsContext);

手动资源绑定

当需要更优化的代码时(例如在渲染管线中),可以手动完成常量缓冲区更新和资源绑定。