From 04e82749db3c3d08d525e2ab05296da593c27010 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 13 Apr 2025 17:34:45 +0200 Subject: [PATCH] Make ETLF_FLIP_Y_UP_RTT work for texture download on GLES --- irr/src/COpenGLCoreTexture.h | 41 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/irr/src/COpenGLCoreTexture.h b/irr/src/COpenGLCoreTexture.h index ba9ad89c3..bc9a7e919 100644 --- a/irr/src/COpenGLCoreTexture.h +++ b/irr/src/COpenGLCoreTexture.h @@ -289,24 +289,8 @@ public: GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData()); TEST_GL_ERROR(Driver); - if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) { - const s32 pitch = tmpImage->getPitch(); - - u8 *srcA = static_cast(tmpImage->getData()); - u8 *srcB = srcA + (tmpImage->getDimension().Height - 1) * pitch; - - u8 *tmpBuffer = new u8[pitch]; - - for (u32 i = 0; i < tmpImage->getDimension().Height; i += 2) { - memcpy(tmpBuffer, srcA, pitch); - memcpy(srcA, srcB, pitch); - memcpy(srcB, tmpBuffer, pitch); - srcA += pitch; - srcB -= pitch; - } - - delete[] tmpBuffer; - } + if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) + flipImageY(tmpImage); } else { @@ -337,11 +321,12 @@ public: TEST_GL_ERROR(Driver); + if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) + flipImageY(tmpImage); + void *src = tmpImage->getData(); void *dest = LockImage->getData(); - // FIXME: what about ETLF_FLIP_Y_UP_RTT - switch (ColorFormat) { case ECF_A1R5G5B5: CColorConverter::convert_A8R8G8B8toA1B5G5R5(src, tmpImage->getDimension().getArea(), dest); @@ -507,6 +492,22 @@ protected: Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8; } + static void flipImageY(IImage *image) + { + const u32 pitch = image->getPitch(); + u8 *srcA = static_cast(image->getData()); + u8 *srcB = srcA + (image->getDimension().Height - 1) * pitch; + + std::vector tmpBuffer(pitch); + for (u32 i = 0; i < image->getDimension().Height; i += 2) { + memcpy(tmpBuffer.data(), srcA, pitch); + memcpy(srcA, srcB, pitch); + memcpy(srcB, tmpBuffer.data(), pitch); + srcA += pitch; + srcB -= pitch; + } + } + void initTexture(u32 layers) { // Compressed textures cannot be pre-allocated and are initialized on upload