Skip to content

Commit

Permalink
feat(webgl): only warn once re: unknown uni/attrib
Browse files Browse the repository at this point in the history
- add thi.ng/memoize dep
- update Shader to only warn once
- update readme
  • Loading branch information
postspectacular committed Aug 20, 2020
1 parent 889e00d commit 7490aa1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/webgl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ yarn add @thi.ng/webgl
<script src="https://unpkg.com/@thi.ng/webgl/lib/index.umd.js" crossorigin></script>
```

Package sizes (gzipped, pre-treeshake): ESM: 11.48 KB / CJS: 11.65 KB / UMD: 11.47 KB
Package sizes (gzipped, pre-treeshake): ESM: 11.52 KB / CJS: 11.69 KB / UMD: 11.52 KB

## Dependencies

Expand All @@ -100,6 +100,7 @@ Package sizes (gzipped, pre-treeshake): ESM: 11.48 KB / CJS: 11.65 KB / UMD: 11.
- [@thi.ng/equiv](https://github.com/thi-ng/umbrella/tree/develop/packages/equiv)
- [@thi.ng/errors](https://github.com/thi-ng/umbrella/tree/develop/packages/errors)
- [@thi.ng/matrices](https://github.com/thi-ng/umbrella/tree/develop/packages/matrices)
- [@thi.ng/memoize](https://github.com/thi-ng/umbrella/tree/develop/packages/memoize)
- [@thi.ng/pixel](https://github.com/thi-ng/umbrella/tree/develop/packages/pixel)
- [@thi.ng/shader-ast](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast)
- [@thi.ng/shader-ast-glsl](https://github.com/thi-ng/umbrella/tree/develop/packages/shader-ast-glsl)
Expand Down
1 change: 1 addition & 0 deletions packages/webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@thi.ng/equiv": "^1.0.29",
"@thi.ng/errors": "^1.2.19",
"@thi.ng/matrices": "^0.6.29",
"@thi.ng/memoize": "^2.0.19",
"@thi.ng/pixel": "^0.4.3",
"@thi.ng/shader-ast": "^0.6.3",
"@thi.ng/shader-ast-glsl": "^0.2.7",
Expand Down
12 changes: 10 additions & 2 deletions packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isFunction,
} from "@thi.ng/checks";
import { unsupported } from "@thi.ng/errors";
import { doOnce } from "@thi.ng/memoize";
import {
input,
output,
Expand Down Expand Up @@ -58,6 +59,13 @@ export class Shader implements IShader {
uniforms: ShaderUniforms;
state: Partial<ShaderState>;

protected warnAttrib = doOnce((id: string) =>
LOGGER.warn(`unknown attrib: ${id}`)
);
protected warnUni = doOnce((id: string) =>
LOGGER.warn(`unknown uniform: ${id}`)
);

constructor(
gl: WebGLRenderingContext,
program: WebGLProgram,
Expand Down Expand Up @@ -119,7 +127,7 @@ export class Shader implements IShader {
attr.offset || 0
);
} else {
LOGGER.warn(`unknown attrib: ${id}`);
this.warnAttrib(id);
}
}
}
Expand All @@ -134,7 +142,7 @@ export class Shader implements IShader {
// console.log(id, val);
u.setter(<UniformValue>val);
} else {
LOGGER.warn(`unknown uniform: ${id}`);
this.warnUni(id);
}
}
// apply defaults for non-specified uniforms in user spec
Expand Down
2 changes: 1 addition & 1 deletion packages/webgl/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { add, mul, Sym, Term } from "@thi.ng/shader-ast";
import type { IObjectOf } from "@thi.ng/api";
import { add, mul, Sym, Term } from "@thi.ng/shader-ast";
import type { ShaderOpts } from "./api/shader";

export const positionAttrib = (
Expand Down

0 comments on commit 7490aa1

Please sign in to comment.