MCPcopy Create free account
hub / github.com/VictorGordan/opengl-tutorials / AddPolyline

Method AddPolyline

ImGUI GLFW Tutorial/imgui/imgui_draw.cpp:703–956  ·  view source on GitHub ↗

TODO: Thickness anti-aliased lines cap are missing their AA fringe. We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds.

Source from the content-addressed store, hash-verified

701// TODO: Thickness anti-aliased lines cap are missing their AA fringe.
702// We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds.
703void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, ImDrawFlags flags, float thickness)
704{
705 if (points_count < 2)
706 return;
707
708 const bool closed = (flags & ImDrawFlags_Closed) != 0;
709 const ImVec2 opaque_uv = _Data->TexUvWhitePixel;
710 const int count = closed ? points_count : points_count - 1; // The number of line segments we need to draw
711 const bool thick_line = (thickness > _FringeScale);
712
713 if (Flags & ImDrawListFlags_AntiAliasedLines)
714 {
715 // Anti-aliased stroke
716 const float AA_SIZE = _FringeScale;
717 const ImU32 col_trans = col & ~IM_COL32_A_MASK;
718
719 // Thicknesses <1.0 should behave like thickness 1.0
720 thickness = ImMax(thickness, 1.0f);
721 const int integer_thickness = (int)thickness;
722 const float fractional_thickness = thickness - integer_thickness;
723
724 // Do we want to draw this line using a texture?
725 // - For now, only draw integer-width lines using textures to avoid issues with the way scaling occurs, could be improved.
726 // - If AA_SIZE is not 1.0f we cannot use the texture path.
727 const bool use_texture = (Flags & ImDrawListFlags_AntiAliasedLinesUseTex) && (integer_thickness < IM_DRAWLIST_TEX_LINES_WIDTH_MAX) && (fractional_thickness <= 0.00001f) && (AA_SIZE == 1.0f);
728
729 // We should never hit this, because NewFrame() doesn't set ImDrawListFlags_AntiAliasedLinesUseTex unless ImFontAtlasFlags_NoBakedLines is off
730 IM_ASSERT_PARANOID(!use_texture || !(_Data->Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedLines));
731
732 const int idx_count = use_texture ? (count * 6) : (thick_line ? count * 18 : count * 12);
733 const int vtx_count = use_texture ? (points_count * 2) : (thick_line ? points_count * 4 : points_count * 3);
734 PrimReserve(idx_count, vtx_count);
735
736 // Temporary buffer
737 // The first <points_count> items are normals at each line point, then after that there are either 2 or 4 temp points for each line point
738 ImVec2* temp_normals = (ImVec2*)alloca(points_count * ((use_texture || !thick_line) ? 3 : 5) * sizeof(ImVec2)); //-V630
739 ImVec2* temp_points = temp_normals + points_count;
740
741 // Calculate normals (tangents) for each line segment
742 for (int i1 = 0; i1 < count; i1++)
743 {
744 const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1;
745 float dx = points[i2].x - points[i1].x;
746 float dy = points[i2].y - points[i1].y;
747 IM_NORMALIZE2F_OVER_ZERO(dx, dy);
748 temp_normals[i1].x = dy;
749 temp_normals[i1].y = -dx;
750 }
751 if (!closed)
752 temp_normals[points_count - 1] = temp_normals[points_count - 2];
753
754 // If we are drawing a one-pixel-wide line without a texture, or a textured line of any width, we only need 2 or 3 vertices per point
755 if (use_texture || !thick_line)
756 {
757 // [PATH 1] Texture-based lines (thick or non-thick)
758 // [PATH 2] Non texture-based lines (non-thick)
759
760 // The width of the geometry we need to draw - this is essentially <thickness> pixels for the line itself, plus "one pixel" for AA.

Callers 2

DebugNodeDrawListMethod · 0.45

Calls 1

ImMaxFunction · 0.70

Tested by

no test coverage detected