From 2821ee4b3bc6cb7fe79fcd79c908cfde9eb86bff Mon Sep 17 00:00:00 2001 From: Benny Morgan Date: Mon, 25 Jul 2016 20:27:24 +0200 Subject: Align pixel-row of the image passed to glTexImage2D to UNPACK_ALIGN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From what I can understand from the OpenGL specification, the image array that is passed as the last parameter to glTexImage2D, the pixel width must always be align to a boundary of what UNPACK_ALIGN parameter is set to. For example if UNPACK_ALIGN is set to 4 (default) the width of the image is 501 pixels, each pixel 3 bytes, each pixel row in image the array must take 1504 bytes. Task-number: QTBUG-54876 Change-Id: I7e3ea0bb11422903a6ca30eeb3ab930b9588f22f Reviewed-by: Miikka Heikkinen Reviewed-by: Pasi Keränen --- src/imports/qtcanvas3d/context3d.cpp | 30 +++++++++++++++++++++++++++--- src/imports/qtcanvas3d/context3d_p.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/imports/qtcanvas3d/context3d.cpp b/src/imports/qtcanvas3d/context3d.cpp index 9e2c488..3ab2429 100644 --- a/src/imports/qtcanvas3d/context3d.cpp +++ b/src/imports/qtcanvas3d/context3d.cpp @@ -91,6 +91,7 @@ CanvasContext::CanvasContext(QQmlEngine *engine, bool isES2, int maxVertexAttrib m_v4engine(QQmlEnginePrivate::getV4Engine(engine)), m_unpackFlipYEnabled(false), m_unpackPremultiplyAlphaEnabled(false), + m_unpackAlignmentValue(4), m_devicePixelRatio(1.0), m_currentProgram(0), m_currentArrayBuffer(0), @@ -1355,6 +1356,11 @@ QByteArray *CanvasContext::unpackPixels(uchar *srcData, bool useSrcDataAsDst, << ")"; int bytesPerRow = width * bytesPerPixel; + + // Align bytesPerRow to UNPACK_ALIGNMENT setting + if ( m_unpackAlignmentValue > 1) + bytesPerRow = bytesPerRow + (m_unpackAlignmentValue - 1) - (bytesPerRow - 1) % m_unpackAlignmentValue; + int totalBytes = bytesPerRow * height; QByteArray *unpackedData = 0; @@ -2493,10 +2499,28 @@ void CanvasContext::pixelStorei(glEnums pname, int param) case UNPACK_COLORSPACE_CONVERSION_WEBGL: // Intentionally ignored break; - case PACK_ALIGNMENT: // Intentional fall-through + case PACK_ALIGNMENT: + if ( param == 1 || param == 2 || param == 4 || param == 8 ) { + m_commandQueue->queueCommand(CanvasGlCommandQueue::glPixelStorei, + GLint(pname), GLint(param)); + } else { + m_error |= CANVAS_INVALID_VALUE; + qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + << ":INVALID_VALUE:" + << "Invalid pack alignment: " << param; + } + break; case UNPACK_ALIGNMENT: - m_commandQueue->queueCommand(CanvasGlCommandQueue::glPixelStorei, - GLint(pname), GLint(param)); + if ( param == 1 || param == 2 || param == 4 || param == 8 ) { + m_unpackAlignmentValue = param; + m_commandQueue->queueCommand(CanvasGlCommandQueue::glPixelStorei, + GLint(pname), GLint(param)); + } else { + m_error |= CANVAS_INVALID_VALUE; + qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ + << ":INVALID_VALUE:" + << "Invalid unpack alignment: " << param; + } break; default: qCWarning(canvas3drendering).nospace() << "Context3D::" << __FUNCTION__ diff --git a/src/imports/qtcanvas3d/context3d_p.h b/src/imports/qtcanvas3d/context3d_p.h index 165ec68..c2c28b4 100644 --- a/src/imports/qtcanvas3d/context3d_p.h +++ b/src/imports/qtcanvas3d/context3d_p.h @@ -1280,6 +1280,7 @@ private: QV4::ExecutionEngine *m_v4engine; bool m_unpackFlipYEnabled; bool m_unpackPremultiplyAlphaEnabled; + int m_unpackAlignmentValue; qreal m_devicePixelRatio; CanvasProgram *m_currentProgram; CanvasBuffer *m_currentArrayBuffer; -- cgit v1.2.3