diff --git a/app/headless/headless_js.go b/app/headless/headless_js.go index 7ce860a2..4c836687 100644 --- a/app/headless/headless_js.go +++ b/app/headless/headless_js.go @@ -17,19 +17,17 @@ type jsContext struct { } func newGLContext() (context, error) { - version := 2 doc := js.Global().Get("document") cnv := doc.Call("createElement", "canvas") ctx := cnv.Call("getContext", "webgl2") if ctx.IsNull() { - version = 1 ctx = cnv.Call("getContext", "webgl") } if ctx.IsNull() { return nil, errors.New("headless: webgl is not supported") } f := &glimpl.Functions{Ctx: ctx} - if err := f.Init(version); err != nil { + if err := f.Init(); err != nil { return nil, err } c := &jsContext{ diff --git a/app/internal/glimpl/gl_js.go b/app/internal/glimpl/gl_js.go index 0fa71160..e9acc19a 100644 --- a/app/internal/glimpl/gl_js.go +++ b/app/internal/glimpl/gl_js.go @@ -20,8 +20,10 @@ type Functions struct { int32Buf js.Value } -func (f *Functions) Init(version int) error { - if version < 2 { +func (f *Functions) Init() error { + webgl2Class := js.Global().Get("WebGL2RenderingContext") + iswebgl2 := !webgl2Class.IsNull() && f.Ctx.InstanceOf(webgl2Class) + if !iswebgl2 { f.EXT_disjoint_timer_query = f.getExtension("EXT_disjoint_timer_query") if f.getExtension("OES_texture_half_float").IsNull() && f.getExtension("OES_texture_float").IsNull() { return errors.New("gl: no support for neither OES_texture_half_float nor OES_texture_float") diff --git a/app/internal/window/gl_js.go b/app/internal/window/gl_js.go index 0adbdf4a..2b0152e4 100644 --- a/app/internal/window/gl_js.go +++ b/app/internal/window/gl_js.go @@ -26,17 +26,15 @@ func newContext(w *window) (*context, error) { "desynchronized": true, "preserveDrawingBuffer": true, } - version := 2 ctx := w.cnv.Call("getContext", "webgl2", args) if ctx.IsNull() { - version = 1 ctx = w.cnv.Call("getContext", "webgl", args) } if ctx.IsNull() { return nil, errors.New("app: webgl is not supported") } f := &glimpl.Functions{Ctx: ctx} - if err := f.Init(version); err != nil { + if err := f.Init(); err != nil { return nil, err } c := &context{