diff options
| author | 2014-07-16 11:24:09 +0200 | |
|---|---|---|
| committer | 2014-07-23 00:33:08 +0200 | |
| commit | 75775e9ef41248592cb2c27ae69737e46499e705 (patch) | |
| tree | 9bff36e351d33fd3dcf40ccfb17e23f4916a23a3 /src/video_core | |
| parent | GPU: Make framebuffer code format-aware. (diff) | |
| download | yuzu-75775e9ef41248592cb2c27ae69737e46499e705.tar.gz yuzu-75775e9ef41248592cb2c27ae69737e46499e705.tar.xz yuzu-75775e9ef41248592cb2c27ae69737e46499e705.zip | |
GPU: Make use of RegisterSet.
Diffstat (limited to 'src/video_core')
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 047c69185..8d9d61ae8 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -12,8 +12,8 @@ | |||
| 12 | 12 | ||
| 13 | /// RendererOpenGL constructor | 13 | /// RendererOpenGL constructor |
| 14 | RendererOpenGL::RendererOpenGL() { | 14 | RendererOpenGL::RendererOpenGL() { |
| 15 | memset(m_fbo, 0, sizeof(m_fbo)); | 15 | memset(m_fbo, 0, sizeof(m_fbo)); |
| 16 | memset(m_fbo_rbo, 0, sizeof(m_fbo_rbo)); | 16 | memset(m_fbo_rbo, 0, sizeof(m_fbo_rbo)); |
| 17 | memset(m_fbo_depth_buffers, 0, sizeof(m_fbo_depth_buffers)); | 17 | memset(m_fbo_depth_buffers, 0, sizeof(m_fbo_depth_buffers)); |
| 18 | 18 | ||
| 19 | m_resolution_width = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); | 19 | m_resolution_width = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); |
| @@ -35,7 +35,7 @@ void RendererOpenGL::SwapBuffers() { | |||
| 35 | m_render_window->MakeCurrent(); | 35 | m_render_window->MakeCurrent(); |
| 36 | 36 | ||
| 37 | // EFB->XFB copy | 37 | // EFB->XFB copy |
| 38 | // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some | 38 | // TODO(bunnei): This is a hack and does not belong here. The copy should be triggered by some |
| 39 | // register write We're also treating both framebuffers as a single one in OpenGL. | 39 | // register write We're also treating both framebuffers as a single one in OpenGL. |
| 40 | common::Rect framebuffer_size(0, 0, m_resolution_width, m_resolution_height); | 40 | common::Rect framebuffer_size(0, 0, m_resolution_width, m_resolution_height); |
| 41 | RenderXFB(framebuffer_size, framebuffer_size); | 41 | RenderXFB(framebuffer_size, framebuffer_size); |
| @@ -71,24 +71,26 @@ void RendererOpenGL::FlipFramebuffer(const u8* in, u8* out) { | |||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | /** | 74 | /** |
| 75 | * Renders external framebuffer (XFB) | 75 | * Renders external framebuffer (XFB) |
| 76 | * @param src_rect Source rectangle in XFB to copy | 76 | * @param src_rect Source rectangle in XFB to copy |
| 77 | * @param dst_rect Destination rectangle in output framebuffer to copy to | 77 | * @param dst_rect Destination rectangle in output framebuffer to copy to |
| 78 | */ | 78 | */ |
| 79 | void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& dst_rect) { | 79 | void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& dst_rect) { |
| 80 | 80 | ||
| 81 | const u32 active_fb_top = (GPU::g_regs.top_framebuffer.active_fb == 1) | 81 | const auto& framebuffer_top = GPU::g_regs.Get<GPU::Regs::FramebufferTop>(); |
| 82 | ? GPU::g_regs.framebuffer_top_left_2 | 82 | const auto& framebuffer_sub = GPU::g_regs.Get<GPU::Regs::FramebufferBottom>(); |
| 83 | : GPU::g_regs.framebuffer_top_left_1; | 83 | const u32 active_fb_top = (framebuffer_top.data.active_fb == 1) |
| 84 | const u32 active_fb_sub = (GPU::g_regs.sub_framebuffer.active_fb == 1) | 84 | ? framebuffer_top.data.address_left2 |
| 85 | ? GPU::g_regs.framebuffer_sub_left_2 | 85 | : framebuffer_top.data.address_left1; |
| 86 | : GPU::g_regs.framebuffer_sub_left_1; | 86 | const u32 active_fb_sub = (framebuffer_sub.data.active_fb == 1) |
| 87 | ? framebuffer_sub.data.address_left2 | ||
| 88 | : framebuffer_sub.data.address_left1; | ||
| 87 | 89 | ||
| 88 | DEBUG_LOG(GPU, "RenderXFB: %x bytes from %x(%xx%x), fmt %x", | 90 | DEBUG_LOG(GPU, "RenderXFB: %x bytes from %x(%xx%x), fmt %x", |
| 89 | GPU::g_regs.top_framebuffer.stride * GPU::g_regs.top_framebuffer.height, | 91 | framebuffer_top.data.stride * framebuffer_top.data.height, |
| 90 | GPU::GetFramebufferAddr(GPU::g_regs.framebuffer_top_left_1), (int)GPU::g_regs.top_framebuffer.width, | 92 | GPU::GetFramebufferAddr(active_fb_top), (int)framebuffer_top.data.width, |
| 91 | (int)GPU::g_regs.top_framebuffer.height, (int)GPU::g_regs.top_framebuffer.format); | 93 | (int)framebuffer_top.data.height, (int)framebuffer_top.data.format); |
| 92 | 94 | ||
| 93 | // TODO: This should consider the GPU registers for framebuffer width, height and stride. | 95 | // TODO: This should consider the GPU registers for framebuffer width, height and stride. |
| 94 | FlipFramebuffer(GPU::GetFramebufferPointer(active_fb_top), m_xfb_top_flipped); | 96 | FlipFramebuffer(GPU::GetFramebufferPointer(active_fb_top), m_xfb_top_flipped); |
| @@ -112,7 +114,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& | |||
| 112 | glReadBuffer(GL_COLOR_ATTACHMENT0); | 114 | glReadBuffer(GL_COLOR_ATTACHMENT0); |
| 113 | 115 | ||
| 114 | // Blit | 116 | // Blit |
| 115 | glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, | 117 | glBlitFramebuffer(src_rect.x0_, src_rect.y0_, src_rect.x1_, src_rect.y1_, |
| 116 | dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, | 118 | dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, |
| 117 | GL_COLOR_BUFFER_BIT, GL_LINEAR); | 119 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 118 | 120 | ||
| @@ -138,7 +140,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& | |||
| 138 | 140 | ||
| 139 | // Blit | 141 | // Blit |
| 140 | int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2; | 142 | int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2; |
| 141 | glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight, | 143 | glBlitFramebuffer(0,0, VideoCore::kScreenBottomWidth, VideoCore::kScreenBottomHeight, |
| 142 | offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0, | 144 | offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0, |
| 143 | GL_COLOR_BUFFER_BIT, GL_LINEAR); | 145 | GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 144 | 146 | ||
| @@ -147,7 +149,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& | |||
| 147 | 149 | ||
| 148 | /// Initialize the FBO | 150 | /// Initialize the FBO |
| 149 | void RendererOpenGL::InitFramebuffer() { | 151 | void RendererOpenGL::InitFramebuffer() { |
| 150 | // TODO(bunnei): This should probably be implemented with the top screen and bottom screen as | 152 | // TODO(bunnei): This should probably be implemented with the top screen and bottom screen as |
| 151 | // separate framebuffers | 153 | // separate framebuffers |
| 152 | 154 | ||
| 153 | // Init the FBOs | 155 | // Init the FBOs |
| @@ -160,12 +162,12 @@ void RendererOpenGL::InitFramebuffer() { | |||
| 160 | for (int i = 0; i < kMaxFramebuffers; i++) { | 162 | for (int i = 0; i < kMaxFramebuffers; i++) { |
| 161 | // Generate color buffer storage | 163 | // Generate color buffer storage |
| 162 | glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_rbo[i]); | 164 | glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_rbo[i]); |
| 163 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth, | 165 | glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, VideoCore::kScreenTopWidth, |
| 164 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); | 166 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); |
| 165 | 167 | ||
| 166 | // Generate depth buffer storage | 168 | // Generate depth buffer storage |
| 167 | glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_depth_buffers[i]); | 169 | glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_depth_buffers[i]); |
| 168 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth, | 170 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, VideoCore::kScreenTopWidth, |
| 169 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); | 171 | VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); |
| 170 | 172 | ||
| 171 | // Attach the buffers | 173 | // Attach the buffers |
| @@ -181,7 +183,7 @@ void RendererOpenGL::InitFramebuffer() { | |||
| 181 | } else { | 183 | } else { |
| 182 | ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); | 184 | ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); |
| 183 | exit(1); | 185 | exit(1); |
| 184 | } | 186 | } |
| 185 | } | 187 | } |
| 186 | glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s) | 188 | glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s) |
| 187 | 189 | ||
| @@ -189,8 +191,8 @@ void RendererOpenGL::InitFramebuffer() { | |||
| 189 | // ------------------------------- | 191 | // ------------------------------- |
| 190 | 192 | ||
| 191 | // Create XFB textures | 193 | // Create XFB textures |
| 192 | glGenTextures(1, &m_xfb_texture_top); | 194 | glGenTextures(1, &m_xfb_texture_top); |
| 193 | glGenTextures(1, &m_xfb_texture_bottom); | 195 | glGenTextures(1, &m_xfb_texture_bottom); |
| 194 | 196 | ||
| 195 | // Alocate video memorry for XFB textures | 197 | // Alocate video memorry for XFB textures |
| 196 | glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); | 198 | glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); |
| @@ -206,13 +208,13 @@ void RendererOpenGL::InitFramebuffer() { | |||
| 206 | // Create the FBO and attach color/depth textures | 208 | // Create the FBO and attach color/depth textures |
| 207 | glGenFramebuffers(1, &m_xfb_top); // Generate framebuffer | 209 | glGenFramebuffers(1, &m_xfb_top); // Generate framebuffer |
| 208 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_top); | 210 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_top); |
| 209 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 211 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 210 | m_xfb_texture_top, 0); | 212 | m_xfb_texture_top, 0); |
| 211 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 213 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 212 | 214 | ||
| 213 | glGenFramebuffers(1, &m_xfb_bottom); // Generate framebuffer | 215 | glGenFramebuffers(1, &m_xfb_bottom); // Generate framebuffer |
| 214 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_bottom); | 216 | glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_bottom); |
| 215 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, | 217 | glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, |
| 216 | m_xfb_texture_bottom, 0); | 218 | m_xfb_texture_bottom, 0); |
| 217 | glBindFramebuffer(GL_FRAMEBUFFER, 0); | 219 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 218 | } | 220 | } |
| @@ -228,7 +230,7 @@ void RendererOpenGL::RenderFramebuffer() { | |||
| 228 | glReadBuffer(GL_COLOR_ATTACHMENT0); | 230 | glReadBuffer(GL_COLOR_ATTACHMENT0); |
| 229 | 231 | ||
| 230 | // Blit | 232 | // Blit |
| 231 | glBlitFramebuffer(0, 0, m_resolution_width, m_resolution_height, 0, 0, m_resolution_width, | 233 | glBlitFramebuffer(0, 0, m_resolution_width, m_resolution_height, 0, 0, m_resolution_width, |
| 232 | m_resolution_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); | 234 | m_resolution_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); |
| 233 | 235 | ||
| 234 | // Update the FPS count | 236 | // Update the FPS count |
| @@ -244,7 +246,7 @@ void RendererOpenGL::RenderFramebuffer() { | |||
| 244 | void RendererOpenGL::UpdateFramerate() { | 246 | void RendererOpenGL::UpdateFramerate() { |
| 245 | } | 247 | } |
| 246 | 248 | ||
| 247 | /** | 249 | /** |
| 248 | * Set the emulator window to use for renderer | 250 | * Set the emulator window to use for renderer |
| 249 | * @param window EmuWindow handle to emulator window to use for rendering | 251 | * @param window EmuWindow handle to emulator window to use for rendering |
| 250 | */ | 252 | */ |
| @@ -278,7 +280,7 @@ void RendererOpenGL::Init() { | |||
| 278 | 280 | ||
| 279 | GLenum err = glewInit(); | 281 | GLenum err = glewInit(); |
| 280 | if (GLEW_OK != err) { | 282 | if (GLEW_OK != err) { |
| 281 | ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...", | 283 | ERROR_LOG(RENDER, "Failed to initialize GLEW! Error message: \"%s\". Exiting...", |
| 282 | glewGetErrorString(err)); | 284 | glewGetErrorString(err)); |
| 283 | exit(-1); | 285 | exit(-1); |
| 284 | } | 286 | } |