Skip to content

Commit

Permalink
Merge 2016803 into 2b94e23
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Aug 29, 2019
2 parents 2b94e23 + 2016803 commit f727afb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Expand Up @@ -84,7 +84,6 @@ Get a program that fits the parameters provided. If one is already cached, retur
* `defines`: Object indicating `#define` constants to include in the shaders.
* `modules`: Array of module objects to include in the shaders.
* `inject`: Object of hook injections to include in the shaders.
* `program`: A `Program` object to compare the new one two. If they're the same, use count won't be modified. If not, `program` will be released.

### `addDefaultModule(module: Object)`

Expand Down
6 changes: 6 additions & 0 deletions modules/core/src/lib/base-model.js
Expand Up @@ -302,6 +302,12 @@ export default class BaseModel {

assert(program instanceof Program, 'Model needs a program');

if (this.programManager) {
// Even if the program didn't change, we 'got'
// a program, so release the old one
this.programManager.release(this.program);
}

if (program === this.program) {
return;
}
Expand Down
25 changes: 6 additions & 19 deletions modules/core/src/resource-management/program-manager.js
Expand Up @@ -61,17 +61,8 @@ export default class ProgramManager {
}

get(props = {}) {
const {
vs = '',
fs = '',
defines = {},
inject = {},
varyings = [],
bufferMode = 0x8c8d,
program = null
} = props; // varyings/bufferMode for xform feedback, 0x8c8d = SEPARATE_ATTRIBS

const oldProgramHash = program ? program.hash : '';
const {vs = '', fs = '', defines = {}, inject = {}, varyings = [], bufferMode = 0x8c8d} = props; // varyings/bufferMode for xform feedback, 0x8c8d = SEPARATE_ATTRIBS

const modules = this._getModuleList(props.modules); // Combine with default modules

const vsHash = this._getHash(vs);
Expand Down Expand Up @@ -100,10 +91,6 @@ export default class ProgramManager {
this._hookStateCounter
}B${bufferMode}`;

if (oldProgramHash === hash) {
return program;
}

if (!this._programCache[hash]) {
const assembled = assembleShaders(this.gl, {
vs,
Expand All @@ -129,10 +116,6 @@ export default class ProgramManager {

this._useCounts[hash]++;

if (program) {
this.release(program);
}

return this._programCache[hash];
}

Expand All @@ -141,6 +124,10 @@ export default class ProgramManager {
}

release(program) {
if (!program) {
return;
}

const hash = program.hash;
this._useCounts[hash]--;

Expand Down

0 comments on commit f727afb

Please sign in to comment.