diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6271fb091..39a46ce87 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -145,7 +145,6 @@ jobs: - name: go test (Wasm) run: | env GOOS=js GOARCH=wasm cleanenv -remove-prefix GITHUB_ -remove-prefix JAVA_ -- go test -shuffle=on -v ./... - env GOOS=js GOARCH=wasm EBITENGINE_OPENGL=webgl1 cleanenv -remove-prefix GITHUB_ -remove-prefix JAVA_ -- go test -shuffle=on -v ./... - name: Install ebitenmobile run: | diff --git a/examples/contextlost/context_js.go b/examples/contextlost/context_js.go index f301d60df..bf449c600 100644 --- a/examples/contextlost/context_js.go +++ b/examples/contextlost/context_js.go @@ -20,25 +20,17 @@ import ( ) func (g *Game) loseAndRestoreContext() { - doc := js.Global().Get("document") - canvas := doc.Call("getElementsByTagName", "canvas").Index(0) - context := canvas.Call("getContext", "webgl2") - if !context.Truthy() { - context = canvas.Call("getContext", "webgl") - if !context.Truthy() { - context = canvas.Call("getContext", "experimental-webgl") - } - } - if g.lost { return } - // Edge might not support the extension. See - // https://developer.mozilla.org/en-US/docs/Web/API/WEBGL_lose_context + doc := js.Global().Get("document") + canvas := doc.Call("getElementsByTagName", "canvas").Index(0) + context := canvas.Call("getContext", "webgl2") + ext := context.Call("getExtension", "WEBGL_lose_context") if !ext.Truthy() { - fmt.Println("Fail to force context lost. Edge might not support the extension yet.") + fmt.Println("Fail to force context lost.") return } diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index b64452fb6..6644b52d2 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -22,12 +22,8 @@ import ( type contextPlatform struct { canvas js.Value - webGL2 bool } func (c *context) glslVersion() glsl.GLSLVersion { - if c.webGL2 { - return glsl.GLSLVersionES300 - } - return glsl.GLSLVersionES100 + return glsl.GLSLVersionES300 } diff --git a/internal/graphicsdriver/opengl/gl/default_js.go b/internal/graphicsdriver/opengl/gl/default_js.go index 1c05a95bd..5f97a72d3 100644 --- a/internal/graphicsdriver/opengl/gl/default_js.go +++ b/internal/graphicsdriver/opengl/gl/default_js.go @@ -96,8 +96,6 @@ type defaultContext struct { fnVertexAttribPointer js.Value fnViewport js.Value - webGL2 bool - buffers values framebuffers values programs values @@ -226,10 +224,6 @@ func NewDefaultContext(v js.Value) (Context, error) { fnViewport: v.Get("viewport").Call("bind", v), } - if webGL2 := js.Global().Get("WebGL2RenderingContext"); webGL2.Truthy() { - g.webGL2 = v.InstanceOf(webGL2) - } - return g, nil } @@ -290,11 +284,7 @@ func (c *defaultContext) BufferInit(target uint32, size int, usage uint32) { func (c *defaultContext) BufferSubData(target uint32, offset int, data []byte) { l := len(data) arr := jsutil.TemporaryUint8ArrayFromUint8Slice(l, data) - if c.webGL2 { - c.fnBufferSubData.Invoke(target, offset, arr, 0, l) - } else { - c.fnBufferSubData.Invoke(target, offset, arr.Call("subarray", 0, l)) - } + c.fnBufferSubData.Invoke(target, offset, arr, 0, l) } func (c *defaultContext) CheckFramebufferStatus(target uint32) uint32 { @@ -540,27 +530,16 @@ func (c *defaultContext) TexParameteri(target uint32, pname uint32, param int32) func (c *defaultContext) TexSubImage2D(target uint32, level int32, xoffset int32, yoffset int32, width int32, height int32, format uint32, xtype uint32, pixels []byte) { arr := jsutil.TemporaryUint8ArrayFromUint8Slice(len(pixels), pixels) - if c.webGL2 { - // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, - // GLsizei width, GLsizei height, - // GLenum format, GLenum type, ArrayBufferView pixels, srcOffset); - c.fnTexSubImage2D.Invoke(target, level, xoffset, yoffset, width, height, format, xtype, arr, 0) - } else { - // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, - // GLsizei width, GLsizei height, - // GLenum format, GLenum type, ArrayBufferView? pixels); - c.fnTexSubImage2D.Invoke(target, level, xoffset, yoffset, width, height, format, xtype, arr) - } + // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, + // GLsizei width, GLsizei height, + // GLenum format, GLenum type, ArrayBufferView pixels, srcOffset); + c.fnTexSubImage2D.Invoke(target, level, xoffset, yoffset, width, height, format, xtype, arr, 0) } func (c *defaultContext) Uniform1fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniform1fv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform1fv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform1fv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform1i(location int32, v0 int32) { @@ -571,101 +550,61 @@ func (c *defaultContext) Uniform1i(location int32, v0 int32) { func (c *defaultContext) Uniform1iv(location int32, value []int32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryInt32Array(len(value), value) - if c.webGL2 { - c.fnUniform1iv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform1iv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform1iv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform2fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniform2fv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform2fv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform2fv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform2iv(location int32, value []int32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryInt32Array(len(value), value) - if c.webGL2 { - c.fnUniform2iv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform2iv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform2iv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform3fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniform3fv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform3fv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform3fv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform3iv(location int32, value []int32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryInt32Array(len(value), value) - if c.webGL2 { - c.fnUniform3iv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform3iv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform3iv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform4fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniform4fv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform4fv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform4fv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) Uniform4iv(location int32, value []int32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryInt32Array(len(value), value) - if c.webGL2 { - c.fnUniform4iv.Invoke(l, arr, 0, len(value)) - } else { - c.fnUniform4iv.Invoke(l, arr.Call("subarray", 0, len(value))) - } + c.fnUniform4iv.Invoke(l, arr, 0, len(value)) } func (c *defaultContext) UniformMatrix2fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniformMatrix2fv.Invoke(l, false, arr, 0, len(value)) - } else { - c.fnUniformMatrix2fv.Invoke(l, false, arr.Call("subarray", 0, len(value))) - } + c.fnUniformMatrix2fv.Invoke(l, false, arr, 0, len(value)) } func (c *defaultContext) UniformMatrix3fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniformMatrix3fv.Invoke(l, false, arr, 0, len(value)) - } else { - c.fnUniformMatrix3fv.Invoke(l, false, arr.Call("subarray", 0, len(value))) - } + c.fnUniformMatrix3fv.Invoke(l, false, arr, 0, len(value)) } func (c *defaultContext) UniformMatrix4fv(location int32, value []float32) { l := c.getUniformLocation(location) arr := jsutil.TemporaryFloat32Array(len(value), value) - if c.webGL2 { - c.fnUniformMatrix4fv.Invoke(l, false, arr, 0, len(value)) - } else { - c.fnUniformMatrix4fv.Invoke(l, false, arr.Call("subarray", 0, len(value))) - } + c.fnUniformMatrix4fv.Invoke(l, false, arr, 0, len(value)) } func (c *defaultContext) UseProgram(program uint32) { diff --git a/internal/graphicsdriver/opengl/graphics_js.go b/internal/graphicsdriver/opengl/graphics_js.go index 1a34cbec2..e1de1fd07 100644 --- a/internal/graphicsdriver/opengl/graphics_js.go +++ b/internal/graphicsdriver/opengl/graphics_js.go @@ -16,8 +16,6 @@ package opengl import ( "fmt" - "os" - "strings" "syscall/js" "github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver" @@ -34,23 +32,10 @@ func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) { attr.Set("premultipliedAlpha", true) attr.Set("stencil", true) - var webGL2 bool - if webGL2MightBeAvailable() { - glContext = canvas.Call("getContext", "webgl2", attr) - } - - if glContext.Truthy() { - webGL2 = true - } else { - // Even though WebGL2RenderingContext exists, getting a webgl2 context might fail (#1738). - glContext = canvas.Call("getContext", "webgl", attr) - if !glContext.Truthy() { - glContext = canvas.Call("getContext", "experimental-webgl", attr) - } - } + glContext = canvas.Call("getContext", "webgl2", attr) if !glContext.Truthy() { - return nil, fmt.Errorf("opengl: getContext failed") + return nil, fmt.Errorf("opengl: getContext for webgl2 failed") } ctx, err := gl.NewDefaultContext(glContext) @@ -61,22 +46,6 @@ func NewGraphics(canvas js.Value) (graphicsdriver.Graphics, error) { g := &Graphics{} g.context.canvas = canvas g.context.ctx = ctx - g.context.webGL2 = webGL2 - - if !webGL2 { - glContext.Call("getExtension", "OES_standard_derivatives") - } return g, nil } - -func webGL2MightBeAvailable() bool { - env := os.Getenv("EBITENGINE_OPENGL") - for _, t := range strings.Split(env, ",") { - switch strings.TrimSpace(t) { - case "webgl1": - return false - } - } - return js.Global().Get("WebGL2RenderingContext").Truthy() -}