mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
ui/app: (wasm) add checks for required extensions
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+5
-1
@@ -23,15 +23,19 @@ func newContext(w *window) (*context, error) {
|
|||||||
"desynchronized": true,
|
"desynchronized": true,
|
||||||
"preserveDrawingBuffer": true,
|
"preserveDrawingBuffer": true,
|
||||||
}
|
}
|
||||||
|
version := 2
|
||||||
ctx := w.cnv.Call("getContext", "webgl2", args)
|
ctx := w.cnv.Call("getContext", "webgl2", args)
|
||||||
if ctx == js.Null() {
|
if ctx == js.Null() {
|
||||||
|
version = 1
|
||||||
ctx = w.cnv.Call("getContext", "webgl", args)
|
ctx = w.cnv.Call("getContext", "webgl", args)
|
||||||
}
|
}
|
||||||
if ctx == js.Null() {
|
if ctx == js.Null() {
|
||||||
return nil, errors.New("app: webgl is not supported")
|
return nil, errors.New("app: webgl is not supported")
|
||||||
}
|
}
|
||||||
f := &gl.Functions{Ctx: ctx}
|
f := &gl.Functions{Ctx: ctx}
|
||||||
f.Init()
|
if err := f.Init(version); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
c := &context{
|
c := &context{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cnv: w.cnv,
|
cnv: w.cnv,
|
||||||
|
|||||||
+16
-10
@@ -3,6 +3,7 @@
|
|||||||
package gl
|
package gl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
)
|
)
|
||||||
@@ -17,18 +18,23 @@ type Functions struct {
|
|||||||
int32Buf js.Value
|
int32Buf js.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Init() {
|
func (f *Functions) Init(version int) error {
|
||||||
f.EXT_disjoint_timer_query_webgl2 = f.getExtension("EXT_disjoint_timer_query_webgl2")
|
if version < 2 {
|
||||||
if f.EXT_disjoint_timer_query_webgl2 == js.Null() {
|
|
||||||
f.EXT_disjoint_timer_query = f.getExtension("EXT_disjoint_timer_query")
|
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.
|
return nil
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) getExtension(name string) js.Value {
|
func (f *Functions) getExtension(name string) js.Value {
|
||||||
|
|||||||
Reference in New Issue
Block a user