From 2a0b0077da6f4065b5ec1e0989e07975ec1614bc Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 10 Aug 2019 00:49:28 +0200 Subject: [PATCH] ui/app: (wasm) add checks for required extensions Signed-off-by: Elias Naur --- ui/app/gl_js.go | 6 +++++- ui/app/internal/gl/gl_js.go | 26 ++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ui/app/gl_js.go b/ui/app/gl_js.go index 3ccc99e4..12a9c5c6 100644 --- a/ui/app/gl_js.go +++ b/ui/app/gl_js.go @@ -23,15 +23,19 @@ func newContext(w *window) (*context, error) { "desynchronized": true, "preserveDrawingBuffer": true, } + version := 2 ctx := w.cnv.Call("getContext", "webgl2", args) if ctx == js.Null() { + version = 1 ctx = w.cnv.Call("getContext", "webgl", args) } if ctx == js.Null() { return nil, errors.New("app: webgl is not supported") } f := &gl.Functions{Ctx: ctx} - f.Init() + if err := f.Init(version); err != nil { + return nil, err + } c := &context{ ctx: ctx, cnv: w.cnv, diff --git a/ui/app/internal/gl/gl_js.go b/ui/app/internal/gl/gl_js.go index d6aff17a..ffb18316 100644 --- a/ui/app/internal/gl/gl_js.go +++ b/ui/app/internal/gl/gl_js.go @@ -3,6 +3,7 @@ package gl import ( + "errors" "strings" "syscall/js" ) @@ -17,18 +18,23 @@ type Functions struct { int32Buf js.Value } -func (f *Functions) Init() { - f.EXT_disjoint_timer_query_webgl2 = f.getExtension("EXT_disjoint_timer_query_webgl2") - if f.EXT_disjoint_timer_query_webgl2 == js.Null() { +func (f *Functions) Init(version int) error { + if version < 2 { f.EXT_disjoint_timer_query = f.getExtension("EXT_disjoint_timer_query") + if f.getExtension("OES_texture_half_float") == js.Null() && f.getExtension("OES_texture_float") == js.Null() { + return errors.New("gl: no support for neither OES_texture_half_float nor OES_texture_float") + } + if f.getExtension("EXT_sRGB") == js.Null() { + return errors.New("gl: EXT_sRGB not supported") + } + } else { + // WebGL2 extensions. + f.EXT_disjoint_timer_query_webgl2 = f.getExtension("EXT_disjoint_timer_query_webgl2") + if f.getExtension("EXT_color_buffer_half_float") == js.Null() && f.getExtension("EXT_color_buffer_float") == js.Null() { + return errors.New("gl: no support for neither EXT_color_buffer_half_float nor EXT_color_buffer_float") + } } - // Enable extensions. - f.getExtension("OES_texture_half_float") - f.getExtension("OES_texture_float") - f.getExtension("EXT_sRGB") - // WebGL2 extensions - f.getExtension("EXT_color_buffer_half_float") - f.getExtension("EXT_color_buffer_float") + return nil } func (f *Functions) getExtension(name string) js.Value {