@codexo/exojs-tilemap 0.19.0 → 0.20.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 +7 -163
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/ChunkSource.d.ts +0 -33
- package/dist/esm/ChunkSource.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.d.ts +0 -104
- package/dist/esm/ChunkStreamer.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.js +0 -229
- package/dist/esm/ChunkStreamer.js.map +0 -1
- package/dist/esm/ImageLayer.d.ts +0 -89
- package/dist/esm/ImageLayer.d.ts.map +0 -1
- package/dist/esm/ImageLayer.js +0 -74
- package/dist/esm/ImageLayer.js.map +0 -1
- package/dist/esm/ImageLayerNode.d.ts +0 -91
- package/dist/esm/ImageLayerNode.d.ts.map +0 -1
- package/dist/esm/ImageLayerNode.js +0 -210
- package/dist/esm/ImageLayerNode.js.map +0 -1
- package/dist/esm/MapObject.d.ts +0 -70
- package/dist/esm/MapObject.d.ts.map +0 -1
- package/dist/esm/MapObject.js +0 -34
- package/dist/esm/MapObject.js.map +0 -1
- package/dist/esm/MapObjectSpawner.d.ts +0 -133
- package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
- package/dist/esm/MapObjectSpawner.js +0 -147
- package/dist/esm/MapObjectSpawner.js.map +0 -1
- package/dist/esm/MapSpawnSession.d.ts +0 -46
- package/dist/esm/MapSpawnSession.d.ts.map +0 -1
- package/dist/esm/MapSpawnSession.js +0 -88
- package/dist/esm/MapSpawnSession.js.map +0 -1
- package/dist/esm/MapWorld.d.ts +0 -134
- package/dist/esm/MapWorld.d.ts.map +0 -1
- package/dist/esm/MapWorld.js +0 -150
- package/dist/esm/MapWorld.js.map +0 -1
- package/dist/esm/MapWorldRuntime.d.ts +0 -180
- package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
- package/dist/esm/MapWorldRuntime.js +0 -261
- package/dist/esm/MapWorldRuntime.js.map +0 -1
- package/dist/esm/ObjectLayer.d.ts +0 -379
- package/dist/esm/ObjectLayer.d.ts.map +0 -1
- package/dist/esm/ObjectLayer.js +0 -221
- package/dist/esm/ObjectLayer.js.map +0 -1
- package/dist/esm/SampledChunkSource.d.ts +0 -43
- package/dist/esm/SampledChunkSource.d.ts.map +0 -1
- package/dist/esm/SampledChunkSource.js +0 -48
- package/dist/esm/SampledChunkSource.js.map +0 -1
- package/dist/esm/TileAnimator.d.ts +0 -72
- package/dist/esm/TileAnimator.d.ts.map +0 -1
- package/dist/esm/TileAnimator.js +0 -158
- package/dist/esm/TileAnimator.js.map +0 -1
- package/dist/esm/TileChunk.d.ts +0 -103
- package/dist/esm/TileChunk.d.ts.map +0 -1
- package/dist/esm/TileChunk.js +0 -194
- package/dist/esm/TileChunk.js.map +0 -1
- package/dist/esm/TileChunkNode.d.ts +0 -2
- package/dist/esm/TileChunkNode.d.ts.map +0 -1
- package/dist/esm/TileChunkNode.js +0 -145
- package/dist/esm/TileChunkNode.js.map +0 -1
- package/dist/esm/TileLayer.d.ts +0 -286
- package/dist/esm/TileLayer.d.ts.map +0 -1
- package/dist/esm/TileLayer.js +0 -526
- package/dist/esm/TileLayer.js.map +0 -1
- package/dist/esm/TileLayerNode.d.ts +0 -129
- package/dist/esm/TileLayerNode.d.ts.map +0 -1
- package/dist/esm/TileLayerNode.js +0 -245
- package/dist/esm/TileLayerNode.js.map +0 -1
- package/dist/esm/TileMap.d.ts +0 -317
- package/dist/esm/TileMap.d.ts.map +0 -1
- package/dist/esm/TileMap.js +0 -406
- package/dist/esm/TileMap.js.map +0 -1
- package/dist/esm/TileMapBand.d.ts +0 -80
- package/dist/esm/TileMapBand.d.ts.map +0 -1
- package/dist/esm/TileMapBand.js +0 -155
- package/dist/esm/TileMapBand.js.map +0 -1
- package/dist/esm/TileMapNode.d.ts +0 -92
- package/dist/esm/TileMapNode.d.ts.map +0 -1
- package/dist/esm/TileMapNode.js +0 -134
- package/dist/esm/TileMapNode.js.map +0 -1
- package/dist/esm/TileMapView.d.ts +0 -248
- package/dist/esm/TileMapView.d.ts.map +0 -1
- package/dist/esm/TileMapView.js +0 -394
- package/dist/esm/TileMapView.js.map +0 -1
- package/dist/esm/TileProjection.d.ts +0 -59
- package/dist/esm/TileProjection.d.ts.map +0 -1
- package/dist/esm/TileProjection.js +0 -106
- package/dist/esm/TileProjection.js.map +0 -1
- package/dist/esm/TileSet.d.ts +0 -116
- package/dist/esm/TileSet.d.ts.map +0 -1
- package/dist/esm/TileSet.js +0 -168
- package/dist/esm/TileSet.js.map +0 -1
- package/dist/esm/WangSet.d.ts +0 -80
- package/dist/esm/WangSet.d.ts.map +0 -1
- package/dist/esm/WangSet.js +0 -73
- package/dist/esm/WangSet.js.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.js +0 -113
- package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
- package/dist/esm/autoTile.d.ts +0 -88
- package/dist/esm/autoTile.d.ts.map +0 -1
- package/dist/esm/autoTile.js +0 -173
- package/dist/esm/autoTile.js.map +0 -1
- package/dist/esm/chunkGeometry.d.ts +0 -2
- package/dist/esm/chunkGeometry.d.ts.map +0 -1
- package/dist/esm/chunkGeometry.js +0 -116
- package/dist/esm/chunkGeometry.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -27
- package/dist/esm/nodeBounds.d.ts +0 -2
- package/dist/esm/nodeBounds.d.ts.map +0 -1
- package/dist/esm/nodeBounds.js +0 -40
- package/dist/esm/nodeBounds.js.map +0 -1
- package/dist/esm/pixelSnap.d.ts +0 -2
- package/dist/esm/pixelSnap.d.ts.map +0 -1
- package/dist/esm/pixelSnap.js +0 -21
- package/dist/esm/pixelSnap.js.map +0 -1
- package/dist/esm/projectObject.d.ts +0 -4
- package/dist/esm/projectObject.d.ts.map +0 -1
- package/dist/esm/projectObject.js +0 -87
- package/dist/esm/projectObject.js.map +0 -1
- package/dist/esm/public.d.ts +0 -48
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/tileCollision.d.ts +0 -190
- package/dist/esm/tileCollision.d.ts.map +0 -1
- package/dist/esm/tileCollision.js +0 -399
- package/dist/esm/tileCollision.js.map +0 -1
- package/dist/esm/tileWord.d.ts +0 -2
- package/dist/esm/tileWord.d.ts.map +0 -1
- package/dist/esm/tileWord.js +0 -16
- package/dist/esm/tileWord.js.map +0 -1
- package/dist/esm/tilemapExtension.d.ts +0 -20
- package/dist/esm/tilemapExtension.d.ts.map +0 -1
- package/dist/esm/tilemapExtension.js +0 -53
- package/dist/esm/tilemapExtension.js.map +0 -1
- package/dist/esm/tilemapSerializers.d.ts +0 -2
- package/dist/esm/tilemapSerializers.d.ts.map +0 -1
- package/dist/esm/tilemapSerializers.js +0 -54
- package/dist/esm/tilemapSerializers.js.map +0 -1
- package/dist/esm/types.d.ts +0 -231
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -129
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { TILE_DIAGONAL_BIT, TILE_ROW_MASK } from "../tileWord.js";
|
|
2
|
-
import tile_chunk_default from "./shaders/tile-chunk.frag.js";
|
|
3
|
-
import tile_chunk_default$1 from "./shaders/tile-chunk.vert.js";
|
|
4
|
-
import { AbstractWebGl2Renderer, BlendModes, BufferTypes, BufferUsage, RenderingPrimitives, WebGl2RenderBuffer, WebGl2Shader, WebGl2VertexArrayObject, colorShaderSourcesGlsl, createWebGl2ShaderProgram, fillShaderSource, packedGroupChanged, spliceGlslPrologue, uploadBufferRange, uploadBufferStore } from "@codexo/exojs/renderer-sdk";
|
|
5
|
-
|
|
6
|
-
//#region src/webgl2/WebGl2TileChunkRenderer.ts
|
|
7
|
-
const instanceStrideBytes = 32;
|
|
8
|
-
const wordsPerInstance = instanceStrideBytes / Uint32Array.BYTES_PER_ELEMENT;
|
|
9
|
-
const transformTextureUnit = 1;
|
|
10
|
-
const identityGroupMat3 = new Float32Array([
|
|
11
|
-
1,
|
|
12
|
-
0,
|
|
13
|
-
0,
|
|
14
|
-
0,
|
|
15
|
-
1,
|
|
16
|
-
0,
|
|
17
|
-
0,
|
|
18
|
-
0,
|
|
19
|
-
1
|
|
20
|
-
]);
|
|
21
|
-
const tileVertexSource = spliceGlslPrologue(fillShaderSource(tile_chunk_default$1, {
|
|
22
|
-
tileRowMask: TILE_ROW_MASK,
|
|
23
|
-
tileDiagonalBit: TILE_DIAGONAL_BIT
|
|
24
|
-
}), colorShaderSourcesGlsl);
|
|
25
|
-
/**
|
|
26
|
-
* Instanced WebGL2 renderer for {@link TileChunkNode}. Each tile is one
|
|
27
|
-
* instanced quad; tiles are batched by `(shader, tileset texture)` and one
|
|
28
|
-
* `drawArraysInstanced` is issued per batch. Per-chunk transforms ride on the
|
|
29
|
-
* shared transform buffer (one row per chunk node), so the chunk geometry is
|
|
30
|
-
* orientation-neutral and never re-uploaded for a camera pan.
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
var WebGl2TileChunkRenderer = class extends AbstractWebGl2Renderer {
|
|
34
|
-
/**
|
|
35
|
-
* Retained-batch capability opt-in: a tile chunk's per-flush
|
|
36
|
-
* instanced batches (fixed 32-byte layout, tile word at word 7) can be
|
|
37
|
-
* recorded into a group's instruction set and replayed from group-owned
|
|
38
|
-
* resources. Pixel-snapped draws are excluded by the collect-time
|
|
39
|
-
* recordability predicate (and belt-and-braces poisoning in {@link render});
|
|
40
|
-
* tile chunks have no custom-material path to exclude.
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
supportsRetainedBatches = true;
|
|
44
|
-
_shader;
|
|
45
|
-
_batchSize;
|
|
46
|
-
_instanceData;
|
|
47
|
-
_instanceFloat32;
|
|
48
|
-
_instanceUint32;
|
|
49
|
-
_transformUnitScratch = new Int32Array([transformTextureUnit]);
|
|
50
|
-
_baseTextureUnitScratch = new Int32Array([0]);
|
|
51
|
-
_recordTextures = [null];
|
|
52
|
-
_quadIndex = 0;
|
|
53
|
-
_maxNodeIndex = 0;
|
|
54
|
-
_batchNodeCount = 0;
|
|
55
|
-
_nodeBooked = false;
|
|
56
|
-
_currentBlendMode = null;
|
|
57
|
-
_currentTexture = null;
|
|
58
|
-
_currentView = null;
|
|
59
|
-
_currentViewId = -1;
|
|
60
|
-
_hasWrittenGroup = false;
|
|
61
|
-
_writtenGroupData = /* @__PURE__ */ new Float32Array(9);
|
|
62
|
-
_instanceBuffer = null;
|
|
63
|
-
_vao = null;
|
|
64
|
-
_connection = null;
|
|
65
|
-
constructor(batchSize) {
|
|
66
|
-
super();
|
|
67
|
-
this._batchSize = batchSize;
|
|
68
|
-
this._shader = new WebGl2Shader(tileVertexSource, tile_chunk_default);
|
|
69
|
-
this._instanceData = /* @__PURE__ */ new ArrayBuffer(batchSize * instanceStrideBytes);
|
|
70
|
-
this._instanceFloat32 = new Float32Array(this._instanceData);
|
|
71
|
-
this._instanceUint32 = new Uint32Array(this._instanceData);
|
|
72
|
-
}
|
|
73
|
-
render(node) {
|
|
74
|
-
const pages = node.pages;
|
|
75
|
-
this._nodeBooked = false;
|
|
76
|
-
if (pages.length === 0) return;
|
|
77
|
-
const backend = this.getBackend();
|
|
78
|
-
const blendMode = node.blendMode;
|
|
79
|
-
const tintRgba = node.tint.toRgba8();
|
|
80
|
-
const command = backend.activeDrawCommand;
|
|
81
|
-
const nodeIndex = command !== null ? command.nodeIndex : backend.pushTransform(node);
|
|
82
|
-
for (const page of pages) this._renderPage(page.texture, page.quads, blendMode, tintRgba, nodeIndex);
|
|
83
|
-
}
|
|
84
|
-
_renderPage(texture, quads, blendMode, tintRgba, nodeIndex) {
|
|
85
|
-
if (quads.length === 0) return;
|
|
86
|
-
const textureChanged = this._currentTexture !== null && texture !== this._currentTexture;
|
|
87
|
-
const blendModeChanged = this._currentBlendMode !== null && blendMode !== this._currentBlendMode;
|
|
88
|
-
if (this._quadIndex > 0 && (blendModeChanged || textureChanged || this._quadIndex + quads.length > this._batchSize)) this.flush();
|
|
89
|
-
this._currentBlendMode = blendMode;
|
|
90
|
-
this._currentTexture = texture;
|
|
91
|
-
const flipY = texture.flipY;
|
|
92
|
-
let offset = 0;
|
|
93
|
-
while (offset < quads.length) {
|
|
94
|
-
const remaining = quads.length - offset;
|
|
95
|
-
const runSize = Math.min(remaining, this._batchSize);
|
|
96
|
-
this._writeRun(quads, offset, runSize, flipY, tintRgba, nodeIndex);
|
|
97
|
-
offset += runSize;
|
|
98
|
-
if (offset < quads.length) {
|
|
99
|
-
this.flush();
|
|
100
|
-
this._currentBlendMode = blendMode;
|
|
101
|
-
this._currentTexture = texture;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
_writeRun(quads, offset, count, flipY, tintRgba, nodeIndex) {
|
|
106
|
-
const f32 = this._instanceFloat32;
|
|
107
|
-
const u32 = this._instanceUint32;
|
|
108
|
-
const baseWord = nodeIndex & TILE_ROW_MASK;
|
|
109
|
-
if (!this._nodeBooked) {
|
|
110
|
-
this._nodeBooked = true;
|
|
111
|
-
this._batchNodeCount++;
|
|
112
|
-
}
|
|
113
|
-
for (let i = 0; i < count; i++) {
|
|
114
|
-
const q = quads[offset + i];
|
|
115
|
-
const idx = this._quadIndex * wordsPerInstance;
|
|
116
|
-
f32[idx + 0] = q.x0;
|
|
117
|
-
f32[idx + 1] = q.y0;
|
|
118
|
-
f32[idx + 2] = q.x1;
|
|
119
|
-
f32[idx + 3] = q.y1;
|
|
120
|
-
const flipX = (q.orient & 1) !== 0;
|
|
121
|
-
const tileFlipY = (q.orient & 2) !== 0;
|
|
122
|
-
const diagonal = (q.orient & 4) !== 0;
|
|
123
|
-
const uA = flipX ? q.u1 : q.u0;
|
|
124
|
-
const uB = flipX ? q.u0 : q.u1;
|
|
125
|
-
let vA = tileFlipY ? q.v1 : q.v0;
|
|
126
|
-
let vB = tileFlipY ? q.v0 : q.v1;
|
|
127
|
-
if (flipY) {
|
|
128
|
-
const swap = vA;
|
|
129
|
-
vA = vB;
|
|
130
|
-
vB = swap;
|
|
131
|
-
}
|
|
132
|
-
const uMin = uA * 65535 & 65535;
|
|
133
|
-
const vMin = vA * 65535 & 65535;
|
|
134
|
-
const uMax = uB * 65535 & 65535;
|
|
135
|
-
const vMax = vB * 65535 & 65535;
|
|
136
|
-
u32[idx + 4] = uMin | vMin << 16;
|
|
137
|
-
u32[idx + 5] = uMax | vMax << 16;
|
|
138
|
-
u32[idx + 6] = tintRgba;
|
|
139
|
-
u32[idx + 7] = (diagonal ? baseWord | TILE_DIAGONAL_BIT : baseWord) >>> 0;
|
|
140
|
-
this._quadIndex++;
|
|
141
|
-
}
|
|
142
|
-
if (nodeIndex > this._maxNodeIndex) this._maxNodeIndex = nodeIndex;
|
|
143
|
-
}
|
|
144
|
-
flush() {
|
|
145
|
-
const backend = this.getBackendOrNull();
|
|
146
|
-
const instanceBuffer = this._instanceBuffer;
|
|
147
|
-
const vao = this._vao;
|
|
148
|
-
if (this._quadIndex === 0 || backend === null || instanceBuffer === null || vao === null) {
|
|
149
|
-
this._resetBatchState();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
this._stageViewUniforms(backend);
|
|
153
|
-
if (this._currentTexture !== null) {
|
|
154
|
-
backend.bindTexture(this._currentTexture, 0);
|
|
155
|
-
this._shader.getUniform("u_texture").setValue(this._baseTextureUnitScratch);
|
|
156
|
-
}
|
|
157
|
-
backend.bindTransformBufferTexture(transformTextureUnit, this._maxNodeIndex + 1);
|
|
158
|
-
this._shader.getUniform("u_transforms").setValue(this._transformUnitScratch);
|
|
159
|
-
this._shader.sync();
|
|
160
|
-
backend.bindVertexArrayObject(vao);
|
|
161
|
-
instanceBuffer.upload(this._instanceFloat32, 0, this._quadIndex * wordsPerInstance);
|
|
162
|
-
backend.setBlendMode(this._currentBlendMode ?? BlendModes.Normal);
|
|
163
|
-
vao.drawInstanced(4, 0, this._quadIndex, RenderingPrimitives.TriangleStrip);
|
|
164
|
-
backend.stats.batches++;
|
|
165
|
-
backend.stats.drawCalls++;
|
|
166
|
-
if (backend._isRetainedCapturing && this._currentTexture !== null) {
|
|
167
|
-
this._recordTextures[0] = this._currentTexture;
|
|
168
|
-
backend.recordRetainedBatch(this, this._instanceUint32.subarray(0, this._quadIndex * wordsPerInstance), this._quadIndex, this._currentBlendMode ?? BlendModes.Normal, this._recordTextures, 1, null, null, this._batchNodeCount);
|
|
169
|
-
}
|
|
170
|
-
this._resetBatchState();
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Scope the batch memos to one batch: they describe what is accumulating, not
|
|
174
|
-
* what GL holds, so a memo that outlived its flush would let the next batch
|
|
175
|
-
* skip establishing state another renderer has since changed.
|
|
176
|
-
*/
|
|
177
|
-
_resetBatchState() {
|
|
178
|
-
this._quadIndex = 0;
|
|
179
|
-
this._maxNodeIndex = 0;
|
|
180
|
-
this._batchNodeCount = 0;
|
|
181
|
-
this._currentBlendMode = null;
|
|
182
|
-
this._currentTexture = null;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Stage `u_projection` (live view) and `u_group` (live composed group
|
|
186
|
-
* matrix) on the shader, guarded by cached view/group stamps. Shared by the
|
|
187
|
-
* live flush path and retained-batch replay - replay resolves exactly the
|
|
188
|
-
* same live state a slow-path flush would.
|
|
189
|
-
*/
|
|
190
|
-
_stageViewUniforms(backend) {
|
|
191
|
-
const view = backend.view;
|
|
192
|
-
if (this._currentView !== view || this._currentViewId !== view.updateId) {
|
|
193
|
-
this._currentView = view;
|
|
194
|
-
this._currentViewId = view.updateId;
|
|
195
|
-
this._shader.getUniform("u_projection").setValue(view.getTransform().toArray(false));
|
|
196
|
-
}
|
|
197
|
-
const groupTransform = backend.renderGroupTransform;
|
|
198
|
-
const groupData = groupTransform !== null ? groupTransform.toArray(false) : identityGroupMat3;
|
|
199
|
-
if (!this._hasWrittenGroup || packedGroupChanged(groupData, this._writtenGroupData, 0)) {
|
|
200
|
-
this._shader.getUniform("u_group").setValue(groupData);
|
|
201
|
-
this._writtenGroupData.set(groupData);
|
|
202
|
-
this._hasWrittenGroup = true;
|
|
203
|
-
}
|
|
204
|
-
backend.stageViewportUniform(this._shader);
|
|
205
|
-
}
|
|
206
|
-
/** @internal See {@link WebGl2RetainedBatchReplayer.scanRetainedNodeIndexRange}. */
|
|
207
|
-
scanRetainedNodeIndexRange(payload, range) {
|
|
208
|
-
const words = payload.bundle.instanceWords;
|
|
209
|
-
const start = payload.byteOffset / Uint32Array.BYTES_PER_ELEMENT;
|
|
210
|
-
for (let i = 0; i < payload.instanceCount; i++) {
|
|
211
|
-
const row = words[start + i * wordsPerInstance + 7] & TILE_ROW_MASK;
|
|
212
|
-
if (row < range.min) range.min = row;
|
|
213
|
-
if (row > range.max) range.max = row;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/** @internal See {@link WebGl2RetainedBatchReplayer.rebaseRetainedNodeIndices} (group-local indices). */
|
|
217
|
-
rebaseRetainedNodeIndices(payload, base) {
|
|
218
|
-
const words = payload.bundle.instanceWords;
|
|
219
|
-
const start = payload.byteOffset / Uint32Array.BYTES_PER_ELEMENT;
|
|
220
|
-
for (let i = 0; i < payload.instanceCount; i++) {
|
|
221
|
-
const index = start + i * wordsPerInstance + 7;
|
|
222
|
-
const word = words[index];
|
|
223
|
-
words[index] = (word & TILE_DIAGONAL_BIT | (word & TILE_ROW_MASK) - base & TILE_ROW_MASK) >>> 0;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Point the batch VAO's per-instance attributes at the bundle's persistent
|
|
228
|
-
* instance buffer, based at the batch's byte offset (WebGL2 has no
|
|
229
|
-
* baseInstance, hence one small VAO per recorded batch). Same attribute
|
|
230
|
-
* set/locations as the live VAO in {@link onConnect}.
|
|
231
|
-
* @internal
|
|
232
|
-
*/
|
|
233
|
-
configureRetainedVao(payload) {
|
|
234
|
-
const gl = this.getBackend().context;
|
|
235
|
-
const buffer = payload.bundle.instanceBuffer;
|
|
236
|
-
const vao = payload.vao;
|
|
237
|
-
if (buffer === null || vao === null) throw new Error("WebGl2TileChunkRenderer: retained batch VAO configuration requires an uploaded bundle.");
|
|
238
|
-
const base = payload.byteOffset;
|
|
239
|
-
vao.addAttribute(buffer, this._shader.getAttribute("a_quadBounds"), gl.FLOAT, false, instanceStrideBytes, base + 0, false, 1).addAttribute(buffer, this._shader.getAttribute("a_uvBounds"), gl.UNSIGNED_SHORT, true, instanceStrideBytes, base + 16, false, 1).addAttribute(buffer, this._shader.getAttribute("a_color"), gl.UNSIGNED_BYTE, true, instanceStrideBytes, base + 24, false, 1).addAttribute(buffer, this._shader.getAttribute("a_tileWord"), gl.UNSIGNED_INT, false, instanceStrideBytes, base + 28, true, 1);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Replay one recorded batch: all STATE is resolved live - blend mode via
|
|
243
|
-
* the backend's dedup, `u_projection`/`u_group` from the live view + live
|
|
244
|
-
* composed group matrix (the camera-pan / group-move win), the single
|
|
245
|
-
* tileset texture bound to unit 0 by recorded slot order - and only the
|
|
246
|
-
* DATA is cached: the instance bytes in the bundle buffer (bound through
|
|
247
|
-
* the per-batch VAO) and the group-owned transform texture on the shared
|
|
248
|
-
* transform unit. The backend hook flushed any pending live batch before
|
|
249
|
-
* dispatching here and bumps the stats from the instruction descriptor.
|
|
250
|
-
* @internal
|
|
251
|
-
*/
|
|
252
|
-
replayRetainedBatch(payload) {
|
|
253
|
-
const backend = this.getBackendOrNull();
|
|
254
|
-
const vao = payload.vao;
|
|
255
|
-
const transformTexture = payload.bundle.transformTexture;
|
|
256
|
-
if (backend === null || vao === null || transformTexture === null) return false;
|
|
257
|
-
backend.setBlendMode(payload.blendMode);
|
|
258
|
-
this._stageViewUniforms(backend);
|
|
259
|
-
const textures = payload.textures;
|
|
260
|
-
for (let i = 0; i < textures.length; i++) backend.bindTexture(textures[i], i);
|
|
261
|
-
this._shader.getUniform("u_texture").setValue(this._baseTextureUnitScratch);
|
|
262
|
-
backend.bindTexture(transformTexture, transformTextureUnit);
|
|
263
|
-
this._shader.getUniform("u_transforms").setValue(this._transformUnitScratch);
|
|
264
|
-
this._shader.sync();
|
|
265
|
-
backend.bindVertexArrayObject(vao);
|
|
266
|
-
vao.drawInstanced(4, 0, payload.instanceCount, RenderingPrimitives.TriangleStrip);
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
onConnect(backend) {
|
|
270
|
-
const gl = backend.context;
|
|
271
|
-
this._shader.connect(createWebGl2ShaderProgram(gl));
|
|
272
|
-
this._connection = this._createConnection(gl);
|
|
273
|
-
this._instanceBuffer = new WebGl2RenderBuffer(BufferTypes.ArrayBuffer, this._instanceData, BufferUsage.DynamicDraw).connect(this._createBufferRuntime(this._connection));
|
|
274
|
-
this._shader.sync();
|
|
275
|
-
this._vao = new WebGl2VertexArrayObject(RenderingPrimitives.TriangleStrip).addAttribute(this._instanceBuffer, this._shader.getAttribute("a_quadBounds"), gl.FLOAT, false, instanceStrideBytes, 0, false, 1).addAttribute(this._instanceBuffer, this._shader.getAttribute("a_uvBounds"), gl.UNSIGNED_SHORT, true, instanceStrideBytes, 16, false, 1).addAttribute(this._instanceBuffer, this._shader.getAttribute("a_color"), gl.UNSIGNED_BYTE, true, instanceStrideBytes, 24, false, 1).addAttribute(this._instanceBuffer, this._shader.getAttribute("a_tileWord"), gl.UNSIGNED_INT, false, instanceStrideBytes, 28, true, 1).connect(this._createVaoRuntime(this._connection));
|
|
276
|
-
}
|
|
277
|
-
onDisconnect() {
|
|
278
|
-
this._shader.destroy();
|
|
279
|
-
this._instanceBuffer?.destroy();
|
|
280
|
-
this._instanceBuffer = null;
|
|
281
|
-
this._vao?.destroy();
|
|
282
|
-
this._vao = null;
|
|
283
|
-
this._connection = null;
|
|
284
|
-
this._currentBlendMode = null;
|
|
285
|
-
this._currentTexture = null;
|
|
286
|
-
this._currentView = null;
|
|
287
|
-
this._currentViewId = -1;
|
|
288
|
-
this._hasWrittenGroup = false;
|
|
289
|
-
this._quadIndex = 0;
|
|
290
|
-
this._maxNodeIndex = 0;
|
|
291
|
-
this._batchNodeCount = 0;
|
|
292
|
-
this._nodeBooked = false;
|
|
293
|
-
}
|
|
294
|
-
destroy() {
|
|
295
|
-
this.disconnect();
|
|
296
|
-
this._shader.destroy();
|
|
297
|
-
}
|
|
298
|
-
_createConnection(gl) {
|
|
299
|
-
const vaoHandle = gl.createVertexArray();
|
|
300
|
-
if (vaoHandle === null) throw new Error("WebGl2TileChunkRenderer: could not create vertex array object.");
|
|
301
|
-
return {
|
|
302
|
-
gl,
|
|
303
|
-
buffers: /* @__PURE__ */ new Map(),
|
|
304
|
-
vaoHandle
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
_createBufferRuntime(connection) {
|
|
308
|
-
const handle = connection.gl.createBuffer();
|
|
309
|
-
if (handle === null) throw new Error("WebGl2TileChunkRenderer: could not create render buffer.");
|
|
310
|
-
return {
|
|
311
|
-
bind: (buffer) => {
|
|
312
|
-
connection.gl.bindBuffer(buffer.type, handle);
|
|
313
|
-
},
|
|
314
|
-
upload: (buffer, offset) => {
|
|
315
|
-
const gl = connection.gl;
|
|
316
|
-
const state = connection.buffers.get(buffer);
|
|
317
|
-
gl.bindBuffer(buffer.type, handle);
|
|
318
|
-
if (state && state.dataByteLength >= buffer.uploadByteLength) {
|
|
319
|
-
uploadBufferRange(gl, buffer, offset);
|
|
320
|
-
state.dataByteLength = buffer.uploadByteLength;
|
|
321
|
-
} else {
|
|
322
|
-
uploadBufferStore(gl, buffer);
|
|
323
|
-
connection.buffers.set(buffer, {
|
|
324
|
-
handle,
|
|
325
|
-
dataByteLength: buffer.uploadByteLength
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
destroy: (buffer) => {
|
|
330
|
-
connection.gl.deleteBuffer(handle);
|
|
331
|
-
connection.buffers.delete(buffer);
|
|
332
|
-
buffer.disconnect();
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
_createVaoRuntime(connection) {
|
|
337
|
-
let appliedVersion = -1;
|
|
338
|
-
return {
|
|
339
|
-
bind: (vao) => {
|
|
340
|
-
const gl = connection.gl;
|
|
341
|
-
gl.bindVertexArray(connection.vaoHandle);
|
|
342
|
-
if (appliedVersion !== vao.version) {
|
|
343
|
-
let lastBuffer = null;
|
|
344
|
-
for (const attribute of vao.attributes) {
|
|
345
|
-
if (lastBuffer !== attribute.buffer) {
|
|
346
|
-
attribute.buffer.bind();
|
|
347
|
-
lastBuffer = attribute.buffer;
|
|
348
|
-
}
|
|
349
|
-
if (attribute.integer) gl.vertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, attribute.start);
|
|
350
|
-
else gl.vertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.start);
|
|
351
|
-
gl.enableVertexAttribArray(attribute.location);
|
|
352
|
-
gl.vertexAttribDivisor(attribute.location, attribute.divisor);
|
|
353
|
-
}
|
|
354
|
-
appliedVersion = vao.version;
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
unbind: () => {
|
|
358
|
-
connection.gl.bindVertexArray(null);
|
|
359
|
-
},
|
|
360
|
-
draw: (_vao, size, start, type) => {
|
|
361
|
-
connection.gl.drawArrays(type, start, size);
|
|
362
|
-
},
|
|
363
|
-
drawInstanced: (_vao, count, start, instanceCount, type) => {
|
|
364
|
-
connection.gl.drawArraysInstanced(type, start, count, instanceCount);
|
|
365
|
-
},
|
|
366
|
-
destroy: (vao) => {
|
|
367
|
-
connection.gl.deleteVertexArray(connection.vaoHandle);
|
|
368
|
-
vao.disconnect();
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
//#endregion
|
|
375
|
-
export { WebGl2TileChunkRenderer };
|
|
376
|
-
//# sourceMappingURL=WebGl2TileChunkRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebGl2TileChunkRenderer.js","names":["tileVertexTemplate","tileFragmentSource"],"sources":["../../../src/webgl2/WebGl2TileChunkRenderer.ts"],"sourcesContent":["import type {\n RenderTexture,\n Texture,\n View,\n WebGl2Backend,\n WebGl2RenderBufferRuntime,\n WebGl2RetainedBatchPayload,\n WebGl2RetainedBatchReplayer,\n WebGl2RetainedNodeIndexRange,\n WebGl2VertexArrayObjectRuntime,\n} from '@codexo/exojs/renderer-sdk';\nimport {\n AbstractWebGl2Renderer,\n BlendModes,\n BufferTypes,\n BufferUsage,\n colorShaderSourcesGlsl,\n createWebGl2ShaderProgram,\n fillShaderSource,\n packedGroupChanged,\n RenderingPrimitives,\n spliceGlslPrologue,\n uploadBufferRange,\n uploadBufferStore,\n WebGl2RenderBuffer,\n WebGl2Shader,\n WebGl2VertexArrayObject,\n} from '@codexo/exojs/renderer-sdk';\n\nimport type { TileQuad } from '../chunkGeometry';\nimport type { TileChunkNode } from '../TileChunkNode';\nimport { TILE_DIAGONAL_BIT, TILE_ROW_MASK } from '../tileWord';\nimport tileFragmentSource from './shaders/tile-chunk.frag';\nimport tileVertexTemplate from './shaders/tile-chunk.vert';\n\n// One instance = one tile quad. Layout matches the engine's instanced-quad\n// convention (NineSlice/Repeating): float32x4 local rect, unorm16x4 UV bounds,\n// unorm8x4 tint, uint32 tile word (transform row + diagonal bit).\nconst instanceStrideBytes = 32;\nconst wordsPerInstance = instanceStrideBytes / Uint32Array.BYTES_PER_ELEMENT;\nconst transformTextureUnit = 1;\nconst identityGroupMat3 = new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);\n\nconst tileVertexSource = spliceGlslPrologue(\n fillShaderSource(tileVertexTemplate, { tileRowMask: TILE_ROW_MASK, tileDiagonalBit: TILE_DIAGONAL_BIT }),\n colorShaderSourcesGlsl,\n);\n\ninterface TileRendererConnection {\n readonly gl: WebGL2RenderingContext;\n readonly buffers: Map<WebGl2RenderBuffer, { handle: WebGLBuffer; dataByteLength: number }>;\n readonly vaoHandle: WebGLVertexArrayObject;\n}\n\n/**\n * Instanced WebGL2 renderer for {@link TileChunkNode}. Each tile is one\n * instanced quad; tiles are batched by `(shader, tileset texture)` and one\n * `drawArraysInstanced` is issued per batch. Per-chunk transforms ride on the\n * shared transform buffer (one row per chunk node), so the chunk geometry is\n * orientation-neutral and never re-uploaded for a camera pan.\n * @internal\n */\nexport class WebGl2TileChunkRenderer extends AbstractWebGl2Renderer<TileChunkNode> implements WebGl2RetainedBatchReplayer {\n /**\n * Retained-batch capability opt-in: a tile chunk's per-flush\n * instanced batches (fixed 32-byte layout, tile word at word 7) can be\n * recorded into a group's instruction set and replayed from group-owned\n * resources. Pixel-snapped draws are excluded by the collect-time\n * recordability predicate (and belt-and-braces poisoning in {@link render});\n * tile chunks have no custom-material path to exclude.\n * @internal\n */\n public readonly supportsRetainedBatches = true;\n\n private readonly _shader: WebGl2Shader;\n private readonly _batchSize: number;\n private readonly _instanceData: ArrayBuffer;\n private readonly _instanceFloat32: Float32Array;\n private readonly _instanceUint32: Uint32Array;\n\n private readonly _transformUnitScratch: Int32Array = new Int32Array([transformTextureUnit]);\n // Pinned unit index for the single tileset texture sampler (unit 0), reused\n // by the live flush and retained replay so both stay allocation-free.\n private readonly _baseTextureUnitScratch: Int32Array = new Int32Array([0]);\n // Reused single-slot texture list handed to the backend at record time; a\n // tile chunk batch always binds exactly one tileset texture (slot 0).\n private readonly _recordTextures: Array<Texture | RenderTexture | null> = [null];\n\n private _quadIndex = 0;\n private _maxNodeIndex = 0;\n // Chunk nodes booked against the PENDING batch, and whether the chunk being\n // rendered right now has already been booked. One chunk emits one tile\n // instance per tile, so the recorded batch's `submittedNodes` contribution is\n // this count and not `_quadIndex`. A chunk whose pages/runs span several\n // batches is booked once, against the batch its first run lands in.\n private _batchNodeCount = 0;\n private _nodeBooked = false;\n // Blend mode and tileset texture of the batch currently accumulating, used to\n // detect a batch break. Neither is a mirror of backend state: `flush()`\n // establishes both at the draw (see {@link _resetBatchState}).\n private _currentBlendMode: BlendModes | null = null;\n private _currentTexture: Texture | null = null;\n private _currentView: View | null = null;\n private _currentViewId = -1;\n private _hasWrittenGroup = false;\n private readonly _writtenGroupData = new Float32Array(9);\n\n private _instanceBuffer: WebGl2RenderBuffer | null = null;\n private _vao: WebGl2VertexArrayObject | null = null;\n private _connection: TileRendererConnection | null = null;\n\n public constructor(batchSize: number) {\n super();\n\n this._batchSize = batchSize;\n this._shader = new WebGl2Shader(tileVertexSource, tileFragmentSource);\n this._instanceData = new ArrayBuffer(batchSize * instanceStrideBytes);\n this._instanceFloat32 = new Float32Array(this._instanceData);\n this._instanceUint32 = new Uint32Array(this._instanceData);\n }\n\n public render(node: TileChunkNode): void {\n const pages = node.pages;\n\n this._nodeBooked = false;\n\n if (pages.length === 0) {\n return;\n }\n\n const backend = this.getBackend();\n\n const blendMode = node.blendMode;\n const tintRgba = node.tint.toRgba8();\n\n const command = backend.activeDrawCommand;\n const nodeIndex = command !== null ? command.nodeIndex : backend.pushTransform(node);\n\n for (const page of pages) {\n this._renderPage(page.texture, page.quads, blendMode, tintRgba, nodeIndex);\n }\n }\n\n private _renderPage(texture: Texture, quads: readonly TileQuad[], blendMode: BlendModes, tintRgba: number, nodeIndex: number): void {\n if (quads.length === 0) {\n return;\n }\n\n const textureChanged = this._currentTexture !== null && texture !== this._currentTexture;\n const blendModeChanged = this._currentBlendMode !== null && blendMode !== this._currentBlendMode;\n\n if (this._quadIndex > 0 && (blendModeChanged || textureChanged || this._quadIndex + quads.length > this._batchSize)) {\n this.flush();\n }\n\n this._currentBlendMode = blendMode;\n this._currentTexture = texture;\n\n const flipY = texture.flipY;\n\n // A chunk page may hold more tiles than the fixed batch buffer; write in\n // batch-sized runs, flushing (and re-establishing state) between runs.\n let offset = 0;\n\n while (offset < quads.length) {\n const remaining = quads.length - offset;\n const runSize = Math.min(remaining, this._batchSize);\n\n this._writeRun(quads, offset, runSize, flipY, tintRgba, nodeIndex);\n\n offset += runSize;\n\n if (offset < quads.length) {\n this.flush();\n this._currentBlendMode = blendMode;\n this._currentTexture = texture;\n }\n }\n }\n\n private _writeRun(quads: readonly TileQuad[], offset: number, count: number, flipY: boolean, tintRgba: number, nodeIndex: number): void {\n const f32 = this._instanceFloat32;\n const u32 = this._instanceUint32;\n const baseWord = nodeIndex & TILE_ROW_MASK;\n\n // Booked here rather than in render(): any flush the page/run loops trigger\n // has already happened, so the chunk lands on the batch that actually holds\n // its first tile.\n if (!this._nodeBooked) {\n this._nodeBooked = true;\n this._batchNodeCount++;\n }\n\n for (let i = 0; i < count; i++) {\n const q = quads[offset + i]!;\n const idx = this._quadIndex * wordsPerInstance;\n\n f32[idx + 0] = q.x0;\n f32[idx + 1] = q.y0;\n f32[idx + 2] = q.x1;\n f32[idx + 3] = q.y1;\n\n // Bake flipX/flipY into the UV corner ordering; the diagonal axis swap is\n // resolved in the shader. Texture flipY (uploaded-flipped atlases) is an\n // additional vertical swap that composes with the tile flipY.\n const flipX = (q.orient & 1) !== 0;\n const tileFlipY = (q.orient & 2) !== 0;\n const diagonal = (q.orient & 4) !== 0;\n\n const uA = flipX ? q.u1 : q.u0;\n const uB = flipX ? q.u0 : q.u1;\n let vA = tileFlipY ? q.v1 : q.v0;\n let vB = tileFlipY ? q.v0 : q.v1;\n\n if (flipY) {\n const swap = vA;\n vA = vB;\n vB = swap;\n }\n\n const uMin = (uA * 0xffff) & 0xffff;\n const vMin = (vA * 0xffff) & 0xffff;\n const uMax = (uB * 0xffff) & 0xffff;\n const vMax = (vB * 0xffff) & 0xffff;\n\n u32[idx + 4] = uMin | (vMin << 16);\n u32[idx + 5] = uMax | (vMax << 16);\n u32[idx + 6] = tintRgba;\n u32[idx + 7] = (diagonal ? baseWord | TILE_DIAGONAL_BIT : baseWord) >>> 0;\n\n this._quadIndex++;\n }\n\n if (nodeIndex > this._maxNodeIndex) {\n this._maxNodeIndex = nodeIndex;\n }\n }\n\n public flush(): void {\n const backend = this.getBackendOrNull();\n const instanceBuffer = this._instanceBuffer;\n const vao = this._vao;\n\n if (this._quadIndex === 0 || backend === null || instanceBuffer === null || vao === null) {\n this._resetBatchState();\n return;\n }\n\n this._stageViewUniforms(backend);\n\n // Blend state and texture unit 0 are global and shared with every other\n // renderer - a sprite drawn between two tile layers binds its own texture\n // to the same unit - so this batch establishes both at its own draw. The\n // backend collapses a redundant call.\n if (this._currentTexture !== null) {\n backend.bindTexture(this._currentTexture, 0);\n this._shader.getUniform('u_texture').setValue(this._baseTextureUnitScratch);\n }\n\n backend.bindTransformBufferTexture(transformTextureUnit, this._maxNodeIndex + 1);\n this._shader.getUniform('u_transforms').setValue(this._transformUnitScratch);\n\n this._shader.sync();\n backend.bindVertexArrayObject(vao);\n instanceBuffer.upload(this._instanceFloat32, 0, this._quadIndex * wordsPerInstance);\n backend.setBlendMode(this._currentBlendMode ?? BlendModes.Normal);\n vao.drawInstanced(4, 0, this._quadIndex, RenderingPrimitives.TriangleStrip);\n backend.stats.batches++;\n backend.stats.drawCalls++;\n\n // Retained recording: while a capture window is open, hand the\n // exact packed instance words of this flush to the backend - byte-\n // identical to what just drew. A batch always binds a single tileset\n // texture (slot 0); a pixel-snapped node already poisoned the capture in\n // render().\n if (backend._isRetainedCapturing && this._currentTexture !== null) {\n this._recordTextures[0] = this._currentTexture;\n backend.recordRetainedBatch(\n this,\n this._instanceUint32.subarray(0, this._quadIndex * wordsPerInstance),\n this._quadIndex,\n this._currentBlendMode ?? BlendModes.Normal,\n this._recordTextures,\n 1,\n null,\n null,\n this._batchNodeCount,\n );\n }\n\n this._resetBatchState();\n }\n\n /**\n * Scope the batch memos to one batch: they describe what is accumulating, not\n * what GL holds, so a memo that outlived its flush would let the next batch\n * skip establishing state another renderer has since changed.\n */\n private _resetBatchState(): void {\n this._quadIndex = 0;\n this._maxNodeIndex = 0;\n this._batchNodeCount = 0;\n this._currentBlendMode = null;\n this._currentTexture = null;\n }\n\n /**\n * Stage `u_projection` (live view) and `u_group` (live composed group\n * matrix) on the shader, guarded by cached view/group stamps. Shared by the\n * live flush path and retained-batch replay - replay resolves exactly the\n * same live state a slow-path flush would.\n */\n private _stageViewUniforms(backend: WebGl2Backend): void {\n const view = backend.view;\n\n if (this._currentView !== view || this._currentViewId !== view.updateId) {\n this._currentView = view;\n this._currentViewId = view.updateId;\n this._shader.getUniform('u_projection').setValue(view.getTransform().toArray(false));\n }\n\n const groupTransform = backend.renderGroupTransform;\n const groupData = groupTransform !== null ? groupTransform.toArray(false) : identityGroupMat3;\n\n if (!this._hasWrittenGroup || packedGroupChanged(groupData, this._writtenGroupData, 0)) {\n this._shader.getUniform('u_group').setValue(groupData);\n this._writtenGroupData.set(groupData);\n this._hasWrittenGroup = true;\n }\n\n backend.stageViewportUniform(this._shader);\n }\n\n // ── Retained-batch record/replay ──────────────────────────────────────────\n // The bundle stores raw instance bytes; this renderer owns the 32-byte\n // layout (tile word at word 7: transform row in bits 0..28, diagonal flip in\n // bit 29), so the layout-aware finalize steps (node-index scan/rebase, VAO\n // attribute wiring) and the replay dispatch live here - mirroring\n // WebGl2NineSliceSpriteRenderer's seam.\n\n /** @internal See {@link WebGl2RetainedBatchReplayer.scanRetainedNodeIndexRange}. */\n public scanRetainedNodeIndexRange(payload: WebGl2RetainedBatchPayload, range: WebGl2RetainedNodeIndexRange): void {\n const words = payload.bundle.instanceWords;\n const start = payload.byteOffset / Uint32Array.BYTES_PER_ELEMENT;\n\n for (let i = 0; i < payload.instanceCount; i++) {\n // In-bounds: the payload's word range was appended to the bundle store.\n // The tile word is the last word of the 32-byte (8-word) instance\n // layout; only the low 29 bits address the transform buffer row - the\n // diagonal-flip flag (bit 29) is orientation, not a row index.\n const row = words[start + i * wordsPerInstance + 7]! & TILE_ROW_MASK;\n\n if (row < range.min) {\n range.min = row;\n }\n\n if (row > range.max) {\n range.max = row;\n }\n }\n }\n\n /** @internal See {@link WebGl2RetainedBatchReplayer.rebaseRetainedNodeIndices} (group-local indices). */\n public rebaseRetainedNodeIndices(payload: WebGl2RetainedBatchPayload, base: number): void {\n const words = payload.bundle.instanceWords;\n const start = payload.byteOffset / Uint32Array.BYTES_PER_ELEMENT;\n\n for (let i = 0; i < payload.instanceCount; i++) {\n const index = start + i * wordsPerInstance + 7;\n // In-bounds: see the scan above. Rebase ONLY the row field; the\n // diagonal-flip bit must survive untouched or tile orientation corrupts.\n const word = words[index]!;\n const diagonal = word & TILE_DIAGONAL_BIT;\n const row = word & TILE_ROW_MASK;\n\n words[index] = (diagonal | ((row - base) & TILE_ROW_MASK)) >>> 0;\n }\n }\n\n /**\n * Point the batch VAO's per-instance attributes at the bundle's persistent\n * instance buffer, based at the batch's byte offset (WebGL2 has no\n * baseInstance, hence one small VAO per recorded batch). Same attribute\n * set/locations as the live VAO in {@link onConnect}.\n * @internal\n */\n public configureRetainedVao(payload: WebGl2RetainedBatchPayload): void {\n const gl = this.getBackend().context;\n const buffer = payload.bundle.instanceBuffer;\n const vao = payload.vao;\n\n if (buffer === null || vao === null) {\n throw new Error('WebGl2TileChunkRenderer: retained batch VAO configuration requires an uploaded bundle.');\n }\n\n const base = payload.byteOffset;\n\n vao\n .addAttribute(buffer, this._shader.getAttribute('a_quadBounds'), gl.FLOAT, false, instanceStrideBytes, base + 0, false, 1)\n .addAttribute(buffer, this._shader.getAttribute('a_uvBounds'), gl.UNSIGNED_SHORT, true, instanceStrideBytes, base + 16, false, 1)\n .addAttribute(buffer, this._shader.getAttribute('a_color'), gl.UNSIGNED_BYTE, true, instanceStrideBytes, base + 24, false, 1)\n .addAttribute(buffer, this._shader.getAttribute('a_tileWord'), gl.UNSIGNED_INT, false, instanceStrideBytes, base + 28, true, 1);\n }\n\n /**\n * Replay one recorded batch: all STATE is resolved live - blend mode via\n * the backend's dedup, `u_projection`/`u_group` from the live view + live\n * composed group matrix (the camera-pan / group-move win), the single\n * tileset texture bound to unit 0 by recorded slot order - and only the\n * DATA is cached: the instance bytes in the bundle buffer (bound through\n * the per-batch VAO) and the group-owned transform texture on the shared\n * transform unit. The backend hook flushed any pending live batch before\n * dispatching here and bumps the stats from the instruction descriptor.\n * @internal\n */\n public replayRetainedBatch(payload: WebGl2RetainedBatchPayload): boolean {\n const backend = this.getBackendOrNull();\n const vao = payload.vao;\n const transformTexture = payload.bundle.transformTexture;\n\n if (backend === null || vao === null || transformTexture === null) {\n // Defensive: a bundle in this state never validates (generation), so a\n // spliced replay cannot reach here; skip rather than crash mid-frame.\n return false;\n }\n\n backend.setBlendMode(payload.blendMode);\n this._stageViewUniforms(backend);\n\n const textures = payload.textures;\n\n for (let i = 0; i < textures.length; i++) {\n // In-bounds: i < textures.length.\n backend.bindTexture(textures[i]!, i);\n }\n\n this._shader.getUniform('u_texture').setValue(this._baseTextureUnitScratch);\n\n // The group-owned transform store replaces the shared frame buffer on the\n // SAME unit/sampler - zero GLSL changes. The next live flush re-binds the\n // shared texture through bindTransformBufferTexture.\n backend.bindTexture(transformTexture, transformTextureUnit);\n this._shader.getUniform('u_transforms').setValue(this._transformUnitScratch);\n\n this._shader.sync();\n backend.bindVertexArrayObject(vao);\n vao.drawInstanced(4, 0, payload.instanceCount, RenderingPrimitives.TriangleStrip);\n\n return true;\n }\n\n protected onConnect(backend: WebGl2Backend): void {\n const gl = backend.context;\n\n this._shader.connect(createWebGl2ShaderProgram(gl));\n this._connection = this._createConnection(gl);\n this._instanceBuffer = new WebGl2RenderBuffer(BufferTypes.ArrayBuffer, this._instanceData, BufferUsage.DynamicDraw).connect(\n this._createBufferRuntime(this._connection),\n );\n this._shader.sync();\n\n this._vao = new WebGl2VertexArrayObject(RenderingPrimitives.TriangleStrip)\n .addAttribute(this._instanceBuffer, this._shader.getAttribute('a_quadBounds'), gl.FLOAT, false, instanceStrideBytes, 0, false, 1)\n .addAttribute(this._instanceBuffer, this._shader.getAttribute('a_uvBounds'), gl.UNSIGNED_SHORT, true, instanceStrideBytes, 16, false, 1)\n .addAttribute(this._instanceBuffer, this._shader.getAttribute('a_color'), gl.UNSIGNED_BYTE, true, instanceStrideBytes, 24, false, 1)\n .addAttribute(this._instanceBuffer, this._shader.getAttribute('a_tileWord'), gl.UNSIGNED_INT, false, instanceStrideBytes, 28, true, 1)\n .connect(this._createVaoRuntime(this._connection));\n }\n\n protected onDisconnect(): void {\n this._shader.destroy();\n this._instanceBuffer?.destroy();\n this._instanceBuffer = null;\n this._vao?.destroy();\n this._vao = null;\n this._connection = null;\n this._currentBlendMode = null;\n this._currentTexture = null;\n this._currentView = null;\n this._currentViewId = -1;\n this._hasWrittenGroup = false;\n this._quadIndex = 0;\n this._maxNodeIndex = 0;\n this._batchNodeCount = 0;\n this._nodeBooked = false;\n }\n\n public destroy(): void {\n this.disconnect();\n this._shader.destroy();\n }\n\n private _createConnection(gl: WebGL2RenderingContext): TileRendererConnection {\n const vaoHandle = gl.createVertexArray();\n\n if (vaoHandle === null) {\n throw new Error('WebGl2TileChunkRenderer: could not create vertex array object.');\n }\n\n return { gl, buffers: new Map(), vaoHandle };\n }\n\n private _createBufferRuntime(connection: TileRendererConnection): WebGl2RenderBufferRuntime {\n const handle = connection.gl.createBuffer();\n\n if (handle === null) {\n throw new Error('WebGl2TileChunkRenderer: could not create render buffer.');\n }\n\n return {\n bind: (buffer): void => {\n connection.gl.bindBuffer(buffer.type, handle);\n },\n upload: (buffer, offset): void => {\n const gl = connection.gl;\n const state = connection.buffers.get(buffer);\n\n gl.bindBuffer(buffer.type, handle);\n\n if (state && state.dataByteLength >= buffer.uploadByteLength) {\n uploadBufferRange(gl, buffer, offset);\n state.dataByteLength = buffer.uploadByteLength;\n } else {\n uploadBufferStore(gl, buffer);\n connection.buffers.set(buffer, { handle, dataByteLength: buffer.uploadByteLength });\n }\n },\n destroy: (buffer): void => {\n connection.gl.deleteBuffer(handle);\n connection.buffers.delete(buffer);\n buffer.disconnect();\n },\n };\n }\n\n private _createVaoRuntime(connection: TileRendererConnection): WebGl2VertexArrayObjectRuntime {\n let appliedVersion = -1;\n\n return {\n bind: (vao): void => {\n const gl = connection.gl;\n\n gl.bindVertexArray(connection.vaoHandle);\n\n if (appliedVersion !== vao.version) {\n let lastBuffer: WebGl2RenderBuffer | null = null;\n\n for (const attribute of vao.attributes) {\n if (lastBuffer !== attribute.buffer) {\n attribute.buffer.bind();\n lastBuffer = attribute.buffer;\n }\n\n if (attribute.integer) {\n gl.vertexAttribIPointer(attribute.location, attribute.size, attribute.type, attribute.stride, attribute.start);\n } else {\n gl.vertexAttribPointer(attribute.location, attribute.size, attribute.type, attribute.normalized, attribute.stride, attribute.start);\n }\n\n gl.enableVertexAttribArray(attribute.location);\n gl.vertexAttribDivisor(attribute.location, attribute.divisor);\n }\n\n appliedVersion = vao.version;\n }\n },\n unbind: (): void => {\n connection.gl.bindVertexArray(null);\n },\n draw: (_vao, size, start, type): void => {\n connection.gl.drawArrays(type, start, size);\n },\n drawInstanced: (_vao, count, start, instanceCount, type): void => {\n connection.gl.drawArraysInstanced(type, start, count, instanceCount);\n },\n destroy: (vao): void => {\n connection.gl.deleteVertexArray(connection.vaoHandle);\n vao.disconnect();\n },\n };\n }\n}\n"],"mappings":";;;;;;AAsCA,MAAM,sBAAsB;AAC5B,MAAM,mBAAmB,sBAAsB,YAAY;AAC3D,MAAM,uBAAuB;AAC7B,MAAM,oBAAoB,IAAI,aAAa;CAAC;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;CAAG;AAAC,CAAC;AAEtE,MAAM,mBAAmB,mBACvB,iBAAiBA,sBAAoB;CAAE,aAAa;CAAe,iBAAiB;AAAkB,CAAC,GACvG,sBACF;;;;;;;;;AAgBA,IAAa,0BAAb,cAA6C,uBAA6E;;;;;;;;;;CAUxH,AAAgB,0BAA0B;CAE1C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAiB,wBAAoC,IAAI,WAAW,CAAC,oBAAoB,CAAC;CAG1F,AAAiB,0BAAsC,IAAI,WAAW,CAAC,CAAC,CAAC;CAGzE,AAAiB,kBAAyD,CAAC,IAAI;CAE/E,AAAQ,aAAa;CACrB,AAAQ,gBAAgB;CAMxB,AAAQ,kBAAkB;CAC1B,AAAQ,cAAc;CAItB,AAAQ,oBAAuC;CAC/C,AAAQ,kBAAkC;CAC1C,AAAQ,eAA4B;CACpC,AAAQ,iBAAiB;CACzB,AAAQ,mBAAmB;CAC3B,AAAiB,oCAAoB,IAAI,aAAa,CAAC;CAEvD,AAAQ,kBAA6C;CACrD,AAAQ,OAAuC;CAC/C,AAAQ,cAA6C;CAErD,AAAO,YAAY,WAAmB;EACpC,MAAM;EAEN,KAAK,aAAa;EAClB,KAAK,UAAU,IAAI,aAAa,kBAAkBC,kBAAkB;EACpE,KAAK,gCAAgB,IAAI,YAAY,YAAY,mBAAmB;EACpE,KAAK,mBAAmB,IAAI,aAAa,KAAK,aAAa;EAC3D,KAAK,kBAAkB,IAAI,YAAY,KAA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ACA,OAAO,MAAM,MAAM,OAAO,SAAe;IACvC,WAAW,GAAG,WAAW,MAAM,OAAO,IAAI;GAC5C;GACA,gBAAgB,MAAM,OAAO,OAAO,eAAe,SAAe;IAChE,WAAW,GAAG,oBAAoB,MAAM,OAAO,OAAO,aAAa;GACrE;GACA,UAAU,QAAc;IACtB,WAAW,GAAG,kBAAkB,WAAW,SAAS;IACpD,IAAI,WAAW;GACjB;EACF;CACF;AACF"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/webgl2/shaders/tile-chunk.frag
|
|
2
|
-
var tile_chunk_default = "#version 300 es\nprecision highp float;\nuniform sampler2D u_texture;\nin vec2 v_texcoord;\nin vec4 v_color;\nlayout(location = 0) out vec4 fragColor;\nvoid main(void) {\nvec4 sampleColor = texture(u_texture, v_texcoord);\nfragColor = sampleColor * v_color;\n}";
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
export { tile_chunk_default as default };
|
|
6
|
-
//# sourceMappingURL=tile-chunk.frag.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tile-chunk.frag.js","names":[],"sources":["../../../../src/webgl2/shaders/tile-chunk.frag"],"sourcesContent":["export default \"#version 300 es\\nprecision highp float;\\nuniform sampler2D u_texture;\\nin vec2 v_texcoord;\\nin vec4 v_color;\\nlayout(location = 0) out vec4 fragColor;\\nvoid main(void) {\\nvec4 sampleColor = texture(u_texture, v_texcoord);\\nfragColor = sampleColor * v_color;\\n}\";"],"mappings":";AAAA,yBAAe"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/webgl2/shaders/tile-chunk.vert
|
|
2
|
-
var tile_chunk_default = "#version 300 es\nprecision highp float;\nprecision highp int;\nlayout(location = 0) in vec4 a_quadBounds;\nlayout(location = 1) in vec4 a_uvBounds;\nlayout(location = 2) in vec4 a_color;\nlayout(location = 3) in uint a_tileWord;\nuniform mat3 u_projection;\nuniform mat3 u_group;\nuniform vec4 u_viewport;\nuniform sampler2D u_transforms;\n// #exo-include transform-texture\nout vec2 v_texcoord;\nout vec4 v_color;\nvoid main(void) {\nint vid = gl_VertexID;\nint cornerX = vid & 1;\nint cornerY = (vid >> 1) & 1;\nfloat localX = (cornerX == 0) ? a_quadBounds.x : a_quadBounds.z;\nfloat localY = (cornerY == 0) ? a_quadBounds.y : a_quadBounds.w;\nint row = int(a_tileWord & {{tileRowMask}}u);\nbool diagonal = (a_tileWord & {{tileDiagonalBit}}u) != 0u;\nvec4 m0 = texelFetch(u_transforms, exoTransformTexel(row, 0), 0);\nvec4 m1 = texelFetch(u_transforms, exoTransformTexel(row, 1), 0);\nfloat worldX = (m0.x * localX) + (m0.y * localY) + m1.x;\nfloat worldY = (m0.z * localX) + (m0.w * localY) + m1.y;\nvec2 clip = (u_projection * u_group * vec3(worldX, worldY, 1.0)).xy;\nif (m1.z != 0.0) {\nvec2 originClip = (u_projection * u_group * vec3(m1.x, m1.y, 1.0)).xy;\nvec2 originDevice = u_viewport.xy + (originClip * 0.5 + 0.5) * u_viewport.zw;\nclip += (floor(originDevice + 0.5) - originDevice) * 2.0 / max(u_viewport.zw, vec2(1.0));\n}\ngl_Position = vec4(clip, 0.0, 1.0);\nint su = cornerX;\nint sv = cornerY;\nif (diagonal) { int t = su; su = sv; sv = t; }\nfloat u = (su == 0) ? a_uvBounds.x : a_uvBounds.z;\nfloat v = (sv == 0) ? a_uvBounds.y : a_uvBounds.w;\nv_texcoord = vec2(u, v);\nhighp vec3 linearTint = srgbToLinear(a_color.rgb);\nv_color = vec4(linearTint * a_color.a, a_color.a);\n}";
|
|
3
|
-
|
|
4
|
-
//#endregion
|
|
5
|
-
export { tile_chunk_default as default };
|
|
6
|
-
//# sourceMappingURL=tile-chunk.vert.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tile-chunk.vert.js","names":[],"sources":["../../../../src/webgl2/shaders/tile-chunk.vert"],"sourcesContent":["export default \"#version 300 es\\nprecision highp float;\\nprecision highp int;\\nlayout(location = 0) in vec4 a_quadBounds;\\nlayout(location = 1) in vec4 a_uvBounds;\\nlayout(location = 2) in vec4 a_color;\\nlayout(location = 3) in uint a_tileWord;\\nuniform mat3 u_projection;\\nuniform mat3 u_group;\\nuniform vec4 u_viewport;\\nuniform sampler2D u_transforms;\\n// #exo-include transform-texture\\nout vec2 v_texcoord;\\nout vec4 v_color;\\nvoid main(void) {\\nint vid = gl_VertexID;\\nint cornerX = vid & 1;\\nint cornerY = (vid >> 1) & 1;\\nfloat localX = (cornerX == 0) ? a_quadBounds.x : a_quadBounds.z;\\nfloat localY = (cornerY == 0) ? a_quadBounds.y : a_quadBounds.w;\\nint row = int(a_tileWord & {{tileRowMask}}u);\\nbool diagonal = (a_tileWord & {{tileDiagonalBit}}u) != 0u;\\nvec4 m0 = texelFetch(u_transforms, exoTransformTexel(row, 0), 0);\\nvec4 m1 = texelFetch(u_transforms, exoTransformTexel(row, 1), 0);\\nfloat worldX = (m0.x * localX) + (m0.y * localY) + m1.x;\\nfloat worldY = (m0.z * localX) + (m0.w * localY) + m1.y;\\nvec2 clip = (u_projection * u_group * vec3(worldX, worldY, 1.0)).xy;\\nif (m1.z != 0.0) {\\nvec2 originClip = (u_projection * u_group * vec3(m1.x, m1.y, 1.0)).xy;\\nvec2 originDevice = u_viewport.xy + (originClip * 0.5 + 0.5) * u_viewport.zw;\\nclip += (floor(originDevice + 0.5) - originDevice) * 2.0 / max(u_viewport.zw, vec2(1.0));\\n}\\ngl_Position = vec4(clip, 0.0, 1.0);\\nint su = cornerX;\\nint sv = cornerY;\\nif (diagonal) { int t = su; su = sv; sv = t; }\\nfloat u = (su == 0) ? a_uvBounds.x : a_uvBounds.z;\\nfloat v = (sv == 0) ? a_uvBounds.y : a_uvBounds.w;\\nv_texcoord = vec2(u, v);\\nhighp vec3 linearTint = srgbToLinear(a_color.rgb);\\nv_color = vec4(linearTint * a_color.a, a_color.a);\\n}\";"],"mappings":";AAAA,yBAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WebGpuTileChunkRenderer.d.ts","sourceRoot":"","sources":["../../../src/webgpu/WebGpuTileChunkRenderer.ts"],"names":[],"mappings":""}
|