mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
opengl: Remove Node.js support (#141)
This commit is contained in:
parent
6956e15b08
commit
4a5420d6f2
@ -22,6 +22,8 @@ import (
|
|||||||
|
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
"github.com/gopherjs/webgl"
|
"github.com/gopherjs/webgl"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Note that `type Texture *js.Object` doesn't work.
|
// Note that `type Texture *js.Object` doesn't work.
|
||||||
@ -103,31 +105,22 @@ type context struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Init() error {
|
func Init() error {
|
||||||
var gl *webgl.Context
|
if web.IsNodeJS() {
|
||||||
|
return fmt.Errorf("opengl: Node.js is not supported")
|
||||||
|
}
|
||||||
|
|
||||||
if js.Global.Get("require") == js.Undefined {
|
// TODO: Define id?
|
||||||
// TODO: Define id?
|
canvas := js.Global.Get("document").Call("querySelector", "canvas")
|
||||||
canvas := js.Global.Get("document").Call("querySelector", "canvas")
|
gl, err := webgl.NewContext(canvas, &webgl.ContextAttributes{
|
||||||
var err error
|
Alpha: true,
|
||||||
gl, err = webgl.NewContext(canvas, &webgl.ContextAttributes{
|
PremultipliedAlpha: true,
|
||||||
Alpha: true,
|
})
|
||||||
PremultipliedAlpha: true,
|
if err != nil {
|
||||||
})
|
return err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: Now Ebiten with headless-gl doesn't work well (#141).
|
|
||||||
// Use headless-gl for testing.
|
|
||||||
options := map[string]bool{
|
|
||||||
"alpha": true,
|
|
||||||
"premultipliedAlpha": true,
|
|
||||||
}
|
|
||||||
webglContext := js.Global.Call("require", "gl").Invoke(16, 16, options)
|
|
||||||
gl = &webgl.Context{Object: webglContext}
|
|
||||||
}
|
}
|
||||||
c := &Context{}
|
c := &Context{}
|
||||||
c.gl = gl
|
c.gl = gl
|
||||||
|
|
||||||
// Getting an extension might fail after the context is lost, so
|
// Getting an extension might fail after the context is lost, so
|
||||||
// it is required to get the extension here.
|
// it is required to get the extension here.
|
||||||
c.loseContext = gl.GetExtension("WEBGL_lose_context")
|
c.loseContext = gl.GetExtension("WEBGL_lose_context")
|
||||||
|
@ -22,8 +22,12 @@ import (
|
|||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func IsNodeJS() bool {
|
||||||
|
return js.Global.Get("require") != js.Undefined
|
||||||
|
}
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return true
|
return !IsNodeJS()
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsIOSSafari() bool {
|
func IsIOSSafari() bool {
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
|
|
||||||
package web
|
package web
|
||||||
|
|
||||||
|
func IsNodeJS() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func IsBrowser() bool {
|
func IsBrowser() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user