bind method

void bind(
  1. RenderPass pass,
  2. HostBuffer transientsBuffer,
  3. EnvironmentMap environment
)

Binds the fragment's uniform blocks, textures, and (when useEnvironment) the environment IBL samplers. Called by the engine during the background draw; not part of the app-facing API.

Implementation

void bind(
  gpu.RenderPass pass,
  gpu.HostBuffer transientsBuffer,
  EnvironmentMap environment,
) {
  for (final entry in _uniformBlocks.entries) {
    pass.bindUniform(
      fragmentShader.getUniformSlot(entry.key),
      transientsBuffer.emplace(entry.value),
    );
  }
  for (final entry in _textures.entries) {
    pass.bindTexture(
      fragmentShader.getUniformSlot(entry.key),
      entry.value.texture,
      sampler: entry.value.sampler ?? gpu.SamplerOptions(),
    );
  }
  if (useEnvironment) {
    EngineLightingUniforms.bindPrefilteredRadiance(
      pass,
      fragmentShader,
      environment,
    );
    pass.bindTexture(
      fragmentShader.getUniformSlot('brdf_lut'),
      Material.getBrdfLutTexture(),
      sampler: gpu.SamplerOptions(
        minFilter: gpu.MinMagFilter.linear,
        magFilter: gpu.MinMagFilter.linear,
        widthAddressMode: gpu.SamplerAddressMode.clampToEdge,
        heightAddressMode: gpu.SamplerAddressMode.clampToEdge,
      ),
    );
  }
}