@next2d/webgl 1.14.20
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/BezierConverter.d.ts +59 -0
- package/dist/BezierConverter.js +106 -0
- package/dist/CanvasGradientToWebGL.d.ts +96 -0
- package/dist/CanvasGradientToWebGL.js +181 -0
- package/dist/CanvasPatternToWebGL.d.ts +39 -0
- package/dist/CanvasPatternToWebGL.js +66 -0
- package/dist/CanvasToWebGLContext.d.ts +591 -0
- package/dist/CanvasToWebGLContext.js +1427 -0
- package/dist/CanvasToWebGLContextBlend.d.ts +97 -0
- package/dist/CanvasToWebGLContextBlend.js +299 -0
- package/dist/CanvasToWebGLContextGrid.d.ts +74 -0
- package/dist/CanvasToWebGLContextGrid.js +283 -0
- package/dist/CanvasToWebGLContextMask.d.ts +113 -0
- package/dist/CanvasToWebGLContextMask.js +436 -0
- package/dist/CanvasToWebGLContextPath.d.ts +111 -0
- package/dist/CanvasToWebGLContextPath.js +210 -0
- package/dist/CanvasToWebGLContextStyle.d.ts +78 -0
- package/dist/CanvasToWebGLContextStyle.js +139 -0
- package/dist/ColorBufferPool.d.ts +58 -0
- package/dist/ColorBufferPool.js +134 -0
- package/dist/FrameBufferManager.d.ts +135 -0
- package/dist/FrameBufferManager.js +358 -0
- package/dist/StencilBufferPool.d.ts +56 -0
- package/dist/StencilBufferPool.js +142 -0
- package/dist/TextureManager.d.ts +130 -0
- package/dist/TextureManager.js +296 -0
- package/dist/VertexArrayObjectManager.d.ts +96 -0
- package/dist/VertexArrayObjectManager.js +277 -0
- package/dist/WebGLFillMeshGenerator.d.ts +31 -0
- package/dist/WebGLFillMeshGenerator.js +101 -0
- package/dist/WebGLStrokeMeshGenerator.d.ts +183 -0
- package/dist/WebGLStrokeMeshGenerator.js +504 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/interface/AttachmentImpl.d.ts +11 -0
- package/dist/interface/AttachmentImpl.js +1 -0
- package/dist/interface/BoundsImpl.d.ts +6 -0
- package/dist/interface/BoundsImpl.js +1 -0
- package/dist/interface/CapsStyleImpl.d.ts +1 -0
- package/dist/interface/CapsStyleImpl.js +1 -0
- package/dist/interface/ClipObjectImpl.d.ts +14 -0
- package/dist/interface/ClipObjectImpl.js +1 -0
- package/dist/interface/FillMeshImpl.d.ts +5 -0
- package/dist/interface/FillMeshImpl.js +1 -0
- package/dist/interface/GradientTypeImpl.d.ts +1 -0
- package/dist/interface/GradientTypeImpl.js +1 -0
- package/dist/interface/GridImpl.d.ts +6 -0
- package/dist/interface/GridImpl.js +1 -0
- package/dist/interface/IndexRangeImpl.d.ts +4 -0
- package/dist/interface/IndexRangeImpl.js +1 -0
- package/dist/interface/InterpolationMethodImpl.d.ts +1 -0
- package/dist/interface/InterpolationMethodImpl.js +1 -0
- package/dist/interface/JointStyleImpl.d.ts +1 -0
- package/dist/interface/JointStyleImpl.js +1 -0
- package/dist/interface/SpreadMethodImpl.d.ts +1 -0
- package/dist/interface/SpreadMethodImpl.js +1 -0
- package/dist/interface/StrokeMethImpl.d.ts +4 -0
- package/dist/interface/StrokeMethImpl.js +1 -0
- package/dist/interface/UniformDataImpl.d.ts +5 -0
- package/dist/interface/UniformDataImpl.js +1 -0
- package/dist/interface/VerticesImpl.d.ts +1 -0
- package/dist/interface/VerticesImpl.js +1 -0
- package/dist/shader/CanvasToWebGLShader.d.ts +85 -0
- package/dist/shader/CanvasToWebGLShader.js +192 -0
- package/dist/shader/CanvasToWebGLShaderList.d.ts +70 -0
- package/dist/shader/CanvasToWebGLShaderList.js +109 -0
- package/dist/shader/GradientLUTGenerator.d.ts +36 -0
- package/dist/shader/GradientLUTGenerator.js +123 -0
- package/dist/shader/WebGLShaderUniform.d.ts +52 -0
- package/dist/shader/WebGLShaderUniform.js +165 -0
- package/dist/shader/fragment/FragmentShaderLibrary.d.ts +18 -0
- package/dist/shader/fragment/FragmentShaderLibrary.js +35 -0
- package/dist/shader/fragment/FragmentShaderSource.d.ts +29 -0
- package/dist/shader/fragment/FragmentShaderSource.js +99 -0
- package/dist/shader/fragment/FragmentShaderSourceBlend.d.ts +67 -0
- package/dist/shader/fragment/FragmentShaderSourceBlend.js +319 -0
- package/dist/shader/fragment/FragmentShaderSourceGradient.d.ts +44 -0
- package/dist/shader/fragment/FragmentShaderSourceGradient.js +114 -0
- package/dist/shader/fragment/FragmentShaderSourceGradientLUT.d.ts +14 -0
- package/dist/shader/fragment/FragmentShaderSourceGradientLUT.js +58 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.d.ts +12 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.js +36 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.d.ts +12 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.js +42 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.d.ts +11 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.js +35 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.d.ts +16 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.js +80 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.d.ts +15 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.js +106 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceFilter.d.ts +112 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceFilter.js +275 -0
- package/dist/shader/variants/BlendShaderVariantCollection.d.ts +99 -0
- package/dist/shader/variants/BlendShaderVariantCollection.js +239 -0
- package/dist/shader/variants/FilterShaderVariantCollection.d.ts +150 -0
- package/dist/shader/variants/FilterShaderVariantCollection.js +395 -0
- package/dist/shader/variants/GradientLUTShaderVariantCollection.d.ts +49 -0
- package/dist/shader/variants/GradientLUTShaderVariantCollection.js +107 -0
- package/dist/shader/variants/GradientShapeShaderVariantCollection.d.ts +61 -0
- package/dist/shader/variants/GradientShapeShaderVariantCollection.js +196 -0
- package/dist/shader/variants/ShapeShaderVariantCollection.d.ts +117 -0
- package/dist/shader/variants/ShapeShaderVariantCollection.js +427 -0
- package/dist/shader/vertex/VertexShaderLibrary.d.ts +18 -0
- package/dist/shader/vertex/VertexShaderLibrary.js +75 -0
- package/dist/shader/vertex/VertexShaderSource.d.ts +23 -0
- package/dist/shader/vertex/VertexShaderSource.js +92 -0
- package/dist/shader/vertex/VertexShaderSourceFill.d.ts +45 -0
- package/dist/shader/vertex/VertexShaderSourceFill.js +112 -0
- package/dist/shader/vertex/VertexShaderSourceStroke.d.ts +27 -0
- package/dist/shader/vertex/VertexShaderSourceStroke.js +149 -0
- package/package.json +37 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { BezierConverter } from "./BezierConverter";
|
|
2
|
+
import { $getArray, $poolArray } from "@next2d/share";
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export class CanvasToWebGLContextPath {
|
|
7
|
+
/**
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
constructor() {
|
|
11
|
+
/**
|
|
12
|
+
* @type {array}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
this._$currentPath = $getArray();
|
|
16
|
+
/**
|
|
17
|
+
* @type {array}
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
this._$vertices = $getArray();
|
|
21
|
+
/**
|
|
22
|
+
* @type {BezierConverter}
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
this._$bezierConverter = new BezierConverter();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @member {array}
|
|
29
|
+
* @readonly
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
get vertices() {
|
|
33
|
+
this._$pushCurrentPathToVertices();
|
|
34
|
+
return this._$vertices;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @return {void}
|
|
38
|
+
* @method
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
begin() {
|
|
42
|
+
this._$currentPath.length = 0;
|
|
43
|
+
while (this._$vertices.length) {
|
|
44
|
+
$poolArray(this._$vertices.pop());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @param {number} x
|
|
49
|
+
* @param {number} y
|
|
50
|
+
* @return {void}
|
|
51
|
+
* @method
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
moveTo(x, y) {
|
|
55
|
+
if (!this._$currentPath.length) {
|
|
56
|
+
this._$pushPointToCurrentPath(x, y, false);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (this._$equalsToLastPoint(x, y)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this._$pushCurrentPathToVertices();
|
|
63
|
+
this._$pushPointToCurrentPath(x, y, false);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @param {number} x
|
|
67
|
+
* @param {number} y
|
|
68
|
+
* @return {void}
|
|
69
|
+
* @method
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
lineTo(x, y) {
|
|
73
|
+
if (!this._$currentPath.length) {
|
|
74
|
+
this.moveTo(0, 0);
|
|
75
|
+
}
|
|
76
|
+
if (this._$equalsToLastPoint(x, y)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
this._$pushPointToCurrentPath(x, y, false);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @param {number} cx
|
|
83
|
+
* @param {number} cy
|
|
84
|
+
* @param {number} x
|
|
85
|
+
* @param {number} y
|
|
86
|
+
* @return {void}
|
|
87
|
+
* @method
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
quadTo(cx, cy, x, y) {
|
|
91
|
+
if (!this._$currentPath.length) {
|
|
92
|
+
this.moveTo(0, 0);
|
|
93
|
+
}
|
|
94
|
+
if (this._$equalsToLastPoint(x, y)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this._$pushPointToCurrentPath(cx, cy, true);
|
|
98
|
+
this._$pushPointToCurrentPath(x, y, false);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @param {number} cx1
|
|
102
|
+
* @param {number} cy1
|
|
103
|
+
* @param {number} cx2
|
|
104
|
+
* @param {number} cy2
|
|
105
|
+
* @param {number} x
|
|
106
|
+
* @param {number} y
|
|
107
|
+
* @return {void}
|
|
108
|
+
* @method
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
cubicTo(cx1, cy1, cx2, cy2, x, y) {
|
|
112
|
+
if (!this._$currentPath.length) {
|
|
113
|
+
this.moveTo(0, 0);
|
|
114
|
+
}
|
|
115
|
+
if (this._$equalsToLastPoint(x, y)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const fromX = +this._$currentPath[this._$currentPath.length - 3];
|
|
119
|
+
const fromY = +this._$currentPath[this._$currentPath.length - 2];
|
|
120
|
+
this
|
|
121
|
+
._$bezierConverter
|
|
122
|
+
.cubicToQuad(fromX, fromY, cx1, cy1, cx2, cy2, x, y);
|
|
123
|
+
const buffer = this
|
|
124
|
+
._$bezierConverter
|
|
125
|
+
._$bezierConverterBuffer;
|
|
126
|
+
for (let i = 0; i < 32;) {
|
|
127
|
+
this.quadTo(buffer[i++], buffer[i++], buffer[i++], buffer[i++]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @param {number} x
|
|
132
|
+
* @param {number} y
|
|
133
|
+
* @param {number} radius
|
|
134
|
+
* @return {void}
|
|
135
|
+
* @method
|
|
136
|
+
* @public
|
|
137
|
+
*/
|
|
138
|
+
drawCircle(x, y, radius) {
|
|
139
|
+
const r = radius;
|
|
140
|
+
const k = radius * 0.5522847498307936;
|
|
141
|
+
this.cubicTo(x + r, y + k, x + k, y + r, x, y + r);
|
|
142
|
+
this.cubicTo(x - k, y + r, x - r, y + k, x - r, y);
|
|
143
|
+
this.cubicTo(x - r, y - k, x - k, y - r, x, y - r);
|
|
144
|
+
this.cubicTo(x + k, y - r, x + r, y - k, x + r, y);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @return {void}
|
|
148
|
+
* @method
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
close() {
|
|
152
|
+
if (this._$currentPath.length <= 6) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const x = +this._$currentPath[0];
|
|
156
|
+
const y = +this._$currentPath[1];
|
|
157
|
+
if (this._$equalsToLastPoint(x, y)) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
this._$pushPointToCurrentPath(x, y, false);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @param {number} x
|
|
164
|
+
* @param {number} y
|
|
165
|
+
* @return {boolean}
|
|
166
|
+
* @method
|
|
167
|
+
* @private
|
|
168
|
+
*/
|
|
169
|
+
_$equalsToLastPoint(x, y) {
|
|
170
|
+
const lastX = +this._$currentPath[this._$currentPath.length - 3];
|
|
171
|
+
const lastY = +this._$currentPath[this._$currentPath.length - 2];
|
|
172
|
+
return x === lastX && y === lastY;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* @param {number} x
|
|
176
|
+
* @param {number} y
|
|
177
|
+
* @param {boolean} is_control_point
|
|
178
|
+
* @return {void}
|
|
179
|
+
* @method
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
_$pushPointToCurrentPath(x, y, is_control_point) {
|
|
183
|
+
this._$currentPath.push(x, y, is_control_point);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* @return {void}
|
|
187
|
+
* @method
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
_$pushCurrentPathToVertices() {
|
|
191
|
+
if (this._$currentPath.length < 4) {
|
|
192
|
+
this._$currentPath.length = 0;
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this._$vertices.push(this._$currentPath);
|
|
196
|
+
this._$currentPath = $getArray();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @param {number} x
|
|
200
|
+
* @param {number} y
|
|
201
|
+
* @param {number} w
|
|
202
|
+
* @param {number} h
|
|
203
|
+
* @return {array}
|
|
204
|
+
* @method
|
|
205
|
+
* @public
|
|
206
|
+
*/
|
|
207
|
+
createRectVertices(x, y, w, h) {
|
|
208
|
+
return $getArray($getArray(x, y, false, x + w, y, false, x + w, y + h, false, x, y + h, false));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CanvasGradientToWebGL } from "./CanvasGradientToWebGL";
|
|
2
|
+
import { CanvasPatternToWebGL } from "./CanvasPatternToWebGL";
|
|
3
|
+
import type { CapsStyleImpl } from "./interface/CapsStyleImpl";
|
|
4
|
+
import type { JointStyleImpl } from "./interface/JointStyleImpl";
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
*/
|
|
8
|
+
export declare class CanvasToWebGLContextStyle {
|
|
9
|
+
private _$fillStyle;
|
|
10
|
+
private _$strokeStyle;
|
|
11
|
+
private _$lineWidth;
|
|
12
|
+
private _$lineCap;
|
|
13
|
+
private _$lineJoin;
|
|
14
|
+
private _$miterLimit;
|
|
15
|
+
/**
|
|
16
|
+
* @constructor
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* @member {number}
|
|
22
|
+
* @default 5
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
get miterLimit(): number;
|
|
26
|
+
set miterLimit(miter_limit: number);
|
|
27
|
+
/**
|
|
28
|
+
* @member {number}
|
|
29
|
+
* @default 1
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
get lineWidth(): number;
|
|
33
|
+
set lineWidth(line_width: number);
|
|
34
|
+
/**
|
|
35
|
+
* @member {string}
|
|
36
|
+
* @default "round"
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
get lineCap(): CapsStyleImpl;
|
|
40
|
+
set lineCap(line_cap: CapsStyleImpl);
|
|
41
|
+
/**
|
|
42
|
+
* @member {string}
|
|
43
|
+
* @default "round"
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
get lineJoin(): JointStyleImpl;
|
|
47
|
+
set lineJoin(line_join: JointStyleImpl);
|
|
48
|
+
/**
|
|
49
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
get fillStyle(): Float32Array | CanvasGradientToWebGL | CanvasPatternToWebGL;
|
|
53
|
+
set fillStyle(style: Float32Array | CanvasGradientToWebGL | CanvasPatternToWebGL);
|
|
54
|
+
/**
|
|
55
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
get strokeStyle(): Float32Array | CanvasGradientToWebGL | CanvasPatternToWebGL;
|
|
59
|
+
set strokeStyle(style: Float32Array | CanvasGradientToWebGL | CanvasPatternToWebGL);
|
|
60
|
+
/**
|
|
61
|
+
* @return {void}
|
|
62
|
+
* @method
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
clear(): void;
|
|
66
|
+
/**
|
|
67
|
+
* @return {void}
|
|
68
|
+
* @method
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
_$clearFill(): void;
|
|
72
|
+
/**
|
|
73
|
+
* @return {void}
|
|
74
|
+
* @method
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
_$clearStroke(): void;
|
|
78
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { CanvasGradientToWebGL } from "./CanvasGradientToWebGL";
|
|
2
|
+
import { CanvasPatternToWebGL } from "./CanvasPatternToWebGL";
|
|
3
|
+
import { $getFloat32Array4, $poolFloat32Array4, $Float32Array } from "@next2d/share";
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
7
|
+
export class CanvasToWebGLContextStyle {
|
|
8
|
+
/**
|
|
9
|
+
* @constructor
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
constructor() {
|
|
13
|
+
this._$fillStyle = $getFloat32Array4(1, 1, 1, 1); // fixed size 4
|
|
14
|
+
this._$strokeStyle = $getFloat32Array4(1, 1, 1, 1); // fixed size 4
|
|
15
|
+
this._$lineWidth = 1;
|
|
16
|
+
this._$lineCap = "round";
|
|
17
|
+
this._$lineJoin = "round";
|
|
18
|
+
this._$miterLimit = 5;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @member {number}
|
|
22
|
+
* @default 5
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
get miterLimit() {
|
|
26
|
+
return this._$miterLimit;
|
|
27
|
+
}
|
|
28
|
+
set miterLimit(miter_limit) {
|
|
29
|
+
this._$miterLimit = miter_limit;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @member {number}
|
|
33
|
+
* @default 1
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
get lineWidth() {
|
|
37
|
+
return this._$lineWidth;
|
|
38
|
+
}
|
|
39
|
+
set lineWidth(line_width) {
|
|
40
|
+
this._$lineWidth = line_width;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @member {string}
|
|
44
|
+
* @default "round"
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
get lineCap() {
|
|
48
|
+
return this._$lineCap;
|
|
49
|
+
}
|
|
50
|
+
set lineCap(line_cap) {
|
|
51
|
+
this._$lineCap = line_cap;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @member {string}
|
|
55
|
+
* @default "round"
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
get lineJoin() {
|
|
59
|
+
return this._$lineJoin;
|
|
60
|
+
}
|
|
61
|
+
set lineJoin(line_join) {
|
|
62
|
+
this._$lineJoin = line_join;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
get fillStyle() {
|
|
69
|
+
return this._$fillStyle;
|
|
70
|
+
}
|
|
71
|
+
set fillStyle(style) {
|
|
72
|
+
if (this._$fillStyle instanceof $Float32Array) {
|
|
73
|
+
$poolFloat32Array4(this._$fillStyle);
|
|
74
|
+
}
|
|
75
|
+
this._$fillStyle = style;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
get strokeStyle() {
|
|
82
|
+
return this._$strokeStyle;
|
|
83
|
+
}
|
|
84
|
+
set strokeStyle(style) {
|
|
85
|
+
if (this._$strokeStyle instanceof $Float32Array) {
|
|
86
|
+
$poolFloat32Array4(this._$strokeStyle);
|
|
87
|
+
}
|
|
88
|
+
this._$strokeStyle = style;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* @return {void}
|
|
92
|
+
* @method
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
clear() {
|
|
96
|
+
this._$lineWidth = 1;
|
|
97
|
+
this._$lineCap = "round";
|
|
98
|
+
this._$lineJoin = "round";
|
|
99
|
+
this._$miterLimit = 5;
|
|
100
|
+
this._$clearFill();
|
|
101
|
+
this._$clearStroke();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @return {void}
|
|
105
|
+
* @method
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
_$clearFill() {
|
|
109
|
+
if (this._$fillStyle instanceof CanvasGradientToWebGL) {
|
|
110
|
+
this._$fillStyle.dispose();
|
|
111
|
+
this._$fillStyle = $getFloat32Array4(1, 1, 1, 1);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (this._$fillStyle instanceof CanvasPatternToWebGL) {
|
|
115
|
+
this._$fillStyle.dispose();
|
|
116
|
+
this._$fillStyle = $getFloat32Array4(1, 1, 1, 1);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this._$fillStyle.fill(1);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @return {void}
|
|
123
|
+
* @method
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
_$clearStroke() {
|
|
127
|
+
if (this._$strokeStyle instanceof CanvasGradientToWebGL) {
|
|
128
|
+
this._$strokeStyle.dispose();
|
|
129
|
+
this._$strokeStyle = $getFloat32Array4(1, 1, 1, 1);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (this._$strokeStyle instanceof CanvasPatternToWebGL) {
|
|
133
|
+
this._$strokeStyle.dispose();
|
|
134
|
+
this._$strokeStyle = $getFloat32Array4(1, 1, 1, 1);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
this._$strokeStyle.fill(1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export declare class ColorBufferPool {
|
|
5
|
+
private readonly _$gl;
|
|
6
|
+
private readonly _$objectPool;
|
|
7
|
+
private _$samples;
|
|
8
|
+
/**
|
|
9
|
+
* @param {WebGL2RenderingContext} gl
|
|
10
|
+
* @param {number} samples
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(gl: WebGL2RenderingContext, samples: number);
|
|
14
|
+
/**
|
|
15
|
+
* @member {number}
|
|
16
|
+
* @param {number} samples
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
set samples(samples: number);
|
|
20
|
+
/**
|
|
21
|
+
* @return {WebGLRenderbuffer}
|
|
22
|
+
* @method
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
_$createColorBuffer(): WebGLRenderbuffer;
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} area
|
|
28
|
+
* @return {WebGLRenderbuffer}
|
|
29
|
+
* @method
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_$getColorBuffer(area: number): WebGLRenderbuffer;
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} width
|
|
35
|
+
* @param {number} height
|
|
36
|
+
* @param {number} [samples=0]
|
|
37
|
+
* @return {WebGLRenderbuffer}
|
|
38
|
+
* @method
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
create(width: number, height: number, samples?: number): WebGLRenderbuffer;
|
|
42
|
+
/**
|
|
43
|
+
* @param {WebGLRenderbuffer} [colorBuffer = null]
|
|
44
|
+
* @return {void}
|
|
45
|
+
* @method
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
release(colorBuffer: WebGLRenderbuffer): void;
|
|
49
|
+
/**
|
|
50
|
+
* @description 「めぐる式二分探索法」で面積が引数以上の要素のインデックスを求める
|
|
51
|
+
*
|
|
52
|
+
* @param {number} area
|
|
53
|
+
* @return {number}
|
|
54
|
+
* @method
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
_$bsearch(area: number): number;
|
|
58
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { $getArray, $Math, $upperPowerOfTwo } from "@next2d/share";
|
|
2
|
+
/**
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
export class ColorBufferPool {
|
|
6
|
+
/**
|
|
7
|
+
* @param {WebGL2RenderingContext} gl
|
|
8
|
+
* @param {number} samples
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor(gl, samples) {
|
|
12
|
+
this._$gl = gl;
|
|
13
|
+
this._$samples = samples;
|
|
14
|
+
this._$objectPool = $getArray();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @member {number}
|
|
18
|
+
* @param {number} samples
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
set samples(samples) {
|
|
22
|
+
this._$samples = samples;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @return {WebGLRenderbuffer}
|
|
26
|
+
* @method
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
_$createColorBuffer() {
|
|
30
|
+
const colorBuffer = this._$gl.createRenderbuffer();
|
|
31
|
+
if (!colorBuffer) {
|
|
32
|
+
throw new Error("the color buffer is null.");
|
|
33
|
+
}
|
|
34
|
+
const stencilBuffer = this._$gl.createRenderbuffer();
|
|
35
|
+
if (!stencilBuffer) {
|
|
36
|
+
throw new Error("the stencil buffer is null.");
|
|
37
|
+
}
|
|
38
|
+
colorBuffer.stencil = stencilBuffer;
|
|
39
|
+
colorBuffer.samples = 0;
|
|
40
|
+
colorBuffer.width = 0;
|
|
41
|
+
colorBuffer.height = 0;
|
|
42
|
+
colorBuffer.area = 0;
|
|
43
|
+
colorBuffer.dirty = true;
|
|
44
|
+
return colorBuffer;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @param {number} area
|
|
48
|
+
* @return {WebGLRenderbuffer}
|
|
49
|
+
* @method
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
_$getColorBuffer(area) {
|
|
53
|
+
if (!this._$objectPool.length) {
|
|
54
|
+
return this._$createColorBuffer();
|
|
55
|
+
}
|
|
56
|
+
const index = this._$bsearch(area);
|
|
57
|
+
if (index < this._$objectPool.length) {
|
|
58
|
+
const colorBuffer = this._$objectPool[index];
|
|
59
|
+
this._$objectPool.splice(index, 1);
|
|
60
|
+
return colorBuffer;
|
|
61
|
+
}
|
|
62
|
+
const colorBuffer = this._$objectPool.shift();
|
|
63
|
+
if (!colorBuffer) {
|
|
64
|
+
throw new Error("the color buffer is void.");
|
|
65
|
+
}
|
|
66
|
+
return colorBuffer;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param {number} width
|
|
70
|
+
* @param {number} height
|
|
71
|
+
* @param {number} [samples=0]
|
|
72
|
+
* @return {WebGLRenderbuffer}
|
|
73
|
+
* @method
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
create(width, height, samples = 0) {
|
|
77
|
+
// 128以下で描画崩れが発生する場合がある?ため、256を最小サイズにする
|
|
78
|
+
width = $Math.max(256, $upperPowerOfTwo(width));
|
|
79
|
+
height = $Math.max(256, $upperPowerOfTwo(height));
|
|
80
|
+
const colorBuffer = this._$getColorBuffer(width * height);
|
|
81
|
+
if (!samples) {
|
|
82
|
+
samples = this._$samples;
|
|
83
|
+
}
|
|
84
|
+
if (colorBuffer.width < width
|
|
85
|
+
|| colorBuffer.height < height
|
|
86
|
+
|| colorBuffer.samples !== samples) {
|
|
87
|
+
width = $Math.max(width, colorBuffer.width);
|
|
88
|
+
height = $Math.max(height, colorBuffer.height);
|
|
89
|
+
colorBuffer.samples = samples;
|
|
90
|
+
colorBuffer.width = width;
|
|
91
|
+
colorBuffer.height = height;
|
|
92
|
+
colorBuffer.area = width * height;
|
|
93
|
+
colorBuffer.dirty = false;
|
|
94
|
+
this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, colorBuffer);
|
|
95
|
+
this._$gl.renderbufferStorageMultisample(this._$gl.RENDERBUFFER, samples, this._$gl.RGBA8, width, height);
|
|
96
|
+
this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, colorBuffer.stencil);
|
|
97
|
+
this._$gl.renderbufferStorageMultisample(this._$gl.RENDERBUFFER, samples, this._$gl.STENCIL_INDEX8, width, height);
|
|
98
|
+
}
|
|
99
|
+
return colorBuffer;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* @param {WebGLRenderbuffer} [colorBuffer = null]
|
|
103
|
+
* @return {void}
|
|
104
|
+
* @method
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
release(colorBuffer) {
|
|
108
|
+
colorBuffer.dirty = true;
|
|
109
|
+
const index = this._$bsearch(colorBuffer.area);
|
|
110
|
+
this._$objectPool.splice(index, 0, colorBuffer);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description 「めぐる式二分探索法」で面積が引数以上の要素のインデックスを求める
|
|
114
|
+
*
|
|
115
|
+
* @param {number} area
|
|
116
|
+
* @return {number}
|
|
117
|
+
* @method
|
|
118
|
+
* @private
|
|
119
|
+
*/
|
|
120
|
+
_$bsearch(area) {
|
|
121
|
+
let ng = -1;
|
|
122
|
+
let ok = this._$objectPool.length;
|
|
123
|
+
while ($Math.abs(ok - ng) > 1) {
|
|
124
|
+
const mid = $Math.floor((ok + ng) / 2);
|
|
125
|
+
if (area <= this._$objectPool[mid].area) {
|
|
126
|
+
ok = mid;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
ng = mid;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return ok;
|
|
133
|
+
}
|
|
134
|
+
}
|