Skip to content

Commit

Permalink
refactor(webgl): redefine WebGL error, migrate logger
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Sep 24, 2021
1 parent a4a3e61 commit 6a5158d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
10 changes: 4 additions & 6 deletions packages/webgl/src/error.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export class WebGLError extends Error {
constructor(msg?: string) {
super(`WebGL error ${msg ? ": " + msg : ""}`);
}
}
import { defError } from "@thi.ng/errors";

export const error = (msg?: string) => {
export const WebGLError = defError(() => "WebGL");

export const error = (msg?: string): never => {
throw new WebGLError(msg);
};
2 changes: 1 addition & 1 deletion packages/webgl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 All @@ -15,6 +14,7 @@ export * from "./checks";
export * from "./draw";
export * from "./error";
export * from "./fbo";
export * from "./logger";
export * from "./material";
export * from "./matrices";
export * from "./multipass";
Expand Down
File renamed without changes.
11 changes: 8 additions & 3 deletions packages/webgl/src/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
GL_EXT_INFO,
} from "./api/ext";
import type { GLSL } from "./api/glsl";
import { LOGGER } from "./api/logger";
import type { ModelAttributeSpecs, ModelSpec } from "./api/model";
import {
DEFAULT_OUTPUT,
Expand All @@ -44,6 +43,7 @@ import {
import { getExtensions } from "./canvas";
import { isGL2Context } from "./checks";
import { error } from "./error";
import { LOGGER } from "./logger";
import { GLSL_HEADER, NO_PREFIXES, SYNTAX } from "./syntax";
import { UNIFORM_SETTERS } from "./uniforms";

Expand All @@ -57,10 +57,15 @@ export class Shader implements IShader {
state: Partial<ShaderState>;

protected warnAttrib = doOnce((id: string) =>
LOGGER.warn(`unknown attrib: ${id}`)
LOGGER.warn(
`unknown attrib: ${id} (no further warnings will be shown...)`
)
);

protected warnUni = doOnce((id: string) =>
LOGGER.warn(`unknown uniform: ${id}`)
LOGGER.warn(
`unknown uniform: ${id} (no further warnings will be shown...)`
)
);

constructor(
Expand Down

0 comments on commit 6a5158d

Please sign in to comment.