@next2d/webgl 3.18.0 → 3.19.1

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.
Files changed (24) hide show
  1. package/package.json +3 -3
  2. package/src/Context/usecase/ContextBindUseCase.d.ts +12 -0
  3. package/src/Context/usecase/ContextBindUseCase.js +44 -14
  4. package/src/Context/usecase/ContextDeferBindUseCase.d.ts +18 -0
  5. package/src/Context/usecase/ContextDeferBindUseCase.js +28 -0
  6. package/src/Context/usecase/ContextDrawFillUseCase.js +9 -0
  7. package/src/Context/usecase/ContextSyncAttachmentUseCase.d.ts +13 -0
  8. package/src/Context/usecase/ContextSyncAttachmentUseCase.js +21 -0
  9. package/src/Context.d.ts +15 -0
  10. package/src/Context.js +98 -1
  11. package/src/FrameBufferManager/service/FrameBufferManagerBindAttachmentObjectService.js +3 -1
  12. package/src/FrameBufferManager/service/FrameBufferManagerUnBindAttachmentObjectService.js +3 -1
  13. package/src/FrameBufferManager.d.ts +37 -0
  14. package/src/FrameBufferManager.js +41 -0
  15. package/src/Shader/GradientLUTCache.d.ts +81 -0
  16. package/src/Shader/GradientLUTCache.js +213 -0
  17. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTDrawShapeTextureUseCase.d.ts +16 -0
  18. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTDrawShapeTextureUseCase.js +37 -0
  19. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTGenerateShapeTextureUseCase.d.ts +6 -6
  20. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTGenerateShapeTextureUseCase.js +20 -30
  21. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTPrepareShapeTexturesUseCase.d.ts +16 -0
  22. package/src/Shader/GradientLUTGenerator/usecase/GradientLUTPrepareShapeTexturesUseCase.js +89 -0
  23. package/src/interface/IGradientLUTSlot.d.ts +9 -0
  24. package/src/interface/IGradientLUTSlot.js +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/webgl",
3
- "version": "3.18.0",
3
+ "version": "3.19.1",
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.18.0",
28
- "@next2d/render-queue": "3.18.0"
27
+ "@next2d/texture-packer": "3.19.1",
28
+ "@next2d/render-queue": "3.19.1"
29
29
  }
30
30
  }
@@ -1,5 +1,17 @@
1
1
  import type { IAttachmentObject } from "../../interface/IAttachmentObject";
2
2
  import type { Context } from "../../Context";
3
+ /**
4
+ * @description GL のフレームバッファを attachment_object に切り替える
5
+ * Switch the GL framebuffer to attachment_object
6
+ *
7
+ * @param {Context} context
8
+ * @param {IAttachmentObject} attachment_object
9
+ * @param {IAttachmentObject | null} previous 直前まで GL に付いていたアタッチメントオブジェクト
10
+ * @return {void}
11
+ * @method
12
+ * @protected
13
+ */
14
+ export declare const $bindPhysical: (context: Context, attachment_object: IAttachmentObject, previous: IAttachmentObject | null) => void;
3
15
  /**
4
16
  * @description アタッチメントオブジェクトのサイズに変更・初期化し、フレームバッファにアタッチメントオブジェクトをバインドする
5
17
  * Change and initialize to the size of the attachment object and bind the attachment object to the frame buffer
@@ -1,30 +1,26 @@
1
- import { $currentAttachment } from "../../FrameBufferManager";
1
+ import { $currentAttachment, $setCurrentAttachment, $physicalAttachment, $attachmentDeferred, $setAttachmentDeferred, $isFramebufferBound } from "../../FrameBufferManager";
2
2
  import { execute as frameBufferManagerBindAttachmentObjectService } from "../../FrameBufferManager/service/FrameBufferManagerBindAttachmentObjectService";
3
3
  import { execute as maskBindUseCase } from "../../Mask/usecase/MaskBindUseCase";
4
4
  import { $gl, $setViewportSize } from "../../WebGLUtil";
5
5
  /**
6
- * @description アタッチメントオブジェクトのサイズに変更・初期化し、フレームバッファにアタッチメントオブジェクトをバインドする
7
- * Change and initialize to the size of the attachment object and bind the attachment object to the frame buffer
6
+ * @description GL のフレームバッファを attachment_object に切り替える
7
+ * Switch the GL framebuffer to attachment_object
8
8
  *
9
9
  * @param {Context} context
10
10
  * @param {IAttachmentObject} attachment_object
11
+ * @param {IAttachmentObject | null} previous 直前まで GL に付いていたアタッチメントオブジェクト
11
12
  * @return {void}
12
13
  * @method
13
14
  * @protected
14
15
  */
