Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Clear" stencil buffer manually; workaround for #5490 #5704

Merged
merged 1 commit into from
Nov 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,40 @@ class Painter {
*/
clearStencil() {
const gl = this.gl;
gl.clearStencil(0x0);

// As a temporary workaround for https://github.com/mapbox/mapbox-gl-js/issues/5490,
// pending an upstream fix, we draw a fullscreen stencil=0 clipping mask here,
// effectively clearing the stencil buffer: restore this code for native
// performance and readability once an upstream patch lands.

// gl.clearStencil(0x0);
// gl.stencilMask(0xFF);
// gl.clear(gl.STENCIL_BUFFER_BIT);

gl.colorMask(false, false, false, false);
this.depthMask(false);
gl.disable(gl.DEPTH_TEST);
gl.enable(gl.STENCIL_TEST);

gl.stencilMask(0xFF);
gl.clear(gl.STENCIL_BUFFER_BIT);
gl.stencilOp(gl.ZERO, gl.ZERO, gl.ZERO);

gl.stencilFunc(gl.ALWAYS, 0x0, 0xFF);

const matrix = mat4.create();
mat4.ortho(matrix, 0, this.width, this.height, 0, 0, 1);
mat4.scale(matrix, matrix, [gl.drawingBufferWidth, gl.drawingBufferHeight, 0]);

const program = this.useProgram('fill', this.basicFillProgramConfiguration);
gl.uniformMatrix4fv(program.uniforms.u_matrix, false, matrix);

this.viewportVAO.bind(gl, program, this.viewportBuffer);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);

gl.stencilMask(0x00);
gl.colorMask(true, true, true, true);
this.depthMask(true);
gl.enable(gl.DEPTH_TEST);
}

clearDepth() {
Expand Down