diff --git a/bundled_deps/admesh/admesh/connect.cpp b/bundled_deps/admesh/admesh/connect.cpp index 8c3ab154adf..fb3e043f484 100644 --- a/bundled_deps/admesh/admesh/connect.cpp +++ b/bundled_deps/admesh/admesh/connect.cpp @@ -140,12 +140,12 @@ struct HashTableEdges { void insert_edge_exact(stl_file *stl, const HashEdge &edge) { - this->insert_edge(stl, edge, [stl](const HashEdge& edge1, const HashEdge& edge2) { record_neighbors(stl, edge1, edge2); }); + this->insert_edge(stl, edge, [stl](const HashEdge& edge1, const HashEdge& edge2) { HashTableEdges::record_neighbors(stl, edge1, edge2); }); } void insert_edge_nearby(stl_file *stl, const HashEdge &edge) { - this->insert_edge(stl, edge, [stl](const HashEdge& edge1, const HashEdge& edge2) { match_neighbors_nearby(stl, edge1, edge2); }); + this->insert_edge(stl, edge, [stl](const HashEdge& edge1, const HashEdge& edge2) { HashTableEdges::match_neighbors_nearby(stl, edge1, edge2); }); } // Hash table on edges @@ -216,7 +216,6 @@ struct HashTableEdges { // This is a match. Record result in neighbors list. match_neighbors(edge, *link->next); // Delete the matched edge from the list. - HashEdge *temp = link->next; link->next = link->next->next; // pool.destroy(temp); #ifndef NDEBUG @@ -482,9 +481,10 @@ void stl_check_facets_nearby(stl_file *stl, float tolerance) { assert(stl->stats.connected_facets_3_edge <= stl->stats.connected_facets_2_edge); assert(stl->stats.connected_facets_2_edge <= stl->stats.connected_facets_1_edge); - assert(stl->stats.connected_facets_1_edge <= stl->stats.number_of_facets); + // cast number_of_facets to int to avoid signed/unsigned comparison warnings + assert(stl->stats.connected_facets_1_edge <= static_cast(stl->stats.number_of_facets)); - if (stl->stats.connected_facets_3_edge == stl->stats.number_of_facets) + if (stl->stats.connected_facets_3_edge == static_cast(stl->stats.number_of_facets)) // No need to check any further. All facets are connected. return; @@ -533,7 +533,8 @@ void stl_remove_unconnected_facets(stl_file *stl) for (int i = 0; i < 3; ++ i) if (neighbors.neighbor[i] != -1) { int &other_face_idx = stl->neighbors_start[neighbors.neighbor[i]].neighbor[(neighbors.which_vertex_not[i] + 1) % 3]; - if (other_face_idx != stl->stats.number_of_facets) { + // compare with casted value to avoid signed/unsigned mismatch + if (other_face_idx != static_cast(stl->stats.number_of_facets)) { BOOST_LOG_TRIVIAL(info) << "in remove_facet: neighbor = " << other_face_idx << " numfacets = " << stl->stats.number_of_facets << " this is wrong"; return; } diff --git a/bundled_deps/admesh/admesh/normals.cpp b/bundled_deps/admesh/admesh/normals.cpp index 3b677641f99..8ec376aa43e 100644 --- a/bundled_deps/admesh/admesh/normals.cpp +++ b/bundled_deps/admesh/admesh/normals.cpp @@ -188,12 +188,11 @@ void stl_fix_normal_directions(stl_file *stl) // Get next facet to fix from top of list. if (head->next != tail) { facet_num = head->next->facet_num; - assert(facet_num < stl->stats.number_of_facets); + assert(static_cast(facet_num) < stl->stats.number_of_facets); if (norm_sw[facet_num] != 1) { // If facet is in list mutiple times norm_sw[facet_num] = 1; // Record this one as being fixed. ++ checked; } - stl_normal *temp = head->next; // Delete this facet from the list. head->next = head->next->next; // pool.destroy(temp); } else { // If we ran out of facets to fix: All of the facets in this part have been fixed. diff --git a/bundled_deps/admesh/admesh/shared.cpp b/bundled_deps/admesh/admesh/shared.cpp index 1948255c0cf..4f3a857ebf9 100644 --- a/bundled_deps/admesh/admesh/shared.cpp +++ b/bundled_deps/admesh/admesh/shared.cpp @@ -139,9 +139,9 @@ bool its_write_off(const indexed_triangle_set &its, const char *file) fprintf(fp, "OFF\n"); fprintf(fp, "%d %d 0\n", (int)its.vertices.size(), (int)its.indices.size()); - for (int i = 0; i < its.vertices.size(); ++ i) + for (size_t i = 0; i < its.vertices.size(); ++ i) fprintf(fp, "\t%f %f %f\n", its.vertices[i](0), its.vertices[i](1), its.vertices[i](2)); - for (uint32_t i = 0; i < its.indices.size(); ++ i) + for (size_t i = 0; i < its.indices.size(); ++ i) fprintf(fp, "\t3 %d %d %d\n", its.indices[i][0], its.indices[i][1], its.indices[i][2]); fclose(fp); return true; @@ -172,7 +172,7 @@ bool its_write_vrml(const indexed_triangle_set &its, const char *file) fprintf(fp, "\t\tDEF STLVertices Coordinate3 {\n"); fprintf(fp, "\t\t\tpoint [\n"); - int i = 0; + size_t i = 0; for (; i + 1 < its.vertices.size(); ++ i) fprintf(fp, "\t\t\t\t%f %f %f,\n", its.vertices[i](0), its.vertices[i](1), its.vertices[i](2)); fprintf(fp, "\t\t\t\t%f %f %f]\n", its.vertices[i](0), its.vertices[i](1), its.vertices[i](2)); diff --git a/bundled_deps/admesh/admesh/stlinit.cpp b/bundled_deps/admesh/admesh/stlinit.cpp index f2a518486fd..9da553ff2db 100644 --- a/bundled_deps/admesh/admesh/stlinit.cpp +++ b/bundled_deps/admesh/admesh/stlinit.cpp @@ -203,7 +203,8 @@ static bool stl_read(stl_file *stl, FILE *fp, int first_facet, bool first) sscanf(normal_buf[2], "%f", &facet.normal(2)) != 1) { // Normal was mangled. Maybe denormals or "not a number" were stored? // Just reset the normal and silently ignore it. - memset(&facet.normal, 0, sizeof(facet.normal)); + // Avoid raw-memory writes into non-trivially-copyable Eigen types. + facet.normal.setZero(); } } @@ -288,3 +289,4 @@ void stl_facet_stats(stl_file *stl, stl_facet facet, bool &first) stl->stats.max = stl->stats.max.cwiseMax(facet.vertex[i]); } } + diff --git a/bundled_deps/admesh/admesh/util.cpp b/bundled_deps/admesh/admesh/util.cpp index 644fa1834ca..1cdb9aba676 100644 --- a/bundled_deps/admesh/admesh/util.cpp +++ b/bundled_deps/admesh/admesh/util.cpp @@ -324,10 +324,12 @@ void stl_repair( } if (nearby_flag || fixall_flag) { - if (! tolerance_flag) + if (! tolerance_flag) { tolerance = stl->stats.shortest_edge; - if (! increment_flag) + } + if (! increment_flag){ increment = stl->stats.bounding_diameter / 10000.0; + } } if (stl->stats.connected_facets_3_edge < int(stl->stats.number_of_facets)) { diff --git a/bundled_deps/avrdude/avrdude/avr.c b/bundled_deps/avrdude/avrdude/avr.c index defae75d50c..3cf471d1430 100644 --- a/bundled_deps/avrdude/avrdude/avr.c +++ b/bundled_deps/avrdude/avrdude/avr.c @@ -83,7 +83,8 @@ int avr_tpi_chip_erase(PROGRAMMER * pgm, AVRPART * p) 0xFF }; - while (avr_tpi_poll_nvmbsy(pgm)); + while (avr_tpi_poll_nvmbsy(pgm)) + ; err = pgm->cmd_tpi(pgm, cmd, sizeof(cmd), NULL, 0); if(err) diff --git a/bundled_deps/avrdude/avrdude/buspirate.c b/bundled_deps/avrdude/avrdude/buspirate.c index dc8c68fbebd..29b606f859d 100644 --- a/bundled_deps/avrdude/avrdude/buspirate.c +++ b/bundled_deps/avrdude/avrdude/buspirate.c @@ -568,8 +568,7 @@ static int buspirate_start_mode_bin(struct programmer_t *pgm) memset(buf, 0, sizeof(buf)); buspirate_recv_bin(pgm, buf, 4); if (sscanf((const char*)buf, submode->entered_format, &PDATA(pgm)->submode_version) != 1) { - avrdude_message(MSG_INFO, "%s mode not confirmed: '%s'\n", - submode->name, buf); + avrdude_message(MSG_INFO, "BusPirate submode not confirmed: '%s'\n", buf); buspirate_reset_from_binmode(pgm); return -1; } diff --git a/src/clipper/clipper.cpp b/src/clipper/clipper.cpp index 4da58dc26b2..1e3213f74a4 100644 --- a/src/clipper/clipper.cpp +++ b/src/clipper/clipper.cpp @@ -428,7 +428,7 @@ void ReversePolyPtLinks(OutPt *pp) inline void InitEdge(TEdge* e, TEdge* eNext, TEdge* ePrev, const IntPoint& Pt) { - std::memset(e, 0, sizeof(TEdge)); + *e = TEdge(); e->Next = eNext; e->Prev = ePrev; e->Curr = Pt; @@ -786,7 +786,7 @@ bool ClipperBase::AddPathInternal(const Path &pg, int highI, PolyType PolyTyp, b throw clipperException("AddPath: Open paths have been disabled."); #endif - assert(highI >= 0 && highI < pg.size()); + assert(highI >= 0 && static_cast(highI) < pg.size()); //1. Basic (first) edge initialization ... try diff --git a/src/libslic3r/CutSurface.cpp b/src/libslic3r/CutSurface.cpp index 57dfb85608f..b2e1c1a3b47 100644 --- a/src/libslic3r/CutSurface.cpp +++ b/src/libslic3r/CutSurface.cpp @@ -680,9 +680,9 @@ indexed_triangle_set Slic3r::cut2model(const SurfaceCut &cut, assert(i.x() + back_offset < result.vertices.size()); assert(i.y() + back_offset < result.vertices.size()); assert(i.z() + back_offset < result.vertices.size()); - assert(i.x() >= 0 && i.x() < cut.vertices.size()); - assert(i.y() >= 0 && i.y() < cut.vertices.size()); - assert(i.z() >= 0 && i.z() < cut.vertices.size()); + assert(i.x() >= 0 && i.x() < static_cast(cut.vertices.size())); + assert(i.y() >= 0 && i.y() < static_cast(cut.vertices.size())); + assert(i.z() >= 0 && i.z() < static_cast(cut.vertices.size())); // Y and Z is swapped CCW triangles for back side result.indices.emplace_back(i.x() + back_offset, i.z() + back_offset, diff --git a/src/libvgcode/src/ShadersES.hpp b/src/libvgcode/src/ShadersES.hpp index e688fa7b4c6..76c9844c5ac 100644 --- a/src/libvgcode/src/ShadersES.hpp +++ b/src/libvgcode/src/ShadersES.hpp @@ -10,219 +10,219 @@ namespace libvgcode { -static const char* Segments_Vertex_Shader_ES = -"#version 300 es\n" -"precision lowp usampler2D;\n" -"#define POINTY_CAPS\n" -"#define FIX_TWISTING\n" -"const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);\n" -"const float light_top_diffuse = 0.6 * 0.8;\n" -"const float light_top_specular = 0.6 * 0.125;\n" -"const float light_top_shininess = 20.0;\n" -"const vec3 light_front_dir = vec3(0.6985074, 0.1397015, 0.6985074);\n" -"const float light_front_diffuse = 0.6 * 0.3;\n" -"const float ambient = 0.3;\n" -"const float emission = 0.15;\n" -"const vec3 UP = vec3(0, 0, 1);\n" -"uniform mat4 view_matrix;\n" -"uniform mat4 projection_matrix;\n" -"uniform vec3 camera_position;\n" -"uniform sampler2D position_tex;\n" -"uniform sampler2D height_width_angle_tex;\n" -"uniform sampler2D color_tex;\n" -"uniform usampler2D segment_index_tex;\n" -"in float vertex_id_float;\n" -"out vec3 color;\n" -"vec3 decode_color(float color) {\n" -" int c = int(round(color));\n" -" int r = (c >> 16) & 0xFF;\n" -" int g = (c >> 8) & 0xFF;\n" -" int b = (c >> 0) & 0xFF;\n" -" float f = 1.0 / 255.0f;\n" -" return f * vec3(r, g, b);\n" -"}\n" -"float lighting(vec3 eye_position, vec3 eye_normal) {\n" -" float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" -" float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" -" float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" -" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" -"}\n" -"ivec2 tex_coord(sampler2D sampler, int id) {\n" -" ivec2 tex_size = textureSize(sampler, 0);\n" -" return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" -"}\n" -"ivec2 tex_coord_u(usampler2D sampler, int id) {\n" -" ivec2 tex_size = textureSize(sampler, 0);\n" -" return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" -"}\n" -"void main() {\n" -" int vertex_id = int(vertex_id_float);\n" -" int id_a = int(texelFetch(segment_index_tex, tex_coord_u(segment_index_tex, gl_InstanceID), 0).r);\n" -" int id_b = id_a + 1;\n" -" vec3 pos_a = texelFetch(position_tex, tex_coord(position_tex, id_a), 0).xyz;\n" -" vec3 pos_b = texelFetch(position_tex, tex_coord(position_tex, id_b), 0).xyz;\n" -" vec3 line = pos_b - pos_a;\n" -" // directions of the line box in world space\n" -" float line_len = length(line);\n" -" vec3 line_dir;\n" -" if (line_len < 1e-4)\n" -" line_dir = vec3(1.0, 0.0, 0.0);\n" -" else\n" -" line_dir = line / line_len;\n" -" vec3 line_right_dir;\n" -" if (abs(dot(line_dir, UP)) > 0.9) {\n" -" // For vertical lines, the width and height should be same, there is no concept of up and down.\n" -" // For simplicity, the code will expand width in the x axis, and height in the y axis\n" -" line_right_dir = normalize(cross(vec3(1, 0, 0), line_dir));\n" -" }\n" -" else\n" -" line_right_dir = normalize(cross(line_dir, UP));\n" -" vec3 line_up_dir = normalize(cross(line_right_dir, line_dir));\n" -" const vec2 horizontal_vertical_view_signs_array[16] = vec2[](\n" -" //horizontal view (from right)\n" -" vec2(1.0, 0.0),\n" -" vec2(0.0, 1.0),\n" -" vec2(0.0, 0.0),\n" -" vec2(0.0, -1.0),\n" -" vec2(0.0, -1.0),\n" -" vec2(1.0, 0.0),\n" -" vec2(0.0, 1.0),\n" -" vec2(0.0, 0.0),\n" -" // vertical view (from top)\n" -" vec2(0.0, 1.0),\n" -" vec2(-1.0, 0.0),\n" -" vec2(0.0, 0.0),\n" -" vec2(1.0, 0.0),\n" -" vec2(1.0, 0.0),\n" -" vec2(0.0, 1.0),\n" -" vec2(-1.0, 0.0),\n" -" vec2(0.0, 0.0)\n" -" );\n" -" int id = vertex_id < 4 ? id_a : id_b;\n" -" vec3 endpoint_pos = vertex_id < 4 ? pos_a : pos_b;\n" -" vec3 height_width_angle = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, id), 0).xyz;\n" -"#ifdef FIX_TWISTING\n" -" int closer_id = (dot(camera_position - pos_a, camera_position - pos_a) < dot(camera_position - pos_b, camera_position - pos_b)) ? id_a : id_b;\n" -" vec3 closer_pos = (closer_id == id_a) ? pos_a : pos_b;\n" -" vec3 camera_view_dir = normalize(closer_pos - camera_position);\n" -" vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, closer_id), 0).xyz;\n" -" vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);\n" -"#else\n" -" vec3 camera_view_dir = normalize(endpoint_pos - camera_position);\n" -" vec3 diagonal_dir_border = normalize(height_width_angle.x * line_up_dir + height_width_angle.y * line_right_dir);\n" -"#endif\n" -" bool is_vertical_view = abs(dot(camera_view_dir, line_up_dir)) / abs(dot(diagonal_dir_border, line_up_dir)) >\n" -" abs(dot(camera_view_dir, line_right_dir)) / abs(dot(diagonal_dir_border, line_right_dir));\n" -" vec2 signs = horizontal_vertical_view_signs_array[vertex_id + 8 * int(is_vertical_view)];\n" -"#ifndef POINTY_CAPS\n" -" if (vertex_id == 2 || vertex_id == 7) signs = -horizontal_vertical_view_signs_array[(vertex_id - 2) + 8 * int(is_vertical_view)];\n" -"#endif\n" -" float view_right_sign = sign(dot(-camera_view_dir, line_right_dir));\n" -" float view_top_sign = sign(dot(-camera_view_dir, line_up_dir));\n" -" float half_height = 0.5 * height_width_angle.x;\n" -" float half_width = 0.5 * height_width_angle.y;\n" -" vec3 horizontal_dir = half_width * line_right_dir;\n" -" vec3 vertical_dir = half_height * line_up_dir;\n" -" float horizontal_sign = signs.x * view_right_sign;\n" -" float vertical_sign = signs.y * view_top_sign;\n" -" vec3 pos = endpoint_pos + horizontal_sign * horizontal_dir + vertical_sign * vertical_dir;\n" -" if (vertex_id == 2 || vertex_id == 7) {\n" -" float line_dir_sign = (vertex_id == 2) ? -1.0 : 1.0;\n" -" if (height_width_angle.z == 0.0) {\n" -"#ifdef POINTY_CAPS\n" -" // There I add a cap to lines that do not have a following line\n" -" // (or they have one, but perfectly aligned, so the cap is hidden inside the next line).\n" -" pos += line_dir_sign * line_dir * half_width;\n" -"#endif\n" -" }\n" -" else {\n" -" pos += line_dir_sign * line_dir * half_width * sin(abs(height_width_angle.z) * 0.5);\n" -" pos += sign(height_width_angle.z) * horizontal_dir * cos(abs(height_width_angle.z) * 0.5);\n" -" }\n" -" }\n" -" vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\n" -" vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;\n" -" vec3 color_base = decode_color(texelFetch(color_tex, tex_coord(color_tex, id), 0).r);\n" -" color = color_base * lighting(eye_position, eye_normal);\n" -" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" -"}\n"; +// static const char* Segments_Vertex_Shader_ES = +// "#version 300 es\n" +// "precision lowp usampler2D;\n" +// "#define POINTY_CAPS\n" +// "#define FIX_TWISTING\n" +// "const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);\n" +// "const float light_top_diffuse = 0.6 * 0.8;\n" +// "const float light_top_specular = 0.6 * 0.125;\n" +// "const float light_top_shininess = 20.0;\n" +// "const vec3 light_front_dir = vec3(0.6985074, 0.1397015, 0.6985074);\n" +// "const float light_front_diffuse = 0.6 * 0.3;\n" +// "const float ambient = 0.3;\n" +// "const float emission = 0.15;\n" +// "const vec3 UP = vec3(0, 0, 1);\n" +// "uniform mat4 view_matrix;\n" +// "uniform mat4 projection_matrix;\n" +// "uniform vec3 camera_position;\n" +// "uniform sampler2D position_tex;\n" +// "uniform sampler2D height_width_angle_tex;\n" +// "uniform sampler2D color_tex;\n" +// "uniform usampler2D segment_index_tex;\n" +// "in float vertex_id_float;\n" +// "out vec3 color;\n" +// "vec3 decode_color(float color) {\n" +// " int c = int(round(color));\n" +// " int r = (c >> 16) & 0xFF;\n" +// " int g = (c >> 8) & 0xFF;\n" +// " int b = (c >> 0) & 0xFF;\n" +// " float f = 1.0 / 255.0f;\n" +// " return f * vec3(r, g, b);\n" +// "}\n" +// "float lighting(vec3 eye_position, vec3 eye_normal) {\n" +// " float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" +// " float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" +// " float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" +// " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" +// "}\n" +// "ivec2 tex_coord(sampler2D sampler, int id) {\n" +// " ivec2 tex_size = textureSize(sampler, 0);\n" +// " return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" +// "}\n" +// "ivec2 tex_coord_u(usampler2D sampler, int id) {\n" +// " ivec2 tex_size = textureSize(sampler, 0);\n" +// " return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" +// "}\n" +// "void main() {\n" +// " int vertex_id = int(vertex_id_float);\n" +// " int id_a = int(texelFetch(segment_index_tex, tex_coord_u(segment_index_tex, gl_InstanceID), 0).r);\n" +// " int id_b = id_a + 1;\n" +// " vec3 pos_a = texelFetch(position_tex, tex_coord(position_tex, id_a), 0).xyz;\n" +// " vec3 pos_b = texelFetch(position_tex, tex_coord(position_tex, id_b), 0).xyz;\n" +// " vec3 line = pos_b - pos_a;\n" +// " // directions of the line box in world space\n" +// " float line_len = length(line);\n" +// " vec3 line_dir;\n" +// " if (line_len < 1e-4)\n" +// " line_dir = vec3(1.0, 0.0, 0.0);\n" +// " else\n" +// " line_dir = line / line_len;\n" +// " vec3 line_right_dir;\n" +// " if (abs(dot(line_dir, UP)) > 0.9) {\n" +// " // For vertical lines, the width and height should be same, there is no concept of up and down.\n" +// " // For simplicity, the code will expand width in the x axis, and height in the y axis\n" +// " line_right_dir = normalize(cross(vec3(1, 0, 0), line_dir));\n" +// " }\n" +// " else\n" +// " line_right_dir = normalize(cross(line_dir, UP));\n" +// " vec3 line_up_dir = normalize(cross(line_right_dir, line_dir));\n" +// " const vec2 horizontal_vertical_view_signs_array[16] = vec2[](\n" +// " //horizontal view (from right)\n" +// " vec2(1.0, 0.0),\n" +// " vec2(0.0, 1.0),\n" +// " vec2(0.0, 0.0),\n" +// " vec2(0.0, -1.0),\n" +// " vec2(0.0, -1.0),\n" +// " vec2(1.0, 0.0),\n" +// " vec2(0.0, 1.0),\n" +// " vec2(0.0, 0.0),\n" +// " // vertical view (from top)\n" +// " vec2(0.0, 1.0),\n" +// " vec2(-1.0, 0.0),\n" +// " vec2(0.0, 0.0),\n" +// " vec2(1.0, 0.0),\n" +// " vec2(1.0, 0.0),\n" +// " vec2(0.0, 1.0),\n" +// " vec2(-1.0, 0.0),\n" +// " vec2(0.0, 0.0)\n" +// " );\n" +// " int id = vertex_id < 4 ? id_a : id_b;\n" +// " vec3 endpoint_pos = vertex_id < 4 ? pos_a : pos_b;\n" +// " vec3 height_width_angle = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, id), 0).xyz;\n" +// "#ifdef FIX_TWISTING\n" +// " int closer_id = (dot(camera_position - pos_a, camera_position - pos_a) < dot(camera_position - pos_b, camera_position - pos_b)) ? id_a : id_b;\n" +// " vec3 closer_pos = (closer_id == id_a) ? pos_a : pos_b;\n" +// " vec3 camera_view_dir = normalize(closer_pos - camera_position);\n" +// " vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, closer_id), 0).xyz;\n" +// " vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);\n" +// "#else\n" +// " vec3 camera_view_dir = normalize(endpoint_pos - camera_position);\n" +// " vec3 diagonal_dir_border = normalize(height_width_angle.x * line_up_dir + height_width_angle.y * line_right_dir);\n" +// "#endif\n" +// " bool is_vertical_view = abs(dot(camera_view_dir, line_up_dir)) / abs(dot(diagonal_dir_border, line_up_dir)) >\n" +// " abs(dot(camera_view_dir, line_right_dir)) / abs(dot(diagonal_dir_border, line_right_dir));\n" +// " vec2 signs = horizontal_vertical_view_signs_array[vertex_id + 8 * int(is_vertical_view)];\n" +// "#ifndef POINTY_CAPS\n" +// " if (vertex_id == 2 || vertex_id == 7) signs = -horizontal_vertical_view_signs_array[(vertex_id - 2) + 8 * int(is_vertical_view)];\n" +// "#endif\n" +// " float view_right_sign = sign(dot(-camera_view_dir, line_right_dir));\n" +// " float view_top_sign = sign(dot(-camera_view_dir, line_up_dir));\n" +// " float half_height = 0.5 * height_width_angle.x;\n" +// " float half_width = 0.5 * height_width_angle.y;\n" +// " vec3 horizontal_dir = half_width * line_right_dir;\n" +// " vec3 vertical_dir = half_height * line_up_dir;\n" +// " float horizontal_sign = signs.x * view_right_sign;\n" +// " float vertical_sign = signs.y * view_top_sign;\n" +// " vec3 pos = endpoint_pos + horizontal_sign * horizontal_dir + vertical_sign * vertical_dir;\n" +// " if (vertex_id == 2 || vertex_id == 7) {\n" +// " float line_dir_sign = (vertex_id == 2) ? -1.0 : 1.0;\n" +// " if (height_width_angle.z == 0.0) {\n" +// "#ifdef POINTY_CAPS\n" +// " // There I add a cap to lines that do not have a following line\n" +// " // (or they have one, but perfectly aligned, so the cap is hidden inside the next line).\n" +// " pos += line_dir_sign * line_dir * half_width;\n" +// "#endif\n" +// " }\n" +// " else {\n" +// " pos += line_dir_sign * line_dir * half_width * sin(abs(height_width_angle.z) * 0.5);\n" +// " pos += sign(height_width_angle.z) * horizontal_dir * cos(abs(height_width_angle.z) * 0.5);\n" +// " }\n" +// " }\n" +// " vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\n" +// " vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;\n" +// " vec3 color_base = decode_color(texelFetch(color_tex, tex_coord(color_tex, id), 0).r);\n" +// " color = color_base * lighting(eye_position, eye_normal);\n" +// " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" +// "}\n"; -static const char* Segments_Fragment_Shader_ES = -"#version 300 es\n" -"precision highp float;\n" -"in vec3 color;\n" -"out vec4 fragment_color;\n" -"void main() {\n" -" fragment_color = vec4(color, 1.0);\n" -"}\n"; +// static const char* Segments_Fragment_Shader_ES = +// "#version 300 es\n" +// "precision highp float;\n" +// "in vec3 color;\n" +// "out vec4 fragment_color;\n" +// "void main() {\n" +// " fragment_color = vec4(color, 1.0);\n" +// "}\n"; -static const char* Options_Vertex_Shader_ES = -"#version 300 es\n" -"precision lowp usampler2D;\n" -"const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);\n" -"const float light_top_diffuse = 0.6 * 0.8;\n" -"const float light_top_specular = 0.6 * 0.125;\n" -"const float light_top_shininess = 20.0;\n" -"const vec3 light_front_dir = vec3(0.6985074, 0.1397015, 0.6985074);\n" -"const float light_front_diffuse = 0.6 * 0.3;\n" -"const float ambient = 0.3;\n" -"const float emission = 0.25;\n" -"const float scaling_factor = 1.5;\n" -"uniform mat4 view_matrix;\n" -"uniform mat4 projection_matrix;\n" -"uniform sampler2D position_tex;\n" -"uniform sampler2D height_width_angle_tex;\n" -"uniform sampler2D color_tex;\n" -"uniform usampler2D segment_index_tex;\n" -"in vec3 in_position;\n" -"in vec3 in_normal;\n" -"out vec3 color;\n" -"vec3 decode_color(float color) {\n" -" int c = int(round(color));\n" -" int r = (c >> 16) & 0xFF;\n" -" int g = (c >> 8) & 0xFF;\n" -" int b = (c >> 0) & 0xFF;\n" -" float f = 1.0 / 255.0f;\n" -" return f * vec3(r, g, b);\n" -"}\n" -"float lighting(vec3 eye_position, vec3 eye_normal) {\n" -" float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" -" float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" -" float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" -" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" -"}\n" -"ivec2 tex_coord(sampler2D sampler, int id) {\n" -" ivec2 tex_size = textureSize(sampler, 0);\n" -" return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" -"}\n" -"ivec2 tex_coord_u(usampler2D sampler, int id) {\n" -" ivec2 tex_size = textureSize(sampler, 0);\n" -" return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" -"}\n" -"void main() {\n" -" int id = int(texelFetch(segment_index_tex, tex_coord_u(segment_index_tex, gl_InstanceID), 0).r);\n" -" vec2 height_width = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, id), 0).xy;\n" -" vec3 offset = texelFetch(position_tex, tex_coord(position_tex, id), 0).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n" -" height_width *= scaling_factor;\n" -" mat3 scale_matrix = mat3(\n" -" height_width.y, 0.0, 0.0,\n" -" 0.0, height_width.y, 0.0,\n" -" 0.0, 0.0, height_width.x);\n" -" vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\n" -" vec3 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n" -" vec3 color_base = decode_color(texelFetch(color_tex, tex_coord(color_tex, id), 0).r);\n" -" color = color_base * lighting(eye_position, eye_normal);\n" -" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" -"}\n"; +// static const char* Options_Vertex_Shader_ES = +// "#version 300 es\n" +// "precision lowp usampler2D;\n" +// "const vec3 light_top_dir = vec3(-0.4574957, 0.4574957, 0.7624929);\n" +// "const float light_top_diffuse = 0.6 * 0.8;\n" +// "const float light_top_specular = 0.6 * 0.125;\n" +// "const float light_top_shininess = 20.0;\n" +// "const vec3 light_front_dir = vec3(0.6985074, 0.1397015, 0.6985074);\n" +// "const float light_front_diffuse = 0.6 * 0.3;\n" +// "const float ambient = 0.3;\n" +// "const float emission = 0.25;\n" +// "const float scaling_factor = 1.5;\n" +// "uniform mat4 view_matrix;\n" +// "uniform mat4 projection_matrix;\n" +// "uniform sampler2D position_tex;\n" +// "uniform sampler2D height_width_angle_tex;\n" +// "uniform sampler2D color_tex;\n" +// "uniform usampler2D segment_index_tex;\n" +// "in vec3 in_position;\n" +// "in vec3 in_normal;\n" +// "out vec3 color;\n" +// "vec3 decode_color(float color) {\n" +// " int c = int(round(color));\n" +// " int r = (c >> 16) & 0xFF;\n" +// " int g = (c >> 8) & 0xFF;\n" +// " int b = (c >> 0) & 0xFF;\n" +// " float f = 1.0 / 255.0f;\n" +// " return f * vec3(r, g, b);\n" +// "}\n" +// "float lighting(vec3 eye_position, vec3 eye_normal) {\n" +// " float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" +// " float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" +// " float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" +// " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" +// "}\n" +// "ivec2 tex_coord(sampler2D sampler, int id) {\n" +// " ivec2 tex_size = textureSize(sampler, 0);\n" +// " return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" +// "}\n" +// "ivec2 tex_coord_u(usampler2D sampler, int id) {\n" +// " ivec2 tex_size = textureSize(sampler, 0);\n" +// " return (tex_size.y == 1) ? ivec2(id, 0) : ivec2(id % tex_size.x, id / tex_size.x);\n" +// "}\n" +// "void main() {\n" +// " int id = int(texelFetch(segment_index_tex, tex_coord_u(segment_index_tex, gl_InstanceID), 0).r);\n" +// " vec2 height_width = texelFetch(height_width_angle_tex, tex_coord(height_width_angle_tex, id), 0).xy;\n" +// " vec3 offset = texelFetch(position_tex, tex_coord(position_tex, id), 0).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n" +// " height_width *= scaling_factor;\n" +// " mat3 scale_matrix = mat3(\n" +// " height_width.y, 0.0, 0.0,\n" +// " 0.0, height_width.y, 0.0,\n" +// " 0.0, 0.0, height_width.x);\n" +// " vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\n" +// " vec3 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n" +// " vec3 color_base = decode_color(texelFetch(color_tex, tex_coord(color_tex, id), 0).r);\n" +// " color = color_base * lighting(eye_position, eye_normal);\n" +// " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" +// "}\n"; -static const char* Options_Fragment_Shader_ES = -"#version 300 es\n" -"precision highp float;\n" -"in vec3 color;\n" -"out vec4 fragment_color;\n" -"void main() {\n" -" fragment_color = vec4(color, 1.0);\n" -"}\n"; +// static const char* Options_Fragment_Shader_ES = +// "#version 300 es\n" +// "precision highp float;\n" +// "in vec3 color;\n" +// "out vec4 fragment_color;\n" +// "void main() {\n" +// " fragment_color = vec4(color, 1.0);\n" +// "}\n"; #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS static const char* Cog_Marker_Vertex_Shader_ES = diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index e2a0093da59..504f9b2a62b 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -186,7 +186,7 @@ static Mat4x4 inverse(const Mat4x4& m) det = 1.0f / det; std::array ret = {}; - for (int i = 0; i < 16; ++i) { + for (size_t i = 0; i < 16; ++i) { ret[i] = inv[i] * det; } @@ -1888,7 +1888,7 @@ void ViewerImpl::render_segments(const Mat4x4& view_matrix, const Mat4x4& projec } #else std::array curr_bound_texture = { 0, 0, 0, 0 }; - for (int i = 0; i < curr_bound_texture.size(); ++i) { + for (size_t i = 0; i < curr_bound_texture.size(); ++i) { glsafe(glActiveTexture(GL_TEXTURE0 + i)); glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture[i])); //assert(curr_bound_texture[i] == 0); @@ -1917,7 +1917,7 @@ void ViewerImpl::render_segments(const Mat4x4& view_matrix, const Mat4x4& projec #ifdef ENABLE_OPENGL_ES glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture)); #else - for (int i = 0; i < curr_bound_texture.size(); ++i) { + for (size_t i = 0; i < curr_bound_texture.size(); ++i) { glsafe(glActiveTexture(GL_TEXTURE0 + i)); glsafe(glBindTexture(GL_TEXTURE_BUFFER, curr_bound_texture[i])); } @@ -1975,7 +1975,7 @@ void ViewerImpl::render_options(const Mat4x4& view_matrix, const Mat4x4& project } #else std::array curr_bound_texture = { 0, 0, 0, 0 }; - for (int i = 0; i < curr_bound_texture.size(); ++i) { + for (size_t i = 0; i < curr_bound_texture.size(); ++i) { glsafe(glActiveTexture(GL_TEXTURE0 + i)); glsafe(glGetIntegerv(GL_TEXTURE_BINDING_BUFFER, &curr_bound_texture[i])); //assert(curr_bound_texture[i] == 0); @@ -2004,7 +2004,7 @@ void ViewerImpl::render_options(const Mat4x4& view_matrix, const Mat4x4& project #ifdef ENABLE_OPENGL_ES glsafe(glBindTexture(GL_TEXTURE_2D, curr_bound_texture)); #else - for (int i = 0; i < curr_bound_texture.size(); ++i) { + for (size_t i = 0; i < curr_bound_texture.size(); ++i) { glsafe(glActiveTexture(GL_TEXTURE0 + i)); glsafe(glBindTexture(GL_TEXTURE_BUFFER, curr_bound_texture[i])); }