COGLES2Driver: fix swapped color screenshots.

Thanks @sfan5 for patch (05c109a1d5)
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
master
cutealien 2022-05-05 14:10:48 +00:00 committed by Maksim
parent f8ddafbb63
commit fef3a3e538
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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<u8*>(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();