Skip to content

Commit

Permalink
avoid repeatedly restringifying program configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Oct 30, 2016
1 parent c8b911b commit d47dfcc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
13 changes: 4 additions & 9 deletions js/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class ProgramConfiguration {
}
}

self.cacheKey = JSON.stringify([self.vertexPragmas, self.fragmentPragmas]);

return self;
}

Expand All @@ -127,6 +129,8 @@ class ProgramConfiguration {
pragmas.initialize[uniform.name.slice(2)] = `${type} ${uniform.name.slice(2)} = ${uniform.name};\n`;
}

self.cacheKey = JSON.stringify(pragmas);

return self;
}

Expand All @@ -153,15 +157,6 @@ class ProgramConfiguration {
return new VertexArrayType(this.attributes);
}

programCacheKey(name, showOverdraw) {
return JSON.stringify({
name: name,
vertexPragmas: this.vertexPragmas,
fragmentPragmas: this.fragmentPragmas,
overdraw: showOverdraw
});
}

createProgram(name, showOverdraw, gl) {
const program = gl.createProgram();
const definition = shaders[name];
Expand Down
2 changes: 1 addition & 1 deletion js/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class Painter {

_createProgramCached(name, paintAttributeSet) {
this.cache = this.cache || {};
const key = paintAttributeSet.programCacheKey(name, this._showOverdrawInspector);
const key = `${name}:${paintAttributeSet.cacheKey}:${this._showOverdrawInspector}`;
if (!this.cache[key]) {
this.cache[key] = paintAttributeSet.createProgram(name, this._showOverdrawInspector, this.gl);
}
Expand Down

0 comments on commit d47dfcc

Please sign in to comment.