@next2d/webgpu 3.19.1 → 3.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/package.json +3 -3
- package/src/Context.d.ts +10 -0
- package/src/Context.js +24 -4
- package/src/Mesh/usecase/MeshBitmapStrokeGenerateUseCase.js +12 -0
- package/src/Mesh/usecase/MeshGradientStrokeGenerateUseCase.js +12 -0
- package/src/NativeShape.d.ts +10 -1
- package/src/NativeShape.js +9 -0
- package/src/PathCommand.d.ts +18 -0
- package/src/PathCommand.js +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgpu",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.0",
|
|
4
4
|
"description": "Next2D WebGPU 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.20.0",
|
|
28
|
+
"@next2d/render-queue": "3.20.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/Context.d.ts
CHANGED
|
@@ -401,6 +401,16 @@ export declare class Context {
|
|
|
401
401
|
* @return {void}
|
|
402
402
|
*/
|
|
403
403
|
private fillSimple;
|
|
404
|
+
/**
|
|
405
|
+
* @description 線のメッシュの元になる経路を取得する。実行環境が線の外周の計算を提供していれば、
|
|
406
|
+
* 外周の計算もメッシュの生成も実行環境の側で行う ($NATIVE_FILL_PATH が返る)。
|
|
407
|
+
* Returns the paths a stroke mesh is built from. When the runtime provides the stroke
|
|
408
|
+
* outline computation, both the outline and the mesh are built on the runtime side
|
|
409
|
+
* ($NATIVE_FILL_PATH is returned).
|
|
410
|
+
*
|
|
411
|
+
* @return {IPath[]}
|
|
412
|
+
*/
|
|
413
|
+
private getStrokeSource;
|
|
404
414
|
/**
|
|
405
415
|
* @description 線の描画を実行(WebGL版と同じ仕様)
|
|
406
416
|
* Execute stroke drawing (same specification as WebGL version)
|
package/src/Context.js
CHANGED
|
@@ -17,6 +17,7 @@ import { execute as maskLeaveMaskUseCase } from "./Mask/usecase/MaskLeaveMaskUse
|
|
|
17
17
|
import { $isMaskTestEnabled, $isMaskDrawing, $getMaskStencilReference, $resetMaskState } from "./Mask";
|
|
18
18
|
import { execute as meshFillGenerateUseCase } from "./Mesh/usecase/MeshFillGenerateUseCase";
|
|
19
19
|
import { generateStrokeMesh } from "./Mesh/usecase/MeshStrokeGenerateUseCase";
|
|
20
|
+
import { $NATIVE_FILL_PATH } from "./NativeShape";
|
|
20
21
|
import { $gridDataMap, $fillBufferIndex, $terminateGrid } from "./Grid";
|
|
21
22
|
import { $setGradientLUTDevice, $clearGradientAttachmentObjects, $cleanupLUTCache, $clearLUTCache } from "./Gradient/GradientLUTCache";
|
|
22
23
|
import { $releaseFillTexture, $acquireRenderTexture, $releaseRenderTexture, $clearFillTexturePool, $getOrCreateView } from "./FillTexturePool";
|
|
@@ -965,6 +966,22 @@ export class Context {
|
|
|
965
966
|
const clipLevel = this.$mainAttachmentObject?.clipLevel ?? 1;
|
|
966
967
|
contextFillSimpleService(this.renderPassEncoder, this.pipelineManager, vertex_buffer, vertex_count, bind_group, uniform_offset, this.currentRenderTarget !== null, use_stencil_pipeline, clipLevel);
|
|
967
968
|
}
|
|
969
|
+
/**
|
|
970
|
+
* @description 線のメッシュの元になる経路を取得する。実行環境が線の外周の計算を提供していれば、
|
|
971
|
+
* 外周の計算もメッシュの生成も実行環境の側で行う ($NATIVE_FILL_PATH が返る)。
|
|
972
|
+
* Returns the paths a stroke mesh is built from. When the runtime provides the stroke
|
|
973
|
+
* outline computation, both the outline and the mesh are built on the runtime side
|
|
974
|
+
* ($NATIVE_FILL_PATH is returned).
|
|
975
|
+
*
|
|
976
|
+
* @return {IPath[]}
|
|
977
|
+
*/
|
|
978
|
+
getStrokeSource() {
|
|
979
|
+
// 曲線の座標 1 単位が画面上で何ピクセルになるか (generateStrokeOutline と同じ)
|
|
980
|
+
const matrix = this.$matrix;
|
|
981
|
+
const scaleX = Math.sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]);
|
|
982
|
+
const scaleY = Math.sqrt(matrix[3] * matrix[3] + matrix[4] * matrix[4]);
|
|
983
|
+
return this.pathCommand.getStrokeSource(this.thickness / 2, this.joints, this.caps, scaleX > scaleY ? scaleX : scaleY);
|
|
984
|
+
}
|
|
968
985
|
/**
|
|
969
986
|
* @description 線の描画を実行(WebGL版と同じ仕様)
|
|
970
987
|
* Execute stroke drawing (same specification as WebGL version)
|
|
@@ -974,14 +991,17 @@ export class Context {
|
|
|
974
991
|
*/
|
|
975
992
|
stroke() {
|
|
976
993
|
// WebGL版と同じ: IPath[]形式で頂点を取得
|
|
977
|
-
const vertices = this.
|
|
994
|
+
const vertices = this.getStrokeSource();
|
|
978
995
|
if (vertices.length === 0) {
|
|
979
996
|
return;
|
|
980
997
|
}
|
|
981
998
|
this.ensureFillRenderPass();
|
|
982
999
|
const viewportWidth = this.viewportWidth;
|
|
983
1000
|
const viewportHeight = this.viewportHeight;
|
|
984
|
-
|
|
1001
|
+
// 経路が実行環境の側にあれば、線の外周はすでにそちらで計算済み
|
|
1002
|
+
const strokeOutlines = vertices === $NATIVE_FILL_PATH
|
|
1003
|
+
? vertices
|
|
1004
|
+
: generateStrokeMesh(vertices, this.thickness);
|
|
985
1005
|
if (strokeOutlines.length === 0) {
|
|
986
1006
|
return;
|
|
987
1007
|
}
|
|
@@ -1095,7 +1115,7 @@ export class Context {
|
|
|
1095
1115
|
*/
|
|
1096
1116
|
gradientStroke(type, stops, matrix, spread, interpolation, focal) {
|
|
1097
1117
|
// WebGL版と同じ: IPath[]形式で頂点を取得
|
|
1098
|
-
const vertices = this.
|
|
1118
|
+
const vertices = this.getStrokeSource();
|
|
1099
1119
|
if (vertices.length === 0) {
|
|
1100
1120
|
return;
|
|
1101
1121
|
}
|
|
@@ -1130,7 +1150,7 @@ export class Context {
|
|
|
1130
1150
|
*/
|
|
1131
1151
|
bitmapStroke(pixels, matrix, width, height, repeat, smooth) {
|
|
1132
1152
|
// WebGL版と同じ: IPath[]形式で頂点を取得
|
|
1133
|
-
const vertices = this.
|
|
1153
|
+
const vertices = this.getStrokeSource();
|
|
1134
1154
|
if (vertices.length === 0) {
|
|
1135
1155
|
return;
|
|
1136
1156
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { generateStrokeOutline } from "./MeshStrokeGenerateUseCase";
|
|
2
2
|
import { execute as meshStrokeFillGenerateService } from "../service/MeshStrokeFillGenerateService";
|
|
3
|
+
import { $nativeShape, $nativeFillSize, $NATIVE_FILL_PATH } from "../../NativeShape";
|
|
3
4
|
/**
|
|
4
5
|
* @description メッシュ生成用の再利用可能な一時バッファ(GC回避)
|
|
5
6
|
*/
|
|
@@ -32,6 +33,17 @@ const $upperPowerOfTwo = (v) => {
|
|
|
32
33
|
* @protected
|
|
33
34
|
*/
|
|
34
35
|
export const execute = (vertices, thickness) => {
|
|
36
|
+
// 経路が実行環境の側にあるときは、線の外周はすでに計算済みで、メッシュもそちらで作る
|
|
37
|
+
if (vertices === $NATIVE_FILL_PATH && $nativeShape) {
|
|
38
|
+
if ($meshTempBuffer.length < $nativeFillSize) {
|
|
39
|
+
$meshTempBuffer = new Float32Array($upperPowerOfTwo($nativeFillSize));
|
|
40
|
+
}
|
|
41
|
+
const indexCount = $nativeShape.fill($meshTempBuffer, true);
|
|
42
|
+
return {
|
|
43
|
+
"buffer": $meshTempBuffer.subarray(0, indexCount * 4),
|
|
44
|
+
"indexCount": indexCount
|
|
45
|
+
};
|
|
46
|
+
}
|
|
35
47
|
const halfThickness = thickness / 2;
|
|
36
48
|
// 各パスのアウトラインを生成
|
|
37
49
|
const fillVertices = [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { generateStrokeOutline } from "./MeshStrokeGenerateUseCase";
|
|
2
2
|
import { execute as meshStrokeFillGenerateService } from "../service/MeshStrokeFillGenerateService";
|
|
3
|
+
import { $nativeShape, $nativeFillSize, $NATIVE_FILL_PATH } from "../../NativeShape";
|
|
3
4
|
/**
|
|
4
5
|
* @description メッシュ生成用の再利用可能な一時バッファ(GC回避)
|
|
5
6
|
*/
|
|
@@ -32,6 +33,17 @@ const $upperPowerOfTwo = (v) => {
|
|
|
32
33
|
* @protected
|
|
33
34
|
*/
|
|
34
35
|
export const execute = (vertices, thickness) => {
|
|
36
|
+
// 経路が実行環境の側にあるときは、線の外周はすでに計算済みで、メッシュもそちらで作る
|
|
37
|
+
if (vertices === $NATIVE_FILL_PATH && $nativeShape) {
|
|
38
|
+
if ($meshTempBuffer.length < $nativeFillSize) {
|
|
39
|
+
$meshTempBuffer = new Float32Array($upperPowerOfTwo($nativeFillSize));
|
|
40
|
+
}
|
|
41
|
+
const indexCount = $nativeShape.fill($meshTempBuffer, true);
|
|
42
|
+
return {
|
|
43
|
+
"buffer": $meshTempBuffer.subarray(0, indexCount * 4),
|
|
44
|
+
"indexCount": indexCount
|
|
45
|
+
};
|
|
46
|
+
}
|
|
35
47
|
const halfThickness = thickness / 2;
|
|
36
48
|
// 各パスのアウトラインを生成
|
|
37
49
|
const fillVertices = [];
|
package/src/NativeShape.d.ts
CHANGED
|
@@ -12,15 +12,24 @@ import type { IPath } from "./interface/IPath";
|
|
|
12
12
|
export interface INativeShape {
|
|
13
13
|
path(commands: Float32Array, index: number, pixel_scale: number): number;
|
|
14
14
|
fillSize(): number;
|
|
15
|
-
fill(target: Float32Array): number;
|
|
15
|
+
fill(target: Float32Array, flat?: boolean): number;
|
|
16
16
|
exportPath(stroke: boolean): Float64Array;
|
|
17
17
|
reset(): void;
|
|
18
|
+
strokeSize?(thickness: number, joints: number, caps: number, pixel_scale: number): number;
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* @type {INativeShape | null}
|
|
21
22
|
* @public
|
|
22
23
|
*/
|
|
23
24
|
export declare const $nativeShape: INativeShape | null;
|
|
25
|
+
/**
|
|
26
|
+
* @description 実行環境が、線の外周の計算も提供しているか
|
|
27
|
+
* Whether the runtime also provides the stroke outline computation
|
|
28
|
+
*
|
|
29
|
+
* @type {boolean}
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare const $nativeStroke: boolean;
|
|
24
33
|
/**
|
|
25
34
|
* @description 経路が実行環境の側にあることを表す目印。PathCommand.$getVertices がこれを返したら、
|
|
26
35
|
* MeshFillGenerateUseCase はメッシュを実行環境の側で作る。中身は使わない。
|
package/src/NativeShape.js
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
5
|
export const $nativeShape = globalThis.__next2dShape?.webgpu || null;
|
|
6
|
+
/**
|
|
7
|
+
* @description 実行環境が、線の外周の計算も提供しているか
|
|
8
|
+
* Whether the runtime also provides the stroke outline computation
|
|
9
|
+
*
|
|
10
|
+
* @type {boolean}
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export const $nativeStroke = $nativeShape !== null
|
|
14
|
+
&& typeof $nativeShape.strokeSize === "function";
|
|
6
15
|
/**
|
|
7
16
|
* @description 経路が実行環境の側にあることを表す目印。PathCommand.$getVertices がこれを返したら、
|
|
8
17
|
* MeshFillGenerateUseCase はメッシュを実行環境の側で作る。中身は使わない。
|
package/src/PathCommand.d.ts
CHANGED
|
@@ -139,6 +139,24 @@ export declare class PathCommand {
|
|
|
139
139
|
* @return {IPath[]}
|
|
140
140
|
*/
|
|
141
141
|
getVerticesForStroke(): IPath[];
|
|
142
|
+
/**
|
|
143
|
+
* @description 線のメッシュの元になる経路を取得する。
|
|
144
|
+
* 経路が実行環境の側にあり、実行環境が線の外周の計算を提供していれば、経路を線の外周へ
|
|
145
|
+
* 置き換えて目印 ($NATIVE_FILL_PATH) を返す (メッシュも実行環境の側で作る)。
|
|
146
|
+
* それ以外は getVerticesForStroke と同じ経路を返すので、呼び出し側が線の外周を計算する。
|
|
147
|
+
* Returns the paths a stroke mesh is built from. When the path lives on the runtime
|
|
148
|
+
* side and the runtime provides the stroke outline computation, the path is replaced
|
|
149
|
+
* by its outline and the marker ($NATIVE_FILL_PATH) is returned (the mesh is built on
|
|
150
|
+
* the runtime side as well). Otherwise the same paths as getVerticesForStroke are
|
|
151
|
+
* returned and the caller computes the outline.
|
|
152
|
+
*
|
|
153
|
+
* @param {number} half_thickness 線の太さの半分
|
|
154
|
+
* @param {number} joints
|
|
155
|
+
* @param {number} caps
|
|
156
|
+
* @param {number} pixel_scale 座標 1 単位が画面上で何ピクセルになるか
|
|
157
|
+
* @return {IPath[]}
|
|
158
|
+
*/
|
|
159
|
+
getStrokeSource(half_thickness: number, joints: number, caps: number, pixel_scale: number): IPath[];
|
|
142
160
|
/**
|
|
143
161
|
* @description リセット
|
|
144
162
|
* @return {void}
|
package/src/PathCommand.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { adaptiveCubicToQuad } from "./BezierConverter/BezierConverter";
|
|
2
|
-
import { $nativeShape, $NATIVE_FILL_PATH, $setNativeFillSize } from "./NativeShape";
|
|
2
|
+
import { $nativeShape, $nativeStroke, $NATIVE_FILL_PATH, $setNativeFillSize } from "./NativeShape";
|
|
3
3
|
/**
|
|
4
4
|
* @description 経路が 1 本も無いときに返す配列
|
|
5
5
|
* The array returned when there is no path at all
|
|
@@ -278,6 +278,35 @@ export class PathCommand {
|
|
|
278
278
|
}
|
|
279
279
|
return vertices;
|
|
280
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* @description 線のメッシュの元になる経路を取得する。
|
|
283
|
+
* 経路が実行環境の側にあり、実行環境が線の外周の計算を提供していれば、経路を線の外周へ
|
|
284
|
+
* 置き換えて目印 ($NATIVE_FILL_PATH) を返す (メッシュも実行環境の側で作る)。
|
|
285
|
+
* それ以外は getVerticesForStroke と同じ経路を返すので、呼び出し側が線の外周を計算する。
|
|
286
|
+
* Returns the paths a stroke mesh is built from. When the path lives on the runtime
|
|
287
|
+
* side and the runtime provides the stroke outline computation, the path is replaced
|
|
288
|
+
* by its outline and the marker ($NATIVE_FILL_PATH) is returned (the mesh is built on
|
|
289
|
+
* the runtime side as well). Otherwise the same paths as getVerticesForStroke are
|
|
290
|
+
* returned and the caller computes the outline.
|
|
291
|
+
*
|
|
292
|
+
* @param {number} half_thickness 線の太さの半分
|
|
293
|
+
* @param {number} joints
|
|
294
|
+
* @param {number} caps
|
|
295
|
+
* @param {number} pixel_scale 座標 1 単位が画面上で何ピクセルになるか
|
|
296
|
+
* @return {IPath[]}
|
|
297
|
+
*/
|
|
298
|
+
getStrokeSource(half_thickness, joints, caps, pixel_scale) {
|
|
299
|
+
if (this.$native && $nativeStroke) {
|
|
300
|
+
const size = $nativeShape
|
|
301
|
+
.strokeSize(half_thickness, joints, caps, pixel_scale);
|
|
302
|
+
if (!size) {
|
|
303
|
+
return $EMPTY_VERTICES;
|
|
304
|
+
}
|
|
305
|
+
$setNativeFillSize(size);
|
|
306
|
+
return $NATIVE_FILL_PATH;
|
|
307
|
+
}
|
|
308
|
+
return this.getVerticesForStroke();
|
|
309
|
+
}
|
|
281
310
|
/**
|
|
282
311
|
* @description リセット
|
|
283
312
|
* @return {void}
|