Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing, Font and Ellipse fixes #7

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cpu_evaluators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,3 +1078,26 @@ func (c *rotation2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error
err = sdf.Evaluate(posTransf, dist, userData)
return err
}

func (c *scale2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error {
sdf, err := gleval.AssertSDF2(c.s)
if err != nil {
return err
}
vp, err := gleval.GetVecPool(userData)
if err != nil {
return err
}
posTransf := vp.V2.Acquire(len(pos))
defer vp.V2.Release(posTransf)
invScale := 1. / c.scale
for i, p := range pos {
posTransf[i] = ms2.Scale(invScale, p)
}
err = sdf.Evaluate(posTransf, dist, userData)
scale := c.scale
for i, d := range dist {
dist[i] = d * scale
}
return err
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704
golang.org/x/image v0.22.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5 h1:PyD0ceAopD2FDv3ddx99Q+h7QxIzDPPuOQiaZrRA7yU=
github.com/soypat/glgl v0.0.0-20241124175250-a2463fe190a5/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704 h1:KU+Ofl/VEFFM/uNpDPu+2Ds8RrkJUu21Ef0klG7xK08=
github.com/soypat/glgl v0.0.0-20241218113040-663b03b49704/go.mod h1:1LcEp6XHSMCI91WlJHzl/aW4Bp5v6yQOiYFyjrlk350=
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30 h1:m9O6OTJ627iFnN2JIWfdqlZCzneRO6EEBsHXI25P8ws=
golang.org/x/exp v0.0.0-20221230185412-738e83a70c30/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/image v0.22.0 h1:UtK5yLUzilVrkjMAZAZ34DXGpASN8i8pj8g+O+yd10g=
Expand Down
62 changes: 20 additions & 42 deletions gsdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gsdf

import (
_ "embed"
"encoding/binary"
"errors"
"fmt"
"unsafe"
Expand Down Expand Up @@ -134,16 +133,6 @@ func absf(a float32) float32 {
return math32.Abs(a)
}

func hashvec2(vecs ...ms2.Vec) float32 {
var hashA float32 = 0.0
var hashB float32 = 1.0
for _, v := range vecs {
hashA, hashB = hashAdd(hashA, hashB, v.X)
hashA, hashB = hashAdd(hashA, hashB, v.Y)
}
return hashfint(hashA + hashB)
}

func hash2vec2(vecs ...[2]ms2.Vec) float32 {
var hashA float32 = 0.0
var hashB float32 = 1.0
Expand All @@ -156,17 +145,6 @@ func hash2vec2(vecs ...[2]ms2.Vec) float32 {
return hashfint(hashA + hashB)
}

func hashvec3(vecs ...ms3.Vec) float32 {
var hashA float32 = 0.0
var hashB float32 = 1.0
for _, v := range vecs {
hashA, hashB = hashAdd(hashA, hashB, v.X)
hashA, hashB = hashAdd(hashA, hashB, v.Y)
hashA, hashB = hashAdd(hashA, hashB, v.Z)
}
return hashfint(hashA + hashB)
}

func hashf(values []float32) float32 {
var hashA float32 = 0.0
var hashB float32 = 1.0
Expand All @@ -189,26 +167,26 @@ func hashfint(f float32) float32 {
return float32(int(f*1000000)%1000000) / 1000000 // Keep within [0.0, 1.0)
}

func hash(b []byte, in uint64) uint64 {
x := in
for len(b) >= 8 {
x ^= binary.LittleEndian.Uint64(b)
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
x = (x ^ (x >> 27)) * 0x94d049bb133111eb
x ^= x >> 31
b = b[8:]

}
if len(b) > 0 {
var buf [8]byte
copy(buf[:], b)
x ^= binary.LittleEndian.Uint64(buf[:])
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
x = (x ^ (x >> 27)) * 0x94d049bb133111eb
x ^= x >> 31
}
return x
}
// func hash(b []byte, in uint64) uint64 {
// x := in
// for len(b) >= 8 {
// x ^= binary.LittleEndian.Uint64(b)
// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
// x = (x ^ (x >> 27)) * 0x94d049bb133111eb
// x ^= x >> 31
// b = b[8:]

// }
// if len(b) > 0 {
// var buf [8]byte
// copy(buf[:], b)
// x ^= binary.LittleEndian.Uint64(buf[:])
// x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9
// x = (x ^ (x >> 27)) * 0x94d049bb133111eb
// x ^= x >> 31
// }
// return x
// }

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