Skip to content

Commit

Permalink
Merge pull request #9258 from camptocamp/backport/9257-to-master
Browse files Browse the repository at this point in the history
[Backport master] Monkey-patch clear WebGL
  • Loading branch information
llienher authored Nov 17, 2023
2 parents cda4475 + e0264d5 commit fa3bc61
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Binary file modified examples/mapswipe-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 fa3bc61

Please sign in to comment.