summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp97
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h5
-rw-r--r--src/video_core/textures/texture.h34
3 files changed, 72 insertions, 64 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 168288088..e33848bc1 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -802,104 +802,87 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config,
802 802
803void RasterizerOpenGL::SamplerInfo::Create() { 803void RasterizerOpenGL::SamplerInfo::Create() {
804 sampler.Create(); 804 sampler.Create();
805 mag_filter = min_filter = Tegra::Texture::TextureFilter::Linear; 805 mag_filter = Tegra::Texture::TextureFilter::Linear;
806 wrap_u = wrap_v = wrap_p = Tegra::Texture::WrapMode::Wrap; 806 min_filter = Tegra::Texture::TextureFilter::Linear;
807 uses_depth_compare = false; 807 wrap_u = Tegra::Texture::WrapMode::Wrap;
808 wrap_v = Tegra::Texture::WrapMode::Wrap;
809 wrap_p = Tegra::Texture::WrapMode::Wrap;
810 use_depth_compare = false;
808 depth_compare_func = Tegra::Texture::DepthCompareFunc::Never; 811 depth_compare_func = Tegra::Texture::DepthCompareFunc::Never;
809 812
810 // default is GL_LINEAR_MIPMAP_LINEAR 813 // OpenGL's default is GL_LINEAR_MIPMAP_LINEAR
811 glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 814 glSamplerParameteri(sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
812 // Other attributes have correct defaults
813 glSamplerParameteri(sampler.handle, GL_TEXTURE_COMPARE_FUNC, GL_NEVER); 815 glSamplerParameteri(sampler.handle, GL_TEXTURE_COMPARE_FUNC, GL_NEVER);
816
817 // Other attributes have correct defaults
814} 818}
815 819
816void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntry& config) { 820void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntry& config) {
817 const GLuint s = sampler.handle; 821 const GLuint sampler_id = sampler.handle;
818 if (mag_filter != config.mag_filter) { 822 if (mag_filter != config.mag_filter) {
819 mag_filter = config.mag_filter; 823 mag_filter = config.mag_filter;
820 glSamplerParameteri( 824 glSamplerParameteri(
821 s, GL_TEXTURE_MAG_FILTER, 825 sampler_id, GL_TEXTURE_MAG_FILTER,
822 MaxwellToGL::TextureFilterMode(mag_filter, Tegra::Texture::TextureMipmapFilter::None)); 826 MaxwellToGL::TextureFilterMode(mag_filter, Tegra::Texture::TextureMipmapFilter::None));
823 } 827 }
824 if (min_filter != config.min_filter || mip_filter != config.mip_filter) { 828 if (min_filter != config.min_filter || mipmap_filter != config.mipmap_filter) {
825 min_filter = config.min_filter; 829 min_filter = config.min_filter;
826 mip_filter = config.mip_filter; 830 mipmap_filter = config.mipmap_filter;
827 glSamplerParameteri(s, GL_TEXTURE_MIN_FILTER, 831 glSamplerParameteri(sampler_id, GL_TEXTURE_MIN_FILTER,
828 MaxwellToGL::TextureFilterMode(min_filter, mip_filter)); 832 MaxwellToGL::TextureFilterMode(min_filter, mipmap_filter));
829 } 833 }
830 834
831 if (wrap_u != config.wrap_u) { 835 if (wrap_u != config.wrap_u) {
832 wrap_u = config.wrap_u; 836 wrap_u = config.wrap_u;
833 glSamplerParameteri(s, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(wrap_u)); 837 glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_S, MaxwellToGL::WrapMode(wrap_u));
834 } 838 }
835 if (wrap_v != config.wrap_v) { 839 if (wrap_v != config.wrap_v) {
836 wrap_v = config.wrap_v; 840 wrap_v = config.wrap_v;
837 glSamplerParameteri(s, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(wrap_v)); 841 glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_T, MaxwellToGL::WrapMode(wrap_v));
838 } 842 }
839 if (wrap_p != config.wrap_p) { 843 if (wrap_p != config.wrap_p) {
840 wrap_p = config.wrap_p; 844 wrap_p = config.wrap_p;
841 glSamplerParameteri(s, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(wrap_p)); 845 glSamplerParameteri(sampler_id, GL_TEXTURE_WRAP_R, MaxwellToGL::WrapMode(wrap_p));
842 } 846 }
843 847
844 if (uses_depth_compare != (config.depth_compare_enabled == 1)) { 848 if (const bool enabled = config.depth_compare_enabled == 1; use_depth_compare != enabled) {
845 uses_depth_compare = (config.depth_compare_enabled == 1); 849 use_depth_compare = enabled;
846 if (uses_depth_compare) { 850 glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_MODE,
847 glSamplerParameteri(s, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); 851 use_depth_compare ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE);
848 } else {
849 glSamplerParameteri(s, GL_TEXTURE_COMPARE_MODE, GL_NONE);
850 }
851 } 852 }
852 853
853 if (depth_compare_func != config.depth_compare_func) { 854 if (depth_compare_func != config.depth_compare_func) {
854 depth_compare_func = config.depth_compare_func; 855 depth_compare_func = config.depth_compare_func;
855 glSamplerParameteri(s, GL_TEXTURE_COMPARE_FUNC, 856 glSamplerParameteri(sampler_id, GL_TEXTURE_COMPARE_FUNC,
856 MaxwellToGL::DepthCompareFunc(depth_compare_func)); 857 MaxwellToGL::DepthCompareFunc(depth_compare_func));
857 } 858 }
858 859
859 GLvec4 new_border_color; 860 if (const auto new_border_color = config.GetBorderColor(); border_color != new_border_color) {
860 if (config.srgb_conversion) {
861 new_border_color[0] = config.srgb_border_color_r / 255.0f;
862 new_border_color[1] = config.srgb_border_color_g / 255.0f;
863 new_border_color[2] = config.srgb_border_color_g / 255.0f;
864 } else {
865 new_border_color[0] = config.border_color_r;
866 new_border_color[1] = config.border_color_g;
867 new_border_color[2] = config.border_color_b;
868 }
869 new_border_color[3] = config.border_color_a;
870
871 if (border_color != new_border_color) {
872 border_color = new_border_color; 861 border_color = new_border_color;
873 glSamplerParameterfv(s, GL_TEXTURE_BORDER_COLOR, border_color.data()); 862 glSamplerParameterfv(sampler_id, GL_TEXTURE_BORDER_COLOR, border_color.data());
874 } 863 }
875 864
876 const float anisotropic_max = static_cast<float>(1 << config.max_anisotropy.Value()); 865 if (const float anisotropic = config.GetMaxAnisotropy(); max_anisotropic != anisotropic) {
877 if (anisotropic_max != max_anisotropic) { 866 max_anisotropic = anisotropic;
878 max_anisotropic = anisotropic_max;
879 if (GLAD_GL_ARB_texture_filter_anisotropic) { 867 if (GLAD_GL_ARB_texture_filter_anisotropic) {
880 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropic); 868 glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY, max_anisotropic);
881 } else if (GLAD_GL_EXT_texture_filter_anisotropic) { 869 } else if (GLAD_GL_EXT_texture_filter_anisotropic) {
882 glSamplerParameterf(s, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropic); 870 glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropic);
883 } 871 }
884 } 872 }
885 const float lod_min = static_cast<float>(config.min_lod_clamp.Value()) / 256.0f;
886 if (lod_min != min_lod) {
887 min_lod = lod_min;
888 glSamplerParameterf(s, GL_TEXTURE_MIN_LOD, min_lod);
889 }
890 873
891 const float lod_max = static_cast<float>(config.max_lod_clamp.Value()) / 256.0f; 874 if (const float min = config.GetMinLod(); min_lod != min) {
892 if (lod_max != max_lod) { 875 min_lod = min;
893 max_lod = lod_max; 876 glSamplerParameterf(sampler_id, GL_TEXTURE_MIN_LOD, min_lod);
894 glSamplerParameterf(s, GL_TEXTURE_MAX_LOD, max_lod);
895 } 877 }
896 const u32 bias = config.mip_lod_bias.Value(); 878 if (const float max = config.GetMaxLod(); max_lod != max) {
897 // Sign extend the 13-bit value. 879 max_lod = max;
898 constexpr u32 mask = 1U << (13 - 1); 880 glSamplerParameterf(sampler_id, GL_TEXTURE_MAX_LOD, max_lod);
899 const float bias_lod = static_cast<s32>((bias ^ mask) - mask) / 256.f; 881 }
900 if (lod_bias != bias_lod) { 882
901 lod_bias = bias_lod; 883 if (const float bias = config.GetLodBias(); lod_bias != bias) {
902 glSamplerParameterf(s, GL_TEXTURE_LOD_BIAS, lod_bias); 884 lod_bias = bias;
885 glSamplerParameterf(sampler_id, GL_TEXTURE_LOD_BIAS, lod_bias);
903 } 886 }
904} 887}
905 888
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 2f0524f85..7e63f8008 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -94,11 +94,12 @@ private:
94 private: 94 private:
95 Tegra::Texture::TextureFilter mag_filter = Tegra::Texture::TextureFilter::Nearest; 95 Tegra::Texture::TextureFilter mag_filter = Tegra::Texture::TextureFilter::Nearest;
96 Tegra::Texture::TextureFilter min_filter = Tegra::Texture::TextureFilter::Nearest; 96 Tegra::Texture::TextureFilter min_filter = Tegra::Texture::TextureFilter::Nearest;
97 Tegra::Texture::TextureMipmapFilter mip_filter = Tegra::Texture::TextureMipmapFilter::None; 97 Tegra::Texture::TextureMipmapFilter mipmap_filter =
98 Tegra::Texture::TextureMipmapFilter::None;
98 Tegra::Texture::WrapMode wrap_u = Tegra::Texture::WrapMode::ClampToEdge; 99 Tegra::Texture::WrapMode wrap_u = Tegra::Texture::WrapMode::ClampToEdge;
99 Tegra::Texture::WrapMode wrap_v = Tegra::Texture::WrapMode::ClampToEdge; 100 Tegra::Texture::WrapMode wrap_v = Tegra::Texture::WrapMode::ClampToEdge;
100 Tegra::Texture::WrapMode wrap_p = Tegra::Texture::WrapMode::ClampToEdge; 101 Tegra::Texture::WrapMode wrap_p = Tegra::Texture::WrapMode::ClampToEdge;
101 bool uses_depth_compare = false; 102 bool use_depth_compare = false;
102 Tegra::Texture::DepthCompareFunc depth_compare_func = 103 Tegra::Texture::DepthCompareFunc depth_compare_func =
103 Tegra::Texture::DepthCompareFunc::Always; 104 Tegra::Texture::DepthCompareFunc::Always;
104 GLvec4 border_color = {}; 105 GLvec4 border_color = {};
diff --git a/src/video_core/textures/texture.h b/src/video_core/textures/texture.h
index 0fc5530f2..8c278c0e2 100644
--- a/src/video_core/textures/texture.h
+++ b/src/video_core/textures/texture.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
7#include "common/assert.h" 8#include "common/assert.h"
8#include "common/bit_field.h" 9#include "common/bit_field.h"
9#include "common/common_funcs.h" 10#include "common/common_funcs.h"
@@ -293,7 +294,7 @@ struct TSCEntry {
293 union { 294 union {
294 BitField<0, 2, TextureFilter> mag_filter; 295 BitField<0, 2, TextureFilter> mag_filter;
295 BitField<4, 2, TextureFilter> min_filter; 296 BitField<4, 2, TextureFilter> min_filter;
296 BitField<6, 2, TextureMipmapFilter> mip_filter; 297 BitField<6, 2, TextureMipmapFilter> mipmap_filter;
297 BitField<9, 1, u32> cubemap_interface_filtering; 298 BitField<9, 1, u32> cubemap_interface_filtering;
298 BitField<12, 13, u32> mip_lod_bias; 299 BitField<12, 13, u32> mip_lod_bias;
299 }; 300 };
@@ -306,10 +307,33 @@ struct TSCEntry {
306 BitField<12, 8, u32> srgb_border_color_g; 307 BitField<12, 8, u32> srgb_border_color_g;
307 BitField<20, 8, u32> srgb_border_color_b; 308 BitField<20, 8, u32> srgb_border_color_b;
308 }; 309 };
309 float border_color_r; 310 std::array<f32, 4> border_color;
310 float border_color_g; 311
311 float border_color_b; 312 float GetMaxAnisotropy() const {
312 float border_color_a; 313 return static_cast<float>(1U << max_anisotropy);
314 }
315
316 float GetMinLod() const {
317 return static_cast<float>(min_lod_clamp) / 256.0f;
318 }
319
320 float GetMaxLod() const {
321 return static_cast<float>(max_lod_clamp) / 256.0f;
322 }
323
324 float GetLodBias() const {
325 // Sign extend the 13-bit value.
326 constexpr u32 mask = 1U << (13 - 1);
327 return static_cast<float>((mip_lod_bias ^ mask) - mask) / 256.0f;
328 }
329
330 std::array<float, 4> GetBorderColor() const {
331 if (srgb_conversion) {
332 return {srgb_border_color_r / 255.0f, srgb_border_color_g / 255.0f,
333 srgb_border_color_b / 255.0f, border_color[3]};
334 }
335 return border_color;
336 }
313}; 337};
314static_assert(sizeof(TSCEntry) == 0x20, "TSCEntry has wrong size"); 338static_assert(sizeof(TSCEntry) == 0x20, "TSCEntry has wrong size");
315 339