@@ -187,21 +187,17 @@ function _WebGL_doLink(gl, vshader, fshader) {
187187function _WebGL_getAttributeInfo ( gl , type ) {
188188 switch ( type ) {
189189 case gl . FLOAT :
190- return { size : 1 , type : Float32Array , baseType : gl . FLOAT } ;
190+ return { size : 1 , arraySize : 1 , type : Float32Array , baseType : gl . FLOAT } ;
191191 case gl . FLOAT_VEC2 :
192- return { size : 2 , type : Float32Array , baseType : gl . FLOAT } ;
192+ return { size : 2 , arraySize : 1 , type : Float32Array , baseType : gl . FLOAT } ;
193193 case gl . FLOAT_VEC3 :
194- return { size : 3 , type : Float32Array , baseType : gl . FLOAT } ;
194+ return { size : 3 , arraySize : 1 , type : Float32Array , baseType : gl . FLOAT } ;
195195 case gl . FLOAT_VEC4 :
196- return { size : 4 , type : Float32Array , baseType : gl . FLOAT } ;
196+ return { size : 4 , arraySize : 1 , type : Float32Array , baseType : gl . FLOAT } ;
197+ case gl . FLOAT_MAT4 :
198+ return { size : 4 , arraySize : 4 , type : Float32Array , baseType : gl . FLOAT } ;
197199 case gl . INT :
198- return { size : 1 , type : Int32Array , baseType : gl . INT } ;
199- case gl . INT_VEC2 :
200- return { size : 2 , type : Int32Array , baseType : gl . INT } ;
201- case gl . INT_VEC3 :
202- return { size : 3 , type : Int32Array , baseType : gl . INT } ;
203- case gl . INT_VEC4 :
204- return { size : 4 , type : Int32Array , baseType : gl . INT } ;
200+ return { size : 1 , arraySize : 1 , type : Int32Array , baseType : gl . INT } ;
205201 }
206202}
207203
@@ -249,11 +245,12 @@ function _WebGL_doBindAttribute(gl, attribute, mesh, attributes) {
249245 }
250246
251247 var dataIdx = 0 ;
252- var array = new attributeInfo . type ( _WebGL_listLength ( mesh . b ) * attributeInfo . size * elemSize ) ;
248+ var dataOffset = attributeInfo . size * attributeInfo . arraySize * elemSize ;
249+ var array = new attributeInfo . type ( _WebGL_listLength ( mesh . b ) * dataOffset ) ;
253250
254251 _WebGL_listEach ( function ( elem ) {
255- dataFill ( array , attributeInfo . size , dataIdx , elem , attributes [ attribute . name ] || attribute . name ) ;
256- dataIdx += attributeInfo . size * elemSize ;
252+ dataFill ( array , attributeInfo . size * attributeInfo . arraySize , dataIdx , elem , attributes [ attribute . name ] || attribute . name ) ;
253+ dataIdx += dataOffset ;
257254 } , mesh . b ) ;
258255
259256 var buffer = gl . createBuffer ( ) ;
@@ -436,9 +433,19 @@ var _WebGL_drawGL = F2(function (model, domNode) {
436433 var attributeInfo = _WebGL_getAttributeInfo ( gl , attribute . type ) ;
437434
438435 gl . bindBuffer ( gl . ARRAY_BUFFER , attributeBuffer ) ;
439- gl . vertexAttribPointer ( attribLocation , attributeInfo . size , attributeInfo . baseType , false , 0 , 0 ) ;
440- }
441436
437+ if ( attributeInfo . arraySize === 1 ) {
438+ gl . vertexAttribPointer ( attribLocation , attributeInfo . size , attributeInfo . baseType , false , 0 , 0 ) ;
439+ } else {
440+ // Point to four vec4 in case of mat4
441+ var offset = attributeInfo . size * 4 ; // float32 takes 4 bytes
442+ var stride = offset * attributeInfo . arraySize ;
443+ for ( var m = 0 ; m < attributeInfo . arraySize ; m ++ ) {
444+ gl . enableVertexAttribArray ( attribLocation + m ) ;
445+ gl . vertexAttribPointer ( attribLocation + m , attributeInfo . size , attributeInfo . baseType , false , stride , offset * m ) ;
446+ }
447+ }
448+ }
442449 _WebGL_listEach ( function ( setting ) {
443450 return A2 ( __WI_enableSetting , gl , setting ) ;
444451 } , entity . __settings ) ;
0 commit comments