Skip to content

Commit

Permalink
Add constrained border colours to samplers (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi authored and IsaacMarovitz committed Sep 28, 2024
1 parent b33c1ae commit e27ade5
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Ryujinx.Graphics.Metal/Sampler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public Sampler(MTLDevice device, SamplerCreateInfo info)
{
(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,
Expand All @@ -39,6 +41,37 @@ public Sampler(MTLSamplerState samplerState)
_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;
Expand Down

0 comments on commit e27ade5

Please sign in to comment.