From d7dfb681aa1f771172f314677e23d1447899cdf4 Mon Sep 17 00:00:00 2001 From: raven02 Date: Wed, 24 Jun 2015 08:25:22 -0700 Subject: [PATCH] gl4: implement texture max anisotropy --- src/xenia/gpu/gl4/texture_cache.cc | 29 +++++++++++++++++++++++++++-- src/xenia/gpu/sampler_info.cc | 4 ++++ src/xenia/gpu/sampler_info.h | 4 +++- src/xenia/gpu/xenos.h | 3 ++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/xenia/gpu/gl4/texture_cache.cc b/src/xenia/gpu/gl4/texture_cache.cc index 2c582da01..a3c409983 100644 --- a/src/xenia/gpu/gl4/texture_cache.cc +++ b/src/xenia/gpu/gl4/texture_cache.cc @@ -362,8 +362,33 @@ TextureCache::SamplerEntry* TextureCache::LookupOrInsertSampler( glSamplerParameteri(entry->handle, GL_TEXTURE_MIN_FILTER, min_filter); glSamplerParameteri(entry->handle, GL_TEXTURE_MAG_FILTER, mag_filter); - // TODO(benvanik): anisotropic filtering. - // GL_TEXTURE_MAX_ANISOTROPY_EXT + GLfloat aniso; + switch (sampler_info.aniso_filter) { + case ucode::ANISO_FILTER_DISABLED: + aniso = 0.0f; + break; + case ucode::ANISO_FILTER_MAX_1_1: + aniso = 1.0f; + break; + case ucode::ANISO_FILTER_MAX_2_1: + aniso = 2.0f; + break; + case ucode::ANISO_FILTER_MAX_4_1: + aniso = 4.0f; + break; + case ucode::ANISO_FILTER_MAX_8_1: + aniso = 8.0f; + break; + case ucode::ANISO_FILTER_MAX_16_1: + aniso = 16.0f; + break; + default: + assert_unhandled_case(aniso); + return nullptr; + } + + if (aniso) + glSamplerParameterf(entry->handle, GL_TEXTURE_MAX_ANISOTROPY_EXT, aniso); // Add to map - map takes ownership. auto entry_ptr = entry.get(); diff --git a/src/xenia/gpu/sampler_info.cc b/src/xenia/gpu/sampler_info.cc index 5140db71d..6bef01ae0 100644 --- a/src/xenia/gpu/sampler_info.cc +++ b/src/xenia/gpu/sampler_info.cc @@ -30,6 +30,10 @@ bool SamplerInfo::Prepare(const xenos::xe_gpu_texture_fetch_t& fetch, out_info->clamp_u = fetch.clamp_x; out_info->clamp_v = fetch.clamp_y; out_info->clamp_w = fetch.clamp_z; + out_info->aniso_filter = static_cast( + fetch_instr.aniso_filter == 7 ? fetch.aniso_filter + : fetch_instr.aniso_filter); + return true; } diff --git a/src/xenia/gpu/sampler_info.h b/src/xenia/gpu/sampler_info.h index c89b582ea..4cc310731 100644 --- a/src/xenia/gpu/sampler_info.h +++ b/src/xenia/gpu/sampler_info.h @@ -23,6 +23,7 @@ struct SamplerInfo { uint32_t clamp_u; uint32_t clamp_v; uint32_t clamp_w; + ucode::instr_aniso_filter_t aniso_filter; static bool Prepare(const xenos::xe_gpu_texture_fetch_t& fetch, const ucode::instr_fetch_tex_t& fetch_instr, @@ -32,7 +33,8 @@ struct SamplerInfo { bool operator==(const SamplerInfo& other) const { return min_filter == other.min_filter && mag_filter == other.mag_filter && mip_filter == other.mip_filter && clamp_u == other.clamp_u && - clamp_v == other.clamp_v && clamp_w == other.clamp_w; + clamp_v == other.clamp_v && clamp_w == other.clamp_w && + aniso_filter == other.aniso_filter; } }; diff --git a/src/xenia/gpu/xenos.h b/src/xenia/gpu/xenos.h index 927cc62fb..e910d9002 100644 --- a/src/xenia/gpu/xenos.h +++ b/src/xenia/gpu/xenos.h @@ -342,7 +342,8 @@ XEPACKEDUNION(xe_gpu_texture_fetch_t, { uint32_t mag_filter : 2; uint32_t min_filter : 2; uint32_t mip_filter : 2; - uint32_t unk3_2 : 6; + uint32_t aniso_filter : 3; // correct ? + uint32_t arbitrary_filter : 3; // correct ? uint32_t border : 1; uint32_t unk4_0 : 2; // dword_4 uint32_t mip_min_level : 4;