Skip to content
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
23 changes: 14 additions & 9 deletions src/RenderWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ class RenderWebGL extends EventEmitter {

/**
* Check if a particular Drawable is touching a particular color.
* Unlike touching drawable, touching color tests invisible sprites.
* @param {int} drawableID The ID of the Drawable to check.
* @param {Array<int>} color3b Test if the Drawable is touching this color.
* @param {Array<int>} [mask3b] Optionally mask the check to this part of Drawable.
Expand All @@ -435,11 +436,11 @@ class RenderWebGL extends EventEmitter {

const bounds = this._touchingBounds(drawableID);
if (!bounds) {
return;
return false;
}
const candidateIDs = this._filterCandidatesTouching(drawableID, this._drawList, bounds);
if (!candidateIDs) {
return;
return false;
}

// Limit size of viewport to the bounds around the target Drawable,
Expand Down Expand Up @@ -477,7 +478,10 @@ class RenderWebGL extends EventEmitter {
ShaderManager.DRAW_MODE.colorMask :
ShaderManager.DRAW_MODE.silhouette,
projection,
{extraUniforms});
{
extraUniforms,
ignoreVisibility: true // Touching color ignores sprite visibility
});

gl.stencilFunc(gl.EQUAL, 1, 1);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
Expand Down Expand Up @@ -533,11 +537,11 @@ class RenderWebGL extends EventEmitter {

const bounds = this._touchingBounds(drawableID);
if (!bounds) {
return;
return false;
}
candidateIDs = this._filterCandidatesTouching(drawableID, candidateIDs, bounds);
if (!candidateIDs) {
return;
return false;
}

// Limit size of viewport to the bounds around the target Drawable,
Expand Down Expand Up @@ -1003,7 +1007,7 @@ class RenderWebGL extends EventEmitter {

try {
gl.disable(gl.BLEND);
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {isStamping: true});
this._drawThese([stampID], ShaderManager.DRAW_MODE.default, projection, {ignoreVisibility: true});
} finally {
gl.enable(gl.BLEND);
}
Expand Down Expand Up @@ -1097,7 +1101,7 @@ class RenderWebGL extends EventEmitter {
* @param {idFilterFunc} opts.filter An optional filter function.
* @param {object.<string,*>} opts.extraUniforms Extra uniforms for the shaders.
* @param {int} opts.effectMask Bitmask for effects to allow
* @param {boolean} opts.isStamping Stamp mode ignores sprite visibility, always drawing.
* @param {boolean} opts.ignoreVisibility Draw all, despite visibility (e.g. stamping, touching color)
* @private
*/
_drawThese (drawables, drawMode, projection, opts = {}) {
Expand All @@ -1114,8 +1118,9 @@ class RenderWebGL extends EventEmitter {
const drawable = this._allDrawables[drawableID];
/** @todo check if drawable is inside the viewport before anything else */

// Hidden drawables (e.g., by a "hide" block) are not drawn unless stamping
if (!drawable.getVisible() && !opts.isStamping) continue;
// Hidden drawables (e.g., by a "hide" block) are not drawn unless
// the ignoreVisibility flag is used (e.g. for stamping or touchingColor).
if (!drawable.getVisible() && !opts.ignoreVisibility) continue;

const drawableScale = drawable.scale;

Expand Down