From ec38b153dacec161d8dd4e26728a9e0435b8974c Mon Sep 17 00:00:00 2001 From: cutealien Date: Thu, 5 May 2022 14:10:48 +0000 Subject: [PATCH] COGLES2Driver: fix swapped color screenshots. Thanks @sfan5 for patch (https://github.com/minetest/irrlicht/commit/05c109a1d52db8293d8721337853043924feedae) Forum: https://irrlicht.sourceforge.io/forum/viewtopic.php?f=2&t=52819&p=306518 git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6383 dfc29bdd-3216-0410-991c-e03cc46cb475 --- changes.txt | 1 + source/Irrlicht/COGLES2Driver.cpp | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/changes.txt b/changes.txt index 0a19f48a..1aee101d 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in ogl-es (not yet released - will be merged with trunk at some point) +- COGLES2Driver: fix swapped color screenshots. Thanks @sfan5 for patch (https://github.com/minetest/irrlicht/commit/05c109a1d52db8293d8721337853043924feedae) - Add support for (experimental) WebGL1 driver for emscripten (still work in process) - Add support for emscripten. Thanks @labsin for the patch. - Add IVideoDriver::getAmbientLight function so shaders can access global ambient light easier diff --git a/source/Irrlicht/COGLES2Driver.cpp b/source/Irrlicht/COGLES2Driver.cpp index 8a6b3c1d..a43b1bf1 100644 --- a/source/Irrlicht/COGLES2Driver.cpp +++ b/source/Irrlicht/COGLES2Driver.cpp @@ -2535,7 +2535,7 @@ COGLES2Driver::~COGLES2Driver() if (target==video::ERT_MULTI_RENDER_TEXTURES || target==video::ERT_RENDER_TEXTURE || target==video::ERT_STEREO_BOTH_BUFFERS) return 0; - GLint internalformat = GL_RGBA; + GLint internalformat = GL_RGBA; // Note BGRA not available on ES2. Thought there might be extensions we could use maybe. GLint type = GL_UNSIGNED_BYTE; { // glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &internalformat); @@ -2591,6 +2591,22 @@ COGLES2Driver::~COGLES2Driver() } delete [] tmpBuffer; + // also GL_RGBA doesn't match the internal encoding of the image (which is BGRA) + if (GL_RGBA == internalformat && GL_UNSIGNED_BYTE == type) + { + pixels = static_cast(newImage->getData()); + for (u32 i = 0; i < ScreenSize.Height; i++) + { + for (u32 j = 0; j < ScreenSize.Width; j++) + { + u32 c = *(u32*) (pixels + 4 * j); + *(u32*) (pixels + 4 * j) = (c & 0xFF00FF00) | + ((c & 0x00FF0000) >> 16) | ((c & 0x000000FF) << 16); + } + pixels += pitch; + } + } + if (testGLError(__LINE__)) { newImage->drop();