app/internal/glimpl: derive version parameter in Functions.Init

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-12-04 19:20:25 +01:00
parent 85a06223a6
commit b8e33bb420
3 changed files with 6 additions and 8 deletions
+1 -3
View File
@@ -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{
+4 -2
View File
@@ -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")
+1 -3
View File
@@ -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{