-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathjs.go
More file actions
39 lines (31 loc) · 774 Bytes
/
js.go
File metadata and controls
39 lines (31 loc) · 774 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//go:build js
package main
import (
"syscall/js"
"time"
"github.com/cogentcore/webgpu/wgpu"
)
type window struct{}
func (w window) GetSize() (int, int) {
vv := js.Global().Get("visualViewport")
return vv.Get("width").Int(), vv.Get("height").Int()
}
func main() {
document := js.Global().Get("document")
canvas := document.Call("createElement", "canvas")
document.Get("body").Call("appendChild", canvas)
w := &window{}
width, height := w.GetSize()
canvas.Set("width", width)
canvas.Set("height", height)
canvas.Set("style", "width:100vw; height:100vh")
s, err := InitState(w, &wgpu.SurfaceDescriptor{Canvas: canvas})
if err != nil {
panic(err)
}
defer s.Destroy()
ticker := time.NewTicker(time.Second / 30)
for range ticker.C {
s.Render()
}
}