mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-03 00:16:15 +00:00
gpu/headless: move package app/headless
Package headless is more about rendering that windows. Move it accordingly. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// SPDX-License-Identifier: Unlicense OR MIT
|
||||
|
||||
package headless
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall/js"
|
||||
|
||||
"gioui.org/gpu"
|
||||
"gioui.org/internal/glimpl"
|
||||
)
|
||||
|
||||
type jsContext struct {
|
||||
ctx js.Value
|
||||
}
|
||||
|
||||
func newGLContext() (context, error) {
|
||||
doc := js.Global().Get("document")
|
||||
cnv := doc.Call("createElement", "canvas")
|
||||
ctx := cnv.Call("getContext", "webgl2")
|
||||
if ctx.IsNull() {
|
||||
ctx = cnv.Call("getContext", "webgl")
|
||||
}
|
||||
if ctx.IsNull() {
|
||||
return nil, errors.New("headless: webgl is not supported")
|
||||
}
|
||||
c := &jsContext{
|
||||
ctx: ctx,
|
||||
}
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *jsContext) API() gpu.API {
|
||||
return gpu.OpenGL{Context: glimpl.Context(c.ctx)}
|
||||
}
|
||||
|
||||
func (c *jsContext) Release() {
|
||||
}
|
||||
|
||||
func (c *jsContext) ReleaseCurrent() {
|
||||
}
|
||||
|
||||
func (c *jsContext) MakeCurrent() error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user