From f3406a033c132b9d6d67a9847a14c9d3220e6ad2 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 19 Aug 2024 12:56:30 +0300 Subject: [PATCH] opengl: Set GL_UNPACK_ROW_LENGTH in GLTexture::upload() The image stride can be other than "width * bpp". In order to properly handle such a case, we need to set GL_UNPACK_ROW_LENGTH to skip the right amount of pixels between consecutive rows. Co-authored-by: Gabriel Souza Franco --- src/opengl/gltexture.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/opengl/gltexture.cpp b/src/opengl/gltexture.cpp index 6c24d7f8f0..4f9e96cfa4 100644 --- a/src/opengl/gltexture.cpp +++ b/src/opengl/gltexture.cpp @@ -587,6 +587,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) } glBindTexture(GL_TEXTURE_2D, texture); + glPixelStorei(GL_UNPACK_ROW_LENGTH, im.bytesPerLine() / (im.depth() / 8)); if (!context->isOpenGLES()) { if (context->supportsTextureStorage()) { glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height()); @@ -598,6 +599,7 @@ std::unique_ptr GLTexture::upload(const QImage &image) } else { glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, im.width(), im.height(), 0, format, type, im.constBits()); } + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glBindTexture(GL_TEXTURE_2D, 0); return std::unique_ptr(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY));