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 <gabrielfrancosouza@gmail.com>
This commit is contained in:
Vlad Zahorodnii 2024-08-19 12:56:30 +03:00
parent 31adedba3a
commit f3406a033c

View file

@ -587,6 +587,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
} }
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glPixelStorei(GL_UNPACK_ROW_LENGTH, im.bytesPerLine() / (im.depth() / 8));
if (!context->isOpenGLES()) { if (!context->isOpenGLES()) {
if (context->supportsTextureStorage()) { if (context->supportsTextureStorage()) {
glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height()); glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, im.width(), im.height());
@ -598,6 +599,7 @@ std::unique_ptr<GLTexture> GLTexture::upload(const QImage &image)
} else { } else {
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, im.width(), im.height(), 0, format, type, im.constBits()); 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); glBindTexture(GL_TEXTURE_2D, 0);
return std::unique_ptr<GLTexture>(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY)); return std::unique_ptr<GLTexture>(new GLTexture(GL_TEXTURE_2D, texture, internalFormat, image.size(), 1, true, OutputTransform::FlipY));