diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-10-15 17:08:15 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-10-17 12:43:59 -0700 |
commit | 34240fec4adc3316920a269478f84b3dbebca78b (patch) | |
tree | 6f0e39591480c57d9a6d859bef50127d43c3a05b /src/library_gl.js | |
parent | eb466e688fb95efe4bdf32facb99c1b668e6cb4e (diff) |
return identical ids from glGetUniformLocation when we need to
Diffstat (limited to 'src/library_gl.js')
-rw-r--r-- | src/library_gl.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/library_gl.js b/src/library_gl.js index 765b3cdb..99198196 100644 --- a/src/library_gl.js +++ b/src/library_gl.js @@ -19,6 +19,8 @@ var LibraryGL = { uniforms: [], shaders: [], + uniformTable: {}, // name => uniform ID. the uID must be identical until relinking, cannot create a new uID each call to glGetUniformLocation + packAlignment: 4, // default alignment is 4 bytes unpackAlignment: 4, // default alignment is 4 bytes @@ -520,10 +522,15 @@ var LibraryGL = { glGetUniformLocation: function(program, name) { name = Pointer_stringify(name); + var ptable = GL.uniformTable[program]; + if (!ptable) ptable = GL.uniformTable[program] = {}; + var id = ptable[name]; + if (id) return id; var loc = Module.ctx.getUniformLocation(GL.programs[program], name); if (!loc) return -1; - var id = GL.getNewId(GL.uniforms); + id = GL.getNewId(GL.uniforms); GL.uniforms[id] = loc; + ptable[name] = id; return id; }, @@ -826,6 +833,7 @@ var LibraryGL = { glDeleteProgram: function(program) { Module.ctx.deleteProgram(GL.programs[program]); GL.programs[program] = null; + GL.uniformTable[program] = null; }, glAttachShader: function(program, shader) { @@ -842,6 +850,7 @@ var LibraryGL = { glLinkProgram: function(program) { Module.ctx.linkProgram(GL.programs[program]); + GL.uniformTable[program] = {}; // uniforms no longer keep the same names after linking }, glGetProgramInfoLog: function(program, maxLength, length, infoLog) { |