Skip to content

Commit 3a1408c

Browse files
build
1 parent d7e6888 commit 3a1408c

6 files changed

Lines changed: 213 additions & 20 deletions

File tree

dist/littlejs.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,18 @@ declare module "littlejsengine" {
20722072
* @param {number} [rgbaAdditive=0] - black is 0
20732073
* @memberof WebGL */
20742074
export function glDraw(x: number, y: number, sizeX: number, sizeY: number, angle?: number, uv0X?: number, uv0Y?: number, uv1X?: number, uv1Y?: number, rgba?: number, rgbaAdditive?: number): void;
2075+
/** Add an untextured rect to the gl draw list
2076+
* Picks the optimal path: if already in poly mode, emits a tristrip rect
2077+
* so it batches with surrounding polys; otherwise uses the instanced path
2078+
* with uvs and rgba zeroed so the color falls through the additive slot.
2079+
* @param {number} x
2080+
* @param {number} y
2081+
* @param {number} sizeX
2082+
* @param {number} sizeY
2083+
* @param {number} angle
2084+
* @param {number} rgba - color as 32-bit integer
2085+
* @memberof WebGL */
2086+
export function glDrawUntextured(x: number, y: number, sizeX: number, sizeY: number, angle: number, rgba: number): void;
20752087
/** Transform and add a polygon to the gl draw list
20762088
* @param {Array<Vector2>} points - Array of Vector2 points
20772089
* @param {number} rgba - Color of the polygon as a 32-bit integer

dist/littlejs.esm.js

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

dist/littlejs.esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/littlejs.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

dist/littlejs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/littlejs.release.js

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,13 +3423,12 @@ function drawTile(pos, size=vec2(1), tileInfo, color=WHITE,
34233423
}
34243424
else
34253425
{
3426-
// if no tile info, force untextured by zeroing rgba (so whatever
3427-
// texture is bound doesn't leak in) and folding color+additive
3428-
// into the additive slot — matches the Canvas2D path's
3429-
// color.add(additiveColor) on line ~337.
3426+
// untextured: glDrawUntextured picks the optimal path (poly
3427+
// tristrip if already in poly mode, otherwise instanced with
3428+
// uvs/rgba zeroed). Color+additive are folded together to match
3429+
// the Canvas2D path's color.add(additiveColor) on line ~337.
34303430
const combined = additiveColor ? color.add(additiveColor) : color;
3431-
glDraw(pos.x, pos.y, size.x, size.y, angle, 0, 0, 0, 0,
3432-
0, combined.rgbaInt());
3431+
glDrawUntextured(pos.x, pos.y, size.x, size.y, angle, combined.rgbaInt());
34333432
}
34343433
}
34353434
else
@@ -7820,6 +7819,67 @@ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgb
78207819
glPositionData[offset++] = angle;
78217820
}
78227821

7822+
/** Add an untextured rect to the gl draw list
7823+
* Picks the optimal path: if already in poly mode, emits a tristrip rect
7824+
* so it batches with surrounding polys; otherwise uses the instanced path
7825+
* with uvs and rgba zeroed so the color falls through the additive slot.
7826+
* @param {number} x
7827+
* @param {number} y
7828+
* @param {number} sizeX
7829+
* @param {number} sizeY
7830+
* @param {number} angle
7831+
* @param {number} rgba - color as 32-bit integer
7832+
* @memberof WebGL */
7833+
function glDrawUntextured(x, y, sizeX, sizeY, angle, rgba)
7834+
{
7835+
if (glPolyMode)
7836+
{
7837+
// batch with surrounding polys as a 4-vertex tristrip rect
7838+
const vertCount = 6; // 4 corners + 2 degenerate verts
7839+
if (glBatchCount+vertCount >= gl_MAX_POLY_VERTEXES || glBatchAdditive !== glAdditive)
7840+
glFlush();
7841+
7842+
// compute rotated corners in world space (matches glDrawPointsTransform rotation)
7843+
const hx = sizeX*.5, hy = sizeY*.5;
7844+
const c = cos(angle), s = sin(angle);
7845+
const chx = c*hx, shx = s*hx, chy = c*hy, shy = s*hy;
7846+
const x0 = x - chx - shy, y0 = y + shx - chy; // (-hx,-hy)
7847+
const x1 = x + chx - shy, y1 = y - shx - chy; // ( hx,-hy)
7848+
const x2 = x - chx + shy, y2 = y + shx + chy; // (-hx, hy)
7849+
const x3 = x + chx + shy, y3 = y - shx + chy; // ( hx, hy)
7850+
7851+
// write tristrip with leading/trailing degenerate verts
7852+
let offset = glBatchCount * gl_INDICES_PER_POLY_VERTEX;
7853+
glPositionData[offset++] = x0; glPositionData[offset++] = y0; glColorData[offset++] = rgba;
7854+
glPositionData[offset++] = x0; glPositionData[offset++] = y0; glColorData[offset++] = rgba;
7855+
glPositionData[offset++] = x1; glPositionData[offset++] = y1; glColorData[offset++] = rgba;
7856+
glPositionData[offset++] = x2; glPositionData[offset++] = y2; glColorData[offset++] = rgba;
7857+
glPositionData[offset++] = x3; glPositionData[offset++] = y3; glColorData[offset++] = rgba;
7858+
glPositionData[offset++] = x3; glPositionData[offset++] = y3; glColorData[offset++] = rgba;
7859+
glBatchCount += vertCount;
7860+
return;
7861+
}
7862+
7863+
// instanced path: zero uvs and rgba so the texture contribution is killed,
7864+
// then carry the real color in the additive slot
7865+
if (glBatchCount >= gl_MAX_INSTANCES || glBatchAdditive !== glAdditive)
7866+
glFlush();
7867+
glSetInstancedMode();
7868+
7869+
let offset = glBatchCount++ * gl_INDICES_PER_INSTANCE;
7870+
glPositionData[offset++] = x;
7871+
glPositionData[offset++] = y;
7872+
glPositionData[offset++] = sizeX;
7873+
glPositionData[offset++] = sizeY;
7874+
glPositionData[offset++] = 0;
7875+
glPositionData[offset++] = 0;
7876+
glPositionData[offset++] = 0;
7877+
glPositionData[offset++] = 0;
7878+
glColorData[offset++] = 0;
7879+
glColorData[offset++] = rgba;
7880+
glPositionData[offset++] = angle;
7881+
}
7882+
78237883
/** Transform and add a polygon to the gl draw list
78247884
* @param {Array<Vector2>} points - Array of Vector2 points
78257885
* @param {number} rgba - Color of the polygon as a 32-bit integer

0 commit comments

Comments
 (0)