1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Make ETLF_FLIP_Y_UP_RTT work for texture download on GLES

This commit is contained in:
sfan5 2025-04-13 17:34:45 +02:00
parent cf07b56235
commit 04e82749db

View file

@ -289,24 +289,8 @@ public:
GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData()); GL.GetTexImage(tmpTextureType, MipLevelStored, PixelFormat, PixelType, tmpImage->getData());
TEST_GL_ERROR(Driver); TEST_GL_ERROR(Driver);
if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT) { if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT)
const s32 pitch = tmpImage->getPitch(); flipImageY(tmpImage);
u8 *srcA = static_cast<u8 *>(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;
}
} else { } else {
@ -337,11 +321,12 @@ public:
TEST_GL_ERROR(Driver); TEST_GL_ERROR(Driver);
if (IsRenderTarget && lockFlags == ETLF_FLIP_Y_UP_RTT)
flipImageY(tmpImage);
void *src = tmpImage->getData(); void *src = tmpImage->getData();
void *dest = LockImage->getData(); void *dest = LockImage->getData();
// FIXME: what about ETLF_FLIP_Y_UP_RTT
switch (ColorFormat) { switch (ColorFormat) {
case ECF_A1R5G5B5: case ECF_A1R5G5B5:
CColorConverter::convert_A8R8G8B8toA1B5G5R5(src, tmpImage->getDimension().getArea(), dest); CColorConverter::convert_A8R8G8B8toA1B5G5R5(src, tmpImage->getDimension().getArea(), dest);
@ -507,6 +492,22 @@ protected:
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8; Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
} }
static void flipImageY(IImage *image)
{
const u32 pitch = image->getPitch();
u8 *srcA = static_cast<u8 *>(image->getData());
u8 *srcB = srcA + (image->getDimension().Height - 1) * pitch;
std::vector<u8> 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) void initTexture(u32 layers)
{ {
// Compressed textures cannot be pre-allocated and are initialized on upload // Compressed textures cannot be pre-allocated and are initialized on upload