15
- export const execute = (context, attachment_object) => {
16
- // fixed logic
17
- const currentAttachment = $currentAttachment;
18
- if (currentAttachment
19
- && attachment_object.id === currentAttachment.id) {
20
- return;
21
- }
16
+ export const $bindPhysical = (context, attachment_object, previous) => {
22
17
  // フレームバッファにアタッチメントオブジェクトをバインドする
23
18
  frameBufferManagerBindAttachmentObjectService(attachment_object);
24
- if (!currentAttachment
25
- || currentAttachment.width !== attachment_object.width
26
- || currentAttachment.height !== attachment_object.height) {
27
- $setViewportSize(attachment_object.width, attachment_object.height);
19
+ // ビューポートの大きさは、切り替えを保留している間に書き換わっていることがあるので必ず合わせる
20
+ $setViewportSize(attachment_object.width, attachment_object.height);
21
+ if (!previous
22
+ || previous.width !== attachment_object.width
23
+ || previous.height !== attachment_object.height) {
28
24
  $gl.viewport(0, 0, attachment_object.width, attachment_object.height);
29
25
  }
30
26
  // カラーバッファorステンシルバッファが、未初期化の場合はクリアする
@@ -45,3 +41,37 @@ export const execute = (context, attachment_object) => {
45
41
  // mask bind
46
42
  maskBindUseCase(attachment_object.mask);
47
43
  };
44
+ /**
45
+ * @description アタッチメントオブジェクトのサイズに変更・初期化し、フレームバッファにアタッチメントオブジェクトをバインドする
46
+ * Change and initialize to the size of the attachment object and bind the attachment object to the frame buffer
47
+ *
48
+ * @param {Context} context
49
+ * @param {IAttachmentObject} attachment_object
50
+ * @return {void}
51
+ * @method
52
+ * @protected
53
+ */
54
+ export const execute = (context, attachment_object) => {
55
+ // 描画先の切り替えを保留している間 (ContextDeferBindUseCase): GL にはまだ前の描画先が付いている
56
+ if ($attachmentDeferred) {
57
+ $setAttachmentDeferred(false);
58
+ const physical = $physicalAttachment;
59
+ if (physical
60
+ && physical.id === attachment_object.id
61
+ && $isFramebufferBound) {
62
+ // GL に付いたままの描画先へ戻るだけ: 何も切り替えずに済む
63
+ $setCurrentAttachment(attachment_object);
64
+ $setViewportSize(attachment_object.width, attachment_object.height);
65
+ return;
66
+ }
67
+ $bindPhysical(context, attachment_object, physical);
68
+ return;
69
+ }
70
+ // fixed logic
71
+ const currentAttachment = $currentAttachment;
72
+ if (currentAttachment
73
+ && attachment_object.id === currentAttachment.id) {
74
+ return;
75
+ }
76
+ $bindPhysical(context, attachment_object, currentAttachment);
77
+ };
@@ -0,0 +1,18 @@
1
+ import type { IAttachmentObject } from "../../interface/IAttachmentObject";
2
+ /**
3
+ * @description 描画先を attachment_object に切り替えるが、GL のフレームバッファの切り替えは、実際に GL で
4
+ * 描く時点まで保留する。アトラスへ図形を描いた後に元の描画先へ戻す処理で使う: 未キャッシュの
5
+ * 図形が続くと、次の図形がすぐにアトラスへ切り替え直すので、戻す切り替えは無駄になる。
6
+ * 現在の描画先とビューポートの大きさ (どちらも JavaScript の値) は、ここで切り替え後の値にする。
7
+ * Switch the render target to attachment_object, but postpone switching the GL framebuffer
8
+ * until something is actually drawn with GL. Used to go back to the previous target after
9
+ * drawing a shape into the atlas: when uncached shapes follow one another, the next one
10
+ * switches straight back to the atlas, so switching back in between is wasted. The current
11
+ * attachment and the viewport size (both JavaScript values) take their new values here.
12
+ *
13
+ * @param {IAttachmentObject} attachment_object
14
+ * @return {void}
15
+ * @method
16
+ * @protected
17
+ */
18
+ export declare const execute: (attachment_object: IAttachmentObject) => void;
@@ -0,0 +1,28 @@
1
+ import { $currentAttachment, $setCurrentAttachment, $setAttachmentDeferred } from "../../FrameBufferManager";
2
+ import { $setViewportSize } from "../../WebGLUtil";
3
+ /**
4
+ * @description 描画先を attachment_object に切り替えるが、GL のフレームバッファの切り替えは、実際に GL で
5
+ * 描く時点まで保留する。アトラスへ図形を描いた後に元の描画先へ戻す処理で使う: 未キャッシュの
6
+ * 図形が続くと、次の図形がすぐにアトラスへ切り替え直すので、戻す切り替えは無駄になる。
7
+ * 現在の描画先とビューポートの大きさ (どちらも JavaScript の値) は、ここで切り替え後の値にする。
8
+ * Switch the render target to attachment_object, but postpone switching the GL framebuffer
9
+ * until something is actually drawn with GL. Used to go back to the previous target after
10
+ * drawing a shape into the atlas: when uncached shapes follow one another, the next one
11
+ * switches straight back to the atlas, so switching back in between is wasted. The current
12
+ * attachment and the viewport size (both JavaScript values) take their new values here.
13
+ *
14
+ * @param {IAttachmentObject} attachment_object
15
+ * @return {void}
16
+ * @method
17
+ * @protected
18
+ */
19
+ export const execute = (attachment_object) => {
20
+ const currentAttachment = $currentAttachment;
21
+ if (currentAttachment
22
+ && attachment_object.id === currentAttachment.id) {
23
+ return;
24
+ }
25
+ $setCurrentAttachment(attachment_object);
26
+ $setViewportSize(attachment_object.width, attachment_object.height);
27
+ $setAttachmentDeferred(true);
28
+ };
@@ -5,6 +5,8 @@ import { execute as contextLinearGradientFillUseCase } from "./ContextLinearGrad
5
5
  import { execute as contextRadialGradientFillUseCase } from "./ContextRadialGradientFillUseCase";
6
6
  import { execute as contextPatternBitmapFillUseCase } from "./ContextPatternBitmapFillUseCase";
7
7
  import { execute as stencilResetService } from "../../Stencil/service/StencilResetService";
8
+ import { execute as gradientLUTPrepareShapeTexturesUseCase } from "../../Shader/GradientLUTGenerator/usecase/GradientLUTPrepareShapeTexturesUseCase";
9
+ import { $gradientData } from "../../Gradient";
8
10
  import { $gl, $enableStencilTest, $disableStencilTest } from "../../WebGLUtil";
9
11
  import { $terminateGrid, $gridDataMap } from "../../Grid";
10
12
  import { $fillBufferIndexes, $fillTypes, $clearFillBufferSetting } from "../../Mesh";
@@ -23,6 +25,13 @@ export const execute = () => {
23
25
  $gl.stencilMask(0xff);
24
26
  // Reset stencil cache at the start of fill processing
25
27
  stencilResetService();
28
+ // グラデーションの LUT は、塗りごとではなく、ここでまとめて先に描く
29
+ // (LUT を描いた場合はステンシルテストが無効になっているので、戻す)
30
+ if ($gradientData.length && gradientLUTPrepareShapeTexturesUseCase()) {
31
+ $enableStencilTest();
32
+ $gl.stencilMask(0xff);
33
+ stencilResetService();
34
+ }
26
35
  let fillOffset = 0;
27
36
  let gridData = null;
28
37
  for (let idx = 0; idx < $fillTypes.length; idx++) {
@@ -0,0 +1,13 @@
1
+ import type { Context } from "../../Context";
2
+ /**
3
+ * @description 保留していた描画先の切り替え (ContextDeferBindUseCase) を、GL のフレームバッファに反映する。
4
+ * GL で描く処理の先頭で、$attachmentDeferred が true のときに呼ぶ。
5
+ * Apply the postponed render target switch (ContextDeferBindUseCase) to the GL framebuffer.
6
+ * Called at the start of anything that draws with GL, when $attachmentDeferred is true.
7
+ *
8
+ * @param {Context} context
9
+ * @return {void}
10
+ * @method
11
+ * @protected
12
+ */
13
+ export declare const execute: (context: Context) => void;
@@ -0,0 +1,21 @@
1
+ import { $currentAttachment, $physicalAttachment, $setAttachmentDeferred } from "../../FrameBufferManager";
2
+ import { $bindPhysical } from "./ContextBindUseCase";
3
+ /**
4
+ * @description 保留していた描画先の切り替え (ContextDeferBindUseCase) を、GL のフレームバッファに反映する。
5
+ * GL で描く処理の先頭で、$attachmentDeferred が true のときに呼ぶ。
6
+ * Apply the postponed render target switch (ContextDeferBindUseCase) to the GL framebuffer.
7
+ * Called at the start of anything that draws with GL, when $attachmentDeferred is true.
8
+ *
9
+ * @param {Context} context
10
+ * @return {void}
11
+ * @method
12
+ * @protected
13
+ */
14
+ export const execute = (context) => {
15
+ $setAttachmentDeferred(false);
16
+ const attachment = $currentAttachment;
17
+ if (!attachment) {
18
+ return;
19
+ }
20
+ $bindPhysical(context, attachment, $physicalAttachment);
21
+ };
package/src/Context.d.ts CHANGED
@@ -31,6 +31,21 @@ export declare class Context {
31
31
  resize(width: number, height: number, cache_clear?: boolean): void;
32
32
  clearRect(x: number, y: number, w: number, h: number): void;
33
33
  bind(attachment_object: IAttachmentObject): void;
34
+ /**
35
+ * @description 描画先を attachment_object に戻す。GL のフレームバッファの切り替えは、次に GL で描く時点まで
36
+ * 保留する (すぐ次の処理が同じ描画先へ切り替え直す場合、切り替えそのものを省ける)。
37
+ * アトラスへ描いた後に、元の描画先へ戻すときに使う。
38
+ * Go back to attachment_object as the render target. Switching the GL framebuffer is
39
+ * postponed until the next GL draw (and skipped altogether when the next operation
40
+ * switches straight back). Use it to return to the previous target after drawing
41
+ * into the atlas.
42
+ *
43
+ * @param {IAttachmentObject} attachment_object
44
+ * @return {void}
45
+ * @method
46
+ * @public
47
+ */
48
+ deferBind(attachment_object: IAttachmentObject): void;
34
49
  queueTextElement(node: Node, canvas: OffscreenCanvas): boolean;
35
50
  save(): void;
36
51
  restore(): void;
package/src/Context.js CHANGED
@@ -14,6 +14,8 @@ import { execute as contextFillBackgroundColorService } from "./Context/service/
14
14
  import { execute as contextResizeUseCase } from "./Context/usecase/ContextResizeUseCase";
15
15
  import { execute as contextClearRectUseCase } from "./Context/usecase/ContextClearRectUseCase";
16
16
  import { execute as contextBindUseCase } from "./Context/usecase/ContextBindUseCase";
17
+ import { execute as contextDeferBindUseCase } from "./Context/usecase/ContextDeferBindUseCase";
18
+ import { execute as contextSyncAttachmentUseCase } from "./Context/usecase/ContextSyncAttachmentUseCase";
17
19
  import { execute as contextSaveService } from "./Context/service/ContextSaveService";
18
20
  import { execute as contextRestoreService } from "./Context/service/ContextRestoreService";
19
21
  import { execute as contextSetTransformService } from "./Context/service/ContextSetTransformService";
@@ -55,7 +57,7 @@ import { execute as contextDrawFillUseCase } from "./Context/usecase/ContextDraw
55
57
  import { execute as contextCreateImageBitmapService } from "./Context/service/ContextCreateImageBitmapService";
56
58
  import { $setGradientLUTGeneratorMaxLength } from "./Shader/GradientLUTGenerator";
57
59
  import { $getAtlasAttachmentObject, $clearTransferBounds, $getAtlasTextureObject, $setAtlasPageDirty, $rootNodes, $setActiveAtlasIndex } from "./AtlasManager";
58
- import { $setReadFrameBuffer, $setDrawFrameBuffer, $currentAttachment, $setAtlasFrameBuffer, $setBitmapFrameBuffer } from "./FrameBufferManager";
60
+ import { $setReadFrameBuffer, $setDrawFrameBuffer, $currentAttachment, $attachmentDeferred, $setAtlasFrameBuffer, $setBitmapFrameBuffer } from "./FrameBufferManager";
59
61
  import { $setRenderMaxSize, $setWebGL2RenderingContext, $setSamples, $getFloat32Array9, $getArray, $setContext, $setDevicePixelRatio } from "./WebGLUtil";
60
62
  export class Context {
61
63
  constructor(gl, samples, device_pixel_ratio = 1) {
@@ -124,14 +126,23 @@ export class Context {
124
126
  contextUpdateBackgroundColorService(this, red, green, blue, alpha);
125
127
  }
126
128
  fillBackgroundColor() {
129
+ if ($attachmentDeferred) {
130
+ contextSyncAttachmentUseCase(this);
131
+ }
127
132
  flushTextUploads();
128
133
  contextFillBackgroundColorService(this.$clearColorR, this.$clearColorG, this.$clearColorB, this.$clearColorA);
129
134
  }
130
135
  resize(width, height, cache_clear = true) {
136
+ if ($attachmentDeferred) {
137
+ contextSyncAttachmentUseCase(this);
138
+ }
131
139
  disposeTextUploads();
132
140
  contextResizeUseCase(this, width, height, cache_clear);
133
141
  }
134
142
  clearRect(x, y, w, h) {
143
+ if ($attachmentDeferred) {
144
+ contextSyncAttachmentUseCase(this);
145
+ }
135
146
  flushTextUploads();
136
147
  contextClearRectUseCase(x, y, w, h);
137
148
  }
@@ -139,6 +150,23 @@ export class Context {
139
150
  flushTextUploads();
140
151
  contextBindUseCase(this, attachment_object);
141
152
  }
153
+ /**
154
+ * @description 描画先を attachment_object に戻す。GL のフレームバッファの切り替えは、次に GL で描く時点まで
155
+ * 保留する (すぐ次の処理が同じ描画先へ切り替え直す場合、切り替えそのものを省ける)。
156
+ * アトラスへ描いた後に、元の描画先へ戻すときに使う。
157
+ * Go back to attachment_object as the render target. Switching the GL framebuffer is
158
+ * postponed until the next GL draw (and skipped altogether when the next operation
159
+ * switches straight back). Use it to return to the previous target after drawing
160
+ * into the atlas.
161
+ *
162
+ * @param {IAttachmentObject} attachment_object
163
+ * @return {void}
164
+ * @method
165
+ * @public
166
+ */
167
+ deferBind(attachment_object) {
168
+ contextDeferBindUseCase(attachment_object);
169
+ }
142
170
  queueTextElement(node, canvas) {
143
171
  return queueTextUpload(node, canvas);
144
172
  }
@@ -155,6 +183,9 @@ export class Context {
155
183
  contextTransformService(this, a, b, c, d, e, f);
156
184
  }
157
185
  reset() {
186
+ if ($attachmentDeferred) {
187
+ contextSyncAttachmentUseCase(this);
188
+ }
158
189
  flushTextUploads();
159
190
  contextResetService(this);
160
191
  }
@@ -219,30 +250,51 @@ export class Context {
219
250
  bezierCurveTo(cx1, cy1, cx2, cy2, x, y);
220
251
  }
221
252
  fill() {
253
+ if ($attachmentDeferred) {
254
+ contextSyncAttachmentUseCase(this);
255
+ }
222
256
  flushTextUploads();
223
257
  contextFillUseCase("fill");
224
258
  }
225
259
  gradientFill(type, stops, matrix, spread, interpolation, focal) {
260
+ if ($attachmentDeferred) {
261
+ contextSyncAttachmentUseCase(this);
262
+ }
226
263
  flushTextUploads();
227
264
  contextGradientFillUseCase(type, stops, matrix, spread, interpolation, focal);
228
265
  }
229
266
  bitmapFill(pixels, matrix, width, height, repeat, smooth) {
267
+ if ($attachmentDeferred) {
268
+ contextSyncAttachmentUseCase(this);
269
+ }
230
270
  flushTextUploads();
231
271
  contextBitmapFillUseCase(pixels, matrix, width, height, repeat, smooth);
232
272
  }
233
273
  stroke() {
274
+ if ($attachmentDeferred) {
275
+ contextSyncAttachmentUseCase(this);
276
+ }
234
277
  flushTextUploads();
235
278
  contextStrokeUseCase();
236
279
  }
237
280
  gradientStroke(type, stops, matrix, spread, interpolation, focal) {
281
+ if ($attachmentDeferred) {
282
+ contextSyncAttachmentUseCase(this);
283
+ }
238
284
  flushTextUploads();
239
285
  contextGradientStrokeUseCase(type, stops, matrix, spread, interpolation, focal);
240
286
  }
241
287
  bitmapStroke(pixels, matrix, width, height, repeat, smooth) {
288
+ if ($attachmentDeferred) {
289
+ contextSyncAttachmentUseCase(this);
290
+ }
242
291
  flushTextUploads();
243
292
  contextBitmapStrokeUseCase(pixels, matrix, width, height, repeat, smooth);
244
293
  }
245
294
  clip() {
295
+ if ($attachmentDeferred) {
296
+ contextSyncAttachmentUseCase(this);
297
+ }
246
298
  flushTextUploads();
247
299
  contextClipUseCase();
248
300
  }
@@ -298,6 +350,9 @@ export class Context {
298
350
  }
299
351
  }
300
352
  beginNodeRendering(node) {
353
+ if ($attachmentDeferred) {
354
+ contextSyncAttachmentUseCase(this);
355
+ }
301
356
  flushTextUploads();
302
357
  this.newDrawState = true;
303
358
  // このページには未解決の描き込みがある(次回の解決対象)
@@ -306,10 +361,16 @@ export class Context {
306
361
  contextBeginNodeRenderingService(node.x, node.y, node.w, node.h);
307
362
  }
308
363
  endNodeRendering() {
364
+ if ($attachmentDeferred) {
365
+ contextSyncAttachmentUseCase(this);
366
+ }
309
367
  flushTextUploads();
310
368
  contextEndNodeRenderingService();
311
369
  }
312
370
  drawFill() {
371
+ if ($attachmentDeferred) {
372
+ contextSyncAttachmentUseCase(this);
373
+ }
313
374
  flushTextUploads();
314
375
  contextDrawFillUseCase();
315
376
  }
@@ -318,6 +379,9 @@ export class Context {
318
379
  blnedDrawDisplayObjectUseCase(node, x_min, y_min, x_max, y_max, color_transform, color_transform_offset);
319
380
  }
320
381
  drawArraysInstanced() {
382
+ if ($attachmentDeferred) {
383
+ contextSyncAttachmentUseCase(this);
384
+ }
321
385
  flushTextUploads();
322
386
  blnedDrawArraysInstancedUseCase();
323
387
  }
@@ -325,26 +389,44 @@ export class Context {
325
389
  blnedClearArraysInstancedUseCase();
326
390
  }
327
391
  transferMainCanvas() {
392
+ if ($attachmentDeferred) {
393
+ contextSyncAttachmentUseCase(this);
394
+ }
328
395
  flushTextUploads();
329
396
  frameBufferManagerTransferMainCanvasService();
330
397
  }
331
398
  drawPixels(node, pixels) {
399
+ if ($attachmentDeferred) {
400
+ contextSyncAttachmentUseCase(this);
401
+ }
332
402
  flushTextUploads();
333
403
  contextDrawPixelsUseCase(node, pixels);
334
404
  }
335
405
  drawElement(node, element, _flipY = false) {
406
+ if ($attachmentDeferred) {
407
+ contextSyncAttachmentUseCase(this);
408
+ }
336
409
  flushTextUploads();
337
410
  contextDrawElementUseCase(node, element);
338
411
  }
339
412
  beginMask() {
413
+ if ($attachmentDeferred) {
414
+ contextSyncAttachmentUseCase(this);
415
+ }
340
416
  flushTextUploads();
341
417
  maskBeginMaskService();
342
418
  }
343
419
  setMaskBounds(x_min, y_min, x_max, y_max) {
420
+ if ($attachmentDeferred) {
421
+ contextSyncAttachmentUseCase(this);
422
+ }
344
423
  flushTextUploads();
345
424
  maskSetMaskBoundsService(x_min, y_min, x_max, y_max);
346
425
  }
347
426
  endMask() {
427
+ if ($attachmentDeferred) {
428
+ contextSyncAttachmentUseCase(this);
429
+ }
348
430
  flushTextUploads();
349
431
  maskEndMaskService();
350
432
  }
@@ -364,6 +446,9 @@ export class Context {
364
446
  contextContainerBeginLayerUseCase(width, height);
365
447
  }
366
448
  containerEndLayer(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key, layer_scale_x = 1, layer_scale_y = 1) {
449
+ if ($attachmentDeferred) {
450
+ contextSyncAttachmentUseCase(this);
451
+ }
367
452
  contextContainerEndLayerUseCase(blend_mode, matrix, color_transform, use_filter, filter_bounds, filter_params, unique_key, filter_key, layer_scale_x, layer_scale_y);
368
453
  }
369
454
  containerBeginAtlasNode(width, height) {
@@ -376,17 +461,29 @@ export class Context {
376
461
  return node;
377
462
  }
378
463
  containerEndAtlasNode() {
464
+ if ($attachmentDeferred) {
465
+ contextSyncAttachmentUseCase(this);
466
+ }
379
467
  const node = this._pendingAtlasNodes.pop();
380
468
  contextContainerEndAtlasNodeUseCase(node);
381
469
  }
382
470
  containerDrawCachedFilter(blend_mode, matrix, color_transform, filter_bounds, unique_key, filter_key) {
471
+ if ($attachmentDeferred) {
472
+ contextSyncAttachmentUseCase(this);
473
+ }
383
474
  contextContainerDrawCachedFilterUseCase(blend_mode, matrix, color_transform, filter_bounds, unique_key, filter_key);
384
475
  }
385
476
  async createImageBitmap(width, height) {
477
+ if ($attachmentDeferred) {
478
+ contextSyncAttachmentUseCase(this);
479
+ }
386
480
  flushTextUploads();
387
481
  return await contextCreateImageBitmapService(width, height);
388
482
  }
389
483
  getRenderCompletion() {
484
+ if ($attachmentDeferred) {
485
+ contextSyncAttachmentUseCase(this);
486
+ }
390
487
  flushTextUploads();
391
488
  return contextGetRenderCompletionService();
392
489
  }
@@ -1,7 +1,7 @@
1
1
  import { $gl } from "../../WebGLUtil";
2
2
  import { execute as textureManagerBind0UseCase } from "../../TextureManager/usecase/TextureManagerBind0UseCase";
3
3
  import { execute as textureManagerBindService } from "../../TextureManager/service/TextureManagerBindService";
4
- import { $setFramebufferBound, $setCurrentAttachment, $readFrameBuffer, $isFramebufferBound, $attachedColor, $setAttachedColor, $attachedStencil, $setAttachedStencil } from "../../FrameBufferManager";
4
+ import { $setFramebufferBound, $setCurrentAttachment, $setPhysicalAttachment, $setAttachmentDeferred, $readFrameBuffer, $isFramebufferBound, $attachedColor, $setAttachedColor, $attachedStencil, $setAttachedStencil } from "../../FrameBufferManager";
5
5
  /**
6
6
  * @description フレームバッファにアタッチメントオブジェクトをバインドする
7
7
  * Bind the attachment object to the frame buffer
@@ -13,6 +13,8 @@ import { $setFramebufferBound, $setCurrentAttachment, $readFrameBuffer, $isFrame
13
13
  */
14
14
  export const execute = (attachment_object) => {
15
15
  $setCurrentAttachment(attachment_object);
16
+ $setPhysicalAttachment(attachment_object);
17
+ $setAttachmentDeferred(false);
16
18
  if (!$isFramebufferBound) {
17
19
  $setFramebufferBound(true);
18
20
  $gl.bindFramebuffer($gl.FRAMEBUFFER, $readFrameBuffer);
@@ -1,5 +1,5 @@
1
1
  import { $gl } from "../../WebGLUtil";
2
- import { $setCurrentAttachment, $isFramebufferBound, $setFramebufferBound } from "../../FrameBufferManager";
2
+ import { $setCurrentAttachment, $setPhysicalAttachment, $setAttachmentDeferred, $isFramebufferBound, $setFramebufferBound } from "../../FrameBufferManager";
3
3
  /**
4
4
  * @description 現在アタッチされているFramebufferのバインド解除
5
5
  * Unbind the currently attached Framebuffer
@@ -10,6 +10,8 @@ import { $setCurrentAttachment, $isFramebufferBound, $setFramebufferBound } from
10
10
  */
11
11
  export const execute = () => {
12
12
  $setCurrentAttachment(null);
13
+ $setPhysicalAttachment(null);
14
+ $setAttachmentDeferred(false);
13
15
  if ($isFramebufferBound) {
14
16
  $setFramebufferBound(false);
15
17
  $gl.bindFramebuffer($gl.FRAMEBUFFER, null);
@@ -48,6 +48,43 @@ export declare let $atlasFrameBuffer: WebGLFramebuffer | null;
48
48
  export declare const $setAtlasFrameBuffer: (gl: WebGL2RenderingContext) => void;
49
49
  export declare let $currentAttachment: IAttachmentObject | null;
50
50
  export declare const $setCurrentAttachment: (attachment_object: IAttachmentObject | null) => void;
51
+ /**
52
+ * @description GL のフレームバッファに実際に付いているアタッチメントオブジェクト。
53
+ * 通常は $currentAttachment と同じ。$attachmentDeferred が true の間だけ違う。
54
+ * The attachment object actually attached to the GL framebuffer. Normally the same as
55
+ * $currentAttachment; they differ only while $attachmentDeferred is true.
56
+ *
57
+ * @type {IAttachmentObject | null}
58
+ * @public
59
+ */
60
+ export declare let $physicalAttachment: IAttachmentObject | null;
61
+ /**
62
+ * @param {IAttachmentObject | null} attachment_object
63
+ * @return {void}
64
+ * @method
65
+ * @public
66
+ */
67
+ export declare const $setPhysicalAttachment: (attachment_object: IAttachmentObject | null) => void;
68
+ /**
69
+ * @description 描画先の切り替えを保留しているかどうか。true の間、$currentAttachment (とビューポートの
70
+ * 大きさ) は切り替え後の値だが、GL のフレームバッファは $physicalAttachment のまま。
71
+ * GL で描く前に ContextSyncAttachmentUseCase で実際に切り替える。
72
+ * Whether a render target switch is pending. While true, $currentAttachment (and the
73
+ * viewport size) already hold the new target but the GL framebuffer still has
74
+ * $physicalAttachment. ContextSyncAttachmentUseCase performs the switch before
75
+ * anything is drawn with GL.
76
+ *
77
+ * @type {boolean}
78
+ * @public
79
+ */
80
+ export declare let $attachmentDeferred: boolean;
81
+ /**
82
+ * @param {boolean} state
83
+ * @return {void}
84
+ * @method
85
+ * @public
86
+ */
87
+ export declare const $setAttachmentDeferred: (state: boolean) => void;
51
88
  export declare let $isFramebufferBound: boolean;
52
89
  export declare const $setFramebufferBound: (state: boolean) => void;
53
90
  export declare let $readBitmapFramebuffer: WebGLFramebuffer | null;
@@ -64,6 +64,47 @@ export let $currentAttachment = null;
64
64
  export const $setCurrentAttachment = (attachment_object) => {
65
65
  $currentAttachment = attachment_object;
66
66
  };
67
+ /**
68
+ * @description GL のフレームバッファに実際に付いているアタッチメントオブジェクト。
69
+ * 通常は $currentAttachment と同じ。$attachmentDeferred が true の間だけ違う。
70
+ * The attachment object actually attached to the GL framebuffer. Normally the same as
71
+ * $currentAttachment; they differ only while $attachmentDeferred is true.
72
+ *
73
+ * @type {IAttachmentObject | null}
74
+ * @public
75
+ */
76
+ export let $physicalAttachment = null;
77
+ /**
78
+ * @param {IAttachmentObject | null} attachment_object
79
+ * @return {void}
80
+ * @method
81
+ * @public
82
+ */
83
+ export const $setPhysicalAttachment = (attachment_object) => {
84
+ $physicalAttachment = attachment_object;
85
+ };
86
+ /**
87
+ * @description 描画先の切り替えを保留しているかどうか。true の間、$currentAttachment (とビューポートの
88
+ * 大きさ) は切り替え後の値だが、GL のフレームバッファは $physicalAttachment のまま。
89
+ * GL で描く前に ContextSyncAttachmentUseCase で実際に切り替える。
90
+ * Whether a render target switch is pending. While true, $currentAttachment (and the
91
+ * viewport size) already hold the new target but the GL framebuffer still has
92
+ * $physicalAttachment. ContextSyncAttachmentUseCase performs the switch before
93
+ * anything is drawn with GL.
94
+ *
95
+ * @type {boolean}
96
+ * @public
97
+ */
98
+ export let $attachmentDeferred = false;
99
+ /**
100
+ * @param {boolean} state
101
+ * @return {void}
102
+ * @method
103
+ * @public
104
+ */
105
+ export const $setAttachmentDeferred = (state) => {
106
+ $attachmentDeferred = state;
107
+ };
67
108
  export let $isFramebufferBound = false;
68
109
  export const $setFramebufferBound = (state) => {
69
110
  $isFramebufferBound = state;
@@ -0,0 +1,81 @@
1
+ import type { IGradientLUTSlot } from "../interface/IGradientLUTSlot";
2
+ /**
3
+ * @description 図形のグラデーション LUT を保持する枠の数 (解像度ごと)。
4
+ * LUT は 1 行のテクスチャ (幅 256 / 512 / 1024) なので、枠を増やしてもメモリはわずか。
5
+ * The number of slots holding shape gradient LUTs (per resolution). A LUT is a one-row
6
+ * texture (256 / 512 / 1024 wide), so the slots cost very little memory.
7
+ *
8
+ * @type {number}
9
+ * @const
10
+ */
11
+ export declare const $GRADIENT_LUT_SLOT_COUNT: number;
12
+ /**
13
+ * @description 通し番号を進めて返却
14
+ * Advance and return the serial number
15
+ *
16
+ * @return {number}
17
+ * @method
18
+ * @protected
19
+ */
20
+ export declare const $nextGradientLUTPass: () => number;
21
+ /**
22
+ * @description stops と補間方法からハッシュ値を計算
23
+ * Compute a hash from the stops and the interpolation
24
+ *
25
+ * @param {array} stops
26
+ * @param {number} interpolation
27
+ * @return {number}
28
+ * @method
29
+ * @protected
30
+ */
31
+ export declare const $hashGradientStops: (stops: number[], interpolation: number) => number;
32
+ /**
33
+ * @description 同じ stops・補間方法の LUT を持つ枠を返却 (無ければ null)
34
+ * Return the slot holding the LUT of the same stops and interpolation (null if none)
35
+ *
36
+ * @param {number} resolution
37
+ * @param {array} stops
38
+ * @param {number} interpolation
39
+ * @param {number} hash
40
+ * @return {IGradientLUTSlot | null}
41
+ * @method
42
+ * @protected
43
+ */
44
+ export declare const $findGradientLUTSlot: (resolution: number, stops: number[], interpolation: number, hash: number) => IGradientLUTSlot | null;
45
+ /**
46
+ * @description 新しい LUT を描く枠を返却。空きが無ければ古い枠を順に上書きする。
47
+ * protect_pass の回で割り当てた枠は上書きしない (全部がその回の枠なら null)。
48
+ * Return a slot to draw a new LUT into. When none is free, old slots are overwritten in
49
+ * turn. Slots assigned in the pass protect_pass are never overwritten (null when every
50
+ * slot belongs to that pass).
51
+ *
52
+ * @param {number} resolution
53
+ * @param {number} protect_pass
54
+ * @return {IGradientLUTSlot | null}
55
+ * @method
56
+ * @protected
57
+ */
58
+ export declare const $takeGradientLUTSlot: (resolution: number, protect_pass: number) => IGradientLUTSlot | null;
59
+ /**
60
+ * @description 枠に、これから描く LUT の stops・補間方法を記録
61
+ * Record in the slot the stops and interpolation of the LUT about to be drawn
62
+ *
63
+ * @param {IGradientLUTSlot} slot
64
+ * @param {array} stops
65
+ * @param {number} interpolation
66
+ * @param {number} hash
67
+ * @param {number} pass
68
+ * @return {void}
69
+ * @method
70
+ * @protected
71
+ */
72
+ export declare const $storeGradientLUTSlot: (slot: IGradientLUTSlot, stops: number[], interpolation: number, hash: number, pass: number) => void;
73
+ /**
74
+ * @description すべての枠を破棄 (テスト用)
75
+ * Discard every slot (for tests)
76
+ *
77
+ * @return {void}
78
+ * @method
79
+ * @protected
80
+ */
81
+ export declare const $clearGradientLUTSlots: () => void;
@@ -0,0 +1,213 @@
1
+ import { execute as frameBufferManagerGetAttachmentObjectUseCase } from "../FrameBufferManager/usecase/FrameBufferManagerGetAttachmentObjectUseCase";
2
+ import { execute as frameBufferManagerCreateAttachmentObjectService } from "../FrameBufferManager/service/FrameBufferManagerCreateAttachmentObjectService";
3
+ import { execute as textureManagerGetTextureUseCase } from "../TextureManager/usecase/TextureManagerGetTextureUseCase";
4
+ /**
5
+ * @description 図形のグラデーション LUT を保持する枠の数 (解像度ごと)。
6
+ * LUT は 1 行のテクスチャ (幅 256 / 512 / 1024) なので、枠を増やしてもメモリはわずか。
7
+ * The number of slots holding shape gradient LUTs (per resolution). A LUT is a one-row
8
+ * texture (256 / 512 / 1024 wide), so the slots cost very little memory.
9
+ *
10
+ * @type {number}
11
+ * @const
12
+ */
13
+ export const $GRADIENT_LUT_SLOT_COUNT = 32;
14
+ /**
15
+ * @description 解像度ごとの LUT の枠
16
+ * LUT slots by resolution
17
+ *
18
+ * @type {Map<number, IGradientLUTSlot[]>}
19
+ * @private
20
+ */
21
+ const $slots = new Map();
22
+ /**
23
+ * @description 解像度ごとの、次に上書きする枠の位置
24
+ * The position of the next slot to overwrite, by resolution
25
+ *
26
+ * @type {Map<number, number>}
27
+ * @private
28
+ */
29
+ const $cursors = new Map();
30
+ /**
31
+ * @description まとめて LUT を用意する処理の通し番号。同じ回で割り当てた枠を、その回のうちに
32
+ * 上書きしないために使う。
33
+ * Serial number of the batched LUT preparation. Used so that a slot assigned in a pass
34
+ * is not overwritten within that pass.
35
+ *
36
+ * @type {number}
37
+ * @private
38
+ */
39
+ let $pass = 0;
40
+ /**
41
+ * @description 通し番号を進めて返却
42
+ * Advance and return the serial number
43
+ *
44
+ * @return {number}
45
+ * @method
46
+ * @protected
47
+ */
48
+ export const $nextGradientLUTPass = () => {
49
+ return ++$pass;
50
+ };
51
+ /**
52
+ * @description stops と補間方法からハッシュ値を計算
53
+ * Compute a hash from the stops and the interpolation
54
+ *
55
+ * @param {array} stops
56
+ * @param {number} interpolation
57
+ * @return {number}
58
+ * @method
59
+ * @protected
60
+ */
61
+ export const $hashGradientStops = (stops, interpolation) => {
62
+ let hash = interpolation | 0;
63
+ for (let idx = 0; idx < stops.length; ++idx) {
64
+ hash = Math.imul(hash, 31) + (stops[idx] * 1024 | 0) | 0;
65
+ }
66
+ return hash;
67
+ };
68
+ /**
69
+ * @description 同じ stops・補間方法の LUT を持つ枠を返却 (無ければ null)
70
+ * Return the slot holding the LUT of the same stops and interpolation (null if none)
71
+ *
72
+ * @param {number} resolution
73
+ * @param {array} stops
74
+ * @param {number} interpolation
75
+ * @param {number} hash
76
+ * @return {IGradientLUTSlot | null}
77
+ * @method
78
+ * @protected
79
+ */
80
+ export const $findGradientLUTSlot = (resolution, stops, interpolation, hash) => {
81
+ const slots = $slots.get(resolution);
82
+ if (!slots) {
83
+ return null;
84
+ }
85
+ const length = stops.length;
86
+ for (let idx = 0; idx < slots.length; ++idx) {
87
+ const slot = slots[idx];
88
+ if (slot.hash !== hash
89
+ || slot.length !== length
90
+ || slot.interpolation !== interpolation) {
91
+ continue;
92
+ }
93
+ // ハッシュ値が同じでも中身が違うことがあるので、値を比べる
94
+ const values = slot.stops;
95
+ let same = true;
96
+ for (let i = 0; i < length; ++i) {
97
+ if (values[i] !== stops[i]) {
98
+ same = false;
99
+ break;
100
+ }
101
+ }
102
+ if (same) {
103
+ return slot;
104
+ }
105
+ }
106
+ return null;
107
+ };
108
+ /**
109
+ * @description 枠の描画先を作成。LUT の描画はステンシルを使わないので、同じ解像度の枠は
110
+ * ステンシルバッファを共有する (枠ごとに作ると、初めて使うときの確保と付け替えが
111
+ * 枠の数だけ走る。共有すれば、枠を切り替えてもテクスチャの付け替えだけで済む)。
112
+ * Create the render target of a slot. Drawing a LUT does not use the stencil, so the
113
+ * slots of one resolution share a stencil buffer (one per slot would allocate and
114
+ * attach as many buffers on first use; sharing leaves only the texture to re-attach
115
+ * when switching between slots).
116
+ *
117
+ * @param {number} resolution
118
+ * @param {IAttachmentObject | null} shared
119
+ * @return {IAttachmentObject}
120
+ * @method
121
+ * @private
122
+ */
123
+ const $createAttachment = (resolution, shared) => {
124
+ if (!shared) {
125
+ return frameBufferManagerGetAttachmentObjectUseCase(resolution, 1, false);
126
+ }
127
+ const attachment = frameBufferManagerCreateAttachmentObjectService();
128
+ attachment.width = resolution;
129
+ attachment.height = 1;
130
+ attachment.texture = textureManagerGetTextureUseCase(resolution, 1);
131
+ attachment.stencil = shared.stencil;
132
+ return attachment;
133
+ };
134
+ /**
135
+ * @description 新しい LUT を描く枠を返却。空きが無ければ古い枠を順に上書きする。
136
+ * protect_pass の回で割り当てた枠は上書きしない (全部がその回の枠なら null)。
137
+ * Return a slot to draw a new LUT into. When none is free, old slots are overwritten in
138
+ * turn. Slots assigned in the pass protect_pass are never overwritten (null when every
139
+ * slot belongs to that pass).
140
+ *
141
+ * @param {number} resolution
142
+ * @param {number} protect_pass
143
+ * @return {IGradientLUTSlot | null}
144
+ * @method
145
+ * @protected
146
+ */
147
+ export const $takeGradientLUTSlot = (resolution, protect_pass) => {
148
+ let slots = $slots.get(resolution);
149
+ if (!slots) {
150
+ slots = [];
151
+ $slots.set(resolution, slots);
152
+ $cursors.set(resolution, 0);
153
+ }
154
+ if (slots.length < $GRADIENT_LUT_SLOT_COUNT) {
155
+ const slot = {
156
+ "attachment": $createAttachment(resolution, slots.length ? slots[0].attachment : null),
157
+ "hash": 0,
158
+ "interpolation": -1,
159
+ "length": 0,
160
+ "stops": [],
161
+ "pass": 0
162
+ };
163
+ slots.push(slot);
164
+ return slot;
165
+ }
166
+ let cursor = $cursors.get(resolution);
167
+ for (let idx = 0; idx < $GRADIENT_LUT_SLOT_COUNT; ++idx) {
168
+ const slot = slots[cursor];
169
+ cursor = (cursor + 1) % $GRADIENT_LUT_SLOT_COUNT;
170
+ if (slot.pass !== protect_pass) {
171
+ $cursors.set(resolution, cursor);
172
+ return slot;
173
+ }
174
+ }
175
+ return null;
176
+ };
177
+ /**
178
+ * @description 枠に、これから描く LUT の stops・補間方法を記録
179
+ * Record in the slot the stops and interpolation of the LUT about to be drawn
180
+ *
181
+ * @param {IGradientLUTSlot} slot
182
+ * @param {array} stops
183
+ * @param {number} interpolation
184
+ * @param {number} hash
185
+ * @param {number} pass
186
+ * @return {void}
187
+ * @method
188
+ * @protected
189
+ */
190
+ export const $storeGradientLUTSlot = (slot, stops, interpolation, hash, pass) => {
191
+ const length = stops.length;
192
+ const values = slot.stops;
193
+ values.length = length;
194
+ for (let idx = 0; idx < length; ++idx) {
195
+ values[idx] = stops[idx];
196
+ }
197
+ slot.hash = hash;
198
+ slot.interpolation = interpolation;
199
+ slot.length = length;
200
+ slot.pass = pass;
201
+ };
202
+ /**
203
+ * @description すべての枠を破棄 (テスト用)
204
+ * Discard every slot (for tests)
205
+ *
206
+ * @return {void}
207
+ * @method
208
+ * @protected
209
+ */
210
+ export const $clearGradientLUTSlots = () => {
211
+ $slots.clear();
212
+ $cursors.clear();
213
+ };
@@ -0,0 +1,16 @@
1
+ import type { IAttachmentObject } from "../../../interface/IAttachmentObject";
2
+ /**
3
+ * @description 指定の描画先へ、グラデーションの LUT を描きます。
4
+ * 描画先は切り替えたままにします (元へ戻すのは呼び出し側)。
5
+ * ブレンド・シザー・ステンシルの設定も呼び出し側で行います。
6
+ * Draw the gradient LUT into the given target. The target stays bound (the caller
7
+ * switches back). The caller also sets up blending, the scissor and the stencil.
8
+ *
9
+ * @param {IAttachmentObject} attachment_object
10
+ * @param {array} stops
11
+ * @param {number} interpolation
12
+ * @return {void}
13
+ * @method
14
+ * @protected
15
+ */
16
+ export declare const execute: (attachment_object: IAttachmentObject, stops: number[], interpolation: number) => void;
@@ -0,0 +1,37 @@
1
+ import { execute as variantsGradientLUTShaderService } from "../../Variants/GradientLUT/service/VariantsGradientLUTShaderService";
2
+ import { execute as gradientLUTSetUniformService } from "../service/GradientLUTSetUniformService";
3
+ import { execute as gradientLUTGeneratorFillTextureUseCase } from "./GradientLUTGeneratorFillTextureUseCase";
4
+ import { $context } from "../../../WebGLUtil";
5
+ import { $getGradientLUTGeneratorMaxLength, $rgbIdentityTable, $rgbToLinearTable } from "../../GradientLUTGenerator";
6
+ /**
7
+ * @description 指定の描画先へ、グラデーションの LUT を描きます。
8
+ * 描画先は切り替えたままにします (元へ戻すのは呼び出し側)。
9
+ * ブレンド・シザー・ステンシルの設定も呼び出し側で行います。
10
+ * Draw the gradient LUT into the given target. The target stays bound (the caller
11
+ * switches back). The caller also sets up blending, the scissor and the stencil.
12
+ *
13
+ * @param {IAttachmentObject} attachment_object
14
+ * @param {array} stops
15
+ * @param {number} interpolation
16
+ * @return {void}
17
+ * @method
18
+ * @protected
19
+ */
20
+ export const execute = (attachment_object, stops, interpolation) => {
21
+ $context.bind(attachment_object);
22
+ const isLinearSpace = interpolation === 0;
23
+ const stopsLength = stops.length / 5;
24
+ const table = isLinearSpace
25
+ ? $rgbToLinearTable
26
+ : $rgbIdentityTable;
27
+ const maxLength = $getGradientLUTGeneratorMaxLength();
28
+ for (let begin = 0; begin < stopsLength; begin += maxLength - 1) {
29
+ const end = Math.min(begin + maxLength, stopsLength);
30
+ const shaderManager = variantsGradientLUTShaderService(end - begin, isLinearSpace);
31
+ gradientLUTSetUniformService(shaderManager, stops, begin, end, table);
32
+ // 先頭チャンクは0、末尾チャンクは1まで矩形を拡張して描画する。
33
+ // シェーダー側が最初/最後のストップ色でパディングするため、
34
+ // ストップ範囲外のtexelが未描画(前回内容のまま)になるのを防ぐ。
35
+ gradientLUTGeneratorFillTextureUseCase(shaderManager, begin === 0 ? 0 : stops[begin * 5], end === stopsLength ? 1 : stops[(end - 1) * 5]);
36
+ }
37
+ };
@@ -1,11 +1,11 @@
1
1
  import type { ITextureObject } from "../../../interface/ITextureObject";
2
2
  /**
3
- * @description グラデーションのテクスチャを生成します。
4
- * Generates a texture of the gradient.
5
- * 注意: グラデーションLUTは共有テクスチャに描画されるため、
6
- * キャッシュは使用しません。各フレームで再描画が必要です。
7
- * Note: Gradient LUT is drawn to a shared texture, so caching
8
- * is not used. Re-drawing is required each frame.
3
+ * @description グラデーションのテクスチャを返却します。
4
+ * 同じ stops・補間方法の LUT が枠に残っていれば、描かずにそれを返します。
5
+ * 無ければ、枠の 1 つへ描いてから返します (描画先を切り替えて、元へ戻す)。
6
+ * Return the texture of the gradient. When a LUT of the same stops and interpolation
7
+ * is still in a slot it is returned without drawing. Otherwise it is drawn into a slot
8
+ * first (switching the render target and back).
9
9
  *
10
10
  * @param {array} stops
11
11
  * @param {number} interpolation
@@ -1,17 +1,16 @@
1
- import { execute as variantsGradientLUTShaderService } from "../../Variants/GradientLUT/service/VariantsGradientLUTShaderService";
2
1
  import { execute as blendOneZeroService } from "../../../Blend/service/BlendOneZeroService";
3
2
  import { execute as blendResetService } from "../../../Blend/service/BlendResetService";
4
- import { execute as gradientLUTSetUniformService } from "../service/GradientLUTSetUniformService";
5
- import { execute as gradientLUTGeneratorFillTextureUseCase } from "./GradientLUTGeneratorFillTextureUseCase";
3
+ import { execute as gradientLUTDrawShapeTextureUseCase } from "./GradientLUTDrawShapeTextureUseCase";
6
4
  import { $context, $enableScissorTest, $disableScissorTest, $scissorBox, $setScissorBox } from "../../../WebGLUtil";
7
- import { $getGradientAttachmentObjectWithResolution, $getAdaptiveResolution, $getGradientLUTGeneratorMaxLength, $rgbIdentityTable, $rgbToLinearTable } from "../../GradientLUTGenerator";
5
+ import { $getAdaptiveResolution } from "../../GradientLUTGenerator";
6
+ import { $findGradientLUTSlot, $hashGradientStops, $storeGradientLUTSlot, $takeGradientLUTSlot } from "../../GradientLUTCache";
8
7
  /**
9
- * @description グラデーションのテクスチャを生成します。
10
- * Generates a texture of the gradient.
11
- * 注意: グラデーションLUTは共有テクスチャに描画されるため、
12
- * キャッシュは使用しません。各フレームで再描画が必要です。
13
- * Note: Gradient LUT is drawn to a shared texture, so caching
14
- * is not used. Re-drawing is required each frame.
8
+ * @description グラデーションのテクスチャを返却します。
9
+ * 同じ stops・補間方法の LUT が枠に残っていれば、描かずにそれを返します。
10
+ * 無ければ、枠の 1 つへ描いてから返します (描画先を切り替えて、元へ戻す)。
11
+ * Return the texture of the gradient. When a LUT of the same stops and interpolation
12
+ * is still in a slot it is returned without drawing. Otherwise it is drawn into a slot
13
+ * first (switching the render target and back).
15
14
  *
16
15
  * @param {array} stops
17
16
  * @param {number} interpolation
@@ -20,6 +19,15 @@ import { $getGradientAttachmentObjectWithResolution, $getAdaptiveResolution, $ge
20
19
  * @protected
21
20
  */
22
21
  export const execute = (stops, interpolation) => {
22
+ const resolution = $getAdaptiveResolution(stops.length / 5);
23
+ const hash = $hashGradientStops(stops, interpolation);
24
+ let slot = $findGradientLUTSlot(resolution, stops, interpolation, hash);
25
+ if (slot) {
26
+ return slot.attachment.texture;
27
+ }
28
+ // 直後に使うので、どの枠を上書きしてもよい
29
+ slot = $takeGradientLUTSlot(resolution, -1);
30
+ $storeGradientLUTSlot(slot, stops, interpolation, hash, 0);
23
31
  const currentAttachment = $context.currentAttachmentObject;
24
32
  // JS側で追跡しているscissor矩形を退避(getParameterの同期クエリを回避)
25
33
  const scissorX = $scissorBox[0];
@@ -27,26 +35,8 @@ export const execute = (stops, interpolation) => {
27
35
  const scissorW = $scissorBox[2];
28
36
  const scissorH = $scissorBox[3];
29
37
  $disableScissorTest();
30
- const isLinearSpace = interpolation === 0;
31
- const stopsLength = stops.length / 5;
32
- // 適応的解像度を使用
33
- const resolution = $getAdaptiveResolution(stopsLength);
34
- const gradientAttachmentObject = $getGradientAttachmentObjectWithResolution(resolution);
35
- $context.bind(gradientAttachmentObject);
36
- const table = isLinearSpace
37
- ? $rgbToLinearTable
38
- : $rgbIdentityTable;
39
38
  blendOneZeroService();
40
- const maxLength = $getGradientLUTGeneratorMaxLength();
41
- for (let begin = 0; begin < stopsLength; begin += maxLength - 1) {
42
- const end = Math.min(begin + maxLength, stopsLength);
43
- const shaderManager = variantsGradientLUTShaderService(end - begin, isLinearSpace);
44
- gradientLUTSetUniformService(shaderManager, stops, begin, end, table);
45
- // 先頭チャンクは0、末尾チャンクは1まで矩形を拡張して描画する。
46
- // シェーダー側が最初/最後のストップ色でパディングするため、
47
- // ストップ範囲外のtexelが未描画(前回内容のまま)になるのを防ぐ。
48
- gradientLUTGeneratorFillTextureUseCase(shaderManager, begin === 0 ? 0 : stops[begin * 5], end === stopsLength ? 1 : stops[(end - 1) * 5]);
49
- }
39
+ gradientLUTDrawShapeTextureUseCase(slot.attachment, stops, interpolation);
50
40
  blendResetService();
51
41
  if (currentAttachment) {
52
42
  $context.bind(currentAttachment);
@@ -54,5 +44,5 @@ export const execute = (stops, interpolation) => {
54
44
  // bugfix: @see https://github.com/Next2D/player/issues/234
55
45
  $enableScissorTest();
56
46
  $setScissorBox(scissorX, scissorY, scissorW, scissorH);
57
- return gradientAttachmentObject.texture;
47
+ return slot.attachment.texture;
58
48
  };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @description これから塗る図形のグラデーションの LUT を、まとめて先に描きます。
3
+ * 塗りごとに「LUT の描画先へ切り替え → 描く → 元へ戻す」を行うと、元へ戻す切り替えが
4
+ * 塗りの数だけ走る。先にまとめて描けば、元へ戻すのは 1 回で済む。
5
+ * 枠に残っている LUT は描き直さない。枠が足りない分はここでは描かず、塗るときに描く。
6
+ * Draw the gradient LUTs of the fills about to be painted, all at once. Doing "switch to
7
+ * the LUT target, draw, switch back" per fill switches back once per fill; drawing them
8
+ * up front switches back only once. LUTs still held in a slot are not redrawn. Those
9
+ * that do not fit in the slots are left to be drawn when they are painted.
10
+ *
11
+ * @return {boolean} LUT を描いたら true (ステンシルテストを無効にしている) / true when any LUT was
12
+ * drawn (the stencil test has been disabled)
13
+ * @method
14
+ * @protected
15
+ */
16
+ export declare const execute: () => boolean;
@@ -0,0 +1,89 @@
1
+ import { execute as blendOneZeroService } from "../../../Blend/service/BlendOneZeroService";
2
+ import { execute as blendResetService } from "../../../Blend/service/BlendResetService";
3
+ import { execute as stencilResetService } from "../../../Stencil/service/StencilResetService";
4
+ import { execute as gradientLUTDrawShapeTextureUseCase } from "./GradientLUTDrawShapeTextureUseCase";
5
+ import { $gradientData } from "../../../Gradient";
6
+ import { $fillTypes } from "../../../Mesh";
7
+ import { $context, $enableScissorTest, $disableScissorTest, $disableStencilTest, $scissorBox, $setScissorBox } from "../../../WebGLUtil";
8
+ import { $getAdaptiveResolution } from "../../GradientLUTGenerator";
9
+ import { $findGradientLUTSlot, $hashGradientStops, $nextGradientLUTPass, $storeGradientLUTSlot, $takeGradientLUTSlot } from "../../GradientLUTCache";
10
+ /**
11
+ * @description これから塗る図形のグラデーションの LUT を、まとめて先に描きます。
12
+ * 塗りごとに「LUT の描画先へ切り替え → 描く → 元へ戻す」を行うと、元へ戻す切り替えが
13
+ * 塗りの数だけ走る。先にまとめて描けば、元へ戻すのは 1 回で済む。
14
+ * 枠に残っている LUT は描き直さない。枠が足りない分はここでは描かず、塗るときに描く。
15
+ * Draw the gradient LUTs of the fills about to be painted, all at once. Doing "switch to
16
+ * the LUT target, draw, switch back" per fill switches back once per fill; drawing them
17
+ * up front switches back only once. LUTs still held in a slot are not redrawn. Those
18
+ * that do not fit in the slots are left to be drawn when they are painted.
19
+ *
20
+ * @return {boolean} LUT を描いたら true (ステンシルテストを無効にしている) / true when any LUT was
21
+ * drawn (the stencil test has been disabled)
22
+ * @method
23
+ * @protected
24
+ */
25
+ export const execute = () => {
26
+ const pass = $nextGradientLUTPass();
27
+ let drawn = false;
28
+ let currentAttachment = null;
29
+ let scissorX = 0;
30
+ let scissorY = 0;
31
+ let scissorW = 0;
32
+ let scissorH = 0;
33
+ let position = 0;
34
+ for (let idx = 0; idx < $fillTypes.length; ++idx) {
35
+ // $gradientData の並びは ContextGradientFillUseCase / ContextGradientStrokeUseCase を参照
36
+ const type = $fillTypes[idx];
37
+ let size = 0;
38
+ if (type === "linear") {
39
+ size = 4;
40
+ }
41
+ else if (type === "radial") {
42
+ size = 5;
43
+ }
44
+ else {
45
+ continue;
46
+ }
47
+ const stops = $gradientData[position];
48
+ const interpolation = $gradientData[position + 3];
49
+ position += size;
50
+ const resolution = $getAdaptiveResolution(stops.length / 5);
51
+ const hash = $hashGradientStops(stops, interpolation);
52
+ let slot = $findGradientLUTSlot(resolution, stops, interpolation, hash);
53
+ if (slot) {
54
+ // この回の塗りが使うので、この回のうちは上書きさせない
55
+ slot.pass = pass;
56
+ continue;
57
+ }
58
+ slot = $takeGradientLUTSlot(resolution, pass);
59
+ if (!slot) {
60
+ // 枠が足りない。残りは塗るときに描く
61
+ continue;
62
+ }
63
+ if (!drawn) {
64
+ drawn = true;
65
+ currentAttachment = $context.currentAttachmentObject;
66
+ // JS側で追跡しているscissor矩形を退避(getParameterの同期クエリを回避)
67
+ scissorX = $scissorBox[0];
68
+ scissorY = $scissorBox[1];
69
+ scissorW = $scissorBox[2];
70
+ scissorH = $scissorBox[3];
71
+ $disableScissorTest();
72
+ stencilResetService();
73
+ $disableStencilTest();
74
+ blendOneZeroService();
75
+ }
76
+ $storeGradientLUTSlot(slot, stops, interpolation, hash, pass);
77
+ gradientLUTDrawShapeTextureUseCase(slot.attachment, stops, interpolation);
78
+ }
79
+ if (drawn) {
80
+ blendResetService();
81
+ if (currentAttachment) {
82
+ $context.bind(currentAttachment);
83
+ }
84
+ // bugfix: @see https://github.com/Next2D/player/issues/234
85
+ $enableScissorTest();
86
+ $setScissorBox(scissorX, scissorY, scissorW, scissorH);
87
+ }
88
+ return drawn;
89
+ };
@@ -0,0 +1,9 @@
1
+ import type { IAttachmentObject } from "./IAttachmentObject";
2
+ export interface IGradientLUTSlot {
3
+ attachment: IAttachmentObject;
4
+ hash: number;
5
+ interpolation: number;
6
+ length: number;
7
+ stops: number[];
8
+ pass: number;
9
+ }
@@ -0,0 +1 @@
1
+ export {};