@@ -182,23 +182,9 @@ class RenderWebGL extends EventEmitter {
182
182
/** @type {function } */
183
183
this . _exitRegion = null ;
184
184
185
- /** @type {object } */
186
- this . _backgroundDrawRegionId = {
187
- enter : ( ) => this . _enterDrawBackground ( ) ,
188
- exit : ( ) => this . _exitDrawBackground ( )
189
- } ;
190
-
191
185
/** @type {Array.<snapshotCallback> } */
192
186
this . _snapshotCallbacks = [ ] ;
193
187
194
- /** @type {Array<number> } */
195
- // Don't set this directly-- use setBackgroundColor so it stays in sync with _backgroundColor3b
196
- this . _backgroundColor4f = [ 0 , 0 , 0 , 1 ] ;
197
-
198
- /** @type {Uint8ClampedArray } */
199
- // Don't set this directly-- use setBackgroundColor so it stays in sync with _backgroundColor4f
200
- this . _backgroundColor3b = new Uint8ClampedArray ( 3 ) ;
201
-
202
188
this . _createGeometry ( ) ;
203
189
204
190
this . on ( RenderConstants . Events . NativeSizeChanged , this . onNativeSizeChanged ) ;
@@ -258,14 +244,7 @@ class RenderWebGL extends EventEmitter {
258
244
* @param {number } blue The blue component for the background.
259
245
*/
260
246
setBackgroundColor ( red , green , blue ) {
261
- this . _backgroundColor4f [ 0 ] = red ;
262
- this . _backgroundColor4f [ 1 ] = green ;
263
- this . _backgroundColor4f [ 2 ] = blue ;
264
-
265
- this . _backgroundColor3b [ 0 ] = red * 255 ;
266
- this . _backgroundColor3b [ 1 ] = green * 255 ;
267
- this . _backgroundColor3b [ 2 ] = blue * 255 ;
268
-
247
+ this . _backgroundColor = [ red , green , blue , 1 ] ;
269
248
}
270
249
271
250
/**
@@ -644,7 +623,7 @@ class RenderWebGL extends EventEmitter {
644
623
645
624
twgl . bindFramebufferInfo ( gl , null ) ;
646
625
gl . viewport ( 0 , 0 , gl . canvas . width , gl . canvas . height ) ;
647
- gl . clearColor . apply ( gl , this . _backgroundColor4f ) ;
626
+ gl . clearColor . apply ( gl , this . _backgroundColor ) ;
648
627
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
649
628
650
629
this . _drawThese ( this . _drawList , ShaderManager . DRAW_MODE . default , this . _projection ) ;
@@ -760,20 +739,12 @@ class RenderWebGL extends EventEmitter {
760
739
*/
761
740
isTouchingColor ( drawableID , color3b , mask3b ) {
762
741
const candidates = this . _candidatesTouching ( drawableID , this . _visibleDrawList ) ;
763
-
764
- let bounds ;
765
- if ( colorMatches ( color3b , this . _backgroundColor3b , 0 ) ) {
766
- // If the color we're checking for is the background color, don't confine the check to
767
- // candidate drawables' bounds--since the background spans the entire stage, we must check
768
- // everything that lies inside the drawable.
769
- bounds = this . _touchingBounds ( drawableID ) ;
770
- } else if ( candidates . length === 0 ) {
771
- // If not checking for the background color, we can return early if there are no candidate drawables.
742
+ if ( candidates . length === 0 ) {
772
743
return false ;
773
- } else {
774
- bounds = this . _candidatesBounds ( candidates ) ;
775
744
}
776
745
746
+ const bounds = this . _candidatesBounds ( candidates ) ;
747
+
777
748
const maxPixelsForCPU = this . _getMaxPixelsForCPU ( ) ;
778
749
779
750
const debugCanvasContext = this . _debugCanvas && this . _debugCanvas . getContext ( '2d' ) ;
@@ -834,19 +805,6 @@ class RenderWebGL extends EventEmitter {
834
805
}
835
806
}
836
807
837
- _enterDrawBackground ( ) {
838
- const gl = this . gl ;
839
- const currentShader = this . _shaderManager . getShader ( ShaderManager . DRAW_MODE . background , 0 ) ;
840
- gl . disable ( gl . BLEND ) ;
841
- gl . useProgram ( currentShader . program ) ;
842
- twgl . setBuffersAndAttributes ( gl , currentShader , this . _bufferInfo ) ;
843
- }
844
-
845
- _exitDrawBackground ( ) {
846
- const gl = this . gl ;
847
- gl . enable ( gl . BLEND ) ;
848
- }
849
-
850
808
_isTouchingColorGpuStart ( drawableID , candidateIDs , bounds , color3b , mask3b ) {
851
809
this . _doExitDrawRegion ( ) ;
852
810
@@ -858,8 +816,15 @@ class RenderWebGL extends EventEmitter {
858
816
gl . viewport ( 0 , 0 , bounds . width , bounds . height ) ;
859
817
const projection = twgl . m4 . ortho ( bounds . left , bounds . right , bounds . top , bounds . bottom , - 1 , 1 ) ;
860
818
861
- // Clear the query buffer to fully transparent. This will be the color of pixels that fail the stencil test.
862
- gl . clearColor ( 0 , 0 , 0 , 0 ) ;
819
+ let fillBackgroundColor = this . _backgroundColor ;
820
+
821
+ // When using masking such that the background fill color will showing through, ensure we don't
822
+ // fill using the same color that we are trying to detect!
823
+ if ( color3b [ 0 ] > 196 && color3b [ 1 ] > 196 && color3b [ 2 ] > 196 ) {
824
+ fillBackgroundColor = [ 0 , 0 , 0 , 255 ] ;
825
+ }
826
+
827
+ gl . clearColor . apply ( gl , fillBackgroundColor ) ;
863
828
gl . clear ( gl . COLOR_BUFFER_BIT | gl . STENCIL_BUFFER_BIT ) ;
864
829
865
830
let extraUniforms ;
@@ -871,9 +836,6 @@ class RenderWebGL extends EventEmitter {
871
836
}
872
837
873
838
try {
874
- // Using the stencil buffer, mask out the drawing to either the drawable's alpha channel
875
- // or pixels of the drawable which match the mask color, depending on whether a mask color is given.
876
- // Masked-out pixels will not be checked.
877
839
gl . enable ( gl . STENCIL_TEST ) ;
878
840
gl . stencilFunc ( gl . ALWAYS , 1 , 1 ) ;
879
841
gl . stencilOp ( gl . KEEP , gl . KEEP , gl . REPLACE ) ;
@@ -894,25 +856,12 @@ class RenderWebGL extends EventEmitter {
894
856
gl . stencilOp ( gl . KEEP , gl . KEEP , gl . KEEP ) ;
895
857
gl . colorMask ( true , true , true , true ) ;
896
858
897
- // Draw the background as a quad. Drawing a background with gl.clear will not mask to the stenciled area.
898
- this . enterDrawRegion ( this . _backgroundDrawRegionId ) ;
899
-
900
- const uniforms = {
901
- u_backgroundColor : this . _backgroundColor4f
902
- } ;
903
-
904
- const currentShader = this . _shaderManager . getShader ( ShaderManager . DRAW_MODE . background , 0 ) ;
905
- twgl . setUniforms ( currentShader , uniforms ) ;
906
- twgl . drawBufferInfo ( gl , this . _bufferInfo , gl . TRIANGLES ) ;
907
-
908
- // Draw the candidate drawables on top of the background.
909
859
this . _drawThese ( candidateIDs , ShaderManager . DRAW_MODE . default , projection ,
910
860
{ idFilterFunc : testID => testID !== drawableID }
911
861
) ;
912
862
} finally {
913
863
gl . colorMask ( true , true , true , true ) ;
914
864
gl . disable ( gl . STENCIL_TEST ) ;
915
- this . _doExitDrawRegion ( ) ;
916
865
}
917
866
}
918
867
@@ -931,8 +880,7 @@ class RenderWebGL extends EventEmitter {
931
880
}
932
881
933
882
for ( let pixelBase = 0 ; pixelBase < pixels . length ; pixelBase += 4 ) {
934
- // Transparent pixels are masked (either by the drawable's alpha channel or color mask).
935
- if ( pixels [ pixelBase + 3 ] !== 0 && colorMatches ( color3b , pixels , pixelBase ) ) {
883
+ if ( colorMatches ( color3b , pixels , pixelBase ) ) {
936
884
return true ;
937
885
}
938
886
}
@@ -1260,7 +1208,7 @@ class RenderWebGL extends EventEmitter {
1260
1208
gl . viewport ( 0 , 0 , bounds . width , bounds . height ) ;
1261
1209
const projection = twgl . m4 . ortho ( bounds . left , bounds . right , bounds . top , bounds . bottom , - 1 , 1 ) ;
1262
1210
1263
- gl . clearColor . apply ( gl , this . _backgroundColor4f ) ;
1211
+ gl . clearColor . apply ( gl , this . _backgroundColor ) ;
1264
1212
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
1265
1213
this . _drawThese ( this . _drawList , ShaderManager . DRAW_MODE . default , projection ) ;
1266
1214
@@ -1348,13 +1296,6 @@ class RenderWebGL extends EventEmitter {
1348
1296
// Update the CPU position data
1349
1297
drawable . updateCPURenderAttributes ( ) ;
1350
1298
const candidateBounds = drawable . getFastBounds ( ) ;
1351
-
1352
- // Push bounds out to integers. If a drawable extends out into half a pixel, that half-pixel still
1353
- // needs to be tested. Plus, in some areas we construct another rectangle from the union of these,
1354
- // and iterate over its pixels (width * height). Turns out that doesn't work so well when the
1355
- // width/height aren't integers.
1356
- candidateBounds . snapToInt ( ) ;
1357
-
1358
1299
if ( bounds . intersects ( candidateBounds ) ) {
1359
1300
result . push ( {
1360
1301
id,
0 commit comments