@next2d/webgl 3.17.1 → 3.18.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/webgl",
3
- "version": "3.17.1",
3
+ "version": "3.18.0",
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.17.1",
28
- "@next2d/render-queue": "3.17.1"
27
+ "@next2d/texture-packer": "3.18.0",
28
+ "@next2d/render-queue": "3.18.0"
29
29
  }
30
30
  }
@@ -1,7 +1,6 @@
1
- import { $getVertices } from "../../PathCommand";
2
- import { execute as meshFillGenerateUseCase } from "../../Mesh/usecase/MeshFillGenerateUseCase";
1
+ import { execute as meshFillCurrentPathUseCase } from "../../Mesh/usecase/MeshFillCurrentPathUseCase";
3
2
  import { $bitmapData } from "../../Bitmap";
4
- import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
3
+ import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
5
4
  /**
6
5
  * @description パスコマンドのビットマップ塗り実行します。
7
6
  * Execute bitmap painting of path commands.
@@ -17,15 +16,14 @@ import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
17
16
  * @protected
18
17
  */
19
18
  export const execute = (pixels, matrix, width, height, repeat, smooth) => {
20
- const vertices = $getVertices();
21
- if (!vertices.length) {
19
+ // いまの経路を塗りのメッシュにして、塗りのバッファへ追加する
20
+ const indexCount = meshFillCurrentPathUseCase();
21
+ if (indexCount < 0) {
22
22
  return;
23
23
  }
24
24
  // 塗りの種類を追加
25
25
  $fillTypes.push("bitmap");
26
- const fillMesh = meshFillGenerateUseCase(vertices);
27
- $addFillBuffer(fillMesh.buffer);
28
26
  // 塗りのインデックスを追加
29
- $fillBufferIndexes.push(fillMesh.indexCount);
27
+ $fillBufferIndexes.push(indexCount);
30
28
  $bitmapData.push(pixels, matrix, width, height, repeat, smooth);
31
29
  };
@@ -1,6 +1,5 @@
1
- import { $getVertices } from "../../PathCommand";
2
- import { execute as meshFillGenerateUseCase } from "../../Mesh/usecase/MeshFillGenerateUseCase";
3
- import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
1
+ import { execute as meshFillCurrentPathUseCase } from "../../Mesh/usecase/MeshFillCurrentPathUseCase";
2
+ import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
4
3
  /**
5
4
  * @description Contextのパスコマンドの塗り実行します。
6
5
  * Execute Context path command painting.
@@ -10,14 +9,13 @@ import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
10
9
  * @protected
11
10
  */
12
11
  export const execute = (type) => {
13
- const vertices = $getVertices();
14
- if (!vertices.length) {
12
+ // いまの経路を塗りのメッシュにして、塗りのバッファへ追加する
13
+ const indexCount = meshFillCurrentPathUseCase();
14
+ if (indexCount < 0) {
15
15
  return;
16
16
  }
17
17
  // 塗りの種類を追加
18
18
  $fillTypes.push(type);
19
- const mesh = meshFillGenerateUseCase(vertices);
20
- $addFillBuffer(mesh.buffer);
21
19
  // 塗りのインデックスを追加
22
- $fillBufferIndexes.push(mesh.indexCount);
20
+ $fillBufferIndexes.push(indexCount);
23
21
  };
@@ -1,7 +1,6 @@
1
- import { $getVertices } from "../../PathCommand";
2
- import { execute as meshFillGenerateUseCase } from "../../Mesh/usecase/MeshFillGenerateUseCase";
1
+ import { execute as meshFillCurrentPathUseCase } from "../../Mesh/usecase/MeshFillCurrentPathUseCase";
3
2
  import { $gradientData } from "../../Gradient";
4
- import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
3
+ import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
5
4
  /**
6
5
  * @description グラデーション塗りを描画
7
6
  * Draw a gradient fill
@@ -17,16 +16,15 @@ import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
17
16
  * @protected
18
17
  */
19
18
  export const execute = (type, stops, matrix, spread, interpolation, focal) => {
20
- const vertices = $getVertices();
21
- if (!vertices.length) {
19
+ // いまの経路を塗りのメッシュにして、塗りのバッファへ追加する
20
+ const indexCount = meshFillCurrentPathUseCase();
21
+ if (indexCount < 0) {
22
22
  return;
23
23
  }
24
24
  // 塗りの種類を追加
25
25
  $fillTypes.push(type === 0 ? "linear" : "radial");
26
- const fillMesh = meshFillGenerateUseCase(vertices);
27
- $addFillBuffer(fillMesh.buffer);
28
26
  // 塗りのインデックスを追加
29
- $fillBufferIndexes.push(fillMesh.indexCount);
27
+ $fillBufferIndexes.push(indexCount);
30
28
  $gradientData.push(stops, matrix, spread, interpolation);
31
29
  if (type === 1) {
32
30
  $gradientData.push(focal);
package/src/Context.d.ts CHANGED
@@ -37,6 +37,7 @@ export declare class Context {
37
37
  setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
38
38
  transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
39
39
  reset(): void;
40
+ pathCommands(commands: Float32Array, index: number): number;
40
41
  beginPath(): void;
41
42
  moveTo(x: number, y: number): void;
42
43
  lineTo(x: number, y: number): void;
package/src/Context.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { $nativeShape, $nativePathActive, $setNativePathActive } from "./NativeShape";
2
+ import { $currentPath, $vertices } from "./PathCommand";
1
3
  import { queueTextUpload, flushTextUploads, flushTextUploadsForNode, disposeTextUploads } from "./TextUploadBatch";
2
4
  import { execute as contextGetRenderCompletionService } from "./Context/service/ContextGetRenderCompletionService";
3
5
  import { execute as beginPath } from "./PathCommand/service/PathCommandBeginPathService";
@@ -156,6 +158,30 @@ export class Context {
156
158
  flushTextUploads();
157
159
  contextResetService(this);
158
160
  }
161
+ // 描画命令の並びのうち、index から続く経路の命令をまとめて処理する。実行環境が経路の実装を
162
+ // 提供していればそれを使い、次に処理する命令の位置を返す。使えないときは -1 を返すので、
163
+ // 呼び出し側が moveTo などを 1 つずつ呼ぶ。
164
+ pathCommands(commands, index) {
165
+ if (!$nativeShape) {
166
+ return -1;
167
+ }
168
+ // 3 次ベジェ曲線の分割数は画面上の拡大率で決まる (PathCommandBezierCurveToUseCase と同じ計算)
169
+ const matrix = this.$matrix;
170
+ const scaleX = matrix[0] * matrix[0] + matrix[1] * matrix[1];
171
+ const scaleY = matrix[3] * matrix[3] + matrix[4] * matrix[4];
172
+ const scaleSquared = scaleX > scaleY ? scaleX : scaleY;
173
+ if (!(scaleSquared > 0)) {
174
+ return -1;
175
+ }
176
+ if (!$nativePathActive) {
177
+ // JavaScript 側で経路を作り始めていたら、混ぜない
178
+ if ($currentPath.length || $vertices.length) {
179
+ return -1;
180
+ }
181
+ $setNativePathActive(true);
182
+ }
183
+ return $nativeShape.path(commands, index, scaleSquared);
184
+ }
159
185
  beginPath() {
160
186
  // reset color style
161
187
  contextResetStyleService(this);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @description いまの経路を塗りのメッシュにして、塗りのバッファへ追加する。
3
+ * 経路を実行環境の側で組み立てていれば、メッシュもそちらで作る。
4
+ * Turns the current path into a fill mesh and appends it to the fill buffer.
5
+ * If the path was built on the runtime side, the mesh is generated there too.
6
+ *
7
+ * @return {number} 追加した頂点数。塗る経路が無ければ -1
8
+ * @method
9
+ * @protected
10
+ */
11
+ export declare const execute: () => number;
@@ -0,0 +1,41 @@
1
+ import { $getVertices } from "../../PathCommand";
2
+ import { execute as meshFillGenerateUseCase } from "./MeshFillGenerateUseCase";
3
+ import { $addFillBuffer, $reserveFillBuffer, $advanceFillBuffer, $getFillBuffer, $getFillBufferOffset } from "../../Mesh";
4
+ import { $nativeShape, $nativePathActive, $setNativePathActive } from "../../NativeShape";
5
+ import { $context, $viewportWidth, $viewportHeight } from "../../WebGLUtil";
6
+ /**
7
+ * @description いまの経路を塗りのメッシュにして、塗りのバッファへ追加する。
8
+ * 経路を実行環境の側で組み立てていれば、メッシュもそちらで作る。
9
+ * Turns the current path into a fill mesh and appends it to the fill buffer.
10
+ * If the path was built on the runtime side, the mesh is generated there too.
11
+ *
12
+ * @return {number} 追加した頂点数。塗る経路が無ければ -1
13
+ * @method
14
+ * @protected
15
+ */
16
+ export const execute = () => {
17
+ if ($nativePathActive && $nativeShape) {
18
+ $setNativePathActive(false);
19
+ const size = $nativeShape.fillSize();
20
+ if (!size) {
21
+ $nativeShape.reset();
22
+ return -1;
23
+ }
24
+ // MeshFillGenerateUseCase と同じ値を渡す
25
+ const colorStyle = $context.$fillStyle;
26
+ const matrix = $context.$matrix;
27
+ const width = $viewportWidth;
28
+ const height = $viewportHeight;
29
+ $reserveFillBuffer(size);
30
+ const indexCount = $nativeShape.fill($getFillBuffer(), $getFillBufferOffset(), matrix[0] / width, matrix[1] / height, matrix[3] / width, matrix[4] / height, matrix[6] / width, matrix[7] / height, colorStyle[0], colorStyle[1], colorStyle[2], colorStyle[3]);
31
+ $advanceFillBuffer(size);
32
+ return indexCount;
33
+ }
34
+ const vertices = $getVertices();
35
+ if (!vertices.length) {
36
+ return -1;
37
+ }
38
+ const mesh = meshFillGenerateUseCase(vertices);
39
+ $addFillBuffer(mesh.buffer);
40
+ return mesh.indexCount;
41
+ };
package/src/Mesh.d.ts CHANGED
@@ -37,6 +37,30 @@ export declare const $getFillBufferOffset: () => number;
37
37
  * @protected
38
38
  */
39
39
  export declare const $addFillBuffer: (buffer: Float32Array) => void;
40
+ /**
41
+ * @description 塗りのバッファに、あと size 要素を書けるだけの領域を確保する (内容は保つ)。
42
+ * 確保した後、$getFillBuffer() の $getFillBufferOffset() の位置から直接書き、
43
+ * $advanceFillBuffer(size) で位置を進める。
44
+ * Reserves room for `size` more elements in the fill buffer, keeping its content.
45
+ * Then write directly from $getFillBufferOffset() of $getFillBuffer() and advance
46
+ * the position with $advanceFillBuffer(size).
47
+ *
48
+ * @param {number} size
49
+ * @return {void}
50
+ * @method
51
+ * @protected
52
+ */
53
+ export declare const $reserveFillBuffer: (size: number) => void;
54
+ /**
55
+ * @description 塗りのバッファの書き込み位置を size 要素だけ進める
56
+ * Advances the write position of the fill buffer by `size` elements
57
+ *
58
+ * @param {number} size
59
+ * @return {void}
60
+ * @method
61
+ * @protected
62
+ */
63
+ export declare const $advanceFillBuffer: (size: number) => void;
40
64
  /**
41
65
  * @description バッファを頂点数の配列
42
66
  * Array of the number of vertices in the buffer
package/src/Mesh.js CHANGED
@@ -73,6 +73,41 @@ export const $addFillBuffer = (buffer) => {
73
73
  }
74
74
  $fillBufferOffset += buffer.length;
75
75
  };
76
+ /**
77
+ * @description 塗りのバッファに、あと size 要素を書けるだけの領域を確保する (内容は保つ)。
78
+ * 確保した後、$getFillBuffer() の $getFillBufferOffset() の位置から直接書き、
79
+ * $advanceFillBuffer(size) で位置を進める。
80
+ * Reserves room for `size` more elements in the fill buffer, keeping its content.
81
+ * Then write directly from $getFillBufferOffset() of $getFillBuffer() and advance
82
+ * the position with $advanceFillBuffer(size).
83
+ *
84
+ * @param {number} size
85
+ * @return {void}
86
+ * @method
87
+ * @protected
88
+ */
89
+ export const $reserveFillBuffer = (size) => {
90
+ const length = size + $fillBufferOffset;
91
+ if (length > $fillBuffer.length) {
92
+ const newBuffer = new Float32Array($upperPowerOfTwo(length));
93
+ if ($fillBufferOffset > 0) {
94
+ newBuffer.set($fillBuffer.subarray(0, $fillBufferOffset));
95
+ }
96
+ $fillBuffer = newBuffer;
97
+ }
98
+ };
99
+ /**
100
+ * @description 塗りのバッファの書き込み位置を size 要素だけ進める
101
+ * Advances the write position of the fill buffer by `size` elements
102
+ *
103
+ * @param {number} size
104
+ * @return {void}
105
+ * @method
106
+ * @protected
107
+ */
108
+ export const $advanceFillBuffer = (size) => {
109
+ $fillBufferOffset += size;
110
+ };
76
111
  /**
77
112
  * @description バッファを頂点数の配列
78
113
  * Array of the number of vertices in the buffer
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @description 実行環境が提供する、図形の「経路の組み立て」と「塗りのメッシュの生成」の実装。
3
+ * JIT が使えない実行環境 (ゲーム機向けのホスト) が、グローバルの __next2dShape に置く。
4
+ * 無い環境 (ブラウザ) では null で、すべて JavaScript で処理する。結果はどちらも同じ。
5
+ *
6
+ * The implementation of path building and fill mesh generation provided by the runtime.
7
+ * Runtimes without a JIT (hosts for game consoles) put it on the global as
8
+ * __next2dShape. Where it is absent (browsers) this is null and everything runs in
9
+ * JavaScript. Both produce the same result.
10
+ */
11
+ export interface INativeShape {
12
+ path(commands: Float32Array, index: number, scale_squared: number): number;
13
+ fillSize(): number;
14
+ fill(target: Float32Array, offset: number, a: number, b: number, c: number, d: number, tx: number, ty: number, red: number, green: number, blue: number, alpha: number): number;
15
+ exportPath(stroke: boolean): Float64Array;
16
+ reset(): void;
17
+ }
18
+ /**
19
+ * @type {INativeShape | null}
20
+ * @public
21
+ */
22
+ export declare const $nativeShape: INativeShape | null;
23
+ /**
24
+ * @description 経路を実行環境の側で組み立てている最中かどうか。
25
+ * true の間、JavaScript 側の経路 ($currentPath / $vertices) は空。
26
+ * Whether the path is currently being built on the runtime side. While true, the
27
+ * JavaScript-side path ($currentPath / $vertices) is empty.
28
+ *
29
+ * @type {boolean}
30
+ * @public
31
+ */
32
+ export declare let $nativePathActive: boolean;
33
+ /**
34
+ * @param {boolean} active
35
+ * @return {void}
36
+ * @method
37
+ * @public
38
+ */
39
+ export declare const $setNativePathActive: (active: boolean) => void;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @type {INativeShape | null}
3
+ * @public
4
+ */
5
+ export const $nativeShape = globalThis.__next2dShape || null;
6
+ /**
7
+ * @description 経路を実行環境の側で組み立てている最中かどうか。
8
+ * true の間、JavaScript 側の経路 ($currentPath / $vertices) は空。
9
+ * Whether the path is currently being built on the runtime side. While true, the
10
+ * JavaScript-side path ($currentPath / $vertices) is empty.
11
+ *
12
+ * @type {boolean}
13
+ * @public
14
+ */
15
+ export let $nativePathActive = false;
16
+ /**
17
+ * @param {boolean} active
18
+ * @return {void}
19
+ * @method
20
+ * @public
21
+ */
22
+ export const $setNativePathActive = (active) => {
23
+ $nativePathActive = active;
24
+ };
@@ -1,4 +1,5 @@
1
1
  import { $poolArray } from "../../WebGLUtil";
2
+ import { $nativeShape, $nativePathActive, $setNativePathActive } from "../../NativeShape";
2
3
  import { $currentPath, $vertices } from "../../PathCommand";
3
4
  /**
4
5
  * @description 現在操作中のパス配列を全てクリアします。
@@ -9,6 +10,11 @@ import { $currentPath, $vertices } from "../../PathCommand";
9
10
  * @protected
10
11
  */
11
12
  export const execute = () => {
13
+ // 経路を実行環境の側で組み立てていた場合は、そちらを空にする
14
+ if ($nativePathActive && $nativeShape) {
15
+ $setNativePathActive(false);
16
+ $nativeShape.reset();
17
+ }
12
18
  $currentPath.length = 0;
13
19
  while ($vertices.length) {
14
20
  $poolArray($vertices.pop());
@@ -1,4 +1,5 @@
1
1
  import { $getArray } from "./WebGLUtil";
2
+ import { $nativeShape, $nativePathActive, $setNativePathActive } from "./NativeShape";
2
3
  /**
3
4
  * @description 現在操作中のパス配列
4
5
  * Current path array being operated
@@ -26,6 +27,25 @@ export const $vertices = $getArray();
26
27
  */
27
28
  export const $getVertices = (stroke = false) => {
28
29
  // stroke: 最低2頂点(6要素)が必要、fill: 最低3頂点(9要素)が必要
30
+ // 経路を実行環境の側で組み立てていた場合は、そこから取り出す
31
+ // (線の生成など、実行環境の側に実装が無い処理が経路を必要としたとき)
32
+ if ($nativePathActive && $nativeShape) {
33
+ $setNativePathActive(false);
34
+ const data = $nativeShape.exportPath(stroke);
35
+ const paths = [];
36
+ const count = data[0];
37
+ let offset = 1;
38
+ for (let idx = 0; idx < count; ++idx) {
39
+ const size = data[offset++];
40
+ const path = [];
41
+ for (let position = 0; position < size; position += 3) {
42
+ path.push(data[offset + position], data[offset + position + 1], data[offset + position + 2] !== 0);
43
+ }
44
+ offset += size;
45
+ paths.push(path);
46
+ }
47
+ return paths;
48
+ }
29
49
  const minVertices = stroke ? 6 : 9;
30
50
  // 現在のパスをverticesに追加
31
51
  if ($currentPath.length >= minVertices) {