Wish the GPU compiles pipeline "fillTriangle" { {vec2 p0 vec2 p1 vec2 p2 vec4 color} { vec2 vertices[4] = vec2[4](p0, p1, p2, p0); return vertices[gl_VertexIndex]; } { return color; } } When /someone/ wishes to draw a triangle with /...options/ { dict with options { Wish the GPU draws pipeline "fillTriangle" with arguments \ [list $p0 $p1 $p2 [getColor $color]] } } When /someone/ wishes to draw a quad with /...options/ { dict with options { if {![info exists layer]} { set layer 0 } Wish the GPU draws pipeline "fillTriangle" with arguments \ [list $p1 $p2 $p3 [getColor $color]] layer $layer Wish the GPU draws pipeline "fillTriangle" with arguments \ [list $p0 $p1 $p3 [getColor $color]] layer $layer } } When /someone/ wishes to draw a polygon with /...options/ { set points [dict get $options points] set color [dict get $options color] set num_points [llength $points] if {$num_points < 3} { error "At least 3 points are required to form a polygon." } elseif {$num_points == 3} { Wish to draw a triangle with \ p0 [lindex $points 0] p1 [lindex $points 1] p2 [lindex $points 2] \ color $color } elseif {$num_points == 4} { Wish to draw a quad with \ p0 [lindex $points 0] p1 [lindex $points 1] p2 [lindex $points 2] p3 [lindex $points 3] \ color $color } else { # Get the first point in the list as the "base" point of the triangles set p0 [lindex $points 0] for {set i 1} {$i < $num_points - 1} {incr i} { set p1 [lindex $points $i] set p2 [lindex $points [expr {$i+1}]] Wish the GPU draws pipeline "fillTriangle" with arguments \ [list $p0 $p1 $p2 [getColor $color]] } } }