diff --git a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp index 3a17922711e..e5757c6d47f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_c3t3_item.cpp @@ -43,6 +43,7 @@ //TODO: Secure the case where there are more that 124 different subdomains and the case OpenGL is too old. (no shifting before 1.30) +//TODO: Replace the facet patch_id by a pair of patch_ids (one per adjacent cell), and test the pair instead of only one id in the shader. typedef CGAL::AABB_triangulation_3_cell_primitive Primitive; @@ -98,7 +99,7 @@ public : std::vector *p_edges, std::vector *p_colors, std::vector *p_bary, - std::vector *p_subdomain_ids) + std::vector *p_subdomain_ids) { vertices = p_vertices; normals = p_normals; @@ -134,7 +135,7 @@ public : getTriangleContainer(0)->allocate(Tc::Facet_centers, barycenters->data(), static_cast(barycenters->size()*sizeof(float))); getTriangleContainer(0)->allocate(Tc::Subdomain_indices, subdomain_ids->data(), - static_cast(subdomain_ids->size()*sizeof(GLuint))); + static_cast(subdomain_ids->size()*sizeof(float))); getEdgeContainer(0)->allocate(Ec::Vertices, edges->data(), static_cast(edges->size()*sizeof(float))); setBuffersFilled(true); @@ -292,7 +293,7 @@ private: mutable std::vector *edges; mutable std::vector *colors; mutable std::vector *barycenters; - mutable std::vector *subdomain_ids; + mutable std::vector *subdomain_ids; mutable bool is_fast; mutable QSlider* alphaSlider; mutable float m_alpha ; @@ -484,7 +485,7 @@ struct Scene_c3t3_item_priv { mutable std::vector positions_grid; mutable std::vector positions_poly; mutable std::vector positions_barycenter; - mutable std::vector inter_subdomain_ids; + mutable std::vector inter_subdomain_ids; mutable std::vector normals; mutable std::vector f_colors; @@ -494,7 +495,7 @@ struct Scene_c3t3_item_priv { mutable std::vector ws_vertex; mutable std::vector s_radius; mutable std::vector s_center; - mutable std::vector subdomain_ids; + mutable std::vector subdomain_ids; mutable bool computed_stats; mutable float max_edges_length; mutable float min_edges_length; @@ -998,15 +999,11 @@ void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const { getTriangleContainer(C3t3_faces)->setAlpha(alpha()); getTriangleContainer(C3t3_faces)->setIsSurface(d->is_surface); - GLuint visible_bitset[4] = - { - static_cast(d->bs[0].to_ulong()), - static_cast(d->bs[1].to_ulong()), - static_cast(d->bs[2].to_ulong()), - static_cast(d->bs[3].to_ulong()) - }; - std::cout<getShaderProgram(getTriangleContainer(C3t3_faces)->getProgram())->setUniformValueArray("is_visible_bitset", visible_bitset, 4); + QVector4D visible_bitset(d->bs[0].to_ulong(),d->bs[1].to_ulong(),d->bs[2].to_ulong(),d->bs[3].to_ulong()); + QOpenGLShaderProgram* program = viewer->getShaderProgram(getTriangleContainer(C3t3_faces)->getProgram()); + program->bind(); + program->setUniformValue("is_visible_bitset", visible_bitset); + program->release(); getTriangleContainer(C3t3_faces)->draw(viewer, false); if(d->show_tetrahedra){ ncthis->show_intersection(true); @@ -1359,8 +1356,10 @@ void Scene_c3t3_item_priv::computeIntersection(const Primitive& cell) const Tr::Bare_point& pd = wp2p(ch->vertex(3)->point()); CGAL::IO::Color color(UC(c.red()), UC(c.green()), UC(c.blue())); - for(int i=0; i< 4; ++i) - inter_subdomain_ids.push_back(id_to_compact[ch->subdomain_index()]); + for(int i=0; i< 12; ++i) + { + inter_subdomain_ids.push_back(static_cast(id_to_compact[ch->subdomain_index()])); + } intersection->addTriangle(pb, pa, pc, color); intersection->addTriangle(pa, pb, pd, color); intersection->addTriangle(pa, pd, pc, color); @@ -1528,7 +1527,10 @@ void Scene_c3t3_item_priv::computeElements() f_colors.push_back((float)color.redF());f_colors.push_back((float)color.greenF());f_colors.push_back((float)color.blueF()); f_colors.push_back((float)color.redF());f_colors.push_back((float)color.greenF());f_colors.push_back((float)color.blueF()); f_colors.push_back((float)color.redF());f_colors.push_back((float)color.greenF());f_colors.push_back((float)color.blueF()); - subdomain_ids.push_back(id_to_compact[cell->subdomain_index()]); + for(int i=0; i<3; ++i) + { + subdomain_ids.push_back(static_cast(id_to_compact[cell->subdomain_index()])); + } if ((index % 2 == 1) == c3t3.is_in_complex(cell)) draw_triangle(pb, pa, pc); else draw_triangle(pa, pb, pc); @@ -2115,7 +2117,7 @@ void Scene_c3t3_item::computeElements()const getTriangleContainer(C3t3_faces)->allocate( Tc::Subdomain_indices, d->subdomain_ids.data(), - static_cast(d->subdomain_ids.size()*sizeof(GLuint))); + static_cast(d->subdomain_ids.size()*sizeof(float))); d->positions_poly_size = d->positions_poly.size(); diff --git a/Polyhedron/demo/Polyhedron/Triangle_container.cpp b/Polyhedron/demo/Polyhedron/Triangle_container.cpp index 7f0d8bf0d43..2a0f012d431 100644 --- a/Polyhedron/demo/Polyhedron/Triangle_container.cpp +++ b/Polyhedron/demo/Polyhedron/Triangle_container.cpp @@ -138,13 +138,16 @@ void Triangle_container::initGL( Viewer_interface* viewer) if(!getTexture()) setTexture(new Texture()); } + // This is passed as float because to pass an integer type to glslthe function is glVertexAttribIPointer(), + // but the qt system only calls glVertexAttribPointer(), whatever type is given. It is far less efforts to + // convert floats that to reimplement the whole system without Qt for this attribute. if(viewer->getShaderProgram(getProgram())->property("hasSubdomainIndicesValues").toBool()) { if(!getVbo(Subdomain_indices)) setVbo(Subdomain_indices, new Vbo("subdomain_in", Vbo::GEOMETRY, - QOpenGLBuffer::VertexBuffer, GL_UNSIGNED_INT, 0, 1)); + QOpenGLBuffer::VertexBuffer, GL_FLOAT, 0, 1)); getVao(viewer)->addVbo(getVbo(Subdomain_indices)); } } diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag index d521488e9db..8ac89802894 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.frag @@ -2,7 +2,7 @@ in vec4 color; in vec4 fP; in vec3 fN; -flat in uint subdomain_out; +flat in float subdomain_out; uniform vec4 light_pos; uniform vec4 light_diff; uniform vec4 light_spec; @@ -19,7 +19,7 @@ uniform bool writing; uniform sampler2D sampler; uniform float alpha; uniform bool is_surface; -uniform uvec4 is_visible_bitset; +uniform vec4 is_visible_bitset; out vec4 out_color; float depth(float z) @@ -28,12 +28,28 @@ float depth(float z) } void main(void) { - uint i = subdomain_out/32u; - if(4u>>(subdomain_out%32u) != 1u) + uint domain = uint(subdomain_out); + uint i = domain/32u; + uint visible = uint(is_visible_bitset[i]); + if(domain==0u) { - out_color = vec4(1.0,0,0,1.0); + out_color = vec4(1.0,0.0,0.0,1.0); return; } + else if(domain==1u) + { + out_color = vec4(0.0,1.0,0.0,1.0); + return; + } + else if(domain==2u) + { + out_color = vec4(0.0,0.0,1.0,1.0); + return; + } + if(visible>>(domain%32u) == 0u) + { + discard; + } float d = depth(gl_FragCoord.z); float test = texture(sampler, vec2(gl_FragCoord.x/width, gl_FragCoord.y/height)).r; if(comparing && d <= test) diff --git a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert index 5cde2fb4bce..9388379be3d 100644 --- a/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert +++ b/Polyhedron/demo/Polyhedron/resources/shader_c3t3.vert @@ -3,7 +3,7 @@ in vec4 vertex; in vec3 normals; in vec3 colors; in vec3 center; -in uint subdomain_in; +in float subdomain_in; uniform mat4 mvp_matrix; uniform mat4 mv_matrix; uniform mat4 norm_matrix; @@ -12,7 +12,7 @@ uniform float shrink_factor; out vec4 fP; out vec3 fN; out vec4 color; -flat out uint subdomain_out; +flat out float subdomain_out; uniform float point_size; void main(void) {