@next2d/renderer 3.0.5 → 3.2.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/renderer",
3
- "version": "3.0.5",
3
+ "version": "3.2.0",
4
4
  "description": "Next2D Renderer Package",
5
5
  "author": "Toshiyuki Ienaga<ienaga@next2d.app> (https://github.com/ienaga/)",
6
6
  "license": "MIT",
@@ -24,9 +24,9 @@
24
24
  "url": "git+https://github.com/Next2D/Player.git"
25
25
  },
26
26
  "dependencies": {
27
- "@next2d/webgl": "3.0.5",
28
- "@next2d/webgpu": "3.0.5",
29
- "@next2d/cache": "3.0.5",
30
- "@next2d/texture-packer": "3.0.5"
27
+ "@next2d/webgl": "3.2.0",
28
+ "@next2d/webgpu": "3.2.0",
29
+ "@next2d/cache": "3.2.0",
30
+ "@next2d/texture-packer": "3.2.0"
31
31
  }
32
32
  }
@@ -1,4 +1,5 @@
1
1
  import { $context } from "../../RendererUtil";
2
+ import { $cacheStore } from "@next2d/cache";
2
3
  import { execute as shapeRenderUseCase } from "../../Shape/usecase/ShapeRenderUseCase";
3
4
  import { execute as shapeClipRenderUseCase } from "../../Shape/usecase/ShapeClipRenderUseCase";
4
5
  import { execute as textFieldRenderUseCase } from "../../TextField/usecase/TextFieldRenderUseCase";
