Skip to content

Commit

Permalink
Correct stencil mask modes
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Dec 12, 2017
1 parent aa18375 commit 5560506
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/gl/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ class Context {
this.stencilTest.set(true);
this.stencilMask.set(stencilMode.mask);
this.stencilOp.set([stencilMode.fail, stencilMode.depthFail, stencilMode.pass]);
this.stencilFunc.set(util.pick(stencilMode, ['func', 'ref', 'mask']));
this.stencilFunc.set({
func: stencilMode.test.func,
ref: stencilMode.ref,
mask: stencilMode.test.mask
});
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/gl/stencil_mode.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// @flow
import type { CompareFuncType, StencilOpConstant } from './types';
import type { StencilOpConstant, StencilTest } from './types';

const ALWAYS = 0x0207;
const KEEP = 0x1E00;

class StencilMode {
func: CompareFuncType;
test: StencilTest;
ref: number;
mask: number;
fail: StencilOpConstant;
depthFail: StencilOpConstant;
pass: StencilOpConstant;

constructor(func: CompareFuncType, ref: number, mask: number, fail: StencilOpConstant,
constructor(test: StencilTest, ref: number, mask: number, fail: StencilOpConstant,
depthFail: StencilOpConstant, pass: StencilOpConstant) {
this.func = func;
this.test = test;
this.ref = ref;
this.mask = mask;
this.fail = fail;
Expand All @@ -23,7 +23,7 @@ class StencilMode {
}

static disabled() {
return new StencilMode(ALWAYS, 0, 0, KEEP, KEEP, KEEP);
return new StencilMode({ func: ALWAYS, mask: 0 }, 0, 0, KEEP, KEEP, KEEP);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/gl/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ export type StencilOpType = [StencilOpConstant, StencilOpConstant, StencilOpCons
export type TextureUnitType = number;

export type ViewportType = [number, number, number, number];

export type StencilTest =
| { func: $PropertyType<WebGLRenderingContext, 'NEVER'>, mask: 0 }
| { func: $PropertyType<WebGLRenderingContext, 'LESS'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'EQUAL'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'LEQUAL'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'GREATER'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'NOTEQUAL'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'GEQUAL'>, mask: number }
| { func: $PropertyType<WebGLRenderingContext, 'ALWAYS'>, mask: 0 };
6 changes: 3 additions & 3 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Painter {

context.setColorMode(ColorMode.disabled());
context.setDepthMode(DepthMode.disabled());
context.setStencilMode(new StencilMode(gl.ALWAYS, 0x0, 0xFF, gl.ZERO, gl.ZERO, gl.ZERO));
context.setStencilMode(new StencilMode({ func: gl.ALWAYS, mask: 0 }, 0x0, 0xFF, gl.ZERO, gl.ZERO, gl.ZERO));

const matrix = mat4.create();
mat4.ortho(matrix, 0, this.width, this.height, 0, 0, 1);
Expand Down Expand Up @@ -219,7 +219,7 @@ class Painter {
const id = this._tileClippingMaskIDs[tileID.key] = idNext++;

// Tests will always pass, and ref value will be written to stencil buffer.
context.setStencilMode(new StencilMode(gl.ALWAYS, id, 0xFF, gl.KEEP, gl.KEEP, gl.REPLACE));
context.setStencilMode(new StencilMode({ func: gl.ALWAYS, mask: 0 }, id, 0xFF, gl.KEEP, gl.KEEP, gl.REPLACE));

const program = this.useProgram('fill', programConfiguration);
gl.uniformMatrix4fv(program.uniforms.u_matrix, false, tileID.posMatrix);
Expand All @@ -232,7 +232,7 @@ class Painter {

stencilModeForClipping(tileID: OverscaledTileID): StencilMode {
const gl = this.context.gl;
return new StencilMode(gl.EQUAL, this._tileClippingMaskIDs[tileID.key], 0xFF, gl.KEEP, gl.KEEP, gl.REPLACE);
return new StencilMode({ func: gl.EQUAL, mask: 0xFF }, this._tileClippingMaskIDs[tileID.key], 0x00, gl.KEEP, gl.KEEP, gl.REPLACE);
}

colorModeForRenderPass(): ColorMode {
Expand Down

0 comments on commit 5560506

Please sign in to comment.