pixi-marrow 0.2.0 → 0.3.0

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.
package/AGENTS.md CHANGED
@@ -4,7 +4,7 @@ This file ships in the npm package `pixi-marrow`. It tells a coding agent how to
4
4
 
5
5
  ## What the package is
6
6
 
7
- pixi-marrow is a Spine runtime for PixiJS v8. It plays skeletons that the Spine editor exported as 4.1, 4.2 or 4.3, on WebGL2 and WebGPU. `MarrowSpine` is a Pixi `Container`. The package needs `pixi.js` 8.23 or later and has no other dependency.
7
+ pixi-marrow is a Spine runtime for PixiJS v8. It plays skeletons that the Spine editor exported as 4.1, 4.2 or 4.3, on WebGL2, WebGPU and WebGL1. On WebGL1, `skinning: 'gpu'` and instancing draw nothing. `MarrowSpine` is a Pixi `Container`. The package needs `pixi.js` 8.23 or later and has no other dependency.
8
8
 
9
9
  ```bash
10
10
  npm install pixi-marrow pixi.js
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # pixi-marrow
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#45](https://github.com/schmooky/pixi-marrow/pull/45) [`4adbbec`](https://github.com/schmooky/pixi-marrow/commit/4adbbecc39cee22482b34771cea1c4c67b4290a6) Thanks [@igaming-bulochka](https://github.com/igaming-bulochka)! - Skeletons draw on WebGL1, the context Pixi falls back to where a browser has no WebGL2. The batched mode, the mesh mode with `skinning: 'cpu'` and clip masks get a second program of GLSL 1.00, made from the same sources. WebGL2 and WebGPU compile the same programs as before. The warning `this renderer draws no skeleton` now shows on the Canvas renderer alone. A render of another renderer inside a render no longer changes which program the outer render uses.
8
+
9
+ `skinning: 'gpu'` and instancing still need WebGL2 or WebGPU. On WebGL1 they draw nothing, their clip masks included, and warn once. They upload nothing there and report 0 draw calls. A WebGL1 device without 32-bit indices warns once: a batch or a mesh of more than 65535 vertices draws nothing there.
10
+
3
11
  ## 0.2.0
4
12
 
5
13
  ### Minor Changes
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![CI](https://github.com/schmooky/pixi-marrow/actions/workflows/ci.yml/badge.svg)](https://github.com/schmooky/pixi-marrow/actions/workflows/ci.yml)
5
5
  [![Licence: Spine Runtimes License](https://img.shields.io/badge/licence-Spine%20Runtimes%20License-blue)](LICENSE)
6
6
 
7
- pixi-marrow is a fast Spine runtime for PixiJS v8 (pixi.js <!-- fact:floor.pixiShort -->8.23<!-- /fact --> or later). It plays Spine 4.1, 4.2 and 4.3 skeletons on WebGL2 and WebGPU with its own pose core and its own render path. It is an alternative to the official `@esotericsoftware/spine-pixi-v8` and to `pixi-spine`, and it does not ship `spine-core`.
7
+ pixi-marrow is a fast Spine runtime for PixiJS v8 (pixi.js <!-- fact:floor.pixiShort -->8.23<!-- /fact --> or later). It plays Spine 4.1, 4.2 and 4.3 skeletons on WebGL2, WebGPU and WebGL1 with its own pose core and its own render path. It is an alternative to the official `@esotericsoftware/spine-pixi-v8` and to `pixi-spine`, and it does not ship `spine-core`.
8
8
 
9
9
  - [Docs](https://pixi-marrow.schmooky.dev): the guide, How it works and the reference.
10
10
  - [Playground](https://pixi-marrow.schmooky.dev/playground/): drop your own Spine files on it.
@@ -1,3 +1,4 @@
1
+ import { serveWebGL1 } from "./glsl100.js";
1
2
  import { GlProgram, GpuProgram, Shader, getBatchSamplersUniformGroup } from "pixi.js";
2
3
  // src/render/batch-shader.ts
3
4
  const range = (count) => Array.from({ length: count }, (_, i) => i);
@@ -142,8 +143,8 @@ return ${color};
142
143
  /** The shaders that exist, by texture count and tint mode. All batchers of a kind share one. */
143
144
  const shaders = /* @__PURE__ */ new Map();
144
145
  /**
145
- * The shader that draws the batches of skeletons: a WebGL2 program and a WebGPU program with the
146
- * same output. A batch samples up to `textures` textures, and attribute `aFlags.x` selects one of
146
+ * The shader that draws the batches of skeletons: a WebGL2 program, its WebGL1 twin and a WebGPU
147
+ * program with the same output. A batch samples up to `textures` textures, and attribute `aFlags.x` selects one of
147
148
  * them. `dark` adds the dark color attribute and the two color tint of the official runtime.
148
149
  *
149
150
  * The output is premultiplied, and so must the textures be on the GPU. Every call with the same
@@ -158,11 +159,13 @@ function createBatchShader(textures, dark) {
158
159
  let shader = shaders.get(name);
159
160
  if (shader === void 0) {
160
161
  const source = wgsl(dark, textures);
162
+ const vertex = glVertex(dark);
163
+ const fragment = glFragment(dark, textures);
161
164
  shader = new Shader({
162
165
  glProgram: GlProgram.from({
163
166
  name,
164
- vertex: glVertex(dark),
165
- fragment: glFragment(dark, textures)
167
+ vertex,
168
+ fragment
166
169
  }),
167
170
  gpuProgram: GpuProgram.from({
168
171
  name,
@@ -177,6 +180,7 @@ function createBatchShader(textures, dark) {
177
180
  }),
178
181
  resources: { batchSamplers: getBatchSamplersUniformGroup(textures) }
179
182
  });
183
+ serveWebGL1(shader, name, vertex, fragment);
180
184
  shaders.set(name, shader);
181
185
  }
182
186
  return shader;
@@ -4,6 +4,10 @@ import { DOCS_SITE } from "../base/errors.js";
4
4
  const watched = /* @__PURE__ */ new WeakSet();
5
5
  /** True while the renderer that renders at the moment has lost its context. */
6
6
  let lost = false;
7
+ /** True while the renderer that renders at the moment is one of WebGL1. */
8
+ let old = false;
9
+ /** The answers of the renders that are under way around the current one: bit 1 lost, bit 2 old. */
10
+ const outer = [];
7
11
  /**
8
12
  * Whether the renderer that draws at the moment has lost its WebGL context. What draws a
9
13
  * skeleton asks this right before it draws, and draws nothing when it is true.
@@ -15,23 +19,42 @@ function contextLost() {
15
19
  return lost;
16
20
  }
17
21
  /**
18
- * Whether a renderer can draw no skeleton at all: one of WebGL1, or one that is neither WebGL
19
- * nor WebGPU, as the Canvas renderer of Pixi.
22
+ * Whether the renderer that draws at the moment is one of WebGL1. The shaders ask it for the
23
+ * program they hand Pixi, see `glsl100.ts`.
24
+ *
25
+ * @example
26
+ * const program = webGL1() ? programOf100 : programOf300;
27
+ */
28
+ function webGL1() {
29
+ return old;
30
+ }
31
+ /**
32
+ * Whether a renderer is one of WebGL1. Pixi falls back to WebGL1 where a browser has no WebGL2.
33
+ *
34
+ * @example
35
+ * if (isWebGL1(renderer)) console.log('GLSL 1.00');
36
+ */
37
+ function isWebGL1(renderer) {
38
+ return "gl" in renderer && renderer.context?.webGLVersion === 1;
39
+ }
40
+ /**
41
+ * Whether a renderer can draw no skeleton at all: one that is neither WebGL nor WebGPU, as the
42
+ * Canvas renderer of Pixi.
20
43
  *
21
44
  * @example
22
45
  * if (drawsNothing(renderer)) stats.drawCalls = 0;
23
46
  */
24
47
  function drawsNothing(renderer) {
25
- return "gl" in renderer && renderer.context?.webGLVersion === 1 || renderer.type > 2;
48
+ return renderer.type > 2;
26
49
  }
27
50
  /**
28
51
  * Makes a renderer say before each of its renders whether its WebGL context is lost. The first
29
52
  * call for a renderer adds one listener to it, later calls do nothing. Call it before the
30
53
  * renderer first draws a skeleton: the answer for the render that is under way is set at once.
31
54
  *
32
- * A renderer without a WebGL context, as the one of WebGPU, never counts as lost. A renderer of
33
- * WebGL1 always counts as lost, and warns once. So does a renderer whose `type` names neither
34
- * WebGL nor WebGPU.
55
+ * A renderer without a WebGL context, as the one of WebGPU, never counts as lost. A renderer
56
+ * whose `type` names neither WebGL nor WebGPU always counts as lost, and warns once. A renderer
57
+ * of WebGL1 without 32-bit indices warns once too.
35
58
  *
36
59
  * @example
37
60
  * watchContext(renderer);
@@ -40,12 +63,25 @@ function drawsNothing(renderer) {
40
63
  function watchContext(renderer) {
41
64
  if (watched.has(renderer)) return;
42
65
  watched.add(renderer);
43
- const old = drawsNothing(renderer);
44
- if (old) console.warn(`pixi-marrow: this renderer draws no skeleton. Use WebGL2 or WebGPU. ${DOCS_SITE}good-to-know/#limits`);
45
- const watch = { prerender() {
46
- lost = old || "gl" in renderer && renderer.gl.isContextLost();
47
- } };
66
+ const none = drawsNothing(renderer);
67
+ const one = isWebGL1(renderer);
68
+ if (none) console.warn(`pixi-marrow: this renderer draws no skeleton. Use WebGL2 or WebGPU. ${DOCS_SITE}good-to-know/#limits`);
69
+ if (one && "gl" in renderer && !renderer.context.supports.uint32Indices) console.warn(`pixi-marrow: this WebGL1 device has no 32-bit indices. A batch or a mesh of more than 65535 vertices draws nothing. ${DOCS_SITE}good-to-know/#limits`);
70
+ const watch = {
71
+ prerender() {
72
+ outer.push((lost ? 1 : 0) | (old ? 2 : 0));
73
+ lost = none || "gl" in renderer && renderer.gl.isContextLost();
74
+ old = one;
75
+ },
76
+ postrender() {
77
+ const was = outer.pop();
78
+ if (was === void 0) return;
79
+ lost = (was & 1) !== 0;
80
+ old = (was & 2) !== 0;
81
+ }
82
+ };
48
83
  renderer.runners.prerender.add(watch);
