|
|
|
@ -1268,36 +1268,48 @@ Sampler::Sampler(TextureCacheRuntime& runtime, const TSCEntry& config) {
|
|
|
|
|
|
|
|
|
|
UNIMPLEMENTED_IF(config.cubemap_anisotropy != 1);
|
|
|
|
|
|
|
|
|
|
sampler.Create();
|
|
|
|
|
const GLuint handle = sampler.handle;
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(config.wrap_u));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(config.wrap_v));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(config.wrap_p));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_COMPARE_MODE, compare_mode);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_COMPARE_FUNC, compare_func);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, mag);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, min);
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_LOD_BIAS, config.LodBias());
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MIN_LOD, config.MinLod());
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MAX_LOD, config.MaxLod());
|
|
|
|
|
glSamplerParameterfv(handle, GL_TEXTURE_BORDER_COLOR, config.BorderColor().data());
|
|
|
|
|
const f32 max_anisotropy = std::clamp(config.MaxAnisotropy(), 1.0f, 16.0f);
|
|
|
|
|
|
|
|
|
|
if (GLAD_GL_ARB_texture_filter_anisotropic || GLAD_GL_EXT_texture_filter_anisotropic) {
|
|
|
|
|
const f32 max_anisotropy = std::clamp(config.MaxAnisotropy(), 1.0f, 16.0f);
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropy);
|
|
|
|
|
} else {
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_anisotropic is required");
|
|
|
|
|
}
|
|
|
|
|
if (GLAD_GL_ARB_texture_filter_minmax || GLAD_GL_EXT_texture_filter_minmax) {
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_REDUCTION_MODE_ARB, reduction_filter);
|
|
|
|
|
} else if (reduction_filter != GL_WEIGHTED_AVERAGE_ARB) {
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_minmax is required");
|
|
|
|
|
}
|
|
|
|
|
if (GLAD_GL_ARB_seamless_cubemap_per_texture || GLAD_GL_AMD_seamless_cubemap_per_texture) {
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_CUBE_MAP_SEAMLESS, seamless);
|
|
|
|
|
} else if (seamless == GL_FALSE) {
|
|
|
|
|
// We default to false because it's more common
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_seamless_cubemap_per_texture is required");
|
|
|
|
|
const auto create_sampler = [&](const f32 anisotropy) {
|
|
|
|
|
OGLSampler new_sampler;
|
|
|
|
|
new_sampler.Create();
|
|
|
|
|
const GLuint handle = new_sampler.handle;
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(config.wrap_u));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(config.wrap_v));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(config.wrap_p));
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_COMPARE_MODE, compare_mode);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_COMPARE_FUNC, compare_func);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_MAG_FILTER, mag);
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_MIN_FILTER, min);
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_LOD_BIAS, config.LodBias());
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MIN_LOD, config.MinLod());
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MAX_LOD, config.MaxLod());
|
|
|
|
|
glSamplerParameterfv(handle, GL_TEXTURE_BORDER_COLOR, config.BorderColor().data());
|
|
|
|
|
|
|
|
|
|
if (GLAD_GL_ARB_texture_filter_anisotropic || GLAD_GL_EXT_texture_filter_anisotropic) {
|
|
|
|
|
glSamplerParameterf(handle, GL_TEXTURE_MAX_ANISOTROPY, anisotropy);
|
|
|
|
|
} else {
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_anisotropic is required");
|
|
|
|
|
}
|
|
|
|
|
if (GLAD_GL_ARB_texture_filter_minmax || GLAD_GL_EXT_texture_filter_minmax) {
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_REDUCTION_MODE_ARB, reduction_filter);
|
|
|
|
|
} else if (reduction_filter != GL_WEIGHTED_AVERAGE_ARB) {
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_texture_filter_minmax is required");
|
|
|
|
|
}
|
|
|
|
|
if (GLAD_GL_ARB_seamless_cubemap_per_texture || GLAD_GL_AMD_seamless_cubemap_per_texture) {
|
|
|
|
|
glSamplerParameteri(handle, GL_TEXTURE_CUBE_MAP_SEAMLESS, seamless);
|
|
|
|
|
} else if (seamless == GL_FALSE) {
|
|
|
|
|
// We default to false because it's more common
|
|
|
|
|
LOG_WARNING(Render_OpenGL, "GL_ARB_seamless_cubemap_per_texture is required");
|
|
|
|
|
}
|
|
|
|
|
return new_sampler;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sampler = create_sampler(max_anisotropy);
|
|
|
|
|
|
|
|
|
|
const f32 max_anisotropy_default = static_cast<f32>(1U << config.max_anisotropy);
|
|
|
|
|
if (max_anisotropy > max_anisotropy_default) {
|
|
|
|
|
sampler_default_anisotropy = create_sampler(max_anisotropy_default);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|