@next2d/webgl 3.19.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next2d/webgl",
3
- "version": "3.19.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.19.0",
28
- "@next2d/render-queue": "3.19.0"
27
+ "@next2d/texture-packer": "3.19.1",
28
+ "@next2d/render-queue": "3.19.1"
29
29
  }
30
30
  }
@@ -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,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 {};