Skip to content

Commit

Permalink
Monkey-patch the WebGL clear function to disable the scissor when set
Browse files Browse the repository at this point in the history
  • Loading branch information
llienher committed Nov 16, 2023
1 parent 6b77daa commit 22d9ebd
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/map/swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,32 @@ export class SwipeController {
ctx.clip();
} else {
// ctx instanceof WebGLRenderingContext
ctx.clear(ctx.COLOR_BUFFER_BIT);
this.fixWebGLContextScissorClear(ctx);
ctx.enable(ctx.SCISSOR_TEST);
ctx.scissor(0, 0, width, height);
}
}

/**
* Will monkey-patch the context to make sure that clear() calls will not
* take into account any scissor test previously set.
* @param {WebGLRenderingContext} gl WebGL Context
* @private
*/
fixWebGLContextScissorClear(gl) {
if (gl._scissorClearFixed) {
return;
}
const clearFn = gl.clear;
gl.clear = function (...args) {
const scissorEnabled = gl.getParameter(gl.SCISSOR_TEST);
scissorEnabled && gl.disable(gl.SCISSOR_TEST);
clearFn.apply(gl, args);
scissorEnabled && gl.enable(gl.SCISSOR_TEST);
};
gl._scissorClearFixed = true;
}

/**
* @param {?Event|import('ol/events/Event').default} evt OpenLayers object event.
* @private
Expand Down

0 comments on commit 22d9ebd

Please sign in to comment.