Skip to content

Commit 962a3fe

Browse files
authored
Testing for CPU on CI; font, ellipse, scale2D fixes
* fix CPU ellipse; fix GPU vec2 ssbo; add polyssbo/translatemulti2d; 87% test coverage; * add gsdf.Builder to font config * update README * fix uninitialized Font crash; fix polygon self-closing case; admit multiple identical SSBOs; color conversion additions * rewrite tests to run on CPU; add Scale2D CPU evaluator; bump glgl version
1 parent 38ee365 commit 962a3fe

File tree

6 files changed

+750
-685
lines changed

6 files changed

+750
-685
lines changed

cpu_evaluators.go

+23
Original file line numberDiff line numberDiff line change
@@ -1078,3 +1078,26 @@ func (c *rotation2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error
10781078
err = sdf.Evaluate(posTransf, dist, userData)
10791079
return err
10801080
}
1081+
1082+
func (c *scale2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error {
1083+
sdf, err := gleval.AssertSDF2(c.s)
1084+
if err != nil {
1085+
return err
1086+
}
1087+
vp, err := gleval.GetVecPool(userData)
1088+
if err != nil {
1089+
return err
1090+
}
1091+
posTransf := vp.V2.Acquire(len(pos))
1092+
defer vp.V2.Release(posTransf)
1093+
invScale := 1. / c.scale
1094+
for i, p := range pos {
1095+
posTransf[i] = ms2.Scale(invScale, p)
1096+
}
1097+
err = sdf.Evaluate(posTransf, dist, userData)
1098+
scale := c.scale
1099+
for i, d := range dist {
1100+
dist[i] = d * scale
1101+
}
1102+
return err
1103+
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71
88
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b
99
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
10-
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5
10+
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704
1111
golang.org/x/image v0.22.0
1212
)
1313

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
1010
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
1111
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5 h1:PyD0ceAopD2FDv3ddx99Q+h7QxIzDPPuOQiaZrRA7yU=
1212
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
13+
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704 h1:KU+Ofl/VEFFM/uNpDPu+2Ds8RrkJUu21Ef0klG7xK08=
14+
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
1315
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 h1:m9O6OTJ627iFnN2JIWfdqlZCzneRO6EEBsHXI25P8ws=
1416
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
1517
golang.org/x/image v0.22.0 h1:UtK5yLUzilVrkjMAZAZ34DXGpASN8i8pj8g+O+yd10g=

gsdf.go

+20-42
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package gsdf
22

33
import (
44
_ "embed"
5-
"encoding/binary"
65
"errors"
76
"fmt"
87
"unsafe"
@@ -134,16 +133,6 @@ func absf(a float32) float32 {
134133
return math32.Abs(a)
135134
}
136135

137-
func hashvec2(vecs ...ms2.Vec) float32 {
138-
var hashA float32 = 0.0
139-
var hashB float32 = 1.0
140-
for _, v := range vecs {
141-
hashA, hashB = hashAdd(hashA, hashB, v.X)
142-
hashA, hashB = hashAdd(hashA, hashB, v.Y)
143-
}
144-
return hashfint(hashA + hashB)
145-
}
146-
147136
func hash2vec2(vecs ...[2]ms2.Vec) float32 {
148137
var hashA float32 = 0.0
149138
var hashB float32 = 1.0
@@ -156,17 +145,6 @@ func hash2vec2(vecs ...[2]ms2.Vec) float32 {
156145
return hashfint(hashA + hashB)
157146
}
158147

159-
func hashvec3(vecs ...ms3.Vec) float32 {
160-
var hashA float32 = 0.0
161-
var hashB float32 = 1.0
162-
for _, v := range vecs {
163-
hashA, hashB = hashAdd(hashA, hashB, v.X)
164-
hashA, hashB = hashAdd(hashA, hashB, v.Y)
165-
hashA, hashB = hashAdd(hashA, hashB, v.Z)
166-
}
167-
return hashfint(hashA + hashB)
168-
}
169-
170148
func hashf(values []float32) float32 {
171149
var hashA float32 = 0.0
172150
var hashB float32 = 1.0
@@ -189,26 +167,26 @@ func hashfint(f float32) float32 {
189167
return float32(int(f*1000000)%1000000) / 1000000 // Keep within [0.0, 1.0)
190168
}
191169

192-
func hash(b []byte, in uint64) uint64 {
193-
x := in
194-
for len(b) >= 8 {
195-
x ^= binary.LittleEndian.Uint64(b)
196-
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
197-
x = (x ^ (x >> 27)) * 0x94d049bb133111eb
198-
x ^= x >> 31
199-
b = b[8:]
200-
201-
}
202-
if len(b) > 0 {
203-
var buf [8]byte
204-
copy(buf[:], b)
205-
x ^= binary.LittleEndian.Uint64(buf[:])
206-
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
207-
x = (x ^ (x >> 27)) * 0x94d049bb133111eb
208-
x ^= x >> 31
209-
}
210-
return x
211-
}
170+
// func hash(b []byte, in uint64) uint64 {
171+
// x := in
172+
// for len(b) >= 8 {
173+
// x ^= binary.LittleEndian.Uint64(b)
174+
// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
175+
// x = (x ^ (x >> 27)) * 0x94d049bb133111eb
176+
// x ^= x >> 31
177+
// b = b[8:]
178+
179+
// }
180+
// if len(b) > 0 {
181+
// var buf [8]byte
182+
// copy(buf[:], b)
183+
// x ^= binary.LittleEndian.Uint64(buf[:])
184+
// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
185+
// x = (x ^ (x >> 27)) * 0x94d049bb133111eb
186+
// x ^= x >> 31
187+
// }
188+
// return x
189+
// }
212190

213191
func hashshaderptr(s glbuild.Shader) uint64 {
214192
v := *(*[2]uintptr)(unsafe.Pointer(&s))

0 commit comments

Comments
 (0)