Skip to content

Commit 6299a88

Browse files
committed
Monkey-patch the WebGL clear function to disable the scissor when set
1 parent cda4475 commit 6299a88

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/map/swipe.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,32 @@ export class SwipeController {
193193
ctx.clip();
194194
} else {
195195
// ctx instanceof WebGLRenderingContext
196-
ctx.clear(ctx.COLOR_BUFFER_BIT);
196+
this.fixWebGLContextScissorClear(ctx);
197197
ctx.enable(ctx.SCISSOR_TEST);
198198
ctx.scissor(0, 0, width, height);
199199
}
200200
}
201201

202+
/**
203+
* Will monkey-patch the context to make sure that clear() calls will not
204+
* take into account any scissor test previously set.
205+
* @param {WebGLRenderingContext} gl WebGL Context
206+
* @private
207+
*/
208+
fixWebGLContextScissorClear(gl) {
209+
if (gl._scissorClearFixed) {
210+
return;
211+
}
212+
const clearFn = gl.clear;
213+
gl.clear = function (...args) {
214+
const scissorEnabled = gl.getParameter(gl.SCISSOR_TEST);
215+
scissorEnabled && gl.disable(gl.SCISSOR_TEST);
216+
clearFn.apply(gl, args);
217+
scissorEnabled && gl.enable(gl.SCISSOR_TEST);
218+
};
219+
gl._scissorClearFixed = true;
220+
}
221+
202222
/**
203223
* @param {?Event|import('ol/events/Event').default} evt OpenLayers object event.
204224
* @private

0 commit comments

Comments
 (0)