Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metal: enable mipmap support #2235

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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