diff options
author | Inho Lee <inho.lee@qt.io> | 2020-05-25 11:21:57 +0200 |
---|---|---|
committer | Inho Lee <inho.lee@qt.io> | 2020-09-14 20:41:42 +0200 |
commit | 02d5566d681697844206c6f035d8fecc9c31e748 (patch) | |
tree | bbeb62a978ae20448162838c83b90af5ec84905e | |
parent | db07a2035562f3e1843b9fefdfb98b8e6149fe33 (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>
-rw-r--r-- | src/gui/rhi/qrhigles2.cpp | 29 |
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)); |