Skip to content

Commit

Permalink
colorMask.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakuna committed Oct 8, 2023
1 parent a468f28 commit d665d89
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"#BlendFunctionSet": "./dist/types/BlendFunctionSet.js",
"#Canvas": "./dist/types/Canvas.js",
"#Color": "./dist/types/Color.js",
"#ColorMask": "./dist/types/ColorMask.js",
"#FloatTypedArray": "./dist/types/FloatTypedArray.js",
"#IntTypedArray": "./dist/types/IntTypedArray.js",
"#TypedArray": "./dist/types/TypedArray.js",
Expand Down
8 changes: 8 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,11 @@ export const DEPTH_BUFFER_BIT = 0x00000100;
* @internal
*/
export const STENCIL_BUFFER_BIT = 0x00000400;

/**
* The mask that specifies which components to enable or disable when
* rendering to a framebuffer.
* @see [`getParameter`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getParameter)
* @internal
*/
export const COLOR_WRITEMASK = 0x0c23;
35 changes: 34 additions & 1 deletion src/core/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
STENCIL_CLEAR_VALUE,
COLOR_BUFFER_BIT,
DEPTH_BUFFER_BIT,
STENCIL_BUFFER_BIT
STENCIL_BUFFER_BIT,
COLOR_WRITEMASK
} from "#constants";
import ApiInterface from "#ApiInterface";
import type { Canvas } from "#Canvas";
Expand All @@ -27,6 +28,7 @@ import type BlendFunctionFullSet from "#BlendFunctionFullSet";
import type BlendFunction from "#BlendFunction";
import ErrorCode from "#ErrorCode";
import WebglError from "#WebglError";
import type ColorMask from "#ColorMask";

/**
* A WebGL2 rendering context.
Expand Down Expand Up @@ -541,4 +543,35 @@ export default class Context extends ApiInterface {
this.gl.clearStencil(value);
this.clearStencilCache = value;
}

/**
* The mask that specifies which components to enable or disable when
* rendering to a framebuffer.
* @see [`colorMask`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask)
* @internal
*/
private colorMaskCache?: ColorMask;

/**
* The mask that specifies which components to enable or disable when
* rendering to a framebuffer.
* @see [`colorMask`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask)
*/
public get colorMask(): ColorMask {
if (typeof this.colorMaskCache == "undefined") {
this.colorMaskCache = this.gl.getParameter(COLOR_WRITEMASK);
}

return this.colorMaskCache!;
}

/**
* The mask that specifies which components to enable or disable when
* rendering to a framebuffer.
* @see [`colorMask`](https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/colorMask)
*/
public set colorMask(value: ColorMask) {
this.gl.colorMask(value[0], value[1], value[2], value[3]);
this.colorMaskCache = value;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type { default as BlendFunctionFullSet } from "#BlendFunctionFullSet";
export type { default as BlendFunctionSet } from "#BlendFunctionSet";
export type { Canvas } from "#Canvas";
export type { default as Color } from "#Color";
export type { default as ColorMask } from "#ColorMask";
export type { FloatTypedArray } from "#FloatTypedArray";
export type { TypedArray } from "#TypedArray";
export type { IntTypedArray } from "#IntTypedArray";
Expand Down
14 changes: 14 additions & 0 deletions src/types/ColorMask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** A color mask. */
export default interface ColorMask {
/** Whether to write to the red component. */
0: boolean;

/** Whether to write to the green component. */
1: boolean;

/** Whether to write to the blue component. */
2: boolean;

/** Whether to write to the alpha component. */
3: boolean;
}

0 comments on commit d665d89

Please sign in to comment.