@next2d/webgl 3.15.1 → 3.17.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/BezierConverter/usecase/BezierConverterAdaptiveCubicToQuadUseCase.d.ts +1 -1
- package/src/BezierConverter/usecase/BezierConverterAdaptiveCubicToQuadUseCase.js +52 -6
- package/src/BezierConverter.d.ts +44 -0
- package/src/BezierConverter.js +62 -0
- package/src/Context.js +3 -126
- package/src/FrameBufferManager/service/FrameBufferManagerBindAttachmentObjectService.js +19 -6
- package/src/FrameBufferManager.d.ts +40 -0
- package/src/FrameBufferManager.js +46 -0
- package/src/Mesh/usecase/MeshCalculateCurveRectangleUseCase.d.ts +11 -3
- package/src/Mesh/usecase/MeshCalculateCurveRectangleUseCase.js +94 -7
- package/src/Mesh/usecase/MeshGenerateStrokeOutlineUseCase.js +7 -1
- package/src/PathCommand/usecase/PathCommandBezierCurveToUseCase.js +31 -7
- package/src/Shader/GradientLUTGenerator/service/GradientLUTSetFilterUniformService.js +17 -0
- package/src/Shader/GradientLUTGenerator/service/GradientLUTSetUniformService.js +17 -0
- package/src/Shader/GradientLUTGenerator.d.ts +26 -0
- package/src/Shader/GradientLUTGenerator.js +26 -0
- package/src/Shader/ShaderInstancedManager.js +0 -6
- package/src/Shader/ShaderManager.js +0 -30
- package/src/Shader/Variants/GradientLUT/service/VariantsGradientLUTShaderService.js +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next2d/webgl",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.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.17.0",
|
|
28
|
+
"@next2d/render-queue": "3.17.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -15,4 +15,4 @@ import type { ICubicConverterReturnObject } from "../../interface/ICubicConverte
|
|
|
15
15
|
* @method
|
|
16
16
|
* @protected
|
|
17
17
|
*/
|
|
18
|
-
export declare const execute: (from_x: number, from_y: number, cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number) => ICubicConverterReturnObject;
|
|
18
|
+
export declare const execute: (from_x: number, from_y: number, cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number, pixel_scale?: number) => ICubicConverterReturnObject;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $adaptiveBuffer, $adaptiveSegmentCount, $getAdaptiveSubdivisionCount, $ensureAdaptiveBufferSize, $setAdaptiveSegmentCount, $resetSplitBufferPool, $getSplitBuffer } from "../../BezierConverter";
|
|
1
|
+
import { $adaptiveBuffer, $adaptiveSegmentCount, $getAdaptiveSubdivisionCount, $getCubicSegmentCount, $ensureAdaptiveBufferSize, $setAdaptiveSegmentCount, $resetSplitBufferPool, $getSplitBuffer } from "../../BezierConverter";
|
|
2
2
|
/**
|
|
3
3
|
* @description De Casteljauアルゴリズムで3次ベジエを分割
|
|
4
4
|
* Split cubic Bezier using De Casteljau algorithm
|
|
@@ -85,6 +85,16 @@ const cubicToQuad = (p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y, buffer, offset) =>
|
|
|
85
85
|
// 一時バッファ(分割用)
|
|
86
86
|
const $tempLeft = new Float32Array(8);
|
|
87
87
|
const $tempRight = new Float32Array(8);
|
|
88
|
+
// 戻り値のオブジェクト。曲線 1 本ごとに作ると、その確保と回収が描画の停止として現れるので使い回す。
|
|
89
|
+
// The returned object. Reused because allocating one per curve shows up as a stall.
|
|
90
|
+
const $result = {
|
|
91
|
+
"buffer": $adaptiveBuffer,
|
|
92
|
+
"count": 0
|
|
93
|
+
};
|
|
94
|
+
// n 等分するときの作業用バッファ (残りの曲線を 2 本で交互に持つ)
|
|
95
|
+
// Work buffers for splitting into n equal parts (the remaining curve alternates between the two)
|
|
96
|
+
const $restA = new Float32Array(8);
|
|
97
|
+
const $restB = new Float32Array(8);
|
|
88
98
|
/**
|
|
89
99
|
* @description 3次ベジェ曲線を適応的に2次ベジェ曲線に分割
|
|
90
100
|
* Adaptively split cubic Bezier curve into quadratic Bezier curves
|
|
@@ -101,7 +111,44 @@ const $tempRight = new Float32Array(8);
|
|
|
101
111
|
* @method
|
|
102
112
|
* @protected
|
|
103
113
|
*/
|
|
104
|
-
export const execute = (from_x, from_y, cx1, cy1, cx2, cy2, x, y) => {
|
|
114
|
+
export const execute = (from_x, from_y, cx1, cy1, cx2, cy2, x, y, pixel_scale = 0) => {
|
|
115
|
+
// 画面上の拡大率が分かるときは、近似の誤差から必要な本数を決め、その本数に等分する
|
|
116
|
+
if (pixel_scale > 0) {
|
|
117
|
+
const count = $getCubicSegmentCount(from_x, from_y, cx1, cy1, cx2, cy2, x, y, pixel_scale);
|
|
118
|
+
$ensureAdaptiveBufferSize(count * 4);
|
|
119
|
+
let offset = 0;
|
|
120
|
+
if (count === 1) {
|
|
121
|
+
cubicToQuad(from_x, from_y, cx1, cy1, cx2, cy2, x, y, $adaptiveBuffer, offset);
|
|
122
|
+
offset += 4;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// 残りの曲線の先頭 1 / (残りの本数) を切り出すことを繰り返す
|
|
126
|
+
let rest = $restA;
|
|
127
|
+
let next = $restB;
|
|
128
|
+
rest[0] = from_x;
|
|
129
|
+
rest[1] = from_y;
|
|
130
|
+
rest[2] = cx1;
|
|
131
|
+
rest[3] = cy1;
|
|
132
|
+
rest[4] = cx2;
|
|
133
|
+
rest[5] = cy2;
|
|
134
|
+
rest[6] = x;
|
|
135
|
+
rest[7] = y;
|
|
136
|
+
for (let idx = 0; idx < count - 1; ++idx) {
|
|
137
|
+
splitCubicAt(rest[0], rest[1], rest[2], rest[3], rest[4], rest[5], rest[6], rest[7], 1 / (count - idx), $tempLeft, next);
|
|
138
|
+
cubicToQuad($tempLeft[0], $tempLeft[1], $tempLeft[2], $tempLeft[3], $tempLeft[4], $tempLeft[5], $tempLeft[6], $tempLeft[7], $adaptiveBuffer, offset);
|
|
139
|
+
offset += 4;
|
|
140
|
+
const swap = rest;
|
|
141
|
+
rest = next;
|
|
142
|
+
next = swap;
|
|
143
|
+
}
|
|
144
|
+
cubicToQuad(rest[0], rest[1], rest[2], rest[3], rest[4], rest[5], rest[6], rest[7], $adaptiveBuffer, offset);
|
|
145
|
+
offset += 4;
|
|
146
|
+
}
|
|
147
|
+
$setAdaptiveSegmentCount(count);
|
|
148
|
+
$result.buffer = $adaptiveBuffer;
|
|
149
|
+
$result.count = count;
|
|
150
|
+
return $result;
|
|
151
|
+
}
|
|
105
152
|
// 曲率に基づいて分割数を決定
|
|
106
153
|
const subdivisions = $getAdaptiveSubdivisionCount(from_x, from_y, cx1, cy1, cx2, cy2, x, y);
|
|
107
154
|
// 各2次ベジエは4floats(cx, cy, x, y)
|
|
@@ -186,8 +233,7 @@ export const execute = (from_x, from_y, cx1, cy1, cx2, cy2, x, y) => {
|
|
|
186
233
|
offset += 4;
|
|
187
234
|
}
|
|
188
235
|
$setAdaptiveSegmentCount(offset / 4);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
};
|
|
236
|
+
$result.buffer = $adaptiveBuffer;
|
|
237
|
+
$result.count = $adaptiveSegmentCount;
|
|
238
|
+
return $result;
|
|
193
239
|
};
|
package/src/BezierConverter.d.ts
CHANGED
|
@@ -56,6 +56,50 @@ export declare const $calculateFlatness: (p0x: number, p0y: number, p1x: number,
|
|
|
56
56
|
* @protected
|
|
57
57
|
*/
|
|
58
58
|
export declare const $getAdaptiveSubdivisionCount: (p0x: number, p0y: number, p1x: number, p1y: number, p2x: number, p2y: number, p3x: number, p3y: number) => number;
|
|
59
|
+
/**
|
|
60
|
+
* @description 3次ベジェ曲線が 1 本の2次ベジェ曲線で足りるかどうかを、平方根を取らずに判定するための上限。
|
|
61
|
+
* |P3 - 3 * P2 + 3 * P1 - P0|² * scale² がこの値以下なら 1 本で足りる。
|
|
62
|
+
* (CUBIC_TOLERANCE / (√3 / 36))² = (0.05 * 36 / √3)² = 1.08
|
|
63
|
+
* Limit for deciding without square roots whether one quadratic curve is enough:
|
|
64
|
+
* one is enough when |P3 - 3 * P2 + 3 * P1 - P0|² * scale² is at most this value.
|
|
65
|
+
*
|
|
66
|
+
* @type {number}
|
|
67
|
+
* @const
|
|
68
|
+
*/
|
|
69
|
+
export declare const $CUBIC_SINGLE_SEGMENT_LIMIT: number;
|
|
70
|
+
/**
|
|
71
|
+
* @description 3次ベジェ曲線を何本の2次ベジェ曲線で近似するかを、画面上の誤差から求める。
|
|
72
|
+
*
|
|
73
|
+
* 3次ベジェ曲線を 1 本の2次ベジェ曲線 (制御点 = (3 * P1 + 3 * P2 - P0 - P3) / 4) で近似した
|
|
74
|
+
* ときの誤差の上限は √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|。曲線を n 等分してから近似すると、
|
|
75
|
+
* 誤差は 1 / n³ になる。画面上の誤差が CUBIC_TOLERANCE 以内になる最小の n を返す
|
|
76
|
+
* (1 以上 MAX_SUBDIVISIONS 以下)。
|
|
77
|
+
*
|
|
78
|
+
* 制御点と弦の離れ具合 ($calculateFlatness) は「直線からどれだけ離れているか」であって、
|
|
79
|
+
* 2次曲線で近似したときの誤差とは対応しない。大きく曲がっていても2次曲線に近い曲線は
|
|
80
|
+
* 1 本で足り、小さな図形 (文字や数字の輪郭など) の曲線の多くがこれに当たる。
|
|
81
|
+
*
|
|
82
|
+
* Returns how many quadratic Bezier curves are needed to approximate a cubic one, from the
|
|
83
|
+
* on-screen error. Approximating a cubic with a single quadratic (control point
|
|
84
|
+
* (3 * P1 + 3 * P2 - P0 - P3) / 4) has an error of at most √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|,
|
|
85
|
+
* and splitting the curve into n equal parts first divides the error by n³. The smallest n
|
|
86
|
+
* keeping the on-screen error within CUBIC_TOLERANCE is returned (1 to MAX_SUBDIVISIONS).
|
|
87
|
+
*
|
|
88
|
+
* @param {number} p0x
|
|
89
|
+
* @param {number} p0y
|
|
90
|
+
* @param {number} p1x
|
|
91
|
+
* @param {number} p1y
|
|
92
|
+
* @param {number} p2x
|
|
93
|
+
* @param {number} p2y
|
|
94
|
+
* @param {number} p3x
|
|
95
|
+
* @param {number} p3y
|
|
96
|
+
* @param {number} pixel_scale 曲線の座標 1 単位が画面上で何ピクセルになるか
|
|
97
|
+
* On-screen pixels per unit of the curve's coordinates
|
|
98
|
+
* @return {number}
|
|
99
|
+
* @method
|
|
100
|
+
* @protected
|
|
101
|
+
*/
|
|
102
|
+
export declare const $getCubicSegmentCount: (p0x: number, p0y: number, p1x: number, p1y: number, p2x: number, p2y: number, p3x: number, p3y: number, pixel_scale: number) => number;
|
|
59
103
|
/**
|
|
60
104
|
* @description 適応的バッファのサイズを確保
|
|
61
105
|
* Ensure adaptive buffer size
|
package/src/BezierConverter.js
CHANGED
|
@@ -97,6 +97,68 @@ export const $getAdaptiveSubdivisionCount = (p0x, p0y, p1x, p1y, p2x, p2y, p3x,
|
|
|
97
97
|
const level = Math.ceil(Math.log2(Math.sqrt(flatness) / FLATNESS_THRESHOLD) / 2);
|
|
98
98
|
return Math.min(Math.max(level + MIN_SUBDIVISIONS, MIN_SUBDIVISIONS), MAX_SUBDIVISIONS);
|
|
99
99
|
};
|
|
100
|
+
/**
|
|
101
|
+
* @description 3次ベジェ曲線を2次ベジェ曲線で近似するときの、画面上の誤差の許容値 (ピクセル)
|
|
102
|
+
* Allowed on-screen error in pixels when approximating a cubic Bezier curve with quadratic ones
|
|
103
|
+
*
|
|
104
|
+
* @type {number}
|
|
105
|
+
* @const
|
|
106
|
+
*/
|
|
107
|
+
const CUBIC_TOLERANCE = 0.05;
|
|
108
|
+
/**
|
|
109
|
+
* @description 3次ベジェ曲線が 1 本の2次ベジェ曲線で足りるかどうかを、平方根を取らずに判定するための上限。
|
|
110
|
+
* |P3 - 3 * P2 + 3 * P1 - P0|² * scale² がこの値以下なら 1 本で足りる。
|
|
111
|
+
* (CUBIC_TOLERANCE / (√3 / 36))² = (0.05 * 36 / √3)² = 1.08
|
|
112
|
+
* Limit for deciding without square roots whether one quadratic curve is enough:
|
|
113
|
+
* one is enough when |P3 - 3 * P2 + 3 * P1 - P0|² * scale² is at most this value.
|
|
114
|
+
*
|
|
115
|
+
* @type {number}
|
|
116
|
+
* @const
|
|
117
|
+
*/
|
|
118
|
+
export const $CUBIC_SINGLE_SEGMENT_LIMIT = 1.08;
|
|
119
|
+
/**
|
|
120
|
+
* @description 3次ベジェ曲線を何本の2次ベジェ曲線で近似するかを、画面上の誤差から求める。
|
|
121
|
+
*
|
|
122
|
+
* 3次ベジェ曲線を 1 本の2次ベジェ曲線 (制御点 = (3 * P1 + 3 * P2 - P0 - P3) / 4) で近似した
|
|
123
|
+
* ときの誤差の上限は √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|。曲線を n 等分してから近似すると、
|
|
124
|
+
* 誤差は 1 / n³ になる。画面上の誤差が CUBIC_TOLERANCE 以内になる最小の n を返す
|
|
125
|
+
* (1 以上 MAX_SUBDIVISIONS 以下)。
|
|
126
|
+
*
|
|
127
|
+
* 制御点と弦の離れ具合 ($calculateFlatness) は「直線からどれだけ離れているか」であって、
|
|
128
|
+
* 2次曲線で近似したときの誤差とは対応しない。大きく曲がっていても2次曲線に近い曲線は
|
|
129
|
+
* 1 本で足り、小さな図形 (文字や数字の輪郭など) の曲線の多くがこれに当たる。
|
|
130
|
+
*
|
|
131
|
+
* Returns how many quadratic Bezier curves are needed to approximate a cubic one, from the
|
|
132
|
+
* on-screen error. Approximating a cubic with a single quadratic (control point
|
|
133
|
+
* (3 * P1 + 3 * P2 - P0 - P3) / 4) has an error of at most √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0|,
|
|
134
|
+
* and splitting the curve into n equal parts first divides the error by n³. The smallest n
|
|
135
|
+
* keeping the on-screen error within CUBIC_TOLERANCE is returned (1 to MAX_SUBDIVISIONS).
|
|
136
|
+
*
|
|
137
|
+
* @param {number} p0x
|
|
138
|
+
* @param {number} p0y
|
|
139
|
+
* @param {number} p1x
|
|
140
|
+
* @param {number} p1y
|
|
141
|
+
* @param {number} p2x
|
|
142
|
+
* @param {number} p2y
|
|
143
|
+
* @param {number} p3x
|
|
144
|
+
* @param {number} p3y
|
|
145
|
+
* @param {number} pixel_scale 曲線の座標 1 単位が画面上で何ピクセルになるか
|
|
146
|
+
* On-screen pixels per unit of the curve's coordinates
|
|
147
|
+
* @return {number}
|
|
148
|
+
* @method
|
|
149
|
+
* @protected
|
|
150
|
+
*/
|
|
151
|
+
export const $getCubicSegmentCount = (p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y, pixel_scale) => {
|
|
152
|
+
const dx = p3x - 3 * p2x + 3 * p1x - p0x;
|
|
153
|
+
const dy = p3y - 3 * p2y + 3 * p1y - p0y;
|
|
154
|
+
// √3 / 36 = 0.048112522432468816
|
|
155
|
+
const error = 0.048112522432468816 * Math.sqrt(dx * dx + dy * dy) * pixel_scale;
|
|
156
|
+
let count = 1;
|
|
157
|
+
while (count < MAX_SUBDIVISIONS && error > CUBIC_TOLERANCE * count * count * count) {
|
|
158
|
+
++count;
|
|
159
|
+
}
|
|
160
|
+
return count;
|
|
161
|
+
};
|
|
100
162
|
/**
|
|
101
163
|
* @description 適応的バッファのサイズを確保
|
|
102
164
|
* Ensure adaptive buffer size
|
package/src/Context.js
CHANGED
|
@@ -57,132 +57,9 @@ import { $setReadFrameBuffer, $setDrawFrameBuffer, $currentAttachment, $setAtlas
|
|
|
57
57
|
import { $setRenderMaxSize, $setWebGL2RenderingContext, $setSamples, $getFloat32Array9, $getArray, $setContext, $setDevicePixelRatio } from "./WebGLUtil";
|
|
58
58
|
export class Context {
|
|
59
59
|
constructor(gl, samples, device_pixel_ratio = 1) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
writable: true,
|
|
64
|
-
value: new WeakMap()
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "$stack", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: void 0
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "$matrix", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: void 0
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(this, "$clearColorR", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true,
|
|
82
|
-
value: void 0
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(this, "$clearColorG", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: void 0
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(this, "$clearColorB", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(this, "$clearColorA", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: void 0
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(this, "$mainAttachmentObject", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
configurable: true,
|
|
105
|
-
writable: true,
|
|
106
|
-
value: void 0
|
|
107
|
-
});
|
|
108
|
-
Object.defineProperty(this, "$stackAttachmentObject", {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
configurable: true,
|
|
111
|
-
writable: true,
|
|
112
|
-
value: void 0
|
|
113
|
-
});
|
|
114
|
-
Object.defineProperty(this, "globalAlpha", {
|
|
115
|
-
enumerable: true,
|
|
116
|
-
configurable: true,
|
|
117
|
-
writable: true,
|
|
118
|
-
value: void 0
|
|
119
|
-
});
|
|
120
|
-
Object.defineProperty(this, "globalCompositeOperation", {
|
|
121
|
-
enumerable: true,
|
|
122
|
-
configurable: true,
|
|
123
|
-
writable: true,
|
|
124
|
-
value: void 0
|
|
125
|
-
});
|
|
126
|
-
Object.defineProperty(this, "imageSmoothingEnabled", {
|
|
127
|
-
enumerable: true,
|
|
128
|
-
configurable: true,
|
|
129
|
-
writable: true,
|
|
130
|
-
value: void 0
|
|
131
|
-
});
|
|
132
|
-
Object.defineProperty(this, "$fillStyle", {
|
|
133
|
-
enumerable: true,
|
|
134
|
-
configurable: true,
|
|
135
|
-
writable: true,
|
|
136
|
-
value: void 0
|
|
137
|
-
});
|
|
138
|
-
Object.defineProperty(this, "$strokeStyle", {
|
|
139
|
-
enumerable: true,
|
|
140
|
-
configurable: true,
|
|
141
|
-
writable: true,
|
|
142
|
-
value: void 0
|
|
143
|
-
});
|
|
144
|
-
Object.defineProperty(this, "maskBounds", {
|
|
145
|
-
enumerable: true,
|
|
146
|
-
configurable: true,
|
|
147
|
-
writable: true,
|
|
148
|
-
value: void 0
|
|
149
|
-
});
|
|
150
|
-
Object.defineProperty(this, "thickness", {
|
|
151
|
-
enumerable: true,
|
|
152
|
-
configurable: true,
|
|
153
|
-
writable: true,
|
|
154
|
-
value: void 0
|
|
155
|
-
});
|
|
156
|
-
Object.defineProperty(this, "caps", {
|
|
157
|
-
enumerable: true,
|
|
158
|
-
configurable: true,
|
|
159
|
-
writable: true,
|
|
160
|
-
value: void 0
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(this, "joints", {
|
|
163
|
-
enumerable: true,
|
|
164
|
-
configurable: true,
|
|
165
|
-
writable: true,
|
|
166
|
-
value: void 0
|
|
167
|
-
});
|
|
168
|
-
Object.defineProperty(this, "miterLimit", {
|
|
169
|
-
enumerable: true,
|
|
170
|
-
configurable: true,
|
|
171
|
-
writable: true,
|
|
172
|
-
value: void 0
|
|
173
|
-
});
|
|
174
|
-
Object.defineProperty(this, "newDrawState", {
|
|
175
|
-
enumerable: true,
|
|
176
|
-
configurable: true,
|
|
177
|
-
writable: true,
|
|
178
|
-
value: false
|
|
179
|
-
});
|
|
180
|
-
Object.defineProperty(this, "_pendingAtlasNodes", {
|
|
181
|
-
enumerable: true,
|
|
182
|
-
configurable: true,
|
|
183
|
-
writable: true,
|
|
184
|
-
value: []
|
|
185
|
-
});
|
|
60
|
+
this._nodeRoots = new WeakMap();
|
|
61
|
+
this.newDrawState = false;
|
|
62
|
+
this._pendingAtlasNodes = [];
|
|
186
63
|
disposeTextUploads();
|
|
187
64
|
$setWebGL2RenderingContext(gl);
|
|
188
65
|
$setRenderMaxSize(gl.getParameter(gl.MAX_TEXTURE_SIZE));
|
|
@@ -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 } from "../../FrameBufferManager";
|
|
4
|
+
import { $setFramebufferBound, $setCurrentAttachment, $readFrameBuffer, $isFramebufferBound, $attachedColor, $setAttachedColor, $attachedStencil, $setAttachedStencil } from "../../FrameBufferManager";
|
|
5
5
|
/**
|
|
6
6
|
* @description フレームバッファにアタッチメントオブジェクトをバインドする
|
|
7
7
|
* Bind the attachment object to the frame buffer
|
|
@@ -17,19 +17,32 @@ export const execute = (attachment_object) => {
|
|
|
17
17
|
$setFramebufferBound(true);
|
|
18
18
|
$gl.bindFramebuffer($gl.FRAMEBUFFER, $readFrameBuffer);
|
|
19
19
|
}
|
|
20
|
+
// 描画先の切り替えは図形ごとに起きるので、GL の呼び出しを必要な分だけにする:
|
|
21
|
+
// - framebufferRenderbuffer はレンダーバッファを引数で受け取るので、bindRenderbuffer は要らない
|
|
22
|
+
// - すでに同じリソースがアタッチされていれば、付け直さない
|
|
20
23
|
if (attachment_object.msaa) {
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const color = attachment_object.color.resource;
|
|
25
|
+
if ($attachedColor !== color) {
|
|
26
|
+
$setAttachedColor(color);
|
|
27
|
+
$gl.framebufferRenderbuffer($gl.FRAMEBUFFER, $gl.COLOR_ATTACHMENT0, $gl.RENDERBUFFER, color);
|
|
28
|
+
}
|
|
23
29
|
}
|
|
24
30
|
else {
|
|
25
31
|
textureManagerBind0UseCase(attachment_object.texture);
|
|
26
|
-
|
|
32
|
+
const texture = attachment_object.texture.resource;
|
|
33
|
+
if ($attachedColor !== texture) {
|
|
34
|
+
$setAttachedColor(texture);
|
|
35
|
+
$gl.framebufferTexture2D($gl.FRAMEBUFFER, $gl.COLOR_ATTACHMENT0, $gl.TEXTURE_2D, texture, 0);
|
|
36
|
+
}
|
|
27
37
|
// テクスチャフィードバックループを防止:
|
|
28
38
|
// WebGL2ではテクスチャユニットにバインドされたテクスチャが描画フレームバッファにも
|
|
29
39
|
// アタッチされている場合、drawArrays等がINVALID_OPERATIONを生成する。
|
|
30
40
|
// framebufferTexture2Dにはテクスチャユニットへのバインドは不要なため、アンバインドする。
|
|
31
41
|
textureManagerBindService(0, $gl.TEXTURE0, null);
|
|
32
42
|
}
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
const stencil = attachment_object.stencil.resource;
|
|
44
|
+
if ($attachedStencil !== stencil) {
|
|
45
|
+
$setAttachedStencil(stencil);
|
|
46
|
+
$gl.framebufferRenderbuffer($gl.FRAMEBUFFER, $gl.STENCIL_ATTACHMENT, $gl.RENDERBUFFER, stencil);
|
|
47
|
+
}
|
|
35
48
|
};
|
|
@@ -2,6 +2,46 @@ import type { IAttachmentObject } from "./interface/IAttachmentObject";
|
|
|
2
2
|
export declare const $objectPool: IAttachmentObject[];
|
|
3
3
|
export declare let $readFrameBuffer: WebGLFramebuffer;
|
|
4
4
|
export declare const $setReadFrameBuffer: (gl: WebGL2RenderingContext) => void;
|
|
5
|
+
/**
|
|
6
|
+
* @description $readFrameBuffer の COLOR_ATTACHMENT0 に現在アタッチしているリソース
|
|
7
|
+
* (WebGLRenderbuffer または WebGLTexture)。同じものの付け直しを省くために覚えておく。
|
|
8
|
+
* $readFrameBuffer のアタッチメントを変えるのは
|
|
9
|
+
* FrameBufferManagerBindAttachmentObjectService だけ。
|
|
10
|
+
* The resource currently attached to COLOR_ATTACHMENT0 of $readFrameBuffer, kept so that
|
|
11
|
+
* re-attaching the same one can be skipped.
|
|
12
|
+
*
|
|
13
|
+
* @type {WebGLRenderbuffer | WebGLTexture | null}
|
|
14
|
+
* @protected
|
|
15
|
+
*/
|
|
16
|
+
export declare let $attachedColor: WebGLRenderbuffer | WebGLTexture | null;
|
|
17
|
+
/**
|
|
18
|
+
* @description $attachedColor を更新
|
|
19
|
+
* Update $attachedColor
|
|
20
|
+
*
|
|
21
|
+
* @param {WebGLRenderbuffer | WebGLTexture | null} resource
|
|
22
|
+
* @return {void}
|
|
23
|
+
* @method
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
export declare const $setAttachedColor: (resource: WebGLRenderbuffer | WebGLTexture | null) => void;
|
|
27
|
+
/**
|
|
28
|
+
* @description $readFrameBuffer の STENCIL_ATTACHMENT に現在アタッチしている WebGLRenderbuffer
|
|
29
|
+
* The WebGLRenderbuffer currently attached to STENCIL_ATTACHMENT of $readFrameBuffer
|
|
30
|
+
*
|
|
31
|
+
* @type {WebGLRenderbuffer | null}
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
export declare let $attachedStencil: WebGLRenderbuffer | null;
|
|
35
|
+
/**
|
|
36
|
+
* @description $attachedStencil を更新
|
|
37
|
+
* Update $attachedStencil
|
|
38
|
+
*
|
|
39
|
+
* @param {WebGLRenderbuffer | null} resource
|
|
40
|
+
* @return {void}
|
|
41
|
+
* @method
|
|
42
|
+
* @protected
|
|
43
|
+
*/
|
|
44
|
+
export declare const $setAttachedStencil: (resource: WebGLRenderbuffer | null) => void;
|
|
5
45
|
export declare let $drawFrameBuffer: WebGLFramebuffer | null;
|
|
6
46
|
export declare const $setDrawFrameBuffer: (gl: WebGL2RenderingContext) => void;
|
|
7
47
|
export declare let $atlasFrameBuffer: WebGLFramebuffer | null;
|
|
@@ -2,6 +2,52 @@ export const $objectPool = [];
|
|
|
2
2
|
export let $readFrameBuffer;
|
|
3
3
|
export const $setReadFrameBuffer = (gl) => {
|
|
4
4
|
$readFrameBuffer = gl.createFramebuffer();
|
|
5
|
+
$attachedColor = null;
|
|
6
|
+
$attachedStencil = null;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* @description $readFrameBuffer の COLOR_ATTACHMENT0 に現在アタッチしているリソース
|
|
10
|
+
* (WebGLRenderbuffer または WebGLTexture)。同じものの付け直しを省くために覚えておく。
|
|
11
|
+
* $readFrameBuffer のアタッチメントを変えるのは
|
|
12
|
+
* FrameBufferManagerBindAttachmentObjectService だけ。
|
|
13
|
+
* The resource currently attached to COLOR_ATTACHMENT0 of $readFrameBuffer, kept so that
|
|
14
|
+
* re-attaching the same one can be skipped.
|
|
15
|
+
*
|
|
16
|
+
* @type {WebGLRenderbuffer | WebGLTexture | null}
|
|
17
|
+
* @protected
|
|
18
|
+
*/
|
|
19
|
+
export let $attachedColor = null;
|
|
20
|
+
/**
|
|
21
|
+
* @description $attachedColor を更新
|
|
22
|
+
* Update $attachedColor
|
|
23
|
+
*
|
|
24
|
+
* @param {WebGLRenderbuffer | WebGLTexture | null} resource
|
|
25
|
+
* @return {void}
|
|
26
|
+
* @method
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
export const $setAttachedColor = (resource) => {
|
|
30
|
+
$attachedColor = resource;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* @description $readFrameBuffer の STENCIL_ATTACHMENT に現在アタッチしている WebGLRenderbuffer
|
|
34
|
+
* The WebGLRenderbuffer currently attached to STENCIL_ATTACHMENT of $readFrameBuffer
|
|
35
|
+
*
|
|
36
|
+
* @type {WebGLRenderbuffer | null}
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
export let $attachedStencil = null;
|
|
40
|
+
/**
|
|
41
|
+
* @description $attachedStencil を更新
|
|
42
|
+
* Update $attachedStencil
|
|
43
|
+
*
|
|
44
|
+
* @param {WebGLRenderbuffer | null} resource
|
|
45
|
+
* @return {void}
|
|
46
|
+
* @method
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
export const $setAttachedStencil = (resource) => {
|
|
50
|
+
$attachedStencil = resource;
|
|
5
51
|
};
|
|
6
52
|
export let $drawFrameBuffer = null;
|
|
7
53
|
export const $setDrawFrameBuffer = (gl) => {
|
|
@@ -4,12 +4,17 @@ import type { IPoint } from "../../interface/IPoint";
|
|
|
4
4
|
* @description カーブの矩形を計算する
|
|
5
5
|
* Calculate curve rectangle
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* 曲線を分割し、各区間を左右へ thickness だけずらした輪郭を返す。分割数は、画面上の拡大率
|
|
8
|
+
* (pixel_scale) が分かれば必要な分だけ (1〜32 区間)、分からなければ 32 区間にする。
|
|
9
|
+
* 小さな図形の輪郭 (文字や数字の縁取りなど) は 1〜2 区間で足りることが多く、常に 32 区間に
|
|
10
|
+
* 分けると、輪郭の計算と、そのあとの頂点の生成がそれだけ重くなる。
|
|
8
11
|
* 線の輪郭は図形を初めて描くときに曲線ごとに計算されるため、点や区間ごとに
|
|
9
12
|
* オブジェクトや配列を作ると、その確保と回収が描画の停止として現れる。
|
|
10
13
|
* ここでは作業領域を使い回し、結果の配列だけを作る。
|
|
11
14
|
*
|
|
12
|
-
* Splits the curve
|
|
15
|
+
* Splits the curve and returns the outline offset by thickness on both sides. With a known
|
|
16
|
+
* on-screen scale (pixel_scale) only as many segments as needed are used (1 to 32);
|
|
17
|
+
* otherwise 32. Outlines of small shapes usually need one or two segments.
|
|
13
18
|
* Outlines are computed per curve the first time a shape is drawn, so allocating an object or
|
|
14
19
|
* an array per point or segment shows up as a stall. Work buffers are reused here and only
|
|
15
20
|
* the result array is allocated.
|
|
@@ -18,8 +23,11 @@ import type { IPoint } from "../../interface/IPoint";
|
|
|
18
23
|
* @param {IPoint} control_point
|
|
19
24
|
* @param {IPoint} end_point
|
|
20
25
|
* @param {number} thickness
|
|
26
|
+
* @param {number} [pixel_scale=0] 曲線の座標 1 単位が画面上で何ピクセルになるか。0 以下なら最大数で分割する。
|
|
27
|
+
* On-screen pixels per unit of the curve's coordinates. 0 or less splits
|
|
28
|
+
* into the maximum number of segments.
|
|
21
29
|
* @return {IPath}
|
|
22
30
|
* @memthod
|
|
23
31
|
* @protected
|
|
24
32
|
*/
|
|
25
|
-
export declare const execute: (start_point: IPoint, control_point: IPoint, end_point: IPoint, thickness: number) => IPath;
|
|
33
|
+
export declare const execute: (start_point: IPoint, control_point: IPoint, end_point: IPoint, thickness: number, pixel_scale?: number) => IPath;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @description 2
|
|
3
|
-
*
|
|
2
|
+
* @description 2次ベジェ曲線を半分に分割する回数の上限。分割後の区間数は最大で 2 の SPLIT_COUNT 乗。
|
|
3
|
+
* Maximum number of times a quadratic Bezier curve is halved. The curve ends up in at most
|
|
4
|
+
* 2 ** SPLIT_COUNT segments.
|
|
4
5
|
*
|
|
5
6
|
* @type {number}
|
|
6
7
|
* @const
|
|
@@ -79,16 +80,98 @@ const $offsetPoint = (t, x0, y0, x1, y1, x2, y2, offset) => {
|
|
|
79
80
|
$offsetY = positionY + normalY / length * offset;
|
|
80
81
|
}
|
|
81
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* @description 画面上の誤差の許容値 (ピクセル)。輪郭の近似がこの距離以内に収まる分割回数を選ぶ。
|
|
85
|
+
* Allowed on-screen error in pixels. The split count is chosen so that the outline
|
|
86
|
+
* approximation stays within this distance.
|
|
87
|
+
*
|
|
88
|
+
* @type {number}
|
|
89
|
+
* @const
|
|
90
|
+
*/
|
|
91
|
+
const STROKE_TOLERANCE = 0.05;
|
|
92
|
+
/**
|
|
93
|
+
* @description 2次ベジェ曲線の線の輪郭を作るときに、曲線を半分に分割する回数を求める。
|
|
94
|
+
*
|
|
95
|
+
* 輪郭は、分割した各区間を「t = 0, 0.5, 1 の点を法線方向へずらした 3 点」の 2 次ベジェで
|
|
96
|
+
* 近似する。区間 1 つの弦からのふくらみは (D + thickness * θ² / 8) / 4^n、近似の誤差は
|
|
97
|
+
* その約半分になる (D = |P0 - 2 * P1 + P2| / 4、θ = 始点と終点の接線がなす角、n = 分割回数)。
|
|
98
|
+
* 見積もりに 1.5 倍の余裕を持たせ、画面上の誤差が STROKE_TOLERANCE 以内になる最小の n を返す。
|
|
99
|
+
* 折り返しに近い曲線 (θ が 2 ラジアンを超える) は見積もりが甘くなるので、最大回数にする。
|
|
100
|
+
* pixel_scale が 0 以下のとき (画面上の拡大率が分からない) も最大回数にする。
|
|
101
|
+
*
|
|
102
|
+
* Returns how many times a quadratic Bezier curve is halved when building a stroke outline.
|
|
103
|
+
* Each resulting segment is approximated by the quadratic through the points at t = 0, 0.5
|
|
104
|
+
* and 1 moved along the normal. The sagitta of one segment is
|
|
105
|
+
* (D + thickness * θ² / 8) / 4^n and the approximation error is about half of it
|
|
106
|
+
* (D = |P0 - 2 * P1 + P2| / 4, θ = angle between the end tangents, n = split count).
|
|
107
|
+
* With a 1.5x margin, the smallest n keeping the on-screen error within STROKE_TOLERANCE is
|
|
108
|
+
* returned. Curves that nearly fold back (θ above 2 radians) and an unknown scale
|
|
109
|
+
* (pixel_scale <= 0) use the maximum.
|
|
110
|
+
*
|
|
111
|
+
* @param {number} x0
|
|
112
|
+
* @param {number} y0
|
|
113
|
+
* @param {number} x1
|
|
114
|
+
* @param {number} y1
|
|
115
|
+
* @param {number} x2
|
|
116
|
+
* @param {number} y2
|
|
117
|
+
* @param {number} thickness
|
|
118
|
+
* @param {number} pixel_scale
|
|
119
|
+
* @return {number}
|
|
120
|
+
* @method
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
const $strokeSplitCount = (x0, y0, x1, y1, x2, y2, thickness, pixel_scale) => {
|
|
124
|
+
if (!(pixel_scale > 0)) {
|
|
125
|
+
return SPLIT_COUNT;
|
|
126
|
+
}
|
|
127
|
+
const ax = x1 - x0;
|
|
128
|
+
const ay = y1 - y0;
|
|
129
|
+
const bx = x2 - x1;
|
|
130
|
+
const by = y2 - y1;
|
|
131
|
+
const lengthA = Math.sqrt(ax * ax + ay * ay);
|
|
132
|
+
const lengthB = Math.sqrt(bx * bx + by * by);
|
|
133
|
+
if (lengthA === 0 || lengthB === 0) {
|
|
134
|
+
return SPLIT_COUNT;
|
|
135
|
+
}
|
|
136
|
+
let cosine = (ax * bx + ay * by) / (lengthA * lengthB);
|
|
137
|
+
if (cosine > 1) {
|
|
138
|
+
cosine = 1;
|
|
139
|
+
}
|
|
140
|
+
else if (cosine < -1) {
|
|
141
|
+
cosine = -1;
|
|
142
|
+
}
|
|
143
|
+
const theta = Math.acos(cosine);
|
|
144
|
+
if (theta > 2) {
|
|
145
|
+
return SPLIT_COUNT;
|
|
146
|
+
}
|
|
147
|
+
const dx = x0 - 2 * x1 + x2;
|
|
148
|
+
const dy = y0 - 2 * y1 + y2;
|
|
149
|
+
const sagitta = Math.sqrt(dx * dx + dy * dy) / 4
|
|
150
|
+
+ Math.abs(thickness) * theta * theta / 8;
|
|
151
|
+
// 誤差 (ピクセル) = sagitta / 2 * 1.5 (余裕) * pixel_scale / 4^n <= STROKE_TOLERANCE
|
|
152
|
+
let error = sagitta * 0.75 * pixel_scale;
|
|
153
|
+
let count = 0;
|
|
154
|
+
while (error > STROKE_TOLERANCE && count < SPLIT_COUNT) {
|
|
155
|
+
error *= 0.25;
|
|
156
|
+
++count;
|
|
157
|
+
}
|
|
158
|
+
return count;
|
|
159
|
+
};
|
|
82
160
|
/**
|
|
83
161
|
* @description カーブの矩形を計算する
|
|
84
162
|
* Calculate curve rectangle
|
|
85
163
|
*
|
|
86
|
-
*
|
|
164
|
+
* 曲線を分割し、各区間を左右へ thickness だけずらした輪郭を返す。分割数は、画面上の拡大率
|
|
165
|
+
* (pixel_scale) が分かれば必要な分だけ (1〜32 区間)、分からなければ 32 区間にする。
|
|
166
|
+
* 小さな図形の輪郭 (文字や数字の縁取りなど) は 1〜2 区間で足りることが多く、常に 32 区間に
|
|
167
|
+
* 分けると、輪郭の計算と、そのあとの頂点の生成がそれだけ重くなる。
|
|
87
168
|
* 線の輪郭は図形を初めて描くときに曲線ごとに計算されるため、点や区間ごとに
|
|
88
169
|
* オブジェクトや配列を作ると、その確保と回収が描画の停止として現れる。
|
|
89
170
|
* ここでは作業領域を使い回し、結果の配列だけを作る。
|
|
90
171
|
*
|
|
91
|
-
* Splits the curve
|
|
172
|
+
* Splits the curve and returns the outline offset by thickness on both sides. With a known
|
|
173
|
+
* on-screen scale (pixel_scale) only as many segments as needed are used (1 to 32);
|
|
174
|
+
* otherwise 32. Outlines of small shapes usually need one or two segments.
|
|
92
175
|
* Outlines are computed per curve the first time a shape is drawn, so allocating an object or
|
|
93
176
|
* an array per point or segment shows up as a stall. Work buffers are reused here and only
|
|
94
177
|
* the result array is allocated.
|
|
@@ -97,12 +180,16 @@ const $offsetPoint = (t, x0, y0, x1, y1, x2, y2, offset) => {
|
|
|
97
180
|
* @param {IPoint} control_point
|
|
98
181
|
* @param {IPoint} end_point
|
|
99
182
|
* @param {number} thickness
|
|
183
|
+
* @param {number} [pixel_scale=0] 曲線の座標 1 単位が画面上で何ピクセルになるか。0 以下なら最大数で分割する。
|
|
184
|
+
* On-screen pixels per unit of the curve's coordinates. 0 or less splits
|
|
185
|
+
* into the maximum number of segments.
|
|
100
186
|
* @return {IPath}
|
|
101
187
|
* @memthod
|
|
102
188
|
* @protected
|
|
103
189
|
*/
|
|
104
|
-
export const execute = (start_point, control_point, end_point, thickness) => {
|
|
105
|
-
|
|
190
|
+
export const execute = (start_point, control_point, end_point, thickness, pixel_scale = 0) => {
|
|
191
|
+
const splitCount = $strokeSplitCount(start_point.x, start_point.y, control_point.x, control_point.y, end_point.x, end_point.y, thickness, pixel_scale);
|
|
192
|
+
// 曲線を半分に分割することを splitCount 回繰り返す (De Casteljau、t = 0.5)
|
|
106
193
|
let segments = $segments;
|
|
107
194
|
let nextSegments = $nextSegments;
|
|
108
195
|
segments[0] = start_point.x;
|
|
@@ -112,7 +199,7 @@ export const execute = (start_point, control_point, end_point, thickness) => {
|
|
|
112
199
|
segments[4] = end_point.x;
|
|
113
200
|
segments[5] = end_point.y;
|
|
114
201
|
let count = 1;
|
|
115
|
-
for (let split = 0; split <
|
|
202
|
+
for (let split = 0; split < splitCount; ++split) {
|
|
116
203
|
for (let idx = 0; idx < count; ++idx) {
|
|
117
204
|
const source = idx * 6;
|
|
118
205
|
const x0 = segments[source];
|
|
@@ -41,6 +41,12 @@ export const execute = (vertices, thickness) => {
|
|
|
41
41
|
const prevPoint = $prevPoint;
|
|
42
42
|
prevPoint.x = 0;
|
|
43
43
|
prevPoint.y = 0;
|
|
44
|
+
// 曲線の座標 1 単位が画面上で何ピクセルになるか (曲線の分割数を決めるのに使う)。
|
|
45
|
+
// 描画行列の x 軸 / y 軸方向の拡大率の大きい方。
|
|
46
|
+
const matrix = $context.$matrix;
|
|
47
|
+
const scaleX = Math.sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]);
|
|
48
|
+
const scaleY = Math.sqrt(matrix[3] * matrix[3] + matrix[4] * matrix[4]);
|
|
49
|
+
const pixelScale = scaleX > scaleY ? scaleX : scaleY;
|
|
44
50
|
const rectangles = [];
|
|
45
51
|
for (let idx = 3; idx < vertices.length; idx += 3) {
|
|
46
52
|
const x = vertices[idx];
|
|
@@ -53,7 +59,7 @@ export const execute = (vertices, thickness) => {
|
|
|
53
59
|
endPoint.x = x;
|
|
54
60
|
endPoint.y = y;
|
|
55
61
|
if (vertices[idx - 1]) {
|
|
56
|
-
rectangles.push(meshCalculateCurveRectangleUseCase(startPoint, controlPoint, endPoint, thickness));
|
|
62
|
+
rectangles.push(meshCalculateCurveRectangleUseCase(startPoint, controlPoint, endPoint, thickness, pixelScale));
|
|
57
63
|
}
|
|
58
64
|
else {
|
|
59
65
|
rectangles.push(meshCalculateLineRectangleUseCase(startPoint, endPoint, thickness));
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { execute as pathCommandMoveToUseCase } from "./PathCommandMoveToUseCase";
|
|
2
|
-
import { execute as pathCommandEqualsToLastPointService } from "../service/PathCommandEqualsToLastPointService";
|
|
3
2
|
import { execute as pathCommandQuadraticCurveToUseCase } from "./PathCommandQuadraticCurveToUseCase";
|
|
4
3
|
import { execute as bezierConverterAdaptiveCubicToQuadUseCase } from "../../BezierConverter/usecase/BezierConverterAdaptiveCubicToQuadUseCase";
|
|
5
4
|
import { $currentPath } from "../../PathCommand";
|
|
5
|
+
import { $context } from "../../WebGLUtil";
|
|
6
|
+
import { $CUBIC_SINGLE_SEGMENT_LIMIT } from "../../BezierConverter";
|
|
6
7
|
/**
|
|
7
8
|
* @description 3次ベジェ曲線を描画します。適応的テッセレーションにより曲率に応じた分割を行います。
|
|
8
9
|
* Draw a cubic Bezier curve. Uses adaptive tessellation based on curvature.
|
|
@@ -21,15 +22,38 @@ export const execute = (cx1, cy1, cx2, cy2, x, y) => {
|
|
|
21
22
|
if (!$currentPath.length) {
|
|
22
23
|
pathCommandMoveToUseCase(0, 0);
|
|
23
24
|
}
|
|
24
|
-
if (pathCommandEqualsToLastPointService(x, y)) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
25
|
const length = $currentPath.length;
|
|
28
26
|
const fromX = +$currentPath[length - 3];
|
|
29
27
|
const fromY = +$currentPath[length - 2];
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
// 終点が現在の点と同じなら何もしない
|
|
29
|
+
if (x === fromX && y === fromY) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// 曲線の座標 1 単位が画面上で何ピクセルになるか (描画行列の x 軸 / y 軸方向の拡大率の大きい方) の 2 乗。
|
|
33
|
+
// 2次ベジェ曲線で近似するときの本数を、画面上の誤差から決めるのに使う。
|
|
34
|
+
// 描画コンテキストが無い場合 (経路だけを組み立てる場合) は 0 とし、従来の分割数になる。
|
|
35
|
+
let scaleSquared = 0;
|
|
36
|
+
if ($context) {
|
|
37
|
+
const matrix = $context.$matrix;
|
|
38
|
+
const scaleX = matrix[0] * matrix[0] + matrix[1] * matrix[1];
|
|
39
|
+
const scaleY = matrix[3] * matrix[3] + matrix[4] * matrix[4];
|
|
40
|
+
scaleSquared = scaleX > scaleY ? scaleX : scaleY;
|
|
41
|
+
}
|
|
42
|
+
if (scaleSquared > 0) {
|
|
43
|
+
// 1 本の2次ベジェ曲線で足りる場合 (小さな図形の曲線の大半) は、ここで制御点を求めて直接追加する。
|
|
44
|
+
// 画面上の誤差 √3 / 36 * |P3 - 3 * P2 + 3 * P1 - P0| * scale が許容値以内かどうかを、
|
|
45
|
+
// 平方根を取らずに 2 乗どうしで比べる。汎用の経路は曲線 1 本ごとに関数を何段も呼び、
|
|
46
|
+
// 結果を作業用バッファ経由で受け渡すため、曲線の多い図形ではその呼び出しが時間の大半になる。
|
|
47
|
+
// When one quadratic curve is enough (most curves of small shapes), compute the control
|
|
48
|
+
// point here and append it directly, comparing squared values instead of taking square roots.
|
|
49
|
+
const dx = x - 3 * cx2 + 3 * cx1 - fromX;
|
|
50
|
+
const dy = y - 3 * cy2 + 3 * cy1 - fromY;
|
|
51
|
+
if ((dx * dx + dy * dy) * scaleSquared <= $CUBIC_SINGLE_SEGMENT_LIMIT) {
|
|
52
|
+
$currentPath.push((3 * cx1 + 3 * cx2 - fromX - x) * 0.25, (3 * cy1 + 3 * cy2 - fromY - y) * 0.25, true, x, y, false);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const result = bezierConverterAdaptiveCubicToQuadUseCase(fromX, fromY, cx1, cy1, cx2, cy2, x, y, scaleSquared > 0 ? Math.sqrt(scaleSquared) : 0);
|
|
33
57
|
const buffer = result.buffer;
|
|
34
58
|
const count = result.count;
|
|
35
59
|
for (let idx = 0; idx < count * 4;) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { $GRADIENT_LUT_SHARED_STOPS } from "../../GradientLUTGenerator";
|
|
1
2
|
/**
|
|
2
3
|
* @description グラデーションフィルターのLUTのuniform変数を設定します。
|
|
3
4
|
* Set the uniform variables of the gradient filter LUT.
|
|
@@ -14,6 +15,13 @@
|
|
|
14
15
|
*/
|
|
15
16
|
export const execute = (shader_manager, ratios, colors, alphas, begin, end) => {
|
|
16
17
|
const mediump = shader_manager.mediump;
|
|
18
|
+
// 共用のシェーダー (共用のストップ数用。u_mediump の要素数で見分ける) に、それより少ない
|
|
19
|
+
// ストップを渡すときは、足りない分を最後のストップ (同じ色・同じ位置) で埋める。
|
|
20
|
+
const count = end - begin;
|
|
21
|
+
const capacity = count < $GRADIENT_LUT_SHARED_STOPS
|
|
22
|
+
&& mediump.length === Math.ceil($GRADIENT_LUT_SHARED_STOPS * 5 / 4) * 4
|
|
23
|
+
? $GRADIENT_LUT_SHARED_STOPS
|
|
24
|
+
: count;
|
|
17
25
|
// fragment: u_gradient_color
|
|
18
26
|
let i = 0;
|
|
19
27
|
for (let j = begin; j < end; j++) {
|
|
@@ -23,8 +31,17 @@ export const execute = (shader_manager, ratios, colors, alphas, begin, end) => {
|
|
|
23
31
|
mediump[i++] = (color & 0xff) / 255;
|
|
24
32
|
mediump[i++] = alphas[j];
|
|
25
33
|
}
|
|
34
|
+
for (let j = count; j < capacity; j++) {
|
|
35
|
+
mediump[i++] = mediump[count * 4 - 4];
|
|
36
|
+
mediump[i++] = mediump[count * 4 - 3];
|
|
37
|
+
mediump[i++] = mediump[count * 4 - 2];
|
|
38
|
+
mediump[i++] = mediump[count * 4 - 1];
|
|
39
|
+
}
|
|
26
40
|
// fragment: u_gradient_t
|
|
27
41
|
for (let j = begin; j < end; j++) {
|
|
28
42
|
mediump[i++] = ratios[j] / 255;
|
|
29
43
|
}
|
|
44
|
+
for (let j = count; j < capacity; j++) {
|
|
45
|
+
mediump[i++] = ratios[end - 1] / 255;
|
|
46
|
+
}
|
|
30
47
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { $GRADIENT_LUT_SHARED_STOPS } from "../../GradientLUTGenerator";
|
|
1
2
|
/**
|
|
2
3
|
* @description グラデーションLUTのuniform変数を設定します。
|
|
3
4
|
* Set the uniform variables of the gradient LUT.
|
|
@@ -13,6 +14,13 @@
|
|
|
13
14
|
*/
|
|
14
15
|
export const execute = (shader_manager, stops, begin, end, table) => {
|
|
15
16
|
const mediump = shader_manager.mediump;
|
|
17
|
+
// 共用のシェーダー (共用のストップ数用。u_mediump の要素数で見分ける) に、それより少ない
|
|
18
|
+
// ストップを渡すときは、足りない分を最後のストップ (同じ色・同じ位置) で埋める。
|
|
19
|
+
const count = end - begin;
|
|
20
|
+
const capacity = count < $GRADIENT_LUT_SHARED_STOPS
|
|
21
|
+
&& mediump.length === Math.ceil($GRADIENT_LUT_SHARED_STOPS * 5 / 4) * 4
|
|
22
|
+
? $GRADIENT_LUT_SHARED_STOPS
|
|
23
|
+
: count;
|
|
16
24
|
let index = 0;
|
|
17
25
|
// fragment: u_gradient_color
|
|
18
26
|
for (let idx = begin; idx < end; ++idx) {
|
|
@@ -22,8 +30,17 @@ export const execute = (shader_manager, stops, begin, end, table) => {
|
|
|
22
30
|
mediump[index++] = table[stops[position + 3]];
|
|
23
31
|
mediump[index++] = table[stops[position + 4]];
|
|
24
32
|
}
|
|
33
|
+
for (let idx = count; idx < capacity; ++idx) {
|
|
34
|
+
mediump[index++] = mediump[count * 4 - 4];
|
|
35
|
+
mediump[index++] = mediump[count * 4 - 3];
|
|
36
|
+
mediump[index++] = mediump[count * 4 - 2];
|
|
37
|
+
mediump[index++] = mediump[count * 4 - 1];
|
|
38
|
+
}
|
|
25
39
|
// fragment: u_gradient_t
|
|
26
40
|
for (let idx = begin; idx < end; ++idx) {
|
|
27
41
|
mediump[index++] = stops[idx * 5];
|
|
28
42
|
}
|
|
43
|
+
for (let idx = count; idx < capacity; ++idx) {
|
|
44
|
+
mediump[index++] = stops[(end - 1) * 5];
|
|
45
|
+
}
|
|
29
46
|
};
|
|
@@ -28,6 +28,32 @@ export declare const $getGradientAttachmentObjectWithResolution: (resolution: nu
|
|
|
28
28
|
* @protected
|
|
29
29
|
*/
|
|
30
30
|
export declare const $getGradientAttachmentObject: () => IAttachmentObject;
|
|
31
|
+
/**
|
|
32
|
+
* @description LUT 生成シェーダーを共用するストップ数。これ以下のストップ数のグラデーションは、
|
|
33
|
+
* すべてこのストップ数用のシェーダーで処理する。
|
|
34
|
+
*
|
|
35
|
+
* LUT 生成シェーダーはストップ数ごとに別のプログラムになるので、新しいストップ数の
|
|
36
|
+
* グラデーションが初めて出るたびに、コンパイルとリンクが走る (画面が一瞬止まる)。
|
|
37
|
+
* 足りないストップを最後のストップ (同じ色・同じ位置) で埋めれば、埋めた区間は
|
|
38
|
+
* 通らないので、結果はストップ数ごとのシェーダーと同じになる。
|
|
39
|
+
*
|
|
40
|
+
* The stop count whose LUT generator shader is shared. Gradients with this many stops
|
|
41
|
+
* or fewer all use that one shader. The generator is a separate program per stop count,
|
|
42
|
+
* so a program is compiled and linked whenever a new stop count first appears (a visible
|
|
43
|
+
* stall). Padding the missing stops with the last stop (same color, same position) never
|
|
44
|
+
* takes the padded segments, so the result equals the per-count shader's.
|
|
45
|
+
*
|
|
46
|
+
* 8 個にしているのは、シェーダーのコンパイルとリンクの時間がストップ数に対して急に
|
|
47
|
+
* 増えるため (16 個用は 8 個用の数十倍かかるドライバがある)。9 個以上は従来どおり
|
|
48
|
+
* ストップ数ごとのシェーダーを使う。
|
|
49
|
+
* It is 8 because compile and link time grows steeply with the stop count (on some
|
|
50
|
+
* drivers the 16-stop shader takes tens of times longer than the 8-stop one). Nine or
|
|
51
|
+
* more stops keep using a shader per stop count.
|
|
52
|
+
*
|
|
53
|
+
* @type {number}
|
|
54
|
+
* @const
|
|
55
|
+
*/
|
|
56
|
+
export declare const $GRADIENT_LUT_SHARED_STOPS: number;
|
|
31
57
|
/**
|
|
32
58
|
* @description 最大長を返却
|
|
33
59
|
* Returns the maximum length
|
|
@@ -57,6 +57,32 @@ export const $getGradientAttachmentObject = () => {
|
|
|
57
57
|
* @private
|
|
58
58
|
*/
|
|
59
59
|
let $maxLength = 0;
|
|
60
|
+
/**
|
|
61
|
+
* @description LUT 生成シェーダーを共用するストップ数。これ以下のストップ数のグラデーションは、
|
|
62
|
+
* すべてこのストップ数用のシェーダーで処理する。
|
|
63
|
+
*
|
|
64
|
+
* LUT 生成シェーダーはストップ数ごとに別のプログラムになるので、新しいストップ数の
|
|
65
|
+
* グラデーションが初めて出るたびに、コンパイルとリンクが走る (画面が一瞬止まる)。
|
|
66
|
+
* 足りないストップを最後のストップ (同じ色・同じ位置) で埋めれば、埋めた区間は
|
|
67
|
+
* 通らないので、結果はストップ数ごとのシェーダーと同じになる。
|
|
68
|
+
*
|
|
69
|
+
* The stop count whose LUT generator shader is shared. Gradients with this many stops
|
|
70
|
+
* or fewer all use that one shader. The generator is a separate program per stop count,
|
|
71
|
+
* so a program is compiled and linked whenever a new stop count first appears (a visible
|
|
72
|
+
* stall). Padding the missing stops with the last stop (same color, same position) never
|
|
73
|
+
* takes the padded segments, so the result equals the per-count shader's.
|
|
74
|
+
*
|
|
75
|
+
* 8 個にしているのは、シェーダーのコンパイルとリンクの時間がストップ数に対して急に
|
|
76
|
+
* 増えるため (16 個用は 8 個用の数十倍かかるドライバがある)。9 個以上は従来どおり
|
|
77
|
+
* ストップ数ごとのシェーダーを使う。
|
|
78
|
+
* It is 8 because compile and link time grows steeply with the stop count (on some
|
|
79
|
+
* drivers the 16-stop shader takes tens of times longer than the 8-stop one). Nine or
|
|
80
|
+
* more stops keep using a shader per stop count.
|
|
81
|
+
*
|
|
82
|
+
* @type {number}
|
|
83
|
+
* @const
|
|
84
|
+
*/
|
|
85
|
+
export const $GRADIENT_LUT_SHARED_STOPS = 8;
|
|
60
86
|
/**
|
|
61
87
|
* @description 最大長を返却
|
|
62
88
|
* Returns the maximum length
|
|
@@ -3,12 +3,6 @@ import { renderQueue } from "@next2d/render-queue";
|
|
|
3
3
|
export class ShaderInstancedManager extends ShaderManager {
|
|
4
4
|
constructor(vertex_source, fragment_source, atlas = true) {
|
|
5
5
|
super(vertex_source, fragment_source, atlas);
|
|
6
|
-
Object.defineProperty(this, "count", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
6
|
this.count = 0;
|
|
13
7
|
}
|
|
14
8
|
clear() {
|
|
@@ -4,36 +4,6 @@ import { execute as shaderManagerUseProgramService } from "./ShaderManager/servi
|
|
|
4
4
|
import { execute as shaderManagerBindUniformService } from "./ShaderManager/service/ShaderManagerBindUniformService";
|
|
5
5
|
export class ShaderManager {
|
|
6
6
|
constructor(vertex_source, fragment_source, atlas = false) {
|
|
7
|
-
Object.defineProperty(this, "_$programObject", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
writable: true,
|
|
11
|
-
value: void 0
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(this, "_$uniformMap", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: true,
|
|
16
|
-
writable: true,
|
|
17
|
-
value: void 0
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(this, "highp", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true,
|
|
22
|
-
writable: true,
|
|
23
|
-
value: void 0
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(this, "mediump", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
configurable: true,
|
|
28
|
-
writable: true,
|
|
29
|
-
value: void 0
|
|
30
|
-
});
|
|
31
|
-
Object.defineProperty(this, "textures", {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
configurable: true,
|
|
34
|
-
writable: true,
|
|
35
|
-
value: void 0
|
|
36
|
-
});
|
|
37
7
|
this._$programObject = shaderManagerCreateProgramService(vertex_source, fragment_source);
|
|
38
8
|
this._$uniformMap = new Map();
|
|
39
9
|
shaderManagerInitializeUniformService(this._$programObject.resource, this._$uniformMap, atlas);
|
|
@@ -2,6 +2,7 @@ import { $getFromCache, $addToCache } from "../../GradientLUTVariants";
|
|
|
2
2
|
import { ShaderManager } from "../../../ShaderManager";
|
|
3
3
|
import { TEXTURE_TEMPLATE } from "../../../Vertex/VertexShaderSource";
|
|
4
4
|
import { GRADIENT_LUT_TEMPLATE } from "../../../Fragment/FragmentShaderSourceGradientLUT";
|
|
5
|
+
import { $GRADIENT_LUT_SHARED_STOPS } from "../../../GradientLUTGenerator";
|
|
5
6
|
/**
|
|
6
7
|
* @description グラデーションLUTのシェーダーを返却(LRUキャッシュ使用)
|
|
7
8
|
* Returns the shader of the gradient LUT (using LRU cache)
|
|
@@ -13,6 +14,11 @@ import { GRADIENT_LUT_TEMPLATE } from "../../../Fragment/FragmentShaderSourceGra
|
|
|
13
14
|
* @protected
|
|
14
15
|
*/
|
|
15
16
|
export const execute = (stops_length, is_linear_space) => {
|
|
17
|
+
// 共用するストップ数以下は、すべて同じシェーダーを使う (ストップ数ごとのリンクを避ける)。
|
|
18
|
+
// uniform を設定する側が、足りないストップを最後のストップで埋める。
|
|
19
|
+
if (stops_length < $GRADIENT_LUT_SHARED_STOPS) {
|
|
20
|
+
stops_length = $GRADIENT_LUT_SHARED_STOPS;
|
|
21
|
+
}
|
|
16
22
|
const key1 = ("00" + stops_length).slice(-3);
|
|
17
23
|
const key2 = is_linear_space ? "y" : "n";
|
|
18
24
|
const key = `l${key1}${key2}`;
|