Open
Description
Trying to use Protonect with the viewer enabled fails on Mesa 18.1.9 llvmpipe with the following errors:
failed to compile vertex shader!
0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.40, 1.00 ES, and 3.00 ES
failed to compile fragment shader!
0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.40, 1.00 ES, and 3.00 ES
failed to link shader program!
error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
failed to compile vertex shader!
0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.40, 1.00 ES, and 3.00 ES
failed to compile fragment shader!
0:1(10): error: GLSL 3.30 is not supported. Supported versions are: 1.10, 1.20, 1.30, 1.40, 1.00 ES, and 3.00 ES
failed to link shader program!
error: linking with uncompiled/unspecialized shadererror: linking with uncompiled/unspecialized shader
After discussing this on #dri-devel
, it seems this is caused by using #version 330
shaders without specifying an OpenGL version that supports them. In this case, OpenGL 3.1 is specified but GLSL 3.30 is only supported by OpenGL 3.3 and later.
From what the #dri-devel
people told me, and from my own experimentation, it seems the proper solutions are to either:
- Set
GLFW_CONTEXT_VERSION_MINOR
to 3 andGLFW_OPENGL_PROFILE
toGLFW_OPENGL_CORE_PROFILE
and keep the shaders as they are. - Use whatever OpenGL version we want and rewrite the shaders so they only use features available in the corresponding GLSL version.
Since re-writing shaders and OpenGL code is non-trivial, I've written a simple patch to update the OpenGL version for both Linux and Mac, and have tested it to be working on Linux with both the llvmpipe and i965 drivers and on a MacBook Pro (Retina, Early 2015) running macOS 10.13:
diff --git a/examples/viewer.cpp b/examples/viewer.cpp
index c597256..40514be 100644
--- a/examples/viewer.cpp
+++ b/examples/viewer.cpp
@@ -25,14 +25,9 @@ void Viewer::initialize()
// setup context
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
-#ifdef __APPLE__
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+ glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-#else
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
-#endif
//glfwWindowHint(GLFW_VISIBLE, debug ? GL_TRUE : GL_FALSE);
window = glfwCreateWindow(win_width*2, win_height*2, "Viewer (press ESC to exit)", 0, NULL);