setTexture method

void setTexture(
  1. String name,
  2. Object? texture, {
  3. SamplerOptions? sampler,
  4. ShaderStage stage = ShaderStage.fragment,
})

Assign a texture to a sampler uniform by name.

texture accepts a raw gpu.Texture (the low-level custom-shader path), a Texture2D, or a RenderTexture (sampled live; an explicit sampler overrides the source's own sampling). Pass null to clear the binding.

Implementation

void setTexture(
  String name,
  Object? texture, {
  gpu.SamplerOptions? sampler,
  ShaderStage stage = ShaderStage.fragment,
}) {
  final textures = _texturesFor(stage);
  if (texture == null) {
    textures.remove(name);
    return;
  }
  if (texture is! gpu.Texture && texture is! TextureSource) {
    throw ArgumentError.value(
      texture,
      'texture',
      'Expected a gpu.Texture, a Texture2D, or a RenderTexture',
    );
  }
  textures[name] = _BoundTexture(texture, sampler);
}