@@ -1837,10 +1837,8 @@ class RenderWebGL extends EventEmitter {
1837
1837
1838
1838
// Make a new bufferInfo since this._queryBufferInfo is limited to 480x360
1839
1839
const bufferInfo = twgl . createFramebufferInfo (
1840
- gl ,
1841
- [ { format : gl . RGBA } ] ,
1842
- clampedWidth ,
1843
- clampedHeight
1840
+ gl , [ { format : gl . RGBA } ] ,
1841
+ clampedWidth , clampedHeight
1844
1842
) ;
1845
1843
1846
1844
try {
@@ -1850,12 +1848,9 @@ class RenderWebGL extends EventEmitter {
1850
1848
// and create the projection matrix for the draw.
1851
1849
gl . viewport ( 0 , 0 , clampedWidth , clampedHeight ) ;
1852
1850
const projection = twgl . m4 . ortho (
1853
- scratchBounds . left ,
1854
- scratchBounds . right ,
1855
- scratchBounds . top ,
1856
- scratchBounds . bottom ,
1857
- - 1 ,
1858
- 1
1851
+ scratchBounds . left , scratchBounds . right ,
1852
+ scratchBounds . top , scratchBounds . bottom ,
1853
+ - 1 , 1
1859
1854
) ;
1860
1855
1861
1856
gl . clearColor ( 0 , 0 , 0 , 0 ) ;
@@ -1877,20 +1872,13 @@ class RenderWebGL extends EventEmitter {
1877
1872
1878
1873
const data = new Uint8Array ( Math . floor ( clampedWidth * clampedHeight * 4 ) ) ;
1879
1874
gl . readPixels (
1880
- 0 ,
1881
- 0 ,
1882
- clampedWidth ,
1883
- clampedHeight ,
1884
- gl . RGBA ,
1885
- gl . UNSIGNED_BYTE ,
1886
- data
1875
+ 0 , 0 , clampedWidth , clampedHeight ,
1876
+ gl . RGBA , gl . UNSIGNED_BYTE , data
1887
1877
) ;
1888
1878
// readPixels can only read into a Uint8Array, but ImageData has to take a Uint8ClampedArray.
1889
1879
// We can share the same underlying buffer between them to avoid having to copy any data.
1890
1880
const imageData = new ImageData (
1891
- new Uint8ClampedArray ( data . buffer ) ,
1892
- clampedWidth ,
1893
- clampedHeight
1881
+ new Uint8ClampedArray ( data . buffer ) , clampedWidth , clampedHeight
1894
1882
) ;
1895
1883
1896
1884
// On high-DPI devices, the canvas' width (in canvas pixels) will be larger than its width in CSS pixels.
@@ -1902,10 +1890,8 @@ class RenderWebGL extends EventEmitter {
1902
1890
1903
1891
return {
1904
1892
imageData,
1905
- x : canvasSpaceBounds . left * ratio ,
1906
- y : canvasSpaceBounds . bottom * ratio ,
1907
- width : canvasSpaceBounds . width * ratio ,
1908
- height : canvasSpaceBounds . height * ratio
1893
+ x : canvasSpaceBounds . left * ratio , y : canvasSpaceBounds . bottom * ratio ,
1894
+ width : canvasSpaceBounds . width * ratio , height : canvasSpaceBounds . height * ratio
1909
1895
} ;
1910
1896
} finally {
1911
1897
gl . deleteFramebuffer ( bufferInfo . framebuffer ) ;
@@ -1942,58 +1928,42 @@ class RenderWebGL extends EventEmitter {
1942
1928
1943
1929
const bounds = new Rectangle ( ) ;
1944
1930
bounds . initFromBounds (
1945
- scratchX - radius ,
1946
- scratchX + radius ,
1947
- scratchY - radius ,
1948
- scratchY + radius
1931
+ scratchX - radius , scratchX + radius ,
1932
+ scratchY - radius , scratchY + radius
1949
1933
) ;
1950
1934
1951
1935
const pickX = scratchX - bounds . left ;
1952
1936
const pickY = bounds . top - scratchY ;
1953
1937
1954
1938
gl . viewport ( 0 , 0 , bounds . width , bounds . height ) ;
1955
1939
const projection = twgl . m4 . ortho (
1956
- bounds . left ,
1957
- bounds . right ,
1958
- bounds . top ,
1959
- bounds . bottom ,
1960
- - 1 ,
1961
- 1
1940
+ bounds . left , bounds . right ,
1941
+ bounds . top , bounds . bottom ,
1942
+ - 1 , 1
1962
1943
) ;
1963
1944
1964
1945
gl . clearColor ( ...this . _backgroundColor4f ) ;
1965
1946
gl . clear ( gl . COLOR_BUFFER_BIT ) ;
1966
1947
this . _drawThese (
1967
- this . _drawList ,
1968
- ShaderManager . DRAW_MODE . default ,
1969
- projection
1948
+ this . _drawList , ShaderManager . DRAW_MODE . default , projection
1970
1949
) ;
1971
1950
1972
1951
const data = new Uint8Array ( Math . floor ( bounds . width * bounds . height * 4 ) ) ;
1973
1952
gl . readPixels (
1974
- 0 ,
1975
- 0 ,
1976
- bounds . width ,
1977
- bounds . height ,
1978
- gl . RGBA ,
1979
- gl . UNSIGNED_BYTE ,
1980
- data
1953
+ 0 , 0 , bounds . width , bounds . height ,
1954
+ gl . RGBA , gl . UNSIGNED_BYTE , data
1981
1955
) ;
1982
1956
1983
1957
const pixelBase = Math . floor ( 4 * ( pickY * bounds . width + pickX ) ) ;
1984
1958
const color = {
1985
- r : data [ pixelBase ] ,
1986
- g : data [ pixelBase + 1 ] ,
1987
- b : data [ pixelBase + 2 ] ,
1988
- a : data [ pixelBase + 3 ]
1959
+ r : data [ pixelBase ] , g : data [ pixelBase + 1 ] ,
1960
+ b : data [ pixelBase + 2 ] , a : data [ pixelBase + 3 ]
1989
1961
} ;
1990
1962
1991
1963
if ( this . _debugCanvas ) {
1992
1964
this . _debugCanvas . width = bounds . width ;
1993
1965
this . _debugCanvas . height = bounds . height ;
1994
- const ctx = this . _debugCanvas . getContext ( '2d' , {
1995
- willReadFrequently : true
1996
- } ) ;
1966
+ const ctx = this . _debugCanvas . getContext ( '2d' , { willReadFrequently : true } ) ;
1997
1967
const imageData = ctx . createImageData ( bounds . width , bounds . height ) ;
1998
1968
imageData . data . set ( data ) ;
1999
1969
ctx . putImageData ( imageData , 0 , 0 ) ;
@@ -2049,9 +2019,7 @@ class RenderWebGL extends EventEmitter {
2049
2019
if ( ! this . offscreenTouching ) {
2050
2020
bounds . clamp ( this . _xLeft , this . _xRight , this . _yBottom , this . _yTop ) ;
2051
2021
}
2052
- if ( bounds . width === 0 || bounds . height === 0 ) {
2053
- return null ;
2054
- }
2022
+ if ( bounds . width === 0 || bounds . height === 0 ) return null ;
2055
2023
return bounds ;
2056
2024
}
2057
2025
@@ -2065,9 +2033,7 @@ class RenderWebGL extends EventEmitter {
2065
2033
_candidatesTouching ( drawableID , candidateIDs ) {
2066
2034
const bounds = this . _touchingBounds ( drawableID ) ;
2067
2035
const result = [ ] ;
2068
- if ( bounds === null ) {
2069
- return result ;
2070
- }
2036
+ if ( bounds === null ) return result ;
2071
2037
// iterate through the drawables list BACKWARDS - we want the top most item to be the first we check
2072
2038
for ( let index = candidateIDs . length - 1 ; index >= 0 ; index -- ) {
2073
2039
const id = candidateIDs [ index ] ;
@@ -2092,8 +2058,7 @@ class RenderWebGL extends EventEmitter {
2092
2058
2093
2059
if ( bounds . intersects ( candidateBounds ) ) {
2094
2060
result . push ( {
2095
- id,
2096
- drawable,
2061
+ id, drawable,
2097
2062
intersection : Rectangle . intersect ( bounds , candidateBounds )
2098
2063
} ) ;
2099
2064
}
@@ -2111,9 +2076,7 @@ class RenderWebGL extends EventEmitter {
2111
2076
*/
2112
2077
_candidatesBounds ( candidates ) {
2113
2078
return candidates . reduce ( ( memo , { intersection} ) => {
2114
- if ( ! memo ) {
2115
- return intersection ;
2116
- }
2079
+ if ( ! memo ) return intersection ;
2117
2080
// store the union of the two rectangles in our static rectangle instance
2118
2081
return Rectangle . union ( memo , intersection , __candidatesBounds ) ;
2119
2082
} , null ) ;
@@ -2223,9 +2186,7 @@ class RenderWebGL extends EventEmitter {
2223
2186
*/
2224
2187
return ;
2225
2188
}
2226
- if ( 'skinId' in properties ) {
2227
- this . updateDrawableSkinId ( drawableID , properties . skinId ) ;
2228
- }
2189
+ if ( 'skinId' in properties ) this . updateDrawableSkinId ( drawableID , properties . skinId ) ;
2229
2190
drawable . updateProperties ( properties ) ;
2230
2191
}
2231
2192
@@ -2252,17 +2213,11 @@ class RenderWebGL extends EventEmitter {
2252
2213
const inset = Math . floor ( Math . min ( aabb . width , aabb . height ) / 2 ) ;
2253
2214
2254
2215
const sx = this . _xRight - Math . min ( FENCE_WIDTH , inset ) ;
2255
- if ( aabb . right + dx < - sx ) {
2256
- x = Math . ceil ( drawable . _position [ 0 ] - ( sx + aabb . right ) ) ;
2257
- } else if ( aabb . left + dx > sx ) {
2258
- x = Math . floor ( drawable . _position [ 0 ] + ( sx - aabb . left ) ) ;
2259
- }
2216
+ if ( aabb . right + dx < - sx ) x = Math . ceil ( drawable . _position [ 0 ] - ( sx + aabb . right ) ) ;
2217
+ else if ( aabb . left + dx > sx ) x = Math . floor ( drawable . _position [ 0 ] + ( sx - aabb . left ) ) ;
2260
2218
const sy = this . _yTop - Math . min ( FENCE_WIDTH , inset ) ;
2261
- if ( aabb . top + dy < - sy ) {
2262
- y = Math . ceil ( drawable . _position [ 1 ] - ( sy + aabb . top ) ) ;
2263
- } else if ( aabb . bottom + dy > sy ) {
2264
- y = Math . floor ( drawable . _position [ 1 ] + ( sy - aabb . bottom ) ) ;
2265
- }
2219
+ if ( aabb . top + dy < - sy ) y = Math . ceil ( drawable . _position [ 1 ] - ( sy + aabb . top ) ) ;
2220
+ else if ( aabb . bottom + dy > sy ) y = Math . floor ( drawable . _position [ 1 ] + ( sy - aabb . bottom ) ) ;
2266
2221
return [ x , y ] ;
2267
2222
}
2268
2223
@@ -2326,15 +2281,11 @@ class RenderWebGL extends EventEmitter {
2326
2281
penStamp ( penSkinID , stampID ) {
2327
2282
this . dirty = true ;
2328
2283
const stampDrawable = this . _allDrawables [ stampID ] ;
2329
- if ( ! stampDrawable ) {
2330
- return ;
2331
- }
2284
+ if ( ! stampDrawable ) return ;
2332
2285
2333
2286
// TW: The bounds will be snapped later
2334
2287
const bounds = this . _unsnappedTouchingBounds ( stampID ) ;
2335
- if ( ! bounds ) {
2336
- return ;
2337
- }
2288
+ if ( ! bounds ) return ;
2338
2289
2339
2290
this . _doExitDrawRegion ( ) ;
2340
2291
@@ -2355,17 +2306,13 @@ class RenderWebGL extends EventEmitter {
2355
2306
gl . viewport (
2356
2307
this . _nativeSize [ 0 ] * 0.5 * quality + bounds . left ,
2357
2308
this . _nativeSize [ 1 ] * 0.5 * quality - bounds . top ,
2358
- bounds . width ,
2359
- bounds . height
2309
+ bounds . width , bounds . height
2360
2310
) ;
2361
2311
const projection = twgl . m4 . ortho (
2362
2312
// TW: We have to convert the snapped "screen-space" back to "stage-space" for rendering.
2363
- bounds . left / quality ,
2364
- bounds . right / quality ,
2365
- bounds . top / quality ,
2366
- bounds . bottom / quality ,
2367
- - 1 ,
2368
- 1
2313
+ bounds . left / quality , bounds . right / quality ,
2314
+ bounds . top / quality , bounds . bottom / quality ,
2315
+ - 1 , 1
2369
2316
) ;
2370
2317
2371
2318
// Draw the stamped sprite onto the PenSkin's framebuffer.
@@ -2417,29 +2364,20 @@ class RenderWebGL extends EventEmitter {
2417
2364
2418
2365
if ( ! this . _pickBufferInfo ) {
2419
2366
this . _pickBufferInfo = twgl . createFramebufferInfo (
2420
- gl ,
2421
- attachments ,
2422
- MAX_TOUCH_SIZE [ 0 ] ,
2423
- MAX_TOUCH_SIZE [ 1 ]
2367
+ gl , attachments , MAX_TOUCH_SIZE [ 0 ] , MAX_TOUCH_SIZE [ 1 ]
2424
2368
) ;
2425
2369
}
2426
2370
2427
2371
/** @todo should we create this on demand to save memory? */
2428
2372
// A 480x360 32-bpp buffer is 675 KiB.
2429
2373
if ( this . _queryBufferInfo ) {
2430
2374
twgl . resizeFramebufferInfo (
2431
- gl ,
2432
- this . _queryBufferInfo ,
2433
- attachments ,
2434
- width ,
2435
- height
2375
+ gl , this . _queryBufferInfo ,
2376
+ attachments , width , height
2436
2377
) ;
2437
2378
} else {
2438
2379
this . _queryBufferInfo = twgl . createFramebufferInfo (
2439
- gl ,
2440
- attachments ,
2441
- width ,
2442
- height
2380
+ gl , attachments , width , height
2443
2381
) ;
2444
2382
}
2445
2383
}
@@ -2473,9 +2411,7 @@ class RenderWebGL extends EventEmitter {
2473
2411
* state.
2474
2412
*/
2475
2413
_doExitDrawRegion ( ) {
2476
- if ( this . _exitRegion !== null ) {
2477
- this . _exitRegion ( ) ;
2478
- }
2414
+ if ( this . _exitRegion !== null ) this . _exitRegion ( ) ;
2479
2415
this . _exitRegion = null ;
2480
2416
this . _regionId = null ;
2481
2417
}
@@ -2518,7 +2454,6 @@ class RenderWebGL extends EventEmitter {
2518
2454
const drawable = this . _allDrawables [ drawableID ] ;
2519
2455
2520
2456
const uniforms = { } ;
2521
- console . log ( 0 , drawable . uniformApplied , ! this . renderOffscreen ) ;
2522
2457
if ( ! this . renderOffscreen && drawable . uniformApplied ) {
2523
2458
if ( drawMode === ShaderManager . DRAW_MODE . default && drawable . skin ) {
2524
2459
// If rotationCenterDirty or skinScaleDirty is dirty, then set _calculateTransform first
@@ -2531,9 +2466,7 @@ class RenderWebGL extends EventEmitter {
2531
2466
2532
2467
if ( ! drawable . inViewport ( halfNativeSizeX , halfNativeSizeY ) ) continue ;
2533
2468
// If unconfirm was not set before
2534
- if ( ! uniformHasBeenSet ) {
2535
- Object . assign ( uniforms , drawable . getUniforms ( ) ) ;
2536
- }
2469
+ if ( ! uniformHasBeenSet ) Object . assign ( uniforms , drawable . getUniforms ( ) ) ;
2537
2470
} else {
2538
2471
Object . assign ( uniforms , drawable . getUniforms ( ) ) ;
2539
2472
}
@@ -2567,8 +2500,7 @@ class RenderWebGL extends EventEmitter {
2567
2500
2568
2501
let effectBits = drawable . enabledEffects ;
2569
2502
effectBits &= Object . prototype . hasOwnProperty . call ( opts , 'effectMask' )
2570
- ? opts . effectMask
2571
- : effectBits ;
2503
+ ? opts . effectMask : effectBits ;
2572
2504
const newShader = this . _shaderManager . getShader ( drawMode , effectBits ) ;
2573
2505
2574
2506
// Manually perform region check. Do not create functions inside a
@@ -2585,28 +2517,21 @@ class RenderWebGL extends EventEmitter {
2585
2517
} ) ;
2586
2518
}
2587
2519
2588
- console . log ( 2 , drawable . uniformApplied , ! this . renderOffscreen ) ;
2589
- if ( ! this . renderOffscreen && drawable . uniformApplied ) {
2590
- Object . assign ( uniforms , drawable . getUniforms ( ) ) ;
2591
- } else {
2520
+ if ( ! this . renderOffscreen && drawable . uniformApplied ) Object . assign ( uniforms , drawable . getUniforms ( ) ) ;
2521
+ else {
2592
2522
drawable . uniformApplied = true ;
2593
2523
Object . assign (
2594
- uniforms ,
2595
- drawable . skin . getUniforms ( drawableScale ) ,
2596
- drawable . getUniforms ( )
2524
+ uniforms , drawable . skin . getUniforms ( drawableScale ) , drawable . getUniforms ( )
2597
2525
) ;
2598
2526
}
2599
2527
2600
2528
// Apply extra uniforms after the Drawable's, to allow overwriting.
2601
- if ( opts . extraUniforms ) {
2602
- Object . assign ( uniforms , opts . extraUniforms ) ;
2603
- }
2529
+ if ( opts . extraUniforms ) Object . assign ( uniforms , opts . extraUniforms ) ;
2604
2530
2605
2531
if ( uniforms . u_skin ) {
2606
2532
twgl . setTextureParameters ( gl , uniforms . u_skin , {
2607
2533
minMag : drawable . skin . useNearest ( drawableScale , drawable )
2608
- ? gl . NEAREST
2609
- : gl . LINEAR
2534
+ ? gl . NEAREST : gl . LINEAR
2610
2535
} ) ;
2611
2536
}
2612
2537
@@ -2628,9 +2553,7 @@ class RenderWebGL extends EventEmitter {
2628
2553
2629
2554
const [ width , height ] = drawable . skin . size ;
2630
2555
// No points in the hull if invisible or size is 0.
2631
- if ( ! drawable . getVisible ( ) || width === 0 || height === 0 ) {
2632
- return [ ] ;
2633
- }
2556
+ if ( ! drawable . getVisible ( ) || width === 0 || height === 0 ) return [ ] ;
2634
2557
2635
2558
drawable . updateCPURenderAttributes ( ) ;
2636
2559
@@ -2689,9 +2612,7 @@ class RenderWebGL extends EventEmitter {
2689
2612
}
2690
2613
2691
2614
// If we managed to loop all the way through, there are no opaque pixels on this row. Go to the next one
2692
- if ( x >= width ) {
2693
- continue ;
2694
- }
2615
+ if ( x >= width ) continue ;
2695
2616
2696
2617
// Because leftEndPointIndex is initialized to -1, this is skipped for the first two rows.
2697
2618
// It runs only when there are enough points in the left hull to make at least one line.
0 commit comments