diff --git a/GraphicsView/include/CGAL/Qt/qglviewer.h b/GraphicsView/include/CGAL/Qt/qglviewer.h old mode 100644 new mode 100755 index 413369b5e17..f13f5a5ed1c --- a/GraphicsView/include/CGAL/Qt/qglviewer.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer.h @@ -1217,6 +1217,7 @@ protected: //C o n t e x t bool is_ogl_4_3; bool is_sharing; + bool is_linked; QOpenGLContext* shared_context; public: //! Is used to know if the openGL context is 4.3 or ES 2.0. diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index 9436d37b2bc..323ca72bdf4 100755 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -160,6 +160,7 @@ void CGAL::QGLViewer::defaultConstructor() { _offset = CGAL::qglviewer::Vec(0,0,0); stored_fbo = NULL; is_sharing = false; + is_linked = false; shared_context = nullptr; } @@ -275,7 +276,7 @@ void CGAL::QGLViewer::initializeGL() { { vbos[i].create(); } - //program without light + if(!is_linked) { //Vertex source code const char v_s[] = @@ -361,9 +362,6 @@ void CGAL::QGLViewer::initializeGL() { { qDebug() << rendering_program.log(); } - } - //program with light - { //Vertex source code const char vertex_source[] = { @@ -476,8 +474,6 @@ void CGAL::QGLViewer::initializeGL() { //It is said in the doc that a QOpenGLShader is // only destroyed with the QOpenGLShaderProgram //it has been linked with. - QOpenGLShader vertex_shader(QOpenGLShader::Vertex); - QOpenGLShader fragment_shader(QOpenGLShader::Fragment); if(is_ogl_4_3) { if(!vertex_shader.compileSourceCode(vertex_source)) @@ -516,7 +512,7 @@ void CGAL::QGLViewer::initializeGL() { qDebug() << rendering_program_light.log(); } } - + is_linked = true; // Give time to glInit to finish and then call setFullScreen(). if (isFullScreen()) QTimer::singleShot(100, this, SLOT(delayedFullScreen())); diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index fe81b76d971..c07ffb6f564 100755 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -82,7 +82,6 @@ public: //! Decides if the distance between APoint and BPoint must be drawn; bool distance_is_displayed; bool i_is_pressed; - bool initialized; bool z_is_pressed; QImage static_image; //!Draws the distance between two selected points. @@ -249,7 +248,6 @@ void Viewer::doBindings() d->spec_power = viewer_settings.value("spec_power", 51.8).toFloat(); d->scene = 0; d->projection_is_ortho = false; - d->initialized = false; d->twosides = false; this->setProperty("draw_two_sides", false); d->macro_mode = false; @@ -460,91 +458,91 @@ void Viewer::init() d->buffer.create(); //setting the program used for the distance - { - //Vertex source code - const char vertex_source_dist[] = - { - "#version 150 \n" - "in vec4 vertex;\n" - "uniform mat4 mvp_matrix;\n" - "uniform float point_size;\n" - "void main(void)\n" - "{\n" - " gl_PointSize = point_size; \n" - " gl_Position = mvp_matrix * vertex; \n" - "} \n" - "\n" - }; - const char vertex_source_comp_dist[] = - { - "attribute highp vec4 vertex;\n" - "uniform highp mat4 mvp_matrix;\n" - "uniform highp float point_size;\n" - "void main(void)\n" - "{\n" - " gl_PointSize = point_size; \n" - " gl_Position = mvp_matrix * vertex; \n" - "} \n" - "\n" - }; - //Fragment source code - const char fragment_source_dist[] = - { - "#version 150 \n" - "out vec4 out_color; \n" - "void main(void) { \n" - "out_color = vec4(0.0,0.0,0.0,1.0); \n" - "} \n" - "\n" - }; - const char fragment_source_comp_dist[] = - { - "void main(void) { \n" - "gl_FragColor = vec4(0.0,0.0,0.0,1.0); \n" - "} \n" - "\n" - }; - QOpenGLShader vertex_shader(QOpenGLShader::Vertex); - QOpenGLShader fragment_shader(QOpenGLShader::Fragment); - if(isOpenGL_4_3()) - { - if(!vertex_shader.compileSourceCode(vertex_source_dist)) - { - std::cerr<<"Compiling vertex source FAILED"<rendering_program_dist.addShader(&vertex_shader)) - { - std::cerr<<"adding vertex shader FAILED"<rendering_program_dist.addShader(&fragment_shader)) - { - std::cerr<<"adding fragment shader FAILED"<rendering_program_dist.link()) - { - qDebug() << d->rendering_program_dist.log(); - } - } + if(!is_linked) + { + //Vertex source code + const char vertex_source_dist[] = + { + "#version 150 \n" + "in vec4 vertex;\n" + "uniform mat4 mvp_matrix;\n" + "uniform float point_size;\n" + "void main(void)\n" + "{\n" + " gl_PointSize = point_size; \n" + " gl_Position = mvp_matrix * vertex; \n" + "} \n" + "\n" + }; + const char vertex_source_comp_dist[] = + { + "attribute highp vec4 vertex;\n" + "uniform highp mat4 mvp_matrix;\n" + "uniform highp float point_size;\n" + "void main(void)\n" + "{\n" + " gl_PointSize = point_size; \n" + " gl_Position = mvp_matrix * vertex; \n" + "} \n" + "\n" + }; + //Fragment source code + const char fragment_source_dist[] = + { + "#version 150 \n" + "out vec4 out_color; \n" + "void main(void) { \n" + "out_color = vec4(0.0,0.0,0.0,1.0); \n" + "} \n" + "\n" + }; + const char fragment_source_comp_dist[] = + { + "void main(void) { \n" + "gl_FragColor = vec4(0.0,0.0,0.0,1.0); \n" + "} \n" + "\n" + }; + QOpenGLShader vertex_shader(QOpenGLShader::Vertex); + QOpenGLShader fragment_shader(QOpenGLShader::Fragment); + if(isOpenGL_4_3()) + { + if(!vertex_shader.compileSourceCode(vertex_source_dist)) + { + std::cerr<<"Compiling vertex source FAILED"<rendering_program_dist.addShader(&vertex_shader)) + { + std::cerr<<"adding vertex shader FAILED"<rendering_program_dist.addShader(&fragment_shader)) + { + std::cerr<<"adding fragment shader FAILED"<rendering_program_dist.link()) + { + qDebug() << d->rendering_program_dist.log(); + } + } d->painter = new QPainter(); - d->initialized = true; } #include @@ -1332,8 +1330,6 @@ QPainter* Viewer::getPainter(){return d->painter;} void Viewer::paintEvent(QPaintEvent *) { - if(!d->initialized) - initializeGL(); paintGL(); } diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h old mode 100644 new mode 100755