Shaders do not compile when using OpenGLES 3.0 in RPI
On RPI devices using KMS/DRM and the Mesa driver configured for OpenGL ES 3.0, Solarus fails to compile the default shaders:
[Solarus] [0] Info: Compilation result of vertex shader '':
0:1(10): error: GLSL 3.00 is not supported. Supported versions are: 1.00 ES, and 3.00 ES
[Solarus] [0] Error: Failed to compile vertex shader ''
[Solarus] [0] Info: Compilation result of fragment shader '':
0:1(10): error: GLSL 3.00 is not supported. Supported versions are: 1.00 ES, and 3.00 ES
[Solarus] [0] Error: Failed to compile fragment shader ''
[Solarus] [0] Info: Linking result of shader '':
error: no shaders attached to the program
The first problem seems to be that the computed version string to be passed to the shader compiler is 300
instead of 300 es
as suggested by this Wikipedia article.
However after quickly fixing this in Shader.cpp
, we now get the following compilation error for the default fragment shader:
[Solarus] [0] Info: Compilation result of fragment shader '':
0:5(1): error: No precision specified in this scope for type `vec4'
[Solarus] [0] Error: Failed to compile fragment shader ''
[Solarus] [0] Info: Linking result of shader '':
error: program lacks a fragment shader
[Solarus] [0] Error: Failed to link shader '':
This second problem seems to be caused because the default fragment shader program is defining the precision after declaring the out vec4 FragColor
variable:
static const std::string source =
R"(#if __VERSION__ >= 130
#define COMPAT_VARYING in
#define COMPAT_TEXTURE texture
out vec4 FragColor;
#else
#define COMPAT_VARYING varying
#define FragColor gl_FragColor
#define COMPAT_TEXTURE texture2D
#endif
#ifdef GL_ES
precision mediump float;
#define COMPAT_PRECISION mediump
#else
#define COMPAT_PRECISION
#endif
Moving the precision definition before the declaration of FragColor
seems to fix the shader compilation problem altogether and all seems to be working fine for both GLES 2.0 and GLES 3.0.