@driftengine/ui2d 4.12.0 → 4.13.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/README.md +1 -1
- package/dist/spritePass.js +5 -3
- package/dist/theme.d.ts +9 -8
- package/dist/theme.js +19 -4
- package/package.json +2 -2
- package/src/spritePass.ts +8 -4
- package/src/theme.ts +14 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The 2D layer: quads with a texture on them, batched, in the order you drew them.
|
|
4
4
|
|
|
5
|
-
**Cost: 10.
|
|
5
|
+
**Cost: 10.1 KB gzipped on top of core.** Measured by `scripts/size-gate.test.mjs`, which fails if it
|
|
6
6
|
drifts more than 3% — the number is derived from the same floors that gate asserts, so a README
|
|
7
7
|
quoting a stale one is a red suite rather than a thing somebody notices.
|
|
8
8
|
|
package/dist/spritePass.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** The 2D layer as a pass a consumer registers: one batch of quads, drawn where the caller says. */
|
|
2
|
+
import { interfaceGrade } from '@driftengine/core';
|
|
2
3
|
import { SPRITE_BINDINGS } from './shaders/generated/sprite.wgsl.js';
|
|
3
4
|
import { createAffine2D } from './camera2d.js';
|
|
4
5
|
import { createSpriteBatch, resetSpriteBatch } from './spriteBatch.js';
|
|
@@ -101,7 +102,7 @@ export function createSpritePass(options = {}) {
|
|
|
101
102
|
if (gl === null)
|
|
102
103
|
return;
|
|
103
104
|
uploadWebgl2Instances(ctx.gl, gl, batch);
|
|
104
|
-
drawWebgl2Sprites(ctx.gl, gl, batch, toNdc, clipCorrection, ctx.outputTransform,
|
|
105
|
+
drawWebgl2Sprites(ctx.gl, gl, batch, toNdc, clipCorrection, interfaceGrade(ctx.outputTransform), 1);
|
|
105
106
|
return;
|
|
106
107
|
}
|
|
107
108
|
if (gpu === null || device === null)
|
|
@@ -114,8 +115,9 @@ export function createSpritePass(options = {}) {
|
|
|
114
115
|
f[VERT.fields.uToNdc1.offset / 4] = toNdc[4];
|
|
115
116
|
f[VERT.fields.uToNdc1.offset / 4 + 1] = toNdc[5];
|
|
116
117
|
f.set(clipCorrection, VERT.fields.uClipCorrection.offset / 4);
|
|
117
|
-
|
|
118
|
-
gpu.
|
|
118
|
+
/* A 2D layer is painted for the screen: encoded, never put through the scene's curve. */
|
|
119
|
+
gpu.fragmentInts[FRAG.fields.uOutputTransform.offset / 4] = interfaceGrade(ctx.outputTransform);
|
|
120
|
+
gpu.fragmentFloats[FRAG.fields.uOutputExposure.offset / 4] = 1;
|
|
119
121
|
/*
|
|
120
122
|
* Written from inside an open render pass, which is allowed and ordered: a queue write
|
|
121
123
|
* issued now lands before the command buffer this pass is being recorded into is submitted.
|
package/dist/theme.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Named colours and sizes, so an interface stops repeating its own constants.
|
|
3
|
-
*
|
|
4
|
-
* **Flattened at derivation rather than chained at lookup.** A token is read per node per frame, so
|
|
5
|
-
* a chain of parent themes would be a walk on every one of those reads. Spreading once when a
|
|
6
|
-
* theme is derived costs a record and makes every lookup a single property access.
|
|
7
|
-
*/
|
|
1
|
+
/** Named colours, packed as `0xRRGGBBAA`, and sizes, flattened when the theme is derived. */
|
|
8
2
|
export interface Theme {
|
|
9
3
|
readonly values: Readonly<Record<string, number>>;
|
|
10
4
|
}
|
|
@@ -14,7 +8,14 @@ export declare function deriveTheme(base: Theme, overrides: Record<string, numbe
|
|
|
14
8
|
export declare function themeColour(theme: Theme, name: string, fallback: number): number;
|
|
15
9
|
export declare function themeSize(theme: Theme, name: string, fallback: number): number;
|
|
16
10
|
/**
|
|
17
|
-
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are
|
|
11
|
+
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are: the colour
|
|
12
|
+
* decoded from sRGB to the linear light the renderer draws in, the coverage as it is.
|
|
13
|
+
*
|
|
14
|
+
* **Decoded, because a hex colour is a display colour** wherever one is written, CSS included, and
|
|
15
|
+
* the renderer grades everything it draws: read as linear, `0x336699` came out as `0x7caacb` under
|
|
16
|
+
* the default `outputTransform`, every panel a washed-out version of the one picked. What it gives
|
|
17
|
+
* up is a token meant as an amount rather than a look, which a colour token is not. A renderer
|
|
18
|
+
* asked for `outputTransform: 'none'` draws these darker than picked, as it does every colour.
|
|
18
19
|
*
|
|
19
20
|
* **Two of this package's own APIs did not meet**: a theme token is one number and a `UiNode`
|
|
20
21
|
* colour is a `Float32Array`, so every consumer wrote the same four shifts. The editor found it by
|
package/dist/theme.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named colours and sizes, so an interface stops repeating its own constants.
|
|
3
|
+
*
|
|
4
|
+
* **Flattened at derivation rather than chained at lookup.** A token is read per node per frame, so
|
|
5
|
+
* a chain of parent themes would be a walk on every one of those reads. Spreading once when a
|
|
6
|
+
* theme is derived costs a record and makes every lookup a single property access.
|
|
7
|
+
*/
|
|
8
|
+
import { srgbToLinear } from '@driftengine/core';
|
|
1
9
|
export function createTheme(values) {
|
|
2
10
|
return { values: { ...values } };
|
|
3
11
|
}
|
|
@@ -12,7 +20,14 @@ export function themeSize(theme, name, fallback) {
|
|
|
12
20
|
return theme.values[name] ?? fallback;
|
|
13
21
|
}
|
|
14
22
|
/**
|
|
15
|
-
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are
|
|
23
|
+
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are: the colour
|
|
24
|
+
* decoded from sRGB to the linear light the renderer draws in, the coverage as it is.
|
|
25
|
+
*
|
|
26
|
+
* **Decoded, because a hex colour is a display colour** wherever one is written, CSS included, and
|
|
27
|
+
* the renderer grades everything it draws: read as linear, `0x336699` came out as `0x7caacb` under
|
|
28
|
+
* the default `outputTransform`, every panel a washed-out version of the one picked. What it gives
|
|
29
|
+
* up is a token meant as an amount rather than a look, which a colour token is not. A renderer
|
|
30
|
+
* asked for `outputTransform: 'none'` draws these darker than picked, as it does every colour.
|
|
16
31
|
*
|
|
17
32
|
* **Two of this package's own APIs did not meet**: a theme token is one number and a `UiNode`
|
|
18
33
|
* colour is a `Float32Array`, so every consumer wrote the same four shifts. The editor found it by
|
|
@@ -24,9 +39,9 @@ export function themeSize(theme, name, fallback) {
|
|
|
24
39
|
* number, which is exactly the shape of bug that survives review.
|
|
25
40
|
*/
|
|
26
41
|
export function unpackRgba(packed, out) {
|
|
27
|
-
out[0] = ((packed >>> 24) & 0xff) / 255;
|
|
28
|
-
out[1] = ((packed >>> 16) & 0xff) / 255;
|
|
29
|
-
out[2] = ((packed >>> 8) & 0xff) / 255;
|
|
42
|
+
out[0] = srgbToLinear(((packed >>> 24) & 0xff) / 255);
|
|
43
|
+
out[1] = srgbToLinear(((packed >>> 16) & 0xff) / 255);
|
|
44
|
+
out[2] = srgbToLinear(((packed >>> 8) & 0xff) / 255);
|
|
30
45
|
out[3] = (packed & 0xff) / 255;
|
|
31
46
|
return out;
|
|
32
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driftengine/ui2d",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"description": "The 2D layer: batched sprites, sheets, tilemaps, and a retained interface tree over them",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@driftengine/core": "4.
|
|
30
|
+
"@driftengine/core": "4.13.0"
|
|
31
31
|
},
|
|
32
32
|
"author": "Drift Technologies",
|
|
33
33
|
"repository": {
|
package/src/spritePass.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** The 2D layer as a pass a consumer registers: one batch of quads, drawn where the caller says. */
|
|
2
2
|
|
|
3
|
+
import { interfaceGrade } from '@driftengine/core';
|
|
3
4
|
import type { PassContext, PassDefinition, PassDevice } from '@driftengine/core';
|
|
4
5
|
|
|
5
6
|
import { SPRITE_BINDINGS } from './shaders/generated/sprite.wgsl.ts';
|
|
@@ -191,8 +192,8 @@ export function createSpritePass(options: SpritePassOptions = {}): SpritePass {
|
|
|
191
192
|
batch,
|
|
192
193
|
toNdc,
|
|
193
194
|
clipCorrection,
|
|
194
|
-
ctx.outputTransform,
|
|
195
|
-
|
|
195
|
+
interfaceGrade(ctx.outputTransform),
|
|
196
|
+
1,
|
|
196
197
|
);
|
|
197
198
|
return;
|
|
198
199
|
}
|
|
@@ -205,8 +206,11 @@ export function createSpritePass(options: SpritePassOptions = {}): SpritePass {
|
|
|
205
206
|
f[VERT.fields.uToNdc1.offset / 4] = toNdc[4] as number;
|
|
206
207
|
f[VERT.fields.uToNdc1.offset / 4 + 1] = toNdc[5] as number;
|
|
207
208
|
f.set(clipCorrection, VERT.fields.uClipCorrection.offset / 4);
|
|
208
|
-
|
|
209
|
-
gpu.
|
|
209
|
+
/* A 2D layer is painted for the screen: encoded, never put through the scene's curve. */
|
|
210
|
+
gpu.fragmentInts[FRAG.fields.uOutputTransform.offset / 4] = interfaceGrade(
|
|
211
|
+
ctx.outputTransform,
|
|
212
|
+
);
|
|
213
|
+
gpu.fragmentFloats[FRAG.fields.uOutputExposure.offset / 4] = 1;
|
|
210
214
|
/*
|
|
211
215
|
* Written from inside an open render pass, which is allowed and ordered: a queue write
|
|
212
216
|
* issued now lands before the command buffer this pass is being recorded into is submitted.
|
package/src/theme.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* a chain of parent themes would be a walk on every one of those reads. Spreading once when a
|
|
6
6
|
* theme is derived costs a record and makes every lookup a single property access.
|
|
7
7
|
*/
|
|
8
|
+
import { srgbToLinear } from '@driftengine/core';
|
|
9
|
+
|
|
10
|
+
/** Named colours, packed as `0xRRGGBBAA`, and sizes, flattened when the theme is derived. */
|
|
8
11
|
export interface Theme {
|
|
9
12
|
readonly values: Readonly<Record<string, number>>;
|
|
10
13
|
}
|
|
@@ -27,7 +30,14 @@ export function themeSize(theme: Theme, name: string, fallback: number): number
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
|
-
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are
|
|
33
|
+
* A packed `0xRRGGBBAA` token as the four floats a node's `background` and `tint` are: the colour
|
|
34
|
+
* decoded from sRGB to the linear light the renderer draws in, the coverage as it is.
|
|
35
|
+
*
|
|
36
|
+
* **Decoded, because a hex colour is a display colour** wherever one is written, CSS included, and
|
|
37
|
+
* the renderer grades everything it draws: read as linear, `0x336699` came out as `0x7caacb` under
|
|
38
|
+
* the default `outputTransform`, every panel a washed-out version of the one picked. What it gives
|
|
39
|
+
* up is a token meant as an amount rather than a look, which a colour token is not. A renderer
|
|
40
|
+
* asked for `outputTransform: 'none'` draws these darker than picked, as it does every colour.
|
|
31
41
|
*
|
|
32
42
|
* **Two of this package's own APIs did not meet**: a theme token is one number and a `UiNode`
|
|
33
43
|
* colour is a `Float32Array`, so every consumer wrote the same four shifts. The editor found it by
|
|
@@ -39,9 +49,9 @@ export function themeSize(theme: Theme, name: string, fallback: number): number
|
|
|
39
49
|
* number, which is exactly the shape of bug that survives review.
|
|
40
50
|
*/
|
|
41
51
|
export function unpackRgba(packed: number, out: Float32Array): Float32Array {
|
|
42
|
-
out[0] = ((packed >>> 24) & 0xff) / 255;
|
|
43
|
-
out[1] = ((packed >>> 16) & 0xff) / 255;
|
|
44
|
-
out[2] = ((packed >>> 8) & 0xff) / 255;
|
|
52
|
+
out[0] = srgbToLinear(((packed >>> 24) & 0xff) / 255);
|
|
53
|
+
out[1] = srgbToLinear(((packed >>> 16) & 0xff) / 255);
|
|
54
|
+
out[2] = srgbToLinear(((packed >>> 8) & 0xff) / 255);
|
|
45
55
|
out[3] = (packed & 0xff) / 255;
|
|
46
56
|
return out;
|
|
47
57
|
}
|