@@ -188,23 +188,9 @@ class RenderWebGL extends EventEmitter {
188
188
/** @type {function } */
189
189
this . _exitRegion = null ;
190
190
191
- /** @type {object } */
192
- this . _backgroundDrawRegionId = {
193
- enter : ( ) => this . _enterDrawBackground ( ) ,
194
- exit : ( ) => this . _exitDrawBackground ( )
195
- } ;
196
-
197
191
/** @type {Array.<snapshotCallback> } */
198
192
this . _snapshotCallbacks = [ ] ;
199
193
200
- /** @type {Array<number> } */
201
- // Don't set this directly-- use setBackgroundColor so it stays in sync with _backgroundColor3b
202
- this . _backgroundColor4f = [ 0 , 0 , 0 , 1 ] ;
203
-
204
- /** @type {Uint8ClampedArray } */
205
- // Don't set this directly-- use setBackgroundColor so it stays in sync with _backgroundColor4f
206
- this . _backgroundColor3b = new Uint8ClampedArray ( 3 ) ;
207
-
208
194
this . _createGeometry ( ) ;
209
195
210
196
this . on ( RenderConstants . Events . NativeSizeChanged , this . onNativeSizeChanged ) ;
@@ -264,14 +250,7 @@ class RenderWebGL extends EventEmitter {
264
250
* @param {number } blue The blue component for the background.
265
251
*/
266
252
setBackgroundColor ( red , green , blue ) {
267
- this . _backgroundColor4f [ 0 ] = red ;
268
- this . _backgroundColor4f [ 1 ] = green ;
269
- this . _backgroundColor4f [ 2 ] = blue ;
270
-
271
- this . _backgroundColor3b [ 0 ] = red * 255 ;
272
- this . _backgroundColor3b [ 1 ] = green * 255 ;
273
- this . _backgroundColor3b [ 2 ] = blue * 255 ;
274
-
253
+ this . _backgroundColor = [ red , green , blue , 1 ] ;
275
254
}
276
255
277
256
/**
@@ -650,7 +629,7 @@ class RenderWebGL extends EventEmitter {
650
629
651
630
twgl . bindFramebufferInfo ( gl , null ) ;
652
631
gl . viewport ( 0 , 0 , gl . canvas . width , gl . canvas . height ) ;
653
- gl . clearColor . apply ( gl , this . _backgroundColor4f ) ;
632
+ gl . clearColor . apply ( gl , this . _backgroundColor ) ;
654
633
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
655
634
656
635
this . _drawThese ( this . _drawList , ShaderManager . DRAW_MODE . default , this . _projection ) ;
@@ -766,20 +745,12 @@ class RenderWebGL extends EventEmitter {
766
745
*/
767
746
isTouchingColor ( drawableID , color3b , mask3b ) {
768
747
const candidates = this . _candidatesTouching ( drawableID , this . _visibleDrawList ) ;
769
-
770
- let bounds ;
771
- if ( colorMatches ( color3b , this . _backgroundColor3b , 0 ) ) {
772
- // If the color we're checking for is the background color, don't confine the check to
773
- // candidate drawables' bounds--since the background spans the entire stage, we must check
774
- // everything that lies inside the drawable.
775
- bounds = this . _touchingBounds ( drawableID ) ;
776
- } else if ( candidates . length === 0 ) {
777
- // If not checking for the background color, we can return early if there are no candidate drawables.
748
+ if ( candidates . length === 0 ) {
778
749
return false ;
779
- } else {
780
- bounds = this . _candidatesBounds ( candidates ) ;
781
750
}
782
751
752
+ const bounds = this . _candidatesBounds ( candidates ) ;
753
+
783
754
const maxPixelsForCPU = this . _getMaxPixelsForCPU ( ) ;
784
755
785
756
const debugCanvasContext = this . _debugCanvas && this . _debugCanvas . getContext ( '2d' ) ;
@@ -840,19 +811,6 @@ class RenderWebGL extends EventEmitter {
840
811
}
841
812
}
842
813
843
- _enterDrawBackground ( ) {
844
- const gl = this . gl ;
845
- const currentShader = this . _shaderManager . getShader ( ShaderManager . DRAW_MODE . background , 0 ) ;
846
- gl . disable ( gl . BLEND ) ;
847
- gl . useProgram ( currentShader . program ) ;
848
- twgl . setBuffersAndAttributes ( gl , currentShader , this . _bufferInfo ) ;
849
- }
850
-
851
- _exitDrawBackground ( ) {
852
- const gl = this . gl ;
853
- gl . enable ( gl . BLEND ) ;
854
- }
855
-
856
814
_isTouchingColorGpuStart ( drawableID , candidateIDs , bounds , color3b , mask3b ) {
857
815
this . _doExitDrawRegion ( ) ;
858
816
@@ -864,8 +822,15 @@ class RenderWebGL extends EventEmitter {
864
822
gl . viewport ( 0 , 0 , bounds . width , bounds . height ) ;
865
823
const projection = twgl . m4 . ortho ( bounds . left , bounds . right , bounds . top , bounds . bottom , - 1 , 1 ) ;
866
824
867
- // Clear the query buffer to fully transparent. This will be the color of pixels that fail the stencil test.
868
- gl . clearColor ( 0 , 0 , 0 , 0 ) ;
825
+ let fillBackgroundColor = this . _backgroundColor ;
826
+
827
+ // When using masking such that the background fill color will showing through, ensure we don't
828
+ // fill using the same color that we are trying to detect!
829
+ if ( color3b [ 0 ] > 196 && color3b [ 1 ] > 196 && color3b [ 2 ] > 196 ) {
830
+ fillBackgroundColor = [ 0 , 0 , 0 , 255 ] ;
831
+ }
832
+
833
+ gl . clearColor . apply ( gl , fillBackgroundColor ) ;
869
834
gl . clear ( gl . COLOR_BUFFER_BIT | gl . STENCIL_BUFFER_BIT ) ;
870
835
871
836
let extraUniforms ;
@@ -877,9 +842,6 @@ class RenderWebGL extends EventEmitter {
877
842
}
878
843
879
844
try {
880
- // Using the stencil buffer, mask out the drawing to either the drawable's alpha channel
881
- // or pixels of the drawable which match the mask color, depending on whether a mask color is given.
882
- // Masked-out pixels will not be checked.
883
845
gl . enable ( gl . STENCIL_TEST ) ;
884
846
gl . stencilFunc ( gl . ALWAYS , 1 , 1 ) ;
885
847
gl . stencilOp ( gl . KEEP , gl . KEEP , gl . REPLACE ) ;
@@ -900,25 +862,12 @@ class RenderWebGL extends EventEmitter {
900
862
gl . stencilOp ( gl . KEEP , gl . KEEP , gl . KEEP ) ;
901
863
gl . colorMask ( true , true , true , true ) ;
902
864
903
- // Draw the background as a quad. Drawing a background with gl.clear will not mask to the stenciled area.
904
- this . enterDrawRegion ( this . _backgroundDrawRegionId ) ;
905
-
906
- const uniforms = {
907
- u_backgroundColor : this . _backgroundColor4f
908
- } ;
909
-
910
- const currentShader = this . _shaderManager . getShader ( ShaderManager . DRAW_MODE . background , 0 ) ;
911
- twgl . setUniforms ( currentShader , uniforms ) ;
912
- twgl . drawBufferInfo ( gl , this . _bufferInfo , gl . TRIANGLES ) ;
913
-
914
- // Draw the candidate drawables on top of the background.
915
865
this . _drawThese ( candidateIDs , ShaderManager . DRAW_MODE . default , projection ,
916
866
{ idFilterFunc : testID => testID !== drawableID }
917
867
) ;
918
868
} finally {
919
869
gl . colorMask ( true , true , true , true ) ;
920
870
gl . disable ( gl . STENCIL_TEST ) ;
921
- this . _doExitDrawRegion ( ) ;
922
871
}
923
872
}
924
873
@@ -937,8 +886,7 @@ class RenderWebGL extends EventEmitter {
937
886
}
938
887
939
888
for ( let pixelBase = 0 ; pixelBase < pixels . length ; pixelBase += 4 ) {
940
- // Transparent pixels are masked (either by the drawable's alpha channel or color mask).
941
- if ( pixels [ pixelBase + 3 ] !== 0 && colorMatches ( color3b , pixels , pixelBase ) ) {
889
+ if ( colorMatches ( color3b , pixels , pixelBase ) ) {
942
890
return true ;
943
891
}
944
892
}
@@ -1373,7 +1321,7 @@ class RenderWebGL extends EventEmitter {
1373
1321
gl . viewport ( 0 , 0 , bounds . width , bounds . height ) ;
1374
1322
const projection = twgl . m4 . ortho ( bounds . left , bounds . right , bounds . top , bounds . bottom , - 1 , 1 ) ;
1375
1323
1376
- gl . clearColor . apply ( gl , this . _backgroundColor4f ) ;
1324
+ gl . clearColor . apply ( gl , this . _backgroundColor ) ;
1377
1325
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
1378
1326
this . _drawThese ( this . _drawList , ShaderManager . DRAW_MODE . default , projection ) ;
1379
1327
@@ -1461,13 +1409,6 @@ class RenderWebGL extends EventEmitter {
1461
1409
// Update the CPU position data
1462
1410
drawable . updateCPURenderAttributes ( ) ;
1463
1411
const candidateBounds = drawable . getFastBounds ( ) ;
1464
-
1465
- // Push bounds out to integers. If a drawable extends out into half a pixel, that half-pixel still
1466
- // needs to be tested. Plus, in some areas we construct another rectangle from the union of these,
1467
- // and iterate over its pixels (width * height). Turns out that doesn't work so well when the
1468
- // width/height aren't integers.
1469
- candidateBounds . snapToInt ( ) ;
1470
-
1471
1412
if ( bounds . intersects ( candidateBounds ) ) {
1472
1413
result . push ( {
1473
1414
id,
0 commit comments