From 6fe6543b4b649a96c9e8bdd24b3644b0c3acc80c Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 6 Apr 2021 00:09:50 +0900 Subject: [PATCH] internal/graphicsdriver/opengl: Bug fix: getBufferSubData was available only with WebGL2 --- internal/graphicsdriver/opengl/context_js.go | 10 +++++----- internal/graphicsdriver/opengl/gl_js.go | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index b2904e8b0..4ec284e30 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -587,15 +587,15 @@ func (c *context) replacePixelsWithPBO(buffer buffer, t textureNative, width, he } func (c *context) getBufferSubData(buffer buffer, width, height int) []byte { + if !isWebGL2Available { + panic("opengl: WebGL2 must be available when getBufferSubData is called") + } + gl := c.gl gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, js.Value(buffer)) l := 4 * width * height arr := jsutil.TemporaryUint8Array(l, nil) - if isWebGL2Available { - gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr, 0, l) - } else { - gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr.Call("subarray", 0, l)) - } + gl.getBufferSubData.Invoke(gles.PIXEL_UNPACK_BUFFER, 0, arr, 0, l) gl.bindBuffer.Invoke(gles.PIXEL_UNPACK_BUFFER, nil) return jsutil.Uint8ArrayToSlice(arr, l) } diff --git a/internal/graphicsdriver/opengl/gl_js.go b/internal/graphicsdriver/opengl/gl_js.go index 5cd08d37f..7fb73103a 100644 --- a/internal/graphicsdriver/opengl/gl_js.go +++ b/internal/graphicsdriver/opengl/gl_js.go @@ -112,7 +112,6 @@ func newGL(v js.Value) *gl { enableVertexAttribArray: v.Get("enableVertexAttribArray").Call("bind", v), framebufferTexture2D: v.Get("framebufferTexture2D").Call("bind", v), flush: v.Get("flush").Call("bind", v), - getBufferSubData: v.Get("getBufferSubData").Call("bind", v), getParameter: v.Get("getParameter").Call("bind", v), getProgramInfoLog: v.Get("getProgramInfoLog").Call("bind", v), getProgramParameter: v.Get("getProgramParameter").Call("bind", v), @@ -145,7 +144,9 @@ func newGL(v js.Value) *gl { vertexAttribPointer: v.Get("vertexAttribPointer").Call("bind", v), viewport: v.Get("viewport").Call("bind", v), } - if !isWebGL2Available { + if isWebGL2Available { + g.getExtension = v.Get("getBufferSubData").Call("bind", v) + } else { g.getExtension = v.Get("getExtension").Call("bind", v) } return g