diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 1f2187171..1aed45ad8 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -172,8 +172,7 @@ func (q *commandQueue) Flush() { // Note that the vertices passed to BufferSubData is not under GC management // in opengl package due to unsafe-way. // See BufferSubData in context_mobile.go. - opengl.GetContext().ElementArrayBufferSubData(es[:ne]) - opengl.GetContext().ArrayBufferSubData(vs[:nv]) + opengl.BufferSubData(vs[:nv], es[:ne]) es = es[ne:] vs = vs[nv:] } diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index dc8f45169..78bd64b61 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -478,14 +478,14 @@ func (c *Context) bindBuffer(bufferType bufferType, b buffer) { }) } -func (c *Context) ArrayBufferSubData(data []float32) { +func (c *Context) arrayBufferSubData(data []float32) { _ = c.runOnContextThread(func() error { gl.BufferSubData(uint32(arrayBuffer), 0, len(data)*4, gl.Ptr(data)) return nil }) } -func (c *Context) ElementArrayBufferSubData(data []uint16) { +func (c *Context) elementArrayBufferSubData(data []uint16) { _ = c.runOnContextThread(func() error { gl.BufferSubData(uint32(elementArrayBuffer), 0, len(data)*2, gl.Ptr(data)) return nil diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index b73c21f46..077362c59 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -425,14 +425,14 @@ func (c *Context) bindBuffer(bufferType bufferType, b buffer) { gl.Call("bindBuffer", int(bufferType), js.Value(b)) } -func (c *Context) ArrayBufferSubData(data []float32) { +func (c *Context) arrayBufferSubData(data []float32) { gl := c.gl arr := js.TypedArrayOf(data) gl.Call("bufferSubData", int(arrayBuffer), 0, arr) arr.Release() } -func (c *Context) ElementArrayBufferSubData(data []uint16) { +func (c *Context) elementArrayBufferSubData(data []uint16) { gl := c.gl arr := js.TypedArrayOf(data) gl.Call("bufferSubData", int(elementArrayBuffer), 0, arr) diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index 921f0eee4..251b7e7c0 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -374,12 +374,12 @@ func (c *Context) bindBuffer(bufferType bufferType, b buffer) { gl.BindBuffer(mgl.Enum(bufferType), mgl.Buffer(b)) } -func (c *Context) ArrayBufferSubData(data []float32) { +func (c *Context) arrayBufferSubData(data []float32) { gl := c.gl gl.BufferSubData(mgl.Enum(arrayBuffer), 0, float32sToBytes(data)) } -func (c *Context) ElementArrayBufferSubData(data []uint16) { +func (c *Context) elementArrayBufferSubData(data []uint16) { gl := c.gl gl.BufferSubData(mgl.Enum(elementArrayBuffer), 0, uint16sToBytes(data)) } diff --git a/internal/opengl/program.go b/internal/opengl/program.go index 30b19b8d7..e5a19202e 100644 --- a/internal/opengl/program.go +++ b/internal/opengl/program.go @@ -260,6 +260,12 @@ func areSameFloat32Array(a, b []float32) bool { return true } +func BufferSubData(vertices []float32, indices []uint16) { + c := GetContext() + c.arrayBufferSubData(vertices) + c.elementArrayBufferSubData(indices) +} + func UseProgram(proj []float32, texture Texture, dstW, dstH, srcW, srcH int, colorM *affine.ColorM, filter graphics.Filter) { theOpenGLState.useProgram(proj, texture, dstW, dstH, srcW, srcH, colorM, filter) }