@@ -11,7 +11,7 @@ const { getWebGLDrawBuffers } = require('./extensions/webgl-draw-buffers')
1111const {
1212 checkObject,
1313 checkUniform,
14- computePixelSize ,
14+ formatSize ,
1515 isValidString,
1616 typeSize,
1717 uniformTypeSize,
@@ -255,6 +255,35 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
255255 return true
256256 }
257257
258+ _computePixelSize ( type , internalFormat ) {
259+ const pixelSize = formatSize ( internalFormat )
260+ if ( pixelSize === 0 ) {
261+ this . setError ( gl . INVALID_ENUM )
262+ return 0
263+ }
264+ switch ( type ) {
265+ case gl . UNSIGNED_BYTE :
266+ return pixelSize
267+ case gl . UNSIGNED_SHORT_5_6_5 :
268+ if ( internalFormat !== gl . RGB ) {
269+ this . setError ( gl . INVALID_OPERATION )
270+ break
271+ }
272+ return 2
273+ case gl . UNSIGNED_SHORT_4_4_4_4 :
274+ case gl . UNSIGNED_SHORT_5_5_5_1 :
275+ if ( internalFormat !== gl . RGBA ) {
276+ this . setError ( gl . INVALID_OPERATION )
277+ break
278+ }
279+ return 2
280+ case gl . FLOAT :
281+ return 1
282+ }
283+ this . setError ( gl . INVALID_ENUM )
284+ return 0
285+ }
286+
258287 _computeRowStride ( width , pixelSize ) {
259288 let rowStride = width * pixelSize
260289 if ( rowStride % this . _unpackAlignment ) {
@@ -347,11 +376,15 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
347376 }
348377
349378 _getAttachments ( ) {
350- return this . _extensions . webgl_draw_buffers ? this . _extensions . webgl_draw_buffers . _WEBGL_DRAW_BUFFERS_ATTACHMENTS : DEFAULT_ATTACHMENTS
379+ return this . _extensions . webgl_draw_buffers ? this . _extensions . webgl_draw_buffers . _ALL_ATTACHMENTS : DEFAULT_ATTACHMENTS
351380 }
352381
353382 _getColorAttachments ( ) {
354- return this . _extensions . webgl_draw_buffers ? this . _extensions . webgl_draw_buffers . _WEBGL_DRAW_BUFFERS_COLOR_ATTACHMENTS : DEFAULT_COLOR_ATTACHMENTS
383+ return this . _extensions . webgl_draw_buffers ? this . _extensions . webgl_draw_buffers . _ALL_ATTACHMENTS : DEFAULT_COLOR_ATTACHMENTS
384+ }
385+
386+ _getParameterDirect ( pname ) {
387+ return super . getParameter ( pname )
355388 }
356389
357390 _getTexImage ( target ) {
@@ -3052,7 +3085,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
30523085 return
30533086 }
30543087
3055- const pixelSize = computePixelSize ( type , format )
3088+ const pixelSize = this . _computePixelSize ( type , format )
30563089 if ( pixelSize === 0 ) {
30573090 return
30583091 }
@@ -3169,7 +3202,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
31693202 return
31703203 }
31713204
3172- const pixelSize = computePixelSize ( type , format )
3205+ const pixelSize = this . _computePixelSize ( type , format )
31733206 if ( pixelSize === 0 ) {
31743207 return
31753208 }
@@ -3440,9 +3473,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34403473 if ( ! this . _checkUniformValueValid ( location , value , 'uniform1fv' , 1 , 'f' ) ) return
34413474 if ( location . _array ) {
34423475 const locs = location . _array
3443- for ( let j = 0 ; j < locs . length && ( j + 1 ) * 1 <= value . length ; ++ j ) {
3444- const loc = locs [ j ]
3445- super . uniform1fv ( loc , value [ 1 * j ] )
3476+ for ( let i = 0 ; i < locs . length && i < value . length ; ++ i ) {
3477+ const loc = locs [ i ]
3478+ super . uniform1f ( loc , value [ i ] )
34463479 }
34473480 return
34483481 }
@@ -3456,9 +3489,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34563489 if ( ! this . _checkUniformValueValid ( location , value , 'uniform1iv' , 1 , 'i' ) ) return
34573490 if ( location . _array ) {
34583491 const locs = location . _array
3459- for ( let j = 0 ; j < locs . length && ( j + 1 ) * 1 <= value . length ; ++ j ) {
3460- const loc = locs [ j ]
3461- super . uniform1iv ( loc , value [ 1 * j ] )
3492+ for ( let i = 0 ; i < locs . length && i < value . length ; ++ i ) {
3493+ const loc = locs [ i ]
3494+ super . uniform1i ( loc , value [ i ] )
34623495 }
34633496 return
34643497 }
@@ -3473,9 +3506,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34733506 if ( ! this . _checkUniformValueValid ( location , value , 'uniform2fv' , 2 , 'f' ) ) return
34743507 if ( location . _array ) {
34753508 const locs = location . _array
3476- for ( let j = 0 ; j < locs . length && ( j + 2 ) * 1 <= value . length ; ++ j ) {
3477- const loc = locs [ j ]
3478- super . uniform2fv ( loc , value [ 2 * j ] )
3509+ for ( let i = 0 ; i < locs . length && 2 * i < value . length ; ++ i ) {
3510+ const loc = locs [ i ]
3511+ super . uniform2f ( loc , value [ 2 * i ] , value [ ( 2 * i ) + 1 ] )
34793512 }
34803513 return
34813514 }
@@ -3489,9 +3522,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
34893522 if ( ! this . _checkUniformValueValid ( location , value , 'uniform2iv' , 2 , 'i' ) ) return
34903523 if ( location . _array ) {
34913524 const locs = location . _array
3492- for ( let j = 0 ; j < locs . length && ( j + 2 ) * 1 <= value . length ; ++ j ) {
3493- const loc = locs [ j ]
3494- super . uniform2iv ( loc , value [ 2 * j ] )
3525+ for ( let i = 0 ; i < locs . length && 2 * i < value . length ; ++ i ) {
3526+ const loc = locs [ i ]
3527+ super . uniform2i ( loc , value [ 2 * i ] , value [ 2 * i + 1 ] )
34953528 }
34963529 return
34973530 }
@@ -3506,9 +3539,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35063539 if ( ! this . _checkUniformValueValid ( location , value , 'uniform3fv' , 3 , 'f' ) ) return
35073540 if ( location . _array ) {
35083541 const locs = location . _array
3509- for ( let j = 0 ; j < locs . length && ( j + 3 ) * 1 <= value . length ; ++ j ) {
3510- const loc = locs [ j ]
3511- super . uniform3fv ( loc , value [ 3 * j ] )
3542+ for ( let i = 0 ; i < locs . length && 3 * i < value . length ; ++ i ) {
3543+ const loc = locs [ i ]
3544+ super . uniform3f ( loc , value [ 3 * i ] , value [ 3 * i + 1 ] , value [ 3 * i + 2 ] )
35123545 }
35133546 return
35143547 }
@@ -3522,9 +3555,9 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35223555 if ( ! this . _checkUniformValueValid ( location , value , 'uniform3iv' , 3 , 'i' ) ) return
35233556 if ( location . _array ) {
35243557 const locs = location . _array
3525- for ( let j = 0 ; j < locs . length && ( j + 3 ) * 1 <= value . length ; ++ j ) {
3526- const loc = locs [ j ]
3527- super . uniform3iv ( loc , value [ 3 * j ] )
3558+ for ( let i = 0 ; i < locs . length && 3 * i < value . length ; ++ i ) {
3559+ const loc = locs [ i ]
3560+ super . uniform3i ( loc , value [ 3 * i ] , value [ 3 * i + 1 ] , value [ 3 * i + 2 ] )
35283561 }
35293562 return
35303563 }
@@ -3539,25 +3572,25 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
35393572 if ( ! this . _checkUniformValueValid ( location , value , 'uniform4fv' , 4 , 'f' ) ) return
35403573 if ( location . _array ) {
35413574 const locs = location . _array
3542- for ( let j = 0 ; j < locs . length && ( j + 4 ) * 1 <= value . length ; ++ j ) {
3543- const loc = locs [ j ]
3544- super . uniform4fv ( loc , value [ 4 * j ] )
3575+ for ( let i = 0 ; i < locs . length && 4 * i < value . length ; ++ i ) {
3576+ const loc = locs [ i ]
3577+ super . uniform4f ( loc , value [ 4 * i ] , value [ 4 * i + 1 ] , value [ 4 * i + 2 ] , value [ 4 * i + 3 ] )
35453578 }
35463579 return
35473580 }
35483581 super . uniform4f ( location . _ | 0 , value [ 0 ] , value [ 1 ] , value [ 2 ] , value [ 3 ] )
35493582 }
35503583 uniform4i ( location , v0 , v1 , v2 , v3 ) {
35513584 if ( ! this . _checkUniformValid ( location , v0 , 'uniform4i' , 4 , 'i' ) ) return
3552- super . uniform3i ( location . _ | 0 , v0 , v1 , v2 , v3 )
3585+ super . uniform4i ( location . _ | 0 , v0 , v1 , v2 , v3 )
35533586 }
35543587 uniform4iv ( location , value ) {
35553588 if ( ! this . _checkUniformValueValid ( location , value , 'uniform4iv' , 4 , 'i' ) ) return
35563589 if ( location . _array ) {
35573590 const locs = location . _array
3558- for ( let j = 0 ; j < locs . length && ( j + 4 ) * 1 <= value . length ; ++ j ) {
3559- const loc = locs [ j ]
3560- super . uniform4iv ( loc , value [ 4 * j ] )
3591+ for ( let i = 0 ; i < locs . length && 4 * i < value . length ; ++ i ) {
3592+ const loc = locs [ i ]
3593+ super . uniform4i ( loc , value [ 4 * i ] , value [ 4 * i + 1 ] , value [ 4 * i + 2 ] , value [ 4 * i + 3 ] )
35613594 }
35623595 return
35633596 }
@@ -3657,7 +3690,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36573690 }
36583691
36593692 vertexAttrib1fv ( index , value ) {
3660- if ( typeof value !== 'object' || value === null || value . length !== 1 ) {
3693+ if ( typeof value !== 'object' || value === null || value . length < 1 ) {
36613694 this . setError ( gl . INVALID_OPERATION )
36623695 return
36633696 }
@@ -3669,7 +3702,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36693702 return super . vertexAttrib1f ( index | 0 , + value [ 0 ] )
36703703 }
36713704 vertexAttrib2fv ( index , value ) {
3672- if ( typeof value !== 'object' || value === null || value . length !== 2 ) {
3705+ if ( typeof value !== 'object' || value === null || value . length < 2 ) {
36733706 this . setError ( gl . INVALID_OPERATION )
36743707 return
36753708 }
@@ -3681,7 +3714,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36813714 return super . vertexAttrib2f ( index | 0 , + value [ 0 ] , + value [ 1 ] )
36823715 }
36833716 vertexAttrib3fv ( index , value ) {
3684- if ( typeof value !== 'object' || value === null || value . length !== 3 ) {
3717+ if ( typeof value !== 'object' || value === null || value . length < 3 ) {
36853718 this . setError ( gl . INVALID_OPERATION )
36863719 return
36873720 }
@@ -3693,7 +3726,7 @@ class WebGLRenderingContext extends NativeWebGLRenderingContext {
36933726 return super . vertexAttrib3f ( index | 0 , + value [ 0 ] , + value [ 1 ] , + value [ 2 ] )
36943727 }
36953728 vertexAttrib4fv ( index , value ) {
3696- if ( typeof value !== 'object' || value === null || value . length !== 4 ) {
3729+ if ( typeof value !== 'object' || value === null || value . length < 4 ) {
36973730 this . setError ( gl . INVALID_OPERATION )
36983731 return
36993732 }
0 commit comments