@next2d/webgpu 3.15.0 → 3.16.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/webgpu",
3
- "version": "3.15.0",
3
+ "version": "3.16.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.15.0",
28
- "@next2d/render-queue": "3.15.0"
27
+ "@next2d/texture-packer": "3.16.0",
28
+ "@next2d/render-queue": "3.16.0"
29
29
  }
30
30
  }
@@ -11,42 +11,6 @@ export class AttachmentManager {
11
11
  * @param {GPUDevice} device - WebGPUデバイス / WebGPU device
12
12
  */
13
13
  constructor(device) {
14
- Object.defineProperty(this, "device", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "attachmentPool", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
26
- Object.defineProperty(this, "texturePool", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: void 0
31
- });
32
- Object.defineProperty(this, "colorBufferPool", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- Object.defineProperty(this, "stencilBufferPool", {
39
- enumerable: true,
40
- configurable: true,
41
- writable: true,
42
- value: void 0
43
- });
44
- Object.defineProperty(this, "idCounter", {
45
- enumerable: true,
46
- configurable: true,
47
- writable: true,
48
- value: void 0
49
- });
50
14
  this.device = device;
51
15
  this.attachmentPool = [];
52
16
  this.texturePool = new Map();
@@ -1,10 +1,30 @@
1
1
  import type { IPoint } from "../../interface/IPoint";
2
2
  import type { IQuadraticSegment } from "../../interface/IQuadraticSegment";
3
3
  export type { IQuadraticSegment };
4
+ /**
5
+ * @description 3次ベジェ曲線を何本の2次ベジェ曲線で近似するかを、画面上の誤差から求める (WebGL版と同じ式)。
6
+ * 1 本の2次ベジェ曲線 (制御点 = (3 * P1 + 3 * P2 - P0 - P3) / 4) で近似したときの誤差の上限は
7
+ * √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|、n 等分してから近似すると 1 / n³ になる。
8
+ * Returns how many quadratic curves approximate a cubic one, from the on-screen error
9
+ * (same formula as the WebGL renderer).
10
+ *
11
+ * @param {IPoint} p0
12
+ * @param {IPoint} p1
13
+ * @param {IPoint} p2
14
+ * @param {IPoint} p3
15
+ * @param {number} pixel_scale - 曲線の座標 1 単位が画面上で何ピクセルになるか
16
+ * @return {number}
17
+ */
18
+ export declare const getCubicSegmentCount: (p0: IPoint, p1: IPoint, p2: IPoint, p3: IPoint, pixel_scale: number) => number;
4
19
  /**
5
20
  * @description 三次ベジェ曲線を適応的に二次ベジェ曲線群に変換
6
21
  * Adaptively convert cubic bezier to quadratic bezier segments
7
22
  *
23
+ * pixel_scale (曲線の座標 1 単位が画面上で何ピクセルになるか) が渡されたときは、近似の誤差から
24
+ * 必要な本数 (1〜8) を決め、その本数に等分する。直線からの離れ具合 (フラットネス) で再帰的に
25
+ * 分割する方法は、2次曲線で近似したときの誤差と対応せず、小さな曲線でも数十本に分かれる。
26
+ * pixel_scale が無いときは、従来どおりフラットネスで分割する。
27
+ *
8
28
  * フラットネス(平坦度)に基づいて動的に分割数を決定。
9
29
  * 単純な曲線は少ない分割、複雑な曲線は多い分割を行う。
10
30
  *
@@ -13,6 +33,7 @@ export type { IQuadraticSegment };
13
33
  * @param {IPoint} p2 - 制御点2
14
34
  * @param {IPoint} p3 - 終点
15
35
  * @param {number} flatness_threshold - フラットネス閾値(オプション)
36
+ * @param {number} pixel_scale - 曲線の座標 1 単位が画面上で何ピクセルになるか(オプション。0 以下なら従来の分割)
16
37
  * @return {IQuadraticSegment[]} 二次ベジェ曲線のセグメント配列
17
38
  */
18
- export declare const execute: (p0: IPoint, p1: IPoint, p2: IPoint, p3: IPoint, flatness_threshold?: number) => IQuadraticSegment[];
39
+ export declare const execute: (p0: IPoint, p1: IPoint, p2: IPoint, p3: IPoint, flatness_threshold?: number, pixel_scale?: number) => IQuadraticSegment[];
@@ -14,10 +14,51 @@ const DEFAULT_FLATNESS_THRESHOLD = 0.25; // 0.5px squared
14
14
  * Maximum recursion depth to prevent infinite loops
15
15
  */
16
16
  const MAX_RECURSION_DEPTH = 8;
17
+ /**
18
+ * @description 3次ベジェ曲線を2次ベジェ曲線で近似するときの、画面上の誤差の許容値 (ピクセル)。WebGL版と同じ。
19
+ * Allowed on-screen error in pixels when approximating a cubic Bezier curve with quadratic
20
+ * ones. Same as the WebGL renderer.
21
+ */
22
+ const CUBIC_TOLERANCE = 0.05;
23
+ /**
24
+ * @description 3次ベジェ曲線 1 本を近似する2次ベジェ曲線の本数の上限。WebGL版と同じ。
25
+ * Maximum number of quadratic curves per cubic curve. Same as the WebGL renderer.
26
+ */
27
+ const MAX_SEGMENTS = 8;
28
+ /**
29
+ * @description 3次ベジェ曲線を何本の2次ベジェ曲線で近似するかを、画面上の誤差から求める (WebGL版と同じ式)。
30
+ * 1 本の2次ベジェ曲線 (制御点 = (3 * P1 + 3 * P2 - P0 - P3) / 4) で近似したときの誤差の上限は
31
+ * √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|、n 等分してから近似すると 1 / n³ になる。
32
+ * Returns how many quadratic curves approximate a cubic one, from the on-screen error
33
+ * (same formula as the WebGL renderer).
34
+ *
35
+ * @param {IPoint} p0
36
+ * @param {IPoint} p1
37
+ * @param {IPoint} p2
38
+ * @param {IPoint} p3
39
+ * @param {number} pixel_scale - 曲線の座標 1 単位が画面上で何ピクセルになるか
40
+ * @return {number}
41
+ */
42
+ export const getCubicSegmentCount = (p0, p1, p2, p3, pixel_scale) => {
43
+ const dx = p3.x - 3 * p2.x + 3 * p1.x - p0.x;
44
+ const dy = p3.y - 3 * p2.y + 3 * p1.y - p0.y;
45
+ // √3 / 36 = 0.048112522432468816
46
+ const error = 0.048112522432468816 * Math.sqrt(dx * dx + dy * dy) * pixel_scale;
47
+ let count = 1;
48
+ while (count < MAX_SEGMENTS && error > CUBIC_TOLERANCE * count * count * count) {
49
+ ++count;
50
+ }
51
+ return count;
52
+ };
17
53
  /**
18
54
  * @description 三次ベジェ曲線を適応的に二次ベジェ曲線群に変換
19
55
  * Adaptively convert cubic bezier to quadratic bezier segments
20
56
  *
57
+ * pixel_scale (曲線の座標 1 単位が画面上で何ピクセルになるか) が渡されたときは、近似の誤差から
58
+ * 必要な本数 (1〜8) を決め、その本数に等分する。直線からの離れ具合 (フラットネス) で再帰的に
59
+ * 分割する方法は、2次曲線で近似したときの誤差と対応せず、小さな曲線でも数十本に分かれる。
60
+ * pixel_scale が無いときは、従来どおりフラットネスで分割する。
61
+ *
21
62
  * フラットネス(平坦度)に基づいて動的に分割数を決定。
22
63
  * 単純な曲線は少ない分割、複雑な曲線は多い分割を行う。
23
64
  *
@@ -26,10 +67,62 @@ const MAX_RECURSION_DEPTH = 8;
26
67
  * @param {IPoint} p2 - 制御点2
27
68
  * @param {IPoint} p3 - 終点
28
69
  * @param {number} flatness_threshold - フラットネス閾値(オプション)
70
+ * @param {number} pixel_scale - 曲線の座標 1 単位が画面上で何ピクセルになるか(オプション。0 以下なら従来の分割)
29
71
  * @return {IQuadraticSegment[]} 二次ベジェ曲線のセグメント配列
30
72
  */
31
- export const execute = (p0, p1, p2, p3, flatness_threshold = DEFAULT_FLATNESS_THRESHOLD) => {
73
+ export const execute = (p0, p1, p2, p3, flatness_threshold = DEFAULT_FLATNESS_THRESHOLD, pixel_scale = 0) => {
32
74
  const result = [];
75
+ if (pixel_scale > 0) {
76
+ const count = getCubicSegmentCount(p0, p1, p2, p3, pixel_scale);
77
+ // 残りの曲線の先頭 1 / (残りの本数) を切り出すことを繰り返す (De Casteljau)
78
+ let x0 = p0.x;
79
+ let y0 = p0.y;
80
+ let x1 = p1.x;
81
+ let y1 = p1.y;
82
+ let x2 = p2.x;
83
+ let y2 = p2.y;
84
+ const x3 = p3.x;
85
+ const y3 = p3.y;
86
+ for (let idx = 0; idx < count - 1; ++idx) {
87
+ const t = 1 / (count - idx);
88
+ const mt = 1 - t;
89
+ const q0x = mt * x0 + t * x1;
90
+ const q0y = mt * y0 + t * y1;
91
+ const q1x = mt * x1 + t * x2;
92
+ const q1y = mt * y1 + t * y2;
93
+ const q2x = mt * x2 + t * x3;
94
+ const q2y = mt * y2 + t * y3;
95
+ const r0x = mt * q0x + t * q1x;
96
+ const r0y = mt * q0y + t * q1y;
97
+ const r1x = mt * q1x + t * q2x;
98
+ const r1y = mt * q1y + t * q2y;
99
+ const sx = mt * r0x + t * r1x;
100
+ const sy = mt * r0y + t * r1y;
101
+ // 切り出した区間 (x0, y0) - (q0) - (r0) - (s) を 1 本の2次ベジェ曲線で近似する
102
+ result.push({
103
+ "ctrl": {
104
+ "x": (3 * q0x + 3 * r0x - x0 - sx) * 0.25,
105
+ "y": (3 * q0y + 3 * r0y - y0 - sy) * 0.25
106
+ },
107
+ "end": { "x": sx, "y": sy }
108
+ });
109
+ // 残り: (s) - (r1) - (q2) - (x3, y3)
110
+ x0 = sx;
111
+ y0 = sy;
112
+ x1 = r1x;
113
+ y1 = r1y;
114
+ x2 = q2x;
115
+ y2 = q2y;
116
+ }
117
+ result.push({
118
+ "ctrl": {
119
+ "x": (3 * x1 + 3 * x2 - x0 - x3) * 0.25,
120
+ "y": (3 * y1 + 3 * y2 - y0 - y3) * 0.25
121
+ },
122
+ "end": { "x": x3, "y": y3 }
123
+ });
124
+ return result;
125
+ }
33
126
  /**
34
127
  * @description 再帰的に三次ベジェ曲線を分割し、二次ベジェ曲線に近似する内部関数
35
128
  * Internal recursive function that subdivides cubic bezier and approximates with quadratic bezier
@@ -20,60 +20,11 @@ export class DynamicUniformAllocator {
20
20
  * @param {number} capacity - 初期バッファ容量(バイト単位、デフォルト: 65536)
21
21
  */
22
22
  constructor(device, capacity = 65536) {
23
- Object.defineProperty(this, "device", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: void 0
28
- });
29
- Object.defineProperty(this, "buffer", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: null
34
- });
35
- Object.defineProperty(this, "offset", {
36
- enumerable: true,
37
- configurable: true,
38
- writable: true,
39
- value: 0
40
- });
41
- Object.defineProperty(this, "capacity", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: void 0
46
- });
47
- Object.defineProperty(this, "alignment", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: 256
52
- });
53
- Object.defineProperty(this, "pendingDestroyBuffers", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: []
58
- });
59
- Object.defineProperty(this, "stagingBuffer", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- Object.defineProperty(this, "stagingFloat32", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- Object.defineProperty(this, "dirtyEnd", {
72
- enumerable: true,
73
- configurable: true,
74
- writable: true,
75
- value: 0
76
- });
23
+ this.buffer = null;
24
+ this.offset = 0;
25
+ this.alignment = 256;
26
+ this.pendingDestroyBuffers = [];
27
+ this.dirtyEnd = 0;
77
28
  this.device = device;
78
29
  this.capacity = capacity;
79
30
  this.stagingBuffer = new ArrayBuffer(capacity);
@@ -187,85 +138,8 @@ export class BufferManager {
187
138
  * @param {GPUDevice} device - WebGPUデバイス
188
139
  */
189
140
  constructor(device) {
190
- Object.defineProperty(this, "device", {
191
- enumerable: true,
192
- configurable: true,
193
- writable: true,
194
- value: void 0
195
- });
196
- Object.defineProperty(this, "vertexBufferBuckets", {
197
- enumerable: true,
198
- configurable: true,
199
- writable: true,
200
- value: void 0
201
- });
202
- Object.defineProperty(this, "uniformBufferBuckets", {
203
- enumerable: true,
204
- configurable: true,
205
- writable: true,
206
- value: void 0
207
- });
208
- Object.defineProperty(this, "storageBufferPool", {
209
- enumerable: true,
210
- configurable: true,
211
- writable: true,
212
- value: void 0
213
- });
214
- Object.defineProperty(this, "indirectBufferPool", {
215
- enumerable: true,
216
- configurable: true,
217
- writable: true,
218
- value: void 0
219
- });
220
- Object.defineProperty(this, "frameIndirectBuffers", {
221
- enumerable: true,
222
- configurable: true,
223
- writable: true,
224
- value: void 0
225
- });
226
- Object.defineProperty(this, "frameNumber", {
227
- enumerable: true,
228
- configurable: true,
229
- writable: true,
230
- value: void 0
231
- });
232
- Object.defineProperty(this, "unitRectBuffer", {
233
- enumerable: true,
234
- configurable: true,
235
- writable: true,
236
- value: void 0
237
- });
238
141
  /** @description 不変の等倍UV。フレームプールに返さずdisposeまで保持 / Immutable identity UV, owned until dispose */
239
- Object.defineProperty(this, "identityUVBuffer", {
240
- enumerable: true,
241
- configurable: true,
242
- writable: true,
243
- value: null
244
- });
245
- Object.defineProperty(this, "frameVertexPoolBuffers", {
246
- enumerable: true,
247
- configurable: true,
248
- writable: true,
249
- value: void 0
250
- });
251
- Object.defineProperty(this, "frameUniformPoolBuffers", {
252
- enumerable: true,
253
- configurable: true,
254
- writable: true,
255
- value: void 0
256
- });
257
- Object.defineProperty(this, "dynamicUniform", {
258
- enumerable: true,
259
- configurable: true,
260
- writable: true,
261
- value: void 0
262
- });
263
- Object.defineProperty(this, "instanceBuffer", {
264
- enumerable: true,
265
- configurable: true,
266
- writable: true,
267
- value: void 0
268
- });
142
+ this.identityUVBuffer = null;
269
143
  this.device = device;
270
144
  this.vertexBufferBuckets = new Map();
271
145
  this.uniformBufferBuckets = new Map();