diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc index ee7c126753c..b07939a8172 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc +++ b/Polyhedron/demo/Polyhedron/Polyhedron_3.qrc @@ -23,6 +23,7 @@ resources/about.html + resources/shader_c3t3.v resources/shader_with_light.v resources/shader_with_light.f resources/shader_without_light.f diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index ba901acf1d4..4c8b53b15fc 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -104,6 +104,7 @@ Scene_c3t3_item::Scene_c3t3_item() need_changed = false; startTimer(0); connect(frame, SIGNAL(modified()), this, SLOT(changed())); + std::cerr << "A \n"; c3t3_changed(); setRenderingMode(FlatPlusEdges); compile_shaders(); @@ -129,7 +130,8 @@ Scene_c3t3_item::Scene_c3t3_item(const C3t3& c3t3) ws_vertex.resize(0); need_changed = false; startTimer(0); - connect(frame, SIGNAL(modified()), this, SLOT(changed())); + // connect(frame, SIGNAL(modified()), this, SLOT(changed())); + std::cerr << "B \n"; c3t3_changed(); setRenderingMode(FlatPlusEdges); compile_shaders(); @@ -182,19 +184,23 @@ Scene_c3t3_item::c3t3() void Scene_c3t3_item::changed() { - + std::cerr << "changed()\n"; need_changed = true; } void Scene_c3t3_item::timerEvent(QTimerEvent* /*event*/) { // just handle deformation - paint like selection is handled in eventFilter() if(need_changed) { - c3t3_changed(); + std::cerr << "C \n"; + invalidate_buffers(); + need_changed = false; } } + void Scene_c3t3_item::c3t3_changed() { + std::cerr << "c3t3_changedn"; // Update colors // Fill indices map and get max subdomain value indices_.clear(); @@ -212,9 +218,7 @@ Scene_c3t3_item::c3t3_changed() // Rebuild histogram build_histogram(); - //compute_elements(); - this->invalidate_buffers(); - need_changed = false; + } QPixmap @@ -472,10 +476,12 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const { initialize_buffers(viewer); } vaos[Facets]->bind(); - program = getShaderProgram(PROGRAM_WITH_LIGHT); - attrib_buffers(viewer, PROGRAM_WITH_LIGHT); + program = getShaderProgram(PROGRAM_C3T3); + attrib_buffers(viewer, PROGRAM_C3T3); program->bind(); - //program->setAttributeValue("colors", this->color()); + QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d()); + program->setUniformValue("cutplane", cp); + viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast(positions_poly.size() / 3)); program->release(); vaos[Facets]->release(); @@ -763,7 +769,7 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)c { //vao containing the data for the facets { - program = getShaderProgram(PROGRAM_WITH_LIGHT, viewer); + program = getShaderProgram(PROGRAM_C3T3, viewer); program->bind(); vaos[Facets]->bind(); @@ -920,6 +926,7 @@ void Scene_c3t3_item::initialize_buffers(CGAL::Three::Viewer_interface *viewer)c void Scene_c3t3_item::compute_elements() const { + std::cerr << "compute_elements\n"; positions_lines.clear(); positions_poly.clear(); normals.clear(); diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h index f84e9352996..dab29258109 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.h @@ -58,11 +58,6 @@ public: void c3t3_changed(); - void contextual_changed() - { - if (frame->isManipulated() || frame->isSpinning()) - invalidate_buffers(); - } const C3t3& c3t3() const; C3t3& c3t3(); diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp index c28d4660ff7..924fef1f6c1 100644 --- a/Polyhedron/demo/Polyhedron/Viewer.cpp +++ b/Polyhedron/demo/Polyhedron/Viewer.cpp @@ -464,6 +464,16 @@ void Viewer::attrib_buffers(int program_name) const { program->setUniformValue("spec_power", 51.8f); program->setUniformValue("is_two_side", is_both_sides); break; + case PROGRAM_C3T3: + program->setUniformValue("mvp_matrix", mvp_mat); + program->setUniformValue("mv_matrix", mv_mat); + program->setUniformValue("light_pos", position); + program->setUniformValue("light_diff",diffuse); + program->setUniformValue("light_spec", specular); + program->setUniformValue("light_amb", ambient); + program->setUniformValue("spec_power", 51.8f); + program->setUniformValue("is_two_side", is_both_sides); + break; case PROGRAM_WITHOUT_LIGHT: program->setUniformValue("mvp_matrix", mvp_mat); program->setUniformValue("mv_matrix", mv_mat); @@ -883,7 +893,30 @@ QOpenGLShaderProgram* Viewer::getShaderProgram(int name) const switch(name) { - /// @TODO: factorize this code + /// @TODO: factorize this code + case PROGRAM_C3T3: + if(d->shader_programs[PROGRAM_C3T3]) + { + return d->shader_programs[PROGRAM_C3T3]; + } + + else + { + + QOpenGLShaderProgram *program = new QOpenGLShaderProgram(viewer); + if(!program->addShaderFromSourceFile(QOpenGLShader::Vertex,":/cgal/Polyhedron_3/resources/shader_c3t3.v")) + { + std::cerr<<"adding vertex shader FAILED"<addShaderFromSourceFile(QOpenGLShader::Fragment,":/cgal/Polyhedron_3/resources/shader_with_light.f")) + { + std::cerr<<"adding fragment shader FAILED"<link(); + d->shader_programs[PROGRAM_C3T3] = program; + return program; + } + break; case PROGRAM_WITH_LIGHT: if(d->shader_programs[PROGRAM_WITH_LIGHT]) { diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.v b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.v new file mode 100755 index 00000000000..bcc737efd8b --- /dev/null +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.v @@ -0,0 +1,22 @@ +#version 120 +attribute highp vec4 vertex; +attribute highp vec3 normals; +attribute highp vec3 colors; +uniform highp mat4 mvp_matrix; +uniform highp mat4 mv_matrix; +uniform highp vec4 cutplane; +varying highp vec4 fP; +varying highp vec3 fN; +varying highp vec4 color; +void main(void) +{ + if(vertex.x * cutplane.x + vertex.y * cutplane.y + vertex.z * cutplane.z + cutplane.w > 0){ + //color = vec4(colors, 1.0); + color = vec4(0.0, 1.0, 1.0, 0.0); + } else { + color = vec4(0.0, 0.0, 1.0, 1.0); +} + fP = mv_matrix * vertex; + fN = mat3(mv_matrix)* normals; + gl_Position = mvp_matrix * vertex; +} diff --git a/Polyhedron/demo/Polyhedron/resources/shader_with_light.f b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f index 1b1de6f80c3..2da0cac3e31 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_with_light.f +++ b/Polyhedron/demo/Polyhedron/resources/shader_with_light.f @@ -9,7 +9,8 @@ uniform highp vec4 light_amb; uniform highp float spec_power ; uniform int is_two_side; uniform bool is_selected; -void main(void) { +void main(void) { + if(color.w > 0.0){ highp vec3 L = light_pos.xyz - fP.xyz; highp vec3 V = -fP.xyz; highp vec3 N; @@ -31,4 +32,9 @@ void main(void) { gl_FragColor = vec4(ret_color.r+70.0/255.0, ret_color.g+70.0/255.0, ret_color.b+70.0/255.0, 1.0); else gl_FragColor = ret_color; -} +}else{ + discard; +} +} + + diff --git a/Three/include/CGAL/Three/Scene_item.h b/Three/include/CGAL/Three/Scene_item.h index 723795c33d6..03a0da692dc 100644 --- a/Three/include/CGAL/Three/Scene_item.h +++ b/Three/include/CGAL/Three/Scene_item.h @@ -60,6 +60,7 @@ public: PROGRAM_WITH_TEXTURED_EDGES, PROGRAM_INSTANCED, PROGRAM_INSTANCED_WIRE, + PROGRAM_C3T3, NB_OF_PROGRAMS }; typedef CGAL::Three::Scene_interface::Bbox Bbox; diff --git a/Three/include/CGAL/Three/Viewer_interface.h b/Three/include/CGAL/Three/Viewer_interface.h index ea1da1a5153..12737e74c0d 100644 --- a/Three/include/CGAL/Three/Viewer_interface.h +++ b/Three/include/CGAL/Three/Viewer_interface.h @@ -50,6 +50,7 @@ public: PROGRAM_WITH_TEXTURED_EDGES, PROGRAM_INSTANCED, PROGRAM_INSTANCED_WIRE, + PROGRAM_C3T3, NB_OF_PROGRAMS }; Viewer_interface(QWidget* parent) : QGLViewer(CGAL::Qt::createOpenGLContext(), parent) {}