MCPcopy Create free account
hub / github.com/brenocq/implot3d / RendererTriangleFill

Class RendererTriangleFill

implot3d_items.cpp:546–601  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544};
545
546template <class _Getter, class _GetterColor> struct RendererTriangleFill : RendererBase {
547 RendererTriangleFill(const _Getter& getter, const _GetterColor& col_getter)
548 : RendererBase(getter.Count / 3, 3, 3), Getter(getter), ColGetter(col_getter) {}
549
550 void Init(ImDrawList3D& draw_list_3d) const { UV = draw_list_3d._SharedData->TexUvWhitePixel; }
551
552 IMPLOT3D_INLINE bool Render(ImDrawList3D& draw_list_3d, const ImPlot3DBox& cull_box, int prim) const {
553 ImPlot3DPoint p_plot[3];
554 p_plot[0] = Getter(3 * prim);
555 p_plot[1] = Getter(3 * prim + 1);
556 p_plot[2] = Getter(3 * prim + 2);
557
558 // Check if the triangle is outside the culling box
559 if (!cull_box.Contains(p_plot[0]) && !cull_box.Contains(p_plot[1]) && !cull_box.Contains(p_plot[2]))
560 return false;
561
562 // Project the triangle vertices to screen space
563 ImVec2 p[3];
564 p[0] = PlotToPixels(p_plot[0]);
565 p[1] = PlotToPixels(p_plot[1]);
566 p[2] = PlotToPixels(p_plot[2]);
567
568 // 3 vertices per triangle
569 draw_list_3d._VtxWritePtr[0].pos.x = p[0].x;
570 draw_list_3d._VtxWritePtr[0].pos.y = p[0].y;
571 draw_list_3d._VtxWritePtr[0].uv = UV;
572 draw_list_3d._VtxWritePtr[0].col = ColGetter(3 * prim);
573 draw_list_3d._VtxWritePtr[1].pos.x = p[1].x;
574 draw_list_3d._VtxWritePtr[1].pos.y = p[1].y;
575 draw_list_3d._VtxWritePtr[1].uv = UV;
576 draw_list_3d._VtxWritePtr[1].col = ColGetter(3 * prim + 1);
577 draw_list_3d._VtxWritePtr[2].pos.x = p[2].x;
578 draw_list_3d._VtxWritePtr[2].pos.y = p[2].y;
579 draw_list_3d._VtxWritePtr[2].uv = UV;
580 draw_list_3d._VtxWritePtr[2].col = ColGetter(3 * prim + 2);
581 draw_list_3d._VtxWritePtr += 3;
582
583 // 3 indices per triangle
584 draw_list_3d._IdxWritePtr[0] = (ImDrawIdx)(draw_list_3d._VtxCurrentIdx);
585 draw_list_3d._IdxWritePtr[1] = (ImDrawIdx)(draw_list_3d._VtxCurrentIdx + 1);
586 draw_list_3d._IdxWritePtr[2] = (ImDrawIdx)(draw_list_3d._VtxCurrentIdx + 2);
587 draw_list_3d._IdxWritePtr += 3;
588 // 1 Z per vertex
589 draw_list_3d._ZWritePtr[0] = GetPointDepth((p_plot[0] + p_plot[1] + p_plot[2]) / 3);
590 draw_list_3d._ZWritePtr++;
591
592 // Update vertex count
593 draw_list_3d._VtxCurrentIdx += 3;
594
595 return true;
596 }
597
598 const _Getter& Getter;
599 const _GetterColor ColGetter;
600 mutable ImVec2 UV;
601};
602
603template <class _Getter, class _GetterColor> struct RendererQuadFill : RendererBase {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected