@next2d/webgl 3.19.0 → 3.20.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 +3 -3
- package/src/Context/usecase/ContextBitmapStrokeUseCase.js +6 -8
- package/src/Context/usecase/ContextDrawFillUseCase.js +9 -0
- package/src/Context/usecase/ContextGradientStrokeUseCase.js +6 -8
- package/src/Context/usecase/ContextStrokeUseCase.js +6 -8
- package/src/Mesh/usecase/MeshStrokeCurrentPathUseCase.d.ts +13 -0
- package/src/Mesh/usecase/MeshStrokeCurrentPathUseCase.js +46 -0
- package/src/NativeShape.d.ts +9 -0
- package/src/NativeShape.js +8 -0
- package/src/Shader/GradientLUTCache.d.ts +81 -0
- package/src/Shader/GradientLUTCache.js +213 -0
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTDrawShapeTextureUseCase.d.ts +16 -0
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTDrawShapeTextureUseCase.js +37 -0
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTGenerateShapeTextureUseCase.d.ts +6 -6
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTGenerateShapeTextureUseCase.js +20 -30
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTPrepareShapeTexturesUseCase.d.ts +16 -0
- package/src/Shader/GradientLUTGenerator/usecase/GradientLUTPrepareShapeTexturesUseCase.js +89 -0
- package/src/interface/IGradientLUTSlot.d.ts +9 -0
- 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.
|
|
3
|
+
"version": "3.20.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.
|
|
28
|
-
"@next2d/render-queue": "3.
|
|
27
|
+
"@next2d/texture-packer": "3.20.0",
|
|
28
|
+
"@next2d/render-queue": "3.20.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { execute as meshStrokeGenerateUseCase } from "../../Mesh/usecase/MeshStrokeGenerateUseCase";
|
|
1
|
+
import { execute as meshStrokeCurrentPathUseCase } from "../../Mesh/usecase/MeshStrokeCurrentPathUseCase";
|
|
3
2
|
import { $bitmapData } from "../../Bitmap";
|
|
4
|
-
import { $
|
|
3
|
+
import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
|
|
5
4
|
/**
|
|
6
5
|
* @description パスコマンドの線のビットマップの描画を実行します。
|
|
7
6
|
* Execute drawing of bitmap of line of path command.
|
|
@@ -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
|
-
|
|
21
|
-
|
|
19
|
+
// いまの経路を線のメッシュにして、塗りのバッファへ追加する
|
|
20
|
+
const indexCount = meshStrokeCurrentPathUseCase();
|
|
21
|
+
if (indexCount < 0) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
// 塗りの種類を追加
|
|
25
25
|
$fillTypes.push("bitmap");
|
|
26
|
-
const mesh = meshStrokeGenerateUseCase(vertices);
|
|
27
|
-
$addFillBuffer(mesh.buffer);
|
|
28
26
|
// 塗りのインデックスを追加
|
|
29
|
-
$fillBufferIndexes.push(
|
|
27
|
+
$fillBufferIndexes.push(indexCount);
|
|
30
28
|
$bitmapData.push(pixels, matrix, width, height, repeat, smooth);
|
|
31
29
|
};
|
|
@@ -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++) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { execute as meshStrokeGenerateUseCase } from "../../Mesh/usecase/MeshStrokeGenerateUseCase";
|
|
1
|
+
import { execute as meshStrokeCurrentPathUseCase } from "../../Mesh/usecase/MeshStrokeCurrentPathUseCase";
|
|
3
2
|
import { $gradientData } from "../../Gradient";
|
|
4
|
-
import { $
|
|
3
|
+
import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
|
|
5
4
|
/**
|
|
6
5
|
* @description 線のグラデーションを実行
|
|
7
6
|
* Execute gradient of line
|
|
@@ -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
|
-
|
|
21
|
-
|
|
19
|
+
// いまの経路を線のメッシュにして、塗りのバッファへ追加する
|
|
20
|
+
const indexCount = meshStrokeCurrentPathUseCase();
|
|
21
|
+
if (indexCount < 0) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
// 塗りの種類を追加
|
|
25
25
|
$fillTypes.push(type === 0 ? "linear" : "radial");
|
|
26
|
-
const mesh = meshStrokeGenerateUseCase(vertices);
|
|
27
|
-
$addFillBuffer(mesh.buffer);
|
|
28
26
|
// 塗りのインデックスを追加
|
|
29
|
-
$fillBufferIndexes.push(
|
|
27
|
+
$fillBufferIndexes.push(indexCount);
|
|
30
28
|
$gradientData.push(stops, matrix, spread, interpolation);
|
|
31
29
|
if (type === 1) {
|
|
32
30
|
$gradientData.push(focal);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
|
|
1
|
+
import { execute as meshStrokeCurrentPathUseCase } from "../../Mesh/usecase/MeshStrokeCurrentPathUseCase";
|
|
2
|
+
import { $fillTypes, $fillBufferIndexes } from "../../Mesh";
|
|
4
3
|
/**
|
|
5
4
|
* @description ストロークを描画
|
|
6
5
|
* Draw a stroke
|
|
@@ -10,13 +9,12 @@ import { $addFillBuffer, $fillTypes, $fillBufferIndexes } from "../../Mesh";
|
|
|
10
9
|
* @protected
|
|
11
10
|
*/
|
|
12
11
|
export const execute = () => {
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// いまの経路を線のメッシュにして、塗りのバッファへ追加する
|
|
13
|
+
const indexCount = meshStrokeCurrentPathUseCase();
|
|
14
|
+
if (indexCount < 0) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
$fillTypes.push("fill");
|
|
18
|
-
const mesh = meshStrokeGenerateUseCase(vertices);
|
|
19
|
-
$addFillBuffer(mesh.buffer);
|
|
20
18
|
// 塗りのインデックスを追加
|
|
21
|
-
$fillBufferIndexes.push(
|
|
19
|
+
$fillBufferIndexes.push(indexCount);
|
|
22
20
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description いまの経路を線のメッシュにして、塗りのバッファへ追加する。
|
|
3
|
+
* 経路を実行環境の側で組み立てていて、線の外周の計算も提供されていれば、
|
|
4
|
+
* 外周の計算もメッシュの生成もそちらで行う。
|
|
5
|
+
* Turns the current path into a stroke mesh and appends it to the fill buffer.
|
|
6
|
+
* If the path was built on the runtime side and the runtime also provides the stroke
|
|
7
|
+
* outline computation, both the outline and the mesh are generated there.
|
|
8
|
+
*
|
|
9
|
+
* @return {number} 追加した頂点数。描く経路が無ければ -1
|
|
10
|
+
* @method
|
|
11
|
+
* @protected
|
|
12
|
+
*/
|
|
13
|
+
export declare const execute: () => number;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { $getVertices } from "../../PathCommand";
|
|
2
|
+
import { execute as meshStrokeGenerateUseCase } from "./MeshStrokeGenerateUseCase";
|
|
3
|
+
import { $addFillBuffer, $reserveFillBuffer, $advanceFillBuffer, $getFillBuffer, $getFillBufferOffset } from "../../Mesh";
|
|
4
|
+
import { $nativeShape, $nativeStroke, $nativePathActive, $setNativePathActive } from "../../NativeShape";
|
|
5
|
+
import { $context, $viewportWidth, $viewportHeight } from "../../WebGLUtil";
|
|
6
|
+
/**
|
|
7
|
+
* @description いまの経路を線のメッシュにして、塗りのバッファへ追加する。
|
|
8
|
+
* 経路を実行環境の側で組み立てていて、線の外周の計算も提供されていれば、
|
|
9
|
+
* 外周の計算もメッシュの生成もそちらで行う。
|
|
10
|
+
* Turns the current path into a stroke mesh and appends it to the fill buffer.
|
|
11
|
+
* If the path was built on the runtime side and the runtime also provides the stroke
|
|
12
|
+
* outline computation, both the outline and the mesh are generated there.
|
|
13
|
+
*
|
|
14
|
+
* @return {number} 追加した頂点数。描く経路が無ければ -1
|
|
15
|
+
* @method
|
|
16
|
+
* @protected
|
|
17
|
+
*/
|
|
18
|
+
export const execute = () => {
|
|
19
|
+
if ($nativePathActive && $nativeStroke && $nativeShape && $nativeShape.strokeSize) {
|
|
20
|
+
$setNativePathActive(false);
|
|
21
|
+
// 曲線の分割数を決める拡大率 (MeshGenerateStrokeOutlineUseCase と同じ計算)
|
|
22
|
+
const matrix = $context.$matrix;
|
|
23
|
+
const scaleX = Math.sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]);
|
|
24
|
+
const scaleY = Math.sqrt(matrix[3] * matrix[3] + matrix[4] * matrix[4]);
|
|
25
|
+
const size = $nativeShape.strokeSize($context.thickness / 2, $context.joints, $context.caps, scaleX > scaleY ? scaleX : scaleY);
|
|
26
|
+
if (!size) {
|
|
27
|
+
$nativeShape.reset();
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
// MeshFillGenerateUseCase (style = "stroke") と同じ値を渡す
|
|
31
|
+
const colorStyle = $context.$strokeStyle;
|
|
32
|
+
const width = $viewportWidth;
|
|
33
|
+
const height = $viewportHeight;
|
|
34
|
+
$reserveFillBuffer(size);
|
|
35
|
+
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]);
|
|
36
|
+
$advanceFillBuffer(size);
|
|
37
|
+
return indexCount;
|
|
38
|
+
}
|
|
39
|
+
const vertices = $getVertices(true);
|
|
40
|
+
if (!vertices.length) {
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
const mesh = meshStrokeGenerateUseCase(vertices);
|
|
44
|
+
$addFillBuffer(mesh.buffer);
|
|
45
|
+
return mesh.indexCount;
|
|
46
|
+
};
|
package/src/NativeShape.d.ts
CHANGED
|
@@ -14,12 +14,21 @@ export interface INativeShape {
|
|
|
14
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
15
|
exportPath(stroke: boolean): Float64Array;
|
|
16
16
|
reset(): void;
|
|
17
|
+
strokeSize?(thickness: number, joints: number, caps: number, pixel_scale: number): number;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* @type {INativeShape | null}
|
|
20
21
|
* @public
|
|
21
22
|
*/
|
|
22
23
|
export declare const $nativeShape: INativeShape | null;
|
|
24
|
+
/**
|
|
25
|
+
* @description 実行環境が線の外周の計算 (strokeSize) も提供しているかどうか
|
|
26
|
+
* Whether the runtime also provides the stroke outline computation (strokeSize)
|
|
27
|
+
*
|
|
28
|
+
* @type {boolean}
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare const $nativeStroke: boolean;
|
|
23
32
|
/**
|
|
24
33
|
* @description 経路を実行環境の側で組み立てている最中かどうか。
|
|
25
34
|
* true の間、JavaScript 側の経路 ($currentPath / $vertices) は空。
|
package/src/NativeShape.js
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
5
|
export const $nativeShape = globalThis.__next2dShape || null;
|
|
6
|
+
/**
|
|
7
|
+
* @description 実行環境が線の外周の計算 (strokeSize) も提供しているかどうか
|
|
8
|
+
* Whether the runtime also provides the stroke outline computation (strokeSize)
|
|
9
|
+
*
|
|
10
|
+
* @type {boolean}
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export const $nativeStroke = $nativeShape !== null && typeof $nativeShape.strokeSize === "function";
|
|
6
14
|
/**
|
|
7
15
|
* @description 経路を実行環境の側で組み立てている最中かどうか。
|
|
8
16
|
* true の間、JavaScript 側の経路 ($currentPath / $vertices) は空。
|
|
@@ -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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
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 { $
|
|
5
|
+
import { $getAdaptiveResolution } from "../../GradientLUTGenerator";
|
|
6
|
+
import { $findGradientLUTSlot, $hashGradientStops, $storeGradientLUTSlot, $takeGradientLUTSlot } from "../../GradientLUTCache";
|
|
8
7
|
/**
|
|
9
|
-
* @description
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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
|
-
|
|
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
|
|
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 @@
|
|
|
1
|
+
export {};
|