From 0da25736d9492bc97b5ff124ca1a66f8a44e03e3 Mon Sep 17 00:00:00 2001 From: SachinVin <26602104+SachinVin@users.noreply.github.com> Date: Sun, 16 Apr 2023 23:21:21 +0530 Subject: [PATCH] renderer_opengl.cpp: Draw{Top, Bottom}Screen Clean up (#6422) --- .../renderer_opengl/renderer_opengl.cpp | 233 ++++++++++-------- .../renderer_opengl/renderer_opengl.h | 5 +- 2 files changed, 134 insertions(+), 104 deletions(-) diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index f6f204b53..a5e06e3fc 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -977,15 +977,15 @@ void RendererOpenGL::DrawScreens(const Layout::FramebufferLayout& layout, bool f glUniform1i(uniform_layer, 0); if (!Settings::values.swap_screen.GetValue()) { - DrawTopScreen(layout, top_screen, stereo_single_screen); + DrawTopScreen(layout, top_screen); glUniform1i(uniform_layer, 0); ApplySecondLayerOpacity(); - DrawBottomScreen(layout, bottom_screen, stereo_single_screen); + DrawBottomScreen(layout, bottom_screen); } else { - DrawBottomScreen(layout, bottom_screen, stereo_single_screen); + DrawBottomScreen(layout, bottom_screen); glUniform1i(uniform_layer, 0); ApplySecondLayerOpacity(); - DrawTopScreen(layout, top_screen, stereo_single_screen); + DrawTopScreen(layout, top_screen); } ResetSecondLayerOpacity(); } @@ -1013,137 +1013,168 @@ void RendererOpenGL::ResetSecondLayerOpacity() { } void RendererOpenGL::DrawTopScreen(const Layout::FramebufferLayout& layout, - const Common::Rectangle& top_screen, - const bool stereo_single_screen) { + const Common::Rectangle& top_screen) { if (!layout.top_screen_enabled) { return; } + const float top_screen_left = static_cast(top_screen.left); + const float top_screen_top = static_cast(top_screen.top); + const float top_screen_width = static_cast(top_screen.GetWidth()); + const float top_screen_height = static_cast(top_screen.GetHeight()); + if (layout.is_rotated) { - if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Off) { + switch (Settings::values.render_3d.GetValue()) { + case Settings::StereoRenderOption::Off: { int eye = static_cast(Settings::values.mono_render_option.GetValue()); - DrawSingleScreenRotated(screen_infos[eye], (float)top_screen.left, - (float)top_screen.top, (float)top_screen.GetWidth(), - (float)top_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::SideBySide) { - DrawSingleScreenRotated(screen_infos[0], (float)top_screen.left / 2, - (float)top_screen.top, (float)top_screen.GetWidth() / 2, - (float)top_screen.GetHeight()); + DrawSingleScreenRotated(screen_infos[eye], top_screen_left, top_screen_top, + top_screen_width, top_screen_height); + break; + } + case Settings::StereoRenderOption::SideBySide: { + DrawSingleScreenRotated(screen_infos[0], top_screen_left / 2, top_screen_top, + top_screen_width / 2, top_screen_height); glUniform1i(uniform_layer, 1); DrawSingleScreenRotated(screen_infos[1], - ((float)top_screen.left / 2) + ((float)layout.width / 2), - (float)top_screen.top, (float)top_screen.GetWidth() / 2, - (float)top_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::CardboardVR) { - DrawSingleScreenRotated(screen_infos[0], layout.top_screen.left, layout.top_screen.top, - layout.top_screen.GetWidth(), layout.top_screen.GetHeight()); + static_cast((top_screen_left / 2) + (layout.width / 2)), + top_screen_top, top_screen_width / 2, top_screen_height); + break; + } + case Settings::StereoRenderOption::CardboardVR: { + DrawSingleScreenRotated(screen_infos[0], top_screen_left, top_screen_top, + top_screen_width, top_screen_height); glUniform1i(uniform_layer, 1); DrawSingleScreenRotated( - screen_infos[1], layout.cardboard.top_screen_right_eye + ((float)layout.width / 2), - layout.top_screen.top, layout.top_screen.GetWidth(), layout.top_screen.GetHeight()); - } else if (stereo_single_screen) { - DrawSingleScreenStereoRotated(screen_infos[0], screen_infos[1], (float)top_screen.left, - (float)top_screen.top, (float)top_screen.GetWidth(), - (float)top_screen.GetHeight()); + screen_infos[1], + static_cast(layout.cardboard.top_screen_right_eye + (layout.width / 2)), + top_screen_top, top_screen_width, top_screen_height); + break; + } + case Settings::StereoRenderOption::Anaglyph: + case Settings::StereoRenderOption::Interlaced: + case Settings::StereoRenderOption::ReverseInterlaced: { + DrawSingleScreenStereoRotated(screen_infos[0], screen_infos[1], top_screen_left, + top_screen_top, top_screen_width, top_screen_height); + break; + } } } else { - if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Off) { + switch (Settings::values.render_3d.GetValue()) { + case Settings::StereoRenderOption::Off: { int eye = static_cast(Settings::values.mono_render_option.GetValue()); - DrawSingleScreen(screen_infos[eye], (float)top_screen.left, (float)top_screen.top, - (float)top_screen.GetWidth(), (float)top_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::SideBySide) { - DrawSingleScreen(screen_infos[0], (float)top_screen.left / 2, (float)top_screen.top, - (float)top_screen.GetWidth() / 2, (float)top_screen.GetHeight()); + DrawSingleScreen(screen_infos[eye], top_screen_left, top_screen_top, top_screen_width, + top_screen_height); + break; + } + case Settings::StereoRenderOption::SideBySide: { + DrawSingleScreen(screen_infos[0], top_screen_left / 2, top_screen_top, + top_screen_width / 2, top_screen_height); glUniform1i(uniform_layer, 1); DrawSingleScreen(screen_infos[1], - ((float)top_screen.left / 2) + ((float)layout.width / 2), - (float)top_screen.top, (float)top_screen.GetWidth() / 2, - (float)top_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::CardboardVR) { - DrawSingleScreen(screen_infos[0], layout.top_screen.left, layout.top_screen.top, - layout.top_screen.GetWidth(), layout.top_screen.GetHeight()); + static_cast((top_screen_left / 2) + (layout.width / 2)), + top_screen_top, top_screen_width / 2, top_screen_height); + break; + } + case Settings::StereoRenderOption::CardboardVR: { + DrawSingleScreen(screen_infos[0], (float)top_screen.left, top_screen_top, + top_screen_width, top_screen_height); glUniform1i(uniform_layer, 1); DrawSingleScreen( - screen_infos[1], layout.cardboard.top_screen_right_eye + ((float)layout.width / 2), - layout.top_screen.top, layout.top_screen.GetWidth(), layout.top_screen.GetHeight()); - } else if (stereo_single_screen) { - DrawSingleScreenStereo(screen_infos[0], screen_infos[1], (float)top_screen.left, - (float)top_screen.top, (float)top_screen.GetWidth(), - (float)top_screen.GetHeight()); + screen_infos[1], + static_cast(layout.cardboard.top_screen_right_eye + (layout.width / 2)), + top_screen_top, top_screen_width, top_screen_height); + break; + } + case Settings::StereoRenderOption::Anaglyph: + case Settings::StereoRenderOption::Interlaced: + case Settings::StereoRenderOption::ReverseInterlaced: { + DrawSingleScreenStereo(screen_infos[0], screen_infos[1], top_screen_left, + top_screen_top, top_screen_width, top_screen_height); + break; + } } } } void RendererOpenGL::DrawBottomScreen(const Layout::FramebufferLayout& layout, - const Common::Rectangle& bottom_screen, - const bool stereo_single_screen) { + const Common::Rectangle& bottom_screen) { if (!layout.bottom_screen_enabled) { return; } + const float bottom_screen_left = static_cast(bottom_screen.left); + const float bottom_screen_top = static_cast(bottom_screen.top); + const float bottom_screen_width = static_cast(bottom_screen.GetWidth()); + const float bottom_screen_height = static_cast(bottom_screen.GetHeight()); + if (layout.is_rotated) { - if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Off) { - DrawSingleScreenRotated(screen_infos[2], (float)bottom_screen.left, - (float)bottom_screen.top, (float)bottom_screen.GetWidth(), - (float)bottom_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::SideBySide) { - DrawSingleScreenRotated(screen_infos[2], (float)bottom_screen.left / 2, - (float)bottom_screen.top, (float)bottom_screen.GetWidth() / 2, - (float)bottom_screen.GetHeight()); + switch (Settings::values.render_3d.GetValue()) { + case Settings::StereoRenderOption::Off: { + DrawSingleScreenRotated(screen_infos[2], bottom_screen_left, bottom_screen_top, + bottom_screen_width, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::SideBySide: { + DrawSingleScreenRotated(screen_infos[2], bottom_screen_left / 2, bottom_screen_top, + bottom_screen_width / 2, bottom_screen_height); glUniform1i(uniform_layer, 1); - DrawSingleScreenRotated(screen_infos[2], - ((float)bottom_screen.left / 2) + ((float)layout.width / 2), - (float)bottom_screen.top, (float)bottom_screen.GetWidth() / 2, - (float)bottom_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::CardboardVR) { - DrawSingleScreenRotated(screen_infos[2], layout.bottom_screen.left, - layout.bottom_screen.top, layout.bottom_screen.GetWidth(), - layout.bottom_screen.GetHeight()); + DrawSingleScreenRotated( + screen_infos[2], static_cast((bottom_screen_left / 2) + (layout.width / 2)), + bottom_screen_top, bottom_screen_width / 2, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::CardboardVR: { + DrawSingleScreenRotated(screen_infos[2], bottom_screen_left, bottom_screen_top, + bottom_screen_width, bottom_screen_height); glUniform1i(uniform_layer, 1); - DrawSingleScreenRotated(screen_infos[2], - layout.cardboard.bottom_screen_right_eye + - ((float)layout.width / 2), - layout.bottom_screen.top, layout.bottom_screen.GetWidth(), - layout.bottom_screen.GetHeight()); - } else if (stereo_single_screen) { - DrawSingleScreenStereoRotated(screen_infos[2], screen_infos[2], - (float)bottom_screen.left, (float)bottom_screen.top, - (float)bottom_screen.GetWidth(), - (float)bottom_screen.GetHeight()); + DrawSingleScreenRotated( + screen_infos[2], + static_cast(layout.cardboard.bottom_screen_right_eye + (layout.width / 2)), + bottom_screen_top, bottom_screen_width, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::Anaglyph: + case Settings::StereoRenderOption::Interlaced: + case Settings::StereoRenderOption::ReverseInterlaced: { + DrawSingleScreenStereoRotated(screen_infos[2], screen_infos[2], bottom_screen_left, + bottom_screen_top, bottom_screen_width, + bottom_screen_height); + break; + } } } else { - if (Settings::values.render_3d.GetValue() == Settings::StereoRenderOption::Off) { - DrawSingleScreen(screen_infos[2], (float)bottom_screen.left, (float)bottom_screen.top, - (float)bottom_screen.GetWidth(), (float)bottom_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::SideBySide) { - DrawSingleScreen(screen_infos[2], (float)bottom_screen.left / 2, - (float)bottom_screen.top, (float)bottom_screen.GetWidth() / 2, - (float)bottom_screen.GetHeight()); + switch (Settings::values.render_3d.GetValue()) { + case Settings::StereoRenderOption::Off: { + DrawSingleScreen(screen_infos[2], bottom_screen_left, bottom_screen_top, + bottom_screen_width, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::SideBySide: { + DrawSingleScreen(screen_infos[2], bottom_screen_left / 2, bottom_screen_top, + bottom_screen_width / 2, bottom_screen_height); glUniform1i(uniform_layer, 1); DrawSingleScreen(screen_infos[2], - ((float)bottom_screen.left / 2) + ((float)layout.width / 2), - (float)bottom_screen.top, (float)bottom_screen.GetWidth() / 2, - (float)bottom_screen.GetHeight()); - } else if (Settings::values.render_3d.GetValue() == - Settings::StereoRenderOption::CardboardVR) { - DrawSingleScreen(screen_infos[2], layout.bottom_screen.left, layout.bottom_screen.top, - layout.bottom_screen.GetWidth(), layout.bottom_screen.GetHeight()); + static_cast((bottom_screen_left / 2) + (layout.width / 2)), + bottom_screen_top, bottom_screen_width / 2, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::CardboardVR: { + DrawSingleScreen(screen_infos[2], (float)layout.bottom_screen.left, bottom_screen_top, + bottom_screen_width, bottom_screen_height); glUniform1i(uniform_layer, 1); - DrawSingleScreen(screen_infos[2], - layout.cardboard.bottom_screen_right_eye + ((float)layout.width / 2), - layout.bottom_screen.top, layout.bottom_screen.GetWidth(), - layout.bottom_screen.GetHeight()); - } else if (stereo_single_screen) { - DrawSingleScreenStereo(screen_infos[2], screen_infos[2], (float)bottom_screen.left, - (float)bottom_screen.top, (float)bottom_screen.GetWidth(), - (float)bottom_screen.GetHeight()); + DrawSingleScreen( + screen_infos[2], + static_cast(layout.cardboard.bottom_screen_right_eye + (layout.width / 2)), + bottom_screen_top, bottom_screen_width, bottom_screen_height); + break; + } + case Settings::StereoRenderOption::Anaglyph: + case Settings::StereoRenderOption::Interlaced: + case Settings::StereoRenderOption::ReverseInterlaced: { + DrawSingleScreenStereo(screen_infos[2], screen_infos[2], bottom_screen_left, + bottom_screen_top, bottom_screen_width, bottom_screen_height); + break; + } } } } diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index f3beb3a35..9969723f4 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -84,10 +84,9 @@ private: void ApplySecondLayerOpacity(); void ResetSecondLayerOpacity(); void DrawBottomScreen(const Layout::FramebufferLayout& layout, - const Common::Rectangle& bottom_screen, - const bool stereo_single_screen); + const Common::Rectangle& bottom_screen); void DrawTopScreen(const Layout::FramebufferLayout& layout, - const Common::Rectangle& top_screen, const bool stereo_single_screen); + const Common::Rectangle& top_screen); void DrawSingleScreenRotated(const ScreenInfo& screen_info, float x, float y, float w, float h); void DrawSingleScreen(const ScreenInfo& screen_info, float x, float y, float w, float h); void DrawSingleScreenStereoRotated(const ScreenInfo& screen_info_l,