summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhigles2.cpp
diff options
context:
space:
mode:
authorInho Lee <inho.lee@qt.io>2020-05-25 11:21:57 +0200
committerInho Lee <inho.lee@qt.io>2020-09-14 20:41:42 +0200
commit02d5566d681697844206c6f035d8fecc9c31e748 (patch)
treebbeb62a978ae20448162838c83b90af5ec84905e /src/gui/rhi/qrhigles2.cpp
parentdb07a2035562f3e1843b9fefdfb98b8e6149fe33 (diff)
QRhi: support matrix array types of the uniform in GLES2 backend
Task-number: QTBUG-83173 Change-Id: Ieda8948820a9470e3b0bc420ec7b1af09395d568 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhigles2.cpp')
-rw-r--r--src/gui/rhi/qrhigles2.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp
index 99d0cdd40d..a06cec2b38 100644
--- a/src/gui/rhi/qrhigles2.cpp
+++ b/src/gui/rhi/qrhigles2.cpp
@@ -2788,10 +2788,12 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
&& uniform.type != QShaderDescription::Float
&& uniform.type != QShaderDescription::Vec2
&& uniform.type != QShaderDescription::Vec3
- && uniform.type != QShaderDescription::Vec4)
+ && uniform.type != QShaderDescription::Vec4
+ && uniform.type != QShaderDescription::Mat3
+ && uniform.type != QShaderDescription::Mat4)
{
qWarning("Uniform with buffer binding %d, buffer offset %d, type %d is an array, "
- "but arrays are only supported for float, vec2, vec3, and vec4. "
+ "but arrays are only supported for float, vec2, vec3, vec4, mat3 and mat4. "
"Only the first element will be set.",
uniform.binding, uniform.offset, uniform.type);
}
@@ -2848,17 +2850,24 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
break;
case QShaderDescription::Mat3:
{
- // 4 floats per column (or row, if row-major)
- float mat[9];
- const float *srcMat = reinterpret_cast<const float *>(src);
- memcpy(mat, srcMat, 3 * sizeof(float));
- memcpy(mat + 3, srcMat + 4, 3 * sizeof(float));
- memcpy(mat + 6, srcMat + 8, 3 * sizeof(float));
- f->glUniformMatrix3fv(uniform.glslLocation, 1, GL_FALSE, mat);
+ const int elemCount = uniform.arrayDim;
+ if (elemCount < 1) {
+ // 4 floats per column (or row, if row-major)
+ float mat[9];
+ const float *srcMat = reinterpret_cast<const float *>(src);
+ memcpy(mat, srcMat, 3 * sizeof(float));
+ memcpy(mat + 3, srcMat + 4, 3 * sizeof(float));
+ memcpy(mat + 6, srcMat + 8, 3 * sizeof(float));
+ f->glUniformMatrix3fv(uniform.glslLocation, 1, GL_FALSE, mat);
+ } else {
+ packedFloatArray.resize(elemCount * 9);
+ qrhi_std140_to_packed(packedFloatArray.data(), 3, elemCount * 3, src);
+ f->glUniformMatrix3fv(uniform.glslLocation, elemCount, GL_FALSE, packedFloatArray.constData());
+ }
}
break;
case QShaderDescription::Mat4:
- f->glUniformMatrix4fv(uniform.glslLocation, 1, GL_FALSE, reinterpret_cast<const float *>(src));
+ f->glUniformMatrix4fv(uniform.glslLocation, qMax(1, uniform.arrayDim), GL_FALSE, reinterpret_cast<const float *>(src));
break;
case QShaderDescription::Int:
f->glUniform1i(uniform.glslLocation, *reinterpret_cast<const qint32 *>(src));