diff options
author | lawl <github@dumbinter.net> | 2022-01-06 10:44:13 +0200 |
---|---|---|
committer | lawl <github@dumbinter.net> | 2022-01-06 16:04:34 +0530 |
commit | 8c34658b64f1efeab501bef57d2bfa9579fe34e2 (patch) | |
tree | 3fef93871214bc85c89ffcd04c6782c8aa3862ce /vendor/gioui.org/app/gl_js.go | |
parent | 38787e4195f2a34d7ec4421caf17cb99bc31fa2b (diff) | |
download | noisetorch-8c34658b64f1efeab501bef57d2bfa9579fe34e2.tar.gz noisetorch-8c34658b64f1efeab501bef57d2bfa9579fe34e2.zip |
Chore: Upgrade nucular GUI dependency
Diffstat (limited to 'vendor/gioui.org/app/gl_js.go')
-rw-r--r-- | vendor/gioui.org/app/gl_js.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/vendor/gioui.org/app/gl_js.go b/vendor/gioui.org/app/gl_js.go new file mode 100644 index 0000000..e3aee8d --- /dev/null +++ b/vendor/gioui.org/app/gl_js.go @@ -0,0 +1,69 @@ +// SPDX-License-Identifier: Unlicense OR MIT + +package app + +import ( + "errors" + "syscall/js" + + "gioui.org/gpu" + "gioui.org/internal/gl" +) + +type glContext struct { + ctx js.Value + cnv js.Value +} + +func newContext(w *window) (*glContext, error) { + args := map[string]interface{}{ + // Enable low latency rendering. + // See https://developers.google.com/web/updates/2019/05/desynchronized. + "desynchronized": true, + "preserveDrawingBuffer": true, + } + ctx := w.cnv.Call("getContext", "webgl2", args) + if ctx.IsNull() { + ctx = w.cnv.Call("getContext", "webgl", args) + } + if ctx.IsNull() { + return nil, errors.New("app: webgl is not supported") + } + c := &glContext{ + ctx: ctx, + cnv: w.cnv, + } + return c, nil +} + +func (c *glContext) RenderTarget() (gpu.RenderTarget, error) { + return gpu.OpenGLRenderTarget{}, nil +} + +func (c *glContext) API() gpu.API { + return gpu.OpenGL{Context: gl.Context(c.ctx)} +} + +func (c *glContext) Release() { +} + +func (c *glContext) Present() error { + if c.ctx.Call("isContextLost").Bool() { + return errors.New("context lost") + } + return nil +} + +func (c *glContext) Lock() error { + return nil +} + +func (c *glContext) Unlock() {} + +func (c *glContext) Refresh() error { + return nil +} + +func (w *window) NewContext() (context, error) { + return newContext(w) +} |