summaryrefslogtreecommitdiffstats
path: root/virtual-programs
diff options
context:
space:
mode:
authorOmar Rizwan <omar@omar.website>2023-09-16 01:36:42 +0000
committerOmar Rizwan <omar@omar.website>2023-09-16 01:36:42 +0000
commitf7eb36e51fab7abd5ebc74dce9419d01e4a1dfa7 (patch)
tree60cd62567312188e2dc28f5d9a733958edad7201 /virtual-programs
parentWIP: Stub in GPU into Folk. Doesn't draw yet (diff)
downloadfolk-f7eb36e51fab7abd5ebc74dce9419d01e4a1dfa7.tar.gz
folk-f7eb36e51fab7abd5ebc74dce9419d01e4a1dfa7.zip
display: Add basic stroke support
Diffstat (limited to 'virtual-programs')
-rw-r--r--virtual-programs/display.folk23
1 files changed, 20 insertions, 3 deletions
diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk
index 7d4f47b6..c9c172cc 100644
--- a/virtual-programs/display.folk
+++ b/virtual-programs/display.folk
@@ -40,12 +40,29 @@ namespace eval ::Display {
On process {
source pi/Gpu.tcl
Gpu::init
+ Gpu::ImageManager::imageManagerInit
namespace eval Display {
- proc start {} {}
+ variable line [Gpu::pipeline {vec2 from vec2 to float thickness} {
+ 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 ? vec4(1, 0, 1, 1) : vec4(0, 0, 0, 0);
+ }]
- proc stroke {points width color} {
+ proc start {} { Gpu::drawStart }
+ proc stroke {points width color} {
+ variable line
+ for {set i 0} {$i < [expr {[llength $points] - 1}]} {incr i} {
+ set from [lindex $points $i]
+ set to [lindex $points [expr $i+1]]
+ Gpu::draw $line $from $to $width
+ }
}
proc circle {x y radius thickness color} {}
proc text {x y scale text radians} {}
@@ -54,7 +71,7 @@ On process {
proc fillPolygon {args} {}
proc image {x y im radians {scale 1.0}} {}
- proc end {} {}
+ proc end {} { Gpu::drawEnd }
}
puts "Display tid: [getTid]"