spryte 0.3.0 → 0.4.1
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/README.md +10 -7
- package/dist/backend.d.ts +2 -2
- package/dist/backend.d.ts.map +1 -1
- package/dist/canvas2d.d.ts +1 -1
- package/dist/canvas2d.d.ts.map +1 -1
- package/dist/canvas2d.js +2 -0
- package/dist/canvas2d.js.map +1 -1
- package/dist/draw.d.ts +14 -4
- package/dist/draw.d.ts.map +1 -1
- package/dist/draw.js +23 -4
- package/dist/draw.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/phaser.d.ts +80 -0
- package/dist/phaser.d.ts.map +1 -0
- package/dist/phaser.js +100 -0
- package/dist/phaser.js.map +1 -0
- package/dist/shared.d.ts +29 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +134 -0
- package/dist/shared.js.map +1 -0
- package/dist/webgl2.d.ts +21 -11
- package/dist/webgl2.d.ts.map +1 -1
- package/dist/webgl2.js +16 -13
- package/dist/webgl2.js.map +1 -1
- package/package.json +8 -2
package/dist/phaser.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createSharedRenderer } from "./shared.js";
|
|
2
|
+
/**
|
|
3
|
+
* Draw with spryte in an `Extern`'s slot: `render` is called each frame with a `Draw` whose transform is the
|
|
4
|
+
* Extern's `calcMatrix` (the camera, and any Container it's in), so world coordinates are Phaser's. Filters on the
|
|
5
|
+
* Extern or its camera, camera viewports and `Stencil` masks apply, since spryte draws into Phaser's drawing context
|
|
6
|
+
* under its state. The game must run on a WebGL2 context (`createPhaserContext`).
|
|
7
|
+
*/
|
|
8
|
+
export function spryteExtern(extern, render, options = {}) {
|
|
9
|
+
let shared = null;
|
|
10
|
+
extern.render = (renderer, context, m) => {
|
|
11
|
+
const gl = renderer.gl;
|
|
12
|
+
if (typeof WebGL2RenderingContext === "undefined" || !(gl instanceof WebGL2RenderingContext))
|
|
13
|
+
throw new Error("spryte/phaser: Phaser is on a WebGL1 context. Create the game with `...createPhaserContext()` in its config.");
|
|
14
|
+
shared ??= createSharedRenderer(gl, options);
|
|
15
|
+
// Phaser's full state for this destination, forced: it has only reset blend, VAO and textures for the Extern.
|
|
16
|
+
renderer.glWrapper.update(context.state, true);
|
|
17
|
+
shared.target(context.framebuffer?.webGLFramebuffer ?? null, context.width, context.height);
|
|
18
|
+
const draw = shared.draw;
|
|
19
|
+
draw.begin(null, context.width, context.height, 1);
|
|
20
|
+
draw.transform(m.a, m.b, m.c, m.d, m.e, m.f);
|
|
21
|
+
render(draw);
|
|
22
|
+
draw.end();
|
|
23
|
+
};
|
|
24
|
+
const dispose = () => {
|
|
25
|
+
shared?.draw.dispose();
|
|
26
|
+
shared = null;
|
|
27
|
+
};
|
|
28
|
+
extern.once?.("destroy", dispose);
|
|
29
|
+
return {
|
|
30
|
+
get draw() {
|
|
31
|
+
return shared?.draw ?? null;
|
|
32
|
+
},
|
|
33
|
+
dispose,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A WebGL2 context for Phaser to run on, with its shaders translated to GLSL ES 3.00 (`shimShaders`). Spread the
|
|
38
|
+
* result into the game config, with `type: Phaser.WEBGL`. `attributes` are the context's, defaulting to Phaser's
|
|
39
|
+
* (opaque, antialiased, premultiplied, with a stencil buffer, on the high-performance GPU). `gl` is the context;
|
|
40
|
+
* `context` is the same object, typed to fit whatever Phaser's config declares (a 2D context, in 4.2.1).
|
|
41
|
+
*/
|
|
42
|
+
export function createPhaserContext(canvas = document.createElement("canvas"), attributes = {}) {
|
|
43
|
+
const gl = canvas.getContext("webgl2", {
|
|
44
|
+
alpha: false,
|
|
45
|
+
antialias: true,
|
|
46
|
+
premultipliedAlpha: true,
|
|
47
|
+
stencil: true,
|
|
48
|
+
powerPreference: "high-performance",
|
|
49
|
+
...attributes,
|
|
50
|
+
});
|
|
51
|
+
if (!gl)
|
|
52
|
+
throw new Error("spryte/phaser: WebGL2 is unavailable in this browser");
|
|
53
|
+
shimShaders(gl);
|
|
54
|
+
return { canvas, context: gl, gl };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Translate every GLSL ES 1.00 shader compiled on `gl` to ES 3.00. Phaser 4's shaders are ES 1.00, and on a WebGL2
|
|
58
|
+
* context the ones that use derivatives (`Gradient`, noise objects with `noiseNormalMap`, `smoothPixelArt`) fail
|
|
59
|
+
* to compile, since `OES_standard_derivatives` is a WebGL1 extension (Phaser 4.2.1). Install it before
|
|
60
|
+
* `new Phaser.Game`; `createPhaserContext` does. Shaders that already declare `#version 300 es` pass through.
|
|
61
|
+
*/
|
|
62
|
+
export function shimShaders(gl) {
|
|
63
|
+
const types = new WeakMap();
|
|
64
|
+
const createShader = gl.createShader.bind(gl);
|
|
65
|
+
gl.createShader = (type) => {
|
|
66
|
+
const shader = createShader(type);
|
|
67
|
+
if (shader)
|
|
68
|
+
types.set(shader, type);
|
|
69
|
+
return shader;
|
|
70
|
+
};
|
|
71
|
+
const shaderSource = gl.shaderSource.bind(gl);
|
|
72
|
+
gl.shaderSource = (shader, source) => shaderSource(shader, /^\s*#version\s+300/.test(source) ? source : toEs300(source, types.get(shader) === gl.FRAGMENT_SHADER));
|
|
73
|
+
// Uniforms and attributes renamed in the source are looked up and bound by their new names.
|
|
74
|
+
const getUniformLocation = gl.getUniformLocation.bind(gl);
|
|
75
|
+
gl.getUniformLocation = (program, name) => getUniformLocation(program, renameIdentifier(name));
|
|
76
|
+
const getAttribLocation = gl.getAttribLocation.bind(gl);
|
|
77
|
+
gl.getAttribLocation = (program, name) => getAttribLocation(program, renameIdentifier(name));
|
|
78
|
+
const bindAttribLocation = gl.bindAttribLocation.bind(gl);
|
|
79
|
+
gl.bindAttribLocation = (program, index, name) => bindAttribLocation(program, index, renameIdentifier(name));
|
|
80
|
+
}
|
|
81
|
+
/** Identifiers that are keywords or built-in functions in ES 3.00 but were free in ES 1.00. */
|
|
82
|
+
const RESERVED = /\b(sample|centroid|smooth|layout|patch|uint|uvec[234]|texture)\b/g;
|
|
83
|
+
/** A uniform or attribute name (`smooth`, `smooth[0]`, `light.sample`) as `toEs300` renamed it. */
|
|
84
|
+
function renameIdentifier(name) {
|
|
85
|
+
return name.replace(RESERVED, "$1_");
|
|
86
|
+
}
|
|
87
|
+
/** @internal GLSL ES 1.00 to 3.00, for the constructs Phaser's shaders use. Exported for tests. */
|
|
88
|
+
export function toEs300(source, fragment) {
|
|
89
|
+
let out = source
|
|
90
|
+
.replace(/^[ \t]*#version\s+100.*$/m, "")
|
|
91
|
+
.replace(/^[ \t]*#extension\s+GL_(OES_standard_derivatives|EXT_shader_texture_lod)\b.*$/gm, "")
|
|
92
|
+
.replace(RESERVED, "$1_")
|
|
93
|
+
.replace(/\btexture(2D|Cube)(Lod|Proj)?(EXT)?\b/g, (_, _dim, fn) => (fn ? `texture${fn}` : "texture"));
|
|
94
|
+
if (fragment)
|
|
95
|
+
out = out.replace(/\bvarying\b/g, "in").replace(/\bgl_FragColor\b/g, "spryte_FragColor");
|
|
96
|
+
else
|
|
97
|
+
out = out.replace(/\battribute\b/g, "in").replace(/\bvarying\b/g, "out");
|
|
98
|
+
return `#version 300 es\n${fragment ? "out highp vec4 spryte_FragColor;\n" : ""}${out}`;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=phaser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phaser.js","sourceRoot":"","sources":["../src/phaser.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,oBAAoB,EAAmD,MAAM,aAAa,CAAC;AA2CpG;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAoB,EAAE,MAA4B,EAAE,OAAO,GAA0B,EAAE;IAClH,IAAI,MAAM,GAA0B,IAAI,CAAC;IACzC,MAAM,CAAC,MAAM,GAAG,CAAC,QAAQ,EAAE,OAAO,EAA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xB,OAAO,CAAC,wCAAwC,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAW,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;IAC1H,IAAI,QAAQ;QAAE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC;;QAClG,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IAC9E,OAAO,oBAAoB,QAAQ,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC;AAC1F,CAAC"}
|
package/dist/shared.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Draw } from "./draw.js";
|
|
2
|
+
export interface SharedRendererOptions {
|
|
3
|
+
/** Linear filtering for images by default. Pass false for pixel art. Default true. */
|
|
4
|
+
smooth?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** spryte drawing on a WebGL2 context another engine owns. See `createSharedRenderer`. */
|
|
7
|
+
export interface SharedRenderer {
|
|
8
|
+
readonly draw: Draw;
|
|
9
|
+
/**
|
|
10
|
+
* Where the next `draw.begin()` draws: the host's framebuffer (null for the canvas) and its size in pixels. Call it
|
|
11
|
+
* when the host's destination changes, such as a filter or post-processing pass that renders into its own
|
|
12
|
+
* framebuffer. Until it's called, drawing goes to the canvas at its current size.
|
|
13
|
+
*/
|
|
14
|
+
target(framebuffer: WebGLFramebuffer | null, width: number, height: number): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A `Draw` for a WebGL2 context another engine owns (Phaser, PixiJS, your own code), to draw with spryte inside the
|
|
18
|
+
* host's frame and in its draw order, on one GPU context with no overlay canvas. Create it inside the slot the host
|
|
19
|
+
* gives you for foreign drawing, since creating it changes GL state. Each frame, in that slot:
|
|
20
|
+
* `shared.target(...)` if the host's destination changed, `draw.begin(null, width, height, scale)` (null draws
|
|
21
|
+
* over the host's frame), draw, `draw.end()`.
|
|
22
|
+
*
|
|
23
|
+
* What spryte sets at `begin()` and leaves to the host afterwards is listed in `docs/architecture.md`. The host's
|
|
24
|
+
* scissor and stencil are respected: a camera viewport or mask applies to spryte's drawing too, and spryte's own
|
|
25
|
+
* clips intersect the host's scissor. Context loss is the host's: it must `preventDefault` on `webglcontextlost`
|
|
26
|
+
* for the browser to restore the context, and spryte rebuilds its GPU objects at the first `begin()` after.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createSharedRenderer(gl: WebGL2RenderingContext, options?: SharedRendererOptions): SharedRenderer;
|
|
29
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAIjC,MAAM,WAAW,qBAAqB;IACpC,sFAAsF;IACtF,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,0FAA0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,WAAW,EAAE,gBAAgB,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,sBAAsB,EAAE,OAAO,GAAE,qBAA0B,GAAG,cAAc,CAapH"}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Draw } from "./draw.js";
|
|
2
|
+
import { WebGL2Backend } from "./webgl2.js";
|
|
3
|
+
/**
|
|
4
|
+
* A `Draw` for a WebGL2 context another engine owns (Phaser, PixiJS, your own code), to draw with spryte inside the
|
|
5
|
+
* host's frame and in its draw order, on one GPU context with no overlay canvas. Create it inside the slot the host
|
|
6
|
+
* gives you for foreign drawing, since creating it changes GL state. Each frame, in that slot:
|
|
7
|
+
* `shared.target(...)` if the host's destination changed, `draw.begin(null, width, height, scale)` (null draws
|
|
8
|
+
* over the host's frame), draw, `draw.end()`.
|
|
9
|
+
*
|
|
10
|
+
* What spryte sets at `begin()` and leaves to the host afterwards is listed in `docs/architecture.md`. The host's
|
|
11
|
+
* scissor and stencil are respected: a camera viewport or mask applies to spryte's drawing too, and spryte's own
|
|
12
|
+
* clips intersect the host's scissor. Context loss is the host's: it must `preventDefault` on `webglcontextlost`
|
|
13
|
+
* for the browser to restore the context, and spryte rebuilds its GPU objects at the first `begin()` after.
|
|
14
|
+
*/
|
|
15
|
+
export function createSharedRenderer(gl, options = {}) {
|
|
16
|
+
const backend = new SharedBackend(gl);
|
|
17
|
+
const draw = new Draw(backend, options.smooth ?? true);
|
|
18
|
+
draw.resize(gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
19
|
+
return {
|
|
20
|
+
draw,
|
|
21
|
+
target(framebuffer, width, height) {
|
|
22
|
+
backend.fb = framebuffer;
|
|
23
|
+
backend.fbW = width;
|
|
24
|
+
backend.fbH = height;
|
|
25
|
+
draw.resize(width, height);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The WebGL2 backend on a host's context: draws into the host's framebuffer, assumes nothing about GL state between
|
|
31
|
+
* frames, keeps the host's scissor and stencil, and leaves no sampler objects bound (a host written for WebGL1 never
|
|
32
|
+
* binds samplers, so spryte's would override its texture filtering).
|
|
33
|
+
*/
|
|
34
|
+
class SharedBackend extends WebGL2Backend {
|
|
35
|
+
fb = null;
|
|
36
|
+
fbW;
|
|
37
|
+
fbH;
|
|
38
|
+
/** The host's scissor box at `begin()`, or null when its scissor test was off. */
|
|
39
|
+
hostScissor = null;
|
|
40
|
+
constructor(gl) {
|
|
41
|
+
super(gl);
|
|
42
|
+
this.fbW = gl.drawingBufferWidth;
|
|
43
|
+
this.fbH = gl.drawingBufferHeight;
|
|
44
|
+
// The host owns context loss; begin() notices it instead.
|
|
45
|
+
gl.canvas.removeEventListener("webglcontextlost", this.onLost);
|
|
46
|
+
gl.canvas.removeEventListener("webglcontextrestored", this.onRestored);
|
|
47
|
+
}
|
|
48
|
+
begin(clear, width, height) {
|
|
49
|
+
const gl = this.gl;
|
|
50
|
+
if (gl.isContextLost()) {
|
|
51
|
+
this.lost = true;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (this.lost)
|
|
55
|
+
this.onRestored();
|
|
56
|
+
// The host drew since last frame: rebind everything spryte otherwise assumes stays bound.
|
|
57
|
+
gl.useProgram(this.active.program);
|
|
58
|
+
gl.bindVertexArray(this.vao);
|
|
59
|
+
gl.enable(gl.BLEND);
|
|
60
|
+
gl.blendEquation(gl.FUNC_ADD);
|
|
61
|
+
this.applyBlend();
|
|
62
|
+
gl.disable(gl.DEPTH_TEST);
|
|
63
|
+
gl.disable(gl.CULL_FACE);
|
|
64
|
+
gl.colorMask(true, true, true, true);
|
|
65
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
66
|
+
// Scissor and stencil stay as the host set them: its camera viewport or mask applies to spryte too.
|
|
67
|
+
this.hostScissor = gl.isEnabled(gl.SCISSOR_TEST) ? gl.getParameter(gl.SCISSOR_BOX) : null;
|
|
68
|
+
super.begin(clear, width, height);
|
|
69
|
+
}
|
|
70
|
+
bindOutput() {
|
|
71
|
+
const gl = this.gl;
|
|
72
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, this.fb);
|
|
73
|
+
gl.viewport(0, 0, this.fbW, this.fbH);
|
|
74
|
+
this.outH = this.fbH;
|
|
75
|
+
// Back on the host's framebuffer, where its scissor applies again (a render target had it off).
|
|
76
|
+
this.scissor(null);
|
|
77
|
+
}
|
|
78
|
+
setClip(rect) {
|
|
79
|
+
// Inside a render target the host's scissor doesn't apply: it's in the host framebuffer's pixels.
|
|
80
|
+
if (this.target || this.lost) {
|
|
81
|
+
super.setClip(rect);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.flush();
|
|
85
|
+
this.scissor(rect);
|
|
86
|
+
}
|
|
87
|
+
setTarget(target, clear, width, height) {
|
|
88
|
+
if (target && !this.lost && this.hostScissor) {
|
|
89
|
+
// Submit what's queued for the host's framebuffer under its scissor, then draw the target unscissored.
|
|
90
|
+
this.flush();
|
|
91
|
+
this.gl.disable(this.gl.SCISSOR_TEST);
|
|
92
|
+
}
|
|
93
|
+
super.setTarget(target, clear, width, height);
|
|
94
|
+
}
|
|
95
|
+
end() {
|
|
96
|
+
this.flush();
|
|
97
|
+
if (this.lost)
|
|
98
|
+
return;
|
|
99
|
+
const gl = this.gl;
|
|
100
|
+
this.scissor(null);
|
|
101
|
+
for (let i = 0; i < 8; i++)
|
|
102
|
+
gl.bindSampler(i, null);
|
|
103
|
+
}
|
|
104
|
+
/** Set the scissor to spryte's clip (in the host framebuffer's top-left pixels) intersected with the host's. */
|
|
105
|
+
scissor(rect) {
|
|
106
|
+
const gl = this.gl;
|
|
107
|
+
const host = this.hostScissor;
|
|
108
|
+
if (!rect) {
|
|
109
|
+
if (host) {
|
|
110
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
111
|
+
gl.scissor(host[0], host[1], host[2], host[3]);
|
|
112
|
+
}
|
|
113
|
+
else
|
|
114
|
+
gl.disable(gl.SCISSOR_TEST);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
// WebGL's scissor origin is bottom-left.
|
|
118
|
+
let x = rect.x;
|
|
119
|
+
let y = this.fbH - rect.y - rect.h;
|
|
120
|
+
let w = rect.w;
|
|
121
|
+
let h = rect.h;
|
|
122
|
+
if (host) {
|
|
123
|
+
const x1 = Math.min(x + w, host[0] + host[2]);
|
|
124
|
+
const y1 = Math.min(y + h, host[1] + host[3]);
|
|
125
|
+
x = Math.max(x, host[0]);
|
|
126
|
+
y = Math.max(y, host[1]);
|
|
127
|
+
w = Math.max(0, x1 - x);
|
|
128
|
+
h = Math.max(0, y1 - y);
|
|
129
|
+
}
|
|
130
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
131
|
+
gl.scissor(x, y, w, h);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAkB5C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAA0B,EAAE,OAAO,GAA0B,EAAE;IAClG,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;IACvD,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,kBAAkB,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC;IAC3D,OAAO;QACL,IAAI;QACJ,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM;YAC/B,OAAO,CAAC,EAAE,GAAG,WAAW,CAAC;YACzB,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC;YACpB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC;YACrB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC7B,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,aAAc,SAAQ,aAAa;IACvC,EAAE,GAA4B,IAAI,CAAC;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AC,CAAC;QACf,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACf,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAG,IAAI,CAAC,CAAC,CAAY,GAAI,IAAI,CAAC,CAAC,CAAY,CAAC,CAAC;YACtE,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAG,IAAI,CAAC,CAAC,CAAY,GAAI,IAAI,CAAC,CAAC,CAAY,CAAC,CAAC;YACtE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAW,CAAC,CAAC;YACnC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAW,CAAC,CAAC;YACnC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;YACxB,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QAC1B,CAAC;QACD,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;QAC3B,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACzB,CAAC;CACF"}
|
package/dist/webgl2.d.ts
CHANGED
|
@@ -3,11 +3,18 @@ import { type CopySpec } from "./copies.js";
|
|
|
3
3
|
import type { Shader } from "./shader.js";
|
|
4
4
|
import type { ShapeBuffer } from "./shapes.js";
|
|
5
5
|
import { RenderTarget } from "./target.js";
|
|
6
|
+
/** A linked program and the view size last uploaded to it, so `u_view` is only sent when it changes. */
|
|
7
|
+
interface ProgramInfo {
|
|
8
|
+
program: WebGLProgram;
|
|
9
|
+
view: WebGLUniformLocation | null;
|
|
10
|
+
w: number;
|
|
11
|
+
h: number;
|
|
12
|
+
}
|
|
6
13
|
/** Instanced, multi-texture WebGL2 sprite batcher behind the `draw` API. */
|
|
7
14
|
export declare class WebGL2Backend implements Backend {
|
|
8
15
|
readonly kind: "webgl2";
|
|
9
16
|
readonly raw: RawContext;
|
|
10
|
-
|
|
17
|
+
protected readonly gl: WebGL2RenderingContext;
|
|
11
18
|
private readonly capacity;
|
|
12
19
|
private readonly data;
|
|
13
20
|
private readonly f32;
|
|
@@ -20,10 +27,10 @@ export declare class WebGL2Backend implements Backend {
|
|
|
20
27
|
private linear;
|
|
21
28
|
private main;
|
|
22
29
|
/** The program sprite batches draw with: `main`, or a custom shader's inside `withShader`. */
|
|
23
|
-
|
|
30
|
+
protected active: ProgramInfo;
|
|
24
31
|
private shader;
|
|
25
32
|
private readonly customs;
|
|
26
|
-
|
|
33
|
+
protected vao: WebGLVertexArrayObject;
|
|
27
34
|
private quadBuffer;
|
|
28
35
|
private copyPipe;
|
|
29
36
|
private each;
|
|
@@ -35,15 +42,15 @@ export declare class WebGL2Backend implements Backend {
|
|
|
35
42
|
private staging;
|
|
36
43
|
private readonly targets;
|
|
37
44
|
/** Where drawing goes: a render target, or null for the canvas. */
|
|
38
|
-
|
|
45
|
+
protected target: RenderTarget | null;
|
|
39
46
|
/** Height in pixels of the current destination, for flipping scissor rectangles. */
|
|
40
|
-
|
|
47
|
+
protected outH: number;
|
|
41
48
|
private viewW;
|
|
42
49
|
private viewH;
|
|
43
50
|
/** True between webglcontextlost and webglcontextrestored: drawing is skipped. */
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
protected lost: boolean;
|
|
52
|
+
protected readonly onLost: (e: Event) => void;
|
|
53
|
+
protected readonly onRestored: () => void;
|
|
47
54
|
private readonly units;
|
|
48
55
|
private readonly unitSmooth;
|
|
49
56
|
private unitCount;
|
|
@@ -61,7 +68,9 @@ export declare class WebGL2Backend implements Backend {
|
|
|
61
68
|
get contextLost(): boolean;
|
|
62
69
|
/** Create program, buffers and the white texture. Runs at start and after a context restore. */
|
|
63
70
|
private setup;
|
|
64
|
-
begin(clear: number, width: number, height: number): void;
|
|
71
|
+
begin(clear: number | null, width: number, height: number): void;
|
|
72
|
+
/** Bind the frame's destination, the canvas, with the viewport sized to it. Shared mode binds the host's framebuffer instead. */
|
|
73
|
+
protected bindOutput(): void;
|
|
65
74
|
quad(m: Matrix, src: TextureSource | null, sx: number, sy: number, sw: number, sh: number, color: number, flash: number, smooth: boolean): void;
|
|
66
75
|
quads(t: Matrix, m: Matrix, positions: ArrayLike<number>, count: number, src: TextureSource, sx: number, sy: number, sw: number, sh: number, color: number, flash: number, smooth: boolean, snap: boolean): void;
|
|
67
76
|
copies(c: CopySpec): void;
|
|
@@ -85,7 +94,7 @@ export declare class WebGL2Backend implements Backend {
|
|
|
85
94
|
path(m: Matrix, points: ArrayLike<number>, n: number, closed: boolean, width: number, color: number, aa: number, tessellator: new () => ShapeBuffer): void;
|
|
86
95
|
private flushShapes;
|
|
87
96
|
private shapePipeline;
|
|
88
|
-
|
|
97
|
+
protected flush(): void;
|
|
89
98
|
/** Upload `u_view` to a program if the destination size changed since it last drew. The program must be bound. */
|
|
90
99
|
private syncView;
|
|
91
100
|
private syncUniforms;
|
|
@@ -93,6 +102,7 @@ export declare class WebGL2Backend implements Backend {
|
|
|
93
102
|
private texture;
|
|
94
103
|
/** Texture parameters for the bound texture. Filtering comes from the samplers; this keeps the texture complete without them. */
|
|
95
104
|
private wrap;
|
|
96
|
-
|
|
105
|
+
protected applyBlend(): void;
|
|
97
106
|
}
|
|
107
|
+
export {};
|
|
98
108
|
//# sourceMappingURL=webgl2.d.ts.map
|
package/dist/webgl2.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl2.d.ts","sourceRoot":"","sources":["../src/webgl2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,E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AAO,CAAC,IAAI;IAQZ,SAAS,CAAC,UAAU,IAAI,IAAI,CAU3B;CACF"}
|
package/dist/webgl2.js
CHANGED
|
@@ -296,21 +296,27 @@ export class WebGL2Backend {
|
|
|
296
296
|
if (this.lost)
|
|
297
297
|
return;
|
|
298
298
|
const gl = this.gl;
|
|
299
|
-
if (this.target)
|
|
300
|
-
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
301
299
|
this.target = null;
|
|
302
|
-
this.
|
|
303
|
-
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
300
|
+
this.bindOutput();
|
|
304
301
|
if (this.active !== this.main)
|
|
305
302
|
this.setShader(null);
|
|
306
303
|
this.viewW = width;
|
|
307
304
|
this.viewH = height;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
305
|
+
if (clear !== null) {
|
|
306
|
+
// The canvas is premultiplied, so a see-through clear colour is premultiplied too (opaque colours are unchanged).
|
|
307
|
+
const a = (clear & 0xff) / 255;
|
|
308
|
+
gl.clearColor(((clear >>> 24) / 255) * a, (((clear >>> 16) & 0xff) / 255) * a, (((clear >>> 8) & 0xff) / 255) * a, a);
|
|
309
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
310
|
+
}
|
|
312
311
|
this.submitted = 0;
|
|
313
312
|
}
|
|
313
|
+
/** Bind the frame's destination, the canvas, with the viewport sized to it. Shared mode binds the host's framebuffer instead. */
|
|
314
|
+
bindOutput() {
|
|
315
|
+
const gl = this.gl;
|
|
316
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
317
|
+
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
318
|
+
this.outH = gl.drawingBufferHeight;
|
|
319
|
+
}
|
|
314
320
|
quad(m, src, sx, sy, sw, sh, color, flash, smooth) {
|
|
315
321
|
if (this.lost)
|
|
316
322
|
return;
|
|
@@ -637,11 +643,8 @@ export class WebGL2Backend {
|
|
|
637
643
|
gl.viewport(0, 0, target.width, target.height);
|
|
638
644
|
this.outH = target.height;
|
|
639
645
|
}
|
|
640
|
-
else
|
|
641
|
-
|
|
642
|
-
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
|
|
643
|
-
this.outH = gl.drawingBufferHeight;
|
|
644
|
-
}
|
|
646
|
+
else
|
|
647
|
+
this.bindOutput();
|
|
645
648
|
this.target = target;
|
|
646
649
|
this.viewW = width;
|
|
647
650
|
this.viewH = height;
|