@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,1427 @@
|
|
|
1
|
+
import { CanvasToWebGLContextStyle } from "./CanvasToWebGLContextStyle";
|
|
2
|
+
import { FrameBufferManager } from "./FrameBufferManager";
|
|
3
|
+
import { CanvasToWebGLContextPath } from "./CanvasToWebGLContextPath";
|
|
4
|
+
import { CanvasToWebGLContextGrid } from "./CanvasToWebGLContextGrid";
|
|
5
|
+
import { CanvasToWebGLShaderList } from "./shader/CanvasToWebGLShaderList";
|
|
6
|
+
import { GradientLUTGenerator } from "./shader/GradientLUTGenerator";
|
|
7
|
+
import { VertexArrayObjectManager } from "./VertexArrayObjectManager";
|
|
8
|
+
import { CanvasToWebGLContextMask } from "./CanvasToWebGLContextMask";
|
|
9
|
+
import { CanvasToWebGLContextBlend } from "./CanvasToWebGLContextBlend";
|
|
10
|
+
import { CanvasPatternToWebGL } from "./CanvasPatternToWebGL";
|
|
11
|
+
import { CanvasGradientToWebGL } from "./CanvasGradientToWebGL";
|
|
12
|
+
import { WebGLFillMeshGenerator } from "./WebGLFillMeshGenerator";
|
|
13
|
+
import { $Math, $getFloat32Array9, $getArray, $clamp, $poolArray, $inverseMatrix, $getFloat32Array6, $poolFloat32Array9, $poolBoundsObject, $getBoundsObject } from "@next2d/share";
|
|
14
|
+
/**
|
|
15
|
+
* @class
|
|
16
|
+
*/
|
|
17
|
+
export class CanvasToWebGLContext {
|
|
18
|
+
/**
|
|
19
|
+
* @param {WebGL2RenderingContext} gl
|
|
20
|
+
* @param {number} sample
|
|
21
|
+
* @constructor
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
constructor(gl, sample) {
|
|
25
|
+
/**
|
|
26
|
+
* @type {WebGL2RenderingContext}
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
this._$gl = gl;
|
|
30
|
+
/**
|
|
31
|
+
* @type {number}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
const samples = $Math.min(sample, gl.getParameter(gl.MAX_SAMPLES));
|
|
35
|
+
/**
|
|
36
|
+
* @type {number}
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
this._$maxTextureSize = $Math.min(8192, gl.getParameter(gl.MAX_TEXTURE_SIZE)) - 2;
|
|
40
|
+
/**
|
|
41
|
+
* @type {CanvasToWebGLContextStyle}
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
this._$contextStyle = new CanvasToWebGLContextStyle();
|
|
45
|
+
/**
|
|
46
|
+
* @type {BoundsImpl}
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
this._$cacheBounds = $getBoundsObject();
|
|
50
|
+
/**
|
|
51
|
+
* @type {Float32Array}
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
this._$matrix = $getFloat32Array9(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
55
|
+
/**
|
|
56
|
+
* @type {AttachmentImpl}
|
|
57
|
+
* @default null
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
this._$cacheAttachment = null;
|
|
61
|
+
/**
|
|
62
|
+
* @type {array}
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
this._$stack = [];
|
|
66
|
+
/**
|
|
67
|
+
* @type {number}
|
|
68
|
+
* @default 1
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
this._$globalAlpha = 1;
|
|
72
|
+
/**
|
|
73
|
+
* @type {boolean}
|
|
74
|
+
* @default false
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
this._$imageSmoothingEnabled = false;
|
|
78
|
+
/**
|
|
79
|
+
* @type {string}
|
|
80
|
+
* @default "normal"
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
this._$globalCompositeOperation = "normal";
|
|
84
|
+
/**
|
|
85
|
+
* @type {number}
|
|
86
|
+
* @default 1
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
this._$clearColorR = 1;
|
|
90
|
+
/**
|
|
91
|
+
* @type {number}
|
|
92
|
+
* @default 1
|
|
93
|
+
* @private
|
|
94
|
+
*/
|
|
95
|
+
this._$clearColorG = 1;
|
|
96
|
+
/**
|
|
97
|
+
* @type {number}
|
|
98
|
+
* @default 1
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
this._$clearColorB = 1;
|
|
102
|
+
/**
|
|
103
|
+
* @type {number}
|
|
104
|
+
* @default 1
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
this._$clearColorA = 1;
|
|
108
|
+
/**
|
|
109
|
+
* @type {number}
|
|
110
|
+
* @default 0
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
this._$viewportWidth = 0;
|
|
114
|
+
/**
|
|
115
|
+
* @type {number}
|
|
116
|
+
* @default 0
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
this._$viewportHeight = 0;
|
|
120
|
+
/**
|
|
121
|
+
* @type {FrameBufferManager}
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
this._$frameBufferManager = new FrameBufferManager(gl, samples);
|
|
125
|
+
/**
|
|
126
|
+
* @type {CanvasToWebGLContextPath}
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
this._$path = new CanvasToWebGLContextPath();
|
|
130
|
+
/**
|
|
131
|
+
* @type {CanvasToWebGLContextGrid}
|
|
132
|
+
* @private
|
|
133
|
+
*/
|
|
134
|
+
this._$grid = new CanvasToWebGLContextGrid();
|
|
135
|
+
/**
|
|
136
|
+
* @type {number}
|
|
137
|
+
* @default 0
|
|
138
|
+
* @private
|
|
139
|
+
*/
|
|
140
|
+
this._$offsetX = 0;
|
|
141
|
+
/**
|
|
142
|
+
* @type {number}
|
|
143
|
+
* @default 0
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
this._$offsetY = 0;
|
|
147
|
+
/**
|
|
148
|
+
* @type {array}
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
this._$blends = $getArray();
|
|
152
|
+
/**
|
|
153
|
+
* @type {array}
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
this._$positions = $getArray();
|
|
157
|
+
/**
|
|
158
|
+
* @type {boolean}
|
|
159
|
+
* @default false
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
this._$isLayer = false;
|
|
163
|
+
/**
|
|
164
|
+
* @type {CanvasToWebGLShaderList}
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
this._$shaderList = new CanvasToWebGLShaderList(this, gl);
|
|
168
|
+
/**
|
|
169
|
+
* @type {GradientLUTGenerator}
|
|
170
|
+
* @private
|
|
171
|
+
*/
|
|
172
|
+
this._$gradientLUT = new GradientLUTGenerator(this, gl);
|
|
173
|
+
/**
|
|
174
|
+
* @type {VertexArrayObjectManager}
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
this._$vao = new VertexArrayObjectManager(gl);
|
|
178
|
+
/**
|
|
179
|
+
* @type {CanvasToWebGLContextMask}
|
|
180
|
+
* @private
|
|
181
|
+
*/
|
|
182
|
+
this._$mask = new CanvasToWebGLContextMask(this, gl);
|
|
183
|
+
/**
|
|
184
|
+
* @type {CanvasToWebGLContextBlend}
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
this._$blend = new CanvasToWebGLContextBlend(this, gl);
|
|
188
|
+
/**
|
|
189
|
+
* @type {array}
|
|
190
|
+
* @private
|
|
191
|
+
*/
|
|
192
|
+
this._$maskBufferArray = [];
|
|
193
|
+
/**
|
|
194
|
+
* @type {array}
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
this._$maskBoundsArray = [];
|
|
198
|
+
/**
|
|
199
|
+
* @type {array}
|
|
200
|
+
* @private
|
|
201
|
+
*/
|
|
202
|
+
this._$attachmentArray = [];
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @return {void}
|
|
206
|
+
* @method
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
reset() {
|
|
210
|
+
// reset
|
|
211
|
+
this._$globalAlpha = 1;
|
|
212
|
+
this._$globalCompositeOperation = "normal";
|
|
213
|
+
this._$imageSmoothingEnabled = false;
|
|
214
|
+
// reset color
|
|
215
|
+
this._$contextStyle.clear();
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* @return {boolean}
|
|
219
|
+
* @public
|
|
220
|
+
*/
|
|
221
|
+
get isLayer() {
|
|
222
|
+
return this._$isLayer;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* @memberof CanvasToWebGLContext#
|
|
226
|
+
* @return {HTMLCanvasElement}
|
|
227
|
+
* @public
|
|
228
|
+
*/
|
|
229
|
+
get canvas() {
|
|
230
|
+
return this._$gl.canvas;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @return {AttachmentImpl|null}
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
get cacheAttachment() {
|
|
237
|
+
return this._$cacheAttachment;
|
|
238
|
+
}
|
|
239
|
+
set cacheAttachment(attachment) {
|
|
240
|
+
this._$cacheAttachment = attachment;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @return {BoundsImpl}
|
|
244
|
+
* @readonly
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
get cacheBounds() {
|
|
248
|
+
return this._$cacheBounds;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
get fillStyle() {
|
|
255
|
+
return this._$contextStyle.fillStyle;
|
|
256
|
+
}
|
|
257
|
+
set fillStyle(fill_style) {
|
|
258
|
+
this._$contextStyle.fillStyle = fill_style;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* @member {Float32Array|CanvasGradientToWebGL|CanvasPatternToWebGL}
|
|
262
|
+
* @public
|
|
263
|
+
*/
|
|
264
|
+
get strokeStyle() {
|
|
265
|
+
return this._$contextStyle.strokeStyle;
|
|
266
|
+
}
|
|
267
|
+
set strokeStyle(stroke_style) {
|
|
268
|
+
this._$contextStyle.strokeStyle = stroke_style;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* @member {number}
|
|
272
|
+
* @public
|
|
273
|
+
*/
|
|
274
|
+
get lineWidth() {
|
|
275
|
+
return this._$contextStyle.lineWidth;
|
|
276
|
+
}
|
|
277
|
+
set lineWidth(line_width) {
|
|
278
|
+
this._$contextStyle.lineWidth = line_width;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @member {string}
|
|
282
|
+
* @public
|
|
283
|
+
*/
|
|
284
|
+
get lineCap() {
|
|
285
|
+
return this._$contextStyle.lineCap;
|
|
286
|
+
}
|
|
287
|
+
set lineCap(line_cap) {
|
|
288
|
+
this._$contextStyle.lineCap = line_cap;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* @member {string}
|
|
292
|
+
* @public
|
|
293
|
+
*/
|
|
294
|
+
get lineJoin() {
|
|
295
|
+
return this._$contextStyle.lineJoin;
|
|
296
|
+
}
|
|
297
|
+
set lineJoin(line_join) {
|
|
298
|
+
this._$contextStyle.lineJoin = line_join;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* @member {number}
|
|
302
|
+
* @public
|
|
303
|
+
*/
|
|
304
|
+
get miterLimit() {
|
|
305
|
+
return this._$contextStyle.miterLimit;
|
|
306
|
+
}
|
|
307
|
+
set miterLimit(miter_limit) {
|
|
308
|
+
this._$contextStyle.miterLimit = miter_limit;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @member {number}
|
|
312
|
+
* @public
|
|
313
|
+
*/
|
|
314
|
+
get globalAlpha() {
|
|
315
|
+
return this._$globalAlpha;
|
|
316
|
+
}
|
|
317
|
+
set globalAlpha(global_alpha) {
|
|
318
|
+
this._$globalAlpha = $clamp(global_alpha, 0, 1, 1);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* @member {boolean}
|
|
322
|
+
* @public
|
|
323
|
+
*/
|
|
324
|
+
get imageSmoothingEnabled() {
|
|
325
|
+
return this._$imageSmoothingEnabled;
|
|
326
|
+
}
|
|
327
|
+
set imageSmoothingEnabled(image_smoothing_enabled) {
|
|
328
|
+
this._$imageSmoothingEnabled = image_smoothing_enabled;
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* @member {BlendModeImpl}
|
|
332
|
+
* @public
|
|
333
|
+
*/
|
|
334
|
+
get globalCompositeOperation() {
|
|
335
|
+
return this._$globalCompositeOperation;
|
|
336
|
+
}
|
|
337
|
+
set globalCompositeOperation(global_composite_operation) {
|
|
338
|
+
this._$globalCompositeOperation = global_composite_operation;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* @member {FrameBufferManager}
|
|
342
|
+
* @readonly
|
|
343
|
+
* @public
|
|
344
|
+
*/
|
|
345
|
+
get frameBuffer() {
|
|
346
|
+
return this._$frameBufferManager;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* @member {CanvasToWebGLShaderList}
|
|
350
|
+
* @readonly
|
|
351
|
+
* @public
|
|
352
|
+
*/
|
|
353
|
+
get shaderList() {
|
|
354
|
+
return this._$shaderList;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* @member {CanvasToWebGLContextPath}
|
|
358
|
+
* @readonly
|
|
359
|
+
* @public
|
|
360
|
+
*/
|
|
361
|
+
get path() {
|
|
362
|
+
return this._$path;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @member {CanvasToWebGLContextGrid}
|
|
366
|
+
* @readonly
|
|
367
|
+
* @public
|
|
368
|
+
*/
|
|
369
|
+
get grid() {
|
|
370
|
+
return this._$grid;
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* @member {VertexArrayObjectManager}
|
|
374
|
+
* @readonly
|
|
375
|
+
* @public
|
|
376
|
+
*/
|
|
377
|
+
get vao() {
|
|
378
|
+
return this._$vao;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @member {CanvasToWebGLContextBlend}
|
|
382
|
+
* @readonly
|
|
383
|
+
* @public
|
|
384
|
+
*/
|
|
385
|
+
get blend() {
|
|
386
|
+
return this._$blend;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* @return {object}
|
|
390
|
+
* @private
|
|
391
|
+
*/
|
|
392
|
+
_$getCurrentPosition() {
|
|
393
|
+
return this._$positions[this._$positions.length - 1];
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* @description textureの最大描画可能サイズからリサイズの比率を算出して返す
|
|
397
|
+
* Calculate and return the resize ratio from the maximum drawable size of texture
|
|
398
|
+
*
|
|
399
|
+
* @param {number} width
|
|
400
|
+
* @param {number} height
|
|
401
|
+
* @return {number}
|
|
402
|
+
* @method
|
|
403
|
+
* @public
|
|
404
|
+
*/
|
|
405
|
+
_$getTextureScale(width, height) {
|
|
406
|
+
const maxSize = $Math.max(width, height);
|
|
407
|
+
if (maxSize > this._$maxTextureSize) {
|
|
408
|
+
return this._$maxTextureSize / maxSize;
|
|
409
|
+
}
|
|
410
|
+
return 1;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* @param {object} [attachment = null]
|
|
414
|
+
* @return {void}
|
|
415
|
+
* @method
|
|
416
|
+
* @public
|
|
417
|
+
*/
|
|
418
|
+
_$bind(attachment = null) {
|
|
419
|
+
if (!attachment) {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
this._$frameBufferManager.bind(attachment);
|
|
423
|
+
const colorBuffer = attachment.color;
|
|
424
|
+
const stencilBuffer = attachment.stencil;
|
|
425
|
+
const width = attachment.width;
|
|
426
|
+
const height = attachment.height;
|
|
427
|
+
if (this._$viewportWidth !== width || this._$viewportHeight !== height) {
|
|
428
|
+
this._$viewportWidth = width;
|
|
429
|
+
this._$viewportHeight = height;
|
|
430
|
+
this._$gl.viewport(0, 0, width, height);
|
|
431
|
+
}
|
|
432
|
+
// カラーバッファorステンシルバッファが、未初期化の場合はクリアする
|
|
433
|
+
if (colorBuffer && colorBuffer.dirty
|
|
434
|
+
|| stencilBuffer && stencilBuffer.dirty) {
|
|
435
|
+
if (colorBuffer) {
|
|
436
|
+
colorBuffer.dirty = false;
|
|
437
|
+
}
|
|
438
|
+
if (stencilBuffer) {
|
|
439
|
+
stencilBuffer.dirty = false;
|
|
440
|
+
}
|
|
441
|
+
this._$gl.clearColor(0, 0, 0, 0);
|
|
442
|
+
this.clearRect(0, 0, this._$viewportWidth, this._$viewportHeight);
|
|
443
|
+
this._$gl.clearColor(this._$clearColorR, this._$clearColorG, this._$clearColorB, this._$clearColorA);
|
|
444
|
+
this._$mask._$onClear(attachment.mask);
|
|
445
|
+
}
|
|
446
|
+
this._$mask._$onBind(attachment.mask);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* @param {number} a
|
|
450
|
+
* @param {number} b
|
|
451
|
+
* @param {number} c
|
|
452
|
+
* @param {number} d
|
|
453
|
+
* @param {number} e
|
|
454
|
+
* @param {number} f
|
|
455
|
+
* @return {void}
|
|
456
|
+
* @method
|
|
457
|
+
* @public
|
|
458
|
+
*/
|
|
459
|
+
setTransform(a, b, c, d, e, f) {
|
|
460
|
+
this._$matrix[0] = a;
|
|
461
|
+
this._$matrix[1] = b;
|
|
462
|
+
this._$matrix[3] = c;
|
|
463
|
+
this._$matrix[4] = d;
|
|
464
|
+
this._$matrix[6] = e;
|
|
465
|
+
this._$matrix[7] = f;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* @param {number} width
|
|
469
|
+
* @param {number} height
|
|
470
|
+
* @return {void}
|
|
471
|
+
* @method
|
|
472
|
+
* @public
|
|
473
|
+
*/
|
|
474
|
+
setMaxSize(width, height) {
|
|
475
|
+
this._$frameBufferManager.setMaxSize(width, height);
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* @param {number} a
|
|
479
|
+
* @param {number} b
|
|
480
|
+
* @param {number} c
|
|
481
|
+
* @param {number} d
|
|
482
|
+
* @param {number} e
|
|
483
|
+
* @param {number} f
|
|
484
|
+
* @return {void}
|
|
485
|
+
* @method
|
|
486
|
+
* @public
|
|
487
|
+
*/
|
|
488
|
+
transform(a, b, c, d, e, f) {
|
|
489
|
+
const a00 = this._$matrix[0];
|
|
490
|
+
const a01 = this._$matrix[1];
|
|
491
|
+
const a10 = this._$matrix[3];
|
|
492
|
+
const a11 = this._$matrix[4];
|
|
493
|
+
const a20 = this._$matrix[6];
|
|
494
|
+
const a21 = this._$matrix[7];
|
|
495
|
+
this._$matrix[0] = a * a00 + b * a10;
|
|
496
|
+
this._$matrix[1] = a * a01 + b * a11;
|
|
497
|
+
this._$matrix[3] = c * a00 + d * a10;
|
|
498
|
+
this._$matrix[4] = c * a01 + d * a11;
|
|
499
|
+
this._$matrix[6] = e * a00 + f * a10 + a20;
|
|
500
|
+
this._$matrix[7] = e * a01 + f * a11 + a21;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* @param {WebGLTexture} image
|
|
504
|
+
* @param {number} x
|
|
505
|
+
* @param {number} y
|
|
506
|
+
* @param {number} w
|
|
507
|
+
* @param {number} h
|
|
508
|
+
* @param {Float32Array} [color_transform=null]
|
|
509
|
+
* @return {void}
|
|
510
|
+
* @method
|
|
511
|
+
* @public
|
|
512
|
+
*/
|
|
513
|
+
drawImage(image, x, y, w, h, color_transform = null) {
|
|
514
|
+
let ct0 = 1;
|
|
515
|
+
let ct1 = 1;
|
|
516
|
+
let ct2 = 1;
|
|
517
|
+
let ct4 = 0;
|
|
518
|
+
let ct5 = 0;
|
|
519
|
+
let ct6 = 0;
|
|
520
|
+
const ct3 = this._$globalAlpha;
|
|
521
|
+
const ct7 = 0;
|
|
522
|
+
if (color_transform) {
|
|
523
|
+
ct0 = color_transform[0];
|
|
524
|
+
ct1 = color_transform[1];
|
|
525
|
+
ct2 = color_transform[2];
|
|
526
|
+
ct4 = color_transform[4] / 255;
|
|
527
|
+
ct5 = color_transform[5] / 255;
|
|
528
|
+
ct6 = color_transform[6] / 255;
|
|
529
|
+
}
|
|
530
|
+
this.blend.drawImage(image, x, y, w, h, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7, this._$globalCompositeOperation, this._$viewportWidth, this._$viewportHeight, this._$matrix, this._$imageSmoothingEnabled);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* @param {number} r
|
|
534
|
+
* @param {number} g
|
|
535
|
+
* @param {number} b
|
|
536
|
+
* @param {number} a
|
|
537
|
+
* @return {void}
|
|
538
|
+
* @method
|
|
539
|
+
* @public
|
|
540
|
+
*/
|
|
541
|
+
_$setColor(r = 0, g = 0, b = 0, a = 0) {
|
|
542
|
+
this._$clearColorR = r;
|
|
543
|
+
this._$clearColorG = g;
|
|
544
|
+
this._$clearColorB = b;
|
|
545
|
+
this._$clearColorA = a;
|
|
546
|
+
this._$gl.clearColor(r, g, b, a);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* @param {number} x
|
|
550
|
+
* @param {number} y
|
|
551
|
+
* @param {number} w
|
|
552
|
+
* @param {number} h
|
|
553
|
+
* @return {void}
|
|
554
|
+
* @method
|
|
555
|
+
* @public
|
|
556
|
+
*/
|
|
557
|
+
clearRect(x, y, w, h) {
|
|
558
|
+
this._$mask._$onClearRect();
|
|
559
|
+
this._$gl.enable(this._$gl.SCISSOR_TEST);
|
|
560
|
+
this._$gl.scissor(x, y, w, h);
|
|
561
|
+
this._$gl.clear(this._$gl.COLOR_BUFFER_BIT | this._$gl.STENCIL_BUFFER_BIT);
|
|
562
|
+
this._$gl.disable(this._$gl.SCISSOR_TEST);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* @param {number} x
|
|
566
|
+
* @param {number} y
|
|
567
|
+
* @param {number} w
|
|
568
|
+
* @param {number} h
|
|
569
|
+
* @return {void}
|
|
570
|
+
* @method
|
|
571
|
+
* @public
|
|
572
|
+
*/
|
|
573
|
+
_$clearRectStencil(x, y, w, h) {
|
|
574
|
+
this._$mask._$onClearRect();
|
|
575
|
+
this._$gl.enable(this._$gl.SCISSOR_TEST);
|
|
576
|
+
this._$gl.scissor(x, y, w, h);
|
|
577
|
+
this._$gl.clear(this._$gl.STENCIL_BUFFER_BIT);
|
|
578
|
+
this._$gl.disable(this._$gl.SCISSOR_TEST);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* @param {number} x
|
|
582
|
+
* @param {number} y
|
|
583
|
+
* @return {void}
|
|
584
|
+
* @method
|
|
585
|
+
* @public
|
|
586
|
+
*/
|
|
587
|
+
moveTo(x, y) {
|
|
588
|
+
this._$path.moveTo(x, y);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* @param {number} x
|
|
592
|
+
* @param {number} y
|
|
593
|
+
* @return {void}
|
|
594
|
+
* @method
|
|
595
|
+
* @public
|
|
596
|
+
*/
|
|
597
|
+
lineTo(x, y) {
|
|
598
|
+
this._$path.lineTo(x, y);
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* @return {void}
|
|
602
|
+
* @method
|
|
603
|
+
* @public
|
|
604
|
+
*/
|
|
605
|
+
beginPath() {
|
|
606
|
+
this._$path.begin();
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* @param {number} cx
|
|
610
|
+
* @param {number} cy
|
|
611
|
+
* @param {number} x
|
|
612
|
+
* @param {number} y
|
|
613
|
+
* @return {void}
|
|
614
|
+
* @method
|
|
615
|
+
* @public
|
|
616
|
+
*/
|
|
617
|
+
quadraticCurveTo(cx, cy, x, y) {
|
|
618
|
+
this._$path.quadTo(cx, cy, x, y);
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* @param {number} cp1x
|
|
622
|
+
* @param {number} cp1y
|
|
623
|
+
* @param {number} cp2x
|
|
624
|
+
* @param {number} cp2y
|
|
625
|
+
* @param {number} dx
|
|
626
|
+
* @param {number} dy
|
|
627
|
+
* @return {void}
|
|
628
|
+
* @method
|
|
629
|
+
* @public
|
|
630
|
+
*/
|
|
631
|
+
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, dx, dy) {
|
|
632
|
+
this._$path.cubicTo(cp1x, cp1y, cp2x, cp2y, dx, dy);
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* @return {void}
|
|
636
|
+
* @method
|
|
637
|
+
* @public
|
|
638
|
+
*/
|
|
639
|
+
fill() {
|
|
640
|
+
// to triangle
|
|
641
|
+
const fillVertices = this._$path.vertices;
|
|
642
|
+
if (!fillVertices.length) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const checkVertices = $getArray();
|
|
646
|
+
for (let idx = 0; idx < fillVertices.length; ++idx) {
|
|
647
|
+
const vertices = fillVertices[idx];
|
|
648
|
+
if (10 > vertices.length) {
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
checkVertices.push(vertices);
|
|
652
|
+
}
|
|
653
|
+
if (!checkVertices.length) {
|
|
654
|
+
$poolArray(checkVertices);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const fillVertexArrayObject = this._$vao.createFill(checkVertices);
|
|
658
|
+
const fillStyle = this.fillStyle;
|
|
659
|
+
let matrix = this._$matrix;
|
|
660
|
+
let texture;
|
|
661
|
+
let variants;
|
|
662
|
+
let shader;
|
|
663
|
+
const hasGrid = this._$grid.enabled;
|
|
664
|
+
if (fillStyle instanceof CanvasGradientToWebGL) {
|
|
665
|
+
const stops = fillStyle.stops;
|
|
666
|
+
const isLinearSpace = fillStyle.rgb === "linearRGB";
|
|
667
|
+
texture = this
|
|
668
|
+
._$gradientLUT
|
|
669
|
+
.generateForShape(stops, isLinearSpace);
|
|
670
|
+
this
|
|
671
|
+
._$frameBufferManager
|
|
672
|
+
.textureManager
|
|
673
|
+
.bind0(texture, true);
|
|
674
|
+
variants = this
|
|
675
|
+
._$shaderList
|
|
676
|
+
.gradientShapeShaderVariants;
|
|
677
|
+
if (fillStyle.type === "linear") {
|
|
678
|
+
shader = variants
|
|
679
|
+
.getGradientShapeShader(false, hasGrid, false, false, fillStyle.mode);
|
|
680
|
+
variants.setGradientShapeUniform(shader.uniform, false, 0, 0, 0, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, false, fillStyle.points, 0);
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
matrix = this._$stack[this._$stack.length - 1];
|
|
684
|
+
const hasFocalPoint = fillStyle.focalPointRatio !== 0;
|
|
685
|
+
shader = variants
|
|
686
|
+
.getGradientShapeShader(false, hasGrid, true, hasFocalPoint, fillStyle.mode);
|
|
687
|
+
variants.setGradientShapeUniform(shader.uniform, false, 0, 0, 0, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, true, fillStyle.points, fillStyle.focalPointRatio);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
else if (fillStyle instanceof CanvasPatternToWebGL) {
|
|
691
|
+
matrix = this._$stack[this._$stack.length - 1];
|
|
692
|
+
const pct = fillStyle.colorTransform;
|
|
693
|
+
texture = fillStyle.texture;
|
|
694
|
+
this
|
|
695
|
+
._$frameBufferManager
|
|
696
|
+
.textureManager
|
|
697
|
+
.bind0(texture, this._$imageSmoothingEnabled);
|
|
698
|
+
variants = this
|
|
699
|
+
._$shaderList
|
|
700
|
+
.shapeShaderVariants;
|
|
701
|
+
shader = variants
|
|
702
|
+
.getBitmapShapeShader(false, fillStyle.repeat, hasGrid);
|
|
703
|
+
if (pct) {
|
|
704
|
+
variants.setBitmapShapeUniform(shader.uniform, false, 0, 0, 0, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, texture.width, texture.height, pct[0], pct[1], pct[2], this._$globalAlpha, pct[4] / 255, pct[5] / 255, pct[6] / 255, 0);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
variants.setBitmapShapeUniform(shader.uniform, false, 0, 0, 0, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, texture.width, texture.height, 1, 1, 1, this._$globalAlpha, 0, 0, 0, 0);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
711
|
+
variants = this
|
|
712
|
+
._$shaderList
|
|
713
|
+
.shapeShaderVariants;
|
|
714
|
+
shader = variants
|
|
715
|
+
.getSolidColorShapeShader(false, this._$grid.enabled);
|
|
716
|
+
variants.setSolidColorShapeUniform(shader.uniform, false, 0, 0, 0, hasGrid, matrix, this._$viewportWidth, this._$viewportHeight, this._$grid, fillStyle, this._$globalAlpha);
|
|
717
|
+
}
|
|
718
|
+
const coverageVariants = this
|
|
719
|
+
._$shaderList
|
|
720
|
+
.shapeShaderVariants;
|
|
721
|
+
const coverageShader = coverageVariants
|
|
722
|
+
.getMaskShapeShader(false, hasGrid);
|
|
723
|
+
coverageVariants.setMaskShapeUniform(coverageShader.uniform, hasGrid, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8], this._$viewportWidth, this._$viewportHeight, this._$grid);
|
|
724
|
+
// mask on
|
|
725
|
+
this._$gl.enable(this._$gl.STENCIL_TEST);
|
|
726
|
+
this._$gl.stencilMask(0xff);
|
|
727
|
+
// draw shape
|
|
728
|
+
this._$gl.enable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
729
|
+
this._$gl.stencilFunc(this._$gl.ALWAYS, 0, 0xff);
|
|
730
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.INVERT, this._$gl.INVERT);
|
|
731
|
+
this._$gl.colorMask(false, false, false, false);
|
|
732
|
+
coverageShader._$fill(fillVertexArrayObject);
|
|
733
|
+
this._$gl.disable(this._$gl.SAMPLE_ALPHA_TO_COVERAGE);
|
|
734
|
+
// draw shape range
|
|
735
|
+
this._$gl.stencilFunc(this._$gl.NOTEQUAL, 0, 0xff);
|
|
736
|
+
this._$gl.stencilOp(this._$gl.KEEP, this._$gl.ZERO, this._$gl.ZERO);
|
|
737
|
+
this._$gl.colorMask(true, true, true, true);
|
|
738
|
+
shader._$fill(fillVertexArrayObject);
|
|
739
|
+
// mask off
|
|
740
|
+
this._$gl.disable(this._$gl.STENCIL_TEST);
|
|
741
|
+
// release vertex array
|
|
742
|
+
this.releaseFillVertexArray(fillVertexArrayObject);
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* @param {WebGLVertexArrayObject} vertex_array
|
|
746
|
+
* @return {void}
|
|
747
|
+
* @method
|
|
748
|
+
* @public
|
|
749
|
+
*/
|
|
750
|
+
releaseFillVertexArray(vertex_array) {
|
|
751
|
+
// release shape vertex array object
|
|
752
|
+
this._$vao.releaseFill(vertex_array);
|
|
753
|
+
const indexRanges = vertex_array.indexRanges;
|
|
754
|
+
for (let idx = 0; idx < indexRanges.length; ++idx) {
|
|
755
|
+
WebGLFillMeshGenerator
|
|
756
|
+
.indexRangePool
|
|
757
|
+
.push(indexRanges[idx]);
|
|
758
|
+
}
|
|
759
|
+
$poolArray(indexRanges);
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* @return {void}
|
|
763
|
+
* @method
|
|
764
|
+
* @public
|
|
765
|
+
*/
|
|
766
|
+
_$enterClip() {
|
|
767
|
+
this._$mask._$enterClip();
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* @return {void}
|
|
771
|
+
* @method
|
|
772
|
+
* @public
|
|
773
|
+
*/
|
|
774
|
+
_$beginClipDef() {
|
|
775
|
+
this._$mask._$beginClipDef();
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* @param {boolean} flag
|
|
779
|
+
* @return {void}
|
|
780
|
+
* @method
|
|
781
|
+
* @private
|
|
782
|
+
*/
|
|
783
|
+
_$updateContainerClipFlag(flag) {
|
|
784
|
+
this._$mask.containerClip = flag;
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* @description マスク処理の開始関数
|
|
788
|
+
* Mask processing start function
|
|
789
|
+
*
|
|
790
|
+
* @param {Float32Array} matrix
|
|
791
|
+
* @param {object} bounds
|
|
792
|
+
* @return {Float32Array}
|
|
793
|
+
* @method
|
|
794
|
+
* @public
|
|
795
|
+
*/
|
|
796
|
+
_$startClip(matrix, bounds) {
|
|
797
|
+
let x = bounds.xMin;
|
|
798
|
+
let y = bounds.yMin;
|
|
799
|
+
let width = Math.abs(bounds.xMax - bounds.xMin);
|
|
800
|
+
let height = Math.abs(bounds.yMax - bounds.yMin);
|
|
801
|
+
// resize
|
|
802
|
+
const manager = this._$frameBufferManager;
|
|
803
|
+
const currentAttachment = manager.currentAttachment;
|
|
804
|
+
if (!currentAttachment || !currentAttachment.texture) {
|
|
805
|
+
throw new Error("the current Attachment is null.");
|
|
806
|
+
}
|
|
807
|
+
if (x > currentAttachment.width
|
|
808
|
+
|| y > currentAttachment.height) {
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
if (width + x > currentAttachment.width) {
|
|
812
|
+
width = currentAttachment.width - x;
|
|
813
|
+
}
|
|
814
|
+
if (height + y > currentAttachment.height) {
|
|
815
|
+
height = currentAttachment.height - y;
|
|
816
|
+
}
|
|
817
|
+
if (0 > x) {
|
|
818
|
+
width += x;
|
|
819
|
+
x = 0;
|
|
820
|
+
}
|
|
821
|
+
if (0 > y) {
|
|
822
|
+
height += y;
|
|
823
|
+
y = 0;
|
|
824
|
+
}
|
|
825
|
+
if (0 >= width || 0 >= height) {
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
width = $Math.ceil(width);
|
|
829
|
+
height = $Math.ceil(height);
|
|
830
|
+
this._$cacheBounds.xMin = x;
|
|
831
|
+
this._$cacheBounds.yMin = y;
|
|
832
|
+
this._$cacheBounds.xMax = width;
|
|
833
|
+
this._$cacheBounds.yMax = height;
|
|
834
|
+
this._$cacheAttachment = currentAttachment;
|
|
835
|
+
// create new buffer
|
|
836
|
+
this._$bind(manager.createCacheAttachment(width, height, true));
|
|
837
|
+
// draw background
|
|
838
|
+
const texture = currentAttachment.texture;
|
|
839
|
+
this.reset();
|
|
840
|
+
this.setTransform(1, 0, 0, 1, 0, 0);
|
|
841
|
+
this.drawImage(texture, -x, -y, texture.width, texture.height);
|
|
842
|
+
return $getFloat32Array6(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4] - bounds.xMin, matrix[5] - bounds.yMin);
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* @return {void}
|
|
846
|
+
* @method
|
|
847
|
+
* @public
|
|
848
|
+
*/
|
|
849
|
+
_$endClipDef() {
|
|
850
|
+
this._$mask._$endClipDef();
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* @return {void}
|
|
854
|
+
* @method
|
|
855
|
+
* @public
|
|
856
|
+
*/
|
|
857
|
+
_$leaveClip() {
|
|
858
|
+
this._$mask._$leaveClip();
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* @return {void}
|
|
862
|
+
* @method
|
|
863
|
+
* @public
|
|
864
|
+
*/
|
|
865
|
+
_$drawContainerClip() {
|
|
866
|
+
this._$mask._$drawContainerClip();
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* @return {void}
|
|
870
|
+
* @method
|
|
871
|
+
* @public
|
|
872
|
+
*/
|
|
873
|
+
closePath() {
|
|
874
|
+
this._$path.close();
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* @return {void}
|
|
878
|
+
* @method
|
|
879
|
+
* @public
|
|
880
|
+
*/
|
|
881
|
+
stroke() {
|
|
882
|
+
const strokeVertices = this._$path.vertices;
|
|
883
|
+
if (!strokeVertices.length) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
const checkVertices = $getArray();
|
|
887
|
+
for (let idx = 0; idx < strokeVertices.length; ++idx) {
|
|
888
|
+
const vertices = strokeVertices[idx];
|
|
889
|
+
if (6 > vertices.length) {
|
|
890
|
+
continue;
|
|
891
|
+
}
|
|
892
|
+
checkVertices.push(vertices);
|
|
893
|
+
}
|
|
894
|
+
if (!checkVertices.length) {
|
|
895
|
+
$poolArray(checkVertices);
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
const strokeBuffer = this._$vao.createStroke(strokeVertices, this.lineCap, this.lineJoin);
|
|
899
|
+
let matrix = this._$matrix;
|
|
900
|
+
const strokeStyle = this.strokeStyle;
|
|
901
|
+
let face = $Math.sign(matrix[0] * matrix[4]);
|
|
902
|
+
if (face > 0 && matrix[1] !== 0 && matrix[3] !== 0) {
|
|
903
|
+
face = -$Math.sign(matrix[1] * matrix[3]);
|
|
904
|
+
}
|
|
905
|
+
let lineWidth = this.lineWidth * 0.5;
|
|
906
|
+
let scaleX;
|
|
907
|
+
let scaleY;
|
|
908
|
+
if (this._$grid.enabled) {
|
|
909
|
+
// lineWidth *= $getSameScaleBase();
|
|
910
|
+
scaleX = $Math.abs(this._$grid.ancestorMatrixA + this._$grid.ancestorMatrixD);
|
|
911
|
+
scaleY = $Math.abs(this._$grid.ancestorMatrixB + this._$grid.ancestorMatrixE);
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
scaleX = $Math.abs(matrix[0] + matrix[3]);
|
|
915
|
+
scaleY = $Math.abs(matrix[1] + matrix[4]);
|
|
916
|
+
}
|
|
917
|
+
const scaleMin = $Math.min(scaleX, scaleY);
|
|
918
|
+
const scaleMax = $Math.max(scaleX, scaleY);
|
|
919
|
+
lineWidth *= scaleMax * (1 - 0.3 * $Math.cos($Math.PI * 0.5 * (scaleMin / scaleMax)));
|
|
920
|
+
lineWidth = $Math.max(1, lineWidth);
|
|
921
|
+
const hasGrid = this._$grid.enabled;
|
|
922
|
+
let texture;
|
|
923
|
+
let variants;
|
|
924
|
+
let shader;
|
|
925
|
+
if (strokeStyle instanceof CanvasGradientToWebGL) {
|
|
926
|
+
if (strokeStyle.type === "radial") {
|
|
927
|
+
matrix = this._$stack[this._$stack.length - 1];
|
|
928
|
+
}
|
|
929
|
+
const stops = strokeStyle.stops;
|
|
930
|
+
const isLinearSpace = strokeStyle.rgb === "linearRGB";
|
|
931
|
+
texture = this
|
|
932
|
+
._$gradientLUT
|
|
933
|
+
.generateForShape(stops, isLinearSpace);
|
|
934
|
+
this
|
|
935
|
+
._$frameBufferManager
|
|
936
|
+
.textureManager
|
|
937
|
+
.bind0(texture, true);
|
|
938
|
+
variants = this
|
|
939
|
+
._$shaderList
|
|
940
|
+
.gradientShapeShaderVariants;
|
|
941
|
+
if (strokeStyle.type === "linear") {
|
|
942
|
+
shader = variants
|
|
943
|
+
.getGradientShapeShader(true, hasGrid, false, false, strokeStyle.mode);
|
|
944
|
+
variants.setGradientShapeUniform(shader.uniform, true, lineWidth, face, this.miterLimit, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, false, strokeStyle.points, 0);
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
matrix = this._$stack[this._$stack.length - 1];
|
|
948
|
+
const hasFocalPoint = strokeStyle.focalPointRatio !== 0;
|
|
949
|
+
shader = variants
|
|
950
|
+
.getGradientShapeShader(true, hasGrid, true, hasFocalPoint, strokeStyle.mode);
|
|
951
|
+
variants.setGradientShapeUniform(shader.uniform, true, lineWidth, face, this.miterLimit, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, true, strokeStyle.points, strokeStyle.focalPointRatio);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
else if (strokeStyle instanceof CanvasPatternToWebGL) {
|
|
955
|
+
matrix = this._$stack[this._$stack.length - 1];
|
|
956
|
+
const pct = strokeStyle.colorTransform;
|
|
957
|
+
texture = strokeStyle.texture;
|
|
958
|
+
this
|
|
959
|
+
._$frameBufferManager
|
|
960
|
+
.textureManager
|
|
961
|
+
.bind0(texture);
|
|
962
|
+
variants = this
|
|
963
|
+
._$shaderList
|
|
964
|
+
.shapeShaderVariants;
|
|
965
|
+
shader = variants
|
|
966
|
+
.getBitmapShapeShader(true, strokeStyle.repeat, this._$grid.enabled);
|
|
967
|
+
if (pct) {
|
|
968
|
+
variants.setBitmapShapeUniform(shader.uniform, true, lineWidth, face, this.miterLimit, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, texture.width, texture.height, pct[0], pct[1], pct[2], this._$globalAlpha, pct[4] / 255, pct[5] / 255, pct[6] / 255, 0);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
variants.setBitmapShapeUniform(shader.uniform, true, lineWidth, face, this.miterLimit, hasGrid, matrix, $inverseMatrix(this._$matrix), this._$viewportWidth, this._$viewportHeight, this._$grid, texture.width, texture.height, 1, 1, 1, this._$globalAlpha, 0, 0, 0, 0);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
variants = this
|
|
976
|
+
._$shaderList
|
|
977
|
+
.shapeShaderVariants;
|
|
978
|
+
shader = variants
|
|
979
|
+
.getSolidColorShapeShader(true, this._$grid.enabled);
|
|
980
|
+
variants.setSolidColorShapeUniform(shader.uniform, true, lineWidth, face, this.miterLimit, hasGrid, matrix, this._$viewportWidth, this._$viewportHeight, this._$grid, strokeStyle, this._$globalAlpha);
|
|
981
|
+
}
|
|
982
|
+
shader._$stroke(strokeBuffer);
|
|
983
|
+
this._$vao.releaseStroke(strokeBuffer);
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* @param {number} x
|
|
987
|
+
* @param {number} y
|
|
988
|
+
* @param {number} radius
|
|
989
|
+
* @return {void}
|
|
990
|
+
* @method
|
|
991
|
+
* @public
|
|
992
|
+
*/
|
|
993
|
+
arc(x, y, radius) {
|
|
994
|
+
this._$path.drawCircle(x, y, radius);
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* @return {void}
|
|
998
|
+
* @method
|
|
999
|
+
* @public
|
|
1000
|
+
*/
|
|
1001
|
+
clip() {
|
|
1002
|
+
// to triangle
|
|
1003
|
+
const fillVertices = this._$path.vertices;
|
|
1004
|
+
if (!fillVertices.length) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const checkVertices = $getArray();
|
|
1008
|
+
for (let idx = 0; idx < fillVertices.length; ++idx) {
|
|
1009
|
+
const vertices = fillVertices[idx];
|
|
1010
|
+
if (10 > vertices.length) {
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
checkVertices.push(vertices);
|
|
1014
|
+
}
|
|
1015
|
+
if (!checkVertices.length) {
|
|
1016
|
+
$poolArray(checkVertices);
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
const fillVertexArrayObject = this._$vao.createFill(checkVertices);
|
|
1020
|
+
// mask render
|
|
1021
|
+
const variants = this
|
|
1022
|
+
._$shaderList
|
|
1023
|
+
.shapeShaderVariants;
|
|
1024
|
+
const shader = variants.getMaskShapeShader(false, false);
|
|
1025
|
+
const uniform = shader.uniform;
|
|
1026
|
+
variants.setMaskShapeUniform(uniform, false, this._$matrix[0], this._$matrix[1], this._$matrix[2], this._$matrix[3], this._$matrix[4], this._$matrix[5], this._$matrix[6], this._$matrix[7], this._$matrix[8], this._$viewportWidth, this._$viewportHeight, null);
|
|
1027
|
+
if (this._$mask._$onClip(fillVertexArrayObject, this._$matrix, this._$viewportWidth, this._$viewportHeight)) {
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
shader._$fill(fillVertexArrayObject);
|
|
1031
|
+
this.beginPath();
|
|
1032
|
+
}
|
|
1033
|
+
/**
|
|
1034
|
+
* @return {void}
|
|
1035
|
+
* @method
|
|
1036
|
+
* @public
|
|
1037
|
+
*/
|
|
1038
|
+
save() {
|
|
1039
|
+
// matrix
|
|
1040
|
+
const matrix = this._$matrix;
|
|
1041
|
+
this._$stack.push($getFloat32Array9(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5], matrix[6], matrix[7], matrix[8]));
|
|
1042
|
+
// mask
|
|
1043
|
+
this._$mask._$onSave();
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* @return {void}
|
|
1047
|
+
* @method
|
|
1048
|
+
* @public
|
|
1049
|
+
*/
|
|
1050
|
+
restore() {
|
|
1051
|
+
//matrix
|
|
1052
|
+
if (this._$stack.length) {
|
|
1053
|
+
$poolFloat32Array9(this._$matrix);
|
|
1054
|
+
this._$matrix = this._$stack.pop() || $getFloat32Array9();
|
|
1055
|
+
}
|
|
1056
|
+
// mask
|
|
1057
|
+
this._$mask._$onRestore();
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* @param {WebGLTexture} texture
|
|
1061
|
+
* @param {boolean} repeat
|
|
1062
|
+
* @param {Float32Array} color_transform
|
|
1063
|
+
* @return {CanvasPatternToWebGL}
|
|
1064
|
+
* @method
|
|
1065
|
+
* @public
|
|
1066
|
+
*/
|
|
1067
|
+
createPattern(texture, repeat, color_transform) {
|
|
1068
|
+
return new CanvasPatternToWebGL(this, texture, repeat, color_transform);
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* @param {number} x0
|
|
1072
|
+
* @param {number} y0
|
|
1073
|
+
* @param {number} x1
|
|
1074
|
+
* @param {number} y1
|
|
1075
|
+
* @param {string} [rgb=InterpolationMethod.RGB]
|
|
1076
|
+
* @param {string} [mode=SpreadMethod.PAD]
|
|
1077
|
+
* @return {CanvasGradientToWebGL}
|
|
1078
|
+
* @method
|
|
1079
|
+
* @public
|
|
1080
|
+
*/
|
|
1081
|
+
createLinearGradient(x0, y0, x1, y1, rgb = "rgb", mode = "pad") {
|
|
1082
|
+
return new CanvasGradientToWebGL()
|
|
1083
|
+
.linear(x0, y0, x1, y1, rgb, mode);
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* @param {number} x0
|
|
1087
|
+
* @param {number} y0
|
|
1088
|
+
* @param {number} r0
|
|
1089
|
+
* @param {number} x1
|
|
1090
|
+
* @param {number} y1
|
|
1091
|
+
* @param {number} r1
|
|
1092
|
+
* @param {string} [rgb=InterpolationMethod.RGB]
|
|
1093
|
+
* @param {string} [mode=SpreadMethod.PAD]
|
|
1094
|
+
* @param {number} [focal_point_ratio=0]
|
|
1095
|
+
* @return {CanvasGradientToWebGL}
|
|
1096
|
+
* @method
|
|
1097
|
+
* @public
|
|
1098
|
+
*/
|
|
1099
|
+
createRadialGradient(x0, y0, r0, x1, y1, r1, rgb = "rgb", mode = "pad", focal_point_ratio = 0) {
|
|
1100
|
+
return new CanvasGradientToWebGL()
|
|
1101
|
+
.radial(x0, y0, r0, x1, y1, r1, rgb, mode, focal_point_ratio);
|
|
1102
|
+
}
|
|
1103
|
+
/**
|
|
1104
|
+
* @param {WebGLTexture} texture
|
|
1105
|
+
* @param {boolean} is_horizontal
|
|
1106
|
+
* @param {number} blur
|
|
1107
|
+
* @return {void}
|
|
1108
|
+
* @method
|
|
1109
|
+
* @public
|
|
1110
|
+
*/
|
|
1111
|
+
_$applyBlurFilter(texture, is_horizontal, blur) {
|
|
1112
|
+
const manager = this._$frameBufferManager;
|
|
1113
|
+
const currentAttachment = manager.currentAttachment;
|
|
1114
|
+
if (!currentAttachment) {
|
|
1115
|
+
throw new Error("the current attachment is null.");
|
|
1116
|
+
}
|
|
1117
|
+
const width = currentAttachment.width;
|
|
1118
|
+
const height = currentAttachment.height;
|
|
1119
|
+
manager
|
|
1120
|
+
.textureManager
|
|
1121
|
+
.bind0(texture, true);
|
|
1122
|
+
const halfBlur = $Math.ceil(blur * 0.5);
|
|
1123
|
+
const fraction = 1 - (halfBlur - blur * 0.5);
|
|
1124
|
+
const samples = 1 + blur;
|
|
1125
|
+
const variants = this
|
|
1126
|
+
._$shaderList
|
|
1127
|
+
.filterShaderVariants;
|
|
1128
|
+
const shader = variants
|
|
1129
|
+
.getBlurFilterShader(halfBlur);
|
|
1130
|
+
variants
|
|
1131
|
+
.setBlurFilterUniform(shader.uniform, width, height, is_horizontal, fraction, samples);
|
|
1132
|
+
shader._$drawImage();
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* @param {WebGLTexture} texture
|
|
1136
|
+
* @param {number} width
|
|
1137
|
+
* @param {number} height
|
|
1138
|
+
* @param {number} base_width
|
|
1139
|
+
* @param {number} base_height
|
|
1140
|
+
* @param {number} base_offset_x
|
|
1141
|
+
* @param {number} base_offset_y
|
|
1142
|
+
* @param {number} blur_width
|
|
1143
|
+
* @param {number} blur_height
|
|
1144
|
+
* @param {number} blur_offset_x
|
|
1145
|
+
* @param {number} blur_offset_y
|
|
1146
|
+
* @param {boolean} is_glow
|
|
1147
|
+
* @param {string} type
|
|
1148
|
+
* @param {boolean} knockout
|
|
1149
|
+
* @param {number} strength
|
|
1150
|
+
* @param {array | null} [ratios = null]
|
|
1151
|
+
* @param {array | null} [colors = null]
|
|
1152
|
+
* @param {array | null} [alphas = null]
|
|
1153
|
+
* @param {number} [color_r1 = 0]
|
|
1154
|
+
* @param {number} [color_g1 = 0]
|
|
1155
|
+
* @param {number} [color_b1 = 0]
|
|
1156
|
+
* @param {number} [color_a1 = 0]
|
|
1157
|
+
* @param {number} [color_r2 = 0]
|
|
1158
|
+
* @param {number} [color_g2 = 0]
|
|
1159
|
+
* @param {number} [color_b2 = 0]
|
|
1160
|
+
* @param {number} [color_a2 = 0]
|
|
1161
|
+
* @return {void}
|
|
1162
|
+
* @method
|
|
1163
|
+
* @public
|
|
1164
|
+
*/
|
|
1165
|
+
_$applyBitmapFilter(texture, width, height, base_width, base_height, base_offset_x, base_offset_y, blur_width, blur_height, blur_offset_x, blur_offset_y, is_glow, type, knockout, strength, ratios = null, colors = null, alphas = null, color_r1 = 0, color_g1 = 0, color_b1 = 0, color_a1 = 0, color_r2 = 0, color_g2 = 0, color_b2 = 0, color_a2 = 0) {
|
|
1166
|
+
const manager = this._$frameBufferManager;
|
|
1167
|
+
const isInner = type === "inner";
|
|
1168
|
+
const baseAttachment = manager.currentAttachment;
|
|
1169
|
+
const baseTexture = manager.getTextureFromCurrentAttachment();
|
|
1170
|
+
let lut = null;
|
|
1171
|
+
const isGradient = ratios !== null && colors !== null && alphas !== null;
|
|
1172
|
+
if (ratios !== null && colors !== null && alphas !== null) {
|
|
1173
|
+
lut = this
|
|
1174
|
+
._$gradientLUT
|
|
1175
|
+
.generateForFilter(ratios, colors, alphas);
|
|
1176
|
+
}
|
|
1177
|
+
let targetTextureAttachment;
|
|
1178
|
+
if (isInner) {
|
|
1179
|
+
if (isGradient && lut) {
|
|
1180
|
+
manager
|
|
1181
|
+
.textureManager
|
|
1182
|
+
.bind02(texture, lut, true);
|
|
1183
|
+
}
|
|
1184
|
+
else {
|
|
1185
|
+
manager
|
|
1186
|
+
.textureManager
|
|
1187
|
+
.bind0(texture);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
else {
|
|
1191
|
+
targetTextureAttachment = this
|
|
1192
|
+
._$frameBufferManager
|
|
1193
|
+
.createTextureAttachment(width, height);
|
|
1194
|
+
this._$bind(targetTextureAttachment);
|
|
1195
|
+
if (isGradient && lut) {
|
|
1196
|
+
manager
|
|
1197
|
+
.textureManager
|
|
1198
|
+
.bind012(texture, baseTexture, lut, true);
|
|
1199
|
+
}
|
|
1200
|
+
else {
|
|
1201
|
+
manager
|
|
1202
|
+
.textureManager
|
|
1203
|
+
.bind01(texture, baseTexture);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
const transformsBase = !(isInner || type === "full" && knockout);
|
|
1207
|
+
const transformsBlur = !(width === blur_width && height === blur_height && blur_offset_x === 0 && blur_offset_y === 0);
|
|
1208
|
+
const appliesStrength = !(strength === 1);
|
|
1209
|
+
const variants = this
|
|
1210
|
+
._$shaderList
|
|
1211
|
+
.filterShaderVariants;
|
|
1212
|
+
const shader = variants.getBitmapFilterShader(transformsBase, transformsBlur, is_glow, type, knockout, appliesStrength, isGradient);
|
|
1213
|
+
variants.setBitmapFilterUniform(shader.uniform, width, height, base_width, base_height, base_offset_x, base_offset_y, blur_width, blur_height, blur_offset_x, blur_offset_y, is_glow, strength, color_r1, color_g1, color_b1, color_a1, color_r2, color_g2, color_b2, color_a2, transformsBase, transformsBlur, appliesStrength, isGradient);
|
|
1214
|
+
if (!isInner) {
|
|
1215
|
+
this.blend.toOneZero();
|
|
1216
|
+
}
|
|
1217
|
+
else if (knockout) {
|
|
1218
|
+
this.blend.toSourceIn();
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
this.blend.toSourceAtop();
|
|
1222
|
+
}
|
|
1223
|
+
shader._$drawImage();
|
|
1224
|
+
if (!isInner) {
|
|
1225
|
+
manager
|
|
1226
|
+
.releaseAttachment(baseAttachment, true);
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* @param {WebGLTexture} texture
|
|
1231
|
+
* @param {array} matrix
|
|
1232
|
+
* @return {void}
|
|
1233
|
+
* @method
|
|
1234
|
+
* @public
|
|
1235
|
+
*/
|
|
1236
|
+
_$applyColorMatrixFilter(texture, matrix) {
|
|
1237
|
+
this
|
|
1238
|
+
._$frameBufferManager
|
|
1239
|
+
.textureManager
|
|
1240
|
+
.bind0(texture, true);
|
|
1241
|
+
const variants = this
|
|
1242
|
+
._$shaderList
|
|
1243
|
+
.filterShaderVariants;
|
|
1244
|
+
const shader = variants
|
|
1245
|
+
.getColorMatrixFilterShader();
|
|
1246
|
+
variants
|
|
1247
|
+
.setColorMatrixFilterUniform(shader.uniform, matrix);
|
|
1248
|
+
this.blend.reset();
|
|
1249
|
+
shader._$drawImage();
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* @param {WebGLTexture} texture
|
|
1253
|
+
* @param {number} matrix_x
|
|
1254
|
+
* @param {number} matrix_y
|
|
1255
|
+
* @param {Float32Array} matrix
|
|
1256
|
+
* @param {number} divisor
|
|
1257
|
+
* @param {number} bias
|
|
1258
|
+
* @param {boolean} preserve_alpha
|
|
1259
|
+
* @param {boolean} clamp
|
|
1260
|
+
* @param {number} color_r
|
|
1261
|
+
* @param {number} color_g
|
|
1262
|
+
* @param {number} color_b
|
|
1263
|
+
* @param {number} color_a
|
|
1264
|
+
* @return {void}
|
|
1265
|
+
* @method
|
|
1266
|
+
* @public
|
|
1267
|
+
*/
|
|
1268
|
+
_$applyConvolutionFilter(texture, matrix_x, matrix_y, matrix, divisor, bias, preserve_alpha, clamp, color_r, color_g, color_b, color_a) {
|
|
1269
|
+
const width = texture.width;
|
|
1270
|
+
const height = texture.height;
|
|
1271
|
+
const targetTextureAttachment = this
|
|
1272
|
+
._$frameBufferManager
|
|
1273
|
+
.createTextureAttachment(width, height);
|
|
1274
|
+
this._$bind(targetTextureAttachment);
|
|
1275
|
+
this
|
|
1276
|
+
._$frameBufferManager
|
|
1277
|
+
.textureManager
|
|
1278
|
+
.bind0(texture, true);
|
|
1279
|
+
const variants = this
|
|
1280
|
+
._$shaderList
|
|
1281
|
+
.filterShaderVariants;
|
|
1282
|
+
const shader = variants
|
|
1283
|
+
.getConvolutionFilterShader(matrix_x, matrix_y, preserve_alpha, clamp);
|
|
1284
|
+
variants.setConvolutionFilterUniform(shader.uniform, width, height, matrix, divisor, bias, clamp, color_r, color_g, color_b, color_a);
|
|
1285
|
+
this.blend.reset();
|
|
1286
|
+
shader._$drawImage();
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* @param {WebGLTexture} texture
|
|
1290
|
+
* @param {HTMLImageElement} map
|
|
1291
|
+
* @param {number} base_width
|
|
1292
|
+
* @param {number} base_height
|
|
1293
|
+
* @param {PointImpl} [point=null]
|
|
1294
|
+
* @param {number} component_x
|
|
1295
|
+
* @param {number} component_y
|
|
1296
|
+
* @param {number} scale_x
|
|
1297
|
+
* @param {number} scale_y
|
|
1298
|
+
* @param {string} mode
|
|
1299
|
+
* @param {number} color_r
|
|
1300
|
+
* @param {number} color_g
|
|
1301
|
+
* @param {number} color_b
|
|
1302
|
+
* @param {number} color_a
|
|
1303
|
+
* @return {void}
|
|
1304
|
+
* @method
|
|
1305
|
+
* @private
|
|
1306
|
+
*/
|
|
1307
|
+
_$applyDisplacementMapFilter(texture, map, base_width, base_height, point, component_x, component_y, scale_x, scale_y, mode, color_r, color_g, color_b, color_a) {
|
|
1308
|
+
const width = texture.width;
|
|
1309
|
+
const height = texture.height;
|
|
1310
|
+
const targetTextureAttachment = this
|
|
1311
|
+
._$frameBufferManager
|
|
1312
|
+
.createTextureAttachment(width, height);
|
|
1313
|
+
this._$bind(targetTextureAttachment);
|
|
1314
|
+
if (!point) {
|
|
1315
|
+
point = { "x": 0, "y": 0 };
|
|
1316
|
+
}
|
|
1317
|
+
const mapTexture = this
|
|
1318
|
+
._$frameBufferManager
|
|
1319
|
+
.createTextureFromImage(map);
|
|
1320
|
+
this
|
|
1321
|
+
._$frameBufferManager
|
|
1322
|
+
.textureManager
|
|
1323
|
+
.bind01(texture, mapTexture);
|
|
1324
|
+
const variants = this
|
|
1325
|
+
._$shaderList
|
|
1326
|
+
.filterShaderVariants;
|
|
1327
|
+
const shader = variants
|
|
1328
|
+
.getDisplacementMapFilterShader(component_x, component_y, mode);
|
|
1329
|
+
variants.setDisplacementMapFilterUniform(shader.uniform, map.width, map.height, base_width, base_height, point.x, point.y, scale_x, scale_y, mode, color_r, color_g, color_b, color_a);
|
|
1330
|
+
this.blend.reset();
|
|
1331
|
+
shader._$drawImage();
|
|
1332
|
+
this
|
|
1333
|
+
._$frameBufferManager
|
|
1334
|
+
.releaseTexture(mapTexture);
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* @param {BoundsImpl} position
|
|
1338
|
+
* @return {void}
|
|
1339
|
+
* @method
|
|
1340
|
+
* @private
|
|
1341
|
+
*/
|
|
1342
|
+
_$startLayer(position) {
|
|
1343
|
+
this._$positions.push(position);
|
|
1344
|
+
this._$blends.push(this._$isLayer);
|
|
1345
|
+
this._$isLayer = true;
|
|
1346
|
+
}
|
|
1347
|
+
/**
|
|
1348
|
+
* @return {void}
|
|
1349
|
+
* @method
|
|
1350
|
+
* @private
|
|
1351
|
+
*/
|
|
1352
|
+
_$endLayer() {
|
|
1353
|
+
const bounds = this._$positions.pop();
|
|
1354
|
+
if (bounds) {
|
|
1355
|
+
$poolBoundsObject(bounds);
|
|
1356
|
+
}
|
|
1357
|
+
this._$isLayer = !!this._$blends.pop();
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* @return {void}
|
|
1361
|
+
* @method
|
|
1362
|
+
* @private
|
|
1363
|
+
*/
|
|
1364
|
+
_$saveCurrentMask() {
|
|
1365
|
+
this._$maskBufferArray.push(this._$cacheAttachment);
|
|
1366
|
+
this._$cacheAttachment = null;
|
|
1367
|
+
const bounds = this._$cacheBounds;
|
|
1368
|
+
this._$maskBoundsArray.push($getBoundsObject(bounds.xMin, bounds.xMax, bounds.yMin, bounds.yMax));
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* @param {number} width
|
|
1372
|
+
* @param {number} height
|
|
1373
|
+
* @param {boolean} [multisample=false]
|
|
1374
|
+
* @return {void}
|
|
1375
|
+
* @method
|
|
1376
|
+
* @private
|
|
1377
|
+
*/
|
|
1378
|
+
_$saveAttachment(width, height, multisample = false) {
|
|
1379
|
+
const manager = this._$frameBufferManager;
|
|
1380
|
+
this
|
|
1381
|
+
._$attachmentArray
|
|
1382
|
+
.push(manager.currentAttachment);
|
|
1383
|
+
this._$bind(manager.createCacheAttachment(width, height, multisample));
|
|
1384
|
+
}
|
|
1385
|
+
/**
|
|
1386
|
+
* @return {void}
|
|
1387
|
+
* @method
|
|
1388
|
+
* @private
|
|
1389
|
+
*/
|
|
1390
|
+
_$restoreAttachment(release_texture = false) {
|
|
1391
|
+
const manager = this._$frameBufferManager;
|
|
1392
|
+
manager.releaseAttachment(manager.currentAttachment, release_texture);
|
|
1393
|
+
this._$bind(this._$attachmentArray.pop());
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* @return {void}
|
|
1397
|
+
* @method
|
|
1398
|
+
* @private
|
|
1399
|
+
*/
|
|
1400
|
+
_$restoreCurrentMask() {
|
|
1401
|
+
this._$cacheAttachment = this._$maskBufferArray.pop() || null;
|
|
1402
|
+
this._$cacheBounds = this._$maskBoundsArray.pop() || $getBoundsObject();
|
|
1403
|
+
}
|
|
1404
|
+
/**
|
|
1405
|
+
* @return {object}
|
|
1406
|
+
* @method
|
|
1407
|
+
* @private
|
|
1408
|
+
*/
|
|
1409
|
+
getCurrentPosition() {
|
|
1410
|
+
return this._$positions[this._$positions.length - 1];
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* @description 最大テクスチャサイズを超えないスケール値を取得する
|
|
1414
|
+
* @param {number} width
|
|
1415
|
+
* @param {number} height
|
|
1416
|
+
* @return {number}
|
|
1417
|
+
* @method
|
|
1418
|
+
* @public
|
|
1419
|
+
*/
|
|
1420
|
+
textureScale(width, height) {
|
|
1421
|
+
const maxSize = $Math.max(width, height);
|
|
1422
|
+
if (maxSize > this._$maxTextureSize) {
|
|
1423
|
+
return this._$maxTextureSize / maxSize;
|
|
1424
|
+
}
|
|
1425
|
+
return 1;
|
|
1426
|
+
}
|
|
1427
|
+
}
|