@@ -144,10 +144,11 @@ var LibraryGLEmulation = {
144
144
} ,
145
145
146
146
init ( ) {
147
- // Do not activate immediate/emulation code (e.g. replace glDrawElements) when in FULL_ES2 mode.
148
- // We do not need full emulation, we instead emulate client-side arrays etc. in FULL_ES2 code in
149
- // a straightforward manner, and avoid not having a bound buffer be ambiguous between es2 emulation
150
- // code and legacy gl emulation code.
147
+ // Do not activate immediate/emulation code (e.g. replace glDrawElements)
148
+ // when in FULL_ES2 mode. We do not need full emulation, we instead
149
+ // emulate client-side arrays etc. in FULL_ES2 code in a straightforward
150
+ // manner, and avoid not having a bound buffer be ambiguous between es2
151
+ // emulation code and legacy gl emulation code.
151
152
#if FULL_ES2
152
153
return ;
153
154
#endif
@@ -2898,35 +2899,47 @@ var LibraryGLEmulation = {
2898
2899
// count: number of elements we will draw
2899
2900
// beginEnd: whether we are drawing the results of a begin/end block
2900
2901
prepareClientAttributes ( count , beginEnd ) {
2901
- // If no client attributes were modified since we were last called, do nothing. Note that this
2902
- // does not work for glBegin/End, where we generate renderer components dynamically and then
2903
- // disable them ourselves, but it does help with glDrawElements/Arrays.
2902
+ // If no client attributes were modified since we were last called, do
2903
+ // nothing. Note that this does not work for glBegin/End, where we
2904
+ // generate renderer components dynamically and then disable them
2905
+ // ourselves, but it does help with glDrawElements/Arrays.
2904
2906
if ( ! GLImmediate . modifiedClientAttributes ) {
2905
2907
#if GL_ASSERTIONS
2906
2908
if ( ( GLImmediate . stride & 3 ) != 0 ) {
2907
- warnOnce ( ' Warning: Rendering from client side vertex arrays where stride (' + GLImmediate . stride + ' ) is not a multiple of four! This is not currently supported!' ) ;
2909
+ warnOnce ( ` Warning: Rendering from client side vertex arrays where stride (${ GLImmediate . stride } ) is not a multiple of four! This is not currently supported!` ) ;
2908
2910
}
2909
2911
#endif
2910
2912
GLImmediate . vertexCounter = ( GLImmediate . stride * count ) / 4 ; // XXX assuming float
2911
2913
return ;
2912
2914
}
2913
2915
GLImmediate . modifiedClientAttributes = false ;
2914
2916
2915
- // The role of prepareClientAttributes is to examine the set of client-side vertex attribute buffers
2916
- // that user code has submitted, and to prepare them to be uploaded to a VBO in GPU memory
2917
- // (since WebGL does not support client-side rendering, i.e. rendering from vertex data in CPU memory)
2918
- // User can submit vertex data generally in three different configurations:
2919
- // 1. Fully planar: all attributes are in their own separate tightly-packed arrays in CPU memory.
2920
- // 2. Fully interleaved: all attributes share a single array where data is interleaved something like (pos,uv,normal), (pos,uv,normal), ...
2921
- // 3. Complex hybrid: Multiple separate arrays that either are sparsely strided, and/or partially interleave vertex attributes.
2922
-
2923
- // For simplicity, we support the case (2) as the fast case. For (1) and (3), we do a memory copy of the
2924
- // vertex data here to prepare a relayouted buffer that is of the structure in case (2). The reason
2925
- // for this is that it allows the emulation code to get away with using just one VBO buffer for rendering,
2926
- // and not have to maintain multiple ones. Therefore cases (1) and (3) will be very slow, and case (2) is fast.
2927
-
2928
- // Detect which case we are in by using a quick heuristic by examining the strides of the buffers. If all the buffers have identical
2929
- // stride, we assume we have case (2), otherwise we have something more complex.
2917
+ // The role of prepareClientAttributes is to examine the set of
2918
+ // client-side vertex attribute buffers that user code has submitted, and
2919
+ // to prepare them to be uploaded to a VBO in GPU memory (since WebGL does
2920
+ // not support client-side rendering, i.e. rendering from vertex data in
2921
+ // CPU memory). User can submit vertex data generally in three different
2922
+ // configurations:
2923
+ // 1. Fully planar: all attributes are in their own separate
2924
+ // tightly-packed arrays in CPU memory.
2925
+ // 2. Fully interleaved: all attributes share a single array where data is
2926
+ // interleaved something like (pos,uv,normal),
2927
+ // (pos,uv,normal), ...
2928
+ // 3. Complex hybrid: Multiple separate arrays that either are sparsely
2929
+ // strided, and/or partially interleaves vertex
2930
+ // attributes.
2931
+
2932
+ // For simplicity, we support the case (2) as the fast case. For (1) and
2933
+ // (3), we do a memory copy of the vertex data here to prepare a
2934
+ // relayouted buffer that is of the structure in case (2). The reason
2935
+ // for this is that it allows the emulation code to get away with using
2936
+ // just one VBO buffer for rendering, and not have to maintain multiple
2937
+ // ones. Therefore cases (1) and (3) will be very slow, and case (2) is
2938
+ // fast.
2939
+
2940
+ // Detect which case we are in by using a quick heuristic by examining the
2941
+ // strides of the buffers. If all the buffers have identical stride, we
2942
+ // assume we have case (2), otherwise we have something more complex.
2930
2943
var clientStartPointer = 0x7FFFFFFF ;
2931
2944
var bytes = 0 ; // Total number of bytes taken up by a single vertex.
2932
2945
var minStride = 0x7FFFFFFF ;
@@ -2946,9 +2959,11 @@ var LibraryGLEmulation = {
2946
2959
}
2947
2960
2948
2961
if ( ( minStride != maxStride || maxStride < bytes ) && ! beginEnd ) {
2949
- // We are in cases (1) or (3): slow path, shuffle the data around into a single interleaved vertex buffer.
2950
- // The immediate-mode glBegin()/glEnd() vertex submission gets automatically generated in appropriate layout,
2951
- // so never need to come down this path if that was used.
2962
+ // We are in cases (1) or (3): slow path, shuffle the data around into a
2963
+ // single interleaved vertex buffer.
2964
+ // The immediate-mode glBegin()/glEnd() vertex submission gets
2965
+ // automatically generated in appropriate layout, so never need to come
2966
+ // down this path if that was used.
2952
2967
#if GL_ASSERTIONS
2953
2968
warnOnce ( 'Rendering from planar client-side vertex arrays. This is a very slow emulation path! Use interleaved vertex arrays for best performance.' ) ;
2954
2969
#endif
@@ -3002,7 +3017,7 @@ var LibraryGLEmulation = {
3002
3017
if ( ! beginEnd ) {
3003
3018
#if GL_ASSERTIONS
3004
3019
if ( ( GLImmediate . stride & 3 ) != 0 ) {
3005
- warnOnce ( ' Warning: Rendering from client side vertex arrays where stride (' + GLImmediate . stride + ' ) is not a multiple of four! This is not currently supported!' ) ;
3020
+ warnOnce ( ` Warning: Rendering from client side vertex arrays where stride (${ GLImmediate . stride } ) is not a multiple of four! This is not currently supported!` ) ;
3006
3021
}
3007
3022
#endif
3008
3023
GLImmediate . vertexCounter = ( GLImmediate . stride * count ) / 4 ; // XXX assuming float
@@ -3053,13 +3068,14 @@ var LibraryGLEmulation = {
3053
3068
}
3054
3069
} else if ( GLImmediate . mode > 6 ) { // above GL_TRIANGLE_FAN are the non-GL ES modes
3055
3070
if ( GLImmediate . mode != 7 ) throw 'unsupported immediate mode ' + GLImmediate . mode ; // GL_QUADS
3056
- // GLImmediate.firstVertex is the first vertex we want. Quad indexes are in the pattern
3057
- // 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at index firstVertex * 1.5 to see it.
3058
- // Then since indexes are 2 bytes each, that means 3
3071
+ // GLImmediate.firstVertex is the first vertex we want. Quad indexes are
3072
+ // in the pattern 0 1 2, 0 2 3, 4 5 6, 4 6 7, so we need to look at
3073
+ // index firstVertex * 1.5 to see it. Then since indexes are 2 bytes
3074
+ // each, that means 3
3059
3075
#if ASSERTIONS
3060
3076
assert ( GLImmediate . firstVertex % 4 == 0 ) ;
3061
3077
#endif
3062
- ptr = GLImmediate . firstVertex * 3 ;
3078
+ ptr = GLImmediate . firstVertex * 3 ;
3063
3079
var numQuads = numVertexes / 4 ;
3064
3080
numIndexes = numQuads * 6 ; // 0 1 2, 0 2 3 pattern
3065
3081
#if ASSERTIONS
@@ -3173,19 +3189,19 @@ var LibraryGLEmulation = {
3173
3189
} ,
3174
3190
3175
3191
glVertex2fv__deps: [ 'glVertex2f' ] ,
3176
- glVertex2fv : ( p ) => {
3177
- _glVertex2f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } , { { { makeGetValue ( 'p' , '4' , 'float' ) } } } ) ;
3178
- } ,
3192
+ glVertex2fv : ( p ) => _glVertex2f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } ,
3193
+ { { { makeGetValue ( 'p' , '4' , 'float' ) } } } ) ,
3179
3194
3180
3195
glVertex3fv__deps : [ 'glVertex3f' ] ,
3181
- glVertex3fv : ( p ) => {
3182
- _glVertex3f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } , { { { makeGetValue ( 'p' , '4' , 'float' ) } } } , { { { makeGetValue ( 'p' , '8 ' , 'float' ) } } } ) ;
3183
- } ,
3196
+ glVertex3fv : ( p ) => _glVertex3f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } ,
3197
+ { { { makeGetValue ( 'p' , '4 ' , 'float' ) } } } ,
3198
+ { { { makeGetValue ( 'p' , '8' , 'float' ) } } } ) ,
3184
3199
3185
3200
glVertex4fv__deps : [ 'glVertex4f' ] ,
3186
- glVertex4fv : ( p ) => {
3187
- _glVertex4f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } , { { { makeGetValue ( 'p' , '4' , 'float' ) } } } , { { { makeGetValue ( 'p' , '8' , 'float' ) } } } , { { { makeGetValue ( 'p' , '12' , 'float' ) } } } ) ;
3188
- } ,
3201
+ glVertex4fv : ( p ) => _glVertex4f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } ,
3202
+ { { { makeGetValue ( 'p' , '4' , 'float' ) } } } ,
3203
+ { { { makeGetValue ( 'p' , '8' , 'float' ) } } } ,
3204
+ { { { makeGetValue ( 'p' , '12' , 'float' ) } } } ) ,
3189
3205
3190
3206
glVertex2i : 'glVertex2f' ,
3191
3207
@@ -3204,9 +3220,8 @@ var LibraryGLEmulation = {
3204
3220
glTexCoord2f : 'glTexCoord2i' ,
3205
3221
3206
3222
glTexCoord2fv__deps : [ 'glTexCoord2i' ] ,
3207
- glTexCoord2fv : ( v ) => {
3208
- _glTexCoord2i ( { { { makeGetValue ( 'v' , '0' , 'float' ) } } } , { { { makeGetValue ( 'v' , '4' , 'float' ) } } } ) ;
3209
- } ,
3223
+ glTexCoord2fv : ( v ) =>
3224
+ _glTexCoord2i ( { { { makeGetValue ( 'v' , '0' , 'float' ) } } } , { { { makeGetValue ( 'v' , '4' , 'float' ) } } } ) ,
3210
3225
3211
3226
glTexCoord4f : ( ) => { throw 'glTexCoord4f: TODO' } ,
3212
3227
@@ -3239,60 +3254,59 @@ var LibraryGLEmulation = {
3239
3254
glColor4d : 'glColor4f' ,
3240
3255
3241
3256
glColor4ub__deps : [ 'glColor4f' ] ,
3242
- glColor4ub : ( r , g , b , a ) = > {
3243
- _glColor4f ( ( r & 255 ) / 255 , ( g & 255 ) / 255 , ( b & 255 ) / 255 , ( a & 255 ) / 255 ) ;
3244
- } ,
3257
+ glColor4ub : ( r , g , b , a ) = > _glColor4f ( ( r & 255 ) / 255 , ( g & 255 ) / 255 , ( b & 255 ) / 255 , ( a & 255 ) / 255 ) ,
3258
+
3245
3259
glColor4us__deps : [ 'glColor4f' ] ,
3246
- glColor4us : ( r , g , b , a ) = > {
3247
- _glColor4f ( ( r & 65535 ) / 65535 , ( g & 65535 ) / 65535 , ( b & 65535 ) / 65535 , ( a & 65535 ) / 65535 ) ;
3248
- } ,
3260
+ glColor4us : ( r , g , b , a ) = > _glColor4f ( ( r & 65535 ) / 65535 , ( g & 65535 ) / 65535 , ( b & 65535 ) / 65535 , ( a & 65535 ) / 65535 ) ,
3261
+
3249
3262
glColor4ui__deps : [ 'glColor4f' ] ,
3250
- glColor4ui : ( r , g , b , a ) = > {
3251
- _glColor4f ( ( r >>> 0 ) / 4294967295 , ( g >>> 0 ) / 4294967295 , ( b >>> 0 ) / 4294967295 , ( a >>> 0 ) / 4294967295 ) ;
3252
- } ,
3263
+ glColor4ui : ( r , g , b , a ) = > _glColor4f ( ( r >>> 0 ) / 4294967295 , ( g >>> 0 ) / 4294967295 , ( b >>> 0 ) / 4294967295 , ( a >>> 0 ) / 4294967295 ) ,
3264
+
3253
3265
glColor3f__deps : [ 'glColor4f' ] ,
3254
- glColor3f : ( r , g , b ) = > {
3255
- _glColor4f ( r , g , b , 1 ) ;
3256
- } ,
3266
+ glColor3f : ( r , g , b ) = > _glColor4f ( r , g , b , 1 ) ,
3267
+
3257
3268
glColor3d : 'glColor3f' ,
3269
+
3258
3270
glColor3ub__deps : [ 'glColor4ub' ] ,
3259
- glColor3ub : ( r , g , b ) = > {
3260
- _glColor4ub ( r , g , b , 255 ) ;
3261
- } ,
3271
+ glColor3ub : ( r , g , b ) = > _glColor4ub ( r , g , b , 255 ) ,
3272
+
3262
3273
glColor3us__deps : [ 'glColor4us' ] ,
3263
- glColor3us : ( r , g , b ) = > {
3264
- _glColor4us ( r , g , b , 65535 ) ;
3265
- } ,
3274
+ glColor3us : ( r , g , b ) = > _glColor4us ( r , g , b , 65535 ) ,
3275
+
3266
3276
glColor3ui__deps : [ 'glColor4ui' ] ,
3267
- glColor3ui : ( r , g , b ) = > {
3268
- _glColor4ui ( r , g , b , 4294967295 ) ;
3269
- } ,
3277
+ glColor3ui : ( r , g , b ) = > _glColor4ui ( r , g , b , 4294967295 ) ,
3270
3278
3271
3279
glColor3ubv__deps : [ 'glColor3ub' ] ,
3272
- glColor3ubv : ( p ) = > {
3273
- _glColor3ub ( { { { makeGetValue ( 'p' , '0' , 'i8' ) } } } , { { { makeGetValue ( 'p' , '1' , 'i8' ) } } } , { { { makeGetValue ( 'p' , '2' , 'i8' ) } } } ) ;
3274
- } ,
3280
+ glColor3ubv : ( p ) = > _glColor3ub ( { { { makeGetValue ( 'p' , '0' , 'i8' ) } } } ,
3281
+ { { { makeGetValue ( 'p' , '1' , 'i8' ) } } } ,
3282
+ { { { makeGetValue ( 'p' , '2' , 'i8' ) } } } ) ,
3283
+
3275
3284
glColor3usv__deps : [ 'glColor3us' ] ,
3276
- glColor3usv : ( p ) => {
3277
- _glColor3us ( { { { makeGetValue ( 'p' , '0' , 'i16' ) } } } , { { { makeGetValue ( 'p' , '2' , 'i16' ) } } } , { { { makeGetValue ( 'p' , '4' , 'i16' ) } } } ) ;
3278
- } ,
3285
+ glColor3usv : ( p ) = > _glColor3us ( { { { makeGetValue ( 'p' , '0' , 'i16' ) } } } ,
3286
+ { { { makeGetValue ( 'p' , '2' , 'i16' ) } } } ,
3287
+ { { { makeGetValue ( 'p' , '4' , 'i16' ) } } } ) ,
3288
+
3279
3289
glColor3uiv__deps : [ 'glColor3ui' ] ,
3280
- glColor3uiv : ( p ) => {
3281
- _glColor3ui ( { { { makeGetValue ( 'p' , '0' , 'i32' ) } } } , { { { makeGetValue ( 'p' , '4' , 'i32' ) } } } , { { { makeGetValue ( 'p' , '8' , 'i32' ) } } } ) ;
3282
- } ,
3290
+ glColor3uiv : ( p ) = > _glColor3ui ( { { { makeGetValue ( 'p' , '0' , 'i32' ) } } } ,
3291
+ { { { makeGetValue ( 'p' , '4' , 'i32' ) } } } ,
3292
+ { { { makeGetValue ( 'p' , '8' , 'i32' ) } } } ) ,
3293
+
3283
3294
glColor3fv__deps : [ 'glColor3f' ] ,
3284
- glColor3fv : ( p ) => {
3285
- _glColor3f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } , { { { makeGetValue ( 'p' , '4' , 'float' ) } } } , { { { makeGetValue ( 'p' , '8' , 'float' ) } } } ) ;
3286
- } ,
3295
+ glColor3fv : ( p ) = > _glColor3f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } ,
3296
+ { { { makeGetValue ( 'p' , '4' , 'float' ) } } } ,
3297
+ { { { makeGetValue ( 'p' , '8' , 'float' ) } } } ) ,
3298
+
3287
3299
glColor4fv__deps : [ 'glColor4f' ] ,
3288
- glColor4fv : ( p ) => {
3289
- _glColor4f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } , { { { makeGetValue ( 'p' , '4' , 'float' ) } } } , { { { makeGetValue ( 'p' , '8' , 'float' ) } } } , { { { makeGetValue ( 'p' , '12' , 'float' ) } } } ) ;
3290
- } ,
3300
+ glColor4fv : ( p ) = > _glColor4f ( { { { makeGetValue ( 'p' , '0' , 'float' ) } } } ,
3301
+ { { { makeGetValue ( 'p' , '4' , 'float' ) } } } ,
3302
+ { { { makeGetValue ( 'p' , '8' , 'float' ) } } } ,
3303
+ { { { makeGetValue ( 'p' , '12' , 'float' ) } } } ) ,
3291
3304
3292
3305
glColor4ubv__deps : [ 'glColor4ub' ] ,
3293
- glColor4ubv : ( p ) => {
3294
- _glColor4ub ( { { { makeGetValue ( 'p' , '0' , 'i8' ) } } } , { { { makeGetValue ( 'p' , '1' , 'i8' ) } } } , { { { makeGetValue ( 'p' , '2' , 'i8' ) } } } , { { { makeGetValue ( 'p' , '3' , 'i8' ) } } } ) ;
3295
- } ,
3306
+ glColor4ubv : ( p ) = > _glColor4ub ( { { { makeGetValue ( 'p' , '0' , 'i8' ) } } } ,
3307
+ { { { makeGetValue ( 'p' , '1' , 'i8' ) } } } ,
3308
+ { { { makeGetValue ( 'p' , '2' , 'i8' ) } } } ,
3309
+ { { { makeGetValue ( 'p' , '3' , 'i8' ) } } } ) ,
3296
3310
3297
3311
glFogf : ( pname , param ) = > { // partial support, TODO
3298
3312
switch ( pname ) {
@@ -3493,9 +3507,9 @@ var LibraryGLEmulation = {
3493
3507
GLImmediate . clientActiveTexture = texture - 0x84C0 ; // GL_TEXTURE0
3494
3508
} ,
3495
3509
3496
- // Replace some functions with immediate-mode aware versions. If there are no client
3497
- // attributes enabled, and we use webgl-friendly modes (no GL_QUADS), then no need
3498
- // for emulation
3510
+ // Replace some functions with immediate-mode aware versions. If there are no
3511
+ // client attributes enabled, and we use webgl-friendly modes (no GL_QUADS),
3512
+ // then no need for emulation
3499
3513
glDrawArrays: ( mode , first , count ) => {
3500
3514
if ( GLImmediate . totalEnabledClientAttributes == 0 && mode <= 6 ) {
3501
3515
GLctx . drawArrays ( mode , first , count ) ;
@@ -3512,7 +3526,8 @@ var LibraryGLEmulation = {
3512
3526
GLImmediate . mode = - 1 ;
3513
3527
} ,
3514
3528
3515
- glDrawElements : ( mode , count , type , indices , start , end ) = > { // start, end are given if we come from glDrawRangeElements
3529
+ // start, end are given if we come from glDrawRangeElements
3530
+ glDrawElements: ( mode , count , type , indices , start , end ) => {
3516
3531
if ( GLImmediate . totalEnabledClientAttributes == 0 && mode <= 6 && GLctx . currentElementArrayBufferBinding ) {
3517
3532
GLctx . drawElements ( mode , count , type , indices ) ;
3518
3533
return ;
@@ -3534,7 +3549,8 @@ var LibraryGLEmulation = {
3534
3549
GLImmediate . mode = - 1 ;
3535
3550
} ,
3536
3551
3537
- // Vertex array object (VAO) support. TODO: when the WebGL extension is popular, use that and remove this code and GL.vaos
3552
+ // Vertex array object (VAO) support. TODO: when the WebGL extension is
3553
+ // popular, use that and remove this code and GL.vaos
3538
3554
$emulGlGenVertexArrays__deps : [ '$GLEmulation' ] ,
3539
3555
$emulGlGenVertexArrays : ( n , vaos ) = > {
3540
3556
for ( var i = 0 ; i < n ; i ++ ) {
@@ -3606,7 +3622,7 @@ var LibraryGLEmulation = {
3606
3622
GLImmediate . useTextureMatrix = true ;
3607
3623
GLImmediate . currentMatrix = 2 /*t*/ + GLImmediate . TexEnvJIT . getActiveTexture ( ) ;
3608
3624
} else {
3609
- throw " Wrong mode " + mode + " passed to glMatrixMode" ;
3625
+ throw ` Wrong mode ${ mode } passed to glMatrixMode` ;
3610
3626
}
3611
3627
} ,
3612
3628
@@ -3833,9 +3849,9 @@ var LibraryGLEmulation = {
3833
3849
3834
3850
glTexGeni : ( coord , pname , param ) => { throw 'glTexGeni: TODO' } ,
3835
3851
glTexGenfv : ( coord , pname , param ) => { throw 'glTexGenfv: TODO' } ,
3836
- glTexEnvi : ( target , pname , params ) => { warnOnce ( 'glTexEnvi: TODO' ) } ,
3837
- glTexEnvf : ( target , pname , params ) => { warnOnce ( 'glTexEnvf: TODO' ) } ,
3838
- glTexEnvfv : ( target , pname , params ) => { warnOnce ( 'glTexEnvfv: TODO' ) } ,
3852
+ glTexEnvi : ( target , pname , params ) = > warnOnce ( 'glTexEnvi: TODO' ) ,
3853
+ glTexEnvf : ( target , pname , params ) = > warnOnce ( 'glTexEnvf: TODO' ) ,
3854
+ glTexEnvfv : ( target , pname , params ) = > warnOnce ( 'glTexEnvfv: TODO' ) ,
3839
3855
3840
3856
glGetTexEnviv : ( target , pname , param ) = > { throw 'GL emulation not initialized!' ; } ,
3841
3857
glGetTexEnvfv : ( target , pname , param ) = > { throw 'GL emulation not initialized!' ; } ,
0 commit comments