diff options
Diffstat (limited to 'src/video_core')
-rw-r--r-- | src/video_core/gpu_debugger.h | 11 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 62 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.h | 7 |
3 files changed, 50 insertions, 30 deletions
diff --git a/src/video_core/gpu_debugger.h b/src/video_core/gpu_debugger.h index 5d909beba..d92ceaa72 100644 --- a/src/video_core/gpu_debugger.h +++ b/src/video_core/gpu_debugger.h @@ -50,7 +50,7 @@ public: virtual void GXCommandProcessed(int total_command_count) { const GSP_GPU::GXCommand& cmd = observed->ReadGXCommandHistory(total_command_count-1); - ERROR_LOG(GSP, "Received command: id=%x", cmd.id); + ERROR_LOG(GSP, "Received command: id=%x", (int)cmd.id.Value()); } /** @@ -78,11 +78,13 @@ public: void GXCommandProcessed(u8* command_data) { + if (observers.empty()) + return; + gx_command_history.push_back(GSP_GPU::GXCommand()); GSP_GPU::GXCommand& cmd = gx_command_history[gx_command_history.size()-1]; - const int cmd_length = sizeof(GSP_GPU::GXCommand); - memcpy(cmd.data, command_data, cmd_length); + memcpy(&cmd, command_data, sizeof(GSP_GPU::GXCommand)); ForEachObserver([this](DebuggerObserver* observer) { observer->GXCommandProcessed(this->gx_command_history.size()); @@ -91,6 +93,9 @@ public: void CommandListCalled(u32 address, u32* command_list, u32 size_in_words) { + if (observers.empty()) + return; + PicaCommandList cmdlist; for (u32* parse_pointer = command_list; parse_pointer < command_list + size_in_words;) { diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 70af47c59..d0a8ec1da 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -12,8 +12,8 @@ /// RendererOpenGL constructor RendererOpenGL::RendererOpenGL() { - memset(m_fbo, 0, sizeof(m_fbo)); - memset(m_fbo_rbo, 0, sizeof(m_fbo_rbo)); + memset(m_fbo, 0, sizeof(m_fbo)); + memset(m_fbo_rbo, 0, sizeof(m_fbo_rbo)); memset(m_fbo_depth_buffers, 0, sizeof(m_fbo_depth_buffers)); m_resolution_width = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); @@ -35,7 +35,7 @@ void RendererOpenGL::SwapBuffers() { m_render_window->MakeCurrent(); // EFB->XFB copy - // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some + // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some // register write We're also treating both framebuffers as a single one in OpenGL. common::Rect framebuffer_size(0, 0, m_resolution_width, m_resolution_height); RenderXFB(framebuffer_size, framebuffer_size); @@ -61,24 +61,40 @@ void RendererOpenGL::FlipFramebuffer(const u8* in, u8* out) { int in_coord = 0; for (int x = 0; x < VideoCore::kScreenTopWidth; x++) { for (int y = VideoCore::kScreenTopHeight-1; y >= 0; y--) { + // TODO: Properly support other framebuffer formats int out_coord = (x + y * VideoCore::kScreenTopWidth) * 3; - out[out_coord] = in[in_coord]; - out[out_coord + 1] = in[in_coord + 1]; - out[out_coord + 2] = in[in_coord + 2]; + out[out_coord] = in[in_coord]; // blue? + out[out_coord + 1] = in[in_coord + 1]; // green? + out[out_coord + 2] = in[in_coord + 2]; // red? in_coord+=3; } } } -/** +/** * Renders external framebuffer (XFB) * @param src_rect Source rectangle in XFB to copy * @param dst_rect Destination rectangle in output framebuffer to copy to */ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& dst_rect) { - FlipFramebuffer(GPU::GetFramebufferPointer(GPU::g_regs.framebuffer_top_left_1), m_xfb_top_flipped); - FlipFramebuffer(GPU::GetFramebufferPointer(GPU::g_regs.framebuffer_sub_left_1), m_xfb_bottom_flipped); + const auto& framebuffer_top = GPU::g_regs.Get<GPU::Regs::FramebufferTop>(); + const auto& framebuffer_sub = GPU::g_regs.Get<GPU::Regs::FramebufferBottom>(); + const u32 active_fb_top = (framebuffer_top.active_fb == 1) + ? framebuffer_top.address_left2 + : framebuffer_top.address_left1; + const u32 active_fb_sub = (framebuffer_sub.active_fb == 1) + ? framebuffer_sub.address_left2 + : framebuffer_sub.address_left1; + + DEBUG_LOG(GPU, "RenderXFB: 0x%08x bytes from 0x%08x(%dx%d), fmt %x", + framebuffer_top.stride * framebuffer_top.height, + GPU::GetFramebufferAddr(active_fb_top), (int)framebuffer_top.width, + (int)framebuffer_top.height, (int)framebuffer_top.format); + + // TODO: This should consider the GPU registers for framebuffer width, height and stride. + FlipFramebuffer(GPU::GetFramebufferPointer(active_fb_top), m_xfb_top_flipped); + FlipFramebuffer(GPU::GetFramebufferPointer(active_fb_sub), m_xfb_bottom_flipped); // Blit the top framebuffer // ------------------------ @@ -98,7 +114,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& glReadBuffer(GL_COLOR_ATTACHMENT0); // Blit - glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, + glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, GL_COLOR_BUFFER_BIT, GL_LINEAR); @@ -110,7 +126,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& // Update textures with contents of XFB in RAM - bottom glBindTexture(GL_TEXTURE_2D, m_xfb_texture_bottom); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, - GL_RGB, GL_UNSIGNED_BYTE, m_xfb_bottom_flipped); + GL_BGR, GL_UNSIGNED_BYTE, m_xfb_bottom_flipped); glBindTexture(GL_TEXTURE_2D, 0); // Render target is destination framebuffer @@ -124,7 +140,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& // Blit int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2; - glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight, + glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight, offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0, GL_COLOR_BUFFER_BIT, GL_LINEAR); @@ -133,7 +149,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& /// Initialize the FBO void RendererOpenGL::InitFramebuffer() { - // TODO(bunnei): This should probably be implemented with the top screen and bottom screen as + // TODO(bunnei): This should probably be implemented with the top screen and bottom screen as // separate framebuffers // Init the FBOs @@ -146,12 +162,12 @@ void RendererOpenGL::InitFramebuffer() { for (int i = 0; i < kMaxFramebuffers; i++) { // Generate color buffer storage glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_rbo[i]); - glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth, + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); // Generate depth buffer storage glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_depth_buffers[i]); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth, + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); // Attach the buffers @@ -167,7 +183,7 @@ void RendererOpenGL::InitFramebuffer() { } else { ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); exit(1); - } + } } glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s) @@ -175,8 +191,8 @@ void RendererOpenGL::InitFramebuffer() { // ------------------------------- // Create XFB textures - glGenTextures(1, &m_xfb_texture_top); - glGenTextures(1, &m_xfb_texture_bottom); + glGenTextures(1, &m_xfb_texture_top); + glGenTextures(1, &m_xfb_texture_bottom); // Alocate video memorry for XFB textures glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); @@ -192,13 +208,13 @@ void RendererOpenGL::InitFramebuffer() { // Create the FBO and attach color/depth textures glGenFramebuffers(1, &m_xfb_top); // Generate framebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_top); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_xfb_texture_top, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); glGenFramebuffers(1, &m_xfb_bottom); // Generate framebuffer glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_bottom); - glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_xfb_texture_bottom, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0); } @@ -214,7 +230,7 @@ void RendererOpenGL::RenderFramebuffer() { glReadBuffer(GL_COLOR_ATTACHMENT0); // Blit - glBlitFramebuffer(0, 0, m_resolution_width, m_resolution_height, 0, 0, m_resolution_width, + glBlitFramebuffer(0, 0, m_resolution_width, m_resolution_height, 0, 0, m_resolution_width, m_resolution_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); // Update the FPS count @@ -230,7 +246,7 @@ void RendererOpenGL::RenderFramebuffer() { void RendererOpenGL::UpdateFramerate() { } -/** +/** * Set the emulator window to use for renderer * @param window EmuWindow handle to emulator window to use for rendering */ @@ -264,7 +280,7 @@ void RendererOpenGL::Init() { GLenum err = glewInit(); if (GLEW_OK != err) { - ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...", + ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...", glewGetErrorString(err)); exit(-1); } diff --git a/src/video_core/renderer_opengl/renderer_opengl.h b/src/video_core/renderer_opengl/renderer_opengl.h index dd811cad6..30f4febe0 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.h +++ b/src/video_core/renderer_opengl/renderer_opengl.h @@ -84,7 +84,6 @@ private: // "Flipped" framebuffers translate scanlines from native 3DS left-to-right to top-to-bottom // as OpenGL expects them in a texture. There probably is a more efficient way of doing this: - u8 m_xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth * 4]; - u8 m_xfb_bottom_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopWidth * 4]; - -};
\ No newline at end of file + u8 m_xfb_top_flipped[VideoCore::kScreenTopWidth * VideoCore::kScreenTopHeight * 4]; + u8 m_xfb_bottom_flipped[VideoCore::kScreenBottomWidth * VideoCore::kScreenBottomHeight * 4]; +}; |