@flighthq/render-gl 0.3.1-next.837.46a9259 → 0.3.1-next.847.2e6f8bf

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +11 -11
  2. package/src/glShader.test.ts +28 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/render-gl",
3
- "version": "0.3.1-next.837.46a9259",
3
+ "version": "0.3.1-next.847.2e6f8bf",
4
4
  "author": "Joshua Granick and other contributors",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,16 +38,16 @@
38
38
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
39
39
  },
40
40
  "dependencies": {
41
- "@flighthq/color": "0.3.1-next.837.46a9259",
42
- "@flighthq/entity": "0.3.1-next.837.46a9259",
43
- "@flighthq/log": "0.3.1-next.837.46a9259",
44
- "@flighthq/scene2d": "0.3.1-next.837.46a9259",
45
- "@flighthq/geometry": "0.3.1-next.837.46a9259",
46
- "@flighthq/render": "0.3.1-next.837.46a9259",
47
- "@flighthq/registry": "0.3.1-next.837.46a9259",
48
- "@flighthq/signals": "0.3.1-next.837.46a9259",
49
- "@flighthq/texture": "0.3.1-next.837.46a9259",
50
- "@flighthq/types": "0.3.1-next.837.46a9259"
41
+ "@flighthq/color": "0.3.1-next.847.2e6f8bf",
42
+ "@flighthq/entity": "0.3.1-next.847.2e6f8bf",
43
+ "@flighthq/log": "0.3.1-next.847.2e6f8bf",
44
+ "@flighthq/scene2d": "0.3.1-next.847.2e6f8bf",
45
+ "@flighthq/geometry": "0.3.1-next.847.2e6f8bf",
46
+ "@flighthq/render": "0.3.1-next.847.2e6f8bf",
47
+ "@flighthq/registry": "0.3.1-next.847.2e6f8bf",
48
+ "@flighthq/signals": "0.3.1-next.847.2e6f8bf",
49
+ "@flighthq/texture": "0.3.1-next.847.2e6f8bf",
50
+ "@flighthq/types": "0.3.1-next.847.2e6f8bf"
51
51
  },
52
52
  "devDependencies": {
53
53
  "typescript": "^5.3.0"
@@ -233,6 +233,34 @@ describe('setGlBaseUniforms', () => {
233
233
  });
234
234
 
235
235
  describe('setGlMatrixFromTransform', () => {
236
+ it('projects the quad corner order to a clockwise triangle, which is why 2D draws need culling off', () => {
237
+ // Measured in a real WebGL2 context, not argued: with CULL_FACE enabled and the CCW default, this
238
+ // quad renders 0 lit pixels where it otherwise renders 2304 — a single-sided 3D draw earlier in the
239
+ // frame therefore erases all 2D content. `renderGlScene2D` disables CULL_FACE because of THIS, and
240
+ // without an assertion the reason lives only in a comment: someone who later made the winding CCW
241
+ // would find the disable looking superfluous. The corner order below mirrors the quadVertexData
242
+ // fill in glDraw.ts and must be changed with it.
243
+ const gl = makeGL();
244
+ const m = new Float32Array(9);
245
+ const canvas = document.createElement('canvas');
246
+ canvas.width = 200;
247
+ canvas.height = 100;
248
+ setGlMatrixFromTransform(gl, makeShaderLoc(), m, { a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 }, canvas);
249
+
250
+ const project = (x: number, y: number): [number, number] => [
251
+ m[0] * x + m[3] * y + m[6],
252
+ m[1] * x + m[4] * y + m[7],
253
+ ];
254
+ const [x0, y0, x1, y1] = [20, 30, 120, 80];
255
+ const [ax, ay] = project(x0, y0);
256
+ const [bx, by] = project(x1, y0);
257
+ const [cx, cy] = project(x1, y1);
258
+
259
+ // Signed area of the first indexed triangle (indices [0, 1, 2]); negative is clockwise.
260
+ const signedArea = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
261
+ expect(signedArea).toBeLessThan(0);
262
+ });
263
+
236
264
  it('computes matrix scaled by canvas dimensions for identity transform', () => {
237
265
  const gl = makeGL();
238
266
  const loc = makeShaderLoc();