Skip to content

Commit 0559249

Browse files
committed
wgpu.Instance.CreateSurface: require Canvas to be passed in on web, since Cogent Core must now have control over its creation
1 parent 15b811c commit 0559249

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

wgpu/instance_js.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@ func (g Instance) EnumerateAdapters(options *InstanceEnumerateAdapterOptons) []*
4141
return []*Adapter{a}
4242
}
4343

44+
// SurfaceDescriptor must contain a valid HTML canvas element on web.
4445
type SurfaceDescriptor struct {
46+
// Canvas must be specified.
47+
Canvas js.Value
48+
4549
Label string
4650
}
4751

4852
func (g Instance) CreateSurface(descriptor *SurfaceDescriptor) *Surface {
49-
jsContext := js.Global().Get("document").Call("querySelector", "canvas").Call("getContext", "webgpu")
53+
if descriptor.Canvas.IsUndefined() {
54+
panic("wgpu.Instance.CreateSurface: descriptor.Canvas must be specified")
55+
}
56+
jsContext := descriptor.Canvas.Call("getContext", "webgpu")
5057
return &Surface{jsContext}
5158
}
5259

0 commit comments

Comments
 (0)