summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Casafranca <juan.casafranca@kdab.com>2020-09-25 12:55:37 +0200
committerJuan José Casafranca <juan.casafranca@kdab.com>2020-09-28 09:35:44 +0200
commit327da58f9463354dea30c6fac4fdf8da3c3b7d08 (patch)
tree8cc1f0fe1058b62b339aaadd362794b99e456ae1
parentbbecb4a4ffe06e7f96c108995bc5e75614eaa963 (diff)
Allow to set alignment requirement for an image
Change-Id: Ifffbfd80a3d99b43e348e12bea62e3c90eed80c4 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/plugins/renderers/opengl/textures/gltexture.cpp13
-rw-r--r--src/render/texture/qtextureimagedata.cpp21
-rw-r--r--src/render/texture/qtextureimagedata.h3
-rw-r--r--src/render/texture/qtextureimagedata_p.h1
-rw-r--r--tests/auto/render/qtextureimagedata/tst_qtextureimagedata.cpp1
5 files changed, 33 insertions, 6 deletions
diff --git a/src/plugins/renderers/opengl/textures/gltexture.cpp b/src/plugins/renderers/opengl/textures/gltexture.cpp
index 08c96355a..804b20656 100644
--- a/src/plugins/renderers/opengl/textures/gltexture.cpp
+++ b/src/plugins/renderers/opengl/textures/gltexture.cpp
@@ -78,13 +78,13 @@ void uploadGLData(QOpenGLTexture *glTex,
int level, int layer, QOpenGLTexture::CubeMapFace face,
const QByteArray &bytes, const QTextureImageDataPtr &data)
{
- if (data->isCompressed()) {
+ const auto alignment = data->alignment();
+ QOpenGLPixelTransferOptions uploadOptions;
+ uploadOptions.setAlignment(alignment);
+ if (data->isCompressed())
glTex->setCompressedData(level, layer, face, bytes.size(), bytes.constData());
- } else {
- QOpenGLPixelTransferOptions uploadOptions;
- uploadOptions.setAlignment(1);
+ else
glTex->setData(level, layer, face, data->pixelFormat(), data->pixelType(), bytes.constData(), &uploadOptions);
- }
}
// For partial sub image uploads
@@ -96,8 +96,9 @@ void uploadGLData(QOpenGLTexture *glTex,
if (data->isCompressed()) {
qWarning() << Q_FUNC_INFO << "Uploading non full sized Compressed Data not supported yet";
} else {
+ const auto alignment = data->alignment();
QOpenGLPixelTransferOptions uploadOptions;
- uploadOptions.setAlignment(1);
+ uploadOptions.setAlignment(alignment);
glTex->setData(xOffset, yOffset, zOffset,
data->width(), data->height(), data->depth(),
mipLevel, layer, cubeFace, data->layers(),
diff --git a/src/render/texture/qtextureimagedata.cpp b/src/render/texture/qtextureimagedata.cpp
index 1750fcb13..d6388e389 100644
--- a/src/render/texture/qtextureimagedata.cpp
+++ b/src/render/texture/qtextureimagedata.cpp
@@ -54,6 +54,7 @@ QTextureImageDataPrivate::QTextureImageDataPrivate()
, m_faces(-1)
, m_mipLevels(-1)
, m_blockSize(-1)
+ , m_alignment(1)
, m_target(QOpenGLTexture::Target2D)
, m_format(QOpenGLTexture::NoFormat)
, m_pixelFormat(QOpenGLTexture::RGBA)
@@ -188,6 +189,7 @@ void QTextureImageData::cleanup() Q_DECL_NOTHROW
d->m_faces = -1;
d->m_mipLevels = -1;
d->m_blockSize = 0;
+ d->m_alignment = 1;
d->m_isCompressed = false;
d->m_data.clear();
}
@@ -316,6 +318,25 @@ void QTextureImageData::setFaces(int faces) Q_DECL_NOTHROW
}
/*!
+ * Sets the alignment requirements for the image
+ * \param alignment
+ */
+void QTextureImageData::setAlignment(int alignment) Q_DECL_NOTHROW
+{
+ Q_D(QTextureImageData);
+ d->m_alignment = alignment;
+}
+
+/*!
+ \return the alignment requirement for the image
+ */
+int QTextureImageData::alignment() const Q_DECL_NOTHROW
+{
+ Q_D(const QTextureImageData);
+ return d->m_alignment;
+}
+
+/*!
\return the target for the stored texture
*/
QOpenGLTexture::Target QTextureImageData::target() const Q_DECL_NOTHROW
diff --git a/src/render/texture/qtextureimagedata.h b/src/render/texture/qtextureimagedata.h
index b199d8e56..05b7f95f4 100644
--- a/src/render/texture/qtextureimagedata.h
+++ b/src/render/texture/qtextureimagedata.h
@@ -79,6 +79,9 @@ public:
void setMipLevels(int mipLevels) Q_DECL_NOTHROW;
void setFaces(int faces) Q_DECL_NOTHROW;
+ int alignment() const Q_DECL_NOTHROW;
+ void setAlignment(int alignment) Q_DECL_NOTHROW;
+
QOpenGLTexture::Target target() const Q_DECL_NOTHROW;
QOpenGLTexture::TextureFormat format() const Q_DECL_NOTHROW;
diff --git a/src/render/texture/qtextureimagedata_p.h b/src/render/texture/qtextureimagedata_p.h
index 14095e2eb..ee12d3387 100644
--- a/src/render/texture/qtextureimagedata_p.h
+++ b/src/render/texture/qtextureimagedata_p.h
@@ -76,6 +76,7 @@ public:
int m_faces;
int m_mipLevels;
int m_blockSize;
+ int m_alignment;
QOpenGLTexture::Target m_target;
QOpenGLTexture::TextureFormat m_format;
diff --git a/tests/auto/render/qtextureimagedata/tst_qtextureimagedata.cpp b/tests/auto/render/qtextureimagedata/tst_qtextureimagedata.cpp
index 4912dac0c..c508294df 100644
--- a/tests/auto/render/qtextureimagedata/tst_qtextureimagedata.cpp
+++ b/tests/auto/render/qtextureimagedata/tst_qtextureimagedata.cpp
@@ -59,6 +59,7 @@ private Q_SLOTS:
QCOMPARE(tid->pixelFormat(), QOpenGLTexture::RGBA);
QCOMPARE(tid->pixelType(), QOpenGLTexture::UInt8);
QCOMPARE(tid->isCompressed(), false);
+ QCOMPARE(tid->alignment(), 1);
}
void checkCloning_data()