diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-03-15 19:31:01 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-03-15 19:31:01 -0700 |
commit | 9b64a956949247cb838f03723aa2cde1598e65fc (patch) | |
tree | 0a2c4da424fec58b8df30f66bb8b0931e708bdab | |
parent | 459e5e6f8f0c4b0310ab00f7c0f708f65a66dc18 (diff) |
optimize away the allocation in glUniformMatrix?fv with count == 1
-rw-r--r-- | src/library_gl.js | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 8f99ea67..031f4560 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -903,23 +903,47 @@ var LibraryGL = { glUniformMatrix2fv: function(location, count, transpose, value) { location = GL.uniforms[location]; - count *= 4; - value = {{{ makeHEAPView('F32', 'value', 'value+count*4') }}}; - Module.ctx.uniformMatrix2fv(location, transpose, value); + var view; + if (count == 1) { + // avoid allocation for the common case of uploading one uniform matrix + view = GL.miniTempBufferViews[3]; + for (var i = 0; i < 4; i++) { + view[i] = {{{ makeGetValue('value', 'i*4', 'float') }}}; + } + } else { + view = {{{ makeHEAPView('F32', 'value', 'value+count*16') }}}; + } + Module.ctx.uniformMatrix2fv(location, transpose, view); }, glUniformMatrix3fv: function(location, count, transpose, value) { location = GL.uniforms[location]; - count *= 9; - value = {{{ makeHEAPView('F32', 'value', 'value+count*4') }}}; - Module.ctx.uniformMatrix3fv(location, transpose, value); + var view; + if (count == 1) { + // avoid allocation for the common case of uploading one uniform matrix + view = GL.miniTempBufferViews[8]; + for (var i = 0; i < 9; i++) { + view[i] = {{{ makeGetValue('value', 'i*4', 'float') }}}; + } + } else { + view = {{{ makeHEAPView('F32', 'value', 'value+count*36') }}}; + } + Module.ctx.uniformMatrix3fv(location, transpose, view); }, glUniformMatrix4fv: function(location, count, transpose, value) { location = GL.uniforms[location]; - count *= 16; - value = {{{ makeHEAPView('F32', 'value', 'value+count*4') }}}; - Module.ctx.uniformMatrix4fv(location, transpose, value); + var view; + if (count == 1) { + // avoid allocation for the common case of uploading one uniform matrix + view = GL.miniTempBufferViews[15]; + for (var i = 0; i < 16; i++) { + view[i] = {{{ makeGetValue('value', 'i*4', 'float') }}}; + } + } else { + view = {{{ makeHEAPView('F32', 'value', 'value+count*64') }}}; + } + Module.ctx.uniformMatrix4fv(location, transpose, view); }, glBindBuffer__sig: 'vii', |