|
|
@ -12,8 +12,8 @@ |
|
|
|
|
|
|
|
|
/// RendererOpenGL constructor
|
|
|
/// RendererOpenGL constructor
|
|
|
RendererOpenGL::RendererOpenGL() { |
|
|
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)); |
|
|
memset(m_fbo_depth_buffers, 0, sizeof(m_fbo_depth_buffers)); |
|
|
|
|
|
|
|
|
m_resolution_width = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); |
|
|
m_resolution_width = max(VideoCore::kScreenTopWidth, VideoCore::kScreenBottomWidth); |
|
|
@ -35,7 +35,7 @@ void RendererOpenGL::SwapBuffers() { |
|
|
m_render_window->MakeCurrent(); |
|
|
m_render_window->MakeCurrent(); |
|
|
|
|
|
|
|
|
// EFB->XFB copy
|
|
|
// 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.
|
|
|
// 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); |
|
|
common::Rect framebuffer_size(0, 0, m_resolution_width, m_resolution_height); |
|
|
RenderXFB(framebuffer_size, framebuffer_size); |
|
|
RenderXFB(framebuffer_size, framebuffer_size); |
|
|
@ -61,24 +61,40 @@ void RendererOpenGL::FlipFramebuffer(const u8* in, u8* out) { |
|
|
int in_coord = 0; |
|
|
int in_coord = 0; |
|
|
for (int x = 0; x < VideoCore::kScreenTopWidth; x++) { |
|
|
for (int x = 0; x < VideoCore::kScreenTopWidth; x++) { |
|
|
for (int y = VideoCore::kScreenTopHeight-1; y >= 0; y--) { |
|
|
for (int y = VideoCore::kScreenTopHeight-1; y >= 0; y--) { |
|
|
|
|
|
// TODO: Properly support other framebuffer formats
|
|
|
int out_coord = (x + y * VideoCore::kScreenTopWidth) * 3; |
|
|
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; |
|
|
in_coord+=3; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Renders external framebuffer (XFB) |
|
|
* Renders external framebuffer (XFB) |
|
|
* @param src_rect Source rectangle in XFB to copy |
|
|
* @param src_rect Source rectangle in XFB to copy |
|
|
* @param dst_rect Destination rectangle in output framebuffer to copy to |
|
|
* @param dst_rect Destination rectangle in output framebuffer to copy to |
|
|
*/ |
|
|
*/ |
|
|
void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& dst_rect) { |
|
|
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
|
|
|
// Blit the top framebuffer
|
|
|
// ------------------------
|
|
|
// ------------------------
|
|
|
@ -98,7 +114,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& |
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0); |
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0); |
|
|
|
|
|
|
|
|
// Blit
|
|
|
// 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_, |
|
|
dst_rect.x0_, dst_rect.y1_, dst_rect.x1_, dst_rect.y0_, |
|
|
GL_COLOR_BUFFER_BIT, GL_LINEAR); |
|
|
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
|
|
|
// Update textures with contents of XFB in RAM - bottom
|
|
|
glBindTexture(GL_TEXTURE_2D, m_xfb_texture_bottom); |
|
|
glBindTexture(GL_TEXTURE_2D, m_xfb_texture_bottom); |
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, VideoCore::kScreenTopWidth, VideoCore::kScreenTopHeight, |
|
|
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); |
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
|
|
|
|
|
// Render target is destination framebuffer
|
|
|
// Render target is destination framebuffer
|
|
|
@ -124,7 +140,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& |
|
|
|
|
|
|
|
|
// Blit
|
|
|
// Blit
|
|
|
int offset = (VideoCore::kScreenTopWidth - VideoCore::kScreenBottomWidth) / 2; |
|
|
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, |
|
|
offset, VideoCore::kScreenBottomHeight, VideoCore::kScreenBottomWidth + offset, 0, |
|
|
GL_COLOR_BUFFER_BIT, GL_LINEAR); |
|
|
GL_COLOR_BUFFER_BIT, GL_LINEAR); |
|
|
|
|
|
|
|
|
@ -133,7 +149,7 @@ void RendererOpenGL::RenderXFB(const common::Rect& src_rect, const common::Rect& |
|
|
|
|
|
|
|
|
/// Initialize the FBO
|
|
|
/// Initialize the FBO
|
|
|
void RendererOpenGL::InitFramebuffer() { |
|
|
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
|
|
|
// separate framebuffers
|
|
|
|
|
|
|
|
|
// Init the FBOs
|
|
|
// Init the FBOs
|
|
|
@ -146,12 +162,12 @@ void RendererOpenGL::InitFramebuffer() { |
|
|
for (int i = 0; i < kMaxFramebuffers; i++) { |
|
|
for (int i = 0; i < kMaxFramebuffers; i++) { |
|
|
// Generate color buffer storage
|
|
|
// Generate color buffer storage
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_rbo[i]); |
|
|
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); |
|
|
VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); |
|
|
|
|
|
|
|
|
// Generate depth buffer storage
|
|
|
// Generate depth buffer storage
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_depth_buffers[i]); |
|
|
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); |
|
|
VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight); |
|
|
|
|
|
|
|
|
// Attach the buffers
|
|
|
// Attach the buffers
|
|
|
@ -167,7 +183,7 @@ void RendererOpenGL::InitFramebuffer() { |
|
|
} else { |
|
|
} else { |
|
|
ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); |
|
|
ERROR_LOG(RENDER, "couldn't create OpenGL frame buffer"); |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s)
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind our frame buffer(s)
|
|
|
|
|
|
|
|
|
@ -175,8 +191,8 @@ void RendererOpenGL::InitFramebuffer() { |
|
|
// -------------------------------
|
|
|
// -------------------------------
|
|
|
|
|
|
|
|
|
// Create XFB textures
|
|
|
// 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
|
|
|
// Alocate video memorry for XFB textures
|
|
|
glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); |
|
|
glBindTexture(GL_TEXTURE_2D, m_xfb_texture_top); |
|
|
@ -192,13 +208,13 @@ void RendererOpenGL::InitFramebuffer() { |
|
|
// Create the FBO and attach color/depth textures
|
|
|
// Create the FBO and attach color/depth textures
|
|
|
glGenFramebuffers(1, &m_xfb_top); // Generate framebuffer
|
|
|
glGenFramebuffers(1, &m_xfb_top); // Generate framebuffer
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_top); |
|
|
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); |
|
|
m_xfb_texture_top, 0); |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
|
|
|
|
|
|
glGenFramebuffers(1, &m_xfb_bottom); // Generate framebuffer
|
|
|
glGenFramebuffers(1, &m_xfb_bottom); // Generate framebuffer
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_xfb_bottom); |
|
|
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); |
|
|
m_xfb_texture_bottom, 0); |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0); |
|
|
} |
|
|
} |
|
|
@ -214,7 +230,7 @@ void RendererOpenGL::RenderFramebuffer() { |
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0); |
|
|
glReadBuffer(GL_COLOR_ATTACHMENT0); |
|
|
|
|
|
|
|
|
// Blit
|
|
|
// 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); |
|
|
m_resolution_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); |
|
|
|
|
|
|
|
|
// Update the FPS count
|
|
|
// Update the FPS count
|
|
|
@ -230,7 +246,7 @@ void RendererOpenGL::RenderFramebuffer() { |
|
|
void RendererOpenGL::UpdateFramerate() { |
|
|
void RendererOpenGL::UpdateFramerate() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Set the emulator window to use for renderer |
|
|
* Set the emulator window to use for renderer |
|
|
* @param window EmuWindow handle to emulator window to use for rendering |
|
|
* @param window EmuWindow handle to emulator window to use for rendering |
|
|
*/ |
|
|
*/ |
|
|
@ -264,7 +280,7 @@ void RendererOpenGL::Init() { |
|
|
|
|
|
|
|
|
GLenum err = glewInit(); |
|
|
GLenum err = glewInit(); |
|
|
if (GLEW_OK != err) { |
|
|
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)); |
|
|
glewGetErrorString(err)); |
|
|
exit(-1); |
|
|
exit(-1); |
|
|
} |
|
|
} |
|
|
|