From f4356b98d2041d8188ae61d1025a98db7becdee0 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 6 Oct 2023 17:41:15 -0400 Subject: display: WIP: Refactor into files; use wishes, not Display:: Expose shader stuff to user programs for the first time. Mostly works, but display thread and main thread run much slower (28fps display, 70fps main). Also introduce dict getwithdefault (helpful for rest options). --- virtual-programs/display/stroke.folk | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 virtual-programs/display/stroke.folk (limited to 'virtual-programs/display/stroke.folk') diff --git a/virtual-programs/display/stroke.folk b/virtual-programs/display/stroke.folk new file mode 100644 index 00000000..98eec038 --- /dev/null +++ b/virtual-programs/display/stroke.folk @@ -0,0 +1,33 @@ +Wish the GPU compiles pipeline "line" { + {vec2 from vec2 to float thickness vec4 color} { + vec2 vertices[4] = vec2[4]( + min(from, to) - thickness, + vec2(max(from.x, to.x) + thickness, min(from.y, to.y) - thickness), + vec2(min(from.x, to.x) - thickness, max(from.y, to.y) + thickness), + max(from, to) + thickness + ); + return vertices[gl_VertexIndex]; + } { + float l = length(to - from); + vec2 d = (to - from) / l; + vec2 q = (gl_FragCoord.xy - (from + to)*0.5); + q = mat2(d.x, -d.y, d.y, d.x) * q; + q = abs(q) - vec2(l, thickness)*0.5; + float dist = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0); + + return dist < 0.0 ? color : vec4(0, 0, 0, 0); + } +} + +When /someone/ wishes to draw a stroke with /...options/ { + set points [dict get $options points] + set width [dict get $options width] + set color [getColor [dict get $options color]] + + for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} { + set from [lindex $points $i] + set to [lindex $points [expr $i+1]] + Wish the GPU draws pipeline "line" with arguments \ + [list $from $to $width $color] + } +} -- cgit v1.2.3 From df52094ecdb6cb3dc6e70e15c3ec7f14909e30fe Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Fri, 13 Oct 2023 20:24:08 -0400 Subject: stroke: Use instances. Idk if this helps much --- virtual-programs/display/stroke.folk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'virtual-programs/display/stroke.folk') diff --git a/virtual-programs/display/stroke.folk b/virtual-programs/display/stroke.folk index 98eec038..f212f471 100644 --- a/virtual-programs/display/stroke.folk +++ b/virtual-programs/display/stroke.folk @@ -24,10 +24,11 @@ When /someone/ wishes to draw a stroke with /...options/ { set width [dict get $options width] set color [getColor [dict get $options color]] + set instances [list] for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} { set from [lindex $points $i] set to [lindex $points [expr $i+1]] - Wish the GPU draws pipeline "line" with arguments \ - [list $from $to $width $color] + lappend instances [list $from $to $width $color] } + Wish the GPU draws pipeline "line" with instances $instances } -- cgit v1.2.3