diff options
author | Benny Morgan <benny@zuragon.com> | 2016-07-25 20:27:24 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-08-02 11:28:25 +0000 |
commit | 2821ee4b3bc6cb7fe79fcd79c908cfde9eb86bff (patch) | |
tree | e4b71bfe500c0f4a5e46aec52bcee7e21cbe0f1b /src | |
parent | 95884805facd1721eea025467afd85ed64a70504 (diff) |
Align pixel-row of the image passed to glTexImage2D to UNPACK_ALIGN
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 <miikka.heikkinen@qt.io>
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/imports/qtcanvas3d/context3d.cpp | 30 | ||||
-rw-r--r-- | src/imports/qtcanvas3d/context3d_p.h | 1 |
2 files changed, 28 insertions, 3 deletions
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; |