2019-10-13 08:02:07 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
2019-12-29 18:41:50 +01:00
|
|
|
using Ryujinx.Graphics.GAL;
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-05-23 11:46:09 +02:00
|
|
|
namespace Ryujinx.Graphics.OpenGL.Image
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
class Sampler : ISampler
|
|
|
|
{
|
|
|
|
public int Handle { get; private set; }
|
|
|
|
|
|
|
|
public Sampler(SamplerCreateInfo info)
|
|
|
|
{
|
|
|
|
Handle = GL.GenSampler();
|
|
|
|
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureMinFilter, (int)info.MinFilter.Convert());
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureMagFilter, (int)info.MagFilter.Convert());
|
|
|
|
|
2020-11-02 21:03:06 +01:00
|
|
|
if (HwCapabilities.SupportsSeamlessCubemapPerTexture)
|
|
|
|
{
|
|
|
|
GL.SamplerParameter(Handle, (SamplerParameterName)ArbSeamlessCubemapPerTexture.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2019-10-13 08:02:07 +02:00
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapS, (int)info.AddressU.Convert());
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapT, (int)info.AddressV.Convert());
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapR, (int)info.AddressP.Convert());
|
|
|
|
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareMode, (int)info.CompareMode.Convert());
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareFunc, (int)info.CompareOp.Convert());
|
|
|
|
|
|
|
|
unsafe
|
|
|
|
{
|
|
|
|
float* borderColor = stackalloc float[4]
|
|
|
|
{
|
|
|
|
info.BorderColor.Red,
|
|
|
|
info.BorderColor.Green,
|
|
|
|
info.BorderColor.Blue,
|
2023-07-24 18:35:04 +02:00
|
|
|
info.BorderColor.Alpha,
|
2019-10-13 08:02:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureBorderColor, borderColor);
|
|
|
|
}
|
|
|
|
|
2023-06-28 18:10:55 +02:00
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureMinLod, info.MinLod);
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxLod, info.MaxLod);
|
2019-10-13 08:02:07 +02:00
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureLodBias, info.MipLodBias);
|
|
|
|
|
|
|
|
GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxAnisotropyExt, info.MaxAnisotropy);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Bind(int unit)
|
|
|
|
{
|
|
|
|
GL.BindSampler(unit, Handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
if (Handle != 0)
|
|
|
|
{
|
|
|
|
GL.DeleteSampler(Handle);
|
|
|
|
|
|
|
|
Handle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|