Enable to compile Ebiten on js/wasm with Go 1.14

Fixes #1024
This commit is contained in:
Hajime Hoshi
2019-12-19 00:03:35 +09:00
parent 216eacb0ba
commit 85cbc7e56b
13 changed files with 151 additions and 27 deletions

View File

@@ -41,6 +41,30 @@ type (
}
)
func (t textureNative) equal(rhs textureNative) bool {
return jsutil.Equal(js.Value(t), js.Value(rhs))
}
func (f framebufferNative) equal(rhs framebufferNative) bool {
return jsutil.Equal(js.Value(f), js.Value(rhs))
}
func (s shader) equal(rhs shader) bool {
return jsutil.Equal(js.Value(s), js.Value(rhs))
}
func (b buffer) equal(rhs buffer) bool {
return jsutil.Equal(js.Value(b), js.Value(rhs))
}
func (u uniformLocation) equal(rhs uniformLocation) bool {
return jsutil.Equal(js.Value(u), js.Value(rhs))
}
func (p program) equal(rhs program) bool {
return jsutil.Equal(p.value, rhs.value) && p.id == rhs.id
}
var InvalidTexture = textureNative(js.Null())
func getProgramID(p program) programID {
@@ -96,11 +120,11 @@ type contextImpl struct {
}
func (c *context) ensureGL() {
if c.gl != (js.Value{}) {
if !jsutil.Equal(c.gl, js.Value{}) {
return
}
if js.Global().Get("WebGLRenderingContext") == js.Undefined() {
if jsutil.Equal(js.Global().Get("WebGLRenderingContext"), js.Undefined()) {
panic("opengl: WebGL is not supported")
}
// TODO: Define id?
@@ -109,9 +133,9 @@ func (c *context) ensureGL() {
attr.Set("alpha", true)
attr.Set("premultipliedAlpha", true)
gl := canvas.Call("getContext", "webgl", attr)
if gl == js.Null() {
if jsutil.Equal(gl, js.Null()) {
gl = canvas.Call("getContext", "experimental-webgl", attr)
if gl == js.Null() {
if jsutil.Equal(gl, js.Null()) {
panic("opengl: getContext failed")
}
}
@@ -156,7 +180,7 @@ func (c *context) newTexture(width, height int) (textureNative, error) {
c.ensureGL()
gl := c.gl
t := gl.Call("createTexture")
if t == js.Null() {
if jsutil.Equal(t, js.Null()) {
return textureNative(js.Null()), errors.New("opengl: glGenTexture failed")
}
gl.Call("pixelStorei", unpackAlignment, 4)
@@ -209,7 +233,7 @@ func (c *context) deleteTexture(t textureNative) {
if !gl.Call("isTexture", js.Value(t)).Bool() {
return
}
if c.lastTexture == t {
if c.lastTexture.equal(t) {
c.lastTexture = textureNative(js.Null())
}
gl.Call("deleteTexture", js.Value(t))
@@ -262,7 +286,7 @@ func (c *context) deleteFramebuffer(f framebufferNative) {
// If a framebuffer to be deleted is bound, a newly bound framebuffer
// will be a default framebuffer.
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glDeleteFramebuffers.xml
if c.lastFramebuffer == f {
if c.lastFramebuffer.equal(f) {
c.lastFramebuffer = framebufferNative(js.Null())
c.lastViewportWidth = 0
c.lastViewportHeight = 0
@@ -274,7 +298,7 @@ func (c *context) newShader(shaderType shaderType, source string) (shader, error
c.ensureGL()
gl := c.gl
s := gl.Call("createShader", int(shaderType))
if s == js.Null() {
if jsutil.Equal(s, js.Null()) {
return shader(js.Null()), fmt.Errorf("opengl: glCreateShader failed: shader type: %d", shaderType)
}
@@ -298,7 +322,7 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er
c.ensureGL()
gl := c.gl
v := gl.Call("createProgram")
if v == js.Null() {
if jsutil.Equal(v, js.Null()) {
return program{}, errors.New("opengl: glCreateProgram failed")
}