mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
app/internal/glimpl: derive version parameter in Functions.Init
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -17,19 +17,17 @@ type jsContext struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newGLContext() (context, error) {
|
func newGLContext() (context, error) {
|
||||||
version := 2
|
|
||||||
doc := js.Global().Get("document")
|
doc := js.Global().Get("document")
|
||||||
cnv := doc.Call("createElement", "canvas")
|
cnv := doc.Call("createElement", "canvas")
|
||||||
ctx := cnv.Call("getContext", "webgl2")
|
ctx := cnv.Call("getContext", "webgl2")
|
||||||
if ctx.IsNull() {
|
if ctx.IsNull() {
|
||||||
version = 1
|
|
||||||
ctx = cnv.Call("getContext", "webgl")
|
ctx = cnv.Call("getContext", "webgl")
|
||||||
}
|
}
|
||||||
if ctx.IsNull() {
|
if ctx.IsNull() {
|
||||||
return nil, errors.New("headless: webgl is not supported")
|
return nil, errors.New("headless: webgl is not supported")
|
||||||
}
|
}
|
||||||
f := &glimpl.Functions{Ctx: ctx}
|
f := &glimpl.Functions{Ctx: ctx}
|
||||||
if err := f.Init(version); err != nil {
|
if err := f.Init(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := &jsContext{
|
c := &jsContext{
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ type Functions struct {
|
|||||||
int32Buf js.Value
|
int32Buf js.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Functions) Init(version int) error {
|
func (f *Functions) Init() error {
|
||||||
if version < 2 {
|
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")
|
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() {
|
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")
|
return errors.New("gl: no support for neither OES_texture_half_float nor OES_texture_float")
|
||||||
|
|||||||
@@ -26,17 +26,15 @@ 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.IsNull() {
|
if ctx.IsNull() {
|
||||||
version = 1
|
|
||||||
ctx = w.cnv.Call("getContext", "webgl", args)
|
ctx = w.cnv.Call("getContext", "webgl", args)
|
||||||
}
|
}
|
||||||
if ctx.IsNull() {
|
if ctx.IsNull() {
|
||||||
return nil, errors.New("app: webgl is not supported")
|
return nil, errors.New("app: webgl is not supported")
|
||||||
}
|
}
|
||||||
f := &glimpl.Functions{Ctx: ctx}
|
f := &glimpl.Functions{Ctx: ctx}
|
||||||
if err := f.Init(version); err != nil {
|
if err := f.Init(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := &context{
|
c := &context{
|
||||||
|
|||||||
Reference in New Issue
Block a user