diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index 96ebef00ecf..4b4bb4e69af 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -16,7 +16,6 @@ #include #include -#include #include #include #include "Viewer.h" @@ -92,9 +91,8 @@ void Scene::compile_shaders() //Vertex source code const char vertex_source[] = { - // "#version 330 \n" + "#version 120 \n" "attribute highp vec4 vertex;\n" - // "uniform highp mat4 ortho_matrix;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix;\n" "void main(void)\n" @@ -105,7 +103,7 @@ void Scene::compile_shaders() //Vertex source code const char fragment_source[] = { - //"#version 330 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" @@ -141,7 +139,7 @@ void Scene::compile_shaders() //Vertex source code const char tex_vertex_source[] = { - // "#version 330 \n" + "#version 120 \n" "attribute highp vec4 vertex;\n" "attribute highp vec2 tex_coord; \n" "uniform highp mat4 mvp_matrix;\n" @@ -156,7 +154,7 @@ void Scene::compile_shaders() //Vertex source code const char tex_fragment_source[] = { - //"#version 330 \n" + "#version 120 \n" "uniform sampler2D texture;\n" "varying highp vec2 texc;\n" "void main(void) { \n" @@ -1318,7 +1316,7 @@ void Scene::deactivate_cutting_plane() } void Scene::initGL(Viewer * /* viewer */) { - gl = new QOpenGLFunctions_3_3_Core(); + gl = new QOpenGLFunctions_2_1(); if(!gl->initializeOpenGLFunctions()) { qFatal("ERROR : OpenGL Functions not initialized. Check your OpenGL Verison (should be >=3.3)"); diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index 450559af232..1175ad4700a 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -86,7 +86,7 @@ public: private: // member data - QOpenGLFunctions_3_3_Core *gl; + QOpenGLFunctions_2_1 *gl; Bbox m_bbox; Polyhedron *m_pPolyhedron; std::list m_points; diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp index e276df8661e..a5a0dd2f222 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp @@ -29,14 +29,14 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -44,12 +44,12 @@ void Viewer::compile_shaders() " gl_Position = mvp_matrix * vertex;\n" "}" }; - //Vertex source code + //Fragment source code const char fragment_source[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform highp vec4 color; \n" "uniform vec4 light_pos; \n" "uniform vec4 light_diff; \n" @@ -105,8 +105,8 @@ rendering_program.bind(); //Vertex source code const char vertex_source_points[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" @@ -117,7 +117,7 @@ const char vertex_source_points[] = //Vertex source code const char fragment_source_points[] = { - "#version 330 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" @@ -325,6 +325,7 @@ void Viewer::compute_elements() void Viewer::draw() { + glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); QColor color; diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h index a5cc54aa490..5280aa622b3 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.h @@ -3,13 +3,13 @@ #include "typedefs.h" #include -#include +#include #include #include #include -class Viewer : public QGLViewer, protected QOpenGLFunctions_3_3_Core{ +class Viewer : public QGLViewer, protected QOpenGLFunctions_2_1{ Q_OBJECT CGAL::Timer timer; diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp index 858aa0ab7af..0036038b6de 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp @@ -4,9 +4,12 @@ #include #include #include + + Viewer::Viewer(QWidget* parent ) : QGLViewer(CGAL::Qt::createOpenGLContext(),parent) { + extension_is_found = false; } void Viewer::compile_shaders() @@ -29,16 +32,16 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 center;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 center;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -49,9 +52,9 @@ void Viewer::compile_shaders() //Vertex source code const char fragment_source[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform highp vec4 color; \n" "uniform vec4 light_pos; \n" "uniform vec4 light_diff; \n" @@ -101,6 +104,59 @@ void Viewer::compile_shaders() std::cerr<<"linking Program FAILED"<compileSourceCode(vertex_source_no_ext)) + { + std::cerr<<"Compiling vertex source FAILED"<compileSourceCode(fragment_source_no_ext)) + { + std::cerr<<"Compiling fragmentsource FAILED"<(pos_sphere_inter.size()*sizeof(float))); - vertexLocation[2] = rendering_program.attributeLocation("vertex"); - rendering_program.bind(); - rendering_program.enableAttributeArray(vertexLocation[2]); - rendering_program.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); - buffers[6].release(); - //normals of the sphere - buffers[7].bind(); - buffers[7].allocate(normals_inter.data(), - static_cast(normals_inter.size()*sizeof(float))); - normalsLocation[2] = rendering_program.attributeLocation("normal"); - rendering_program.bind(); - rendering_program.enableAttributeArray(normalsLocation[2]); - rendering_program.setAttributeBuffer(normalsLocation[2],GL_FLOAT,0,3); - buffers[7].release(); - //center of the sphere - buffers[8].bind(); - buffers[8].allocate(pos_points.data(), - static_cast(pos_points.size()*sizeof(float))); - centerLocation = rendering_program.attributeLocation("center"); - rendering_program.bind(); - rendering_program.enableAttributeArray(centerLocation); - rendering_program.setAttributeBuffer(centerLocation,GL_FLOAT,0,3); - buffers[8].release(); - glVertexAttribDivisor(centerLocation, 1); - glVertexAttribDivisor(normalsLocation[1], 0); + if(extension_is_found) + { + //points of the spheres + buffers[6].bind(); + buffers[6].allocate(pos_sphere_inter.data(), + static_cast(pos_sphere_inter.size()*sizeof(float))); + vertexLocation[2] = rendering_program.attributeLocation("vertex"); + rendering_program.bind(); + rendering_program.enableAttributeArray(vertexLocation[2]); + rendering_program.setAttributeBuffer(vertexLocation[2],GL_FLOAT,0,3); + buffers[6].release(); + //normals of the sphere + buffers[7].bind(); + buffers[7].allocate(normals_inter.data(), + static_cast(normals_inter.size()*sizeof(float))); + normalsLocation[2] = rendering_program.attributeLocation("normal"); + rendering_program.bind(); + rendering_program.enableAttributeArray(normalsLocation[2]); + rendering_program.setAttributeBuffer(normalsLocation[2],GL_FLOAT,0,3); + buffers[7].release(); + //center of the sphere + buffers[8].bind(); + buffers[8].allocate(pos_points.data(), + static_cast(pos_points.size()*sizeof(float))); + centerLocation = rendering_program.attributeLocation("center"); + rendering_program.bind(); + rendering_program.enableAttributeArray(centerLocation); + rendering_program.setAttributeBuffer(centerLocation,GL_FLOAT,0,3); + buffers[8].release(); + + glVertexAttribDivisor(centerLocation, 1); + glVertexAttribDivisor(normalsLocation[1], 0); + } + else + { + //points of the sphere + buffers[6].bind(); + buffers[6].allocate(pos_points.data(), + static_cast(pos_points.size()*sizeof(float))); + rendering_program_no_ext.bind(); + rendering_program_no_ext.enableAttributeArray("vertex"); + rendering_program_no_ext.setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[6].release(); + } vao[2].release(); @@ -693,13 +771,20 @@ void Viewer::attrib_buffers(QGLViewer* viewer) rendering_program.setUniformValue(mvpLocation, mvpMatrix); rendering_program.setUniformValue(mvLocation, mvMatrix); - rendering_program.release(); + if(!extension_is_found) + { + rendering_program_no_ext.bind(); + rendering_program_no_ext.setUniformValue("mvp_matrix", mvpMatrix); + rendering_program_no_ext.release(); + } + } void Viewer::draw() { + glEnable(GL_DEPTH_TEST); QColor color; //sphere @@ -708,18 +793,34 @@ void Viewer::draw() rendering_program.bind(); color.setRgbF(1.0f, 1.0f, 1.0f); rendering_program.setUniformValue(colorLocation, color); - glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere.size()/3), 1); + if(extension_is_found) + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere.size()/3), 1); + else + glDrawArrays(GL_TRIANGLES, 0, static_cast(pos_sphere.size()/3)); rendering_program.release(); vao[0].release(); //intersection vao[2].bind(); attrib_buffers(this); - rendering_program.bind(); color.setRgbF(0.0f, 1.0f, 0.0f); - rendering_program.setUniformValue(colorLocation, color); - glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere_inter.size()/3), static_cast(pos_points.size()/3)); - rendering_program.release(); + if(extension_is_found) + { + rendering_program.bind(); + rendering_program.setUniformValue(colorLocation, color); + glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast(pos_sphere_inter.size()/3), static_cast(pos_points.size()/3)); + rendering_program.release(); + } + else + { + glPointSize(4.0f); + rendering_program_no_ext.bind(); + rendering_program_no_ext.setUniformValue(colorLocation, color); + glDrawArrays(GL_POINTS, 0, static_cast(pos_points.size()/3)); + rendering_program_no_ext.release(); + glPointSize(1.0f); + } + vao[2].release(); //circles @@ -738,6 +839,24 @@ void Viewer::draw() void Viewer::init() { + + glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDARBPROC)this->context()->getProcAddress("glDrawArraysInstancedARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glDrawArraysInstancedARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; + + glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORARBPROC)this->context()->getProcAddress("glVertexAttribDivisorARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glVertexAttribDivisorARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; compile_shaders(); compute_elements(); initialize_buffers(); @@ -748,6 +867,7 @@ void Viewer::init() glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); + } template diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h index 81b20ba1746..378fc42114d 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.h @@ -1,14 +1,14 @@ #include #include -#include +#include #include #include #include typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC; -class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core +class Viewer : public QGLViewer, QOpenGLFunctions_2_1 { public: Viewer(QWidget* parent = 0); @@ -29,7 +29,7 @@ private: int mvLocation; int colorLocation; int lightLocation[5]; - + bool extension_is_found; std::vector pos_points; std::vector pos_lines; @@ -43,6 +43,11 @@ private: QOpenGLBuffer buffers[9]; QOpenGLVertexArrayObject vao[3]; QOpenGLShaderProgram rendering_program; + QOpenGLShaderProgram rendering_program_no_ext; + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); + typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); + PFNGLDRAWARRAYSINSTANCEDARBPROC glDrawArraysInstanced; + PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisor; void initialize_buffers(); void compute_elements(); diff --git a/Documentation/doc/Documentation/Installation.txt b/Documentation/doc/Documentation/Installation.txt index 9864272873d..f97e1a58731 100644 --- a/Documentation/doc/Documentation/Installation.txt +++ b/Documentation/doc/Documentation/Installation.txt @@ -423,7 +423,8 @@ it from `http://qt-project.org/`. Older demos of \cgal use libCGAL_Qt3 and \sc{Qt}3, while newer and newly developed demos require libCGAL_Qt5 and \sc{Qt}5. The exhaustive list of \sc{Qt}5 components used in demos is: -`Core`, `Gui`, `Help`, `OpenGL`, `Script`, `ScriptTools`, `Svg`, `Widgets` and `Xml`. +`Core`, `Gui`, `Help`, `OpenGL`, `Script`, `ScriptTools`, `Svg`, `Widgets`, +`qcollectiongenerator` (with `sqlite` driver plugin) and `Xml`. Having \sc{Qt}5 version 5.3.0 is recommended. diff --git a/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h b/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h index 514b6e8007e..7e321582f36 100644 --- a/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h +++ b/GraphicsView/include/CGAL/Qt/CreateOpenGLContext.h @@ -27,7 +27,7 @@ inline QGLContext* createOpenGLContext() { QOpenGLContext *context = new QOpenGLContext(); QSurfaceFormat format; - format.setVersion(3,3); + format.setVersion(2,1); format.setProfile(QSurfaceFormat::CompatibilityProfile); context->setFormat(format); return QGLContext::fromOpenGLContext(context); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp index cf92a3804e3..48569ec0990 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.cpp @@ -232,32 +232,32 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 140 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 color;\n" + "#version 120 \n" + "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" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" - "out highp vec4 fColor; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 fColor; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" " fN = mat3(mv_matrix)* normal; \n" - " fColor = color; \n" + " fColor = vec4(color, 1.0); \n" " gl_Position = mvp_matrix * vertex;\n" "}" }; //Vertex source code const char fragment_source[] = { - "#version 140 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" - "in highp vec4 fColor; \n" + "#version 120 \n" + "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" @@ -310,8 +310,8 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source_p_l[] = { - "#version 140 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -321,7 +321,7 @@ void Viewer::compile_shaders() //Vertex source code const char fragment_source_p_l[] = { - "#version 140 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" @@ -657,20 +657,20 @@ void Viewer::attrib_buffers(QGLViewer* viewer) void Viewer::sceneChanged() { - + compute_elements(); this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(), bb.ymin(), bb.zmin()), qglviewer::Vec(bb.xmax(), bb.ymax(), bb.zmax())); - compute_elements(); - are_buffers_initialized = false; + are_buffers_initialized = false; this->showEntireScene(); } void Viewer::draw() { + glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h index e5dc086f76f..c03977f900a 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/Viewer.h @@ -25,11 +25,11 @@ #include #include -#include +#include #include #include #include -class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core +class Viewer : public QGLViewer, QOpenGLFunctions_2_1 { Q_OBJECT diff --git a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp index cc894397138..1b82b6b3d63 100644 --- a/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_c3t3_item.cpp @@ -51,16 +51,16 @@ void Scene_c3t3_item::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec3 inColor; \n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec3 inColor; \n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" - "out highp vec4 color; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 color; \n" "void main(void)\n" "{\n" " color = vec4(inColor, 1.0); \n" @@ -73,9 +73,9 @@ void Scene_c3t3_item::compile_shaders() const char fragment_source[] = { "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" - "in vec4 color; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" @@ -130,8 +130,8 @@ void Scene_c3t3_item::compile_shaders() //Vertex source code const char vertex_source_grid[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix; \n" @@ -143,7 +143,7 @@ void Scene_c3t3_item::compile_shaders() //Fragment source code const char fragment_source_grid[] = { - "#version 330 \n" + "#version 120 \n" "uniform vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" diff --git a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp index e8690bcf679..2b89086350e 100644 --- a/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_implicit_function_item.cpp @@ -68,8 +68,8 @@ void Scene_implicit_function_item::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" @@ -80,7 +80,7 @@ void Scene_implicit_function_item::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "uniform vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" @@ -115,24 +115,24 @@ void Scene_implicit_function_item::compile_shaders() //Vertex source code const char tex_vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec2 tex_coord; \n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec2 tex_coord; \n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix;\n" - "out highp vec2 texc;\n" + "varying highp vec2 texc;\n" "void main(void)\n" "{\n" " gl_Position = mvp_matrix * f_matrix * vertex;\n" " texc = tex_coord;\n" "}" }; - //Vertex source code + //Fragment source code const char tex_fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "uniform sampler2D texture;\n" - "in highp vec2 texc;\n" + "varying highp vec2 texc;\n" "void main(void) { \n" "gl_FragColor = texture2D(texture, texc.st);\n" "} \n" diff --git a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp index dcaaa23c337..9a2a9a14fdf 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_polygon_soup.cpp @@ -125,14 +125,14 @@ void Scene_polygon_soup::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -143,9 +143,9 @@ void Scene_polygon_soup::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform vec4 color; \n" "uniform bool is_two_side; \n" "uniform highp vec4 light_pos; \n" diff --git a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp index 6d410ba491e..c1e552e2311 100644 --- a/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_polyhedron_item.cpp @@ -54,14 +54,14 @@ void Scene_polyhedron_item::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -72,9 +72,9 @@ void Scene_polyhedron_item::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform vec4 color; \n" "uniform bool is_two_side; \n" "uniform highp vec4 light_pos; \n" diff --git a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp index 408c2e93ac1..a8d3c81a9d5 100644 --- a/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp +++ b/Mesh_3/demo/Mesh_3/Scene_segmented_image_item.cpp @@ -497,16 +497,16 @@ void Scene_segmented_image_item::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 inColor;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 inColor;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" - "out highp vec4 color; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 color; \n" "void main(void)\n" "{\n" " color=inColor; \n" @@ -518,10 +518,10 @@ void Scene_segmented_image_item::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" - "in highp vec4 color; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" + "varying highp vec4 color; \n" "uniform bool is_two_side; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" diff --git a/Mesh_3/demo/Mesh_3/Volume_plane.h b/Mesh_3/demo/Mesh_3/Volume_plane.h index 4cc1e3e04f8..0efdaab4fb1 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane.h +++ b/Mesh_3/demo/Mesh_3/Volume_plane.h @@ -423,9 +423,6 @@ void Volume_plane::init() { template void Volume_plane::initShaders() { - program.create(); - - QOpenGLShader *vertex = new QOpenGLShader(QOpenGLShader::Vertex); vertex->compileSourceCode(vertexShader_source); @@ -436,7 +433,6 @@ void Volume_plane::initShaders() { program.link(); - program_bordures.create(); QOpenGLShader *vertex_bordures = new QOpenGLShader(QOpenGLShader::Vertex); vertex_bordures->compileSourceCode(vertexShader_bordures_source); diff --git a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp index 379f5585c39..c2b3891aad2 100644 --- a/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp +++ b/Mesh_3/demo/Mesh_3/Volume_plane_intersection.cpp @@ -16,8 +16,8 @@ void Volume_plane_intersection::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix; \n" "void main(void)\n" @@ -28,7 +28,7 @@ void Volume_plane_intersection::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "void main(void) { \n" "gl_FragColor = vec4(1.0,0.0,0.0,1.0); \n" "} \n" diff --git a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h index 3e590acd239..9712cc45787 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL_demo/Viewer.h @@ -4,13 +4,13 @@ #include #include #include -#include +#include // forward declarations class QWidget; class Scene_draw_interface; -class VIEWER_EXPORT Viewer : public QGLViewer, public QOpenGLFunctions_3_3_Core { +class VIEWER_EXPORT Viewer : public QGLViewer, public QOpenGLFunctions_2_1 { Q_OBJECT diff --git a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp index 564ec702e70..e9ef91d85d2 100644 --- a/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp +++ b/Mesh_3/demo/Mesh_3/src/CGAL_demo/Viewer.cpp @@ -53,6 +53,7 @@ void Viewer::initializeGL() void Viewer::draw_aux(bool with_names) { QGLViewer::draw(); + glEnable(GL_DEPTH_TEST); if(scene == 0) return; diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp index e922b37f0f3..b530307cb5a 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.cpp @@ -34,8 +34,8 @@ void Scene::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -45,7 +45,7 @@ void Scene::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" @@ -82,15 +82,15 @@ void Scene::compile_shaders() //Vertex source code const char vertex_source_spheres[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 center;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 center;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -101,9 +101,9 @@ void Scene::compile_shaders() //Fragment source code const char fragment_source_spheres[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" @@ -159,18 +159,18 @@ void Scene::compile_shaders() //Vertex source code const char vertex_source_cylinders[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 transfo1;\n" - "in highp vec4 transfo2;\n" - "in highp vec4 transfo3;\n" - "in highp vec4 transfo4;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 transfo1;\n" + "attribute highp vec4 transfo2;\n" + "attribute highp vec4 transfo3;\n" + "attribute highp vec4 transfo4;\n" "mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -488,8 +488,11 @@ void Scene::initialize_buffers() rendering_program_spheres.enableAttributeArray(centerLocation[0]); rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); buffers[0].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[3].release(); rendering_program_spheres.release(); @@ -538,13 +541,15 @@ void Scene::initialize_buffers() rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); buffers[13].release(); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); - glVertexAttribDivisor(centerLocation[1],1); - glVertexAttribDivisor(centerLocation[2],1); - glVertexAttribDivisor(centerLocation[3],1); - glVertexAttribDivisor(centerLocation[4],1); - - glVertexAttribDivisor(normalsLocation[1],0); + glVertexAttribDivisor(normalsLocation[1],0); + } vao[8].release(); vao[9].bind(); @@ -590,13 +595,15 @@ void Scene::initialize_buffers() rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); buffers[18].release(); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); - glVertexAttribDivisor(centerLocation[1],1); - glVertexAttribDivisor(centerLocation[2],1); - glVertexAttribDivisor(centerLocation[3],1); - glVertexAttribDivisor(centerLocation[4],1); - - glVertexAttribDivisor(normalsLocation[1],0); + glVertexAttribDivisor(normalsLocation[1],0); + } vao[9].release(); @@ -642,14 +649,15 @@ void Scene::initialize_buffers() rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); buffers[22].release(); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); - glVertexAttribDivisor(centerLocation[1],1); - glVertexAttribDivisor(centerLocation[2],1); - glVertexAttribDivisor(centerLocation[3],1); - glVertexAttribDivisor(centerLocation[4],1); - - glVertexAttribDivisor(normalsLocation[1],0); - + glVertexAttribDivisor(normalsLocation[1],0); + } vao[10].release(); rendering_program_cylinders.release(); @@ -727,6 +735,25 @@ void Scene::init() { // undo from QGLViewer internal initializeGL function // glDisable(GL_COLOR_MATERIAL); initializeOpenGLFunctions(); + glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDARBPROC)ui->viewer->context()->getProcAddress("glDrawArraysInstancedARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glDrawArraysInstancedARB : extension not found. Wireframe mode will be forced."; + extension_is_found = false; + } + else + extension_is_found = true; + + glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORARBPROC)ui->viewer->context()->getProcAddress("glVertexAttribDivisorARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glVertexAttribDivisorARB : extension not found. Wireframe mode will be forced."; + extension_is_found = false; + } + else + extension_is_found = true; + + wireframe = !extension_is_found; // camera // only 2.7 gets an 'f' as VC++ warns if we don't ui->viewer->camera()->setPosition(Vec(0.5,0.5,2.7f)); @@ -753,6 +780,7 @@ void Scene::init() { // Draws the triangulation void Scene::draw() { + glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); gl_draw_location(); @@ -971,8 +999,11 @@ void Scene::update_position() rendering_program_spheres.enableAttributeArray(centerLocation[0]); rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); buffers[5].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[1],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[1],0); + } vao[7].release(); ui->viewer->update(); diff --git a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h index 4f0db183696..4c012aa04dc 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h +++ b/Periodic_3_triangulation_3/demo/Periodic_3_triangulation_3/Scene.h @@ -6,12 +6,12 @@ #include #include #include -#include +#include #include #include #include -class Scene : public QObject, QOpenGLFunctions_3_3_Core +class Scene : public QObject, QOpenGLFunctions_2_1 { Q_OBJECT @@ -144,9 +144,9 @@ public Q_SLOTS: ui->viewer->update(); } void toggle_wireframe(bool on) { - wireframe = on; - ( on ? glDisable(GL_LIGHTING) : glEnable(GL_LIGHTING) ); - changed(); + wireframe = !(!on && extension_is_found); + ( on ? glDisable(GL_LIGHTING) : glEnable(GL_LIGHTING) ); + changed(); } void toggle_in_plane(bool on) { in_plane = on; @@ -287,11 +287,16 @@ private: std::vector transfo4_square; bool are_buffers_initialized; + bool extension_is_found; QOpenGLBuffer buffers[24]; QOpenGLVertexArrayObject vao[12]; QOpenGLShaderProgram rendering_program; QOpenGLShaderProgram rendering_program_spheres; QOpenGLShaderProgram rendering_program_cylinders; + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); + typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); + PFNGLDRAWARRAYSINSTANCEDARBPROC glDrawArraysInstanced; + PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisor; void initialize_buffers(); void compute_elements(); void attrib_buffers(QGLViewer*); diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp index 7d1b9a93d09..cd59c5dc42f 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.cpp @@ -27,6 +27,7 @@ Viewer::sceneChanged() void Viewer::draw() { + glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); QColor color; @@ -265,8 +266,8 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -276,7 +277,7 @@ void Viewer::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.h b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.h index cce393ebe1d..c03df5c5c65 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.h +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Viewer.h @@ -3,14 +3,14 @@ #include "Scene.h" #include -#include +#include #include #include #include #include -class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { +class Viewer : public QGLViewer, QOpenGLFunctions_2_1 { typedef qglviewer::Vec Vec; diff --git a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h index 6a21b1b4ff5..3bebc4df680 100644 --- a/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h +++ b/Periodic_3_triangulation_3/include/CGAL/Periodic_3_triangulation_3.h @@ -2175,6 +2175,7 @@ Periodic_3_triangulation_3::periodic_insert( // This only holds for Delaunay CGAL_triangulation_assertion(lt != VERTEX); + CGAL_USE(lt); // Choose the periodic copy of tester.point() that is inside c. Offset current_off = get_location_offset(tester, c); diff --git a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h index 10eb01aa7c8..fe99eda60b2 100644 --- a/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h +++ b/Polyhedron/demo/Polyhedron/CGAL_demo/Viewer_interface.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include // forward declarations class QWidget; @@ -14,7 +14,7 @@ class QKeyEvent; #include "../Viewer_config.h" // for VIEWER_EXPORT -class VIEWER_EXPORT Viewer_interface : public QGLViewer, public QOpenGLFunctions_3_3_Core { +class VIEWER_EXPORT Viewer_interface : public QGLViewer, public QOpenGLFunctions_2_1 { Q_OBJECT @@ -30,6 +30,11 @@ public: static QString dumpFrame(const qglviewer::Frame&); virtual bool inFastDrawing() const = 0; + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); + typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); + PFNGLDRAWARRAYSINSTANCEDARBPROC glDrawArraysInstanced; + PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisor; + bool extension_is_found; GLfloat pickMatrix_[16]; Q_SIGNALS: @@ -47,6 +52,7 @@ public Q_SLOTS: virtual QString dumpCameraCoordinates() = 0; virtual bool moveCameraToCoordinates(QString, float animation_duration = 0.5f) = 0; + }; // end class Viewer_interface #endif // VIEWER_INTERFACE_H diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp index e56572adff8..8a06dd6344e 100644 --- a/Polyhedron/demo/Polyhedron/MainWindow.cpp +++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp @@ -959,7 +959,7 @@ QList MainWindow::getSelectedSceneItemIndices() const void MainWindow::selectionChanged() { - scene->setSelectedItem(getSelectedSceneItemIndex()); + scene->setSelectedItemIndex(getSelectedSceneItemIndex()); scene->setSelectedItemsList(getSelectedSceneItemIndices()); Scene_item* item = scene->item(getSelectedSceneItemIndex()); if(item != NULL && item->manipulatable()) { diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.ui b/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.ui index a699faed2b8..917d82a299a 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.ui +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_advancing_front_plugin.ui @@ -30,7 +30,7 @@ 0.000000000000000 - 30.000000000000000 + 999999999.000000000000000 0.000000000000000 diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp index 8c30ec50cb2..43a9325e747 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_hole_filling_plugin.cpp @@ -35,6 +35,7 @@ #include "Kernel_type.h" #include +#include // Class for visualizing holes in a polyhedron // provides mouse selection functionality @@ -307,13 +308,7 @@ public: void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m); Scene_hole_visualizer* get_hole_visualizer(Scene_polyhedron_item* poly_item) { - // did not use a map to assoc Scene_polyhedron_item with Scene_hole_visualizer to prevent crowded code - for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end; ++i) { - Scene_hole_visualizer* hole_visualizer = qobject_cast(scene->item(i)); - if(hole_visualizer && hole_visualizer->poly_item == poly_item) - { return hole_visualizer; } - } - return NULL; + return visualizers[poly_item]; } public Q_SLOTS: @@ -353,6 +348,9 @@ private: QDockWidget* dock_widget; Ui::HoleFilling ui_widget; + //Maintains a reference between all the visualizers and their poly_item + // to ease the management of the visualizers + QMap visualizers; // hold created facet for accept reject functionality std::vector new_facets; Scene_polyhedron_item* last_active_item; // always keep it NULL while not active-reject state @@ -427,11 +425,18 @@ void Polyhedron_demo_hole_filling_plugin::item_about_to_be_destroyed(Scene_item* if(poly_item) { // erase assoc polylines item scene->erase( scene->item_id( get_hole_visualizer(poly_item) ) ); + visualizers.remove(poly_item); // close accept-reject dialog if it is open if(last_active_item == poly_item) { on_Accept_button(); } } + else { + Scene_hole_visualizer* visu_item = qobject_cast(scene_item); + if(visu_item) { + visualizers.remove(visu_item->poly_item); + } + } } // removes Scene_hole_visualizer items void Polyhedron_demo_hole_filling_plugin::dock_widget_closed() { @@ -460,10 +465,12 @@ void Polyhedron_demo_hole_filling_plugin::on_Visualize_holes_button() { } Scene_hole_visualizer* hole_visualizer = new Scene_hole_visualizer(poly_item, mw); + visualizers[poly_item] = hole_visualizer; connect(hole_visualizer, SIGNAL(itemChanged()), this, SLOT(hole_visualizer_changed())); if(hole_visualizer->polyline_data_list.empty()) { print_message("There is no hole in selected polyhedron item!"); + visualizers.remove(poly_item); delete hole_visualizer; return; } @@ -590,6 +597,7 @@ void Polyhedron_demo_hole_filling_plugin::hole_visualizer_changed() { Scene_hole_visualizer* hole_visualizer = qobject_cast(this->sender()); if(hole_visualizer && hole_visualizer->polyline_data_list.empty()) { scene->erase( scene->item_id(hole_visualizer)); + visualizers.remove(hole_visualizer->poly_item); } } // helper function for filling holes diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp index e8d3625ef3a..98161cd4b11 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_mean_curvature_flow_skeleton_plugin.cpp @@ -155,6 +155,9 @@ public: connect(ui->pushButton_segment, SIGNAL(clicked()), this, SLOT(on_actionSegment())); + QObject* scene_object = dynamic_cast(scene); + connect(scene_object, SIGNAL(itemAboutToBeDestroyed(Scene_item*)), + this, SLOT(on_actionItemAboutToBeDestroyed(Scene_item*))); } QList actions() const { @@ -719,10 +722,6 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionRun() delete temp; } - QObject* scene_object = dynamic_cast(scene); - connect(scene_object, SIGNAL(itemAboutToBeDestroyed(Scene_item*)), - this, SLOT(on_actionItemAboutToBeDestroyed(Scene_item*))); - //#define DRAW_NON_FIXED_POINTS #ifdef DRAW_NON_FIXED_POINTS // draw non-fixed points diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp index 01bc86868bb..30c6e3d0d76 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_off_plugin.cpp @@ -5,6 +5,9 @@ #include "Polyhedron_demo_io_plugin_interface.h" #include +#include +#include + class Polyhedron_demo_off_plugin : public QObject, public Polyhedron_demo_io_plugin_interface @@ -37,7 +40,12 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) { std::cerr << "Error! Cannot open file " << (const char*)fileinfo.filePath().toUtf8() << std::endl; return NULL; } - + + // to detect isolated vertices + CGAL::File_scanner_OFF scanner( in, false); + std::size_t total_nb_of_vertices = scanner.size_of_vertices(); + in.seekg(0); + // Try to read .off in a polyhedron Scene_polyhedron_item* item = new Scene_polyhedron_item(); item->setName(fileinfo.baseName()); @@ -56,6 +64,14 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) { } return soup_item; } + else + if( total_nb_of_vertices!= item->polyhedron()->size_of_vertices()) + { + QMessageBox::warning((QWidget*)NULL, + tr("Isolated vertices found"), + tr("%1 isolated vertices ignored") + .arg(total_nb_of_vertices-item->polyhedron()->size_of_vertices())); + } return item; } diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp index a8825d7659b..7fb2f93a929 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_polyhedron_slicer_plugin.cpp @@ -229,6 +229,7 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() get_base_1_2(bases); // no need to check since we call on_Update_plane_button_clicked Epic_kernel::Vector_3 base_1(bases[0], bases[1], bases[2]); Epic_kernel::Vector_3 base_2(bases[3], bases[4], bases[5]); + const Epic_kernel::Vector_3 normal = CGAL::cross_product(base_1, base_2); // get distance between planes bool to_double_ok = true; @@ -255,7 +256,7 @@ void Polyhedron_demo_polyhedron_slicer_plugin::on_Generate_button_clicked() //Epic_kernel::Plane_3 plane(n[0], n[1], n[2], - n * new_pos); Epic_kernel::Point_3 new_pos_cgal(new_pos[0], new_pos[1], new_pos[2]); - Epic_kernel::Plane_3 plane(new_pos_cgal, new_pos_cgal + base_1, new_pos_cgal + base_2); + Epic_kernel::Plane_3 plane(new_pos_cgal, normal); if(!CGAL::do_intersect(cgal_bbox, plane)) { if(dir == -1) { break; } diff --git a/Polyhedron/demo/Polyhedron/Scene.cpp b/Polyhedron/demo/Polyhedron/Scene.cpp index d3fc928e732..fc573bc5776 100644 --- a/Polyhedron/demo/Polyhedron/Scene.cpp +++ b/Polyhedron/demo/Polyhedron/Scene.cpp @@ -288,7 +288,7 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer) ::glPopName(); } } - +glDepthFunc(GL_LEQUAL); // Wireframe OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { @@ -353,6 +353,7 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer) } } + // Points OpenGL drawing for(int index = 0; index < m_entries.size(); ++index) { @@ -381,6 +382,8 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer) ::glPopName(); } } + glDepthFunc(GL_LESS); + } int diff --git a/Polyhedron/demo/Polyhedron/Scene.h b/Polyhedron/demo/Polyhedron/Scene.h index 2777b23715c..a8990104a01 100644 --- a/Polyhedron/demo/Polyhedron/Scene.h +++ b/Polyhedron/demo/Polyhedron/Scene.h @@ -115,6 +115,11 @@ public Q_SLOTS: void itemChanged(int i); void itemChanged(Scene_item*); + void setSelectedItemIndex(int i) + { + selected_item = i; + } + void setSelectedItem(int i ) { selected_item = i; diff --git a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp index e0aaecaf4bb..c1a2ec5a506 100644 --- a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp @@ -73,7 +73,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item const char vertex_shader_source_bbox[] = { - + "#version 120 \n" "attribute highp vec3 vertex; \n" "attribute highp vec3 colors; \n" @@ -92,6 +92,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item }; const char fragment_shader_source[]= { + "#version 120 \n" "varying vec3 fColors; \n" " \n" "void main(void) \n" @@ -214,8 +215,11 @@ void Scene_edit_polyhedron_item::initialize_buffers(Viewer_interface *viewer =0) program->setAttributeBuffer("center",GL_DOUBLE,0,3); buffers[8].release(); - viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); - viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + if(viewer->extension_is_found) + { + viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); + viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + } vaos[3]->release(); } //vao for the BBOX @@ -292,8 +296,11 @@ void Scene_edit_polyhedron_item::initialize_buffers(Viewer_interface *viewer =0) program->setAttributeBuffer("center",GL_DOUBLE,0,3); buffers[16].release(); - viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); - viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + if(viewer->extension_is_found) + { + viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); + viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + } vaos[6]->release(); } //vao for the axis @@ -501,7 +508,7 @@ void Scene_edit_polyhedron_item::draw_ROI_and_control_vertices(Viewer_interface* color.set_rgb_color(0, 1.f, 0); if(ui_widget->ShowROICheckBox->isChecked()) { - if(!ui_widget->ShowAsSphereCheckBox->isChecked()) { + if(!ui_widget->ShowAsSphereCheckBox->isChecked() || !viewer->extension_is_found) { vaos[1]->bind(); program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); @@ -524,7 +531,7 @@ void Scene_edit_polyhedron_item::draw_ROI_and_control_vertices(Viewer_interface* } } - if(!ui_widget->ShowAsSphereCheckBox->isChecked()) { + if(!ui_widget->ShowAsSphereCheckBox->isChecked() || !viewer->extension_is_found) { vaos[5]->bind(); program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT); diff --git a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp index 9314bdbcdea..93a8be66aea 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_polylines_item.cpp @@ -51,40 +51,63 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const } //vao for the spheres { - program = getShaderProgram(PROGRAM_INSTANCED, viewer); - program->bind(); + if(viewer->extension_is_found) + { + program = getShaderProgram(PROGRAM_INSTANCED, viewer); + program->bind(); - vaos[1]->bind(); - buffers[1].bind(); - buffers[1].allocate(positions_spheres.data(), - static_cast(positions_spheres.size()*sizeof(float))); - program->enableAttributeArray("vertex"); - program->setAttributeBuffer("vertex",GL_FLOAT,0,3); - buffers[1].release(); + vaos[1]->bind(); + buffers[1].bind(); + buffers[1].allocate(positions_spheres.data(), + static_cast(positions_spheres.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[1].release(); - buffers[2].bind(); - buffers[2].allocate(normals_spheres.data(), - static_cast(normals_spheres.size()*sizeof(float))); - program->enableAttributeArray("normals"); - program->setAttributeBuffer("normals",GL_FLOAT,0,3); - buffers[2].release(); + buffers[2].bind(); + buffers[2].allocate(normals_spheres.data(), + static_cast(normals_spheres.size()*sizeof(float))); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[2].release(); - buffers[3].bind(); - buffers[3].allocate(color_spheres.data(), - static_cast(color_spheres.size()*sizeof(float))); - program->enableAttributeArray("colors"); - program->setAttributeBuffer("colors",GL_FLOAT,0,3); - buffers[3].release(); + buffers[3].bind(); + buffers[3].allocate(color_spheres.data(), + static_cast(color_spheres.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[3].release(); - buffers[4].bind(); - buffers[4].allocate(positions_center.data(), - static_cast(positions_center.size()*sizeof(float))); - program->enableAttributeArray("center"); - program->setAttributeBuffer("center",GL_FLOAT,0,3); - buffers[4].release(); + buffers[4].bind(); + buffers[4].allocate(positions_center.data(), + static_cast(positions_center.size()*sizeof(float))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_FLOAT,0,3); + buffers[4].release(); - viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); - viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); + viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + } + else + { + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT, viewer); + program->bind(); + + vaos[1]->bind(); + buffers[1].bind(); + buffers[1].allocate(positions_center.data(), + static_cast(positions_center.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[1].release(); + + buffers[2].bind(); + buffers[2].allocate(color_spheres.data(), + static_cast(color_spheres.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[2].release(); + } vaos[1]->release(); program->release(); @@ -92,39 +115,51 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const //vao for the wired spheres { - program = getShaderProgram(PROGRAM_INSTANCED_WIRE, viewer); - program->bind(); + if(viewer->extension_is_found) + { + program = getShaderProgram(PROGRAM_INSTANCED_WIRE, viewer); + program->bind(); - vaos[2]->bind(); - buffers[5].bind(); - buffers[5].allocate(positions_wire_spheres.data(), - static_cast(positions_wire_spheres.size()*sizeof(float))); - program->enableAttributeArray("vertex"); - program->setAttributeBuffer("vertex",GL_FLOAT,0,3); - buffers[5].release(); - QColor temp = this->color(); - program->setAttributeValue("colors", temp); + vaos[2]->bind(); + buffers[5].bind(); + buffers[5].allocate(positions_wire_spheres.data(), + static_cast(positions_wire_spheres.size()*sizeof(float))); + program->enableAttributeArray("vertex"); + program->setAttributeBuffer("vertex",GL_FLOAT,0,3); + buffers[5].release(); - program->setAttributeValue("normals",QVector3D(0.0,0.0,0.0)); - buffers[6].bind(); - buffers[6].allocate(color_spheres.data(), - static_cast(color_spheres.size()*sizeof(float))); - program->enableAttributeArray("colors"); - program->setAttributeBuffer("colors",GL_FLOAT,0,3); - buffers[6].release(); + buffers[3].bind(); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[3].release(); - buffers[7].bind(); - buffers[7].allocate(positions_center.data(), - static_cast(positions_center.size()*sizeof(float))); - program->enableAttributeArray("center"); - program->setAttributeBuffer("center",GL_FLOAT,0,3); - buffers[7].release(); + buffers[2].bind(); + program->enableAttributeArray("normals"); + program->setAttributeBuffer("normals",GL_FLOAT,0,3); + buffers[2].release(); - viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); - viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); - vaos[2]->release(); - program->release(); + buffers[6].bind(); + buffers[6].allocate(color_spheres.data(), + static_cast(color_spheres.size()*sizeof(float))); + program->enableAttributeArray("colors"); + program->setAttributeBuffer("colors",GL_FLOAT,0,3); + buffers[6].release(); + + buffers[7].bind(); + buffers[7].allocate(positions_center.data(), + static_cast(positions_center.size()*sizeof(float))); + program->enableAttributeArray("center"); + program->setAttributeBuffer("center",GL_FLOAT,0,3); + buffers[7].release(); + + + viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1); + viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1); + + vaos[2]->release(); + program->release(); + } } are_buffers_filled = true; @@ -283,7 +318,7 @@ Scene_polylines_item::Scene_polylines_item() ,d(new Scene_polylines_item_private()) ,nbSpheres(0) { - setRenderingMode(Flat); + setRenderingMode(FlatPlusEdges); changed(); } @@ -363,8 +398,7 @@ Scene_polylines_item::toolTip() const { bool Scene_polylines_item::supportsRenderingMode(RenderingMode m) const { return (m == Wireframe || - m == Flat || - m == Flat || + m == FlatPlusEdges || m == Points); } @@ -376,26 +410,30 @@ Scene_polylines_item::draw(Viewer_interface* viewer) const { initialize_buffers(viewer); if(d->draw_extremities) { - vaos[1]->bind(); - program = getShaderProgram(PROGRAM_INSTANCED); - attrib_buffers(viewer, PROGRAM_INSTANCED); - program->bind(); - viewer->glDrawArraysInstanced(GL_TRIANGLES, 0, - static_cast(positions_spheres.size()/3), nbSpheres); - program->release(); - vaos[1]->release(); - } - if(renderingMode() == Flat) - { - vaos[0]->bind(); - attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); - program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); - program->bind(); - QColor temp = this->color(); - program->setAttributeValue("colors", temp); - viewer->glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/4)); - program->release(); - vaos[0]->release(); + if(viewer->extension_is_found) + { + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_INSTANCED); + attrib_buffers(viewer, PROGRAM_INSTANCED); + program->bind(); + viewer->glDrawArraysInstanced(GL_TRIANGLES, 0, + static_cast(positions_spheres.size()/3), nbSpheres); + program->release(); + vaos[1]->release(); + } + else + { + vaos[1]->bind(); + program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); + attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); + glPointSize(8.0f); + glEnable(GL_POINT_SMOOTH); + program->bind(); + viewer->glDrawArrays(GL_POINTS, 0, static_cast(positions_center.size()/3)); + glDisable(GL_POINT_SMOOTH); + program->release(); + vaos[1]->release(); + } } } @@ -409,21 +447,23 @@ Scene_polylines_item::draw_edges(Viewer_interface* viewer) const { attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT); program = getShaderProgram(PROGRAM_WITHOUT_LIGHT); program->bind(); - QColor temp = this->color(); - program->setAttributeValue("colors", temp); + program->setAttributeValue("colors", this->color()); viewer->glDrawArrays(GL_LINES, 0, static_cast(positions_lines.size()/4)); program->release(); vaos[0]->release(); if(d->draw_extremities) { - vaos[2]->bind(); - attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE); - program = getShaderProgram(PROGRAM_INSTANCED_WIRE); - program->bind(); - viewer->glDrawArraysInstanced(GL_LINES, 0, - static_cast(positions_wire_spheres.size()/3), nbSpheres); - program->release(); - vaos[2]->release(); + if(viewer->extension_is_found) + { + vaos[2]->bind(); + attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE); + program = getShaderProgram(PROGRAM_INSTANCED_WIRE); + program->bind(); + viewer->glDrawArraysInstanced(GL_LINES, 0, + static_cast(positions_wire_spheres.size()/3), nbSpheres); + program->release(); + vaos[2]->release(); + } } } diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index 78e08c6dee0..7da7c0d194f 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -105,6 +105,25 @@ void Viewer::initializeGL() { QGLViewer::initializeGL(); initializeOpenGLFunctions(); + glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDARBPROC)this->context()->getProcAddress("glDrawArraysInstancedARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glDrawArraysInstancedARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; + + glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORARBPROC)this->context()->getProcAddress("glVertexAttribDivisorARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glVertexAttribDivisorARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; + + setBackgroundColor(::Qt::white); d->scene->initializeGL(); @@ -202,6 +221,8 @@ void Viewer_impl::draw_aux(bool with_names, Viewer* viewer) scene->drawWithNames(viewer); else scene->draw(viewer); + ::glDisable(GL_POLYGON_OFFSET_FILL); + ::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); } void Viewer::drawWithNames() diff --git a/Polyhedron/demo/Polyhedron/resources/shader_instanced.v b/Polyhedron/demo/Polyhedron/resources/shader_instanced.v index 0f7d6ff4740..d353c8d9949 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_instanced.v +++ b/Polyhedron/demo/Polyhedron/resources/shader_instanced.v @@ -1,4 +1,4 @@ -#version 330 +#version 120 attribute highp vec4 vertex; attribute highp vec3 normals; attribute highp vec3 colors; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_light.f b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f index 9fa9b65352f..8d958ab4085 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_light.f +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f @@ -1,4 +1,4 @@ -#version 330 +#version 120 varying highp vec4 color; varying highp vec4 fP; varying highp vec3 fN; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_light.v b/Polyhedron/demo/Polyhedron/resources/shader_with_light.v index cad171b3084..fa04afac9df 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_light.v +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_light.v @@ -1,4 +1,4 @@ -#version 330 +#version 120 attribute highp vec4 vertex; attribute highp vec3 normals; attribute highp vec3 colors; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f index 2c90da7dba8..4d9bc7ca323 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.f @@ -1,4 +1,4 @@ -#version 330 +#version 120 varying highp vec3 fColors; varying highp vec2 f_texCoord; uniform sampler2D s_texture; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v index 09ced2cacaf..bfecbfc3b74 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_texture.v @@ -1,4 +1,4 @@ -#version 330 +#version 120 attribute highp vec4 vertex; attribute highp vec3 normal; attribute highp vec3 color_facets; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f index ef0d574d1bc..888152005a4 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.f @@ -1,4 +1,4 @@ -#version 330 +#version 120 varying highp vec3 fColors; varying highp vec2 f_texCoord; uniform highp sampler2D s_texture; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v index 7d3010a1ca1..7770cc309fe 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_textured_edges.v @@ -1,4 +1,4 @@ -#version 330 +#version 120 attribute highp vec4 vertex; attribute highp vec2 v_texCoord; uniform highp vec3 color_lines; diff --git a/Polyhedron/demo/Polyhedron/resources/shader_without_light.f b/Polyhedron/demo/Polyhedron/resources/shader_without_light.f index 6a14655a5a7..32b3ebd0455 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_without_light.f +++ b/Polyhedron/demo/Polyhedron/resources/shader_without_light.f @@ -1,4 +1,4 @@ -#version 330 +#version 120 varying highp vec4 color; void main(void) { diff --git a/Polyhedron/demo/Polyhedron/resources/shader_without_light.v b/Polyhedron/demo/Polyhedron/resources/shader_without_light.v index 6f9e362709b..69e5741f510 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_without_light.v +++ b/Polyhedron/demo/Polyhedron/resources/shader_without_light.v @@ -1,12 +1,12 @@ - #version 330 - attribute highp vec4 vertex; - attribute highp vec3 colors; - uniform highp mat4 mvp_matrix; - uniform highp mat4 f_matrix; - varying highp vec4 color; - void main(void) - { - color = vec4(colors, 1.0); - gl_Position = mvp_matrix * f_matrix * vertex; - } +#version 120 +attribute highp vec4 vertex; +attribute highp vec3 colors; +uniform highp mat4 mvp_matrix; +uniform highp mat4 f_matrix; +varying highp vec4 color; +void main(void) +{ + color = vec4(colors, 1.0); + gl_Position = mvp_matrix * f_matrix * vertex; +} diff --git a/Triangulation_3/demo/Triangulation_3/Viewer.cpp b/Triangulation_3/demo/Triangulation_3/Viewer.cpp index 2262eeab95f..495e52b8e4b 100644 --- a/Triangulation_3/demo/Triangulation_3/Viewer.cpp +++ b/Triangulation_3/demo/Triangulation_3/Viewer.cpp @@ -18,6 +18,25 @@ using namespace std; void Viewer::init() { initializeOpenGLFunctions(); + glDrawArraysInstanced = (PFNGLDRAWARRAYSINSTANCEDARBPROC)this->context()->getProcAddress("glDrawArraysInstancedARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glDrawArraysInstancedARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; + + glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORARBPROC)this->context()->getProcAddress("glVertexAttribDivisorARB"); + if(!glDrawArraysInstanced) + { + qDebug()<<"glVertexAttribDivisorARB : extension not found. Spheres will be displayed as points."; + extension_is_found = false; + } + else + extension_is_found = true; +// extension_is_found = false; + /* Initial timer for playing incremental construction */ m_pTimer = new QTimer(this); connect(m_pTimer, SIGNAL(timeout()), this, SLOT(incremental_insert())); @@ -162,8 +181,8 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -173,7 +192,7 @@ void Viewer::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 330 \n" + "#version 120 \n" "uniform highp vec4 color; \n" "void main(void) { \n" "gl_FragColor = color; \n" @@ -210,15 +229,15 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source_spheres[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 center;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 center;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -229,9 +248,9 @@ void Viewer::compile_shaders() //Fragment source code const char fragment_source_spheres[] = { - "#version 330 \n" - "in highp vec4 fP; \n" - "in highp vec3 fN; \n" + "#version 120 \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "uniform vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" @@ -288,18 +307,18 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source_cylinders[] = { - "#version 330 \n" - "in highp vec4 vertex;\n" - "in highp vec3 normal;\n" - "in highp vec4 transfo1;\n" - "in highp vec4 transfo2;\n" - "in highp vec4 transfo3;\n" - "in highp vec4 transfo4;\n" + "#version 120 \n" + "attribute highp vec4 vertex;\n" + "attribute highp vec3 normal;\n" + "attribute highp vec4 transfo1;\n" + "attribute highp vec4 transfo2;\n" + "attribute highp vec4 transfo3;\n" + "attribute highp vec4 transfo4;\n" "mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "out highp vec4 fP; \n" - "out highp vec3 fN; \n" + "varying highp vec4 fP; \n" + "varying highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -714,19 +733,24 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[13].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[11].release(); //Empty Sphere vao[12].bind(); - buffers[14].bind(); - buffers[14].allocate(pos_emptySphere->data(), pos_emptySphere->size()*sizeof(float)); - centerLocation[0] = rendering_program_spheres.attributeLocation("center"); - rendering_program_spheres.enableAttributeArray(centerLocation[0]); - rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); - buffers[14].release(); - + if(extension_is_found) + { + buffers[14].bind(); + buffers[14].allocate(pos_emptySphere->data(), pos_emptySphere->size()*sizeof(float)); + centerLocation[0] = rendering_program_spheres.attributeLocation("center"); + rendering_program_spheres.enableAttributeArray(centerLocation[0]); + rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3); + buffers[14].release(); + } buffers[32].bind(); buffers[32].allocate(normals_emptySphere->data(), normals_emptySphere->size()*sizeof(float)); normalsLocation[0] = rendering_program_spheres.attributeLocation("normal"); @@ -741,8 +765,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[16].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[12].release(); //Vertex Sphere @@ -767,8 +794,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[13].release(); //New point Sphere @@ -791,8 +821,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[14].release(); //Selected point Sphere @@ -815,8 +848,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[15].release(); //Moving point Sphere @@ -839,8 +875,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[16].release(); //Querry point Sphere @@ -863,8 +902,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[17].release(); //Nearest neighbor Sphere @@ -887,8 +929,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[18].release(); //incremental list @@ -910,8 +955,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[25].release(); //incremental next point @@ -933,8 +981,11 @@ void Viewer::initialize_buffers() rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3); buffers[17].release(); - glVertexAttribDivisor(centerLocation[0],1); - glVertexAttribDivisor(normalsLocation[0],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[0],1); + glVertexAttribDivisor(normalsLocation[0],0); + } vao[26].release(); } @@ -985,12 +1036,14 @@ void Viewer::initialize_buffers() rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); buffers[23].release(); - - glVertexAttribDivisor(centerLocation[1],1); - glVertexAttribDivisor(centerLocation[2],1); - glVertexAttribDivisor(centerLocation[3],1); - glVertexAttribDivisor(centerLocation[4],1); - glVertexAttribDivisor(normalsLocation[1],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + glVertexAttribDivisor(normalsLocation[1],0); + } vao[19].release(); @@ -1035,13 +1088,14 @@ void Viewer::initialize_buffers() rendering_program_cylinders.enableAttributeArray(centerLocation[4]); rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4); buffers[27].release(); - - - glVertexAttribDivisor(centerLocation[1],1); - glVertexAttribDivisor(centerLocation[2],1); - glVertexAttribDivisor(centerLocation[3],1); - glVertexAttribDivisor(centerLocation[4],1); - glVertexAttribDivisor(normalsLocation[1],0); + if(extension_is_found) + { + glVertexAttribDivisor(centerLocation[1],1); + glVertexAttribDivisor(centerLocation[2],1); + glVertexAttribDivisor(centerLocation[3],1); + glVertexAttribDivisor(centerLocation[4],1); + glVertexAttribDivisor(normalsLocation[1],0); + } vao[20].release(); } @@ -1139,11 +1193,12 @@ void Viewer::attrib_buffers(QGLViewer* viewer) void Viewer::draw() { + glEnable(GL_DEPTH_TEST); if(!are_buffers_initialized) initialize_buffers(); QFont fontPrompt("Arial", 8); attrib_buffers(this); - if(m_isFlat) + if(m_isFlat || !extension_is_found) { if(m_showVertex) @@ -1564,7 +1619,10 @@ void Viewer::draw() rendering_program_spheres.bind(); vao[11].bind(); rendering_program_spheres.setUniformValue(colorLocation[1], m_colorTrackball); - glDrawArraysInstanced(GL_TRIANGLES, 0, points_trackBall->size()/3, 1); + if(extension_is_found) + glDrawArraysInstanced(GL_TRIANGLES, 0, points_trackBall->size()/3, 1); + else + glDrawArrays(GL_TRIANGLES, 0, points_trackBall->size()/3); vao[11].release(); rendering_program_spheres.release(); } @@ -1573,7 +1631,13 @@ void Viewer::draw() rendering_program_spheres.bind(); vao[12].bind(); rendering_program_spheres.setUniformValue(colorLocation[1], m_colorEmptySphere); - glDrawArraysInstanced(GL_TRIANGLES, 0, points_emptySphere->size()/3, pos_emptySphere->size()/3); + if(extension_is_found) + glDrawArraysInstanced(GL_TRIANGLES, 0, points_emptySphere->size()/3, pos_emptySphere->size()/3); + else if(pos_emptySphere->size()>0) + { + rendering_program_spheres.setAttributeValue("center", QVector4D(pos_emptySphere->at(0), pos_emptySphere->at(1), pos_emptySphere->at(2), 1.0)); + glDrawArrays(GL_TRIANGLES, 0, points_emptySphere->size()/3); + } vao[12].release(); rendering_program_spheres.release(); } diff --git a/Triangulation_3/demo/Triangulation_3/Viewer.h b/Triangulation_3/demo/Triangulation_3/Viewer.h index ca05da36146..c865f018a41 100644 --- a/Triangulation_3/demo/Triangulation_3/Viewer.h +++ b/Triangulation_3/demo/Triangulation_3/Viewer.h @@ -8,7 +8,7 @@ #include #include "PreferenceDlg.h" -#include +#include #include #include #include @@ -18,7 +18,7 @@ using namespace qglviewer; class MainWindow; -class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core { +class Viewer : public QGLViewer, QOpenGLFunctions_2_1 { Q_OBJECT @@ -345,6 +345,8 @@ private: int lightLocation[5*2]; bool are_buffers_initialized; + bool extension_is_found; + std::vector *pos_emptyFacet; std::vector *pos_emptySphere; std::vector *points_emptySphere; @@ -385,6 +387,10 @@ private: QOpenGLShaderProgram rendering_program; QOpenGLShaderProgram rendering_program_spheres; QOpenGLShaderProgram rendering_program_cylinders; + typedef void (APIENTRYP PFNGLDRAWARRAYSINSTANCEDARBPROC) (GLenum mode, GLint first, GLsizei count, GLsizei primcount); + typedef void (APIENTRYP PFNGLVERTEXATTRIBDIVISORARBPROC) (GLuint index, GLuint divisor); + PFNGLDRAWARRAYSINSTANCEDARBPROC glDrawArraysInstanced; + PFNGLVERTEXATTRIBDIVISORARBPROC glVertexAttribDivisor; void initialize_buffers(); void compute_elements(); void attrib_buffers(QGLViewer*);