From 651663e5f7df7b9569411fc9653f70768b519caf Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 30 Jul 2023 02:30:44 +0300 Subject: [PATCH] renderer_gl: Add swap eyes options * Remove reverse interlaced in favour of the checkbox --- src/citra/config.cpp | 2 +- src/citra_qt/configuration/config.cpp | 4 +-- .../configuration/configure_enhancements.cpp | 13 ++++---- .../configuration/configure_enhancements.h | 1 + .../configuration/configure_enhancements.ui | 24 ++------------ src/citra_qt/main.cpp | 2 ++ src/common/settings.cpp | 2 +- src/common/settings.h | 13 ++------ src/core/telemetry_session.cpp | 4 +-- src/video_core/host_shaders/CMakeLists.txt | 2 +- .../host_shaders/opengl_present_anaglyph.frag | 5 +-- .../opengl_present_interlaced.frag | 16 ++++++---- .../renderer_opengl/renderer_opengl.cpp | 31 ++++++------------- .../renderer_opengl/renderer_opengl.h | 1 + 14 files changed, 44 insertions(+), 76 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 5edaf42da..8affeefc3 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -143,7 +143,7 @@ void Config::ReadValues() { ReadSetting("Renderer", Settings::values.use_vsync_new); ReadSetting("Renderer", Settings::values.texture_filter); - ReadSetting("Renderer", Settings::values.mono_render_option); + ReadSetting("Renderer", Settings::values.swap_eyes); ReadSetting("Renderer", Settings::values.render_3d); ReadSetting("Renderer", Settings::values.factor_3d); ReadSetting("Renderer", Settings::values.pp_shader_name); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 3da6114b8..bd57eff86 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -505,9 +505,9 @@ void Config::ReadLayoutValues() { ReadGlobalSetting(Settings::values.swap_screen); ReadGlobalSetting(Settings::values.upright_screen); ReadGlobalSetting(Settings::values.large_screen_proportion); + ReadBasicSetting(Settings::values.swap_eyes); if (global) { - ReadBasicSetting(Settings::values.mono_render_option); ReadBasicSetting(Settings::values.custom_layout); ReadBasicSetting(Settings::values.custom_top_left); ReadBasicSetting(Settings::values.custom_top_top); @@ -1017,9 +1017,9 @@ void Config::SaveLayoutValues() { WriteGlobalSetting(Settings::values.swap_screen); WriteGlobalSetting(Settings::values.upright_screen); WriteGlobalSetting(Settings::values.large_screen_proportion); + WriteBasicSetting(Settings::values.swap_eyes); if (global) { - WriteBasicSetting(Settings::values.mono_render_option); WriteBasicSetting(Settings::values.custom_layout); WriteBasicSetting(Settings::values.custom_top_left); WriteBasicSetting(Settings::values.custom_top_top); diff --git a/src/citra_qt/configuration/configure_enhancements.cpp b/src/citra_qt/configuration/configure_enhancements.cpp index 55b8a79eb..43fcf3b2d 100644 --- a/src/citra_qt/configuration/configure_enhancements.cpp +++ b/src/citra_qt/configuration/configure_enhancements.cpp @@ -74,9 +74,8 @@ void ConfigureEnhancements::SetConfiguration() { ui->render_3d_combobox->setCurrentIndex( static_cast(Settings::values.render_3d.GetValue())); ui->factor_3d->setValue(Settings::values.factor_3d.GetValue()); - ui->mono_rendering_eye->setCurrentIndex( - static_cast(Settings::values.mono_render_option.GetValue())); updateShaders(Settings::values.render_3d.GetValue()); + ui->toggle_swap_eyes->setChecked(Settings::values.swap_eyes.GetValue()); ui->toggle_linear_filter->setChecked(Settings::values.filter_mode.GetValue()); ui->toggle_swap_screen->setChecked(Settings::values.swap_screen.GetValue()); ui->toggle_upright_screen->setChecked(Settings::values.upright_screen.GetValue()); @@ -98,8 +97,7 @@ void ConfigureEnhancements::updateShaders(Settings::StereoRenderOption stereo_op ui->shader_combobox->clear(); ui->shader_combobox->setEnabled(true); - if (stereo_option == Settings::StereoRenderOption::Interlaced || - stereo_option == Settings::StereoRenderOption::ReverseInterlaced) { + if (stereo_option == Settings::StereoRenderOption::Interlaced) { ui->shader_combobox->addItem(QStringLiteral("horizontal (builtin)")); ui->shader_combobox->setCurrentIndex(0); ui->shader_combobox->setEnabled(false); @@ -135,8 +133,6 @@ void ConfigureEnhancements::ApplyConfiguration() { Settings::values.render_3d = static_cast(ui->render_3d_combobox->currentIndex()); Settings::values.factor_3d = ui->factor_3d->value(); - Settings::values.mono_render_option = - static_cast(ui->mono_rendering_eye->currentIndex()); if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Anaglyph) { Settings::values.anaglyph_shader_name = ui->shader_combobox->itemText(ui->shader_combobox->currentIndex()).toStdString(); @@ -146,6 +142,8 @@ void ConfigureEnhancements::ApplyConfiguration() { } Settings::values.large_screen_proportion = ui->large_screen_proportion->value(); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.swap_eyes, ui->toggle_swap_eyes, + swap_eyes); ConfigurationShared::ApplyPerGameSetting(&Settings::values.filter_mode, ui->toggle_linear_filter, linear_filter); ConfigurationShared::ApplyPerGameSetting(&Settings::values.texture_filter, @@ -174,6 +172,7 @@ void ConfigureEnhancements::SetupPerGameUI() { if (Settings::IsConfiguringGlobal()) { ui->widget_resolution->setEnabled(Settings::values.resolution_factor.UsingGlobal()); ui->widget_texture_filter->setEnabled(Settings::values.texture_filter.UsingGlobal()); + ui->toggle_swap_eyes->setEnabled(Settings::values.swap_eyes.UsingGlobal()); ui->toggle_linear_filter->setEnabled(Settings::values.filter_mode.UsingGlobal()); ui->toggle_swap_screen->setEnabled(Settings::values.swap_screen.UsingGlobal()); ui->toggle_upright_screen->setEnabled(Settings::values.upright_screen.UsingGlobal()); @@ -193,6 +192,8 @@ void ConfigureEnhancements::SetupPerGameUI() { linear_filter); ConfigurationShared::SetColoredTristate(ui->toggle_swap_screen, Settings::values.swap_screen, swap_screen); + ConfigurationShared::SetColoredTristate(ui->toggle_swap_eyes, Settings::values.swap_eyes, + swap_eyes); ConfigurationShared::SetColoredTristate(ui->toggle_upright_screen, Settings::values.upright_screen, upright_screen); ConfigurationShared::SetColoredTristate(ui->toggle_dump_textures, diff --git a/src/citra_qt/configuration/configure_enhancements.h b/src/citra_qt/configuration/configure_enhancements.h index c7b7425d2..e423bcf01 100644 --- a/src/citra_qt/configuration/configure_enhancements.h +++ b/src/citra_qt/configuration/configure_enhancements.h @@ -45,5 +45,6 @@ private: ConfigurationShared::CheckState custom_textures; ConfigurationShared::CheckState preload_textures; ConfigurationShared::CheckState async_custom_loading; + ConfigurationShared::CheckState swap_eyes; QColor bg_color; }; diff --git a/src/citra_qt/configuration/configure_enhancements.ui b/src/citra_qt/configuration/configure_enhancements.ui index 862125783..7ce60d477 100644 --- a/src/citra_qt/configuration/configure_enhancements.ui +++ b/src/citra_qt/configuration/configure_enhancements.ui @@ -254,11 +254,6 @@ Interlaced - - - Reverse Interlaced - - @@ -293,26 +288,12 @@ - + - Eye to Render in Monoscopic Mode + Swap Eyes - - - - - Left Eye (default) - - - - - Right Eye - - - - @@ -544,7 +525,6 @@ texture_filter_combobox render_3d_combobox factor_3d - mono_rendering_eye layout_combobox toggle_swap_screen toggle_upright_screen diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index b2069dd55..295868631 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -627,6 +627,8 @@ void GMainWindow::InitializeHotkeys() { Settings::values.frame_limit.SetGlobal(!Settings::values.frame_limit.UsingGlobal()); UpdateStatusBar(); }); + connect_shortcut(QStringLiteral("Swap Eyes"), + [&] { Settings::values.swap_eyes = !Settings::values.swap_eyes; }); connect_shortcut(QStringLiteral("Toggle Texture Dumping"), [&] { Settings::values.dump_textures = !Settings::values.dump_textures; }); connect_shortcut(QStringLiteral("Toggle Custom Textures"), diff --git a/src/common/settings.cpp b/src/common/settings.cpp index f0356b00a..70af84b14 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -84,7 +84,7 @@ void LogSettings() { log_setting("Renderer_TextureFilter", GetTextureFilterName(values.texture_filter.GetValue())); log_setting("Stereoscopy_Render3d", values.render_3d.GetValue()); log_setting("Stereoscopy_Factor3d", values.factor_3d.GetValue()); - log_setting("Stereoscopy_MonoRenderOption", values.mono_render_option.GetValue()); + log_setting("Stereoscopy_SwapEyes", values.swap_eyes.GetValue()); if (values.render_3d.GetValue() == StereoRenderOption::Anaglyph) { log_setting("Renderer_AnaglyphShader", values.anaglyph_shader_name.GetValue()); } diff --git a/src/common/settings.h b/src/common/settings.h index 030797930..16c3ffdb8 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -52,15 +52,7 @@ enum class StereoRenderOption : u32 { TopBottom = 2, Anaglyph = 3, Interlaced = 4, - ReverseInterlaced = 5, - CardboardVR = 6 -}; - -// Which eye to render when 3d is off. 800px wide mode could be added here in the future, when -// implemented -enum class MonoRenderOption : u32 { - LeftEye = 0, - RightEye = 1, + CardboardVR = 5 }; enum class AudioEmulation : u32 { @@ -468,8 +460,7 @@ struct Values { SwitchableSetting render_3d{StereoRenderOption::Off, "render_3d"}; SwitchableSetting factor_3d{0, "factor_3d"}; - SwitchableSetting mono_render_option{MonoRenderOption::LeftEye, - "mono_render_option"}; + SwitchableSetting swap_eyes{false, "swap_eyes"}; Setting cardboard_screen_size{85, "cardboard_screen_size"}; Setting cardboard_x_shift{0, "cardboard_x_shift"}; diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index 968e36eac..b460d4921 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -151,8 +151,8 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) { static_cast(Settings::values.render_3d.GetValue())); AddField(Telemetry::FieldType::UserConfig, "Renderer_Factor3d", Settings::values.factor_3d.GetValue()); - AddField(Telemetry::FieldType::UserConfig, "Renderer_MonoRenderOption", - static_cast(Settings::values.mono_render_option.GetValue())); + AddField(Telemetry::FieldType::UserConfig, "Renderer_SwapEyes", + static_cast(Settings::values.swap_eyes.GetValue())); AddField(Telemetry::FieldType::UserConfig, "System_IsNew3ds", Settings::values.is_new_3ds.GetValue()); AddField(Telemetry::FieldType::UserConfig, "System_RegionValue", diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 1c054978f..8d9dea8a3 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt @@ -103,4 +103,4 @@ add_custom_target(host_shaders ${SHADER_HEADERS} SOURCES ${SHADER_SOURCES} -) +) \ No newline at end of file diff --git a/src/video_core/host_shaders/opengl_present_anaglyph.frag b/src/video_core/host_shaders/opengl_present_anaglyph.frag index 3fbe4a7f7..e4e36b79d 100644 --- a/src/video_core/host_shaders/opengl_present_anaglyph.frag +++ b/src/video_core/host_shaders/opengl_present_anaglyph.frag @@ -23,6 +23,7 @@ layout(binding = 1) uniform sampler2D color_texture_r; uniform vec4 resolution; uniform int layer; +uniform bool swap_eyes; const vec3 gamma_map = vec3(1.6, 0.8, 1.0); @@ -37,7 +38,7 @@ vec3 correct_color(vec3 original) { void main() { vec4 color_left = texture(color_texture, frag_tex_coord); vec4 color_right = texture(color_texture_r, frag_tex_coord); - vec3 optimized_color = clamp(color_left.rgb * left_filter, vec3(0.0), vec3(1.0)) + - clamp(color_right.rgb * right_filter, vec3(0.0), vec3(1.0)); + vec3 optimized_color = clamp(color_left.rgb * (swap_eyes ? right_filter : left_filter), vec3(0.0), vec3(1.0)) + + clamp(color_right.rgb * (swap_eyes ? left_filter : right_filter), vec3(0.0), vec3(1.0)); color = vec4(correct_color(optimized_color), color_left.a); } diff --git a/src/video_core/host_shaders/opengl_present_interlaced.frag b/src/video_core/host_shaders/opengl_present_interlaced.frag index 8bf25c712..aeb4736c6 100644 --- a/src/video_core/host_shaders/opengl_present_interlaced.frag +++ b/src/video_core/host_shaders/opengl_present_interlaced.frag @@ -7,18 +7,22 @@ layout(location = 0) in vec2 frag_tex_coord; layout(location = 0) out vec4 color; -layout(binding = 0) uniform sampler2D color_texture; +layout(binding = 0) uniform sampler2D color_texture_l; layout(binding = 1) uniform sampler2D color_texture_r; uniform vec4 o_resolution; -uniform int reverse_interlaced; uniform ivec2 screen_pos; +uniform bool swap_eyes; void main() { float screen_row = o_resolution.x * frag_tex_coord.x; - const int is_even = int(screen_pos.y % 2 == 0); - if (int(screen_row) % 2 == is_even) - color = texture(color_texture, frag_tex_coord); - else + bool is_even = screen_pos.y % 2 == 0; + if (swap_eyes) { + is_even = !is_even; + } + if (int(screen_row) % 2 == int(is_even)) { + color = texture(color_texture_l, frag_tex_coord); + } else { color = texture(color_texture_r, frag_tex_coord); + } } diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 6a493c3fc..a57552c39 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -404,9 +404,7 @@ void RendererOpenGL::ReloadShader() { shader_data += shader_text; } } - } else if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced || - Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::ReverseInterlaced) { + } else if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced) { shader_data += HostShaders::OPENGL_PRESENT_INTERLACED_FRAG; } else { if (Settings::values.pp_shader_name.GetValue() == "none (builtin)") { @@ -428,20 +426,10 @@ void RendererOpenGL::ReloadShader() { uniform_modelview_matrix = glGetUniformLocation(shader.handle, "modelview_matrix"); uniform_color_texture = glGetUniformLocation(shader.handle, "color_texture"); if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Anaglyph || - Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced || - Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::ReverseInterlaced) { + Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced) { + uniform_swap_eyes = glGetUniformLocation(shader.handle, "swap_eyes"); uniform_color_texture_r = glGetUniformLocation(shader.handle, "color_texture_r"); } - if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced || - Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::ReverseInterlaced) { - GLuint uniform_reverse_interlaced = - glGetUniformLocation(shader.handle, "reverse_interlaced"); - if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::ReverseInterlaced) - glUniform1i(uniform_reverse_interlaced, 1); - else - glUniform1i(uniform_reverse_interlaced, 0); - } uniform_i_resolution = glGetUniformLocation(shader.handle, "i_resolution"); uniform_o_resolution = glGetUniformLocation(shader.handle, "o_resolution"); uniform_layer = glGetUniformLocation(shader.handle, "layer"); @@ -686,8 +674,7 @@ void RendererOpenGL::DrawScreens(const Layout::FramebufferLayout& layout, bool f const bool stereo_single_screen = Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Anaglyph || - Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced || - Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::ReverseInterlaced; + Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Interlaced; // Set the screen position const auto screen_pos = render_window.GetScreenPos() + @@ -760,7 +747,7 @@ void RendererOpenGL::DrawTopScreen(const Layout::FramebufferLayout& layout, : Layout::DisplayOrientation::Portrait; switch (Settings::values.render_3d.GetValue()) { case Settings::StereoRenderOption::Off: { - const int eye = static_cast(Settings::values.mono_render_option.GetValue()); + const u32 eye = static_cast(Settings::values.swap_eyes.GetValue()); DrawSingleScreen(screen_infos[eye], top_screen_left, top_screen_top, top_screen_width, top_screen_height, orientation); break; @@ -794,8 +781,8 @@ void RendererOpenGL::DrawTopScreen(const Layout::FramebufferLayout& layout, break; } case Settings::StereoRenderOption::Anaglyph: - case Settings::StereoRenderOption::Interlaced: - case Settings::StereoRenderOption::ReverseInterlaced: { + case Settings::StereoRenderOption::Interlaced: { + glUniform1i(uniform_swap_eyes, Settings::values.swap_eyes.GetValue()); DrawSingleScreenStereo(screen_infos[0], screen_infos[1], top_screen_left, top_screen_top, top_screen_width, top_screen_height, orientation); break; @@ -852,8 +839,8 @@ void RendererOpenGL::DrawBottomScreen(const Layout::FramebufferLayout& layout, break; } case Settings::StereoRenderOption::Anaglyph: - case Settings::StereoRenderOption::Interlaced: - case Settings::StereoRenderOption::ReverseInterlaced: { + case Settings::StereoRenderOption::Interlaced: { + glUniform1i(uniform_swap_eyes, Settings::values.swap_eyes.GetValue()); DrawSingleScreenStereo(screen_infos[2], screen_infos[2], bottom_screen_left, bottom_screen_top, bottom_screen_width, bottom_screen_height, orientation); diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index 12c994244..eed8f7315 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -103,6 +103,7 @@ private: GLuint uniform_modelview_matrix; GLuint uniform_color_texture; GLuint uniform_color_texture_r; + GLuint uniform_swap_eyes; // Shader uniform for Dolphin compatibility GLuint uniform_i_resolution;