@@ -26,17 +27,55 @@ export const execute = (render_queue, index, image_bitmaps) => {
26
27
  let layerWidth = 0;
27
28
  let layerHeight = 0;
28
29
  let useFilter = false;
30
+ let useCacheAsBitmap = false;
29
31
  let uniqueKey = "";
30
32
  let filterKey = "";
33
+ let cacheRenderScaleX = 1;
34
+ let cacheRenderScaleY = 1;
31
35
  let filterBounds = null;
32
36
  let filterParams = null;
33
37
  let matrix = null;
34
38
  let colorTransform = null;
39
+ // filter layer内部スケール (子孫のcacheAsBitmap最大値)。compose時に 1/layerScaleで縮小合成する。
40
+ let layerScaleX = 1;
41
+ let layerScaleY = 1;
35
42
  if (useLayer) {
36
43
  layerWidth = render_queue[index++];
37
44
  layerHeight = render_queue[index++];
38
- useFilter = Boolean(render_queue[index++]);
39
- if (useFilter) {
45
+ const layerType = render_queue[index++]; // 0=blend, 1=filter, 2=cacheAsBitmap
46
+ useFilter = layerType === 1;
47
+ useCacheAsBitmap = layerType === 2;
48
+ if (useCacheAsBitmap) {
49
+ // cacheAsBitmapパス
50
+ const cacheHit = Boolean(render_queue[index++]);
51
+ uniqueKey = `${render_queue[index++]}`;
52
+ filterKey = `${render_queue[index++]}`;
53
+ // フィルター境界を読み取り
54
+ filterBounds = render_queue.subarray(index, index + 4);
55
+ index += 4;
56
+ // renderScale(キャッシュ描画時のスケール)
57
+ cacheRenderScaleX = render_queue[index++];
58
+ cacheRenderScaleY = render_queue[index++];
59
+ // 親matrix + スクリーン座標 (a, b, c, d, screenX, screenY)
60
+ matrix = render_queue.subarray(index, index + 6);
61
+ index += 6;
62
+ colorTransform = render_queue.subarray(index, index + 8);
63
+ index += 8;
64
+ if (cacheHit) {
65
+ // キャッシュ済み: Shapeと同様にmatrix/renderScaleで描画
66
+ const cachedNode = $cacheStore.get(uniqueKey, "bNode");
67
+ if (cachedNode) {
68
+ $context.globalAlpha = Math.min(Math.max(0, colorTransform[3] + colorTransform[7] / 255), 1);
69
+ $context.globalCompositeOperation = blendMode;
70
+ $context.setTransform(matrix[0] / cacheRenderScaleX, matrix[1] / cacheRenderScaleX, matrix[2] / cacheRenderScaleY, matrix[3] / cacheRenderScaleY, matrix[4], matrix[5]);
71
+ $context.drawDisplayObject(cachedNode, filterBounds[0], filterBounds[1], filterBounds[2], filterBounds[3], colorTransform);
72
+ }
73
+ return index;
74
+ }
75
+ // 初回描画: フィルターパラメータをスキップ(アトラスパスでは不使用)
76
+ index += render_queue[index] + 1;
77
+ }
78
+ else if (useFilter) {
40
79
  // フィルターパス: filterCache/uniqueKey/filterKey を読む
41
80
  const filterCache = Boolean(render_queue[index++]);
42
81
  uniqueKey = `${render_queue[index++]}`;
@@ -46,6 +85,8 @@ export const execute = (render_queue, index, image_bitmaps) => {
46
85
  index += 4;
47
86
  matrix = render_queue.subarray(index, index + 6);
48
87
  index += 6;
88
+ // layerScale (HIT時は合成時のscale補正には未使用)
89
+ index += 2;
49
90
  colorTransform = render_queue.subarray(index, index + 8);
50
91
  index += 8;
51
92
  // キャッシュされたフィルターテクスチャを描画
@@ -56,6 +97,8 @@ export const execute = (render_queue, index, image_bitmaps) => {
56
97
  index += 4;
57
98
  matrix = render_queue.subarray(index, index + 6);
58
99
  index += 6;
100
+ layerScaleX = render_queue[index++];
101
+ layerScaleY = render_queue[index++];
59
102
  colorTransform = render_queue.subarray(index, index + 8);
60
103
  index += 8;
61
104
  const length = render_queue[index++];
@@ -71,7 +114,12 @@ export const execute = (render_queue, index, image_bitmaps) => {
71
114
  }
72
115
  }
73
116
  // コンテナのフィルター/ブレンド用にレイヤーを開始
74
- if (useLayer) {
117
+ let cacheNode = null;
118
+ if (useCacheAsBitmap) {
119
+ // cacheAsBitmap: temp FBO作成→子要素描画→アトラスノードへコピー
120
+ cacheNode = $context.containerBeginAtlasNode(layerWidth, layerHeight);
121
+ }
122
+ else if (useLayer) {
75
123
  $context.containerBeginLayer(layerWidth, layerHeight);
76
124
  }
77
125
  const useMaskDisplayObject = Boolean(render_queue[index++]);
@@ -173,8 +221,24 @@ export const execute = (render_queue, index, image_bitmaps) => {
173
221
  $context.leaveMask();
174
222
  }
175
223
  // コンテナのフィルター/ブレンド結果をメインに合成
176
- if (useLayer) {
177
- $context.containerEndLayer(blendMode, matrix, colorTransform, useFilter, filterBounds, filterParams, uniqueKey, filterKey);
224
+ if (cacheNode) {
225
+ // cacheAsBitmap: アトラス描画終了→キャッシュ→インスタンス描画
226
+ $context.containerEndAtlasNode();
227
+ // 古いノードを解放
228
+ const oldNode = $cacheStore.get(uniqueKey, "bNode");
229
+ if (oldNode) {
230
+ $context.removeNode(oldNode);
231
+ }
232
+ $cacheStore.set(uniqueKey, "bNode", cacheNode);
233
+ $cacheStore.set(uniqueKey, "bKey", filterKey);
234
+ // アトラスからインスタンス描画(Shapeと同様にmatrix/renderScaleで描画)
235
+ $context.globalAlpha = Math.min(Math.max(0, colorTransform[3] + colorTransform[7] / 255), 1);
236
+ $context.globalCompositeOperation = blendMode;
237
+ $context.setTransform(matrix[0] / cacheRenderScaleX, matrix[1] / cacheRenderScaleX, matrix[2] / cacheRenderScaleY, matrix[3] / cacheRenderScaleY, matrix[4], matrix[5]);
238
+ $context.drawDisplayObject(cacheNode, filterBounds[0], filterBounds[1], filterBounds[2], filterBounds[3], colorTransform);
239
+ }
240
+ else if (useLayer) {
241
+ $context.containerEndLayer(blendMode, matrix, colorTransform, useFilter, filterBounds, filterParams, uniqueKey, filterKey, layerScaleX, layerScaleY);
178
242
  }
179
243
  return index;
180
244
  };
@@ -26,7 +26,9 @@ export const execute = (render_queue, index) => {
26
26
  const yMax = render_queue[index++];
27
27
  const isGridEnabled = Boolean(render_queue[index++]);
28
28
  const isDrawable = Boolean(render_queue[index++]);
29
- const isBitmap = Boolean(render_queue[index++]);
29
+ const renderMode = render_queue[index++]; // 0=vector, 1=bitmap, 2=cacheAsBitmap
30
+ const isBitmap = renderMode === 1;
31
+ const isCacheAsBitmap = renderMode === 2;
30
32
  // cache uniqueKey
31
33
  const uniqueKey = `${render_queue[index++]}`;
32
34
  const cacheKey = render_queue[index++];
@@ -138,6 +140,14 @@ export const execute = (render_queue, index) => {
138
140
  $context.setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
139
141
  $context.drawDisplayObject(node, bounds[0], bounds[1], bounds[2], bounds[3], colorTransform);
140
142
  }
143
+ else if (isCacheAsBitmap) {
144
+ // cacheAsBitmap: Bitmapと同様の描画パスで、cacheScaleを補正
145
+ // baseBounds原点(xMin,yMin)のスクリーン座標をtranslationに反映
146
+ const screenX = matrix[0] * xMin + matrix[2] * yMin + matrix[4];
147
+ const screenY = matrix[1] * xMin + matrix[3] * yMin + matrix[5];
148
+ $context.setTransform(matrix[0] / xScale, matrix[1] / xScale, matrix[2] / yScale, matrix[3] / yScale, screenX, screenY);
149
+ $context.drawDisplayObject(node, bounds[0], bounds[1], bounds[2], bounds[3], colorTransform);
150
+ }
141
151
  else {
142
152
  const radianX = Math.atan2(matrix[1], matrix[0]);
143
153
  const radianY = Math.atan2(-matrix[2], matrix[3]);
@@ -32,8 +32,10 @@ export const execute = (render_queue, index) => {
32
32
  // cache uniqueKey
33
33
  const uniqueKey = `${render_queue[index++]}`;
34
34
  const cacheKey = render_queue[index++];
35
- // text state
36
- const changed = Boolean(render_queue[index++]);
35
+ // text state (bit 0 = changed, bit 1 = cacheAsBitmap)
36
+ const changedFlag = render_queue[index++];
37
+ const changed = Boolean(changedFlag & 1);
38
+ const isCacheAsBitmap = Boolean(changedFlag & 2);
37
39
  const xScale = render_queue[index++];
38
40
  const yScale = render_queue[index++];
39
41
  // フィルターキャッシュ用のユニークキー(instanceId)
@@ -133,19 +135,28 @@ export const execute = (render_queue, index) => {
133
135
  $context.globalAlpha = Math.min(Math.max(0, colorTransform[3] + colorTransform[7] / 255), 1);
134
136
  $context.imageSmoothingEnabled = true;
135
137
  $context.globalCompositeOperation = displayObjectGetBlendModeService(blendMode);
136
- const radianX = Math.atan2(matrix[1], matrix[0]);
137
- const radianY = Math.atan2(-matrix[2], matrix[3]);
138
- if (radianX || radianY) {
139
- const tx = xMin * xScale;
140
- const ty = yMin * yScale;
141
- const cosX = Math.cos(radianX);
142
- const sinX = Math.sin(radianX);
143
- const cosY = Math.cos(radianY);
144
- const sinY = Math.sin(radianY);
145
- $context.setTransform(cosX, sinX, -sinY, cosY, tx * cosX - ty * sinY + matrix[4], tx * sinX + ty * cosY + matrix[5]);
138
+ if (isCacheAsBitmap) {
139
+ // cacheAsBitmap: Bitmapと同様の描画パスで、cacheScaleを補正
140
+ // baseBounds原点(xMin,yMin)のスクリーン座標をtranslationに反映
141
+ const screenX = matrix[0] * xMin + matrix[2] * yMin + matrix[4];
142
+ const screenY = matrix[1] * xMin + matrix[3] * yMin + matrix[5];
143
+ $context.setTransform(matrix[0] / xScale, matrix[1] / xScale, matrix[2] / yScale, matrix[3] / yScale, screenX, screenY);
146
144
  }
147
145
  else {
148
- $context.setTransform(1, 0, 0, 1, bounds[0], bounds[1]);
146
+ const radianX = Math.atan2(matrix[1], matrix[0]);
147
+ const radianY = Math.atan2(-matrix[2], matrix[3]);
148
+ if (radianX || radianY) {
149
+ const tx = xMin * xScale;
150
+ const ty = yMin * yScale;
151
+ const cosX = Math.cos(radianX);
152
+ const sinX = Math.sin(radianX);
153
+ const cosY = Math.cos(radianY);
154
+ const sinY = Math.sin(radianY);
155
+ $context.setTransform(cosX, sinX, -sinY, cosY, tx * cosX - ty * sinY + matrix[4], tx * sinX + ty * cosY + matrix[5]);
156
+ }
157
+ else {
158
+ $context.setTransform(1, 0, 0, 1, bounds[0], bounds[1]);
159
+ }
149
160
  }
150
161
  // 描画範囲をinstanced arrayに設定
151
162
  $context.drawDisplayObject(node, bounds[0], bounds[1], bounds[2], bounds[3], colorTransform);