mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +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) {
|
||||
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{
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user