@next2d/webgpu 3.15.1 → 3.17.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.
@@ -1,4 +1,11 @@
1
1
  import { adaptiveCubicToQuad } from "./BezierConverter/BezierConverter";
2
+ /**
3
+ * @description 3次ベジェ曲線を 1 本の2次ベジェ曲線で近似できる上限。
4
+ * (許容誤差 0.05 ピクセル * 36 / √3)² = 1.08。WebGL版と同じ。
5
+ * Upper limit for approximating a cubic Bezier curve with a single quadratic one.
6
+ * (0.05 px tolerance * 36 / √3)² = 1.08. Same as the WebGL renderer.
7
+ */
8
+ const CUBIC_SINGLE_SEGMENT_LIMIT = 1.08;
2
9
  /**
3
10
  * @description WebGPU用パスコマンド(WebGL互換形式)
4
11
  * Path commands for WebGPU (WebGL compatible format)
@@ -12,77 +19,12 @@ export class PathCommand {
12
19
  * @constructor
13
20
  */
14
21
  constructor() {
15
- /**
16
- * @description 現在のパスデータ
17
- * Current path data array
18
- */
19
- Object.defineProperty(this, "$currentPath", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- /**
26
- * @description 確定済みパスの配列
27
- * Array of finalized path vertices
28
- */
29
- Object.defineProperty(this, "$vertices", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: void 0
34
- });
35
- /**
36
- * @description 現在のX座標
37
- * Current X coordinate
38
- */
39
- Object.defineProperty(this, "$currentX", {
40
- enumerable: true,
41
- configurable: true,
42
- writable: true,
43
- value: void 0
44
- });
45
- /**
46
- * @description 現在のY座標
47
- * Current Y coordinate
48
- */
49
- Object.defineProperty(this, "$currentY", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- /**
56
- * @description サブパスの開始X座標
57
- * Start X coordinate of current sub-path
58
- */
59
- Object.defineProperty(this, "$startX", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- /**
66
- * @description サブパスの開始Y座標
67
- * Start Y coordinate of current sub-path
68
- */
69
- Object.defineProperty(this, "$startY", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: void 0
74
- });
75
22
  /**
76
23
  * @description フラットネス閾値(スケールに応じて調整可能)
77
24
  * Flatness threshold for adaptive tessellation
78
25
  * 0.25 = 0.5px squared(滑らかなストローク描画用)
79
26
  */
80
- Object.defineProperty(this, "$flatnessThreshold", {
81
- enumerable: true,
82
- configurable: true,
83
- writable: true,
84
- value: 0.25
85
- });
27
+ this.$flatnessThreshold = 0.25;
86
28
  this.$currentPath = [];
87
29
  this.$vertices = [];
88
30
  this.$currentX = 0;
@@ -164,15 +106,34 @@ export class PathCommand {
164
106
  * @param {number} cy2
165
107
  * @param {number} x
166
108
  * @param {number} y
109
+ * @param {number} [pixel_scale=0] 曲線の座標 1 単位が画面上で何ピクセルになるか。渡すと、近似の誤差から
110
+ * 2次ベジェ曲線の本数を決める。0 以下なら従来の分割。
167
111
  * @return {void}
168
112
  */
169
- bezierCurveTo(cx1, cy1, cx2, cy2, x, y) {
113
+ bezierCurveTo(cx1, cy1, cx2, cy2, x, y, pixel_scale = 0) {
114
+ // 1 本の2次ベジェ曲線で足りる曲線 (小さな図形の曲線の大半) は、その場で経路へ追加する。
115
+ // 汎用の変換は点と区間のオブジェクトを曲線ごとに作るので、その確保を避ける。
116
+ // 判定と制御点は汎用の変換 (getCubicSegmentCount が 1 を返す場合) と同じ式:
117
+ // 誤差 = √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0| * pixel_scale <= 0.05
118
+ // ⇔ |P3 - 3 * P2 + 3 * P1 - P0|² * pixel_scale² <= 1.08
119
+ if (pixel_scale > 0) {
120
+ const fromX = this.$currentX;
121
+ const fromY = this.$currentY;
122
+ const dx = x - 3 * cx2 + 3 * cx1 - fromX;
123
+ const dy = y - 3 * cy2 + 3 * cy1 - fromY;
124
+ if ((dx * dx + dy * dy) * pixel_scale * pixel_scale <= CUBIC_SINGLE_SEGMENT_LIMIT) {
125
+ this.$currentPath.push((3 * cx1 + 3 * cx2 - fromX - x) * 0.25, (3 * cy1 + 3 * cy2 - fromY - y) * 0.25, true, x, y, false);
126
+ this.$currentX = x;
127
+ this.$currentY = y;
128
+ return;
129
+ }
130
+ }
170
131
  // 適応的テッセレーションで三次ベジェを二次ベジェ群に変換
171
132
  const p0 = { "x": this.$currentX, "y": this.$currentY };
172
133
  const p1 = { "x": cx1, "y": cy1 };
173
134
  const p2 = { "x": cx2, "y": cy2 };
174
135
  const p3 = { "x": x, "y": y };
175
- const segments = adaptiveCubicToQuad(p0, p1, p2, p3, this.$flatnessThreshold);
136
+ const segments = adaptiveCubicToQuad(p0, p1, p2, p3, this.$flatnessThreshold, pixel_scale);
176
137
  // 各二次ベジェセグメントをパスに追加
177
138
  for (const segment of segments) {
178
139
  this.$currentPath.push(segment.ctrl.x, segment.ctrl.y, true);
@@ -46,167 +46,77 @@ export class PipelineManager {
46
46
  * @param {GPUTextureFormat} format - テクスチャフォーマット / Texture format for output
47
47
  */
48
48
  constructor(device, format) {
49
- /**
50
- * @description GPUデバイスの参照
51
- * Reference to the GPU device
52
- */
53
- Object.defineProperty(this, "device", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: void 0
58
- });
59
- /**
60
- * @description 出力テクスチャフォーマット
61
- * Output texture format
62
- */
63
- Object.defineProperty(this, "format", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: void 0
68
- });
69
- /**
70
- * @description パイプライン名からGPURenderPipelineへのキャッシュマップ
71
- * Cache map from pipeline name to GPURenderPipeline
72
- */
73
- Object.defineProperty(this, "pipelines", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
- /**
80
- * @description バインドグループレイアウト名からGPUBindGroupLayoutへのキャッシュマップ
81
- * Cache map from layout name to GPUBindGroupLayout
82
- */
83
- Object.defineProperty(this, "bindGroupLayouts", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: void 0
88
- });
89
- /**
90
- * @description MSAAサンプル数
91
- * MSAA sample count
92
- */
93
- Object.defineProperty(this, "sampleCount", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: void 0
98
- });
99
49
  /**
100
50
  * @description シェーダーモジュールのキャッシュ
101
51
  * Shader module cache by key
102
52
  */
103
- Object.defineProperty(this, "shaderModuleCache", {
104
- enumerable: true,
105
- configurable: true,
106
- writable: true,
107
- value: new Map()
108
- });
53
+ this.shaderModuleCache = new Map();
109
54
  /**
110
55
  * @description フィルター用バインドグループレイアウトキャッシュ(テクスチャ数別)
111
56
  * Filter bind group layout cache indexed by texture count
112
57
  */
113
- Object.defineProperty(this, "filterBindGroupLayouts", {
114
- enumerable: true,
115
- configurable: true,
116
- writable: true,
117
- value: new Map()
118
- });
58
+ this.filterBindGroupLayouts = new Map();
119
59
  /**
120
60
  * @description 初期化済みの遅延グループ名セット
121
61
  * Set of initialized lazy group names
122
62
  */
123
- Object.defineProperty(this, "lazyInitGroups", {
124
- enumerable: true,
125
- configurable: true,
126
- writable: true,
127
- value: new Set()
128
- });
63
+ this.lazyInitGroups = new Set();
129
64
  /**
130
65
  * @description パイプライン名から遅延初期化グループ名への読み取り専用マップ
131
66
  * Read-only map from pipeline name to lazy initialization group name
132
67
  */
133
- Object.defineProperty(this, "lazyGroupMap", {
134
- enumerable: true,
135
- configurable: true,
136
- writable: true,
137
- value: new Map([
138
- ...Array.from({ "length": 16 }, (_, i) => [`blur_filter_${i + 1}`, "blur_filter"]),
139
- ["blur_filter", "blur_filter"],
140
- ["texture_copy", "texture_copy"], ["texture_copy_rgba8", "texture_copy"], ["texture_copy_rgba8_msaa", "texture_copy"], ["color_transform", "texture_copy"], ["y_flip_color_transform", "texture_copy"],
141
- ["texture_erase", "texture_copy"], ["blur_texture_copy", "texture_copy"],
142
- ["filter_blend", "texture_copy"], ["texture_copy_bgra", "texture_copy"],
143
- ["filter_output", "texture_copy"], ["filter_output_add", "texture_copy"],
144
- ["filter_output_screen", "texture_copy"], ["filter_output_alpha", "texture_copy"],
145
- ["filter_output_erase", "texture_copy"], ["texture_copy_bgra_msaa", "texture_copy"],
146
- ["filter_output_msaa", "texture_copy"], ["filter_output_add_msaa", "texture_copy"],
147
- ["filter_output_screen_msaa", "texture_copy"], ["filter_output_alpha_msaa", "texture_copy"],
148
- ["filter_output_erase_msaa", "texture_copy"],
149
- ...["", "_add", "_screen", "_alpha", "_erase"].flatMap((suffix) => ["", "_msaa"].map((msaa) => [`cached_ct${suffix}${msaa}`, "cached_ct"])),
150
- ["filter_output_masked", "texture_copy"], ["filter_output_masked_msaa", "texture_copy"],
151
- ["positioned_texture", "texture_copy"], ["positioned_texture_rgba", "texture_copy"],
152
- ["bitmap_render_msaa", "texture_copy"], ["bitmap_render", "texture_copy"],
153
- ["texture_scale", "texture_copy"], ["texture_scale_blend", "texture_copy"],
154
- ["bitmap_sync", "bitmap_sync"],
155
- ["color_matrix_filter", "filter"], ["bevel_base", "filter"],
156
- ["glow_filter", "filter"], ["drop_shadow_filter", "filter"],
157
- ["bevel_filter", "filter"], ["gradient_glow_filter", "filter"],
158
- ["gradient_bevel_filter", "filter"],
159
- ["complex_blend", "complex_blend"],
160
- ["complex_blend_region", "complex_blend"],
161
- ["complex_blend_region_msaa", "complex_blend"],
162
- ["complex_blend_msaa", "complex_blend"],
163
- ["complex_blend_copy", "complex_blend"],
164
- ["complex_blend_scale", "complex_blend"], ["complex_blend_output", "complex_blend"],
165
- ["complex_blend_output_msaa", "complex_blend"],
166
- ["filter_complex_blend_output", "complex_blend"],
167
- ["filter_complex_blend_output_msaa", "complex_blend"]
168
- ])
169
- });
68
+ this.lazyGroupMap = new Map([
69
+ ...Array.from({ "length": 16 }, (_, i) => [`blur_filter_${i + 1}`, "blur_filter"]),
70
+ ["blur_filter", "blur_filter"],
71
+ ["texture_copy", "texture_copy"], ["texture_copy_rgba8", "texture_copy"], ["texture_copy_rgba8_msaa", "texture_copy"], ["color_transform", "texture_copy"], ["y_flip_color_transform", "texture_copy"],
72
+ ["texture_erase", "texture_copy"], ["blur_texture_copy", "texture_copy"],
73
+ ["filter_blend", "texture_copy"], ["texture_copy_bgra", "texture_copy"],
74
+ ["filter_output", "texture_copy"], ["filter_output_add", "texture_copy"],
75
+ ["filter_output_screen", "texture_copy"], ["filter_output_alpha", "texture_copy"],
76
+ ["filter_output_erase", "texture_copy"], ["texture_copy_bgra_msaa", "texture_copy"],
77
+ ["filter_output_msaa", "texture_copy"], ["filter_output_add_msaa", "texture_copy"],
78
+ ["filter_output_screen_msaa", "texture_copy"], ["filter_output_alpha_msaa", "texture_copy"],
79
+ ["filter_output_erase_msaa", "texture_copy"],
80
+ ...["", "_add", "_screen", "_alpha", "_erase"].flatMap((suffix) => ["", "_msaa"].map((msaa) => [`cached_ct${suffix}${msaa}`, "cached_ct"])),
81
+ ["filter_output_masked", "texture_copy"], ["filter_output_masked_msaa", "texture_copy"],
82
+ ["positioned_texture", "texture_copy"], ["positioned_texture_rgba", "texture_copy"],
83
+ ["bitmap_render_msaa", "texture_copy"], ["bitmap_render", "texture_copy"],
84
+ ["texture_scale", "texture_copy"], ["texture_scale_blend", "texture_copy"],
85
+ ["bitmap_sync", "bitmap_sync"],
86
+ ["color_matrix_filter", "filter"], ["bevel_base", "filter"],
87
+ ["glow_filter", "filter"], ["drop_shadow_filter", "filter"],
88
+ ["bevel_filter", "filter"], ["gradient_glow_filter", "filter"],
89
+ ["gradient_bevel_filter", "filter"],
90
+ ["complex_blend", "complex_blend"],
91
+ ["complex_blend_region", "complex_blend"],
92
+ ["complex_blend_region_msaa", "complex_blend"],
93
+ ["complex_blend_msaa", "complex_blend"],
94
+ ["complex_blend_copy", "complex_blend"],
95
+ ["complex_blend_scale", "complex_blend"], ["complex_blend_output", "complex_blend"],
96
+ ["complex_blend_output_msaa", "complex_blend"],
97
+ ["filter_complex_blend_output", "complex_blend"],
98
+ ["filter_complex_blend_output_msaa", "complex_blend"]
99
+ ]);
170
100
  /**
171
101
  * @description グラデーション用パイプラインレイアウト
172
102
  * Pipeline layout for gradient pipelines
173
103
  */
174
- Object.defineProperty(this, "gradientPipelineLayout", {
175
- enumerable: true,
176
- configurable: true,
177
- writable: true,
178
- value: null
179
- });
104
+ this.gradientPipelineLayout = null;
180
105
  /**
181
106
  * @description グラデーション用頂点シェーダーモジュール
182
107
  * Vertex shader module for gradient pipelines
183
108
  */
184
- Object.defineProperty(this, "gradientVertexShaderModule", {
185
- enumerable: true,
186
- configurable: true,
187
- writable: true,
188
- value: null
189
- });
109
+ this.gradientVertexShaderModule = null;
190
110
  /**
191
111
  * @description グラデーション用フラグメントシェーダーモジュール
192
112
  * Fragment shader module for gradient pipelines
193
113
  */
194
- Object.defineProperty(this, "gradientFragmentShaderModule", {
195
- enumerable: true,
196
- configurable: true,
197
- writable: true,
198
- value: null
199
- });
114
+ this.gradientFragmentShaderModule = null;
200
115
  /**
201
116
  * @description グラデーション用ステンシルフラグメントシェーダーモジュール
202
117
  * Stencil fragment shader module for gradient pipelines
203
118
  */
204
- Object.defineProperty(this, "gradientStencilFragmentShaderModule", {
205
- enumerable: true,
206
- configurable: true,
207
- writable: true,
208
- value: null
209
- });
119
+ this.gradientStencilFragmentShaderModule = null;
210
120
  this.device = device;
211
121
  this.format = format;
212
122
  this.pipelines = new Map();
@@ -9,18 +9,6 @@ export class ShaderInstancedManager {
9
9
  * Initialize ShaderInstancedManager
10
10
  */
11
11
  constructor() {
12
- /**
13
- * @description 現在のインスタンス描画カウント
14
- * Current instance draw count
15
- *
16
- * @type {number}
17
- */
18
- Object.defineProperty(this, "count", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: void 0
23
- });
24
12
  this.count = 0;
25
13
  }
26
14
  /**
@@ -10,24 +10,6 @@ export class TextureManager {
10
10
  * @param {GPUDevice} device - WebGPUデバイス / WebGPU device
11
11
  */
12
12
  constructor(device) {
13
- Object.defineProperty(this, "device", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: void 0
18
- });
19
- Object.defineProperty(this, "textures", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "samplers", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
13
  this.device = device;
32
14
  this.textures = new Map();
33
15
  this.samplers = new Map();
@@ -29,56 +29,6 @@ export class TexturePool {
29
29
  * @constructor
30
30
  */
31
31
  constructor(device) {
32
- /**
33
- * @description WebGPUデバイスの参照
34
- * Reference to the WebGPU device
35
- * @type {GPUDevice}
36
- */
37
- Object.defineProperty(this, "device", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- /**
44
- * @description Power-of-2バケットによるテクスチャプール
45
- * Texture pool organized by power-of-2 buckets
46
- * @type {ITexturePoolBuckets}
47
- */
48
- Object.defineProperty(this, "buckets", {
49
- enumerable: true,
50
- configurable: true,
51
- writable: true,
52
- value: void 0
53
- });
54
- Object.defineProperty(this, "entries", {
55
- enumerable: true,
56
- configurable: true,
57
- writable: true,
58
- value: void 0
59
- });
60
- /**
61
- * @description 現在のフレーム番号
62
- * Current frame number for LRU tracking
63
- * @type {number}
64
- */
65
- Object.defineProperty(this, "currentFrame", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- /**
72
- * @description プール内のテクスチャ総数
73
- * Total count of textures in the pool
74
- * @type {number[]}
75
- */
76
- Object.defineProperty(this, "totalCount", {
77
- enumerable: true,
78
- configurable: true,
79
- writable: true,
80
- value: void 0
81
- });
82
32
  this.device = device;
83
33
  this.buckets = new Map();
84
34
  this.entries = new WeakMap();
package/src/WebGPUUtil.js CHANGED
@@ -120,48 +120,28 @@ export class WebGPUUtil {
120
120
  *
121
121
  * @type {GPUDevice | null}
122
122
  */
123
- Object.defineProperty(WebGPUUtil, "device", {
124
- enumerable: true,
125
- configurable: true,
126
- writable: true,
127
- value: null
128
- });
123
+ WebGPUUtil.device = null;
129
124
  /**
130
125
  * @description デバイスピクセル比率
131
126
  * Device pixel ratio for high-DPI rendering
132
127
  *
133
128
  * @type {number}
134
129
  */
135
- Object.defineProperty(WebGPUUtil, "devicePixelRatio", {
136
- enumerable: true,
137
- configurable: true,
138
- writable: true,
139
- value: 1
140
- });
130
+ WebGPUUtil.devicePixelRatio = 1;
141
131
  /**
142
132
  * @description レンダリング最大サイズ(テクスチャアトラス用)
143
133
  * Maximum render size for texture atlas
144
134
  *
145
135
  * @type {number}
146
136
  */
147
- Object.defineProperty(WebGPUUtil, "renderMaxSize", {
148
- enumerable: true,
149
- configurable: true,
150
- writable: true,
151
- value: 8192
152
- });
137
+ WebGPUUtil.renderMaxSize = 8192;
153
138
  /**
154
139
  * @description Float32Array(4) のオブジェクトプール
155
140
  * Object pool for Float32Array(4) instances
156
141
  *
157
142
  * @type {Float32Array[]}
158
143
  */
159
- Object.defineProperty(WebGPUUtil, "float32Array4Pool", {
160
- enumerable: true,
161
- configurable: true,
162
- writable: true,
163
- value: []
164
- });
144
+ WebGPUUtil.float32Array4Pool = [];
165
145
  /**
166
146
  * @description グローバルコンテキスト(WebGLUtilの$contextに相当)
167
147
  * Global context instance (equivalent to $context in WebGLUtil)