84
+ renderer.runners.postrender.add(watch);
49
85
  watch.prerender();
50
86
  }
51
- export { contextLost, drawsNothing, watchContext };
87
+ export { contextLost, drawsNothing, isWebGL1, watchContext, webGL1 };
@@ -0,0 +1,54 @@
1
+ import { webGL1 } from "./context-watch.js";
2
+ import { GlProgram } from "pixi.js";
3
+ // src/render/glsl100.ts
4
+ /** The shaders that have a program for WebGL1. */
5
+ const served = /* @__PURE__ */ new WeakSet();
6
+ /**
7
+ * A GLSL 3.00 source as GLSL 1.00 that Pixi completes: without its version and without `flat`.
8
+ *
9
+ * @example
10
+ * toGlsl100('#version 300 es\nflat out float vPage;'); // '\nout float vPage;'
11
+ */
12
+ function toGlsl100(source) {
13
+ return source.replace("#version 300 es", "").replace(/\bflat /g, "");
14
+ }
15
+ /**
16
+ * Gives a shader a program for WebGL1, made from the GLSL 3.00 sources of its program. In a
17
+ * render of a WebGL1 renderer `shader.glProgram` is then that program. Returns the shader.
18
+ *
19
+ * @example
20
+ * const shader = serveWebGL1(new Shader({ glProgram, gpuProgram, resources }), name, vertex, fragment);
21
+ */
22
+ function serveWebGL1(shader, name, vertex, fragment) {
23
+ let modern = shader.glProgram;
24
+ let old;
25
+ Object.defineProperty(shader, "glProgram", {
26
+ configurable: true,
27
+ enumerable: true,
28
+ get() {
29
+ if (modern === null || !webGL1()) return modern;
30
+ old ??= GlProgram.from({
31
+ name: `${name}-100`,
32
+ vertex: toGlsl100(vertex),
33
+ fragment: toGlsl100(fragment)
34
+ });
35
+ return old;
36
+ },
37
+ set(value) {
38
+ modern = value;
39
+ }
40
+ });
41
+ served.add(shader);
42
+ return shader;
43
+ }
44
+ /**
45
+ * Whether a shader can draw on the renderer of this render: always, except on WebGL1 without a
46
+ * program of {@link serveWebGL1}.
47
+ *
48
+ * @example
49
+ * if (!drawsHere(mesh.shader)) return false;
50
+ */
51
+ function drawsHere(shader) {
52
+ return !webGL1() || shader !== null && served.has(shader);
53
+ }
54
+ export { drawsHere, serveWebGL1, toGlsl100 };
@@ -1,4 +1,4 @@
1
- import { contextLost, watchContext } from "./context-watch.js";
1
+ import { contextLost, watchContext, webGL1 } from "./context-watch.js";
2
2
  import { bendsEdges } from "./gate.js";
