diff --git a/core/renderer/backend/Types.h b/core/renderer/backend/Types.h index a19455f4896..f1433922e7e 100644 --- a/core/renderer/backend/Types.h +++ b/core/renderer/backend/Types.h @@ -46,6 +46,9 @@ inline TargetBufferFlags getMRTColorFlag(size_t index) noexcept typedef TargetBufferFlags ClearFlag; +/// @note In Metal, mipmap filter is derived from `magFilter` value: ie `NEAREST_MIPMAP_LINEAR` and +/// `LINEAR_MIPMAP_LINEAR` will select `LINEAR` filter, while `NEAREST_MIPMAP_NEAREST` and +/// `LINEAR_MIPMAP_NEAREST` will select `NEAREST` filter. struct SamplerDescriptor { SamplerFilter magFilter = SamplerFilter::LINEAR; diff --git a/core/renderer/backend/metal/TextureMTL.mm b/core/renderer/backend/metal/TextureMTL.mm index 042d820b3c2..d142cde5745 100644 --- a/core/renderer/backend/metal/TextureMTL.mm +++ b/core/renderer/backend/metal/TextureMTL.mm @@ -32,7 +32,7 @@ of this software and associated documentation files (the "Software"), to deal namespace { -MTLSamplerAddressMode toMTLSamplerAddressMode(SamplerAddressMode mode) +static MTLSamplerAddressMode toMTLSamplerAddressMode(SamplerAddressMode mode) { MTLSamplerAddressMode ret = MTLSamplerAddressModeRepeat; switch (mode) @@ -53,7 +53,7 @@ MTLSamplerAddressMode toMTLSamplerAddressMode(SamplerAddressMode mode) return ret; } -MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(SamplerFilter mode) +static MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(SamplerFilter mode) { switch (mode) { @@ -70,7 +70,22 @@ MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(SamplerFilter mode) } } -bool isColorRenderable(PixelFormat textureFormat) +static MTLSamplerMipFilter toMTLSamplerMipFilter(SamplerFilter mode) +{ + switch (mode) + { + case SamplerFilter::NEAREST_MIPMAP_LINEAR: + case SamplerFilter::LINEAR_MIPMAP_LINEAR: + return MTLSamplerMipFilterLinear; + case SamplerFilter::NEAREST_MIPMAP_NEAREST: + case SamplerFilter::LINEAR_MIPMAP_NEAREST: + return MTLSamplerMipFilterNearest; + default: + return MTLSamplerMipFilterNotMipmapped; + } +} + +static bool isColorRenderable(PixelFormat textureFormat) { switch (textureFormat) { @@ -168,6 +183,8 @@ bool isColorRenderable(PixelFormat textureFormat) descriptor.minFilter == SamplerFilter::DONT_CARE ? _minFilter : toMTLSamplerMinMagFilter(descriptor.minFilter); mtlDescriptor.magFilter = descriptor.magFilter == SamplerFilter::DONT_CARE ? _magFilter : toMTLSamplerMinMagFilter(descriptor.magFilter); + mtlDescriptor.mipFilter = + descriptor.magFilter == SamplerFilter::DONT_CARE ? _mipFilter : toMTLSamplerMipFilter(descriptor.magFilter); if (_mtlSamplerState) {