@@ -567,6 +567,67 @@ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgb
567567 glPositionData [ offset ++ ] = angle ;
568568}
569569
570+ /** Add an untextured rect to the gl draw list
571+ * Picks the optimal path: if already in poly mode, emits a tristrip rect
572+ * so it batches with surrounding polys; otherwise uses the instanced path
573+ * with uvs and rgba zeroed so the color falls through the additive slot.
574+ * @param {number } x
575+ * @param {number } y
576+ * @param {number } sizeX
577+ * @param {number } sizeY
578+ * @param {number } angle
579+ * @param {number } rgba - color as 32-bit integer
580+ * @memberof WebGL */
581+ function glDrawUntextured ( x , y , sizeX , sizeY , angle , rgba )
582+ {
583+ if ( glPolyMode )
584+ {
585+ // batch with surrounding polys as a 4-vertex tristrip rect
586+ const vertCount = 6 ; // 4 corners + 2 degenerate verts
587+ if ( glBatchCount + vertCount >= gl_MAX_POLY_VERTEXES || glBatchAdditive !== glAdditive )
588+ glFlush ( ) ;
589+
590+ // compute rotated corners in world space (matches glDrawPointsTransform rotation)
591+ const hx = sizeX * .5 , hy = sizeY * .5 ;
592+ const c = cos ( angle ) , s = sin ( angle ) ;
593+ const chx = c * hx , shx = s * hx , chy = c * hy , shy = s * hy ;
594+ const x0 = x - chx - shy , y0 = y + shx - chy ; // (-hx,-hy)
595+ const x1 = x + chx - shy , y1 = y - shx - chy ; // ( hx,-hy)
596+ const x2 = x - chx + shy , y2 = y + shx + chy ; // (-hx, hy)
597+ const x3 = x + chx + shy , y3 = y - shx + chy ; // ( hx, hy)
598+
599+ // write tristrip with leading/trailing degenerate verts
600+ let offset = glBatchCount * gl_INDICES_PER_POLY_VERTEX ;
601+ glPositionData [ offset ++ ] = x0 ; glPositionData [ offset ++ ] = y0 ; glColorData [ offset ++ ] = rgba ;
602+ glPositionData [ offset ++ ] = x0 ; glPositionData [ offset ++ ] = y0 ; glColorData [ offset ++ ] = rgba ;
603+ glPositionData [ offset ++ ] = x1 ; glPositionData [ offset ++ ] = y1 ; glColorData [ offset ++ ] = rgba ;
604+ glPositionData [ offset ++ ] = x2 ; glPositionData [ offset ++ ] = y2 ; glColorData [ offset ++ ] = rgba ;
605+ glPositionData [ offset ++ ] = x3 ; glPositionData [ offset ++ ] = y3 ; glColorData [ offset ++ ] = rgba ;
606+ glPositionData [ offset ++ ] = x3 ; glPositionData [ offset ++ ] = y3 ; glColorData [ offset ++ ] = rgba ;
607+ glBatchCount += vertCount ;
608+ return ;
609+ }
610+
611+ // instanced path: zero uvs and rgba so the texture contribution is killed,
612+ // then carry the real color in the additive slot
613+ if ( glBatchCount >= gl_MAX_INSTANCES || glBatchAdditive !== glAdditive )
614+ glFlush ( ) ;
615+ glSetInstancedMode ( ) ;
616+
617+ let offset = glBatchCount ++ * gl_INDICES_PER_INSTANCE ;
618+ glPositionData [ offset ++ ] = x ;
619+ glPositionData [ offset ++ ] = y ;
620+ glPositionData [ offset ++ ] = sizeX ;
621+ glPositionData [ offset ++ ] = sizeY ;
622+ glPositionData [ offset ++ ] = 0 ;
623+ glPositionData [ offset ++ ] = 0 ;
624+ glPositionData [ offset ++ ] = 0 ;
625+ glPositionData [ offset ++ ] = 0 ;
626+ glColorData [ offset ++ ] = 0 ;
627+ glColorData [ offset ++ ] = rgba ;
628+ glPositionData [ offset ++ ] = angle ;
629+ }
630+
570631/** Transform and add a polygon to the gl draw list
571632 * @param {Array<Vector2> } points - Array of Vector2 points
572633 * @param {number } rgba - Color of the polygon as a 32-bit integer
0 commit comments