From f19e67bb59cb1b9f266232f0ef44b17a19285068 Mon Sep 17 00:00:00 2001 From: Michael Rennie Date: Fri, 5 May 2017 17:50:49 +0100 Subject: [PATCH] Thumbnail generation fix on GLES by glReadPixels(RGBA) instead of RGB. --- renderdoc/driver/gl/gl_driver.cpp | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index d4289fffe..c8cd37c35 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -2809,9 +2809,21 @@ WrappedOpenGL::BackbufferImage *WrappedOpenGL::SaveBackbufferImage() thwidth = m_InitParams.width; thheight = m_InitParams.height; - thpixels = new byte[thwidth * thheight * 3]; + thpixels = new byte[thwidth * thheight * 4]; - m_Real.glReadPixels(0, 0, thwidth, thheight, eGL_RGB, eGL_UNSIGNED_BYTE, thpixels); + // GLES only supports GL_RGBA + m_Real.glReadPixels(0, 0, thwidth, thheight, eGL_RGBA, eGL_UNSIGNED_BYTE, thpixels); + + // RGBA -> RGB + for(uint32_t y = 0; y < thheight; y++) + { + for(uint32_t x = 0; x < thwidth; x++) + { + thpixels[(y * thwidth + x) * 3 + 0] = thpixels[(y * thwidth + x) * 4 + 0]; + thpixels[(y * thwidth + x) * 3 + 1] = thpixels[(y * thwidth + x) * 4 + 1]; + thpixels[(y * thwidth + x) * 3 + 2] = thpixels[(y * thwidth + x) * 4 + 2]; + } + } // flip the image in-place for(uint32_t y = 0; y <= thheight / 2; y++) @@ -2821,17 +2833,17 @@ WrappedOpenGL::BackbufferImage *WrappedOpenGL::SaveBackbufferImage() for(uint32_t x = 0; x < thwidth; x++) { byte save[3]; - save[0] = thpixels[y * (thwidth * 3) + x * 3 + 0]; - save[1] = thpixels[y * (thwidth * 3) + x * 3 + 1]; - save[2] = thpixels[y * (thwidth * 3) + x * 3 + 2]; + save[0] = thpixels[(y * thwidth + x) * 3 + 0]; + save[1] = thpixels[(y * thwidth + x) * 3 + 1]; + save[2] = thpixels[(y * thwidth + x) * 3 + 2]; - thpixels[y * (thwidth * 3) + x * 3 + 0] = thpixels[flipY * (thwidth * 3) + x * 3 + 0]; - thpixels[y * (thwidth * 3) + x * 3 + 1] = thpixels[flipY * (thwidth * 3) + x * 3 + 1]; - thpixels[y * (thwidth * 3) + x * 3 + 2] = thpixels[flipY * (thwidth * 3) + x * 3 + 2]; + thpixels[(y * thwidth + x) * 3 + 0] = thpixels[(flipY * thwidth + x) * 3 + 0]; + thpixels[(y * thwidth + x) * 3 + 1] = thpixels[(flipY * thwidth + x) * 3 + 1]; + thpixels[(y * thwidth + x) * 3 + 2] = thpixels[(flipY * thwidth + x) * 3 + 2]; - thpixels[flipY * (thwidth * 3) + x * 3 + 0] = save[0]; - thpixels[flipY * (thwidth * 3) + x * 3 + 1] = save[1]; - thpixels[flipY * (thwidth * 3) + x * 3 + 2] = save[2]; + thpixels[(flipY * thwidth + x) * 3 + 0] = save[0]; + thpixels[(flipY * thwidth + x) * 3 + 1] = save[1]; + thpixels[(flipY * thwidth + x) * 3 + 2] = save[2]; } }