8
8
// of 9 and 16.
9
9
{ { { GL_POOL_TEMP_BUFFERS_SIZE = 2 * 9 * 16 } } } // = 288
10
10
11
+ { { {
12
+ global . isCurrentContextWebGL2 = function isCurrentContextWebGL2 ( ) {
13
+ if ( MIN_WEBGL_VERSION >= 2 ) return 'true' ;
14
+ if ( MAX_WEBGL_VERSION <= 1 ) return 'false' ;
15
+ return 'GL.currentContext.version >= 2' ;
16
+ }
17
+ } } }
18
+
11
19
var LibraryGL = {
12
20
13
21
// For functions such as glDrawBuffers, glInvalidateFramebuffer and glInvalidateSubFramebuffer that need to pass a short array to the WebGL API,
@@ -483,7 +491,7 @@ var LibraryGL = {
483
491
break ;
484
492
default :
485
493
#if MAX_WEBGL_VERSION >= 2
486
- if ( GL . currentContext . version >= 2 ) {
494
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
487
495
if ( dataType == 0x8368 /* GL_UNSIGNED_INT_2_10_10_10_REV */ || dataType == 0x8D9F /* GL_INT_2_10_10_10_REV */ ) {
488
496
sizeBytes = 4 ;
489
497
break ;
@@ -618,6 +626,9 @@ var LibraryGL = {
618
626
} else {
619
627
#endif
620
628
629
+ #if MIN_WEBGL_VERSION >= 2
630
+ var ctx = canvas . getContext ( "webgl2" , webGLContextAttributes ) ;
631
+ #else
621
632
var ctx =
622
633
#if MAX_WEBGL_VERSION >= 2
623
634
( webGLContextAttributes . majorVersion > 1 )
@@ -635,6 +646,7 @@ var LibraryGL = {
635
646
|| canvas . getContext ( "experimental-webgl" , webGLContextAttributes )
636
647
#endif
637
648
) ;
649
+ #endif // MAX_WEBGL_VERSION >= 2
638
650
639
651
#if GL_PREINITIALIZED_CONTEXT
640
652
}
@@ -1214,7 +1226,7 @@ var LibraryGL = {
1214
1226
var glVersion = GLctx . getParameter ( 0x1F02 /*GL_VERSION*/ ) ;
1215
1227
// return GLES version string corresponding to the version of the WebGL context
1216
1228
#if MAX_WEBGL_VERSION >= 2
1217
- if ( GL . currentContext . version >= 2 ) glVersion = 'OpenGL ES 3.0 (' + glVersion + ')' ;
1229
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) glVersion = 'OpenGL ES 3.0 (' + glVersion + ')' ;
1218
1230
else
1219
1231
#endif
1220
1232
{
@@ -1448,7 +1460,7 @@ var LibraryGL = {
1448
1460
glCompressedTexImage2D__sig : 'viiiiiiii' ,
1449
1461
glCompressedTexImage2D : function ( target , level , internalFormat , width , height , border , imageSize , data ) {
1450
1462
#if MAX_WEBGL_VERSION >= 2
1451
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1463
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1452
1464
if ( GLctx . currentPixelUnpackBufferBinding ) {
1453
1465
GLctx [ 'compressedTexImage2D' ] ( target , level , internalFormat , width , height , border , imageSize , data ) ;
1454
1466
} else {
@@ -1464,7 +1476,7 @@ var LibraryGL = {
1464
1476
glCompressedTexSubImage2D__sig : 'viiiiiiiii ',
1465
1477
glCompressedTexSubImage2D : function ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) {
1466
1478
#if MAX_WEBGL_VERSION >= 2
1467
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1479
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1468
1480
if ( GLctx . currentPixelUnpackBufferBinding ) {
1469
1481
GLctx [ 'compressedTexSubImage2D' ] ( target , level , xoffset , yoffset , width , height , format , imageSize , data ) ;
1470
1482
} else {
@@ -1544,7 +1556,7 @@ var LibraryGL = {
1544
1556
glTexImage2D : function ( target , level , internalFormat , width , height , border , format , type , pixels ) {
1545
1557
#if MAX_WEBGL_VERSION >= 2
1546
1558
#if WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION
1547
- if ( GL . currentContext . version >= 2 ) {
1559
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1548
1560
// WebGL 1 unsized texture internalFormats are no longer supported in WebGL 2, so patch those format
1549
1561
// enums to the ones that are present in WebGL 2.
1550
1562
if ( format = = 0x1902 /*GL_DEPTH_COMPONENT*/ && internalFormat == 0x1902 /*GL_DEPTH_COMPONENT*/ && type == 0x1405 /*GL_UNSIGNED_INT*/ ) {
@@ -1561,7 +1573,7 @@ var LibraryGL = {
1561
1573
}
1562
1574
}
1563
1575
#endif
1564
- if ( GL . currentContext . version >= 2 ) {
1576
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1565
1577
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1566
1578
if ( GLctx . currentPixelUnpackBufferBinding ) {
1567
1579
GLctx . texImage2D( target , level, internalFormat, width, height, border, format, type, pixels) ;
@@ -1586,14 +1598,14 @@ var LibraryGL = {
1586
1598
glTexSubImage2D : function ( target , level , xoffset , yoffset , width , height , format , type , pixels ) {
1587
1599
#if MAX_WEBGL_VERSION >= 2
1588
1600
#if WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION
1589
- if ( GL . currentContext . version >= 2 ) {
1601
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1590
1602
// In WebGL 1 to do half float textures, one uses the type enum GL_HALF_FLOAT_OES, but in
1591
1603
// WebGL 2 when half float textures were adopted to the core spec, the enum changed value
1592
1604
// which breaks backwards compatibility. Route old enum number to the new one.
1593
1605
if ( type = = 0x8d61 /*GL_HALF_FLOAT_OES*/ ) type = 0x140B /*GL_HALF_FLOAT*/ ;
1594
1606
}
1595
1607
#endif
1596
- if ( GL . currentContext . version >= 2 ) {
1608
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
1597
1609
// WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1598
1610
if ( GLctx . currentPixelUnpackBufferBinding ) {
1599
1611
GLctx . texSubImage2D( target , level, xoffset, yoffset, width, height, format, type, pixels) ;
@@ -1619,7 +1631,7 @@ var LibraryGL = {
1619
1631
] ,
1620
1632
glReadPixels : function ( x , y , width , height , format , type , pixels ) {
1621
1633
#if MAX_WEBGL_VERSION >= 2
1622
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1634
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1623
1635
if ( GLctx . currentPixelPackBufferBinding ) {
1624
1636
GLctx . readPixels ( x , y , width , height , format , type , pixels ) ;
1625
1637
} else {
@@ -1800,7 +1812,7 @@ var LibraryGL = {
1800
1812
#endif
1801
1813
1802
1814
#if MAX_WEBGL_VERSION >= 2
1803
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1815
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1804
1816
if ( data ) {
1805
1817
GLctx . bufferData ( target , HEAPU8 , usage , data , size ) ;
1806
1818
} else {
@@ -1819,7 +1831,7 @@ var LibraryGL = {
1819
1831
glBufferSubData__sig : 'viiii' ,
1820
1832
glBufferSubData : function ( target , offset , size , data ) {
1821
1833
#if MAX_WEBGL_VERSION >= 2
1822
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1834
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
1823
1835
GLctx . bufferSubData( target , offset, HEAPU8 , data, size) ;
1824
1836
return ;
1825
1837
}
@@ -2243,7 +2255,7 @@ var LibraryGL = {
2243
2255
#else
2244
2256
2245
2257
#if MAX_WEBGL_VERSION >= 2
2246
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2258
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2247
2259
GLctx . uniform1iv ( GL . uniforms [ location ] , HEAP32 , value> > 2 , count) ;
2248
2260
return ;
2249
2261
}
@@ -2286,7 +2298,7 @@ var LibraryGL = {
2286
2298
#else
2287
2299
2288
2300
#if MAX_WEBGL_VERSION >= 2
2289
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2301
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2290
2302
GLctx . uniform2iv ( GL . uniforms [ location ] , HEAP32 , value> > 2 , count* 2 ) ;
2291
2303
return ;
2292
2304
}
@@ -2330,7 +2342,7 @@ var LibraryGL = {
2330
2342
#else
2331
2343
2332
2344
#if MAX_WEBGL_VERSION >= 2
2333
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2345
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2334
2346
GLctx . uniform3iv ( GL . uniforms [ location ] , HEAP32 , value> > 2 , count* 3 ) ;
2335
2347
return ;
2336
2348
}
@@ -2375,7 +2387,7 @@ var LibraryGL = {
2375
2387
#else
2376
2388
2377
2389
#if MAX_WEBGL_VERSION >= 2
2378
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2390
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2379
2391
GLctx . uniform4iv ( GL . uniforms [ location ] , HEAP32 , value> > 2 , count* 4 ) ;
2380
2392
return ;
2381
2393
}
@@ -2421,7 +2433,7 @@ var LibraryGL = {
2421
2433
#else
2422
2434
2423
2435
#if MAX_WEBGL_VERSION >= 2
2424
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2436
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2425
2437
GLctx . uniform1fv ( GL . uniforms [ location ] , HEAPF32 , value> > 2 , count) ;
2426
2438
return ;
2427
2439
}
@@ -2464,7 +2476,7 @@ var LibraryGL = {
2464
2476
#else
2465
2477
2466
2478
#if MAX_WEBGL_VERSION >= 2
2467
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2479
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2468
2480
GLctx . uniform2fv ( GL . uniforms [ location ] , HEAPF32 , value> > 2 , count* 2 ) ;
2469
2481
return ;
2470
2482
}
@@ -2508,7 +2520,7 @@ var LibraryGL = {
2508
2520
#else
2509
2521
2510
2522
#if MAX_WEBGL_VERSION >= 2
2511
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2523
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2512
2524
GLctx . uniform3fv ( GL . uniforms [ location ] , HEAPF32 , value> > 2 , count* 3 ) ;
2513
2525
return ;
2514
2526
}
@@ -2553,7 +2565,7 @@ var LibraryGL = {
2553
2565
#else
2554
2566
2555
2567
#if MAX_WEBGL_VERSION >= 2
2556
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2568
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2557
2569
GLctx . uniform4fv ( GL . uniforms [ location ] , HEAPF32 , value> > 2 , count* 4 ) ;
2558
2570
return ;
2559
2571
}
@@ -2603,7 +2615,7 @@ var LibraryGL = {
2603
2615
#else
2604
2616
2605
2617
#if MAX_WEBGL_VERSION >= 2
2606
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2618
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2607
2619
GLctx . uniformMatrix2fv ( GL . uniforms [ location ] , ! ! transpose, HEAPF32 , value> > 2 , count* 4 ) ;
2608
2620
return ;
2609
2621
}
@@ -2649,7 +2661,7 @@ var LibraryGL = {
2649
2661
#else
2650
2662
2651
2663
#if MAX_WEBGL_VERSION >= 2
2652
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2664
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2653
2665
GLctx . uniformMatrix3fv ( GL . uniforms [ location ] , ! ! transpose, HEAPF32 , value> > 2 , count* 9 ) ;
2654
2666
return ;
2655
2667
}
@@ -2700,7 +2712,7 @@ var LibraryGL = {
2700
2712
#else
2701
2713
2702
2714
#if MAX_WEBGL_VERSION >= 2
2703
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2715
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
2704
2716
GLctx . uniformMatrix4fv ( GL . uniforms [ location ] , ! ! transpose, HEAPF32 , value> > 2 , count* 16 ) ;
2705
2717
return ;
2706
2718
}
@@ -2896,7 +2908,7 @@ var LibraryGL = {
2896
2908
var source = GL . getSource ( shader , count , string , length ) ;
2897
2909
2898
2910
#if WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION
2899
- if ( GL . currentContext . version >= 2 ) {
2911
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) {
2900
2912
// If a WebGL 1 shader happens to use GL_EXT_shader_texture_lod extension,
2901
2913
// it will not compile on WebGL 2, because WebGL 2 no longer supports that
2902
2914
// extension for WebGL 1 shaders. Therefore upgrade shaders to WebGL 2
@@ -3822,7 +3834,7 @@ var LibraryGL = {
3822
3834
GL . mappedBuffers [ buffer ] = null ;
3823
3835
3824
3836
if ( ! ( mapping . access & 0x10 ) ) /* GL_MAP_FLUSH_EXPLICIT_BIT */
3825
- if ( GL . currentContext . version >= 2 ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
3837
+ if ( { { { isCurrentContextWebGL2 ( ) } } } ) { // WebGL 2 provides new garbage-free entry points to call to WebGL. Use those always when possible.
3826
3838
GLctx . bufferSubData( target , mapping. offset , HEAPU8 , mapping. mem , mapping. length ) ;
3827
3839
} else {
3828
3840
GLctx . bufferSubData( target , mapping. offset , HEAPU8 . subarray ( mapping . mem, mapping. mem + mapping . length ) ) ;
0 commit comments