Skip to content

Commit

Permalink
feat(webgl): add clearCanvas()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 12, 2023
1 parent 3db4463 commit ad362f9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/webgl/src/canvas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { adaptDPI } from "@thi.ng/adapt-dpi";
import { isString } from "@thi.ng/checks/is-string";
import type { ReadonlyVec } from "@thi.ng/vectors";
import type { WeblGLCanvasOpts } from "./api/canvas.js";
import type { WebGLExtensionMap } from "./api/ext.js";
import { error } from "./error.js";
Expand Down Expand Up @@ -56,3 +57,20 @@ export const getExtensions = <K extends keyof WebGLExtensionMap>(
}
return ext;
};

/**
* Sets clear color to given RGBA `color` and clears viewport's
* `COLOR_BUFFER_BIT` and (by default) also `DEPTH_BUFFER_BIT`.
*
* @param gl
* @param color
* @param depth
*/
export const clearCanvas = (
gl: WebGLRenderingContext,
[r, g, b, a]: ReadonlyVec,
depth = true
) => {
gl.clearColor(r, g, b, a);
gl.clear(gl.COLOR_BUFFER_BIT | (depth ? gl.DEPTH_BUFFER_BIT : 0));
};

0 comments on commit ad362f9

Please sign in to comment.