From b8c39d4e42629789fdc1a5ccd01756b03af575da Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Thu, 8 May 2014 16:09:55 +0200 Subject: [PATCH] ReadFramebuffer: Support sub rectangle --- GPU/GLES/Framebuffer.cpp | 30 +++++++++++++++++------------- GPU/GLES/Framebuffer.h | 11 ++++------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/GPU/GLES/Framebuffer.cpp b/GPU/GLES/Framebuffer.cpp index f365039a8c..c3be0c73e7 100644 --- a/GPU/GLES/Framebuffer.cpp +++ b/GPU/GLES/Framebuffer.cpp @@ -858,7 +858,7 @@ void FramebufferManager::DoSetRenderFrameBuffer() { bool updateVRAM = !(g_Config.iRenderingMode == FB_NON_BUFFERED_MODE || g_Config.iRenderingMode == FB_BUFFERED_MODE); if (updateVRAM && !vfb->memoryUpdated) { - ReadFramebufferToMemory(vfb, true); + ReadFramebufferToMemory(vfb, true, 0, 0, 480, 272); } // Use it as a render target. DEBUG_LOG(SCEGE, "Switching render target to FBO for %08x: %i x %i x %i ", vfb->fb_address, vfb->width, vfb->height, vfb->format); @@ -1118,7 +1118,7 @@ void FramebufferManager::CopyDisplayToOutput() { } } -void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync) { +void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h) { #ifndef USING_GLES2 if (sync) { PackFramebufferAsync_(NULL); // flush async just in case when we go for synchronous update @@ -1213,7 +1213,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s } vfb->memoryUpdated = true; - BlitFramebuffer_(vfb, nvfb); + BlitFramebuffer_(nvfb, x, y, vfb, x, y, w, h); // PackFramebufferSync_() - Synchronous pixel data transfer using glReadPixels // PackFramebufferAsync_() - Asynchronous pixel data transfer using glReadPixels with PBOs @@ -1234,7 +1234,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s // TODO: If glBlitFramebuffer is available, we can take a shortcut. If, in addition, the dimensions // are the same, we can use glCopyImageSubData. -void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFramebuffer *dst) { +void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h) { if (!dst->fbo) { ERROR_LOG_REPORT_ONCE(dstfbozero, SCEGE, "BlitFramebuffer_: dst->fbo == 0"); fbo_unbind(); @@ -1267,13 +1267,11 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFrameb glstate.viewport.set(0, 0, dst->width, dst->height); DisableState(); - // These coordinates are relative to the 6th and 7th arguments of DrawActiveTexture. - // Really need to revamp that interface. - float x = 0.0f; - float y = 0.0f; - float w = 480.0f; - float h = 272.0f; - DrawActiveTexture(0, x, y, w, h, 480.0f, 272.0f, false, 0.0f, 0.0f, 1.0f, 1.0f, draw2dprogram_); + // The first four coordinates are relative to the 6th and 7th arguments of DrawActiveTexture. + // Should maybe revamp that interface. + float srcW = src->width; + float srcH = src->height; + DrawActiveTexture(0, dstX, dstY, w, h, dst->width, dst->height, false, srcX / srcW, srcX / srcH, (srcX + w) / srcW, (srcY + h) / srcH, draw2dprogram_); glBindTexture(GL_TEXTURE_2D, 0); fbo_unbind(); @@ -1644,8 +1642,14 @@ void FramebufferManager::DecimateFBOs() { VirtualFramebuffer *vfb = vfbs_[i]; int age = frameLastFramebufUsed - std::max(vfb->last_frame_render, vfb->last_frame_used); - if (updateVram && age == 0 && !vfb->memoryUpdated) - ReadFramebufferToMemory(vfb); + if (updateVram && age == 0 && !vfb->memoryUpdated) { +#ifdef USING_GLES2 + bool sync = true; +#else + bool sync = false; +#endif + ReadFramebufferToMemory(vfb, sync, 0, 0, vfb->width, vfb->height); + } if (vfb == displayFramebuf_ || vfb == prevDisplayFramebuf_ || vfb == prevPrevDisplayFramebuf_) { continue; diff --git a/GPU/GLES/Framebuffer.h b/GPU/GLES/Framebuffer.h index e3f59da8ed..8fb57498d8 100644 --- a/GPU/GLES/Framebuffer.h +++ b/GPU/GLES/Framebuffer.h @@ -165,11 +165,8 @@ public: // read framebuffers is on, in which case this should always return false). bool NotifyBlockTransfer(u32 dstBasePtr, int dstStride, int dstX, int dstY, u32 srcBasePtr, int srcStride, int srcX, int srcY, int w, int h, int bpp); -#ifdef USING_GLES2 - void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync = true); -#else - void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync = false); -#endif + // Reads a rectangular subregion of a framebuffer to the right position in its backing memory. + void ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync, int x, int y, int w, int h); // TODO: Break out into some form of FBO manager VirtualFramebuffer *GetVFBAt(u32 addr); @@ -226,8 +223,8 @@ private: VirtualFramebuffer *currentRenderVfb_; - // Used by ReadFramebufferToMemory - void BlitFramebuffer_(VirtualFramebuffer *src, VirtualFramebuffer *dst); + // Used by ReadFramebufferToMemory and later framebuffer block copies + void BlitFramebuffer_(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h); #ifndef USING_GLES2 void PackFramebufferAsync_(VirtualFramebuffer *vfb); #endif