@@ -27,6 +27,12 @@ var ShapeBatch = function (game, gl, manager)
2727 this . vertexDataBuffer = null ;
2828 this . vertexCount = 0 ;
2929 this . viewMatrixLocation = null ;
30+ this . tempTriangle = [
31+ { x : 0 , y : 0 } ,
32+ { x : 0 , y : 0 } ,
33+ { x : 0 , y : 0 } ,
34+ { x : 0 , y : 0 }
35+ ] ;
3036
3137 // All of these settings will be able to be controlled via the Game Config
3238 this . config = {
@@ -523,6 +529,73 @@ ShapeBatch.prototype = {
523529 vertexBufferF32 [ vertexOffset ++ ] = fillAlpha ;
524530
525531 this . vertexCount += 6 ;
532+ } ,
533+
534+ addFillTriangle : function (
535+ /* Graphics Game Object properties */
536+ srcX , srcY , srcScaleX , srcScaleY , srcRotation ,
537+ /* Triangle properties */
538+ x0 , y0 , x1 , y1 , x2 , y2 , fillColor , fillAlpha ,
539+ /* transform */
540+ a , b , c , d , e , f
541+ ) {
542+ if ( this . vertexCount + 3 > this . maxVertices )
543+ {
544+ this . flush ( ) ;
545+ }
546+ var vertexDataBuffer = this . vertexDataBuffer ;
547+ var vertexBufferF32 = vertexDataBuffer . floatView ;
548+ var vertexBufferU32 = vertexDataBuffer . uintView ;
549+ var vertexOffset = vertexDataBuffer . allocate ( 12 ) ;
550+ var tx0 = x0 * a + y0 * c + e ;
551+ var ty0 = x0 * b + y0 * d + f ;
552+ var tx1 = x1 * a + y1 * c + e ;
553+ var ty1 = x1 * b + y1 * d + f ;
554+ var tx2 = x2 * a + y2 * c + e ;
555+ var ty2 = x2 * b + y2 * d + f ;
556+
557+ vertexBufferF32 [ vertexOffset ++ ] = tx0 ;
558+ vertexBufferF32 [ vertexOffset ++ ] = ty0 ;
559+ vertexBufferU32 [ vertexOffset ++ ] = fillColor ;
560+ vertexBufferF32 [ vertexOffset ++ ] = fillAlpha ;
561+
562+ vertexBufferF32 [ vertexOffset ++ ] = tx1 ;
563+ vertexBufferF32 [ vertexOffset ++ ] = ty1 ;
564+ vertexBufferU32 [ vertexOffset ++ ] = fillColor ;
565+ vertexBufferF32 [ vertexOffset ++ ] = fillAlpha ;
566+
567+ vertexBufferF32 [ vertexOffset ++ ] = tx2 ;
568+ vertexBufferF32 [ vertexOffset ++ ] = ty2 ;
569+ vertexBufferU32 [ vertexOffset ++ ] = fillColor ;
570+ vertexBufferF32 [ vertexOffset ++ ] = fillAlpha ;
571+
572+ this . vertexCount += 3 ;
573+ } ,
574+
575+ addStrokeTriangle : function (
576+ /* Graphics Game Object properties */
577+ srcX , srcY , srcScaleX , srcScaleY , srcRotation ,
578+ /* Triangle properties */
579+ x0 , y0 , x1 , y1 , x2 , y2 , lineWidth , lineColor , lineAlpha ,
580+ /* transform */
581+ a , b , c , d , e , f
582+ ) {
583+ var tempTriangle = this . tempTriangle ;
584+
585+ tempTriangle [ 0 ] . x = x0 ;
586+ tempTriangle [ 0 ] . y = y0 ;
587+ tempTriangle [ 1 ] . x = x1 ;
588+ tempTriangle [ 1 ] . y = y1 ;
589+ tempTriangle [ 2 ] . x = x2 ;
590+ tempTriangle [ 2 ] . y = y2 ;
591+ tempTriangle [ 3 ] . x = x0 ;
592+ tempTriangle [ 3 ] . y = y0 ;
593+
594+ this . addStrokePath (
595+ srcX , srcY , srcScaleX , srcScaleY , srcRotation ,
596+ tempTriangle , lineWidth , lineColor , lineAlpha ,
597+ a , b , c , d , e , f
598+ ) ;
526599 }
527600} ;
528601
0 commit comments