@next2d/webgl 3.11.1 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/Blend/usecase/BlnedDrawDisplayObjectUseCase.d.ts +2 -1
- package/src/Blend/usecase/BlnedDrawDisplayObjectUseCase.js +8 -7
- package/src/Context/service/ContextGetRenderCompletionService.d.ts +2 -0
- package/src/Context/service/ContextGetRenderCompletionService.js +55 -0
- package/src/Context.d.ts +6 -1
- package/src/Context.js +59 -4
- package/src/FrameBufferManager/service/FrameBufferManagerTransferAtlasTextureService.js +1 -1
- package/src/Shader/Variants/Blend/service/VariantsBlendTextBatchShaderService.d.ts +2 -0
- package/src/Shader/Variants/Blend/service/VariantsBlendTextBatchShaderService.js +17 -0
- package/src/TextUploadBatch.d.ts +5 -0
- package/src/TextUploadBatch.js +167 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "Next2D Webgl Package",
|
|
5
5
|
"author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"url": "git+https://github.com/Next2D/Player.git"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@next2d/texture-packer": "3.
|
|
28
|
-
"@next2d/render-queue": "3.
|
|
27
|
+
"@next2d/texture-packer": "3.12.1",
|
|
28
|
+
"@next2d/render-queue": "3.12.1"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -9,8 +9,9 @@ import type { Node } from "@next2d/texture-packer";
|
|
|
9
9
|
* @param {number} x_max
|
|
10
10
|
* @param {number} y_max
|
|
11
11
|
* @param {Float32Array} color_transform
|
|
12
|
+
* @param {number} color_transform_offset - 要素単位の開始位置 / Start offset in elements
|
|
12
13
|
* @return {void}
|
|
13
14
|
* @method
|
|
14
15
|
* @protected
|
|
15
16
|
*/
|
|
16
|
-
export declare const execute: (node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array) => void;
|
|
17
|
+
export declare const execute: (node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array, color_transform_offset?: number) => void;
|
|
@@ -28,18 +28,19 @@ import { renderQueue } from "@next2d/render-queue";
|
|
|
28
28
|
* @param {number} x_max
|
|
29
29
|
* @param {number} y_max
|
|
30
30
|
* @param {Float32Array} color_transform
|
|
31
|
+
* @param {number} color_transform_offset - 要素単位の開始位置 / Start offset in elements
|
|
31
32
|
* @return {void}
|
|
32
33
|
* @method
|
|
33
34
|
* @protected
|
|
34
35
|
*/
|
|
35
|
-
export const execute = (node, x_min, y_min, x_max, y_max, color_transform) => {
|
|
36
|
-
const ct0 = color_transform[
|
|
37
|
-
const ct1 = color_transform[1];
|
|
38
|
-
const ct2 = color_transform[2];
|
|
36
|
+
export const execute = (node, x_min, y_min, x_max, y_max, color_transform, color_transform_offset = 0) => {
|
|
37
|
+
const ct0 = color_transform[color_transform_offset];
|
|
38
|
+
const ct1 = color_transform[color_transform_offset + 1];
|
|
39
|
+
const ct2 = color_transform[color_transform_offset + 2];
|
|
39
40
|
const ct3 = $context.globalAlpha;
|
|
40
|
-
const ct4 = color_transform[4] / 255;
|
|
41
|
-
const ct5 = color_transform[5] / 255;
|
|
42
|
-
const ct6 = color_transform[6] / 255;
|
|
41
|
+
const ct4 = color_transform[color_transform_offset + 4] / 255;
|
|
42
|
+
const ct5 = color_transform[color_transform_offset + 5] / 255;
|
|
43
|
+
const ct6 = color_transform[color_transform_offset + 6] / 255;
|
|
43
44
|
const matrix = $context.$matrix;
|
|
44
45
|
switch ($context.globalCompositeOperation) {
|
|
45
46
|
case "normal":
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { $gl } from "../../WebGLUtil";
|
|
2
|
+
const $queues = new WeakMap();
|
|
3
|
+
/** Observe preceding GL commands after yielding to the worker event loop. */
|
|
4
|
+
export const execute = () => {
|
|
5
|
+
const gl = $gl;
|
|
6
|
+
const sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
7
|
+
if (!sync) {
|
|
8
|
+
return Promise.reject(new Error("Unable to create render fence"));
|
|
9
|
+
}
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
gl.flush();
|
|
12
|
+
let queue = $queues.get(gl);
|
|
13
|
+
if (!queue) {
|
|
14
|
+
const entries = [];
|
|
15
|
+
const poll = () => {
|
|
16
|
+
// Work added during this task must wait for a later task.
|
|
17
|
+
let remaining = entries.length;
|
|
18
|
+
while (remaining-- && entries.length) {
|
|
19
|
+
const entry = entries[0];
|
|
20
|
+
let status;
|
|
21
|
+
try {
|
|
22
|
+
status = gl.clientWaitSync(entry.sync, 0, 0);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
entries.shift();
|
|
26
|
+
entry.reject(error);
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (status === gl.TIMEOUT_EXPIRED) {
|
|
30
|
+
setTimeout(poll, 4);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
entries.shift();
|
|
34
|
+
if (status === gl.ALREADY_SIGNALED || status === gl.CONDITION_SATISFIED) {
|
|
35
|
+
entry.resolve();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
entry.reject(new Error("Render fence wait failed"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (entries.length) {
|
|
42
|
+
setTimeout(poll, 4);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
queue = { entries, poll };
|
|
46
|
+
$queues.set(gl, queue);
|
|
47
|
+
}
|
|
48
|
+
queue.entries.push({ sync, resolve, reject });
|
|
49
|
+
if (queue.entries.length === 1) {
|
|
50
|
+
setTimeout(queue.poll, 4);
|
|
51
|
+
}
|
|
52
|
+
}).finally(() => {
|
|
53
|
+
gl.deleteSync(sync);
|
|
54
|
+
});
|
|
55
|
+
};
|
package/src/Context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { IBlendMode } from "./interface/IBlendMode";
|
|
|
3
3
|
import type { IBounds } from "./interface/IBounds";
|
|
4
4
|
import type { Node } from "@next2d/texture-packer";
|
|
5
5
|
export declare class Context {
|
|
6
|
+
private readonly _nodeRoots;
|
|
6
7
|
readonly $stack: Float32Array[];
|
|
7
8
|
readonly $matrix: Float32Array;
|
|
8
9
|
$clearColorR: number;
|
|
@@ -30,6 +31,7 @@ export declare class Context {
|
|
|
30
31
|
resize(width: number, height: number, cache_clear?: boolean): void;
|
|
31
32
|
clearRect(x: number, y: number, w: number, h: number): void;
|
|
32
33
|
bind(attachment_object: IAttachmentObject): void;
|
|
34
|
+
queueTextElement(node: Node, canvas: OffscreenCanvas): boolean;
|
|
33
35
|
save(): void;
|
|
34
36
|
restore(): void;
|
|
35
37
|
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
@@ -54,6 +56,8 @@ export declare class Context {
|
|
|
54
56
|
get currentAttachmentObject(): IAttachmentObject | null;
|
|
55
57
|
get atlasAttachmentObject(): IAttachmentObject;
|
|
56
58
|
createNode(width: number, height: number): Node;
|
|
59
|
+
/** Select the page of a live cached node without reallocating its rectangle. */
|
|
60
|
+
reuseNode(node: Node): boolean;
|
|
57
61
|
removeNode(node: Node): void;
|
|
58
62
|
/**
|
|
59
63
|
* @description CacheStore に格納された任意の値を解放する。
|
|
@@ -71,7 +75,7 @@ export declare class Context {
|
|
|
71
75
|
beginNodeRendering(node: Node): void;
|
|
72
76
|
endNodeRendering(): void;
|
|
73
77
|
drawFill(): void;
|
|
74
|
-
drawDisplayObject(node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array): void;
|
|
78
|
+
drawDisplayObject(node: Node, x_min: number, y_min: number, x_max: number, y_max: number, color_transform: Float32Array, color_transform_offset?: number): void;
|
|
75
79
|
drawArraysInstanced(): void;
|
|
76
80
|
clearArraysInstanced(): void;
|
|
77
81
|
transferMainCanvas(): void;
|
|
@@ -89,4 +93,5 @@ export declare class Context {
|
|
|
89
93
|
containerEndAtlasNode(): void;
|
|
90
94
|
containerDrawCachedFilter(blend_mode: IBlendMode, matrix: Float32Array, color_transform: Float32Array, filter_bounds: Float32Array, unique_key: string, filter_key: string): void;
|
|
91
95
|
createImageBitmap(width: number, height: number): Promise<ImageBitmap>;
|
|
96
|
+
getRenderCompletion(): Promise<void>;
|
|
92
97
|
}
|
package/src/Context.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { queueTextUpload, flushTextUploads, flushTextUploadsForNode, disposeTextUploads } from "./TextUploadBatch";
|
|
2
|
+
import { execute as contextGetRenderCompletionService } from "./Context/service/ContextGetRenderCompletionService";
|
|
1
3
|
import { execute as beginPath } from "./PathCommand/service/PathCommandBeginPathService";
|
|
2
4
|
import { execute as moveTo } from "./PathCommand/usecase/PathCommandMoveToUseCase";
|
|
3
5
|
import { execute as lineTo } from "./PathCommand/usecase/PathCommandLineToUseCase";
|
|
@@ -50,11 +52,17 @@ import { execute as contextUpdateTransferBoundsService } from "./Context/service
|
|
|
50
52
|
import { execute as contextDrawFillUseCase } from "./Context/usecase/ContextDrawFillUseCase";
|
|
51
53
|
import { execute as contextCreateImageBitmapService } from "./Context/service/ContextCreateImageBitmapService";
|
|
52
54
|
import { $setGradientLUTGeneratorMaxLength } from "./Shader/GradientLUTGenerator";
|
|
53
|
-
import { $getAtlasAttachmentObject, $clearTransferBounds, $getAtlasTextureObject, $setAtlasPageDirty } from "./AtlasManager";
|
|
55
|
+
import { $getAtlasAttachmentObject, $clearTransferBounds, $getAtlasTextureObject, $setAtlasPageDirty, $rootNodes, $setActiveAtlasIndex } from "./AtlasManager";
|
|
54
56
|
import { $setReadFrameBuffer, $setDrawFrameBuffer, $currentAttachment, $setAtlasFrameBuffer, $setBitmapFrameBuffer } from "./FrameBufferManager";
|
|
55
57
|
import { $setRenderMaxSize, $setWebGL2RenderingContext, $setSamples, $getFloat32Array9, $getArray, $setContext, $setDevicePixelRatio } from "./WebGLUtil";
|
|
56
58
|
export class Context {
|
|
57
59
|
constructor(gl, samples, device_pixel_ratio = 1) {
|
|
60
|
+
Object.defineProperty(this, "_nodeRoots", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: new WeakMap()
|
|
65
|
+
});
|
|
58
66
|
Object.defineProperty(this, "$stack", {
|
|
59
67
|
enumerable: true,
|
|
60
68
|
configurable: true,
|
|
@@ -175,6 +183,7 @@ export class Context {
|
|
|
175
183
|
writable: true,
|
|
176
184
|
value: []
|
|
177
185
|
});
|
|
186
|
+
disposeTextUploads();
|
|
178
187
|
$setWebGL2RenderingContext(gl);
|
|
179
188
|
$setRenderMaxSize(gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
|
180
189
|
$setSamples(samples);
|
|
@@ -236,17 +245,24 @@ export class Context {
|
|
|
236
245
|
contextUpdateBackgroundColorService(this, red, green, blue, alpha);
|
|
237
246
|
}
|
|
238
247
|
fillBackgroundColor() {
|
|
248
|
+
flushTextUploads();
|
|
239
249
|
contextFillBackgroundColorService(this.$clearColorR, this.$clearColorG, this.$clearColorB, this.$clearColorA);
|
|
240
250
|
}
|
|
241
251
|
resize(width, height, cache_clear = true) {
|
|
252
|
+
disposeTextUploads();
|
|
242
253
|
contextResizeUseCase(this, width, height, cache_clear);
|
|
243
254
|
}
|
|
244
255
|
clearRect(x, y, w, h) {
|
|
256
|
+
flushTextUploads();
|
|
245
257
|
contextClearRectUseCase(x, y, w, h);
|
|
246
258
|
}
|
|
247
259
|
bind(attachment_object) {
|
|
260
|
+
flushTextUploads();
|
|
248
261
|
contextBindUseCase(this, attachment_object);
|
|
249
262
|
}
|
|
263
|
+
queueTextElement(node, canvas) {
|
|
264
|
+
return queueTextUpload(node, canvas);
|
|
265
|
+
}
|
|
250
266
|
save() {
|
|
251
267
|
contextSaveService(this);
|
|
252
268
|
}
|
|
@@ -260,6 +276,7 @@ export class Context {
|
|
|
260
276
|
contextTransformService(this, a, b, c, d, e, f);
|
|
261
277
|
}
|
|
262
278
|
reset() {
|
|
279
|
+
flushTextUploads();
|
|
263
280
|
contextResetService(this);
|
|
264
281
|
}
|
|
265
282
|
beginPath() {
|
|
@@ -299,24 +316,31 @@ export class Context {
|
|
|
299
316
|
bezierCurveTo(cx1, cy1, cx2, cy2, x, y);
|
|
300
317
|
}
|
|
301
318
|
fill() {
|
|
319
|
+
flushTextUploads();
|
|
302
320
|
contextFillUseCase("fill");
|
|
303
321
|
}
|
|
304
322
|
gradientFill(type, stops, matrix, spread, interpolation, focal) {
|
|
323
|
+
flushTextUploads();
|
|
305
324
|
contextGradientFillUseCase(type, stops, matrix, spread, interpolation, focal);
|
|
306
325
|
}
|
|
307
326
|
bitmapFill(pixels, matrix, width, height, repeat, smooth) {
|
|
327
|
+
flushTextUploads();
|
|
308
328
|
contextBitmapFillUseCase(pixels, matrix, width, height, repeat, smooth);
|
|
309
329
|
}
|
|
310
330
|
stroke() {
|
|
331
|
+
flushTextUploads();
|
|
311
332
|
contextStrokeUseCase();
|
|
312
333
|
}
|
|
313
334
|
gradientStroke(type, stops, matrix, spread, interpolation, focal) {
|
|
335
|
+
flushTextUploads();
|
|
314
336
|
contextGradientStrokeUseCase(type, stops, matrix, spread, interpolation, focal);
|
|
315
337
|
}
|
|
316
338
|
bitmapStroke(pixels, matrix, width, height, repeat, smooth) {
|
|
339
|
+
flushTextUploads();
|
|
317
340
|
contextBitmapStrokeUseCase(pixels, matrix, width, height, repeat, smooth);
|
|
318
341
|
}
|
|
319
342
|
clip() {
|
|
343
|
+
flushTextUploads();
|
|
320
344
|
contextClipUseCase();
|
|
321
345
|
}
|
|
322
346
|
get currentAttachmentObject() {
|
|
@@ -326,10 +350,24 @@ export class Context {
|
|
|
326
350
|
return $getAtlasAttachmentObject();
|
|
327
351
|
}
|
|
328
352
|
createNode(width, height) {
|
|
329
|
-
|
|
353
|
+
const node = atlasManagerCreateNodeService(width, height);
|
|
354
|
+
this._nodeRoots.set(node, $rootNodes[node.index]);
|
|
355
|
+
return node;
|
|
356
|
+
}
|
|
357
|
+
/** Select the page of a live cached node without reallocating its rectangle. */
|
|
358
|
+
reuseNode(node) {
|
|
359
|
+
const root = this._nodeRoots.get(node);
|
|
360
|
+
if (!root || root !== $rootNodes[node.index] || !node.used) {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
flushTextUploadsForNode(node);
|
|
364
|
+
$setActiveAtlasIndex(node.index);
|
|
365
|
+
return true;
|
|
330
366
|
}
|
|
331
367
|
removeNode(node) {
|
|
368
|
+
flushTextUploadsForNode(node);
|
|
332
369
|
atlasManagerRemoveNodeService(node);
|
|
370
|
+
this._nodeRoots.delete(node);
|
|
333
371
|
}
|
|
334
372
|
/**
|
|
335
373
|
* @description CacheStore に格納された任意の値を解放する。
|
|
@@ -348,13 +386,16 @@ export class Context {
|
|
|
348
386
|
return;
|
|
349
387
|
}
|
|
350
388
|
if ("w" in value) {
|
|
389
|
+
flushTextUploadsForNode(value);
|
|
351
390
|
atlasManagerRemoveNodeService(value);
|
|
391
|
+
this._nodeRoots.delete(value);
|
|
352
392
|
}
|
|
353
393
|
else if ("resource" in value) {
|
|
354
394
|
textureManagerReleaseTextureObjectUseCase(value);
|
|
355
395
|
}
|
|
356
396
|
}
|
|
357
397
|
beginNodeRendering(node) {
|
|
398
|
+
flushTextUploads();
|
|
358
399
|
this.newDrawState = true;
|
|
359
400
|
// このページには未解決の描き込みがある(次回の解決対象)
|
|
360
401
|
$setAtlasPageDirty(node.index);
|
|
@@ -362,37 +403,46 @@ export class Context {
|
|
|
362
403
|
contextBeginNodeRenderingService(node.x, node.y, node.w, node.h);
|
|
363
404
|
}
|
|
364
405
|
endNodeRendering() {
|
|
406
|
+
flushTextUploads();
|
|
365
407
|
contextEndNodeRenderingService();
|
|
366
408
|
}
|
|
367
409
|
drawFill() {
|
|
410
|
+
flushTextUploads();
|
|
368
411
|
contextDrawFillUseCase();
|
|
369
412
|
}
|
|
370
|
-
drawDisplayObject(node, x_min, y_min, x_max, y_max, color_transform) {
|
|
413
|
+
drawDisplayObject(node, x_min, y_min, x_max, y_max, color_transform, color_transform_offset = 0) {
|
|
371
414
|
contextUpdateTransferBoundsService(node);
|
|
372
|
-
blnedDrawDisplayObjectUseCase(node, x_min, y_min, x_max, y_max, color_transform);
|
|
415
|
+
blnedDrawDisplayObjectUseCase(node, x_min, y_min, x_max, y_max, color_transform, color_transform_offset);
|
|
373
416
|
}
|
|
374
417
|
drawArraysInstanced() {
|
|
418
|
+
flushTextUploads();
|
|
375
419
|
blnedDrawArraysInstancedUseCase();
|
|
376
420
|
}
|
|
377
421
|
clearArraysInstanced() {
|
|
378
422
|
blnedClearArraysInstancedUseCase();
|
|
379
423
|
}
|
|
380
424
|
transferMainCanvas() {
|
|
425
|
+
flushTextUploads();
|
|
381
426
|
frameBufferManagerTransferMainCanvasService();
|
|
382
427
|
}
|
|
383
428
|
drawPixels(node, pixels) {
|
|
429
|
+
flushTextUploads();
|
|
384
430
|
contextDrawPixelsUseCase(node, pixels);
|
|
385
431
|
}
|
|
386
432
|
drawElement(node, element, _flipY = false) {
|
|
433
|
+
flushTextUploads();
|
|
387
434
|
contextDrawElementUseCase(node, element);
|
|
388
435
|
}
|
|
389
436
|
beginMask() {
|
|
437
|
+
flushTextUploads();
|
|
390
438
|
maskBeginMaskService();
|
|
391
439
|
}
|
|
392
440
|
setMaskBounds(x_min, y_min, x_max, y_max) {
|
|
441
|
+
flushTextUploads();
|
|
393
442
|
maskSetMaskBoundsService(x_min, y_min, x_max, y_max);
|
|
394
443
|
}
|
|
395
444
|
endMask() {
|
|
445
|
+
flushTextUploads();
|
|
396
446
|
maskEndMaskService();
|
|
397
447
|
}
|
|
398
448
|
leaveMask() {
|
|
@@ -430,6 +480,11 @@ export class Context {
|
|
|
430
480
|
contextContainerDrawCachedFilterUseCase(blend_mode, matrix, color_transform, filter_bounds, unique_key, filter_key);
|
|
431
481
|
}
|
|
432
482
|
async createImageBitmap(width, height) {
|
|
483
|
+
flushTextUploads();
|
|
433
484
|
return await contextCreateImageBitmapService(width, height);
|
|
434
485
|
}
|
|
486
|
+
getRenderCompletion() {
|
|
487
|
+
flushTextUploads();
|
|
488
|
+
return contextGetRenderCompletionService();
|
|
489
|
+
}
|
|
435
490
|
}
|
|
@@ -5,7 +5,7 @@ import { $atlasFrameBuffer, $setFramebufferBound } from "../../FrameBufferManage
|
|
|
5
5
|
* @type {number}
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
|
-
const $MAX_VALUE =
|
|
8
|
+
const $MAX_VALUE = Infinity;
|
|
9
9
|
/**
|
|
10
10
|
* @description 未解決(dirty)の全アトラスページを、配列テクスチャの各レイヤーへ解決します。
|
|
11
11
|
* ページ毎に専用レイヤーを持つため、解決は「ページ切替のたび」ではなく
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TEXTURE_PREMULTIPLY } from "../../../Fragment/FragmentShaderSourceTexture";
|
|
2
|
+
import { BLEND_TEMPLATE } from "../../../Vertex/VertexShaderSource";
|
|
3
|
+
import { ShaderManager } from "../../../ShaderManager";
|
|
4
|
+
import { $collection } from "../../BlendVariants";
|
|
5
|
+
export const execute = () => {
|
|
6
|
+
const key = "text-batch";
|
|
7
|
+
const cached = $collection.get(key);
|
|
8
|
+
if (cached) {
|
|
9
|
+
return cached;
|
|
10
|
+
}
|
|
11
|
+
const vertex = BLEND_TEMPLATE()
|
|
12
|
+
.replace("uniform vec4 u_highp[2];", "uniform vec4 u_highp[3];")
|
|
13
|
+
.replace("v_coord = a_vertex;", "v_coord = u_highp[2].xy + a_vertex * u_highp[2].zw;");
|
|
14
|
+
const shader = new ShaderManager(vertex, TEXTURE_PREMULTIPLY());
|
|
15
|
+
$collection.set(key, shader);
|
|
16
|
+
return shader;
|
|
17
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Node } from "@next2d/texture-packer";
|
|
2
|
+
export declare const flushTextUploads: () => void;
|
|
3
|
+
export declare const flushTextUploadsForNode: (node: Node) => void;
|
|
4
|
+
export declare const queueTextUpload: (node: Node, source: OffscreenCanvas) => boolean;
|
|
5
|
+
export declare const disposeTextUploads: () => void;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { $currentAttachment } from "./FrameBufferManager";
|
|
2
|
+
import { $getAtlasAttachmentObject, $setAtlasPageDirty } from "./AtlasManager";
|
|
3
|
+
import { $gl, $context, $RENDER_MAX_SIZE } from "./WebGLUtil";
|
|
4
|
+
import { execute as bindAttachment } from "./Context/usecase/ContextBindUseCase";
|
|
5
|
+
import { execute as beginNode } from "./Context/service/ContextBeginNodeRenderingService";
|
|
6
|
+
import { execute as endNode } from "./Context/service/ContextEndNodeRenderingService";
|
|
7
|
+
import { execute as updateBounds } from "./Context/service/ContextUpdateTransferBoundsService";
|
|
8
|
+
import { execute as resetContext } from "./Context/service/ContextResetService";
|
|
9
|
+
import { execute as setTransform } from "./Context/service/ContextSetTransformService";
|
|
10
|
+
import { execute as getTexture } from "./TextureManager/usecase/TextureManagerGetTextureUseCase";
|
|
11
|
+
import { $boundTextures } from "./TextureManager";
|
|
12
|
+
import { execute as bindTexture } from "./TextureManager/usecase/TextureManagerBind0UseCase";
|
|
13
|
+
import { execute as getShader } from "./Shader/Variants/Blend/service/VariantsBlendTextBatchShaderService";
|
|
14
|
+
import { execute as drawTexture } from "./Shader/ShaderManager/usecase/ShaderManagerDrawTextureUseCase";
|
|
15
|
+
import { execute as resetBlend } from "./Blend/service/BlendResetService";
|
|
16
|
+
const maxSize = 1024;
|
|
17
|
+
let size = 512;
|
|
18
|
+
const limit = 1024;
|
|
19
|
+
const data = new Float64Array(limit * 6);
|
|
20
|
+
const attachments = [];
|
|
21
|
+
const origins = new Set();
|
|
22
|
+
let canvas = null;
|
|
23
|
+
let canvasContext = null;
|
|
24
|
+
let texture = null;
|
|
25
|
+
let count = 0;
|
|
26
|
+
let x = 0;
|
|
27
|
+
let y = 0;
|
|
28
|
+
let rowHeight = 0;
|
|
29
|
+
let flushing = false;
|
|
30
|
+
const origin = (node) => {
|
|
31
|
+
return (node.index * $RENDER_MAX_SIZE + node.y) * $RENDER_MAX_SIZE + node.x;
|
|
32
|
+
};
|
|
33
|
+
export const flushTextUploads = () => {
|
|
34
|
+
if (count) {
|
|
35
|
+
flushPendingTextUploads();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const flushPendingTextUploads = () => {
|
|
39
|
+
if (flushing || !canvas || !canvasContext) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
flushing = true;
|
|
43
|
+
const target = $currentAttachment;
|
|
44
|
+
try {
|
|
45
|
+
if (!texture) {
|
|
46
|
+
texture = getTexture(size, size, false, false);
|
|
47
|
+
}
|
|
48
|
+
bindTexture(texture, false);
|
|
49
|
+
$gl.texSubImage2D($gl.TEXTURE_2D, 0, 0, 0, $gl.RGBA, $gl.UNSIGNED_BYTE, canvas);
|
|
50
|
+
const shader = getShader();
|
|
51
|
+
const highp = shader.highp;
|
|
52
|
+
for (let idx = 0; idx < count; ++idx) {
|
|
53
|
+
const attachment = attachments[idx];
|
|
54
|
+
bindAttachment($context, attachment);
|
|
55
|
+
const offset = idx * 6;
|
|
56
|
+
const nx = data[offset];
|
|
57
|
+
const ny = data[offset + 1];
|
|
58
|
+
const width = data[offset + 2];
|
|
59
|
+
const height = data[offset + 3];
|
|
60
|
+
beginNode(nx, ny, width, height);
|
|
61
|
+
highp[0] = nx;
|
|
62
|
+
highp[1] = attachment.height - ny - height;
|
|
63
|
+
highp[2] = width;
|
|
64
|
+
highp[3] = height;
|
|
65
|
+
highp[4] = attachment.width;
|
|
66
|
+
highp[5] = attachment.height;
|
|
67
|
+
highp[8] = data[offset + 4] / size;
|
|
68
|
+
highp[9] = (size - data[offset + 5] - height) / size;
|
|
69
|
+
highp[10] = width / size;
|
|
70
|
+
highp[11] = height / size;
|
|
71
|
+
bindTexture(texture, false);
|
|
72
|
+
resetBlend();
|
|
73
|
+
drawTexture(shader);
|
|
74
|
+
endNode();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
count = 0;
|
|
79
|
+
attachments.length = 0;
|
|
80
|
+
origins.clear();
|
|
81
|
+
x = y = rowHeight = 0;
|
|
82
|
+
canvasContext.clearRect(0, 0, size, size);
|
|
83
|
+
try {
|
|
84
|
+
if (target) {
|
|
85
|
+
bindAttachment($context, target);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
flushing = false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
export const flushTextUploadsForNode = (node) => {
|
|
94
|
+
if (origins.has(origin(node))) {
|
|
95
|
+
flushTextUploads();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
export const queueTextUpload = (node, source) => {
|
|
99
|
+
const width = node.w;
|
|
100
|
+
const height = node.h;
|
|
101
|
+
if (!$currentAttachment || width <= 0 || height <= 0 || width > maxSize || height > maxSize
|
|
102
|
+
|| source.width !== width || source.height !== height) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (width > size || height > size) {
|
|
106
|
+
// Flush with the old dimensions before replacing staging storage.
|
|
107
|
+
disposeTextUploads();
|
|
108
|
+
size = maxSize;
|
|
109
|
+
}
|
|
110
|
+
if (!canvas) {
|
|
111
|
+
canvas = new OffscreenCanvas(size, size);
|
|
112
|
+
canvasContext = canvas.getContext("2d");
|
|
113
|
+
}
|
|
114
|
+
if (!canvasContext) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
flushTextUploadsForNode(node);
|
|
118
|
+
if (count === limit) {
|
|
119
|
+
flushTextUploads();
|
|
120
|
+
}
|
|
121
|
+
if (x + width > size) {
|
|
122
|
+
x = 0;
|
|
123
|
+
y += rowHeight;
|
|
124
|
+
rowHeight = 0;
|
|
125
|
+
}
|
|
126
|
+
if (y + height > size) {
|
|
127
|
+
flushTextUploads();
|
|
128
|
+
}
|
|
129
|
+
const attachment = $getAtlasAttachmentObject();
|
|
130
|
+
canvasContext.drawImage(source, x, y);
|
|
131
|
+
const offset = count * 6;
|
|
132
|
+
data[offset] = node.x;
|
|
133
|
+
data[offset + 1] = node.y;
|
|
134
|
+
data[offset + 2] = width;
|
|
135
|
+
data[offset + 3] = height;
|
|
136
|
+
data[offset + 4] = x;
|
|
137
|
+
data[offset + 5] = y;
|
|
138
|
+
attachments[count++] = attachment;
|
|
139
|
+
origins.add(origin(node));
|
|
140
|
+
x += width;
|
|
141
|
+
rowHeight = Math.max(rowHeight, height);
|
|
142
|
+
$context.newDrawState = true;
|
|
143
|
+
$setAtlasPageDirty(node.index);
|
|
144
|
+
updateBounds(node);
|
|
145
|
+
resetContext($context);
|
|
146
|
+
setTransform($context.$matrix, 1, 0, 0, 1, node.x, attachment.height - node.y - height);
|
|
147
|
+
return true;
|
|
148
|
+
};
|
|
149
|
+
export const disposeTextUploads = () => {
|
|
150
|
+
try {
|
|
151
|
+
flushTextUploads();
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
if (texture) {
|
|
155
|
+
for (let idx = 0; idx < $boundTextures.length; ++idx) {
|
|
156
|
+
if ($boundTextures[idx] === texture) {
|
|
157
|
+
$boundTextures[idx] = null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
$gl.deleteTexture(texture.resource);
|
|
161
|
+
texture = null;
|
|
162
|
+
}
|
|
163
|
+
canvas = null;
|
|
164
|
+
canvasContext = null;
|
|
165
|
+
size = 512;
|
|
166
|
+
}
|
|
167
|
+
};
|