From ed557c037847e343caa010562952b398f806adcd Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 23 Aug 2018 12:50:36 +0200 Subject: Handle uploading of faked sub-images One trick that is possible to do with QImage is to make it be sub image of its imagedata by manipulating the data start and bytes-per-line, we can not upload that directly and need to detect the case and create a clean copy to upload. Task-number: QTBUG-70105 Change-Id: I7ce184a0892fb4071b6dcc1a1fd3881a4e0703cd Reviewed-by: Simon Hausmann Reviewed-by: Liang Qi --- src/gui/opengl/qopengltextureuploader.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/gui/opengl/qopengltextureuploader.cpp b/src/gui/opengl/qopengltextureuploader.cpp index 1147c81471..2428baed93 100644 --- a/src/gui/opengl/qopengltextureuploader.cpp +++ b/src/gui/opengl/qopengltextureuploader.cpp @@ -313,6 +313,11 @@ qsizetype QOpenGLTextureUploader::textureImage(GLenum target, const QImage &imag if (newSize != tx.size()) tx = tx.scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + // Handle cases where the QImage is actually a sub image of its image data: + qsizetype naturalBpl = ((qsizetype(tx.width()) * tx.depth() + 31) >> 5) << 2; + if (tx.bytesPerLine() != naturalBpl) + tx = tx.copy(tx.rect()); + funcs->glTexImage2D(target, 0, internalFormat, tx.width(), tx.height(), 0, externalFormat, pixelType, tx.constBits()); qsizetype cost = qint64(tx.width()) * tx.height() * tx.depth() / 8; -- cgit v1.2.3