diff --git a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h index 2799c1c5790..944aa973fcf 100644 --- a/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h +++ b/GraphicsView/include/CGAL/Qt/Basic_viewer_qt.h @@ -141,6 +141,89 @@ const char fragment_source_p_l[] = "} \n" "\n" }; + +//------------------------------------------------------------------------------ +// compatibility shaders + +const char vertex_source_color_comp[] = + { + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec3 color;\n" + + "uniform highp mat4 mvp_matrix;\n" + "uniform highp mat4 mv_matrix; \n" + + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + + "uniform highp float point_size; \n" + "void main(void)\n" + "{\n" + " fP = mv_matrix * vertex; \n" + " fN = mat3(mv_matrix)* normal; \n" + " fColor = vec4(color, 1.0); \n" + " gl_PointSize = point_size;\n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +const char fragment_source_color_comp[] = + { + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" + "uniform vec4 light_pos; \n" + "uniform vec4 light_diff; \n" + "uniform vec4 light_spec; \n" + "uniform vec4 light_amb; \n" + "uniform float spec_power ; \n" + + "void main(void) { \n" + + " vec3 L = light_pos.xyz - fP.xyz; \n" + " vec3 V = -fP.xyz; \n" + + " vec3 N = normalize(fN); \n" + " L = normalize(L); \n" + " V = normalize(V); \n" + + " vec3 R = reflect(-L, N); \n" + " vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" + " vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" + + "gl_FragColor = light_amb*fColor + diffuse ; \n" + "} \n" + "\n" + }; + +const char vertex_source_p_l_comp[] = + { + "attribute highp vec4 vertex;\n" + "attribute highp vec3 color;\n" + "uniform highp mat4 mvp_matrix;\n" + "varying highp vec4 fColor; \n" + "uniform highp float point_size; \n" + "void main(void)\n" + "{\n" + " gl_PointSize = point_size;\n" + " fColor = vec4(color, 1.0); \n" + " gl_Position = mvp_matrix * vertex;\n" + "}" + }; + +const char fragment_source_p_l_comp[] = + { + "varying highp vec4 fColor; \n" + "void main(void) { \n" + "gl_FragColor = fColor; \n" + "} \n" + "\n" + }; + + + //------------------------------------------------------------------------------ inline CGAL::Color get_random_color(CGAL::Random& random) { @@ -344,12 +427,21 @@ protected: } // Vertices and segments shader + + const char* source_ = isOpenGL_4_3() + ? vertex_source_p_l + : vertex_source_p_l_comp; + QOpenGLShader *vertex_shader_p_l = new QOpenGLShader(QOpenGLShader::Vertex); - if(!vertex_shader_p_l->compileSourceCode(vertex_source_p_l)) + if(!vertex_shader_p_l->compileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_p_l)) + if(!fragment_shader_p_l->compileSourceCode(source_)) { std::cerr<<"Compiling fragmentsource FAILED"<compileSourceCode(vertex_source_color)) + if(!vertex_shader_face->compileSourceCode(source_)) { std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_color)) { std::cerr<<"Compiling fragmentsource FAILED"<