bindTexture method
Implementation
void bindTexture(
UniformSlot slot,
Texture texture, {
SamplerOptions? sampler,
}) {
if (sampler == null) {
sampler = SamplerOptions();
}
assert(() {
if (texture.storageMode == StorageMode.deviceTransient) {
throw Exception(
"Textures with StorageMode.deviceTransient cannot be bound to a RenderPass",
);
}
return true;
}());
if (sampler.maxAnisotropy < 1) {
throw Exception("SamplerOptions.maxAnisotropy must be at least 1");
}
if (sampler.maxAnisotropy > 1 &&
(sampler.minFilter != MinMagFilter.linear ||
sampler.magFilter != MinMagFilter.linear ||
sampler.mipFilter != MipFilter.linear)) {
throw Exception(
"When SamplerOptions.maxAnisotropy is greater than 1, minFilter, "
"magFilter, and mipFilter must all be linear",
);
}
bool success = _bindTexture(
slot.shader,
slot.uniformName,
texture,
sampler.minFilter.index,
sampler.magFilter.index,
sampler.mipFilter.index,
sampler.widthAddressMode.index,
sampler.heightAddressMode.index,
sampler.maxAnisotropy,
);
if (!success) {
throw Exception("Failed to bind texture");
}
}