diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 3e66323ad..6329db9f6 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -99,6 +99,15 @@ var ( webGL2MightBeAvailable = !forceWebGL1 && (js.Global().Get("WebGL2RenderingContext").Truthy() || js.Global().Get("go2cpp").Truthy()) ) +func uint8ArrayToSlice(value js.Value, length int) []byte { + if l := value.Get("byteLength").Int(); length > l { + length = l + } + s := make([]byte, length) + js.CopyBytesToGo(s, value) + return s +} + type contextImpl struct { gl *gl lastProgramID programID @@ -236,7 +245,7 @@ func (c *context) framebufferPixels(f *framebuffer, width, height int) []byte { p := jsutil.TemporaryUint8Array(l, nil) gl.readPixels.Invoke(0, 0, width, height, gles.RGBA, gles.UNSIGNED_BYTE, p) - return jsutil.Uint8ArrayToSlice(p, l) + return uint8ArrayToSlice(p, l) } func (c *context) framebufferPixelsToBuffer(f *framebuffer, buffer buffer, width, height int) { diff --git a/internal/jsutil/slice_js.go b/internal/jsutil/slice_js.go index 932511693..496b7e8b7 100644 --- a/internal/jsutil/slice_js.go +++ b/internal/jsutil/slice_js.go @@ -22,15 +22,6 @@ import ( "unsafe" ) -func Uint8ArrayToSlice(value js.Value, length int) []byte { - if l := value.Get("byteLength").Int(); length > l { - length = l - } - s := make([]byte, length) - js.CopyBytesToGo(s, value) - return s -} - func sliceToByteSlice(s interface{}) (bs []byte) { switch s := s.(type) { case []int8: