Skip to content

Commit

Permalink
fix(webgl): add LOGGER, update initUniforms()
Browse files Browse the repository at this point in the history
- don't throw error when initializing unused uniforms
  • Loading branch information
postspectacular committed Nov 4, 2019
1 parent 3a6c469 commit 4719110
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions packages/webgl/src/api/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ILogger, NULL_LOGGER } from "@thi.ng/api";

export let LOGGER: ILogger = NULL_LOGGER;

export const setLogger = (logger: ILogger) => (LOGGER = logger);
1 change: 1 addition & 0 deletions packages/webgl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./api/buffers";
export * from "./api/canvas";
export * from "./api/ext";
export * from "./api/glsl";
export * from "./api/logger";
export * from "./api/material";
export * from "./api/model";
export * from "./api/shader";
Expand Down
26 changes: 15 additions & 11 deletions packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
GL_EXT_INFO
} from "./api/ext";
import { GLSL } from "./api/glsl";
import { LOGGER } from "./api/logger";
import { ModelAttributeSpecs, ModelSpec } from "./api/model";
import {
DEFAULT_OUTPUT,
Expand Down Expand Up @@ -478,18 +479,21 @@ const initUniforms = (
type = val;
}
const loc = gl.getUniformLocation(prog, id)!;
loc == null && error(`unknown uniform: ${id}`);
const setter = UNIFORM_SETTERS[type];
if (setter) {
res[id] = {
loc,
setter: setter(gl, loc, defaultVal),
defaultFn,
defaultVal,
type
};
if (loc != null) {
const setter = UNIFORM_SETTERS[type];
if (setter) {
res[id] = {
loc,
setter: setter(gl, loc, defaultVal),
defaultFn,
defaultVal,
type
};
} else {
error(`invalid uniform type: ${type}`);
}
} else {
error(`invalid uniform type: ${type}`);
LOGGER.warn(`unknown uniform: ${id}`);
}
}
return res;
Expand Down

0 comments on commit 4719110

Please sign in to comment.