From d4a24336434f1f3816f831b341fc6fd7d336f2b0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 4 Dec 2020 12:10:05 +0900 Subject: [PATCH] Revert "graphicsdriver/opengl: Reduce creation of Float32Array" This reverts commit 3c28bcf3c4663d9b927071fef26f43f76fdce56b. Reason: Tests failed: https://github.com/hajimehoshi/ebiten/runs/1496602911 --- internal/graphicsdriver/opengl/context_js.go | 21 ++++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index a97a9f711..725fa6d6a 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -386,29 +386,24 @@ func (c *context) uniformFloats(p program, location string, v []float32, typ sha base = typ.Sub[0].Main } + arr8 := jsutil.TemporaryUint8Array(len(v) * 4) + arr := js.Global().Get("Float32Array").New(arr8.Get("buffer"), arr8.Get("byteOffset"), len(v)) + jsutil.CopySliceToJS(arr, v) + switch base { case shaderir.Float: - gl.Call("uniform1f", js.Value(l), v[0]) + gl.Call("uniform1fv", js.Value(l), arr) case shaderir.Vec2: - gl.Call("uniform2f", js.Value(l), v[0], v[1]) + gl.Call("uniform2fv", js.Value(l), arr) case shaderir.Vec3: - gl.Call("uniform3f", js.Value(l), v[0], v[1], v[2]) + gl.Call("uniform3fv", js.Value(l), arr) case shaderir.Vec4: - gl.Call("uniform4f", js.Value(l), v[0], v[1], v[2], v[3]) + gl.Call("uniform4fv", js.Value(l), arr) case shaderir.Mat2: - arr8 := jsutil.TemporaryUint8Array(len(v) * 4) - arr := js.Global().Get("Float32Array").New(arr8.Get("buffer"), arr8.Get("byteOffset"), len(v)) - jsutil.CopySliceToJS(arr, v) gl.Call("uniformMatrix2fv", js.Value(l), false, arr) case shaderir.Mat3: - arr8 := jsutil.TemporaryUint8Array(len(v) * 4) - arr := js.Global().Get("Float32Array").New(arr8.Get("buffer"), arr8.Get("byteOffset"), len(v)) - jsutil.CopySliceToJS(arr, v) gl.Call("uniformMatrix3fv", js.Value(l), false, arr) case shaderir.Mat4: - arr8 := jsutil.TemporaryUint8Array(len(v) * 4) - arr := js.Global().Get("Float32Array").New(arr8.Get("buffer"), arr8.Get("byteOffset"), len(v)) - jsutil.CopySliceToJS(arr, v) gl.Call("uniformMatrix4fv", js.Value(l), false, arr) default: panic(fmt.Sprintf("opengl: unexpected type: %s", typ.String()))