renderer_opengl: Allow usage of Stereoscopic 3D

This commit is contained in:
N00byKing 2018-04-06 15:25:13 +02:00
parent e4788130e5
commit 2814bbc3da
2 changed files with 23 additions and 9 deletions

View File

@ -103,12 +103,13 @@ void RendererOpenGL::SwapBuffers() {
OpenGLState prev_state = OpenGLState::GetCurState();
state.Apply();
for (int i : {0, 1}) {
const auto& framebuffer = GPU::g_regs.framebuffer_config[i];
for (int i : {0, 1, 2}) {
int fb_id = i == 2 ? 1 : 0;
const auto& framebuffer = GPU::g_regs.framebuffer_config[fb_id];
// Main LCD (0): 0x1ED02204, Sub LCD (1): 0x1ED02A04
u32 lcd_color_addr =
(i == 0) ? LCD_REG_INDEX(color_fill_top) : LCD_REG_INDEX(color_fill_bottom);
(fb_id == 0) ? LCD_REG_INDEX(color_fill_top) : LCD_REG_INDEX(color_fill_bottom);
lcd_color_addr = HW::VADDR_LCD + 4 * lcd_color_addr;
LCD::Regs::ColorFill color_fill = {0};
LCD::Read(color_fill.raw, lcd_color_addr);
@ -129,7 +130,7 @@ void RendererOpenGL::SwapBuffers() {
// performance problem.
ConfigureFramebufferTexture(screen_infos[i].texture, framebuffer);
}
LoadFBToScreenInfo(framebuffer, screen_infos[i]);
LoadFBToScreenInfo(framebuffer, screen_infos[i], i == 1);
// Resize the texture in case the framebuffer size has changed
screen_infos[i].texture.width = framebuffer.width;
@ -160,10 +161,12 @@ void RendererOpenGL::SwapBuffers() {
* Loads framebuffer from emulated memory into the active OpenGL texture.
*/
void RendererOpenGL::LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& framebuffer,
ScreenInfo& screen_info) {
ScreenInfo& screen_info, bool right_eye) {
const PAddr framebuffer_addr =
framebuffer.active_fb == 0 ? framebuffer.address_left1 : framebuffer.address_left2;
framebuffer.active_fb == 0
? (!right_eye ? framebuffer.address_left1 : framebuffer.address_right1)
: (!right_eye ? framebuffer.address_left2 : framebuffer.address_right2);
LOG_TRACE(Render_OpenGL, "0x%08x bytes from 0x%08x(%dx%d), fmt %x",
framebuffer.stride * framebuffer.height, framebuffer_addr, (int)framebuffer.width,
@ -397,11 +400,22 @@ void RendererOpenGL::DrawScreens() {
if (layout.top_screen_enabled) {
DrawSingleScreenRotated(screen_infos[0], (float)top_screen.left, (float)top_screen.top,
(float)top_screen.GetWidth(), (float)top_screen.GetHeight());
if (Settings::values.toggle_3d) {
DrawSingleScreenRotated(
screen_infos[1], ((float)top_screen.left * 3) + (float)top_screen.GetWidth(),
(float)top_screen.top, (float)top_screen.GetWidth(), (float)top_screen.GetHeight());
}
}
if (layout.bottom_screen_enabled) {
DrawSingleScreenRotated(screen_infos[1], (float)bottom_screen.left,
DrawSingleScreenRotated(screen_infos[2], (float)bottom_screen.left,
(float)bottom_screen.top, (float)bottom_screen.GetWidth(),
(float)bottom_screen.GetHeight());
if (Settings::values.toggle_3d) {
DrawSingleScreenRotated(
screen_infos[2], ((float)bottom_screen.left * 3) + (float)bottom_screen.GetWidth(),
(float)bottom_screen.top, (float)bottom_screen.GetWidth(),
(float)bottom_screen.GetHeight());
}
}
m_current_frame++;

View File

@ -62,7 +62,7 @@ private:
// Loads framebuffer from emulated memory into the display information structure
void LoadFBToScreenInfo(const GPU::Regs::FramebufferConfig& framebuffer,
ScreenInfo& screen_info);
ScreenInfo& screen_info, bool right_eye);
// Fills active OpenGL texture with the given RGB color.
void LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, const TextureInfo& texture);
@ -76,7 +76,7 @@ private:
OGLProgram shader;
/// Display information for top and bottom screens respectively
std::array<ScreenInfo, 2> screen_infos;
std::array<ScreenInfo, 3> screen_infos;
// Shader uniform location indices
GLuint uniform_modelview_matrix;