From 57f190ddfe396d61b7ed284aae263dfeedc8f666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Brooke?= Date: Tue, 21 Mar 2023 10:37:14 +0100 Subject: RHI: generate GLSL shaders of correct version when running on OpenGL ES OpenGL ES has different shader versions than Desktop OpenGL, which the existing code was not accounting for. Check if we are running OpenGL ES to choose the proper GLSL version, and add the flag QShaderVersion::GlslEs. This fixes errors like this when running on Android: No GLSL shader code found (versions tried: QList(320, 310, 300, 100) ) in baked shader QShader(stage=0 shaders=QList(ShaderKey(1 Version(120 QFlags()) 0)) desc.isValid=true) Pick-to: 6.5 Change-Id: I6b387962e5cf48cdb0aec8ac3e8348d7847fc20a Reviewed-by: Paul Lemire --- .../rhi/graphicshelpers/submissioncontext.cpp | 49 +++++++++++++++------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp index 32fd7fcf2..384d5665e 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -1420,26 +1420,45 @@ void preprocessRHIShader(std::vector &shaderCodes) } } -int glslVersionForFormat(const QSurfaceFormat &format) noexcept +QShaderVersion glslVersionForFormat(const QSurfaceFormat &format) noexcept { const int major = format.majorVersion(); const int minor = format.minorVersion(); - - static const QHash, int> glVersionToGLSLVersion = { - { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, - { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, - { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, - }; - - const auto it = glVersionToGLSLVersion.find({ major, minor }); - if (it == glVersionToGLSLVersion.end()) { - if (major < 3) { - return 120; + const auto type = format.renderableType(); + + if (type != QSurfaceFormat::OpenGLES) { + static const QHash, int> glVersionToGLSLVersion = { + { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, + { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, + { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return 120; + } else { + return major * 100 + minor * 10; + } } else { - return major * 100 + minor * 10; + return *it; + } + } + else { + static const QHash, int> glVersionToGLSLVersion = { + { { 3, 2 }, 320 }, { { 3, 1 }, 310 }, { { 3, 0 }, 300 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return {100, QShaderVersion::GlslEs}; + } else { + return {major * 100 + minor * 10, QShaderVersion::GlslEs}; + } + } else { + return {*it, QShaderVersion::GlslEs}; } - } else { - return *it; } } } -- cgit v1.2.1