From e27ade5aee71eb6e801876c0c6cde7d238a23d1e Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 27 Jun 2024 00:20:00 +0100 Subject: [PATCH] Add constrained border colours to samplers (#26) --- src/Ryujinx.Graphics.Metal/Sampler.cs | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/Sampler.cs b/src/Ryujinx.Graphics.Metal/Sampler.cs index 9f8ae74b4..7930627d4 100644 --- a/src/Ryujinx.Graphics.Metal/Sampler.cs +++ b/src/Ryujinx.Graphics.Metal/Sampler.cs @@ -14,9 +14,11 @@ namespace Ryujinx.Graphics.Metal { (MTLSamplerMinMagFilter minFilter, MTLSamplerMipFilter mipFilter) = info.MinFilter.Convert(); + MTLSamplerBorderColor borderColor = GetConstrainedBorderColor(info.BorderColor, out _); + var samplerState = device.NewSamplerState(new MTLSamplerDescriptor { - BorderColor = MTLSamplerBorderColor.TransparentBlack, + BorderColor = borderColor, MinFilter = minFilter, MagFilter = info.MagFilter.Convert(), MipFilter = mipFilter, @@ -39,6 +41,37 @@ namespace Ryujinx.Graphics.Metal _mtlSamplerState = samplerState; } + private static MTLSamplerBorderColor GetConstrainedBorderColor(ColorF arbitraryBorderColor, out bool cantConstrain) + { + float r = arbitraryBorderColor.Red; + float g = arbitraryBorderColor.Green; + float b = arbitraryBorderColor.Blue; + float a = arbitraryBorderColor.Alpha; + + if (r == 0f && g == 0f && b == 0f) + { + if (a == 1f) + { + cantConstrain = false; + return MTLSamplerBorderColor.OpaqueBlack; + } + + if (a == 0f) + { + cantConstrain = false; + return MTLSamplerBorderColor.TransparentBlack; + } + } + else if (r == 1f && g == 1f && b == 1f && a == 1f) + { + cantConstrain = false; + return MTLSamplerBorderColor.OpaqueWhite; + } + + cantConstrain = true; + return MTLSamplerBorderColor.OpaqueBlack; + } + public MTLSamplerState GetSampler() { return _mtlSamplerState;