mirror of https://github.com/CGAL/cgal
commit
278a28016a
|
|
@ -16,7 +16,6 @@
|
||||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||||
#include <CGAL/Subdivision_method_3.h>
|
#include <CGAL/Subdivision_method_3.h>
|
||||||
|
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
|
||||||
#include <QOpenGLShader>
|
#include <QOpenGLShader>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "Viewer.h"
|
#include "Viewer.h"
|
||||||
|
|
@ -92,9 +91,8 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
// "#version 330 \n"
|
"#version 120 \n"
|
||||||
"attribute highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
// "uniform highp mat4 ortho_matrix;\n"
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 f_matrix;\n"
|
"uniform highp mat4 f_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
|
|
@ -105,7 +103,7 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
//"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
@ -141,7 +139,7 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char tex_vertex_source[] =
|
const char tex_vertex_source[] =
|
||||||
{
|
{
|
||||||
// "#version 330 \n"
|
"#version 120 \n"
|
||||||
"attribute highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"attribute highp vec2 tex_coord; \n"
|
"attribute highp vec2 tex_coord; \n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
|
|
@ -156,7 +154,7 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char tex_fragment_source[] =
|
const char tex_fragment_source[] =
|
||||||
{
|
{
|
||||||
//"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform sampler2D texture;\n"
|
"uniform sampler2D texture;\n"
|
||||||
"varying highp vec2 texc;\n"
|
"varying highp vec2 texc;\n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
|
|
@ -1318,7 +1316,7 @@ void Scene::deactivate_cutting_plane()
|
||||||
}
|
}
|
||||||
void Scene::initGL(Viewer * /* viewer */)
|
void Scene::initGL(Viewer * /* viewer */)
|
||||||
{
|
{
|
||||||
gl = new QOpenGLFunctions_3_3_Core();
|
gl = new QOpenGLFunctions_2_1();
|
||||||
if(!gl->initializeOpenGLFunctions())
|
if(!gl->initializeOpenGLFunctions())
|
||||||
{
|
{
|
||||||
qFatal("ERROR : OpenGL Functions not initialized. Check your OpenGL Verison (should be >=3.3)");
|
qFatal("ERROR : OpenGL Functions not initialized. Check your OpenGL Verison (should be >=3.3)");
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
#include <QtCore/qglobal.h>
|
#include <QtCore/qglobal.h>
|
||||||
#include <QGLViewer/manipulatedFrame.h>
|
#include <QGLViewer/manipulatedFrame.h>
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
|
|
@ -86,7 +86,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// member data
|
// member data
|
||||||
QOpenGLFunctions_3_3_Core *gl;
|
QOpenGLFunctions_2_1 *gl;
|
||||||
Bbox m_bbox;
|
Bbox m_bbox;
|
||||||
Polyhedron *m_pPolyhedron;
|
Polyhedron *m_pPolyhedron;
|
||||||
std::list<Point> m_points;
|
std::list<Point> m_points;
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -44,12 +44,12 @@ void Viewer::compile_shaders()
|
||||||
" gl_Position = mvp_matrix * vertex;\n"
|
" gl_Position = mvp_matrix * vertex;\n"
|
||||||
"}"
|
"}"
|
||||||
};
|
};
|
||||||
//Vertex source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"uniform vec4 light_pos; \n"
|
"uniform vec4 light_pos; \n"
|
||||||
"uniform vec4 light_diff; \n"
|
"uniform vec4 light_diff; \n"
|
||||||
|
|
@ -105,8 +105,8 @@ rendering_program.bind();
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_points[] =
|
const char vertex_source_points[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
|
|
@ -117,7 +117,7 @@ const char vertex_source_points[] =
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char fragment_source_points[] =
|
const char fragment_source_points[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
|
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
|
|
@ -325,6 +325,7 @@ void Viewer::compute_elements()
|
||||||
void
|
void
|
||||||
Viewer::draw()
|
Viewer::draw()
|
||||||
{
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(!are_buffers_initialized)
|
if(!are_buffers_initialized)
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@
|
||||||
|
|
||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
|
|
||||||
|
|
||||||
class Viewer : public QGLViewer, protected QOpenGLFunctions_3_3_Core{
|
class Viewer : public QGLViewer, protected QOpenGLFunctions_2_1{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
CGAL::Timer timer;
|
CGAL::Timer timer;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,12 @@
|
||||||
#include <CGAL/Exact_spherical_kernel_3.h>
|
#include <CGAL/Exact_spherical_kernel_3.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <CGAL/Qt/CreateOpenGLContext.h>
|
#include <CGAL/Qt/CreateOpenGLContext.h>
|
||||||
|
|
||||||
|
|
||||||
Viewer::Viewer(QWidget* parent )
|
Viewer::Viewer(QWidget* parent )
|
||||||
: QGLViewer(CGAL::Qt::createOpenGLContext(),parent)
|
: QGLViewer(CGAL::Qt::createOpenGLContext(),parent)
|
||||||
{
|
{
|
||||||
|
extension_is_found = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::compile_shaders()
|
void Viewer::compile_shaders()
|
||||||
|
|
@ -29,16 +32,16 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 center;\n"
|
"attribute highp vec4 center;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
|
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -49,9 +52,9 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"uniform vec4 light_pos; \n"
|
"uniform vec4 light_pos; \n"
|
||||||
"uniform vec4 light_diff; \n"
|
"uniform vec4 light_diff; \n"
|
||||||
|
|
@ -101,6 +104,59 @@ void Viewer::compile_shaders()
|
||||||
std::cerr<<"linking Program FAILED"<<std::endl;
|
std::cerr<<"linking Program FAILED"<<std::endl;
|
||||||
}
|
}
|
||||||
rendering_program.bind();
|
rendering_program.bind();
|
||||||
|
if(!extension_is_found)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//Vertex source code
|
||||||
|
const char vertex_source_no_ext[] =
|
||||||
|
{
|
||||||
|
"#version 120 \n"
|
||||||
|
"attribute highp vec4 vertex;\n"
|
||||||
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
|
"void main(void)\n"
|
||||||
|
"{\n"
|
||||||
|
" gl_Position = mvp_matrix * vertex;\n"
|
||||||
|
"}"
|
||||||
|
};
|
||||||
|
//Vertex source code
|
||||||
|
const char fragment_source_no_ext[] =
|
||||||
|
{
|
||||||
|
"#version 120 \n"
|
||||||
|
"uniform highp vec4 color; \n"
|
||||||
|
"void main(void) { \n"
|
||||||
|
"gl_FragColor = color; \n"
|
||||||
|
"} \n"
|
||||||
|
"\n"
|
||||||
|
};
|
||||||
|
vertex_shader = new QOpenGLShader(QOpenGLShader::Vertex);
|
||||||
|
if(!vertex_shader->compileSourceCode(vertex_source_no_ext))
|
||||||
|
{
|
||||||
|
std::cerr<<"Compiling vertex source FAILED"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment_shader= new QOpenGLShader(QOpenGLShader::Fragment);
|
||||||
|
if(!fragment_shader->compileSourceCode(fragment_source_no_ext))
|
||||||
|
{
|
||||||
|
std::cerr<<"Compiling fragmentsource FAILED"<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!rendering_program_no_ext.addShader(vertex_shader))
|
||||||
|
{
|
||||||
|
std::cerr<<"adding vertex shader FAILED"<<std::endl;
|
||||||
|
}
|
||||||
|
if(!rendering_program_no_ext.addShader(fragment_shader))
|
||||||
|
{
|
||||||
|
std::cerr<<"adding fragment shader FAILED"<<std::endl;
|
||||||
|
}
|
||||||
|
if(!rendering_program_no_ext.link())
|
||||||
|
{
|
||||||
|
std::cerr<<"linking Program FAILED"<<std::endl;
|
||||||
|
}
|
||||||
|
rendering_program_no_ext.bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +191,12 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program.enableAttributeArray(trivialCenterLocation);
|
rendering_program.enableAttributeArray(trivialCenterLocation);
|
||||||
rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3);
|
rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3);
|
||||||
buffers[2].release();
|
buffers[2].release();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
|
|
||||||
glVertexAttribDivisor(trivialCenterLocation, 1);
|
glVertexAttribDivisor(trivialCenterLocation, 1);
|
||||||
glVertexAttribDivisor(normalsLocation[0], 0);
|
glVertexAttribDivisor(normalsLocation[0], 0);
|
||||||
|
}
|
||||||
vao[0].release();
|
vao[0].release();
|
||||||
|
|
||||||
//The circles
|
//The circles
|
||||||
|
|
@ -168,15 +228,20 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program.enableAttributeArray(trivialCenterLocation);
|
rendering_program.enableAttributeArray(trivialCenterLocation);
|
||||||
rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3);
|
rendering_program.setAttributeBuffer(trivialCenterLocation,GL_FLOAT,0,3);
|
||||||
buffers[5].release();
|
buffers[5].release();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(trivialCenterLocation, 1);
|
glVertexAttribDivisor(trivialCenterLocation, 1);
|
||||||
glVertexAttribDivisor(normalsLocation[0], 0);
|
glVertexAttribDivisor(normalsLocation[0], 0);
|
||||||
|
}
|
||||||
rendering_program.release();
|
rendering_program.release();
|
||||||
|
|
||||||
vao[1].release();
|
vao[1].release();
|
||||||
|
|
||||||
//The little green spheres
|
//The little green spheres
|
||||||
vao[2].bind();
|
vao[2].bind();
|
||||||
//points of the sphere
|
if(extension_is_found)
|
||||||
|
{
|
||||||
|
//points of the spheres
|
||||||
buffers[6].bind();
|
buffers[6].bind();
|
||||||
buffers[6].allocate(pos_sphere_inter.data(),
|
buffers[6].allocate(pos_sphere_inter.data(),
|
||||||
static_cast<int>(pos_sphere_inter.size()*sizeof(float)));
|
static_cast<int>(pos_sphere_inter.size()*sizeof(float)));
|
||||||
|
|
@ -203,8 +268,21 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program.enableAttributeArray(centerLocation);
|
rendering_program.enableAttributeArray(centerLocation);
|
||||||
rendering_program.setAttributeBuffer(centerLocation,GL_FLOAT,0,3);
|
rendering_program.setAttributeBuffer(centerLocation,GL_FLOAT,0,3);
|
||||||
buffers[8].release();
|
buffers[8].release();
|
||||||
|
|
||||||
glVertexAttribDivisor(centerLocation, 1);
|
glVertexAttribDivisor(centerLocation, 1);
|
||||||
glVertexAttribDivisor(normalsLocation[1], 0);
|
glVertexAttribDivisor(normalsLocation[1], 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//points of the sphere
|
||||||
|
buffers[6].bind();
|
||||||
|
buffers[6].allocate(pos_points.data(),
|
||||||
|
static_cast<int>(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();
|
vao[2].release();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -693,13 +771,20 @@ void Viewer::attrib_buffers(QGLViewer* viewer)
|
||||||
rendering_program.setUniformValue(mvpLocation, mvpMatrix);
|
rendering_program.setUniformValue(mvpLocation, mvpMatrix);
|
||||||
rendering_program.setUniformValue(mvLocation, mvMatrix);
|
rendering_program.setUniformValue(mvLocation, mvMatrix);
|
||||||
|
|
||||||
|
|
||||||
rendering_program.release();
|
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()
|
void Viewer::draw()
|
||||||
{
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
||||||
//sphere
|
//sphere
|
||||||
|
|
@ -708,18 +793,34 @@ void Viewer::draw()
|
||||||
rendering_program.bind();
|
rendering_program.bind();
|
||||||
color.setRgbF(1.0f, 1.0f, 1.0f);
|
color.setRgbF(1.0f, 1.0f, 1.0f);
|
||||||
rendering_program.setUniformValue(colorLocation, color);
|
rendering_program.setUniformValue(colorLocation, color);
|
||||||
|
if(extension_is_found)
|
||||||
glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_sphere.size()/3), 1);
|
glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_sphere.size()/3), 1);
|
||||||
|
else
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_sphere.size()/3));
|
||||||
rendering_program.release();
|
rendering_program.release();
|
||||||
vao[0].release();
|
vao[0].release();
|
||||||
|
|
||||||
//intersection
|
//intersection
|
||||||
vao[2].bind();
|
vao[2].bind();
|
||||||
attrib_buffers(this);
|
attrib_buffers(this);
|
||||||
rendering_program.bind();
|
|
||||||
color.setRgbF(0.0f, 1.0f, 0.0f);
|
color.setRgbF(0.0f, 1.0f, 0.0f);
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
|
rendering_program.bind();
|
||||||
rendering_program.setUniformValue(colorLocation, color);
|
rendering_program.setUniformValue(colorLocation, color);
|
||||||
glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_sphere_inter.size()/3), static_cast<GLsizei>(pos_points.size()/3));
|
glDrawArraysInstanced(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_sphere_inter.size()/3), static_cast<GLsizei>(pos_points.size()/3));
|
||||||
rendering_program.release();
|
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<GLsizei>(pos_points.size()/3));
|
||||||
|
rendering_program_no_ext.release();
|
||||||
|
glPointSize(1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
vao[2].release();
|
vao[2].release();
|
||||||
|
|
||||||
//circles
|
//circles
|
||||||
|
|
@ -738,6 +839,24 @@ void Viewer::draw()
|
||||||
|
|
||||||
void Viewer::init()
|
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();
|
compile_shaders();
|
||||||
compute_elements();
|
compute_elements();
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
|
|
@ -748,6 +867,7 @@ void Viewer::init()
|
||||||
glEnable(GL_POINT_SMOOTH);
|
glEnable(GL_POINT_SMOOTH);
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class Output_iterator>
|
template<class Output_iterator>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||||
|
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
|
|
||||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC;
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel EPIC;
|
||||||
|
|
||||||
class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core
|
class Viewer : public QGLViewer, QOpenGLFunctions_2_1
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Viewer(QWidget* parent = 0);
|
Viewer(QWidget* parent = 0);
|
||||||
|
|
@ -29,7 +29,7 @@ private:
|
||||||
int mvLocation;
|
int mvLocation;
|
||||||
int colorLocation;
|
int colorLocation;
|
||||||
int lightLocation[5];
|
int lightLocation[5];
|
||||||
|
bool extension_is_found;
|
||||||
|
|
||||||
std::vector<float> pos_points;
|
std::vector<float> pos_points;
|
||||||
std::vector<float> pos_lines;
|
std::vector<float> pos_lines;
|
||||||
|
|
@ -43,6 +43,11 @@ private:
|
||||||
QOpenGLBuffer buffers[9];
|
QOpenGLBuffer buffers[9];
|
||||||
QOpenGLVertexArrayObject vao[3];
|
QOpenGLVertexArrayObject vao[3];
|
||||||
QOpenGLShaderProgram rendering_program;
|
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 initialize_buffers();
|
||||||
void compute_elements();
|
void compute_elements();
|
||||||
|
|
|
||||||
|
|
@ -423,7 +423,8 @@ it from <A HREF="http://qt-project.org/">`http://qt-project.org/`</A>.
|
||||||
Older demos of \cgal use libCGAL_Qt3 and \sc{Qt}3, while newer and newly
|
Older demos of \cgal use libCGAL_Qt3 and \sc{Qt}3, while newer and newly
|
||||||
developed demos require libCGAL_Qt5 and \sc{Qt}5.
|
developed demos require libCGAL_Qt5 and \sc{Qt}5.
|
||||||
The exhaustive list of \sc{Qt}5 components used in demos is:
|
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.
|
Having \sc{Qt}5 version 5.3.0 is recommended.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ inline QGLContext* createOpenGLContext()
|
||||||
{
|
{
|
||||||
QOpenGLContext *context = new QOpenGLContext();
|
QOpenGLContext *context = new QOpenGLContext();
|
||||||
QSurfaceFormat format;
|
QSurfaceFormat format;
|
||||||
format.setVersion(3,3);
|
format.setVersion(2,1);
|
||||||
format.setProfile(QSurfaceFormat::CompatibilityProfile);
|
format.setProfile(QSurfaceFormat::CompatibilityProfile);
|
||||||
context->setFormat(format);
|
context->setFormat(format);
|
||||||
return QGLContext::fromOpenGLContext(context);
|
return QGLContext::fromOpenGLContext(context);
|
||||||
|
|
|
||||||
|
|
@ -232,32 +232,32 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 140 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 color;\n"
|
"attribute highp vec3 color;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
|
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"out highp vec4 fColor; \n"
|
"varying highp vec4 fColor; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
" fN = mat3(mv_matrix)* normal; \n"
|
" fN = mat3(mv_matrix)* normal; \n"
|
||||||
" fColor = color; \n"
|
" fColor = vec4(color, 1.0); \n"
|
||||||
" gl_Position = mvp_matrix * vertex;\n"
|
" gl_Position = mvp_matrix * vertex;\n"
|
||||||
"}"
|
"}"
|
||||||
};
|
};
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 140 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"in highp vec4 fColor; \n"
|
"varying highp vec4 fColor; \n"
|
||||||
"uniform vec4 light_pos; \n"
|
"uniform vec4 light_pos; \n"
|
||||||
"uniform vec4 light_diff; \n"
|
"uniform vec4 light_diff; \n"
|
||||||
"uniform vec4 light_spec; \n"
|
"uniform vec4 light_spec; \n"
|
||||||
|
|
@ -310,8 +310,8 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_p_l[] =
|
const char vertex_source_p_l[] =
|
||||||
{
|
{
|
||||||
"#version 140 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
@ -321,7 +321,7 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char fragment_source_p_l[] =
|
const char fragment_source_p_l[] =
|
||||||
{
|
{
|
||||||
"#version 140 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
@ -657,20 +657,20 @@ void Viewer::attrib_buffers(QGLViewer* viewer)
|
||||||
void
|
void
|
||||||
Viewer::sceneChanged()
|
Viewer::sceneChanged()
|
||||||
{
|
{
|
||||||
|
compute_elements();
|
||||||
this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(),
|
this->camera()->setSceneBoundingBox(qglviewer::Vec(bb.xmin(),
|
||||||
bb.ymin(),
|
bb.ymin(),
|
||||||
bb.zmin()),
|
bb.zmin()),
|
||||||
qglviewer::Vec(bb.xmax(),
|
qglviewer::Vec(bb.xmax(),
|
||||||
bb.ymax(),
|
bb.ymax(),
|
||||||
bb.zmax()));
|
bb.zmax()));
|
||||||
compute_elements();
|
|
||||||
are_buffers_initialized = false;
|
are_buffers_initialized = false;
|
||||||
this->showEntireScene();
|
this->showEntireScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::draw()
|
void Viewer::draw()
|
||||||
{
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(!are_buffers_initialized)
|
if(!are_buffers_initialized)
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,11 @@
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QGLBuffer>
|
#include <QGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core
|
class Viewer : public QGLViewer, QOpenGLFunctions_2_1
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,16 +51,16 @@ void Scene_c3t3_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec3 inColor; \n"
|
"attribute highp vec3 inColor; \n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"out highp vec4 color; \n"
|
"varying highp vec4 color; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" color = vec4(inColor, 1.0); \n"
|
" color = vec4(inColor, 1.0); \n"
|
||||||
|
|
@ -73,9 +73,9 @@ void Scene_c3t3_item::compile_shaders()
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 330 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"in vec4 color; \n"
|
"varying vec4 color; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
"uniform highp vec4 light_diff; \n"
|
"uniform highp vec4 light_diff; \n"
|
||||||
"uniform highp vec4 light_spec; \n"
|
"uniform highp vec4 light_spec; \n"
|
||||||
|
|
@ -130,8 +130,8 @@ void Scene_c3t3_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_grid[] =
|
const char vertex_source_grid[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 f_matrix; \n"
|
"uniform highp mat4 f_matrix; \n"
|
||||||
|
|
@ -143,7 +143,7 @@ void Scene_c3t3_item::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source_grid[] =
|
const char fragment_source_grid[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform vec4 color; \n"
|
"uniform vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ void Scene_implicit_function_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
|
|
@ -80,7 +80,7 @@ void Scene_implicit_function_item::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform vec4 color; \n"
|
"uniform vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
@ -115,24 +115,24 @@ void Scene_implicit_function_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char tex_vertex_source[] =
|
const char tex_vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec2 tex_coord; \n"
|
"attribute highp vec2 tex_coord; \n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 f_matrix;\n"
|
"uniform highp mat4 f_matrix;\n"
|
||||||
"out highp vec2 texc;\n"
|
"varying highp vec2 texc;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" gl_Position = mvp_matrix * f_matrix * vertex;\n"
|
" gl_Position = mvp_matrix * f_matrix * vertex;\n"
|
||||||
" texc = tex_coord;\n"
|
" texc = tex_coord;\n"
|
||||||
"}"
|
"}"
|
||||||
};
|
};
|
||||||
//Vertex source code
|
//Fragment source code
|
||||||
const char tex_fragment_source[] =
|
const char tex_fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform sampler2D texture;\n"
|
"uniform sampler2D texture;\n"
|
||||||
"in highp vec2 texc;\n"
|
"varying highp vec2 texc;\n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = texture2D(texture, texc.st);\n"
|
"gl_FragColor = texture2D(texture, texc.st);\n"
|
||||||
"} \n"
|
"} \n"
|
||||||
|
|
|
||||||
|
|
@ -125,14 +125,14 @@ void Scene_polygon_soup::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -143,9 +143,9 @@ void Scene_polygon_soup::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform vec4 color; \n"
|
"uniform vec4 color; \n"
|
||||||
"uniform bool is_two_side; \n"
|
"uniform bool is_two_side; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,14 @@ void Scene_polyhedron_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -72,9 +72,9 @@ void Scene_polyhedron_item::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform vec4 color; \n"
|
"uniform vec4 color; \n"
|
||||||
"uniform bool is_two_side; \n"
|
"uniform bool is_two_side; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
|
|
|
||||||
|
|
@ -497,16 +497,16 @@ void Scene_segmented_image_item::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 inColor;\n"
|
"attribute highp vec4 inColor;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"out highp vec4 color; \n"
|
"varying highp vec4 color; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" color=inColor; \n"
|
" color=inColor; \n"
|
||||||
|
|
@ -518,10 +518,10 @@ void Scene_segmented_image_item::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"in highp vec4 color; \n"
|
"varying highp vec4 color; \n"
|
||||||
"uniform bool is_two_side; \n"
|
"uniform bool is_two_side; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
"uniform highp vec4 light_diff; \n"
|
"uniform highp vec4 light_diff; \n"
|
||||||
|
|
|
||||||
|
|
@ -423,9 +423,6 @@ void Volume_plane<T>::init() {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void Volume_plane<T>::initShaders() {
|
void Volume_plane<T>::initShaders() {
|
||||||
program.create();
|
|
||||||
|
|
||||||
|
|
||||||
QOpenGLShader *vertex = new QOpenGLShader(QOpenGLShader::Vertex);
|
QOpenGLShader *vertex = new QOpenGLShader(QOpenGLShader::Vertex);
|
||||||
|
|
||||||
vertex->compileSourceCode(vertexShader_source);
|
vertex->compileSourceCode(vertexShader_source);
|
||||||
|
|
@ -436,7 +433,6 @@ void Volume_plane<T>::initShaders() {
|
||||||
program.link();
|
program.link();
|
||||||
|
|
||||||
|
|
||||||
program_bordures.create();
|
|
||||||
QOpenGLShader *vertex_bordures = new QOpenGLShader(QOpenGLShader::Vertex);
|
QOpenGLShader *vertex_bordures = new QOpenGLShader(QOpenGLShader::Vertex);
|
||||||
|
|
||||||
vertex_bordures->compileSourceCode(vertexShader_bordures_source);
|
vertex_bordures->compileSourceCode(vertexShader_bordures_source);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ void Volume_plane_intersection::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 f_matrix; \n"
|
"uniform highp mat4 f_matrix; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
|
|
@ -28,7 +28,7 @@ void Volume_plane_intersection::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = vec4(1.0,0.0,0.0,1.0); \n"
|
"gl_FragColor = vec4(1.0,0.0,0.0,1.0); \n"
|
||||||
"} \n"
|
"} \n"
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
#include <CGAL_demo/Viewer_config.h>
|
#include <CGAL_demo/Viewer_config.h>
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class Scene_draw_interface;
|
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
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ void Viewer::initializeGL()
|
||||||
void Viewer::draw_aux(bool with_names)
|
void Viewer::draw_aux(bool with_names)
|
||||||
{
|
{
|
||||||
QGLViewer::draw();
|
QGLViewer::draw();
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(scene == 0)
|
if(scene == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
@ -45,7 +45,7 @@ void Scene::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
@ -82,15 +82,15 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_spheres[] =
|
const char vertex_source_spheres[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 center;\n"
|
"attribute highp vec4 center;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -101,9 +101,9 @@ void Scene::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source_spheres[] =
|
const char fragment_source_spheres[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
"uniform highp vec4 light_diff; \n"
|
"uniform highp vec4 light_diff; \n"
|
||||||
"uniform highp vec4 light_spec; \n"
|
"uniform highp vec4 light_spec; \n"
|
||||||
|
|
@ -159,18 +159,18 @@ void Scene::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_cylinders[] =
|
const char vertex_source_cylinders[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 transfo1;\n"
|
"attribute highp vec4 transfo1;\n"
|
||||||
"in highp vec4 transfo2;\n"
|
"attribute highp vec4 transfo2;\n"
|
||||||
"in highp vec4 transfo3;\n"
|
"attribute highp vec4 transfo3;\n"
|
||||||
"in highp vec4 transfo4;\n"
|
"attribute highp vec4 transfo4;\n"
|
||||||
"mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n"
|
"mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -488,8 +488,11 @@ void Scene::initialize_buffers()
|
||||||
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
||||||
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
||||||
buffers[0].release();
|
buffers[0].release();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[3].release();
|
vao[3].release();
|
||||||
rendering_program_spheres.release();
|
rendering_program_spheres.release();
|
||||||
|
|
||||||
|
|
@ -538,13 +541,15 @@ void Scene::initialize_buffers()
|
||||||
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
||||||
buffers[13].release();
|
buffers[13].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[1],1);
|
glVertexAttribDivisor(centerLocation[1],1);
|
||||||
glVertexAttribDivisor(centerLocation[2],1);
|
glVertexAttribDivisor(centerLocation[2],1);
|
||||||
glVertexAttribDivisor(centerLocation[3],1);
|
glVertexAttribDivisor(centerLocation[3],1);
|
||||||
glVertexAttribDivisor(centerLocation[4],1);
|
glVertexAttribDivisor(centerLocation[4],1);
|
||||||
|
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
|
|
||||||
vao[8].release();
|
vao[8].release();
|
||||||
vao[9].bind();
|
vao[9].bind();
|
||||||
|
|
@ -590,13 +595,15 @@ void Scene::initialize_buffers()
|
||||||
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
||||||
buffers[18].release();
|
buffers[18].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[1],1);
|
glVertexAttribDivisor(centerLocation[1],1);
|
||||||
glVertexAttribDivisor(centerLocation[2],1);
|
glVertexAttribDivisor(centerLocation[2],1);
|
||||||
glVertexAttribDivisor(centerLocation[3],1);
|
glVertexAttribDivisor(centerLocation[3],1);
|
||||||
glVertexAttribDivisor(centerLocation[4],1);
|
glVertexAttribDivisor(centerLocation[4],1);
|
||||||
|
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
|
|
||||||
vao[9].release();
|
vao[9].release();
|
||||||
|
|
||||||
|
|
@ -642,14 +649,15 @@ void Scene::initialize_buffers()
|
||||||
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
||||||
buffers[22].release();
|
buffers[22].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[1],1);
|
glVertexAttribDivisor(centerLocation[1],1);
|
||||||
glVertexAttribDivisor(centerLocation[2],1);
|
glVertexAttribDivisor(centerLocation[2],1);
|
||||||
glVertexAttribDivisor(centerLocation[3],1);
|
glVertexAttribDivisor(centerLocation[3],1);
|
||||||
glVertexAttribDivisor(centerLocation[4],1);
|
glVertexAttribDivisor(centerLocation[4],1);
|
||||||
|
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
vao[10].release();
|
vao[10].release();
|
||||||
|
|
||||||
rendering_program_cylinders.release();
|
rendering_program_cylinders.release();
|
||||||
|
|
@ -727,6 +735,25 @@ void Scene::init() {
|
||||||
// undo from QGLViewer internal initializeGL function
|
// undo from QGLViewer internal initializeGL function
|
||||||
// glDisable(GL_COLOR_MATERIAL);
|
// glDisable(GL_COLOR_MATERIAL);
|
||||||
initializeOpenGLFunctions();
|
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
|
// camera
|
||||||
// only 2.7 gets an 'f' as VC++ warns if we don't
|
// only 2.7 gets an 'f' as VC++ warns if we don't
|
||||||
ui->viewer->camera()->setPosition(Vec(0.5,0.5,2.7f));
|
ui->viewer->camera()->setPosition(Vec(0.5,0.5,2.7f));
|
||||||
|
|
@ -753,6 +780,7 @@ void Scene::init() {
|
||||||
|
|
||||||
// Draws the triangulation
|
// Draws the triangulation
|
||||||
void Scene::draw() {
|
void Scene::draw() {
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(!are_buffers_initialized)
|
if(!are_buffers_initialized)
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
gl_draw_location();
|
gl_draw_location();
|
||||||
|
|
@ -971,8 +999,11 @@ void Scene::update_position()
|
||||||
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
||||||
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
||||||
buffers[5].release();
|
buffers[5].release();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
vao[7].release();
|
vao[7].release();
|
||||||
|
|
||||||
ui->viewer->update();
|
ui->viewer->update();
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
|
|
||||||
class Scene : public QObject, QOpenGLFunctions_3_3_Core
|
class Scene : public QObject, QOpenGLFunctions_2_1
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -144,7 +144,7 @@ public Q_SLOTS:
|
||||||
ui->viewer->update();
|
ui->viewer->update();
|
||||||
}
|
}
|
||||||
void toggle_wireframe(bool on) {
|
void toggle_wireframe(bool on) {
|
||||||
wireframe = on;
|
wireframe = !(!on && extension_is_found);
|
||||||
( on ? glDisable(GL_LIGHTING) : glEnable(GL_LIGHTING) );
|
( on ? glDisable(GL_LIGHTING) : glEnable(GL_LIGHTING) );
|
||||||
changed();
|
changed();
|
||||||
}
|
}
|
||||||
|
|
@ -287,11 +287,16 @@ private:
|
||||||
std::vector<float> transfo4_square;
|
std::vector<float> transfo4_square;
|
||||||
|
|
||||||
bool are_buffers_initialized;
|
bool are_buffers_initialized;
|
||||||
|
bool extension_is_found;
|
||||||
QOpenGLBuffer buffers[24];
|
QOpenGLBuffer buffers[24];
|
||||||
QOpenGLVertexArrayObject vao[12];
|
QOpenGLVertexArrayObject vao[12];
|
||||||
QOpenGLShaderProgram rendering_program;
|
QOpenGLShaderProgram rendering_program;
|
||||||
QOpenGLShaderProgram rendering_program_spheres;
|
QOpenGLShaderProgram rendering_program_spheres;
|
||||||
QOpenGLShaderProgram rendering_program_cylinders;
|
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 initialize_buffers();
|
||||||
void compute_elements();
|
void compute_elements();
|
||||||
void attrib_buffers(QGLViewer*);
|
void attrib_buffers(QGLViewer*);
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ Viewer::sceneChanged()
|
||||||
void
|
void
|
||||||
Viewer::draw()
|
Viewer::draw()
|
||||||
{
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(!are_buffers_initialized)
|
if(!are_buffers_initialized)
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
QColor color;
|
QColor color;
|
||||||
|
|
@ -265,8 +266,8 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
@ -276,7 +277,7 @@ void Viewer::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
|
|
||||||
#include "Scene.h"
|
#include "Scene.h"
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
#include <CGAL/Qt/CreateOpenGLContext.h>
|
#include <CGAL/Qt/CreateOpenGLContext.h>
|
||||||
|
|
||||||
|
|
||||||
class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core {
|
class Viewer : public QGLViewer, QOpenGLFunctions_2_1 {
|
||||||
|
|
||||||
typedef qglviewer::Vec Vec;
|
typedef qglviewer::Vec Vec;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2175,6 +2175,7 @@ Periodic_3_triangulation_3<GT,TDS>::periodic_insert(
|
||||||
|
|
||||||
// This only holds for Delaunay
|
// This only holds for Delaunay
|
||||||
CGAL_triangulation_assertion(lt != VERTEX);
|
CGAL_triangulation_assertion(lt != VERTEX);
|
||||||
|
CGAL_USE(lt);
|
||||||
|
|
||||||
// Choose the periodic copy of tester.point() that is inside c.
|
// Choose the periodic copy of tester.point() that is inside c.
|
||||||
Offset current_off = get_location_offset(tester, c);
|
Offset current_off = get_location_offset(tester, c);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <QGLViewer/qglviewer.h>
|
#include <QGLViewer/qglviewer.h>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <CGAL/Qt/CreateOpenGLContext.h>
|
#include <CGAL/Qt/CreateOpenGLContext.h>
|
||||||
// forward declarations
|
// forward declarations
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
@ -14,7 +14,7 @@ class QKeyEvent;
|
||||||
|
|
||||||
#include "../Viewer_config.h" // for VIEWER_EXPORT
|
#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
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -30,6 +30,11 @@ public:
|
||||||
static QString dumpFrame(const qglviewer::Frame&);
|
static QString dumpFrame(const qglviewer::Frame&);
|
||||||
|
|
||||||
virtual bool inFastDrawing() const = 0;
|
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];
|
GLfloat pickMatrix_[16];
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
|
|
@ -47,6 +52,7 @@ public Q_SLOTS:
|
||||||
virtual QString dumpCameraCoordinates() = 0;
|
virtual QString dumpCameraCoordinates() = 0;
|
||||||
virtual bool moveCameraToCoordinates(QString,
|
virtual bool moveCameraToCoordinates(QString,
|
||||||
float animation_duration = 0.5f) = 0;
|
float animation_duration = 0.5f) = 0;
|
||||||
|
|
||||||
}; // end class Viewer_interface
|
}; // end class Viewer_interface
|
||||||
|
|
||||||
#endif // VIEWER_INTERFACE_H
|
#endif // VIEWER_INTERFACE_H
|
||||||
|
|
|
||||||
|
|
@ -959,7 +959,7 @@ QList<int> MainWindow::getSelectedSceneItemIndices() const
|
||||||
|
|
||||||
void MainWindow::selectionChanged()
|
void MainWindow::selectionChanged()
|
||||||
{
|
{
|
||||||
scene->setSelectedItem(getSelectedSceneItemIndex());
|
scene->setSelectedItemIndex(getSelectedSceneItemIndex());
|
||||||
scene->setSelectedItemsList(getSelectedSceneItemIndices());
|
scene->setSelectedItemsList(getSelectedSceneItemIndices());
|
||||||
Scene_item* item = scene->item(getSelectedSceneItemIndex());
|
Scene_item* item = scene->item(getSelectedSceneItemIndex());
|
||||||
if(item != NULL && item->manipulatable()) {
|
if(item != NULL && item->manipulatable()) {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<double>0.000000000000000</double>
|
<double>0.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<double>30.000000000000000</double>
|
<double>999999999.000000000000000</double>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<double>0.000000000000000</double>
|
<double>0.000000000000000</double>
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include "Kernel_type.h"
|
#include "Kernel_type.h"
|
||||||
|
|
||||||
#include <boost/function_output_iterator.hpp>
|
#include <boost/function_output_iterator.hpp>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
// Class for visualizing holes in a polyhedron
|
// Class for visualizing holes in a polyhedron
|
||||||
// provides mouse selection functionality
|
// provides mouse selection functionality
|
||||||
|
|
@ -307,13 +308,7 @@ public:
|
||||||
void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m);
|
void init(QMainWindow* mainWindow, Scene_interface* scene_interface, Messages_interface* m);
|
||||||
|
|
||||||
Scene_hole_visualizer* get_hole_visualizer(Scene_polyhedron_item* poly_item) {
|
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
|
return visualizers[poly_item];
|
||||||
for(Scene_interface::Item_id i = 0, end = scene->numberOfEntries(); i < end; ++i) {
|
|
||||||
Scene_hole_visualizer* hole_visualizer = qobject_cast<Scene_hole_visualizer*>(scene->item(i));
|
|
||||||
if(hole_visualizer && hole_visualizer->poly_item == poly_item)
|
|
||||||
{ return hole_visualizer; }
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
|
|
@ -353,6 +348,9 @@ private:
|
||||||
QDockWidget* dock_widget;
|
QDockWidget* dock_widget;
|
||||||
Ui::HoleFilling ui_widget;
|
Ui::HoleFilling ui_widget;
|
||||||
|
|
||||||
|
//Maintains a reference between all the visualizers and their poly_item
|
||||||
|
// to ease the management of the visualizers
|
||||||
|
QMap<Scene_polyhedron_item*, Scene_hole_visualizer*> visualizers;
|
||||||
// hold created facet for accept reject functionality
|
// hold created facet for accept reject functionality
|
||||||
std::vector<Polyhedron::Facet_handle> new_facets;
|
std::vector<Polyhedron::Facet_handle> new_facets;
|
||||||
Scene_polyhedron_item* last_active_item; // always keep it NULL while not active-reject state
|
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) {
|
if(poly_item) {
|
||||||
// erase assoc polylines item
|
// erase assoc polylines item
|
||||||
scene->erase( scene->item_id( get_hole_visualizer(poly_item) ) );
|
scene->erase( scene->item_id( get_hole_visualizer(poly_item) ) );
|
||||||
|
visualizers.remove(poly_item);
|
||||||
// close accept-reject dialog if it is open
|
// close accept-reject dialog if it is open
|
||||||
if(last_active_item == poly_item) {
|
if(last_active_item == poly_item) {
|
||||||
on_Accept_button();
|
on_Accept_button();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
Scene_hole_visualizer* visu_item = qobject_cast<Scene_hole_visualizer*>(scene_item);
|
||||||
|
if(visu_item) {
|
||||||
|
visualizers.remove(visu_item->poly_item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// removes Scene_hole_visualizer items
|
// removes Scene_hole_visualizer items
|
||||||
void Polyhedron_demo_hole_filling_plugin::dock_widget_closed() {
|
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);
|
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()));
|
connect(hole_visualizer, SIGNAL(itemChanged()), this, SLOT(hole_visualizer_changed()));
|
||||||
|
|
||||||
if(hole_visualizer->polyline_data_list.empty()) {
|
if(hole_visualizer->polyline_data_list.empty()) {
|
||||||
print_message("There is no hole in selected polyhedron item!");
|
print_message("There is no hole in selected polyhedron item!");
|
||||||
|
visualizers.remove(poly_item);
|
||||||
delete hole_visualizer;
|
delete hole_visualizer;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -590,6 +597,7 @@ void Polyhedron_demo_hole_filling_plugin::hole_visualizer_changed() {
|
||||||
Scene_hole_visualizer* hole_visualizer = qobject_cast<Scene_hole_visualizer*>(this->sender());
|
Scene_hole_visualizer* hole_visualizer = qobject_cast<Scene_hole_visualizer*>(this->sender());
|
||||||
if(hole_visualizer && hole_visualizer->polyline_data_list.empty()) {
|
if(hole_visualizer && hole_visualizer->polyline_data_list.empty()) {
|
||||||
scene->erase( scene->item_id(hole_visualizer));
|
scene->erase( scene->item_id(hole_visualizer));
|
||||||
|
visualizers.remove(hole_visualizer->poly_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// helper function for filling holes
|
// helper function for filling holes
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,9 @@ public:
|
||||||
connect(ui->pushButton_segment, SIGNAL(clicked()),
|
connect(ui->pushButton_segment, SIGNAL(clicked()),
|
||||||
this, SLOT(on_actionSegment()));
|
this, SLOT(on_actionSegment()));
|
||||||
|
|
||||||
|
QObject* scene_object = dynamic_cast<QObject*>(scene);
|
||||||
|
connect(scene_object, SIGNAL(itemAboutToBeDestroyed(Scene_item*)),
|
||||||
|
this, SLOT(on_actionItemAboutToBeDestroyed(Scene_item*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QAction*> actions() const {
|
QList<QAction*> actions() const {
|
||||||
|
|
@ -719,10 +722,6 @@ void Polyhedron_demo_mean_curvature_flow_skeleton_plugin::on_actionRun()
|
||||||
delete temp;
|
delete temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject* scene_object = dynamic_cast<QObject*>(scene);
|
|
||||||
connect(scene_object, SIGNAL(itemAboutToBeDestroyed(Scene_item*)),
|
|
||||||
this, SLOT(on_actionItemAboutToBeDestroyed(Scene_item*)));
|
|
||||||
|
|
||||||
//#define DRAW_NON_FIXED_POINTS
|
//#define DRAW_NON_FIXED_POINTS
|
||||||
#ifdef DRAW_NON_FIXED_POINTS
|
#ifdef DRAW_NON_FIXED_POINTS
|
||||||
// draw non-fixed points
|
// draw non-fixed points
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,9 @@
|
||||||
#include "Polyhedron_demo_io_plugin_interface.h"
|
#include "Polyhedron_demo_io_plugin_interface.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <CGAL/IO/File_scanner_OFF.h>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
class Polyhedron_demo_off_plugin :
|
class Polyhedron_demo_off_plugin :
|
||||||
public QObject,
|
public QObject,
|
||||||
public Polyhedron_demo_io_plugin_interface
|
public Polyhedron_demo_io_plugin_interface
|
||||||
|
|
@ -38,6 +41,11 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
|
||||||
return NULL;
|
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
|
// Try to read .off in a polyhedron
|
||||||
Scene_polyhedron_item* item = new Scene_polyhedron_item();
|
Scene_polyhedron_item* item = new Scene_polyhedron_item();
|
||||||
item->setName(fileinfo.baseName());
|
item->setName(fileinfo.baseName());
|
||||||
|
|
@ -56,6 +64,14 @@ Polyhedron_demo_off_plugin::load(QFileInfo fileinfo) {
|
||||||
}
|
}
|
||||||
return soup_item;
|
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;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
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_1(bases[0], bases[1], bases[2]);
|
||||||
Epic_kernel::Vector_3 base_2(bases[3], bases[4], bases[5]);
|
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
|
// get distance between planes
|
||||||
bool to_double_ok = true;
|
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::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::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(!CGAL::do_intersect(cgal_bbox, plane)) {
|
||||||
if(dir == -1) { break; }
|
if(dir == -1) { break; }
|
||||||
|
|
|
||||||
|
|
@ -288,7 +288,7 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer)
|
||||||
::glPopName();
|
::glPopName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
// Wireframe OpenGL drawing
|
// Wireframe OpenGL drawing
|
||||||
for(int index = 0; index < m_entries.size(); ++index)
|
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
|
// Points OpenGL drawing
|
||||||
for(int index = 0; index < m_entries.size(); ++index)
|
for(int index = 0; index < m_entries.size(); ++index)
|
||||||
{
|
{
|
||||||
|
|
@ -381,6 +382,8 @@ Scene::draw_aux(bool with_names, Viewer_interface* viewer)
|
||||||
::glPopName();
|
::glPopName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
glDepthFunc(GL_LESS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,11 @@ public Q_SLOTS:
|
||||||
void itemChanged(int i);
|
void itemChanged(int i);
|
||||||
void itemChanged(Scene_item*);
|
void itemChanged(Scene_item*);
|
||||||
|
|
||||||
|
void setSelectedItemIndex(int i)
|
||||||
|
{
|
||||||
|
selected_item = i;
|
||||||
|
}
|
||||||
|
|
||||||
void setSelectedItem(int i )
|
void setSelectedItem(int i )
|
||||||
{
|
{
|
||||||
selected_item = i;
|
selected_item = i;
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item
|
||||||
|
|
||||||
const char vertex_shader_source_bbox[] =
|
const char vertex_shader_source_bbox[] =
|
||||||
{
|
{
|
||||||
|
"#version 120 \n"
|
||||||
"attribute highp vec3 vertex; \n"
|
"attribute highp vec3 vertex; \n"
|
||||||
"attribute highp vec3 colors; \n"
|
"attribute highp vec3 colors; \n"
|
||||||
|
|
||||||
|
|
@ -92,6 +92,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item
|
||||||
};
|
};
|
||||||
const char fragment_shader_source[]=
|
const char fragment_shader_source[]=
|
||||||
{
|
{
|
||||||
|
"#version 120 \n"
|
||||||
"varying vec3 fColors; \n"
|
"varying vec3 fColors; \n"
|
||||||
" \n"
|
" \n"
|
||||||
"void main(void) \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);
|
program->setAttributeBuffer("center",GL_DOUBLE,0,3);
|
||||||
buffers[8].release();
|
buffers[8].release();
|
||||||
|
|
||||||
|
if(viewer->extension_is_found)
|
||||||
|
{
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
||||||
|
}
|
||||||
vaos[3]->release();
|
vaos[3]->release();
|
||||||
}
|
}
|
||||||
//vao for the BBOX
|
//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);
|
program->setAttributeBuffer("center",GL_DOUBLE,0,3);
|
||||||
buffers[16].release();
|
buffers[16].release();
|
||||||
|
|
||||||
|
if(viewer->extension_is_found)
|
||||||
|
{
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
||||||
|
}
|
||||||
vaos[6]->release();
|
vaos[6]->release();
|
||||||
}
|
}
|
||||||
//vao for the axis
|
//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);
|
color.set_rgb_color(0, 1.f, 0);
|
||||||
if(ui_widget->ShowROICheckBox->isChecked()) {
|
if(ui_widget->ShowROICheckBox->isChecked()) {
|
||||||
|
|
||||||
if(!ui_widget->ShowAsSphereCheckBox->isChecked()) {
|
if(!ui_widget->ShowAsSphereCheckBox->isChecked() || !viewer->extension_is_found) {
|
||||||
|
|
||||||
vaos[1]->bind();
|
vaos[1]->bind();
|
||||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
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();
|
vaos[5]->bind();
|
||||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||||
attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
|
attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const
|
||||||
program->release();
|
program->release();
|
||||||
}
|
}
|
||||||
//vao for the spheres
|
//vao for the spheres
|
||||||
|
{
|
||||||
|
if(viewer->extension_is_found)
|
||||||
{
|
{
|
||||||
program = getShaderProgram(PROGRAM_INSTANCED, viewer);
|
program = getShaderProgram(PROGRAM_INSTANCED, viewer);
|
||||||
program->bind();
|
program->bind();
|
||||||
|
|
@ -85,12 +87,35 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const
|
||||||
|
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 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<int>(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<int>(color_spheres.size()*sizeof(float)));
|
||||||
|
program->enableAttributeArray("colors");
|
||||||
|
program->setAttributeBuffer("colors",GL_FLOAT,0,3);
|
||||||
|
buffers[2].release();
|
||||||
|
}
|
||||||
vaos[1]->release();
|
vaos[1]->release();
|
||||||
|
|
||||||
program->release();
|
program->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
//vao for the wired spheres
|
//vao for the wired spheres
|
||||||
|
{
|
||||||
|
if(viewer->extension_is_found)
|
||||||
{
|
{
|
||||||
program = getShaderProgram(PROGRAM_INSTANCED_WIRE, viewer);
|
program = getShaderProgram(PROGRAM_INSTANCED_WIRE, viewer);
|
||||||
program->bind();
|
program->bind();
|
||||||
|
|
@ -102,10 +127,17 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const
|
||||||
program->enableAttributeArray("vertex");
|
program->enableAttributeArray("vertex");
|
||||||
program->setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
program->setAttributeBuffer("vertex",GL_FLOAT,0,3);
|
||||||
buffers[5].release();
|
buffers[5].release();
|
||||||
QColor temp = this->color();
|
|
||||||
program->setAttributeValue("colors", temp);
|
|
||||||
|
|
||||||
program->setAttributeValue("normals",QVector3D(0.0,0.0,0.0));
|
|
||||||
|
buffers[3].bind();
|
||||||
|
program->enableAttributeArray("colors");
|
||||||
|
program->setAttributeBuffer("colors",GL_FLOAT,0,3);
|
||||||
|
buffers[3].release();
|
||||||
|
|
||||||
|
buffers[2].bind();
|
||||||
|
program->enableAttributeArray("normals");
|
||||||
|
program->setAttributeBuffer("normals",GL_FLOAT,0,3);
|
||||||
|
buffers[2].release();
|
||||||
|
|
||||||
buffers[6].bind();
|
buffers[6].bind();
|
||||||
buffers[6].allocate(color_spheres.data(),
|
buffers[6].allocate(color_spheres.data(),
|
||||||
|
|
@ -121,11 +153,14 @@ Scene_polylines_item::initialize_buffers(Viewer_interface *viewer = 0) const
|
||||||
program->setAttributeBuffer("center",GL_FLOAT,0,3);
|
program->setAttributeBuffer("center",GL_FLOAT,0,3);
|
||||||
buffers[7].release();
|
buffers[7].release();
|
||||||
|
|
||||||
|
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("center"), 1);
|
||||||
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
viewer->glVertexAttribDivisor(program->attributeLocation("colors"), 1);
|
||||||
|
|
||||||
vaos[2]->release();
|
vaos[2]->release();
|
||||||
program->release();
|
program->release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
are_buffers_filled = true;
|
are_buffers_filled = true;
|
||||||
|
|
||||||
|
|
@ -283,7 +318,7 @@ Scene_polylines_item::Scene_polylines_item()
|
||||||
,d(new Scene_polylines_item_private())
|
,d(new Scene_polylines_item_private())
|
||||||
,nbSpheres(0)
|
,nbSpheres(0)
|
||||||
{
|
{
|
||||||
setRenderingMode(Flat);
|
setRenderingMode(FlatPlusEdges);
|
||||||
changed();
|
changed();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -363,8 +398,7 @@ Scene_polylines_item::toolTip() const {
|
||||||
bool
|
bool
|
||||||
Scene_polylines_item::supportsRenderingMode(RenderingMode m) const {
|
Scene_polylines_item::supportsRenderingMode(RenderingMode m) const {
|
||||||
return (m == Wireframe ||
|
return (m == Wireframe ||
|
||||||
m == Flat ||
|
m == FlatPlusEdges ||
|
||||||
m == Flat ||
|
|
||||||
m == Points);
|
m == Points);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -375,6 +409,8 @@ Scene_polylines_item::draw(Viewer_interface* viewer) const {
|
||||||
if(!are_buffers_filled)
|
if(!are_buffers_filled)
|
||||||
initialize_buffers(viewer);
|
initialize_buffers(viewer);
|
||||||
if(d->draw_extremities)
|
if(d->draw_extremities)
|
||||||
|
{
|
||||||
|
if(viewer->extension_is_found)
|
||||||
{
|
{
|
||||||
vaos[1]->bind();
|
vaos[1]->bind();
|
||||||
program = getShaderProgram(PROGRAM_INSTANCED);
|
program = getShaderProgram(PROGRAM_INSTANCED);
|
||||||
|
|
@ -385,17 +421,19 @@ Scene_polylines_item::draw(Viewer_interface* viewer) const {
|
||||||
program->release();
|
program->release();
|
||||||
vaos[1]->release();
|
vaos[1]->release();
|
||||||
}
|
}
|
||||||
if(renderingMode() == Flat)
|
else
|
||||||
{
|
{
|
||||||
vaos[0]->bind();
|
vaos[1]->bind();
|
||||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
|
||||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||||
|
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||||
|
glPointSize(8.0f);
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
program->bind();
|
program->bind();
|
||||||
QColor temp = this->color();
|
viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(positions_center.size()/3));
|
||||||
program->setAttributeValue("colors", temp);
|
glDisable(GL_POINT_SMOOTH);
|
||||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/4));
|
|
||||||
program->release();
|
program->release();
|
||||||
vaos[0]->release();
|
vaos[1]->release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -409,12 +447,13 @@ Scene_polylines_item::draw_edges(Viewer_interface* viewer) const {
|
||||||
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
|
||||||
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
|
||||||
program->bind();
|
program->bind();
|
||||||
QColor temp = this->color();
|
program->setAttributeValue("colors", this->color());
|
||||||
program->setAttributeValue("colors", temp);
|
|
||||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/4));
|
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/4));
|
||||||
program->release();
|
program->release();
|
||||||
vaos[0]->release();
|
vaos[0]->release();
|
||||||
if(d->draw_extremities)
|
if(d->draw_extremities)
|
||||||
|
{
|
||||||
|
if(viewer->extension_is_found)
|
||||||
{
|
{
|
||||||
vaos[2]->bind();
|
vaos[2]->bind();
|
||||||
attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE);
|
attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE);
|
||||||
|
|
@ -425,6 +464,7 @@ Scene_polylines_item::draw_edges(Viewer_interface* viewer) const {
|
||||||
program->release();
|
program->release();
|
||||||
vaos[2]->release();
|
vaos[2]->release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,25 @@ void Viewer::initializeGL()
|
||||||
{
|
{
|
||||||
QGLViewer::initializeGL();
|
QGLViewer::initializeGL();
|
||||||
initializeOpenGLFunctions();
|
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);
|
setBackgroundColor(::Qt::white);
|
||||||
d->scene->initializeGL();
|
d->scene->initializeGL();
|
||||||
|
|
||||||
|
|
@ -202,6 +221,8 @@ void Viewer_impl::draw_aux(bool with_names, Viewer* viewer)
|
||||||
scene->drawWithNames(viewer);
|
scene->drawWithNames(viewer);
|
||||||
else
|
else
|
||||||
scene->draw(viewer);
|
scene->draw(viewer);
|
||||||
|
::glDisable(GL_POLYGON_OFFSET_FILL);
|
||||||
|
::glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::drawWithNames()
|
void Viewer::drawWithNames()
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
attribute highp vec4 vertex;
|
attribute highp vec4 vertex;
|
||||||
attribute highp vec3 normals;
|
attribute highp vec3 normals;
|
||||||
attribute highp vec3 colors;
|
attribute highp vec3 colors;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
varying highp vec4 color;
|
varying highp vec4 color;
|
||||||
varying highp vec4 fP;
|
varying highp vec4 fP;
|
||||||
varying highp vec3 fN;
|
varying highp vec3 fN;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
attribute highp vec4 vertex;
|
attribute highp vec4 vertex;
|
||||||
attribute highp vec3 normals;
|
attribute highp vec3 normals;
|
||||||
attribute highp vec3 colors;
|
attribute highp vec3 colors;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
varying highp vec3 fColors;
|
varying highp vec3 fColors;
|
||||||
varying highp vec2 f_texCoord;
|
varying highp vec2 f_texCoord;
|
||||||
uniform sampler2D s_texture;
|
uniform sampler2D s_texture;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
attribute highp vec4 vertex;
|
attribute highp vec4 vertex;
|
||||||
attribute highp vec3 normal;
|
attribute highp vec3 normal;
|
||||||
attribute highp vec3 color_facets;
|
attribute highp vec3 color_facets;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
varying highp vec3 fColors;
|
varying highp vec3 fColors;
|
||||||
varying highp vec2 f_texCoord;
|
varying highp vec2 f_texCoord;
|
||||||
uniform highp sampler2D s_texture;
|
uniform highp sampler2D s_texture;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
attribute highp vec4 vertex;
|
attribute highp vec4 vertex;
|
||||||
attribute highp vec2 v_texCoord;
|
attribute highp vec2 v_texCoord;
|
||||||
uniform highp vec3 color_lines;
|
uniform highp vec3 color_lines;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
varying highp vec4 color;
|
varying highp vec4 color;
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#version 330
|
#version 120
|
||||||
attribute highp vec4 vertex;
|
attribute highp vec4 vertex;
|
||||||
attribute highp vec3 colors;
|
attribute highp vec3 colors;
|
||||||
uniform highp mat4 mvp_matrix;
|
uniform highp mat4 mvp_matrix;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,25 @@ using namespace std;
|
||||||
void Viewer::init()
|
void Viewer::init()
|
||||||
{
|
{
|
||||||
initializeOpenGLFunctions();
|
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 */
|
/* Initial timer for playing incremental construction */
|
||||||
m_pTimer = new QTimer(this);
|
m_pTimer = new QTimer(this);
|
||||||
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(incremental_insert()));
|
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(incremental_insert()));
|
||||||
|
|
@ -162,8 +181,8 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source[] =
|
const char vertex_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
@ -173,7 +192,7 @@ void Viewer::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source[] =
|
const char fragment_source[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"uniform highp vec4 color; \n"
|
"uniform highp vec4 color; \n"
|
||||||
"void main(void) { \n"
|
"void main(void) { \n"
|
||||||
"gl_FragColor = color; \n"
|
"gl_FragColor = color; \n"
|
||||||
|
|
@ -210,15 +229,15 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_spheres[] =
|
const char vertex_source_spheres[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 center;\n"
|
"attribute highp vec4 center;\n"
|
||||||
|
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \n"
|
" fP = mv_matrix * vertex; \n"
|
||||||
|
|
@ -229,9 +248,9 @@ void Viewer::compile_shaders()
|
||||||
//Fragment source code
|
//Fragment source code
|
||||||
const char fragment_source_spheres[] =
|
const char fragment_source_spheres[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"in highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"uniform vec4 color; \n"
|
"uniform vec4 color; \n"
|
||||||
"uniform highp vec4 light_pos; \n"
|
"uniform highp vec4 light_pos; \n"
|
||||||
"uniform highp vec4 light_diff; \n"
|
"uniform highp vec4 light_diff; \n"
|
||||||
|
|
@ -288,18 +307,18 @@ void Viewer::compile_shaders()
|
||||||
//Vertex source code
|
//Vertex source code
|
||||||
const char vertex_source_cylinders[] =
|
const char vertex_source_cylinders[] =
|
||||||
{
|
{
|
||||||
"#version 330 \n"
|
"#version 120 \n"
|
||||||
"in highp vec4 vertex;\n"
|
"attribute highp vec4 vertex;\n"
|
||||||
"in highp vec3 normal;\n"
|
"attribute highp vec3 normal;\n"
|
||||||
"in highp vec4 transfo1;\n"
|
"attribute highp vec4 transfo1;\n"
|
||||||
"in highp vec4 transfo2;\n"
|
"attribute highp vec4 transfo2;\n"
|
||||||
"in highp vec4 transfo3;\n"
|
"attribute highp vec4 transfo3;\n"
|
||||||
"in highp vec4 transfo4;\n"
|
"attribute highp vec4 transfo4;\n"
|
||||||
"mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n"
|
"mat4 transfo = mat4(transfo1, transfo2, transfo3, transfo4); \n"
|
||||||
"uniform highp mat4 mvp_matrix;\n"
|
"uniform highp mat4 mvp_matrix;\n"
|
||||||
"uniform highp mat4 mv_matrix; \n"
|
"uniform highp mat4 mv_matrix; \n"
|
||||||
"out highp vec4 fP; \n"
|
"varying highp vec4 fP; \n"
|
||||||
"out highp vec3 fN; \n"
|
"varying highp vec3 fN; \n"
|
||||||
"void main(void)\n"
|
"void main(void)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" fP = mv_matrix * vertex; \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);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[13].release();
|
buffers[13].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[11].release();
|
vao[11].release();
|
||||||
|
|
||||||
//Empty Sphere
|
//Empty Sphere
|
||||||
vao[12].bind();
|
vao[12].bind();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
buffers[14].bind();
|
buffers[14].bind();
|
||||||
buffers[14].allocate(pos_emptySphere->data(), pos_emptySphere->size()*sizeof(float));
|
buffers[14].allocate(pos_emptySphere->data(), pos_emptySphere->size()*sizeof(float));
|
||||||
centerLocation[0] = rendering_program_spheres.attributeLocation("center");
|
centerLocation[0] = rendering_program_spheres.attributeLocation("center");
|
||||||
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
rendering_program_spheres.enableAttributeArray(centerLocation[0]);
|
||||||
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(centerLocation[0],GL_FLOAT,0,3);
|
||||||
buffers[14].release();
|
buffers[14].release();
|
||||||
|
}
|
||||||
buffers[32].bind();
|
buffers[32].bind();
|
||||||
buffers[32].allocate(normals_emptySphere->data(), normals_emptySphere->size()*sizeof(float));
|
buffers[32].allocate(normals_emptySphere->data(), normals_emptySphere->size()*sizeof(float));
|
||||||
normalsLocation[0] = rendering_program_spheres.attributeLocation("normal");
|
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);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[16].release();
|
buffers[16].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[12].release();
|
vao[12].release();
|
||||||
|
|
||||||
//Vertex Sphere
|
//Vertex Sphere
|
||||||
|
|
@ -767,8 +794,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[13].release();
|
vao[13].release();
|
||||||
|
|
||||||
//New point Sphere
|
//New point Sphere
|
||||||
|
|
@ -791,8 +821,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[14].release();
|
vao[14].release();
|
||||||
|
|
||||||
//Selected point Sphere
|
//Selected point Sphere
|
||||||
|
|
@ -815,8 +848,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[15].release();
|
vao[15].release();
|
||||||
|
|
||||||
//Moving point Sphere
|
//Moving point Sphere
|
||||||
|
|
@ -839,8 +875,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[16].release();
|
vao[16].release();
|
||||||
|
|
||||||
//Querry point Sphere
|
//Querry point Sphere
|
||||||
|
|
@ -863,8 +902,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[17].release();
|
vao[17].release();
|
||||||
|
|
||||||
//Nearest neighbor Sphere
|
//Nearest neighbor Sphere
|
||||||
|
|
@ -887,8 +929,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[18].release();
|
vao[18].release();
|
||||||
|
|
||||||
//incremental list
|
//incremental list
|
||||||
|
|
@ -910,8 +955,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[25].release();
|
vao[25].release();
|
||||||
|
|
||||||
//incremental next point
|
//incremental next point
|
||||||
|
|
@ -933,8 +981,11 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
rendering_program_spheres.setAttributeBuffer(poly_vertexLocation[1],GL_FLOAT,0,3);
|
||||||
buffers[17].release();
|
buffers[17].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[0],1);
|
glVertexAttribDivisor(centerLocation[0],1);
|
||||||
glVertexAttribDivisor(normalsLocation[0],0);
|
glVertexAttribDivisor(normalsLocation[0],0);
|
||||||
|
}
|
||||||
vao[26].release();
|
vao[26].release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -985,12 +1036,14 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
||||||
buffers[23].release();
|
buffers[23].release();
|
||||||
|
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[1],1);
|
glVertexAttribDivisor(centerLocation[1],1);
|
||||||
glVertexAttribDivisor(centerLocation[2],1);
|
glVertexAttribDivisor(centerLocation[2],1);
|
||||||
glVertexAttribDivisor(centerLocation[3],1);
|
glVertexAttribDivisor(centerLocation[3],1);
|
||||||
glVertexAttribDivisor(centerLocation[4],1);
|
glVertexAttribDivisor(centerLocation[4],1);
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
|
|
||||||
vao[19].release();
|
vao[19].release();
|
||||||
|
|
||||||
|
|
@ -1035,13 +1088,14 @@ void Viewer::initialize_buffers()
|
||||||
rendering_program_cylinders.enableAttributeArray(centerLocation[4]);
|
rendering_program_cylinders.enableAttributeArray(centerLocation[4]);
|
||||||
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
rendering_program_cylinders.setAttributeBuffer(centerLocation[4],GL_FLOAT,0,4);
|
||||||
buffers[27].release();
|
buffers[27].release();
|
||||||
|
if(extension_is_found)
|
||||||
|
{
|
||||||
glVertexAttribDivisor(centerLocation[1],1);
|
glVertexAttribDivisor(centerLocation[1],1);
|
||||||
glVertexAttribDivisor(centerLocation[2],1);
|
glVertexAttribDivisor(centerLocation[2],1);
|
||||||
glVertexAttribDivisor(centerLocation[3],1);
|
glVertexAttribDivisor(centerLocation[3],1);
|
||||||
glVertexAttribDivisor(centerLocation[4],1);
|
glVertexAttribDivisor(centerLocation[4],1);
|
||||||
glVertexAttribDivisor(normalsLocation[1],0);
|
glVertexAttribDivisor(normalsLocation[1],0);
|
||||||
|
}
|
||||||
|
|
||||||
vao[20].release();
|
vao[20].release();
|
||||||
}
|
}
|
||||||
|
|
@ -1139,11 +1193,12 @@ void Viewer::attrib_buffers(QGLViewer* viewer)
|
||||||
|
|
||||||
void Viewer::draw()
|
void Viewer::draw()
|
||||||
{
|
{
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
if(!are_buffers_initialized)
|
if(!are_buffers_initialized)
|
||||||
initialize_buffers();
|
initialize_buffers();
|
||||||
QFont fontPrompt("Arial", 8);
|
QFont fontPrompt("Arial", 8);
|
||||||
attrib_buffers(this);
|
attrib_buffers(this);
|
||||||
if(m_isFlat)
|
if(m_isFlat || !extension_is_found)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(m_showVertex)
|
if(m_showVertex)
|
||||||
|
|
@ -1564,7 +1619,10 @@ void Viewer::draw()
|
||||||
rendering_program_spheres.bind();
|
rendering_program_spheres.bind();
|
||||||
vao[11].bind();
|
vao[11].bind();
|
||||||
rendering_program_spheres.setUniformValue(colorLocation[1], m_colorTrackball);
|
rendering_program_spheres.setUniformValue(colorLocation[1], m_colorTrackball);
|
||||||
|
if(extension_is_found)
|
||||||
glDrawArraysInstanced(GL_TRIANGLES, 0, points_trackBall->size()/3, 1);
|
glDrawArraysInstanced(GL_TRIANGLES, 0, points_trackBall->size()/3, 1);
|
||||||
|
else
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, points_trackBall->size()/3);
|
||||||
vao[11].release();
|
vao[11].release();
|
||||||
rendering_program_spheres.release();
|
rendering_program_spheres.release();
|
||||||
}
|
}
|
||||||
|
|
@ -1573,7 +1631,13 @@ void Viewer::draw()
|
||||||
rendering_program_spheres.bind();
|
rendering_program_spheres.bind();
|
||||||
vao[12].bind();
|
vao[12].bind();
|
||||||
rendering_program_spheres.setUniformValue(colorLocation[1], m_colorEmptySphere);
|
rendering_program_spheres.setUniformValue(colorLocation[1], m_colorEmptySphere);
|
||||||
|
if(extension_is_found)
|
||||||
glDrawArraysInstanced(GL_TRIANGLES, 0, points_emptySphere->size()/3, pos_emptySphere->size()/3);
|
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();
|
vao[12].release();
|
||||||
rendering_program_spheres.release();
|
rendering_program_spheres.release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include "PreferenceDlg.h"
|
#include "PreferenceDlg.h"
|
||||||
|
|
||||||
#include <QOpenGLFunctions_3_3_Core>
|
#include <QOpenGLFunctions_2_1>
|
||||||
#include <QOpenGLVertexArrayObject>
|
#include <QOpenGLVertexArrayObject>
|
||||||
#include <QOpenGLBuffer>
|
#include <QOpenGLBuffer>
|
||||||
#include <QOpenGLShaderProgram>
|
#include <QOpenGLShaderProgram>
|
||||||
|
|
@ -18,7 +18,7 @@ using namespace qglviewer;
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
class Viewer : public QGLViewer, QOpenGLFunctions_3_3_Core {
|
class Viewer : public QGLViewer, QOpenGLFunctions_2_1 {
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
|
@ -345,6 +345,8 @@ private:
|
||||||
int lightLocation[5*2];
|
int lightLocation[5*2];
|
||||||
|
|
||||||
bool are_buffers_initialized;
|
bool are_buffers_initialized;
|
||||||
|
bool extension_is_found;
|
||||||
|
|
||||||
std::vector<float> *pos_emptyFacet;
|
std::vector<float> *pos_emptyFacet;
|
||||||
std::vector<float> *pos_emptySphere;
|
std::vector<float> *pos_emptySphere;
|
||||||
std::vector<float> *points_emptySphere;
|
std::vector<float> *points_emptySphere;
|
||||||
|
|
@ -385,6 +387,10 @@ private:
|
||||||
QOpenGLShaderProgram rendering_program;
|
QOpenGLShaderProgram rendering_program;
|
||||||
QOpenGLShaderProgram rendering_program_spheres;
|
QOpenGLShaderProgram rendering_program_spheres;
|
||||||
QOpenGLShaderProgram rendering_program_cylinders;
|
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 initialize_buffers();
|
||||||
void compute_elements();
|
void compute_elements();
|
||||||
void attrib_buffers(QGLViewer*);
|
void attrib_buffers(QGLViewer*);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue