@holtjs/stage 0.11.0 → 0.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/CHANGELOG.md +22 -0
- package/dist/{anims-BYBzSNXO.d.ts → anims-n8aqhzxu.d.ts} +26 -5
- package/dist/anims.d.ts +1 -1
- package/dist/{display-CuyQc8oE.js → display-CVjvA8ZO.js} +12 -1
- package/dist/{game-COsuqGzC.d.ts → game-C8bz7tay.d.ts} +98 -4
- package/dist/{game-2dS3Qsrn.js → game-CziLa7dv.js} +110 -46
- package/dist/headless.d.ts +14 -3
- package/dist/headless.js +64 -5
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -4
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +1 -1
- package/dist/lighting.js +5 -2
- package/dist/projection.d.ts +1 -1
- package/dist/{renderer-webgpu-CHJxmCvR.js → renderer-webgpu-LDnrpYa0.js} +1720 -29
- package/dist/renderer-webgpu.d.ts +2 -2
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -2
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/dist/world.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,28 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.13.0] - 2026-12-05
|
|
10
|
+
|
|
11
|
+
### Added & Fixed
|
|
12
|
+
- **Transparent Multi-Page Texture Atlases Across WebGPU, WebGL2 & Canvas2D (`TextureManager.addAtlas`, `Texture.addSource`, `Texture.pageCount`)**:
|
|
13
|
+
- `Texture` constructor, `TextureManager.addImage`, and `TextureManager.addAtlas` now accept `TextureImageSource | readonly TextureImageSource[]`, allowing a single logical atlas key (`'nightfall'`, `'world'`) to span any number of `<= 4096x4096` GPU texture pages with zero game-code changes (`SpriteObject`, `ImageObject`, `TileSpriteObject`, `DrawStreamObject`, `AnimationManager.createFromAtlas`, `bindEquipment`).
|
|
14
|
+
- Supports per-frame `page` / `sourceIndex` metadata in flat `@holtjs/craft` & Aseprite atlases, TexturePacker / Phaser 3 multi-atlas `textures: [{ frames }, ...]` manifests, `@holtjs/craft` `pages: [...]` manifests, and dynamic runtime page streaming via `texture.addSource(image)`.
|
|
15
|
+
- Fixed empty-placeholder probing in `addAtlas` (`detectEmptyRect`) to inspect `tex.source[pageIdx].image` rather than `source[0]`.
|
|
16
|
+
- Upgraded `InstancedBatchObject` in both `RendererWebGpu` and `RendererWebGL` (WebGL2 `drawElementsInstanced` order-preserving sub-run flushing + WebGL1 fallback), `TileSpriteObject.setTexture`/`setFrame` repeat flags, and `Lighting2DSystem` normal-map page binding (`${key}_normal`) to switch `TextureSource` pages per frame automatically.
|
|
17
|
+
|
|
18
|
+
## [0.12.0] - 2026-12-04
|
|
19
|
+
|
|
20
|
+
### Added & Fixed
|
|
21
|
+
- **Isomorphic Zero-Dependency Headless WebGPU + Native C FFI Bridge (`requestHeadlessWebGpu`, `openWgpuNativeFfi`, `openDawnWebGpu`, `@holtjs/stage/webgpu` & `@holtjs/stage/headless`)**:
|
|
22
|
+
- Added `src/webgpu-headless.ts` with zero static runtime-specific imports (safe across Browser, Vite, Node.js, Bun, and Deno with zero forced npm dependencies):
|
|
23
|
+
1. **Bun `bun:ffi` + `wgpu-native` (`libwgpu_native.so`/`.dylib`/`.dll`)**: Direct `dlopen` + cached in-memory TinyCC struct-by-value C bridge (`wgpu-bun-ffi`) with single-call synchronous staging readback (`wgpuBufferGetConstMappedRange`).
|
|
24
|
+
2. **Node.js `koffi` + `wgpu-native` (`libwgpu_native.so`/`.dylib`/`.dll`)**: Prebuilt zero-compiler N-API C FFI (`wgpu-node-koffi`) sharing 100% of the 64-bit `webgpu.h` C ABI descriptor packers (`3,686,400 / 3,686,400` byte-identical RGBA parity with `bun:ffi` at 720p).
|
|
25
|
+
3. **Node.js & Bun Google Dawn (`webgpu` N-API)**: Full async `mapAsync` Headless WebGPU support (`dawn`) with `Instance`/`Adapter` lifetime pinning, plus Deno / Browser `navigator.gpu` (`navigator`).
|
|
26
|
+
- **Offscreen `RendererWebGpu` & Sync/Async `HeadlessStage` GPU Video Pipeline (`src/renderer-webgpu.ts`, `src/headless.ts`)**:
|
|
27
|
+
- `RendererWebGpu` now runs headlessly with `context: null`, rendering into an auto-resized offscreen `GPUTexture` with `256`-byte row-aligned staging readback (`readPixelsSync` & `readPixelsAsync`), BGRA/RGBA unpacking, premultiplied `queue.writeTexture` canvas/atlas uploads, `Frame.empty` skipping, and `4`-byte aligned `Uint16Array` index uploads.
|
|
28
|
+
- Wired `gpuDevice` and `gpuFormat` into `createHeadlessStage(...)`, adding `toRgbaAsync()`, `toRgbaIntoAsync()`, and `toPngAsync()` alongside synchronous `toRgba()` / `toPng()` / `renderStoryboard()` (for `wgpu-native` FFI) and streaming WebGPU frames directly into `stage.encodeVideo(...)` (`ffmpeg -f rawvideo -pix_fmt rgba`).
|
|
29
|
+
- Fixed WGSL fragment uniformity in `WGSL_BATCH_SRC` (`textureSample` hoisted before `in.mode` branching) for strict Google Dawn / Chrome Tint compliance.
|
|
30
|
+
|
|
9
31
|
## [0.11.0] - 2026-12-04
|
|
10
32
|
|
|
11
33
|
### Added
|
|
@@ -138,17 +138,31 @@ interface FrameExtraMeta {
|
|
|
138
138
|
loop?: boolean;
|
|
139
139
|
/** True when this frame is an all-transparent occlusion placeholder (`1x1` cell, `2x2` transparent placeholder, or explicit `empty: true`). */
|
|
140
140
|
empty?: boolean;
|
|
141
|
+
/** Optional 0-based texture page index (`sourceIndex`) for multi-page atlases (`@holtjs/stage@>=0.13.0`). */
|
|
142
|
+
page?: number;
|
|
143
|
+
sourceIndex?: number;
|
|
144
|
+
}
|
|
145
|
+
interface AtlasTexturePageLike {
|
|
146
|
+
readonly image?: string;
|
|
147
|
+
readonly scale?: number;
|
|
148
|
+
readonly frames?: Record<string, any> | ReadonlyArray<any>;
|
|
141
149
|
}
|
|
142
150
|
interface AtlasJsonLike {
|
|
143
151
|
readonly yaw?: number;
|
|
144
152
|
readonly pitch?: number;
|
|
145
153
|
readonly scale?: number;
|
|
146
154
|
readonly frames?: Record<string, any> | ReadonlyArray<any>;
|
|
155
|
+
/** TexturePacker / Phaser multi-atlas page list (`textures[p]` maps to `source[p]`). */
|
|
156
|
+
readonly textures?: ReadonlyArray<AtlasTexturePageLike>;
|
|
157
|
+
/** `@holtjs/craft` multi-page atlas metadata (`pages[p]` maps to `source[p]`). */
|
|
158
|
+
readonly pages?: ReadonlyArray<AtlasTexturePageLike>;
|
|
147
159
|
readonly json?: {
|
|
148
160
|
readonly yaw?: number;
|
|
149
161
|
readonly pitch?: number;
|
|
150
162
|
readonly scale?: number;
|
|
151
163
|
readonly frames?: Record<string, any> | ReadonlyArray<any>;
|
|
164
|
+
readonly textures?: ReadonlyArray<AtlasTexturePageLike>;
|
|
165
|
+
readonly pages?: ReadonlyArray<AtlasTexturePageLike>;
|
|
152
166
|
};
|
|
153
167
|
}
|
|
154
168
|
interface TextureImageOptions {
|
|
@@ -249,7 +263,13 @@ declare class Texture {
|
|
|
249
263
|
atlasYaw: number | null;
|
|
250
264
|
atlasPitch: number | null;
|
|
251
265
|
atlasScale: number | null;
|
|
252
|
-
|
|
266
|
+
private readonly hostRef;
|
|
267
|
+
private readonly defaultPremultiply;
|
|
268
|
+
constructor(manager: TextureManager, key: string, image: TextureImageSource | readonly TextureImageSource[], filterMode: FilterModeValue, host: GlTextureHost | null, premultiplyAlpha?: boolean, isRenderTarget?: boolean);
|
|
269
|
+
/** Number of backing `TextureSource` pages attached to this logical texture (`1` for single-page atlases). */
|
|
270
|
+
get pageCount(): number;
|
|
271
|
+
/** Append an additional `TextureSource` page dynamically (returns the new `TextureSource` at `source.length - 1`). */
|
|
272
|
+
addSource(image: TextureImageSource, filterMode?: FilterModeValue, premultiplyAlpha?: boolean): TextureSource;
|
|
253
273
|
add(name: string | number, sourceIndex: number, x: number, y: number, width: number, height: number, meta?: FrameExtraMeta): Frame;
|
|
254
274
|
/**
|
|
255
275
|
* Resolve a stable negative integer frame handle (`-1 - frame.index`) usable directly in
|
|
@@ -280,15 +300,16 @@ declare class TextureManager {
|
|
|
280
300
|
private initBuiltins;
|
|
281
301
|
exists(key: string): boolean;
|
|
282
302
|
get(key: string): Texture;
|
|
283
|
-
addImage(key: string, source: TextureImageSource, options?: TextureImageOptions): Texture | null;
|
|
303
|
+
addImage(key: string, source: TextureImageSource | readonly TextureImageSource[], options?: TextureImageOptions): Texture | null;
|
|
284
304
|
addCanvas(key: string, canvas: HTMLCanvasElement): CanvasTexture | null;
|
|
285
305
|
createCanvas(key: string, width: number, height: number): CanvasTexture | null;
|
|
286
306
|
addSpriteSheet(key: string, source: TextureImageSource, config: SpriteSheetConfig): Texture | null;
|
|
287
307
|
/**
|
|
288
|
-
* Register a
|
|
289
|
-
* preserving per-frame trimmed pivots (`ax/ay` or `pivot`), named sockets (`anchors`), `emissiveCenter`,
|
|
308
|
+
* Register a single-page or multi-page sprite atlas (`@holtjs/craft/three`, `@holtjs/craft/atlas`, or TexturePacker / Aseprite JSON)
|
|
309
|
+
* preserving per-frame trimmed pivots (`ax/ay` or `pivot`), named sockets (`anchors`), `emissiveCenter`, `atlasYaw`,
|
|
310
|
+
* and per-frame `page` / `sourceIndex` across multiple `<= 4096x4096` GPU texture pages!
|
|
290
311
|
*/
|
|
291
|
-
addAtlas(key: string, source: TextureImageSource, atlasData: AtlasJsonLike, options?: TextureImageOptions): Texture | null;
|
|
312
|
+
addAtlas(key: string, source: TextureImageSource | readonly TextureImageSource[], atlasData: AtlasJsonLike, options?: TextureImageOptions): Texture | null;
|
|
292
313
|
remove(key: string): boolean;
|
|
293
314
|
invalidateAllGl(): void;
|
|
294
315
|
destroy(): void;
|
package/dist/anims.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-
|
|
1
|
+
import { a as AtlasClipRule, c as GenerateFrameNamesConfig, i as AtlasAutoAnimOptions, l as GenerateFrameNumbersConfig, n as AnimationFrameInput, o as CompiledAnimationFrame, r as AnimationManager, s as DirectionalAnimGroup, t as AnimationConfig, u as StageAnimation } from "./anims-n8aqhzxu.js";
|
|
2
2
|
export { AnimationConfig, AnimationFrameInput, AnimationManager, AtlasAutoAnimOptions, AtlasClipRule, CompiledAnimationFrame, DirectionalAnimGroup, GenerateFrameNamesConfig, GenerateFrameNumbersConfig, StageAnimation };
|
|
@@ -1100,7 +1100,18 @@ var TileSpriteObject = class extends DisplayObject {
|
|
|
1100
1100
|
this.height = Math.max(0, height);
|
|
1101
1101
|
this.texture = scene.textures.get(key);
|
|
1102
1102
|
this.frame = this.texture.get(frame);
|
|
1103
|
-
this.
|
|
1103
|
+
if (this.frame?.source) this.frame.source.repeat = true;
|
|
1104
|
+
}
|
|
1105
|
+
setTexture(key, frame) {
|
|
1106
|
+
this.texture = this.scene.textures.get(key);
|
|
1107
|
+
this.frame = this.texture.get(frame);
|
|
1108
|
+
if (this.frame?.source) this.frame.source.repeat = true;
|
|
1109
|
+
return this;
|
|
1110
|
+
}
|
|
1111
|
+
setFrame(frame) {
|
|
1112
|
+
this.frame = this.texture.get(frame);
|
|
1113
|
+
if (this.frame?.source) this.frame.source.repeat = true;
|
|
1114
|
+
return this;
|
|
1104
1115
|
}
|
|
1105
1116
|
setTint(color) {
|
|
1106
1117
|
this.tint = color & HEX_MASK;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-
|
|
1
|
+
import { I as ScaleMode, M as Matrix2D, N as Rect2D, O as EventEmitter, P as RgbaColor, R as TintMode, S as TextureSource, T as BlendMode, U as WorldView2D, _ as SpriteSheetConfig, d as AtlasJsonLike, g as GlTextureHost, p as Frame, r as AnimationManager, u as StageAnimation, v as Texture, x as TextureManager, y as TextureImageOptions } from "./anims-n8aqhzxu.js";
|
|
2
2
|
import { c as TweenManager, u as TweenStats } from "./tween-BiF1FUvc.js";
|
|
3
3
|
import { a as ScriptOptions, i as ScriptHandle, o as ScriptScheduler, r as ScriptContext, s as ScriptStats, t as CoroutineGenerator } from "./coroutine-DLgJumtD.js";
|
|
4
4
|
interface CameraFollowOptions {
|
|
@@ -504,6 +504,8 @@ declare class TileSpriteObject extends DisplayObject {
|
|
|
504
504
|
tint: number;
|
|
505
505
|
isTinted: boolean;
|
|
506
506
|
constructor(scene: SceneHostLike, x: number, y: number, width: number, height: number, key: string, frame?: string | number);
|
|
507
|
+
setTexture(key: string, frame?: string | number): this;
|
|
508
|
+
setFrame(frame?: string | number): this;
|
|
507
509
|
setTint(color: number): this;
|
|
508
510
|
clearTint(): this;
|
|
509
511
|
}
|
|
@@ -1259,10 +1261,76 @@ declare class Renderer2D extends EventEmitter {
|
|
|
1259
1261
|
render(displayList: DisplayList, camera: Camera): void;
|
|
1260
1262
|
destroy(): void;
|
|
1261
1263
|
}
|
|
1264
|
+
type HeadlessWebGpuBackend = 'wgpu-bun-ffi' | 'wgpu-node-koffi' | 'dawn' | 'navigator';
|
|
1265
|
+
interface HeadlessWebGpuHandle {
|
|
1266
|
+
readonly backend: HeadlessWebGpuBackend;
|
|
1267
|
+
readonly device: WebGpuDeviceLike;
|
|
1268
|
+
readonly format: 'rgba8unorm' | 'bgra8unorm';
|
|
1269
|
+
/** `true` when `stage.toRgba()` / `renderer.readPixelsSync()` works synchronously without `await` (`wgpu-native` FFI). */
|
|
1270
|
+
readonly supportsSyncReadback: boolean;
|
|
1271
|
+
/** Release native `GPUDevice` / `WGPUInstance` resources. */
|
|
1272
|
+
destroy(): void;
|
|
1273
|
+
}
|
|
1274
|
+
interface OpenWgpuNativeFfiOptions {
|
|
1275
|
+
/**
|
|
1276
|
+
* Path to `libwgpu_native.so` (Linux), `libwgpu_native.dylib` (macOS), or `wgpu_native.dll` (Windows).
|
|
1277
|
+
* Defaults to `process.env.STAGE_WGPU_LIB` or `process.env.WGPU_NATIVE_LIB`, then standard system/local paths.
|
|
1278
|
+
*/
|
|
1279
|
+
readonly libPath?: string;
|
|
1280
|
+
/** FFI engine selection (`'auto'` uses built-in `'bun:ffi'` on Bun and `'koffi'` on Node.js). */
|
|
1281
|
+
readonly runtime?: 'auto' | 'bun' | 'koffi';
|
|
1282
|
+
/** Optional pre-loaded `koffi` module instance on Node.js. */
|
|
1283
|
+
readonly koffiModule?: any;
|
|
1284
|
+
/** Adapter power profile (default `'high-performance'`). */
|
|
1285
|
+
readonly powerPreference?: 'low-power' | 'high-performance';
|
|
1286
|
+
}
|
|
1287
|
+
interface OpenDawnWebGpuOptions {
|
|
1288
|
+
/** Optional pre-loaded `'webgpu'` (Google Dawn N-API) module. */
|
|
1289
|
+
readonly dawnModule?: any;
|
|
1290
|
+
/** Optional Dawn instance flags passed to `dawn.create([...])` (default `[]`). */
|
|
1291
|
+
readonly dawnFlags?: readonly string[];
|
|
1292
|
+
/** Adapter power profile (default `'high-performance'`). */
|
|
1293
|
+
readonly powerPreference?: 'low-power' | 'high-performance';
|
|
1294
|
+
}
|
|
1295
|
+
interface HeadlessWebGpuOptions extends OpenWgpuNativeFfiOptions, OpenDawnWebGpuOptions {
|
|
1296
|
+
/** Backend discovery strategy (`'auto'` tries `wgpu-native` FFI -> Google Dawn `'webgpu'` -> `navigator.gpu`). */
|
|
1297
|
+
readonly backend?: 'auto' | 'ffi' | 'dawn' | 'navigator';
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Open a synchronous native Headless WebGPU `GPUDevice` via `wgpu-native` (`libwgpu_native.so`/`.dylib`/`.dll`)
|
|
1301
|
+
* using Bun's built-in `bun:ffi` or Node.js's prebuilt `koffi` C FFI.
|
|
1302
|
+
* Returns `null` cleanly if `libwgpu_native` or the FFI driver is unavailable.
|
|
1303
|
+
*/
|
|
1304
|
+
declare function openWgpuNativeFfi(options?: OpenWgpuNativeFfiOptions): Promise<HeadlessWebGpuHandle | null>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Open a native Headless WebGPU `GPUDevice` via Google Dawn's prebuilt N-API `'webgpu'` package
|
|
1307
|
+
* (works identically in both Node.js and Bun!).
|
|
1308
|
+
* Returns `null` cleanly if `'webgpu'` is not installed or no Vulkan/Metal/D3D12 adapter is available.
|
|
1309
|
+
*/
|
|
1310
|
+
declare function openDawnWebGpu(options?: OpenDawnWebGpuOptions): Promise<HeadlessWebGpuHandle | null>;
|
|
1311
|
+
/**
|
|
1312
|
+
* Acquire an isomorphic Headless WebGPU device across Bun (`bun:ffi` + `wgpu-native` or Dawn `webgpu`),
|
|
1313
|
+
* Node.js (`koffi` + `wgpu-native` or Dawn `webgpu`), and Deno / Browser (`navigator.gpu`).
|
|
1314
|
+
* Never throws when native drivers are absent — returns `null` so callers can cleanly fall back to Canvas2D.
|
|
1315
|
+
*/
|
|
1316
|
+
declare function requestHeadlessWebGpu(options?: HeadlessWebGpuOptions): Promise<HeadlessWebGpuHandle | null>;
|
|
1262
1317
|
interface WebGpuDeviceLike {
|
|
1263
1318
|
readonly queue: {
|
|
1264
1319
|
writeBuffer(buffer: any, bufferOffset: number, data: BufferSource, dataOffset?: number, size?: number): void;
|
|
1265
|
-
copyExternalImageToTexture(source: any, destination: any, copySize: any): void;
|
|
1320
|
+
copyExternalImageToTexture?(source: any, destination: any, copySize: any): void;
|
|
1321
|
+
writeTexture?(destination: {
|
|
1322
|
+
texture: any;
|
|
1323
|
+
mipLevel?: number;
|
|
1324
|
+
origin?: [number, number, number];
|
|
1325
|
+
}, data: BufferSource, dataLayout: {
|
|
1326
|
+
offset?: number;
|
|
1327
|
+
bytesPerRow: number;
|
|
1328
|
+
rowsPerImage?: number;
|
|
1329
|
+
}, size: [number, number, number] | {
|
|
1330
|
+
width: number;
|
|
1331
|
+
height: number;
|
|
1332
|
+
depthOrArrayLayers?: number;
|
|
1333
|
+
}): void;
|
|
1266
1334
|
submit(commandBuffers: any[]): void;
|
|
1267
1335
|
};
|
|
1268
1336
|
createShaderModule(descriptor: {
|
|
@@ -1280,6 +1348,8 @@ interface WebGpuDeviceLike {
|
|
|
1280
1348
|
createRenderPipeline(descriptor: any): any;
|
|
1281
1349
|
createBindGroup(descriptor: any): any;
|
|
1282
1350
|
createCommandEncoder(descriptor?: any): any;
|
|
1351
|
+
/** Optional synchronous staging-buffer read hook provided by `wgpu-native` C FFI (`bun:ffi` / `koffi`). */
|
|
1352
|
+
_readBufferSync?(buffer: any, dst: Uint8Array, byteLength: number): boolean;
|
|
1283
1353
|
destroy?(): void;
|
|
1284
1354
|
}
|
|
1285
1355
|
interface WebGpuCanvasContextLike {
|
|
@@ -1322,10 +1392,20 @@ declare class RendererWebGpu extends EventEmitter {
|
|
|
1322
1392
|
readonly maxTextures = 16;
|
|
1323
1393
|
readonly canvas: HTMLCanvasElement;
|
|
1324
1394
|
readonly device: WebGpuDeviceLike;
|
|
1325
|
-
readonly gpuContext: WebGpuCanvasContextLike;
|
|
1395
|
+
readonly gpuContext: WebGpuCanvasContextLike | null;
|
|
1326
1396
|
readonly format: string;
|
|
1327
1397
|
width: number;
|
|
1328
1398
|
height: number;
|
|
1399
|
+
private offscreenTex;
|
|
1400
|
+
private offscreenView;
|
|
1401
|
+
private offscreenW;
|
|
1402
|
+
private offscreenH;
|
|
1403
|
+
private readbackBuf;
|
|
1404
|
+
private readbackCap;
|
|
1405
|
+
private readbackBytesPerRow;
|
|
1406
|
+
private uploadStaging;
|
|
1407
|
+
private uploadScratchCanvas;
|
|
1408
|
+
private uploadScratchCtx;
|
|
1329
1409
|
private readonly globalsBuf;
|
|
1330
1410
|
private readonly vbo;
|
|
1331
1411
|
private readonly ibo;
|
|
@@ -1365,6 +1445,8 @@ declare class RendererWebGpu extends EventEmitter {
|
|
|
1365
1445
|
private makeBatchBindGroup;
|
|
1366
1446
|
stats(): RendererStats;
|
|
1367
1447
|
resize(width: number, height: number): void;
|
|
1448
|
+
private ensureOffscreenTarget;
|
|
1449
|
+
private extractAndUploadTexture;
|
|
1368
1450
|
private ensureGpuTexture;
|
|
1369
1451
|
private ensureSourceBindGroup;
|
|
1370
1452
|
private currentScissor;
|
|
@@ -1379,6 +1461,18 @@ declare class RendererWebGpu extends EventEmitter {
|
|
|
1379
1461
|
private renderGraphics;
|
|
1380
1462
|
private renderNode;
|
|
1381
1463
|
render(displayList: DisplayList, camera: Camera): void;
|
|
1464
|
+
private encodeCopyToStaging;
|
|
1465
|
+
private unpackStagingBytes;
|
|
1466
|
+
/**
|
|
1467
|
+
* Synchronously read rendered W3C `RGBA8888` pixels when backed by a synchronous native WebGPU device
|
|
1468
|
+
* (`wgpu-native` C FFI via `bun:ffi` or Node `koffi`).
|
|
1469
|
+
*/
|
|
1470
|
+
readPixelsSync(out?: Uint8Array): Uint8Array;
|
|
1471
|
+
/**
|
|
1472
|
+
* Asynchronously read rendered W3C `RGBA8888` pixels across ALL WebGPU backends
|
|
1473
|
+
* (`wgpu-native` FFI, Google Dawn `webgpu`, Deno `navigator.gpu`, and Browser WebGPU).
|
|
1474
|
+
*/
|
|
1475
|
+
readPixelsAsync(out?: Uint8Array): Promise<Uint8Array>;
|
|
1382
1476
|
/** Create an offscreen render target backed by a registered Stage `Texture` (`key`) for WebGPU passes (e.g. `Lighting2DSystem`). */
|
|
1383
1477
|
createRenderTarget(key: string, width: number, height: number, textures: TextureManager, filterMode?: 0 | 1): StageRenderTarget;
|
|
1384
1478
|
/** Render a `DisplayList` (or callback) into an offscreen `StageRenderTarget` and mark its texture dirty for WebGPU upload (`camera` defaults to `target.camera`). */
|
|
@@ -2507,4 +2601,4 @@ declare class Game {
|
|
|
2507
2601
|
step(time: number, delta: number): void;
|
|
2508
2602
|
destroy(removeCanvas?: boolean): void;
|
|
2509
2603
|
}
|
|
2510
|
-
export { decodeWorldDeltaBytes as $,
|
|
2604
|
+
export { decodeWorldDeltaBytes as $, HiDpiConfigureOptions as $n, OpenWgpuNativeFfiOptions as $t, createInputRecorder as A, InstancedBatchObject as An, SceneDigestOverlayStats as At, RecipeRegistry as B, SceneHostLike as Bn, Pointer as Bt, RecordedInputEntry as C, DrawStreamBulkView as Cn, unpackChunkY as Ct, TimelineClickOptions as D, EquipmentBinding as Dn, SceneDigestEngineSandbox as Dt, StagePlugin as E, DrawStreamSpriteOptions as En, SceneDigestActiveFocus as Et, InventoryContainer as F, PanelObject as Fn, buildSceneDigest as Ft, WorkstationSnapshot as G, SpriteObject as Gn, WebGpuBootstrapResult as Gt, WorkstationInstance as H, ShapeBatchObject as Hn, RendererWebGpu as Ht, ItemDef as I, PanelOpenSide as In, sanitizeTrackToken as It, WorldDeltaSnapshot as J, TextObject as Jn, requestWebGpuDevice as Jt, WorldCatalogRuntime as K, SpritePlayOptions as Kn, WebGpuCanvasContextLike as Kt, ItemRegistry as L, PanelStyleConfig as Ln, InputConfig as Lt, createInputTimeline as M, MsdfIconConfig as Mn, SceneDigestSurfaceEntry as Mt, CatalogReloadDiff as N, MsdfIconObject as Nn, SceneDigestSurfaceSource as Nt, TimelineDragOptions as O, Graphics as On, SceneDigestNode as Ot, FrozenWorldCatalog as P, NineSliceObject as Pn, SceneDigestSurfaces as Pt, createWorldCatalogRuntime as Q, CameraFollowOptions as Qn, OpenDawnWebGpuOptions as Qt, ItemStack as R, RectClipMask as Rn, InputPlugin as Rt, InputTimelinePlugin as S, DisplaySemantics as Sn, unpackChunkX as St, StageKernel as T, DrawStreamOptions as Tn, SceneDigest as Tt, WorkstationJob as U, ShapeBatchStyleDefaults as Un, RendererWebGpuOptions as Ut, TileCellDelta as V, ShapeBatchColumns as Vn, PointerSample as Vt, WorkstationScheduler as W, SpriteAnimEventListener as Wn, RequestWebGpuOptions as Wt, applyWorldDelta as X, TileSpriteObject as Xn, HeadlessWebGpuHandle as Xt, WorldEntityRecord as Y, TextStyleConfig as Yn, HeadlessWebGpuBackend as Yt, captureWorldDelta as Z, Camera as Zn, HeadlessWebGpuOptions as Zt, ActionMap as _, CustomPassOptions as _n, floorDiv as _t, GameLoop as a, RendererGlOptions as an, ChunkedTilemapOptions as at, InputTargetSpec as b, DisplayObject as bn, packChunkKey as bt, LoaderPlugin as c, StageRenderTarget as cn, MountedChunkedTilemap as ct, SceneCtor as d, BlitterObject as dn, TileChunk as dt, openDawnWebGpu as en, HiDpiScaleLike as er, defineWorldCatalog as et, SceneInput as f, Bob as fn, bakeDualGridTileset as ft, ViewportFitResult as g, CustomPassObject as gn, fbm2D as gt, StageRenderer as h, CustomPassCallback as hn, createIslandBiomeGenerator as ht, GameConfig as i, RendererGl as in, ChunkedTilemap as it, createInputReplay as j, InstancedColumns as jn, SceneDigestSandbox as jt, TimelineKeyOptions as k, ImageObject as kn, SceneDigestOptions as kt, ScaleManager as l, AnchorPose2D as ln, SurvivalBiomes as lt, SceneManager as m, ContainerFiltersShim as mn, computeDualGridMask as mt, EngineClockSnapshot as n, requestHeadlessWebGpu as nn, BakedDualGridAtlas as nt, GameObjectFactory as o, RendererStats as on, DualGridLayerSpec as ot, SceneLifecycleStats as p, Container as pn, computeBlob47Index as pt, WorldCatalogSpec as q, SyncAttachmentOptions as qn, WebGpuDeviceLike as qt, Game as r, Renderer2D as rn, ChunkGeneratorFn as rt, JsonCache as s, Stage2DCustomImageHandler as sn, IslandBiomeConfig as st, EngineClock as t, openWgpuNativeFfi as tn, encodeWorldDeltaBytes as tt, Scene as u, BindEquipmentOptions as un, TileCellFlags as ut, InputProvider as v, DirectionalPlayOptions as vn, hash2D as vt, StageInputEvent as w, DrawStreamObject as wn, valueNoise2D as wt, InputTimelineOptions as x, DisplayObjectType as xn, positiveMod as xt, InputRecorderPlugin as y, DisplayList as yn, mountChunkedTilemap as yt, RecipeDef as z, RectangleObject as zn, KeyboardPlugin as zt };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ as rgbToCss, a as EventEmitter, c as Scale, h as packColorAbgr, l as Scenes, m as createMatrix2D, o as FilterMode, p as WHITE_RGB, r as BlendModes, u as TintModes } from "./types-CXsCvp1p.js";
|
|
2
2
|
import { AnimationManager } from "./anims.js";
|
|
3
|
-
import {
|
|
4
|
-
import { _ as TileSpriteObject, c as ImageObject, d as NineSliceObject, f as PanelObject, g as TextObject, h as SpriteObject, i as DisplayList, l as InstancedBatchObject, m as ShapeBatchObject, n as Container, o as DrawStreamObject, p as RectangleObject, r as CustomPassObject, s as Graphics, t as BlitterObject, u as MsdfIconObject } from "./display-
|
|
3
|
+
import { o as Renderer2D, s as Camera, t as RendererWebGpu } from "./renderer-webgpu-LDnrpYa0.js";
|
|
4
|
+
import { _ as TileSpriteObject, c as ImageObject, d as NineSliceObject, f as PanelObject, g as TextObject, h as SpriteObject, i as DisplayList, l as InstancedBatchObject, m as ShapeBatchObject, n as Container, o as DrawStreamObject, p as RectangleObject, r as CustomPassObject, s as Graphics, t as BlitterObject, u as MsdfIconObject } from "./display-CVjvA8ZO.js";
|
|
5
5
|
import { TweenManager } from "./tween.js";
|
|
6
6
|
import { ScriptScheduler } from "./coroutine.js";
|
|
7
7
|
import { StageKernel } from "./kernel.js";
|
|
@@ -218,12 +218,36 @@ var Texture = class {
|
|
|
218
218
|
atlasYaw = null;
|
|
219
219
|
atlasPitch = null;
|
|
220
220
|
atlasScale = null;
|
|
221
|
+
hostRef;
|
|
222
|
+
defaultPremultiply;
|
|
221
223
|
constructor(manager, key, image, filterMode, host, premultiplyAlpha = true, isRenderTarget = false) {
|
|
222
224
|
this.manager = manager;
|
|
223
225
|
this.key = key;
|
|
224
|
-
|
|
225
|
-
this.
|
|
226
|
-
|
|
226
|
+
this.hostRef = host;
|
|
227
|
+
this.defaultPremultiply = premultiplyAlpha;
|
|
228
|
+
const images = Array.isArray(image) ? image : [image];
|
|
229
|
+
this.source = images.map((img, i) => new TextureSource(this, img, filterMode, host, premultiplyAlpha, i === 0 ? isRenderTarget : false));
|
|
230
|
+
const src0 = this.source[0];
|
|
231
|
+
if (src0) this.add("__BASE", 0, 0, 0, src0.width, src0.height);
|
|
232
|
+
if (this.source.length > 1) for (let i = 0; i < this.source.length; i++) {
|
|
233
|
+
const s = this.source[i];
|
|
234
|
+
this.add(`__PAGE_${i}`, i, 0, 0, s.width, s.height);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** Number of backing `TextureSource` pages attached to this logical texture (`1` for single-page atlases). */
|
|
238
|
+
get pageCount() {
|
|
239
|
+
return this.source.length;
|
|
240
|
+
}
|
|
241
|
+
/** Append an additional `TextureSource` page dynamically (returns the new `TextureSource` at `source.length - 1`). */
|
|
242
|
+
addSource(image, filterMode, premultiplyAlpha) {
|
|
243
|
+
const idx = this.source.length;
|
|
244
|
+
const filter = filterMode ?? this.source[0]?.filterMode ?? FilterMode.LINEAR;
|
|
245
|
+
const premul = premultiplyAlpha ?? this.defaultPremultiply;
|
|
246
|
+
const src = new TextureSource(this, image, filter, this.hostRef, premul, false);
|
|
247
|
+
this.source.push(src);
|
|
248
|
+
if (idx === 1 && this.source[0] && !this.has("__PAGE_0")) this.add("__PAGE_0", 0, 0, 0, this.source[0].width, this.source[0].height);
|
|
249
|
+
this.add(`__PAGE_${idx}`, idx, 0, 0, src.width, src.height);
|
|
250
|
+
return src;
|
|
227
251
|
}
|
|
228
252
|
add(name, sourceIndex, x, y, width, height, meta) {
|
|
229
253
|
const frame = new Frame(this, name, sourceIndex, x, y, width, height, meta);
|
|
@@ -339,7 +363,7 @@ var TextureManager = class {
|
|
|
339
363
|
return this.list[key] ?? this.list["__DEFAULT"];
|
|
340
364
|
}
|
|
341
365
|
addImage(key, source, options) {
|
|
342
|
-
if (!source) return null;
|
|
366
|
+
if (!source || Array.isArray(source) && source.length === 0) return null;
|
|
343
367
|
if (this.exists(key)) this.remove(key);
|
|
344
368
|
const filter = options?.filterMode ?? this.defaultFilter;
|
|
345
369
|
const premultiply = options?.premultiplyAlpha ?? true;
|
|
@@ -379,8 +403,9 @@ var TextureManager = class {
|
|
|
379
403
|
return tex;
|
|
380
404
|
}
|
|
381
405
|
/**
|
|
382
|
-
* Register a
|
|
383
|
-
* preserving per-frame trimmed pivots (`ax/ay` or `pivot`), named sockets (`anchors`), `emissiveCenter`,
|
|
406
|
+
* Register a single-page or multi-page sprite atlas (`@holtjs/craft/three`, `@holtjs/craft/atlas`, or TexturePacker / Aseprite JSON)
|
|
407
|
+
* preserving per-frame trimmed pivots (`ax/ay` or `pivot`), named sockets (`anchors`), `emissiveCenter`, `atlasYaw`,
|
|
408
|
+
* and per-frame `page` / `sourceIndex` across multiple `<= 4096x4096` GPU texture pages!
|
|
384
409
|
*/
|
|
385
410
|
addAtlas(key, source, atlasData, options) {
|
|
386
411
|
const tex = this.addImage(key, source, options);
|
|
@@ -389,16 +414,19 @@ var TextureManager = class {
|
|
|
389
414
|
if (typeof root.yaw === "number" && Number.isFinite(root.yaw)) tex.atlasYaw = root.yaw;
|
|
390
415
|
if (typeof root.pitch === "number" && Number.isFinite(root.pitch)) tex.atlasPitch = root.pitch;
|
|
391
416
|
if (typeof root.scale === "number" && Number.isFinite(root.scale)) tex.atlasScale = root.scale;
|
|
392
|
-
const
|
|
393
|
-
|
|
417
|
+
const maxPage = Math.max(0, tex.source.length - 1);
|
|
418
|
+
const resolvePage = (rawPage, defaultPage) => {
|
|
419
|
+
const n = typeof rawPage === "number" && Number.isFinite(rawPage) ? Math.floor(rawPage) : defaultPage;
|
|
420
|
+
return n < 0 ? 0 : n > maxPage ? maxPage : n;
|
|
421
|
+
};
|
|
394
422
|
let probeCanvas = null;
|
|
395
423
|
let probeCtx = null;
|
|
396
424
|
const emptyRectCache = /* @__PURE__ */ new Map();
|
|
397
|
-
const detectEmptyRect = (fx, fy, fw, fh, explicitEmpty) => {
|
|
425
|
+
const detectEmptyRect = (pageIdx, fx, fy, fw, fh, explicitEmpty) => {
|
|
398
426
|
if (typeof explicitEmpty === "boolean") return explicitEmpty;
|
|
399
427
|
if (fw <= 1 && fh <= 1) return true;
|
|
400
428
|
if (fw > 64 || fh > 64) return false;
|
|
401
|
-
const rectKey = `${fx},${fy},${fw},${fh}`;
|
|
429
|
+
const rectKey = `${pageIdx}:${fx},${fy},${fw},${fh}`;
|
|
402
430
|
const cached = emptyRectCache.get(rectKey);
|
|
403
431
|
if (cached !== void 0) return cached;
|
|
404
432
|
let isEmpty = false;
|
|
@@ -411,9 +439,10 @@ var TextureManager = class {
|
|
|
411
439
|
probeCtx = probeCanvas.getContext("2d", { willReadFrequently: true }) ?? false;
|
|
412
440
|
} else probeCtx = false;
|
|
413
441
|
}
|
|
414
|
-
|
|
442
|
+
const pageImg = tex.source[pageIdx]?.image;
|
|
443
|
+
if (probeCtx && pageImg) {
|
|
415
444
|
probeCtx.clearRect(0, 0, fw, fh);
|
|
416
|
-
probeCtx.drawImage(
|
|
445
|
+
probeCtx.drawImage(pageImg, fx, fy, fw, fh, 0, 0, fw, fh);
|
|
417
446
|
const data = probeCtx.getImageData(0, 0, fw, fh).data;
|
|
418
447
|
let allZero = true;
|
|
419
448
|
for (let i = 3; i < data.length; i += 4) if (data[i] !== 0) {
|
|
@@ -428,8 +457,9 @@ var TextureManager = class {
|
|
|
428
457
|
emptyRectCache.set(rectKey, isEmpty);
|
|
429
458
|
return isEmpty;
|
|
430
459
|
};
|
|
431
|
-
const addEntry = (frameName, entry) => {
|
|
460
|
+
const addEntry = (frameName, entry, defaultPage) => {
|
|
432
461
|
if (!entry || typeof entry !== "object") return;
|
|
462
|
+
const pageIdx = resolvePage(entry.page ?? entry.sourceIndex, defaultPage);
|
|
433
463
|
if (entry.frame && typeof entry.frame === "object" && typeof entry.frame.w === "number") {
|
|
434
464
|
const fr = entry.frame;
|
|
435
465
|
const fx = Number(fr.x) || 0;
|
|
@@ -439,7 +469,7 @@ var TextureManager = class {
|
|
|
439
469
|
const meta = {
|
|
440
470
|
baseChar: entry.baseChar,
|
|
441
471
|
baseActor: entry.baseActor,
|
|
442
|
-
empty: detectEmptyRect(fx, fy, fw, fh, entry.empty)
|
|
472
|
+
empty: detectEmptyRect(pageIdx, fx, fy, fw, fh, entry.empty)
|
|
443
473
|
};
|
|
444
474
|
if (entry.pivot && typeof entry.pivot.x === "number" && typeof entry.pivot.y === "number") {
|
|
445
475
|
const px = Number(entry.pivot.x);
|
|
@@ -453,14 +483,14 @@ var TextureManager = class {
|
|
|
453
483
|
}
|
|
454
484
|
}
|
|
455
485
|
if (entry.anchors) meta.anchors = entry.anchors;
|
|
456
|
-
tex.add(frameName,
|
|
486
|
+
tex.add(frameName, pageIdx, fx, fy, fw, fh, meta);
|
|
457
487
|
return;
|
|
458
488
|
}
|
|
459
489
|
const fx = Number(entry.x) || 0;
|
|
460
490
|
const fy = Number(entry.y) || 0;
|
|
461
491
|
const fw = Number(entry.w ?? entry.width) || 0;
|
|
462
492
|
const fh = Number(entry.h ?? entry.height) || 0;
|
|
463
|
-
tex.add(frameName,
|
|
493
|
+
tex.add(frameName, pageIdx, fx, fy, fw, fh, {
|
|
464
494
|
ax: typeof entry.ax === "number" ? entry.ax : void 0,
|
|
465
495
|
ay: typeof entry.ay === "number" ? entry.ay : void 0,
|
|
466
496
|
pivotX: typeof entry.pivotX === "number" ? entry.pivotX : void 0,
|
|
@@ -477,14 +507,25 @@ var TextureManager = class {
|
|
|
477
507
|
frame: typeof entry.frame === "number" ? entry.frame : void 0,
|
|
478
508
|
frames: entry.frames,
|
|
479
509
|
loop: entry.loop,
|
|
480
|
-
empty: detectEmptyRect(fx, fy, fw, fh, entry.empty)
|
|
510
|
+
empty: detectEmptyRect(pageIdx, fx, fy, fw, fh, entry.empty)
|
|
481
511
|
});
|
|
482
512
|
};
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
513
|
+
const ingestFrames = (framesNode, defaultPage) => {
|
|
514
|
+
if (!framesNode) return;
|
|
515
|
+
if (Array.isArray(framesNode)) for (let i = 0; i < framesNode.length; i++) {
|
|
516
|
+
const item = framesNode[i];
|
|
517
|
+
const name = String(item?.filename ?? item?.name ?? item?.key ?? i);
|
|
518
|
+
addEntry(name, item, defaultPage);
|
|
519
|
+
}
|
|
520
|
+
else if (typeof framesNode === "object") for (const [name, item] of Object.entries(framesNode)) addEntry(name, item, defaultPage);
|
|
521
|
+
};
|
|
522
|
+
const multiPages = Array.isArray(root.textures) ? root.textures : Array.isArray(atlasData.textures) ? atlasData.textures : Array.isArray(root.pages) ? root.pages : Array.isArray(atlasData.pages) ? atlasData.pages : null;
|
|
523
|
+
if (multiPages) for (let p = 0; p < multiPages.length; p++) {
|
|
524
|
+
const pageObj = multiPages[p];
|
|
525
|
+
if (pageObj && typeof pageObj === "object" && pageObj.frames) ingestFrames(pageObj.frames, p);
|
|
486
526
|
}
|
|
487
|
-
|
|
527
|
+
const rawFrames = root.frames ?? atlasData.frames;
|
|
528
|
+
if (rawFrames) ingestFrames(rawFrames, 0);
|
|
488
529
|
return tex;
|
|
489
530
|
}
|
|
490
531
|
remove(key) {
|
|
@@ -3785,7 +3826,7 @@ var RendererGl = class extends EventEmitter {
|
|
|
3785
3826
|
const outlineAlpha = icon.outlineAlpha * alpha;
|
|
3786
3827
|
const outlineW = icon.outlineWidth;
|
|
3787
3828
|
if (fillAlpha <= 0 && (outlineW <= 0 || outlineAlpha <= 0)) return;
|
|
3788
|
-
const src = icon.texture?.source?.[0];
|
|
3829
|
+
const src = icon.frame?.source ?? icon.texture?.source?.[0];
|
|
3789
3830
|
if (!src || src.width <= 1 || src.height <= 1) return;
|
|
3790
3831
|
const ox = icon.displayOriginX;
|
|
3791
3832
|
const oy = icon.displayOriginY;
|
|
@@ -3876,19 +3917,23 @@ var RendererGl = class extends EventEmitter {
|
|
|
3876
3917
|
}
|
|
3877
3918
|
renderInstancedBatch(batch, m, alpha) {
|
|
3878
3919
|
const cols = batch.columns;
|
|
3879
|
-
if (!cols || cols.count <= 0) return;
|
|
3880
|
-
const src = batch.texture?.source?.[0];
|
|
3881
|
-
if (!src) return;
|
|
3882
|
-
const glTex = this.ensureGlTexture(src);
|
|
3883
|
-
if (!glTex) return;
|
|
3920
|
+
if (!cols || cols.count <= 0 || !batch.texture) return;
|
|
3884
3921
|
this.setBlend(batch.blendMode);
|
|
3885
3922
|
const n = Math.min(cols.count, batch.maxCount, cols.x.length, cols.y.length);
|
|
3886
3923
|
if (n <= 0) return;
|
|
3887
3924
|
if (!this.ensureInstancedResources()) {
|
|
3888
|
-
|
|
3925
|
+
let lastSrc = null;
|
|
3926
|
+
let lastGlTex = null;
|
|
3889
3927
|
for (let i = 0; i < n; i++) {
|
|
3890
3928
|
const s = cols.order ? cols.order[i] : i;
|
|
3891
3929
|
const fr = cols.frameIndex ? batch.texture.get(cols.frameIndex[s]) : batch.defaultFrame;
|
|
3930
|
+
if (!fr || fr.empty || fr.width <= 0 || fr.height <= 0) continue;
|
|
3931
|
+
if (fr.source !== lastSrc) {
|
|
3932
|
+
lastSrc = fr.source;
|
|
3933
|
+
lastGlTex = this.ensureGlTexture(lastSrc);
|
|
3934
|
+
}
|
|
3935
|
+
if (!lastGlTex) continue;
|
|
3936
|
+
const unit = this.assignTextureUnit(lastGlTex);
|
|
3892
3937
|
const sx = cols.scaleX ? cols.scaleX[s] : 1;
|
|
3893
3938
|
const sy = cols.scaleY ? cols.scaleY[s] : sx;
|
|
3894
3939
|
const a = alpha * (cols.alpha ? cols.alpha[s] : 1);
|
|
@@ -3916,12 +3961,42 @@ var RendererGl = class extends EventEmitter {
|
|
|
3916
3961
|
const ma = m.a, mb = m.b, mc = m.c, md = m.d, mtx = m.tx, mty = m.ty;
|
|
3917
3962
|
const oxRatio = batch.originX;
|
|
3918
3963
|
const oyRatio = batch.originY;
|
|
3964
|
+
const gl2 = this.gl;
|
|
3919
3965
|
let vis = 0;
|
|
3966
|
+
let curSrc = null;
|
|
3967
|
+
let curGlTex = null;
|
|
3968
|
+
let boundProg = false;
|
|
3969
|
+
const flushSubRun = () => {
|
|
3970
|
+
if (vis === 0 || !curGlTex) return;
|
|
3971
|
+
if (!boundProg) {
|
|
3972
|
+
gl2.useProgram(this.instProgram);
|
|
3973
|
+
if (this.instUres) gl2.uniform2f(this.instUres, this.width, this.height);
|
|
3974
|
+
applyGlBlendMode(gl2, this.curBlend);
|
|
3975
|
+
gl2.bindVertexArray(this.instVao);
|
|
3976
|
+
gl2.bindBuffer(gl2.ARRAY_BUFFER, this.instDataVbo);
|
|
3977
|
+
boundProg = true;
|
|
3978
|
+
}
|
|
3979
|
+
this.bindTextureAt(0, curGlTex);
|
|
3980
|
+
gl2.bufferData(gl2.ARRAY_BUFFER, f32.subarray(0, vis * INST_FLOATS), gl2.STREAM_DRAW);
|
|
3981
|
+
gl2.drawElementsInstanced(gl2.TRIANGLES, 6, gl2.UNSIGNED_SHORT, 0, vis);
|
|
3982
|
+
this.curDrawCalls++;
|
|
3983
|
+
this.curFlushes++;
|
|
3984
|
+
this.curQuads += vis;
|
|
3985
|
+
this.curTris += vis * 2;
|
|
3986
|
+
vis = 0;
|
|
3987
|
+
};
|
|
3920
3988
|
for (let i = 0; i < n; i++) {
|
|
3921
3989
|
const s = cols.order ? cols.order[i] : i;
|
|
3922
3990
|
const instA = alpha * (cols.alpha ? cols.alpha[s] : 1);
|
|
3923
3991
|
if (instA <= 0) continue;
|
|
3924
3992
|
const fr = cols.frameIndex ? batch.texture.get(cols.frameIndex[s]) : batch.defaultFrame;
|
|
3993
|
+
if (!fr || fr.empty || fr.width <= 0 || fr.height <= 0) continue;
|
|
3994
|
+
if (fr.source !== curSrc) {
|
|
3995
|
+
flushSubRun();
|
|
3996
|
+
curSrc = fr.source;
|
|
3997
|
+
curGlTex = this.ensureGlTexture(curSrc);
|
|
3998
|
+
}
|
|
3999
|
+
if (!curGlTex) continue;
|
|
3925
4000
|
const sx = (cols.scaleX ? cols.scaleX[s] : 1) * fr.width;
|
|
3926
4001
|
const sy = (cols.scaleY ? cols.scaleY[s] : cols.scaleX ? cols.scaleX[s] : 1) * fr.height;
|
|
3927
4002
|
const rot = cols.rotation ? cols.rotation[s] : 0;
|
|
@@ -3963,22 +4038,11 @@ var RendererGl = class extends EventEmitter {
|
|
|
3963
4038
|
u32[base + 10] = packColorAbgr(rgb, instA);
|
|
3964
4039
|
vis++;
|
|
3965
4040
|
}
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
this.bindTextureAt(0, glTex);
|
|
3972
|
-
gl2.bindVertexArray(this.instVao);
|
|
3973
|
-
gl2.bindBuffer(gl2.ARRAY_BUFFER, this.instDataVbo);
|
|
3974
|
-
gl2.bufferData(gl2.ARRAY_BUFFER, f32.subarray(0, vis * INST_FLOATS), gl2.STREAM_DRAW);
|
|
3975
|
-
gl2.drawElementsInstanced(gl2.TRIANGLES, 6, gl2.UNSIGNED_SHORT, 0, vis);
|
|
3976
|
-
gl2.bindVertexArray(null);
|
|
3977
|
-
this.curDrawCalls++;
|
|
3978
|
-
this.curFlushes++;
|
|
3979
|
-
this.curQuads += vis;
|
|
3980
|
-
this.curTris += vis * 2;
|
|
3981
|
-
this.invalidateProgramState();
|
|
4041
|
+
flushSubRun();
|
|
4042
|
+
if (boundProg) {
|
|
4043
|
+
gl2.bindVertexArray(null);
|
|
4044
|
+
this.invalidateProgramState();
|
|
4045
|
+
}
|
|
3982
4046
|
}
|
|
3983
4047
|
/** Create an offscreen WebGL framebuffer target backed by a registered Stage `Texture` (`key`). */
|
|
3984
4048
|
createRenderTarget(key, width, height, textures, filterMode = FilterMode.LINEAR) {
|
package/dist/headless.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as StagePlugin, Tt as SceneDigest, f as SceneInput, kt as SceneDigestOptions, n as EngineClockSnapshot, r as Game, u as Scene } from "./game-
|
|
1
|
+
import { $t as OpenWgpuNativeFfiOptions, E as StagePlugin, Qt as OpenDawnWebGpuOptions, Tt as SceneDigest, Xt as HeadlessWebGpuHandle, Yt as HeadlessWebGpuBackend, Zt as HeadlessWebGpuOptions, en as openDawnWebGpu, f as SceneInput, kt as SceneDigestOptions, n as EngineClockSnapshot, nn as requestHeadlessWebGpu, qt as WebGpuDeviceLike, r as Game, tn as openWgpuNativeFfi, u as Scene } from "./game-C8bz7tay.js";
|
|
2
2
|
/** Minimal Canvas2D surface compatible with `@napi-rs/canvas`, `node-canvas`, and browser `<canvas>`. */
|
|
3
3
|
export interface HeadlessCanvasLike {
|
|
4
4
|
width: number;
|
|
@@ -26,6 +26,10 @@ export interface HeadlessStageOptions {
|
|
|
26
26
|
readonly pixelArt?: boolean;
|
|
27
27
|
/** Optional custom WebGL/WebGL2 context when testing GPU shaders headlessly; defaults to `CANVAS` (`Renderer2D`). */
|
|
28
28
|
readonly glContext?: WebGL2RenderingContext | WebGLRenderingContext | null;
|
|
29
|
+
/** Optional native Headless WebGPU `GPUDevice` (from `await requestHeadlessWebGpu()` via `bun:ffi` / `koffi` `wgpu-native` or Dawn `webgpu`). */
|
|
30
|
+
readonly gpuDevice?: WebGpuDeviceLike | null;
|
|
31
|
+
/** Optional WebGPU offscreen render format when `gpuDevice` is passed (default `'rgba8unorm'`). */
|
|
32
|
+
readonly gpuFormat?: string;
|
|
29
33
|
/** Optional `StagePlugin[]` (e.g. `createInputTimeline`, `createInputRecorder`) mounted at boot. */
|
|
30
34
|
readonly plugins?: StagePlugin[];
|
|
31
35
|
/** Scene instance or constructor to boot synchronously at frame 0. */
|
|
@@ -83,12 +87,18 @@ export interface HeadlessStage {
|
|
|
83
87
|
keyDown(code: string, key?: string): void;
|
|
84
88
|
/** Synthesize a deterministic key-up event. */
|
|
85
89
|
keyUp(code: string, key?: string): void;
|
|
86
|
-
/** Read raw W3C RGBA8888 pixels (`width * height * 4` bytes). */
|
|
90
|
+
/** Read raw W3C RGBA8888 pixels (`width * height * 4` bytes; synchronous on Canvas2D, WebGL, and `wgpu-native` FFI). */
|
|
87
91
|
toRgba(): Uint8Array;
|
|
88
92
|
/** Copy raw W3C RGBA8888 pixels into an existing `Uint8Array` (avoids per-frame buffer allocation in tight video loops). */
|
|
89
93
|
toRgbaInto(out: Uint8Array): Uint8Array;
|
|
94
|
+
/** Asynchronously read raw W3C RGBA8888 pixels across ALL renderers (including async Dawn `'webgpu'` and `navigator.gpu`). */
|
|
95
|
+
toRgbaAsync(): Promise<Uint8Array>;
|
|
96
|
+
/** Asynchronously copy raw W3C RGBA8888 pixels into an existing `Uint8Array` across ALL renderers. */
|
|
97
|
+
toRgbaIntoAsync(out: Uint8Array): Promise<Uint8Array>;
|
|
90
98
|
/** Encode current frame to PNG bytes (requires `canvas.toBuffer('image/png')` such as `@napi-rs/canvas`). */
|
|
91
99
|
toPng(): Uint8Array;
|
|
100
|
+
/** Asynchronously encode current frame to PNG bytes across ALL renderers (including async Dawn `'webgpu'`). */
|
|
101
|
+
toPngAsync(): Promise<Uint8Array>;
|
|
92
102
|
/** Capture a zero-PII structured `SceneDigest` for the active scene at the current frame. */
|
|
93
103
|
digest(options?: SceneDigestOptions): SceneDigest;
|
|
94
104
|
/** Step and stream raw RGBA frames (e.g. into `ffmpeg`) at deterministic `fps`. */
|
|
@@ -230,4 +240,5 @@ export declare function buildFfmpegRawVideoArgs(options: FfmpegRawVideoArgsOptio
|
|
|
230
240
|
* Step a `HeadlessStage` in Node.js or Bun and stream raw `RGBA8888` frames (`-f rawvideo -pix_fmt rgba`)
|
|
231
241
|
* directly into `ffmpeg` stdin with backpressure handling and optional stereo `.wav` audio muxing.
|
|
232
242
|
*/
|
|
233
|
-
export declare function encodeVideoWithFfmpeg(stage: HeadlessStage, options: EncodeVideoWithFfmpegOptions): Promise<EncodeVideoResult>;
|
|
243
|
+
export declare function encodeVideoWithFfmpeg(stage: HeadlessStage, options: EncodeVideoWithFfmpegOptions): Promise<EncodeVideoResult>;
|
|
244
|
+
export { type HeadlessWebGpuBackend, type HeadlessWebGpuHandle, type HeadlessWebGpuOptions, type OpenDawnWebGpuOptions, type OpenWgpuNativeFfiOptions, openDawnWebGpu, openWgpuNativeFfi, requestHeadlessWebGpu };
|