Retrieve a backend specific sampler object for the given sampler descriptor.
If the descriptor is invalid or there is a loss of rendering context, this method may return a nullptr.
The sampler library implementations must cache this sampler object and guarantee that the reference will continue to be valid throughout the lifetime of the Impeller context.
19 {
20 auto found = samplers_.find(descriptor);
21 if (found != samplers_.end()) {
22 return found->second;
23 }
24 if (!device_) {
26 }
27 auto desc = [[MTLSamplerDescriptor alloc]
init];
34 if (@available(iOS 14.0, macos 10.12, *)) {
35 desc.borderColor = MTLSamplerBorderColorTransparentBlack;
36 }
37 if (!descriptor.label.empty()) {
38 desc.label = @(descriptor.label.c_str());
39 }
40
41 auto mtl_sampler = [device_ newSamplerStateWithDescriptor:
desc];
42 if (!mtl_sampler) {
44 }
45 auto sampler =
46 std::unique_ptr<SamplerMTL>(new SamplerMTL(descriptor, mtl_sampler));
47
48 return (samplers_[descriptor] = std::move(sampler));
49}
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)
static const std::unique_ptr< const Sampler > kNullSampler