Skip to content

Commit

Permalink
Make sure getModuleUniforms is updated on program change. (#1235)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsherif committed Sep 12, 2019
1 parent 2453615 commit f41d4a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
14 changes: 12 additions & 2 deletions modules/core/src/lib/base-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ export default class BaseModel {
return this;
}

getModuleUniforms(opts) {
this._checkProgram();

const getUniforms = this.programManager.getUniforms(this.program);

if (getUniforms) {
return getUniforms(opts);
}

return {};
}

updateModuleSettings(opts) {
const uniforms = this.getModuleUniforms(opts || {});
return this.setUniforms(uniforms);
Expand Down Expand Up @@ -271,7 +283,6 @@ export default class BaseModel {
let {program} = this.programProps;

if (program) {
this.getModuleUniforms = () => {};
this._managedProgram = false;
} else {
const {
Expand All @@ -285,7 +296,6 @@ export default class BaseModel {
bufferMode
} = this.programProps;
program = this.programManager.get({vs, fs, modules, inject, defines, varyings, bufferMode});
this.getModuleUniforms = this.programManager.getUniforms(program);
if (this.program && this._managedProgram) {
this.programManager.release(this.program);
}
Expand Down
32 changes: 32 additions & 0 deletions modules/core/test/lib/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import GL from '@luma.gl/constants';
import luma from '@luma.gl/webgl/init';
// TODO - Model test should not depend on Cube
import {Buffer, Model, CubeGeometry, ProgramManager} from '@luma.gl/core';
import {picking} from '@luma.gl/shadertools';
import test from 'tape-catch';
import {fixture} from 'test/setup';

Expand Down Expand Up @@ -209,6 +210,37 @@ test('Model#program management', t => {
t.end();
});

test('Model#program management - getModuleUniforms', t => {
const {gl} = fixture;

const pm = new ProgramManager(gl);

const vs = 'void main() {}';
const fs = 'void main() {}';

const model = new Model(gl, {
programManager: pm,
vs,
fs
});

t.deepEqual(model.getModuleUniforms(), {}, 'Module uniforms empty with no modules');

model.setProgram({
vs,
fs,
modules: [picking]
});

t.deepEqual(
model.getModuleUniforms(),
picking.getUniforms(),
'Module uniforms correct after update'
);

t.end();
});

test('getBuffersFromGeometry', t => {
const {gl} = fixture;

Expand Down

0 comments on commit f41d4a5

Please sign in to comment.