Skip to content

Commit

Permalink
Metal: enable mipmap support (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
smilediver authored Nov 15, 2024
1 parent f03efb8 commit 502961d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions core/renderer/backend/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions core/renderer/backend/metal/TextureMTL.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -53,7 +53,7 @@ MTLSamplerAddressMode toMTLSamplerAddressMode(SamplerAddressMode mode)
return ret;
}

MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(SamplerFilter mode)
static MTLSamplerMinMagFilter toMTLSamplerMinMagFilter(SamplerFilter mode)
{
switch (mode)
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 502961d

Please sign in to comment.