3
3
  import { INSTANCE_PIPE } from "./instance-id.js";
4
4
  import { RunPart } from "./instance-part.js";
@@ -105,11 +105,14 @@ var InstancePipe = class {
105
105
  }
106
106
  /** A body keeps nothing in the pipe. */
107
107
  destroyRenderable() {}
108
- /** Draws a run, in as few instanced draws as its members allow. Draws nothing while the context is lost. */
108
+ /**
109
+ * Draws a run, in as few instanced draws as its members allow. Draws nothing while the context
110
+ * is lost, and nothing on WebGL1: the instance shader is GLSL 3.00 alone, see `glsl100.ts`.
111
+ */
109
112
  execute(run) {
110
113
  const { renderer } = this;
111
114
  const { members } = run;
112
- if (renderer === null || contextLost()) return;
115
+ if (renderer === null || contextLost() || webGL1()) return;
113
116
  const bends = bendsEdges(renderer);
114
117
  let parts = 0;
115
118
  for (const body of members) if (!body.destroyed) body.gate.beforeDraw(bends);
@@ -1,8 +1,8 @@
1
- import { MarrowError } from "../base/errors.js";
1
+ import { DOCS_SITE, MarrowError } from "../base/errors.js";
2
2
  import { i16, i32 } from "../pose/shared/read.js";
3
3
  import { isNewer } from "../pose/state.js";
4
4
  import { clipCode, clipCodeMissing } from "./clip-code.js";
5
- import { drawsNothing } from "./context-watch.js";
5
+ import { drawsNothing, isWebGL1 } from "./context-watch.js";
6
6
  import { bendsEdges } from "./gate.js";
7
7
  import { instanceBlock, instanceLayout, setupVertices, unionSpread } from "./instance-layout.js";
8
8
  import { InstancePaint } from "./instance-paint.js";
@@ -26,6 +26,16 @@ function shown(node) {
26
26
  for (; node !== null; node = node.parent) if (!node.visible) return false;
27
27
  return true;
28
28
  }
29
+ /** Whether the warning of {@link warnGpuOnWebGL1} was given. */
30
+ let warnedGpu = false;
31
+ /** Says once that `skinning: 'gpu'` draws nothing on WebGL1, and returns true. */
32
+ function warnGpuOnWebGL1() {
33
+ if (!warnedGpu) {
34
+ warnedGpu = true;
35
+ console.warn(`pixi-marrow: skinning: 'gpu' and instancing need WebGL2. Set skinning: 'cpu' for WebGL1. ${DOCS_SITE}good-to-know/#limits`);
36
+ }
37
+ return true;
38
+ }
29
39
  /**
30
40
  * What a view draws with in the mesh mode. These are three Pixi vertex buffers on the data of
31
41
  * its vertex ranges, the draw ranges with their meshes, and the child that asks the view before
@@ -88,11 +98,13 @@ var MeshPaint = class {
88
98
  if (!gpu) restoreColors(template);
89
99
  this.stats = stats;
90
100
  this.container.onRender = (renderer) => {
101
+ if (renderer !== this.linked) {
102
+ linkMeshPipe(renderer);
103
+ this.linked = renderer;
104
+ this.blind = drawsNothing(renderer) || gpu && isWebGL1(renderer) && warnGpuOnWebGL1();
105
+ if (this.blind) stats.drawCalls = stats.maskDraws = stats.indices = 0;
106
+ }
91
107
  this.flush();
92
- if (renderer === this.linked) return;
93
- linkMeshPipe(renderer);
94
- this.linked = renderer;
95
- this.blind = drawsNothing(renderer);
96
108
  };
97
109
  this.positions = vertexBuffer(template.positions, "marrow-positions");
98
110
  this.statics = vertexBuffer(template.statics, "marrow-uvs");
@@ -195,7 +207,7 @@ var MeshPaint = class {
195
207
  */
196
208
  flush() {
197
209
  const { positions, colors, waiting } = this;
198
- if (!shown(this.container)) return;
210
+ if (this.blind || !shown(this.container)) return;
199
211
  if (this.skin !== void 0) this.note("bones", this.skin.flush());
200
212
  this.note("positions", uploadWaiting(positions, waiting, 0, 8));
201
213
  if (colors !== void 0) this.note("statics", uploadWaiting(colors, waiting, 2, this.colorBytes));
@@ -246,8 +258,8 @@ var MeshPaint = class {
246
258
  if (instance !== void 0) {
247
259
  instance.show(template, seen, skipped);
248
260
  stats.maskDraws = 0;
249
- stats.drawCalls = seen.count > 0 ? 1 : 0;
250
- stats.indices = indices;
261
+ stats.drawCalls = seen.count > 0 && !this.blind ? 1 : 0;
262
+ stats.indices = this.blind ? 0 : indices;
251
263
  stats.bufferBytes = templateBytes(template) + ranges.bytes + instance.bytes;
252
264
  return;
253
265
  }
@@ -1,4 +1,5 @@
1
- import { contextLost } from "./context-watch.js";
1
+ import { contextLost, webGL1 } from "./context-watch.js";
2
+ import { drawsHere } from "./glsl100.js";
2
3
  import { MeasuredGeometry } from "./measured-geometry.js";
3
4
  import { Buffer, BufferUsage, Mesh } from "pixi.js";
4
5
  // src/render/range-mesh.ts
@@ -7,16 +8,20 @@ const CLIP_LABEL = "marrow-clip";
7
8
  /**
8
9
  * A Pixi mesh of the mesh mode: a draw range or a clip mask. Pixi asks a mesh right before it
9
10
  * draws it whether it can be drawn. This one says no while the WebGL context of the renderer is
10
- * lost, see `context-watch.ts`.
11
+ * lost, see `context-watch.ts`, and on WebGL1 when its shader has no program for it, see
12
+ * `glsl100.ts`. A mask of a view that draws on WebGL2 alone says no on WebGL1 too: its shader
13
+ * compiles there, but nothing it clips draws.
11
14
  *
12
15
  * @example
13
16
  * const mesh = new RangeMesh({ geometry, shader: createMaskShader() });
14
17
  * console.log(mesh.isRenderable); // true, unless the browser took the context
15
18
  */
16
19
  var RangeMesh = class RangeMesh extends Mesh {
17
- /** Whether Pixi draws the mesh: it is visible, and the renderer has its context. */
20
+ /** True for a mesh that draws nothing on WebGL1: a clip mask of a view with `skinning: 'gpu'`. */
21
+ modern = false;
22
+ /** Whether Pixi draws the mesh: it is visible, the renderer has its context, and the shader compiles there. */
18
23
  get isRenderable() {
19
- return !contextLost() && super.isRenderable;
24
+ return !contextLost() && drawsHere(this.shader) && !(this.modern && webGL1()) && super.isRenderable;
20
25
  }
21
26
  /**
22
27
  * Tells Pixi that the meshes of a view show other vertices: the draw ranges in a container,
@@ -296,6 +296,7 @@ var DrawRanges = class {
296
296
  const container = new Container({ label: CLIP_LABEL });
297
297
  this.maskShader ??= createMaskShader();
298
298
  const mask = new ClipMask(this.maskShader, measure);
299
+ mask.mesh.modern = this.options.shade !== void 0;
299
300
  const group = {
300
301
  container,
301
302
  mask,
@@ -1,3 +1,4 @@
1
+ import { serveWebGL1 } from "./glsl100.js";
1
2
  import { GlProgram, GpuProgram, Shader } from "pixi.js";
2
3
  // src/render/shader.ts
3
4
  const range = (count) => Array.from({ length: count }, (_, i) => i);
@@ -227,8 +228,8 @@ function releaseShader(shader) {
227
228
  }
228
229
  }
229
230
  /**
230
- * The shader that draws one range of a skeleton: a WebGL2 program and a WebGPU program with the
231
- * same output. `sources` are the pages the range samples, 1 to `MAX_PAGES`. Vertex
231
+ * The shader that draws one range of a skeleton: a WebGL2 program, its WebGL1 twin and a WebGPU
232
+ * program with the same output. `sources` are the pages the range samples, 1 to `MAX_PAGES`. Vertex
232
233
  * attribute `aFlags.x` selects one of them. `dark` adds the dark color attribute and the two color
233
234
  * tint of the official runtime.
234
235
  *
@@ -254,11 +255,13 @@ function createViewShader(sources, dark) {
254
255
  resources[`uTexture${i}`] = page;
255
256
  resources[`uSampler${i}`] = page.style;
256
257
  });
258
+ const vertex = glVertex(dark, pages);
259
+ const fragment = glFragment(dark, pages);
257
260
  const shader = new Shader({
258
261
  glProgram: GlProgram.from({
259
262
  name,
260
- vertex: glVertex(dark, pages),
261
- fragment: glFragment(dark, pages)
263
+ vertex,
264
+ fragment
262
265
  }),
263
266
  gpuProgram: GpuProgram.from({
264
267
  name,
@@ -273,6 +276,7 @@ function createViewShader(sources, dark) {
273
276
  }),
274
277
  resources
275
278
  });
279
+ serveWebGL1(shader, name, vertex, fragment);
276
280
  if (first !== void 0) {
277
281
  if (shared === void 0) viewShaders.set(first, /* @__PURE__ */ new Map([[key, shader]]));
278
282
  else shared.set(key, shader);
@@ -384,6 +388,7 @@ function createMaskShader() {
384
388
  }),
385
389
  resources: {}
386
390
  });
391
+ serveWebGL1(maskShader, name, GL_MASK_VERTEX, GL_MASK_FRAGMENT);
387
392
  return retain(maskShader);
388
393
  }
389
394
  export { GL_ROUND, WGSL_ROUND, createMaskShader, createViewShader, glFragment, releaseShader, wgslFragment, wgslHead };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pixi-marrow",
3
- "version": "0.2.0",
4
- "description": "A fast Spine runtime for PixiJS v8 with its own pose core. Plays Spine 4.1, 4.2 and 4.3 skeletons on WebGL2 and WebGPU.",
3
+ "version": "0.3.0",
4
+ "description": "A fast Spine runtime for PixiJS v8 with its own pose core. Plays Spine 4.1, 4.2 and 4.3 skeletons on WebGL2, WebGPU and WebGL1.",
5
5
  "license": "LicenseRef-LICENSE",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -40,7 +40,7 @@
40
40
  "./package.json": "./package.json"
41
41
  },
42
42
  "bin": {
43
- "pixi-marrow": "./bin/pixi-marrow.mjs"
43
+ "pixi-marrow": "bin/pixi-marrow.mjs"
44
44
  },
45
45
  "files": [
46
46
  "dist",