Skip to content

Commit

Permalink
Merge 570be9e into 4a5cd1a
Browse files Browse the repository at this point in the history
  • Loading branch information
felixpalmer committed Mar 21, 2024
2 parents 4a5cd1a + 570be9e commit e0b9a6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/core/src/adapter/types/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export type RenderPassParameters = {
blendConstant?: number[]; // GPUColor
/** Stencil operation "replace" sets the value to stencilReference */
stencilReference?: number; // GPUStencilValue

/** Bitmask controlling which channels are are written to when drawing/clearing. defaulting to 0xF */
colorMask?: number;
};

export type RenderPipelineParameters = RasterizationParameters &
Expand Down
8 changes: 8 additions & 0 deletions modules/webgl/src/adapter/resources/webgl-render-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const GL_STENCIL_BUFFER_BIT = 0x00000400;
const GL_COLOR_BUFFER_BIT = 0x00004000;

const GL_COLOR = 0x1800;
const {RED, GREEN, BLUE, ALPHA} = GPUColorWrite;
const COLOR_CHANNELS = [RED, GREEN, BLUE, ALPHA];

export class WEBGLRenderPass extends RenderPass {
readonly device: WebGLDevice;
Expand Down Expand Up @@ -96,6 +98,12 @@ export class WEBGLRenderPass extends RenderPass {
parameters[GL.STENCIL_REF] = parameters.stencilReference;
}

if (parameters.colorMask) {
glParameters.colorMask = COLOR_CHANNELS.map(channel =>
Boolean(channel & parameters.colorMask)
);
}

this.glParameters = glParameters;

setGLParameters(this.device.gl, glParameters);
Expand Down

0 comments on commit e0b9a6b

Please sign in to comment.