From da741e294ee1ee04656d80fb2bf0cd3ebb8b846a Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 18 Mar 2016 19:26:43 +0100 Subject: [PATCH] gsdx-ogl: optimize GPU->CPU memory transfer size Might help for snow engine game (a little) Previous code use to read the full texture whereas now it will be limited to the size of the useful data. --- plugins/GSdx/GSTextureCacheOGL.cpp | 3 ++- plugins/GSdx/GSTextureOGL.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/GSdx/GSTextureCacheOGL.cpp b/plugins/GSdx/GSTextureCacheOGL.cpp index 9f137e55e4..ee89c6966d 100644 --- a/plugins/GSdx/GSTextureCacheOGL.cpp +++ b/plugins/GSdx/GSTextureCacheOGL.cpp @@ -83,8 +83,9 @@ void GSTextureCacheOGL::Read(Target* t, const GSVector4i& r) if(GSTexture* offscreen = m_renderer->m_dev->CopyOffscreen(t->m_texture, src, r.width(), r.height(), fmt, ps_shader)) { GSTexture::GSMap m; + GSVector4i r_offscreen(0, 0, r.width(), r.height()); - if(offscreen->Map(m)) + if(offscreen->Map(m, &r_offscreen)) { // TODO: block level write diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index a3db8b9a30..1ef622896e 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -396,6 +396,7 @@ bool GSTextureOGL::Map(GSMap& m, const GSVector4i* r) #if 0 // Maybe it is as good as the code below. I don't know + // With openGL 4.5 you can use glGetTextureSubImage glGetTextureImage(m_texture_id, GL_TEX_LEVEL_0, m_int_format, m_int_type, 1024*1024*16, m_local_buffer); @@ -406,7 +407,11 @@ bool GSTextureOGL::Map(GSMap& m, const GSVector4i* r) glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture_id, 0); glPixelStorei(GL_PACK_ALIGNMENT, m_int_alignment); - glReadPixels(0, 0, m_size.x, m_size.y, m_int_format, m_int_type, m_local_buffer); + if (r) + glReadPixels(r->x, r->y, r->width(), r->height(), m_int_format, m_int_type, m_local_buffer); + else + glReadPixels(0, 0, m_size.x, m_size.y, m_int_format, m_int_type, m_local_buffer); + glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); #endif