diff options
author | Aurélien Brooke <aurelien@bahiasoft.fr> | 2023-03-21 10:37:14 +0100 |
---|---|---|
committer | Aurélien Brooke <aurelien@bahiasoft.fr> | 2023-04-13 11:21:40 +0200 |
commit | 57f190ddfe396d61b7ed284aae263dfeedc8f666 (patch) | |
tree | 306e71470c6a07429cea8df1ac6f22a65265010b | |
parent | 640e14d93e9b97c16f53ef65298c0e6ae5ca28cf (diff) | |
download | qt3d-57f190ddfe396d61b7ed284aae263dfeedc8f666.tar.gz |
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 <paul.lemire@kdab.com>
-rw-r--r-- | src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp | 49 |
1 files 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<QByteArray> &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<std::pair<int, int>, 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<std::pair<int, int>, 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<std::pair<int, int>, 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; } } } |