@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,436 @@
|
|
|
1
|
+
import { WebGLFillMeshGenerator } from "./WebGLFillMeshGenerator";
|
|
2
|
+
import { $poolArray } from "@next2d/share";
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export class CanvasToWebGLContextMask {
|
|
7
|
+
/**
|
|
8
|
+
* @param {CanvasToWebGLContext} context
|
|
9
|
+
* @param {WebGL2RenderingContext} gl
|
|
10
|
+
* @constructor
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
constructor(context, gl) {
|
|
14
|
+
/**
|
|
15
|
+
* @type {CanvasToWebGLContext}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
this._$context = context;
|
|
19
|
+
/**
|
|
20
|
+
* @type {WebGL2RenderingContext}
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
this._$gl = gl;
|
|
24
|
+
/**
|
|
25
|
+
* @type {array}
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
this._$clips = [];
|
|
29
|
+
/**
|
|
30
|
+
* @type {array}
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
this._$poolClip = [];
|
|
34
|
+
/**
|
|
35
|
+
* @type {boolean}
|
|
36
|
+
* @default false
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
this._$clipStatus = false;
|
|
40
|
+
/**
|
|
41
|
+
* @type {boolean}
|
|
42
|
+
* @default false
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
this._$containerClip = false;
|
|
46
|
+
/**
|
|
47
|
+
* @type {boolean}
|
|
48
|
+
* @default false
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
this._$currentClip = false;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @member {boolean}
|
|
55
|
+
* @public
|
|
56
|
+
*/
|
|
57
|
+
get containerClip() {
|
|
58
|
+
return this._$containerClip;
|
|
59
|
+
}
|
|
60
|
+
set containerClip(flag) {
|
|
61
|
+
this._$containerClip = flag;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @param {boolean} mask
|
|
65
|
+
* @return {void}
|
|
66
|
+
* @method
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
_$onClear(mask) {
|
|
70
|
+
if (mask) {
|
|
71
|
+
this._$gl.enable(this._$gl.STENCIL_TEST);
|
|
72
|
+
this._$currentClip = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @param {boolean} mask
|
|
77
|
+
* @return {void}
|
|
78
|
+
* @method
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
_$onBind(mask) {
|
|
82
|
+
if (!mask && this._$currentClip) {
|
|
83
|
+
// キャッシュ作成前は、一旦マスクを無効にする
|
|
84
|
+
this._$gl.disable(this._$gl.STENCIL_TEST);
|
|
85
|
+
this._$currentClip = false;
|
|
86
|
+
}
|
|
87
|
+
else if (mask && !this._$currentClip) {
|
|
88
|
+
// キャッシュ作成後は、マスクの状態を復元する
|
|
89
|
+
this._$gl.enable(this._$gl.STENCIL_TEST);
|
|
90
|
+
this._$currentClip = true;
|
|
91
|
+
this._$endClipDef();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @return {void}
|
|
96
|
+
* @method
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
_$onClearRect() {
|
|
100
|
+
this._$gl.disable(this._$gl.STENCIL_TEST);
|
|
101
|
+
this._$currentClip = false;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @return {void}
|
|
105
|
+
* @method
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
_$endClip() {
|
|
109
|
+
const manager = this._$context.frameBuffer;
|
|
110
|
+
const currentAttachment = manager.currentAttachment;
|
|
111
|
+
const texture = manager.getTextureFromCurrentAttachment();
|
|
112
|
+
this._$context._$bind(this._$context.cacheAttachment);
|
|
113
|
+
this._$context.cacheAttachment = null;
|
|
114
|
+
// blend off
|
|
115
|
+
this._$context.blend.disable();
|
|
116
|
+
const cacheBounds = this._$context.cacheBounds;
|
|
117
|
+
this._$context.reset();
|
|
118
|
+
this._$context.setTransform(1, 0, 0, 1, 0, 0);
|
|
119
|
+
this._$context.drawImage(texture, cacheBounds.xMin, cacheBounds.yMin, texture.width, texture.height);
|
|
120
|
+
// blend restart
|
|
121
|
+
this._$context.blend.enable();
|
|
122
|
+
// pool
|
|
123
|
+
manager.releaseAttachment(currentAttachment, true);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* @return {void}
|
|
127
|
+
* @method
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
_$enterClip() {
|
|
131
|
+
if (!this._$currentClip) {
|
|
132
|
+
this._$gl.enable(this._$gl.STENCIL_TEST);
|
|
133
|
+
this._$currentClip = true;
|
|
134
|
+
}
|
|
135
|
+
// buffer mask on
|
|
136
|
+
const currentAttachment = this
|
|
137
|
+
._$context
|
|
138
|
+
.frameBuffer
|
|
139
|
+
.currentAttachment;
|
|
140
|
+
if (!currentAttachment) {
|
|
141
|
+
throw new Error("mask currentAttachment is null.");
|
|
142
|
+
}
|
|
143
|
+
currentAttachment.mask = true;
|
|
144
|
+
++currentAttachment.clipLevel;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @return {void}
|
|
148
|
+
* @method
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
_$beginClipDef() {
|
|
152
|
+
const currentAttachment = this
|
|
153
|
+
._$context
|
|
154
|
+
.frameBuffer
|
|
155
|
+
.currentAttachment;
|
|
156
|
+
if (!currentAttachment) {
|
|
157
|
+
throw new Error("mask currentAttachment is null.");
|
|
158
|
+
}
|
|
159
|
+
this._$gl.enable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
160
|
+
this._$gl.stencilFunc(this._$gl.ALWAYS, 0, 0xff);
|
|
161
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.INVERT, this._$gl.INVERT);
|
|
162
|
+
this._$gl.stencilMask(1 << currentAttachment.clipLevel - 1);
|
|
163
|
+
this._$gl.colorMask(false, false, false, false);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* @return {void}
|
|
167
|
+
* @method
|
|
168
|
+
* @private
|
|
169
|
+
*/
|
|
170
|
+
_$endClipDef() {
|
|
171
|
+
const currentAttachment = this
|
|
172
|
+
._$context
|
|
173
|
+
.frameBuffer
|
|
174
|
+
.currentAttachment;
|
|
175
|
+
if (!currentAttachment) {
|
|
176
|
+
throw new Error("mask currentAttachment is null.");
|
|
177
|
+
}
|
|
178
|
+
const clipLevel = currentAttachment.clipLevel;
|
|
179
|
+
let mask = 0;
|
|
180
|
+
for (let idx = 0; idx < clipLevel; ++idx) {
|
|
181
|
+
mask |= (1 << clipLevel - idx) - 1;
|
|
182
|
+
}
|
|
183
|
+
this._$gl.disable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
184
|
+
this._$gl.stencilFunc(this._$gl.EQUAL, mask & 0xff, mask);
|
|
185
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.KEEP, this._$gl.KEEP);
|
|
186
|
+
this._$gl.stencilMask(0xff);
|
|
187
|
+
this._$gl.colorMask(true, true, true, true);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @return {void}
|
|
191
|
+
* @method
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
_$leaveClip() {
|
|
195
|
+
const currentAttachment = this
|
|
196
|
+
._$context
|
|
197
|
+
.frameBuffer
|
|
198
|
+
.currentAttachment;
|
|
199
|
+
if (!currentAttachment) {
|
|
200
|
+
throw new Error("mask currentAttachment is null.");
|
|
201
|
+
}
|
|
202
|
+
--currentAttachment.clipLevel;
|
|
203
|
+
currentAttachment.mask = !!currentAttachment.clipLevel;
|
|
204
|
+
// end clip
|
|
205
|
+
if (!currentAttachment.clipLevel) {
|
|
206
|
+
this._$context._$clearRectStencil(0, 0, currentAttachment.width, currentAttachment.height);
|
|
207
|
+
if (this._$context.cacheAttachment) {
|
|
208
|
+
this._$endClip();
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// replace
|
|
213
|
+
const w = currentAttachment.width;
|
|
214
|
+
const h = currentAttachment.height;
|
|
215
|
+
// create buffer
|
|
216
|
+
const vertices = this
|
|
217
|
+
._$context
|
|
218
|
+
.path
|
|
219
|
+
.createRectVertices(0, 0, w, h);
|
|
220
|
+
const object = this
|
|
221
|
+
._$context
|
|
222
|
+
.vao
|
|
223
|
+
.createFill(vertices);
|
|
224
|
+
$poolArray(vertices.pop());
|
|
225
|
+
$poolArray(vertices);
|
|
226
|
+
const variants = this
|
|
227
|
+
._$context
|
|
228
|
+
.shaderList
|
|
229
|
+
.shapeShaderVariants;
|
|
230
|
+
const shader = variants.getMaskShapeShader(false, false);
|
|
231
|
+
const uniform = shader.uniform;
|
|
232
|
+
variants.setMaskShapeUniformIdentity(uniform, w, h);
|
|
233
|
+
const range = object.indexRanges[0];
|
|
234
|
+
// deny
|
|
235
|
+
if (!this._$currentClip) {
|
|
236
|
+
this._$currentClip = true;
|
|
237
|
+
this._$gl.enable(this._$gl.STENCIL_TEST);
|
|
238
|
+
}
|
|
239
|
+
this._$gl.enable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
240
|
+
this._$gl.stencilFunc(this._$gl.ALWAYS, 0, 0xff);
|
|
241
|
+
this._$gl.stencilOp(this._$gl.REPLACE, this._$gl.REPLACE, this._$gl.REPLACE);
|
|
242
|
+
this._$gl.stencilMask(1 << currentAttachment.clipLevel);
|
|
243
|
+
this._$gl.colorMask(false, false, false, false);
|
|
244
|
+
shader._$containerClip(object, range.first, range.count);
|
|
245
|
+
// object pool
|
|
246
|
+
const indexRanges = object.indexRanges;
|
|
247
|
+
for (let idx = 0; idx < indexRanges.length; ++idx) {
|
|
248
|
+
WebGLFillMeshGenerator
|
|
249
|
+
.indexRangePool
|
|
250
|
+
.push(indexRanges[idx]);
|
|
251
|
+
}
|
|
252
|
+
$poolArray(object.indexRanges);
|
|
253
|
+
this._$context.vao.releaseFill(object);
|
|
254
|
+
this._$endClipDef();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* @return {void}
|
|
258
|
+
* @method
|
|
259
|
+
* @private
|
|
260
|
+
*/
|
|
261
|
+
_$drawContainerClip() {
|
|
262
|
+
const currentAttachment = this
|
|
263
|
+
._$context
|
|
264
|
+
.frameBuffer
|
|
265
|
+
.currentAttachment;
|
|
266
|
+
if (!currentAttachment) {
|
|
267
|
+
throw new Error("mask currentAttachment is null.");
|
|
268
|
+
}
|
|
269
|
+
const currentClipLevel = currentAttachment.clipLevel;
|
|
270
|
+
const variants = this
|
|
271
|
+
._$context
|
|
272
|
+
.shaderList
|
|
273
|
+
.shapeShaderVariants;
|
|
274
|
+
const shader = variants
|
|
275
|
+
.getMaskShapeShader(false, false);
|
|
276
|
+
const uniform = shader.uniform;
|
|
277
|
+
let useLevel = currentClipLevel;
|
|
278
|
+
// create buffer
|
|
279
|
+
const w = currentAttachment.width;
|
|
280
|
+
const h = currentAttachment.height;
|
|
281
|
+
this._$gl.enable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
282
|
+
this._$gl.stencilFunc(this._$gl.ALWAYS, 0, 0xff);
|
|
283
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.INVERT, this._$gl.INVERT);
|
|
284
|
+
this._$gl.colorMask(false, false, false, false);
|
|
285
|
+
const length = this._$poolClip.length;
|
|
286
|
+
for (let idx = 0; idx < length; ++idx) {
|
|
287
|
+
const object = this._$poolClip.shift(); // fixed
|
|
288
|
+
if (!object) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
variants.setMaskShapeUniform(uniform, false, object.matrixA, object.matrixB, object.matrixC, object.matrixD, object.matrixE, object.matrixF, object.matrixG, object.matrixH, object.matrixI, object.viewportWidth, object.viewportHeight, null);
|
|
292
|
+
const indexRanges = object.vertexArrayObject.indexRanges;
|
|
293
|
+
for (let idx = 0; idx < indexRanges.length; ++idx) {
|
|
294
|
+
const range = indexRanges[idx];
|
|
295
|
+
this._$gl.stencilMask(1 << useLevel - 1);
|
|
296
|
+
shader
|
|
297
|
+
._$containerClip(object.vertexArrayObject, range.first, range.count);
|
|
298
|
+
WebGLFillMeshGenerator
|
|
299
|
+
.indexRangePool
|
|
300
|
+
.push(range);
|
|
301
|
+
}
|
|
302
|
+
$poolArray(indexRanges);
|
|
303
|
+
this._$context.vao.releaseFill(object.vertexArrayObject);
|
|
304
|
+
++useLevel;
|
|
305
|
+
// union
|
|
306
|
+
if (useLevel > 7) {
|
|
307
|
+
// union
|
|
308
|
+
this._$unionStencilMask(currentClipLevel, w, h);
|
|
309
|
+
// reset
|
|
310
|
+
useLevel = currentClipLevel;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
// last union
|
|
314
|
+
if (useLevel > currentClipLevel + 1) {
|
|
315
|
+
this._$unionStencilMask(currentClipLevel, w, h);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* @param {number} level
|
|
320
|
+
* @param {number} w
|
|
321
|
+
* @param {number} h
|
|
322
|
+
* @return {void}
|
|
323
|
+
* @method
|
|
324
|
+
* @private
|
|
325
|
+
*/
|
|
326
|
+
_$unionStencilMask(level, w, h) {
|
|
327
|
+
// create buffer
|
|
328
|
+
const vertices = this
|
|
329
|
+
._$context
|
|
330
|
+
.path
|
|
331
|
+
.createRectVertices(0, 0, w, h);
|
|
332
|
+
const object = this
|
|
333
|
+
._$context
|
|
334
|
+
.vao
|
|
335
|
+
.createFill(vertices);
|
|
336
|
+
$poolArray(vertices.pop());
|
|
337
|
+
$poolArray(vertices);
|
|
338
|
+
const variants = this
|
|
339
|
+
._$context
|
|
340
|
+
.shaderList
|
|
341
|
+
.shapeShaderVariants;
|
|
342
|
+
const shader = variants
|
|
343
|
+
.getMaskShapeShader(false, false);
|
|
344
|
+
const uniform = shader.uniform;
|
|
345
|
+
variants
|
|
346
|
+
.setMaskShapeUniformIdentity(uniform, w, h);
|
|
347
|
+
const range = object.indexRanges[0];
|
|
348
|
+
// 例として level=4 の場合
|
|
349
|
+
//
|
|
350
|
+
// ステンシルバッファの4ビット目以上を4ビット目に統合する。
|
|
351
|
+
// |?|?|?|?|?|*|*|*| -> | | | | |?|*|*|*|
|
|
352
|
+
//
|
|
353
|
+
// このとき、4ビット目以上に1のビットが1つでもあれば4ビット目を1、
|
|
354
|
+
// そうでなければ4ビット目を0とする。
|
|
355
|
+
//
|
|
356
|
+
// 00000*** -> 00000***
|
|
357
|
+
// 00001*** -> 00001***
|
|
358
|
+
// 00010*** -> 00001***
|
|
359
|
+
// 00011*** -> 00001***
|
|
360
|
+
// 00100*** -> 00001***
|
|
361
|
+
// ...
|
|
362
|
+
// 11101*** -> 00001***
|
|
363
|
+
// 11110*** -> 00001***
|
|
364
|
+
// 11111*** -> 00001***
|
|
365
|
+
//
|
|
366
|
+
// したがってステンシルの現在の値を 00001000 と比較すればよい。
|
|
367
|
+
// 比較して 00001000 以上であれば 00001*** で更新し、そうでなければ 00000*** で更新する。
|
|
368
|
+
// 下位3ビットは元の値を保持する必要があるので 11111000 でマスクする。
|
|
369
|
+
this._$gl.stencilFunc(this._$gl.LEQUAL, 1 << level - 1, 0xff);
|
|
370
|
+
this._$gl.stencilOp(this._$gl.ZERO, this._$gl.REPLACE, this._$gl.REPLACE);
|
|
371
|
+
this._$gl.stencilMask(~((1 << level - 1) - 1));
|
|
372
|
+
shader._$containerClip(object, range.first, range.count);
|
|
373
|
+
// reset
|
|
374
|
+
if (this._$poolClip.length) {
|
|
375
|
+
this._$gl.stencilFunc(this._$gl.ALWAYS, 0, 0xff);
|
|
376
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.INVERT, this._$gl.INVERT);
|
|
377
|
+
}
|
|
378
|
+
// object pool
|
|
379
|
+
const indexRanges = object.indexRanges;
|
|
380
|
+
for (let idx = 0; idx < indexRanges.length; ++idx) {
|
|
381
|
+
WebGLFillMeshGenerator
|
|
382
|
+
.indexRangePool
|
|
383
|
+
.push(indexRanges[idx]);
|
|
384
|
+
}
|
|
385
|
+
$poolArray(object.indexRanges);
|
|
386
|
+
this._$context.vao.releaseFill(object);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @param {WebGLVertexArrayObject} vertex_array
|
|
390
|
+
* @param {Float32Array} matrix
|
|
391
|
+
* @param {number} width
|
|
392
|
+
* @param {number} height
|
|
393
|
+
* @return {boolean}
|
|
394
|
+
* @method
|
|
395
|
+
* @private
|
|
396
|
+
*/
|
|
397
|
+
_$onClip(vertex_array, matrix, width, height) {
|
|
398
|
+
this._$clipStatus = true;
|
|
399
|
+
if (this._$containerClip) {
|
|
400
|
+
this._$poolClip.push({
|
|
401
|
+
"vertexArrayObject": vertex_array,
|
|
402
|
+
"matrixA": matrix[0],
|
|
403
|
+
"matrixB": matrix[1],
|
|
404
|
+
"matrixC": matrix[2],
|
|
405
|
+
"matrixD": matrix[3],
|
|
406
|
+
"matrixE": matrix[4],
|
|
407
|
+
"matrixF": matrix[5],
|
|
408
|
+
"matrixG": matrix[6],
|
|
409
|
+
"matrixH": matrix[7],
|
|
410
|
+
"matrixI": matrix[8],
|
|
411
|
+
"viewportWidth": width,
|
|
412
|
+
"viewportHeight": height
|
|
413
|
+
});
|
|
414
|
+
return true;
|
|
415
|
+
}
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* @return {void}
|
|
420
|
+
* @method
|
|
421
|
+
* @public
|
|
422
|
+
*/
|
|
423
|
+
_$onSave() {
|
|
424
|
+
this._$clips.push(this._$clipStatus);
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* @return {void}
|
|
428
|
+
* @method
|
|
429
|
+
* @public
|
|
430
|
+
*/
|
|
431
|
+
_$onRestore() {
|
|
432
|
+
if (this._$clips.length) {
|
|
433
|
+
this._$clipStatus = !!this._$clips.pop();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { VerticesImpl } from "./interface/VerticesImpl";
|
|
2
|
+
/**
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
export declare class CanvasToWebGLContextPath {
|
|
6
|
+
private _$currentPath;
|
|
7
|
+
private readonly _$vertices;
|
|
8
|
+
private readonly _$bezierConverter;
|
|
9
|
+
/**
|
|
10
|
+
* @constructor
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @member {array}
|
|
15
|
+
* @readonly
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
get vertices(): VerticesImpl;
|
|
19
|
+
/**
|
|
20
|
+
* @return {void}
|
|
21
|
+
* @method
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
begin(): void;
|
|
25
|
+
/**
|
|
26
|
+
* @param {number} x
|
|
27
|
+
* @param {number} y
|
|
28
|
+
* @return {void}
|
|
29
|
+
* @method
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
moveTo(x: number, y: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} x
|
|
35
|
+
* @param {number} y
|
|
36
|
+
* @return {void}
|
|
37
|
+
* @method
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
lineTo(x: number, y: number): void;
|
|
41
|
+
/**
|
|
42
|
+
* @param {number} cx
|
|
43
|
+
* @param {number} cy
|
|
44
|
+
* @param {number} x
|
|
45
|
+
* @param {number} y
|
|
46
|
+
* @return {void}
|
|
47
|
+
* @method
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
quadTo(cx: number, cy: number, x: number, y: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* @param {number} cx1
|
|
53
|
+
* @param {number} cy1
|
|
54
|
+
* @param {number} cx2
|
|
55
|
+
* @param {number} cy2
|
|
56
|
+
* @param {number} x
|
|
57
|
+
* @param {number} y
|
|
58
|
+
* @return {void}
|
|
59
|
+
* @method
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
cubicTo(cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* @param {number} x
|
|
65
|
+
* @param {number} y
|
|
66
|
+
* @param {number} radius
|
|
67
|
+
* @return {void}
|
|
68
|
+
* @method
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
drawCircle(x: number, y: number, radius: number): void;
|
|
72
|
+
/**
|
|
73
|
+
* @return {void}
|
|
74
|
+
* @method
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
/**
|
|
79
|
+
* @param {number} x
|
|
80
|
+
* @param {number} y
|
|
81
|
+
* @return {boolean}
|
|
82
|
+
* @method
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
_$equalsToLastPoint(x: number, y: number): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* @param {number} x
|
|
88
|
+
* @param {number} y
|
|
89
|
+
* @param {boolean} is_control_point
|
|
90
|
+
* @return {void}
|
|
91
|
+
* @method
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
_$pushPointToCurrentPath(x: number, y: number, is_control_point: boolean): void;
|
|
95
|
+
/**
|
|
96
|
+
* @return {void}
|
|
97
|
+
* @method
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
_$pushCurrentPathToVertices(): void;
|
|
101
|
+
/**
|
|
102
|
+
* @param {number} x
|
|
103
|
+
* @param {number} y
|
|
104
|
+
* @param {number} w
|
|
105
|
+
* @param {number} h
|
|
106
|
+
* @return {array}
|
|
107
|
+
* @method
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
createRectVertices(x: number, y: number, w: number, h: number): VerticesImpl;
|
|
111
|
+
}
|