@@ -4105,13 +4105,12 @@ function drawTile(pos, size=vec2(1), tileInfo, color=WHITE,
41054105 }
41064106 else
41074107 {
4108- // if no tile info, force untextured by zeroing rgba (so whatever
4109- // texture is bound doesn't leak in) and folding color+additive
4110- // into the additive slot — matches the Canvas2D path's
4111- // color.add(additiveColor) on line ~337.
4108+ // untextured: glDrawUntextured picks the optimal path (poly
4109+ // tristrip if already in poly mode, otherwise instanced with
4110+ // uvs/rgba zeroed). Color+ additive are folded together to match
4111+ // the Canvas2D path's color.add(additiveColor) on line ~337.
41124112 const combined = additiveColor ? color.add(additiveColor) : color;
4113- glDraw(pos.x, pos.y, size.x, size.y, angle, 0, 0, 0, 0,
4114- 0, combined.rgbaInt());
4113+ glDrawUntextured(pos.x, pos.y, size.x, size.y, angle, combined.rgbaInt());
41154114 }
41164115 }
41174116 else
@@ -8502,6 +8501,67 @@ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgb
85028501 glPositionData[offset++] = angle;
85038502}
85048503
8504+ /** Add an untextured rect to the gl draw list
8505+ * Picks the optimal path: if already in poly mode, emits a tristrip rect
8506+ * so it batches with surrounding polys; otherwise uses the instanced path
8507+ * with uvs and rgba zeroed so the color falls through the additive slot.
8508+ * @param {number} x
8509+ * @param {number} y
8510+ * @param {number} sizeX
8511+ * @param {number} sizeY
8512+ * @param {number} angle
8513+ * @param {number} rgba - color as 32-bit integer
8514+ * @memberof WebGL */
8515+ function glDrawUntextured(x, y, sizeX, sizeY, angle, rgba)
8516+ {
8517+ if (glPolyMode)
8518+ {
8519+ // batch with surrounding polys as a 4-vertex tristrip rect
8520+ const vertCount = 6; // 4 corners + 2 degenerate verts
8521+ if (glBatchCount+vertCount >= gl_MAX_POLY_VERTEXES || glBatchAdditive !== glAdditive)
8522+ glFlush();
8523+
8524+ // compute rotated corners in world space (matches glDrawPointsTransform rotation)
8525+ const hx = sizeX*.5, hy = sizeY*.5;
8526+ const c = cos(angle), s = sin(angle);
8527+ const chx = c*hx, shx = s*hx, chy = c*hy, shy = s*hy;
8528+ const x0 = x - chx - shy, y0 = y + shx - chy; // (-hx,-hy)
8529+ const x1 = x + chx - shy, y1 = y - shx - chy; // ( hx,-hy)
8530+ const x2 = x - chx + shy, y2 = y + shx + chy; // (-hx, hy)
8531+ const x3 = x + chx + shy, y3 = y - shx + chy; // ( hx, hy)
8532+
8533+ // write tristrip with leading/trailing degenerate verts
8534+ let offset = glBatchCount * gl_INDICES_PER_POLY_VERTEX;
8535+ glPositionData[offset++] = x0; glPositionData[offset++] = y0; glColorData[offset++] = rgba;
8536+ glPositionData[offset++] = x0; glPositionData[offset++] = y0; glColorData[offset++] = rgba;
8537+ glPositionData[offset++] = x1; glPositionData[offset++] = y1; glColorData[offset++] = rgba;
8538+ glPositionData[offset++] = x2; glPositionData[offset++] = y2; glColorData[offset++] = rgba;
8539+ glPositionData[offset++] = x3; glPositionData[offset++] = y3; glColorData[offset++] = rgba;
8540+ glPositionData[offset++] = x3; glPositionData[offset++] = y3; glColorData[offset++] = rgba;
8541+ glBatchCount += vertCount;
8542+ return;
8543+ }
8544+
8545+ // instanced path: zero uvs and rgba so the texture contribution is killed,
8546+ // then carry the real color in the additive slot
8547+ if (glBatchCount >= gl_MAX_INSTANCES || glBatchAdditive !== glAdditive)
8548+ glFlush();
8549+ glSetInstancedMode();
8550+
8551+ let offset = glBatchCount++ * gl_INDICES_PER_INSTANCE;
8552+ glPositionData[offset++] = x;
8553+ glPositionData[offset++] = y;
8554+ glPositionData[offset++] = sizeX;
8555+ glPositionData[offset++] = sizeY;
8556+ glPositionData[offset++] = 0;
8557+ glPositionData[offset++] = 0;
8558+ glPositionData[offset++] = 0;
8559+ glPositionData[offset++] = 0;
8560+ glColorData[offset++] = 0;
8561+ glColorData[offset++] = rgba;
8562+ glPositionData[offset++] = angle;
8563+ }
8564+
85058565/** Transform and add a polygon to the gl draw list
85068566 * @param {Array<Vector2>} points - Array of Vector2 points
85078567 * @param {number} rgba - Color of the polygon as a 32-bit integer
@@ -15186,6 +15246,7 @@ export
1518615246 glCopyToContext,
1518715247 glSetAntialias,
1518815248 glDraw,
15249+ glDrawUntextured,
1518915250 glDrawPointsTransform,
1519015251 glDrawOutlineTransform,
1519115252 glDrawPoints,
0 commit comments