@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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/BezierConverter.d.ts +59 -0
  4. package/dist/BezierConverter.js +106 -0
  5. package/dist/CanvasGradientToWebGL.d.ts +96 -0
  6. package/dist/CanvasGradientToWebGL.js +181 -0
  7. package/dist/CanvasPatternToWebGL.d.ts +39 -0
  8. package/dist/CanvasPatternToWebGL.js +66 -0
  9. package/dist/CanvasToWebGLContext.d.ts +591 -0
  10. package/dist/CanvasToWebGLContext.js +1427 -0
  11. package/dist/CanvasToWebGLContextBlend.d.ts +97 -0
  12. package/dist/CanvasToWebGLContextBlend.js +299 -0
  13. package/dist/CanvasToWebGLContextGrid.d.ts +74 -0
  14. package/dist/CanvasToWebGLContextGrid.js +283 -0
  15. package/dist/CanvasToWebGLContextMask.d.ts +113 -0
  16. package/dist/CanvasToWebGLContextMask.js +436 -0
  17. package/dist/CanvasToWebGLContextPath.d.ts +111 -0
  18. package/dist/CanvasToWebGLContextPath.js +210 -0
  19. package/dist/CanvasToWebGLContextStyle.d.ts +78 -0
  20. package/dist/CanvasToWebGLContextStyle.js +139 -0
  21. package/dist/ColorBufferPool.d.ts +58 -0
  22. package/dist/ColorBufferPool.js +134 -0
  23. package/dist/FrameBufferManager.d.ts +135 -0
  24. package/dist/FrameBufferManager.js +358 -0
  25. package/dist/StencilBufferPool.d.ts +56 -0
  26. package/dist/StencilBufferPool.js +142 -0
  27. package/dist/TextureManager.d.ts +130 -0
  28. package/dist/TextureManager.js +296 -0
  29. package/dist/VertexArrayObjectManager.d.ts +96 -0
  30. package/dist/VertexArrayObjectManager.js +277 -0
  31. package/dist/WebGLFillMeshGenerator.d.ts +31 -0
  32. package/dist/WebGLFillMeshGenerator.js +101 -0
  33. package/dist/WebGLStrokeMeshGenerator.d.ts +183 -0
  34. package/dist/WebGLStrokeMeshGenerator.js +504 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +6 -0
  37. package/dist/interface/AttachmentImpl.d.ts +11 -0
  38. package/dist/interface/AttachmentImpl.js +1 -0
  39. package/dist/interface/BoundsImpl.d.ts +6 -0
  40. package/dist/interface/BoundsImpl.js +1 -0
  41. package/dist/interface/CapsStyleImpl.d.ts +1 -0
  42. package/dist/interface/CapsStyleImpl.js +1 -0
  43. package/dist/interface/ClipObjectImpl.d.ts +14 -0
  44. package/dist/interface/ClipObjectImpl.js +1 -0
  45. package/dist/interface/FillMeshImpl.d.ts +5 -0
  46. package/dist/interface/FillMeshImpl.js +1 -0
  47. package/dist/interface/GradientTypeImpl.d.ts +1 -0
  48. package/dist/interface/GradientTypeImpl.js +1 -0
  49. package/dist/interface/GridImpl.d.ts +6 -0
  50. package/dist/interface/GridImpl.js +1 -0
  51. package/dist/interface/IndexRangeImpl.d.ts +4 -0
  52. package/dist/interface/IndexRangeImpl.js +1 -0
  53. package/dist/interface/InterpolationMethodImpl.d.ts +1 -0
  54. package/dist/interface/InterpolationMethodImpl.js +1 -0
  55. package/dist/interface/JointStyleImpl.d.ts +1 -0
  56. package/dist/interface/JointStyleImpl.js +1 -0
  57. package/dist/interface/SpreadMethodImpl.d.ts +1 -0
  58. package/dist/interface/SpreadMethodImpl.js +1 -0
  59. package/dist/interface/StrokeMethImpl.d.ts +4 -0
  60. package/dist/interface/StrokeMethImpl.js +1 -0
  61. package/dist/interface/UniformDataImpl.d.ts +5 -0
  62. package/dist/interface/UniformDataImpl.js +1 -0
  63. package/dist/interface/VerticesImpl.d.ts +1 -0
  64. package/dist/interface/VerticesImpl.js +1 -0
  65. package/dist/shader/CanvasToWebGLShader.d.ts +85 -0
  66. package/dist/shader/CanvasToWebGLShader.js +192 -0
  67. package/dist/shader/CanvasToWebGLShaderList.d.ts +70 -0
  68. package/dist/shader/CanvasToWebGLShaderList.js +109 -0
  69. package/dist/shader/GradientLUTGenerator.d.ts +36 -0
  70. package/dist/shader/GradientLUTGenerator.js +123 -0
  71. package/dist/shader/WebGLShaderUniform.d.ts +52 -0
  72. package/dist/shader/WebGLShaderUniform.js +165 -0
  73. package/dist/shader/fragment/FragmentShaderLibrary.d.ts +18 -0
  74. package/dist/shader/fragment/FragmentShaderLibrary.js +35 -0
  75. package/dist/shader/fragment/FragmentShaderSource.d.ts +29 -0
  76. package/dist/shader/fragment/FragmentShaderSource.js +99 -0
  77. package/dist/shader/fragment/FragmentShaderSourceBlend.d.ts +67 -0
  78. package/dist/shader/fragment/FragmentShaderSourceBlend.js +319 -0
  79. package/dist/shader/fragment/FragmentShaderSourceGradient.d.ts +44 -0
  80. package/dist/shader/fragment/FragmentShaderSourceGradient.js +114 -0
  81. package/dist/shader/fragment/FragmentShaderSourceGradientLUT.d.ts +14 -0
  82. package/dist/shader/fragment/FragmentShaderSourceGradientLUT.js +58 -0
  83. package/dist/shader/fragment/FragmentShaderSourceTexture.d.ts +12 -0
  84. package/dist/shader/fragment/FragmentShaderSourceTexture.js +36 -0
  85. package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.d.ts +12 -0
  86. package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.js +42 -0
  87. package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.d.ts +11 -0
  88. package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.js +35 -0
  89. package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.d.ts +16 -0
  90. package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.js +80 -0
  91. package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.d.ts +15 -0
  92. package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.js +106 -0
  93. package/dist/shader/fragment/filter/FragmentShaderSourceFilter.d.ts +112 -0
  94. package/dist/shader/fragment/filter/FragmentShaderSourceFilter.js +275 -0
  95. package/dist/shader/variants/BlendShaderVariantCollection.d.ts +99 -0
  96. package/dist/shader/variants/BlendShaderVariantCollection.js +239 -0
  97. package/dist/shader/variants/FilterShaderVariantCollection.d.ts +150 -0
  98. package/dist/shader/variants/FilterShaderVariantCollection.js +395 -0
  99. package/dist/shader/variants/GradientLUTShaderVariantCollection.d.ts +49 -0
  100. package/dist/shader/variants/GradientLUTShaderVariantCollection.js +107 -0
  101. package/dist/shader/variants/GradientShapeShaderVariantCollection.d.ts +61 -0
  102. package/dist/shader/variants/GradientShapeShaderVariantCollection.js +196 -0
  103. package/dist/shader/variants/ShapeShaderVariantCollection.d.ts +117 -0
  104. package/dist/shader/variants/ShapeShaderVariantCollection.js +427 -0
  105. package/dist/shader/vertex/VertexShaderLibrary.d.ts +18 -0
  106. package/dist/shader/vertex/VertexShaderLibrary.js +75 -0
  107. package/dist/shader/vertex/VertexShaderSource.d.ts +23 -0
  108. package/dist/shader/vertex/VertexShaderSource.js +92 -0
  109. package/dist/shader/vertex/VertexShaderSourceFill.d.ts +45 -0
  110. package/dist/shader/vertex/VertexShaderSourceFill.js +112 -0
  111. package/dist/shader/vertex/VertexShaderSourceStroke.d.ts +27 -0
  112. package/dist/shader/vertex/VertexShaderSourceStroke.js +149 -0
  113. package/package.json +37 -0
@@ -0,0 +1,395 @@
1
+ import { CanvasToWebGLShader } from "../CanvasToWebGLShader";
2
+ import { VertexShaderSource } from "../vertex/VertexShaderSource";
3
+ import { FragmentShaderSourceFilter } from "../fragment/filter/FragmentShaderSourceFilter";
4
+ import { FragmentShaderSourceBlurFilter } from "../fragment/filter/FragmentShaderSourceBlurFilter";
5
+ import { FragmentShaderSourceColorMatrixFilter } from "../fragment/filter/FragmentShaderSourceColorMatrixFilter";
6
+ import { FragmentShaderSourceConvolutionFilter } from "../fragment/filter/FragmentShaderSourceConvolutionFilter";
7
+ import { FragmentShaderSourceDisplacementMapFilter } from "../fragment/filter/FragmentShaderSourceDisplacementMapFilter";
8
+ import { $Math, $getMap } from "@next2d/share";
9
+ /**
10
+ * @class
11
+ */
12
+ export class FilterShaderVariantCollection {
13
+ /**
14
+ * @param {CanvasToWebGLContext} context
15
+ * @param {WebGL2RenderingContext} gl
16
+ * @constructor
17
+ * @public
18
+ */
19
+ constructor(context, gl) {
20
+ /**
21
+ * @type {CanvasToWebGLContext}
22
+ * @private
23
+ */
24
+ this._$context = context;
25
+ /**
26
+ * @type {WebGL2RenderingContext}
27
+ * @private
28
+ */
29
+ this._$gl = gl;
30
+ /**
31
+ * @type {Map}
32
+ * @private
33
+ */
34
+ this._$collection = $getMap();
35
+ }
36
+ /**
37
+ * @param {number} half_blur
38
+ * @return {CanvasToWebGLShader}
39
+ * @method
40
+ * @public
41
+ */
42
+ getBlurFilterShader(half_blur) {
43
+ const key = `b${half_blur}`;
44
+ if (this._$collection.has(key)) {
45
+ const shader = this._$collection.get(key);
46
+ if (shader) {
47
+ return shader;
48
+ }
49
+ }
50
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceBlurFilter.TEMPLATE(half_blur));
51
+ this._$collection.set(key, shader);
52
+ return shader;
53
+ }
54
+ /**
55
+ * @param {boolean} transforms_base
56
+ * @param {boolean} transforms_blur
57
+ * @param {boolean} is_glow
58
+ * @param {string} type
59
+ * @param {boolean} knockout
60
+ * @param {boolean} applies_strength
61
+ * @param {boolean} is_gradient
62
+ * @return {CanvasToWebGLShader}
63
+ * @method
64
+ * @public
65
+ */
66
+ getBitmapFilterShader(transforms_base, transforms_blur, is_glow, type, knockout, applies_strength, is_gradient) {
67
+ const key1 = transforms_base ? "y" : "n";
68
+ const key2 = transforms_blur ? "y" : "n";
69
+ const key3 = is_glow ? "y" : "n";
70
+ const key4 = knockout ? "y" : "n";
71
+ const key5 = applies_strength ? "y" : "n";
72
+ const key = `f${key1}${key2}${key3}${type}${key4}${key5}`;
73
+ if (this._$collection.has(key)) {
74
+ const shader = this._$collection.get(key);
75
+ if (shader) {
76
+ return shader;
77
+ }
78
+ }
79
+ let texturesLength = 1;
80
+ if (transforms_base) {
81
+ texturesLength++;
82
+ }
83
+ if (is_gradient) {
84
+ texturesLength++;
85
+ }
86
+ let mediumpLength = (transforms_base ? 4 : 0)
87
+ + (transforms_blur ? 4 : 0)
88
+ + (applies_strength ? 1 : 0);
89
+ if (!is_gradient) {
90
+ mediumpLength += is_glow ? 4 : 8;
91
+ }
92
+ mediumpLength = $Math.ceil(mediumpLength / 4);
93
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceFilter.TEMPLATE(texturesLength, mediumpLength, transforms_base, transforms_blur, is_glow, type, knockout, applies_strength, is_gradient));
94
+ this._$collection.set(key, shader);
95
+ return shader;
96
+ }
97
+ /**
98
+ * @return {CanvasToWebGLShader}
99
+ * @method
100
+ * @public
101
+ */
102
+ getColorMatrixFilterShader() {
103
+ const key = "m";
104
+ if (this._$collection.has(key)) {
105
+ const shader = this._$collection.get(key);
106
+ if (shader) {
107
+ return shader;
108
+ }
109
+ }
110
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceColorMatrixFilter.TEMPLATE());
111
+ this._$collection.set(key, shader);
112
+ return shader;
113
+ }
114
+ /**
115
+ * @param {number} x
116
+ * @param {number} y
117
+ * @param {boolean} preserve_alpha
118
+ * @param {boolean} clamp
119
+ * @return {CanvasToWebGLShader}
120
+ * @method
121
+ * @public
122
+ */
123
+ getConvolutionFilterShader(x, y, preserve_alpha, clamp) {
124
+ const key1 = ("0" + x).slice(-2);
125
+ const key2 = ("0" + y).slice(-2);
126
+ const key3 = preserve_alpha ? "y" : "n";
127
+ const key4 = clamp ? "y" : "n";
128
+ const key = `c${key1}${key2}${key3}${key4}`;
129
+ if (this._$collection.has(key)) {
130
+ const shader = this._$collection.get(key);
131
+ if (shader) {
132
+ return shader;
133
+ }
134
+ }
135
+ const mediumpLength = (clamp ? 1 : 2) + $Math.ceil(x * y / 4);
136
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceConvolutionFilter.TEMPLATE(mediumpLength, x, y, preserve_alpha, clamp));
137
+ this._$collection.set(key, shader);
138
+ return shader;
139
+ }
140
+ /**
141
+ * @param {number} component_x
142
+ * @param {number} component_y
143
+ * @param {string} mode
144
+ * @return {CanvasToWebGLShader}
145
+ * @method
146
+ * @public
147
+ */
148
+ getDisplacementMapFilterShader(component_x, component_y, mode) {
149
+ const key = `d${component_x}${component_y}${mode}`;
150
+ if (this._$collection.has(key)) {
151
+ const shader = this._$collection.get(key);
152
+ if (shader) {
153
+ return shader;
154
+ }
155
+ }
156
+ const mediumpLength = mode === "color" ? 3 : 2;
157
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceDisplacementMapFilter.TEMPLATE(mediumpLength, component_x, component_y, mode));
158
+ this._$collection.set(key, shader);
159
+ return shader;
160
+ }
161
+ /**
162
+ * @param {WebGLShaderUniform} uniform
163
+ * @param {number} width
164
+ * @param {number} height
165
+ * @param {boolean} is_horizontal
166
+ * @param {number} fraction
167
+ * @param {number} samples
168
+ * @return {void}
169
+ * @method
170
+ * @public
171
+ */
172
+ setBlurFilterUniform(uniform, width, height, is_horizontal, fraction, samples) {
173
+ const mediump = uniform.mediump;
174
+ // fragment: u_offset
175
+ if (is_horizontal) {
176
+ mediump[0] = 1 / width;
177
+ mediump[1] = 0;
178
+ }
179
+ else {
180
+ mediump[0] = 0;
181
+ mediump[1] = 1 / height;
182
+ }
183
+ // fragment: u_fraction
184
+ mediump[2] = fraction;
185
+ // fragment: u_samples
186
+ mediump[3] = samples;
187
+ }
188
+ /**
189
+ * @param {WebGLShaderUniform} uniform
190
+ * @param {number} width
191
+ * @param {number} height
192
+ * @param {number} base_width
193
+ * @param {number} base_height
194
+ * @param {number} base_offset_x
195
+ * @param {number} base_offset_y
196
+ * @param {number} blur_width
197
+ * @param {number} blur_height
198
+ * @param {number} blur_offset_x
199
+ * @param {number} blur_offset_y
200
+ * @param {boolean} is_glow
201
+ * @param {number} strength
202
+ * @param {number} color_r1
203
+ * @param {number} color_g1
204
+ * @param {number} color_b1
205
+ * @param {number} color_a1
206
+ * @param {number} color_r2
207
+ * @param {number} color_g2
208
+ * @param {number} color_b2
209
+ * @param {number} color_a2
210
+ * @param {boolean} transforms_base
211
+ * @param {boolean} transforms_blur
212
+ * @param {boolean} applies_strength
213
+ * @param {boolean} is_gradient
214
+ * @method
215
+ * @public
216
+ */
217
+ setBitmapFilterUniform(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, transforms_base, transforms_blur, applies_strength, is_gradient) {
218
+ let textures;
219
+ // fragment: u_textures
220
+ if (transforms_base) {
221
+ textures = uniform.textures;
222
+ textures[0] = 0;
223
+ textures[1] = 1;
224
+ if (is_gradient) {
225
+ textures[2] = 2;
226
+ }
227
+ }
228
+ else if (is_gradient) {
229
+ textures = uniform.textures;
230
+ textures[0] = 0;
231
+ textures[1] = 2;
232
+ }
233
+ const mediump = uniform.mediump;
234
+ let i = 0;
235
+ if (transforms_base) {
236
+ // fragment: u_uv_scale
237
+ mediump[i] = width / base_width;
238
+ mediump[i + 1] = height / base_height;
239
+ // fragment: u_uv_offset
240
+ mediump[i + 2] = base_offset_x / base_width;
241
+ mediump[i + 3] = (height - base_height - base_offset_y) / base_height;
242
+ i += 4;
243
+ }
244
+ if (transforms_blur) {
245
+ // fragment: u_st_scale
246
+ mediump[i] = width / blur_width;
247
+ mediump[i + 1] = height / blur_height;
248
+ // fragment: u_st_offset
249
+ mediump[i + 2] = blur_offset_x / blur_width;
250
+ mediump[i + 3] = (height - blur_height - blur_offset_y) / blur_height;
251
+ i += 4;
252
+ }
253
+ if (is_gradient) {
254
+ // do nothing
255
+ }
256
+ else if (is_glow) {
257
+ // fragment: u_color
258
+ mediump[i] = color_r1;
259
+ mediump[i + 1] = color_g1;
260
+ mediump[i + 2] = color_b1;
261
+ mediump[i + 3] = color_a1;
262
+ i += 4;
263
+ }
264
+ else {
265
+ // fragment: u_highlight_color
266
+ mediump[i] = color_r1;
267
+ mediump[i + 1] = color_g1;
268
+ mediump[i + 2] = color_b1;
269
+ mediump[i + 3] = color_a1;
270
+ // fragment: u_shadow_color
271
+ mediump[i + 4] = color_r2;
272
+ mediump[i + 5] = color_g2;
273
+ mediump[i + 6] = color_b2;
274
+ mediump[i + 7] = color_a2;
275
+ i += 8;
276
+ }
277
+ if (applies_strength) {
278
+ // fragment: u_strength
279
+ mediump[i] = strength;
280
+ }
281
+ }
282
+ /**
283
+ * @param {WebGLShaderUniform} uniform
284
+ * @param {array} matrix
285
+ * @return {void}
286
+ * @method
287
+ * @public
288
+ */
289
+ setColorMatrixFilterUniform(uniform, matrix) {
290
+ const mediump = uniform.mediump;
291
+ // fragment: u_mul
292
+ mediump[0] = matrix[0];
293
+ mediump[1] = matrix[1];
294
+ mediump[2] = matrix[2];
295
+ mediump[3] = matrix[3];
296
+ mediump[4] = matrix[5];
297
+ mediump[5] = matrix[6];
298
+ mediump[6] = matrix[7];
299
+ mediump[7] = matrix[8];
300
+ mediump[8] = matrix[10];
301
+ mediump[9] = matrix[11];
302
+ mediump[10] = matrix[12];
303
+ mediump[11] = matrix[13];
304
+ mediump[12] = matrix[15];
305
+ mediump[13] = matrix[16];
306
+ mediump[14] = matrix[17];
307
+ mediump[15] = matrix[18];
308
+ // fragment: u_add
309
+ mediump[16] = matrix[4] / 255;
310
+ mediump[17] = matrix[9] / 255;
311
+ mediump[18] = matrix[14] / 255;
312
+ mediump[19] = matrix[19] / 255;
313
+ }
314
+ /**
315
+ * @param {WebGLShaderUniform} uniform
316
+ * @param {number} width
317
+ * @param {number} height
318
+ * @param {Float32Array} matrix
319
+ * @param {number} divisor
320
+ * @param {number} bias
321
+ * @param {boolean} clamp
322
+ * @param {number} color_r
323
+ * @param {number} color_g
324
+ * @param {number} color_b
325
+ * @param {number} color_a
326
+ * @return {void}
327
+ * @method
328
+ * @public
329
+ */
330
+ setConvolutionFilterUniform(uniform, width, height, matrix, divisor, bias, clamp, color_r, color_g, color_b, color_a) {
331
+ const mediump = uniform.mediump;
332
+ // fragment: u_rcp_size
333
+ mediump[0] = 1 / width;
334
+ mediump[1] = 1 / height;
335
+ // fragment: u_rcp_divisor
336
+ mediump[2] = 1 / divisor;
337
+ // fragment: u_bias
338
+ mediump[3] = bias / 255;
339
+ let i = 4;
340
+ if (!clamp) {
341
+ // fragment: u_substitute_color
342
+ mediump[i] = color_r;
343
+ mediump[i + 1] = color_g;
344
+ mediump[i + 2] = color_b;
345
+ mediump[i + 3] = color_a;
346
+ i += 4;
347
+ }
348
+ // fragment: u_matrix
349
+ const length = matrix.length;
350
+ for (let j = 0; j < length; j++) {
351
+ mediump[i++] = matrix[j];
352
+ }
353
+ }
354
+ /**
355
+ * @param {WebGLShaderUniform} uniform
356
+ * @param {number} map_width
357
+ * @param {number} map_height
358
+ * @param {number} base_width
359
+ * @param {number} base_height
360
+ * @param {number} point_x
361
+ * @param {number} point_y
362
+ * @param {number} scale_x
363
+ * @param {number} scale_y
364
+ * @param {string} mode
365
+ * @param {number} color_r
366
+ * @param {number} color_g
367
+ * @param {number} color_b
368
+ * @param {number} color_a
369
+ * @return {void}
370
+ * @method
371
+ * @public
372
+ */
373
+ setDisplacementMapFilterUniform(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) {
374
+ const textures = uniform.textures;
375
+ textures[0] = 0;
376
+ textures[1] = 1;
377
+ const mediump = uniform.mediump;
378
+ // fragment: u_uv_to_st_scale
379
+ mediump[0] = base_width / map_width;
380
+ mediump[1] = base_height / map_height;
381
+ // fragment: u_uv_to_st_offset
382
+ mediump[2] = point_x / map_width;
383
+ mediump[3] = (base_height - map_height - point_y) / map_height;
384
+ // fragment: u_scale
385
+ mediump[4] = scale_x / base_width;
386
+ mediump[5] = -scale_y / base_height;
387
+ if (mode === "color") {
388
+ // fragment: u_substitute_color
389
+ mediump[8] = color_r;
390
+ mediump[9] = color_g;
391
+ mediump[10] = color_b;
392
+ mediump[11] = color_a;
393
+ }
394
+ }
395
+ }
@@ -0,0 +1,49 @@
1
+ import { CanvasToWebGLShader } from "../CanvasToWebGLShader";
2
+ import type { CanvasToWebGLContext } from "../../CanvasToWebGLContext";
3
+ import type { WebGLShaderUniform } from "../WebGLShaderUniform";
4
+ /**
5
+ * @class
6
+ */
7
+ export declare class GradientLUTShaderVariantCollection {
8
+ private readonly _$context;
9
+ private readonly _$gl;
10
+ private readonly _$collection;
11
+ /**
12
+ * @param {CanvasToWebGLContext} context
13
+ * @param {WebGL2RenderingContext} gl
14
+ * @constructor
15
+ * @public
16
+ */
17
+ constructor(context: CanvasToWebGLContext, gl: WebGL2RenderingContext);
18
+ /**
19
+ * @param {number} stops_length
20
+ * @param {boolean} is_linear_space
21
+ * @return {CanvasToWebGLShader}
22
+ * @method
23
+ * @public
24
+ */
25
+ getGradientLUTShader(stops_length: number, is_linear_space: boolean): CanvasToWebGLShader;
26
+ /**
27
+ * @param {WebGLShaderUniform} uniform
28
+ * @param {array} stops
29
+ * @param {number} begin
30
+ * @param {number} end
31
+ * @param {Float32Array} table
32
+ * @return {void}
33
+ * @method
34
+ * @public
35
+ */
36
+ setGradientLUTUniformForShape(uniform: WebGLShaderUniform, stops: any[], begin: number, end: number, table: Float32Array): void;
37
+ /**
38
+ * @param {WebGLShaderUniform} uniform
39
+ * @param {array} ratios
40
+ * @param {array} colors
41
+ * @param {array} alphas
42
+ * @param {number} begin
43
+ * @param {number} end
44
+ * @return {void}
45
+ * @method
46
+ * @public
47
+ */
48
+ setGradientLUTUniformForFilter(uniform: WebGLShaderUniform, ratios: number[], colors: number[], alphas: number[], begin: number, end: number): void;
49
+ }
@@ -0,0 +1,107 @@
1
+ import { VertexShaderSource } from "../vertex/VertexShaderSource";
2
+ import { FragmentShaderSourceGradientLUT } from "../fragment/FragmentShaderSourceGradientLUT";
3
+ import { CanvasToWebGLShader } from "../CanvasToWebGLShader";
4
+ import { $Math, $getMap } from "@next2d/share";
5
+ /**
6
+ * @class
7
+ */
8
+ export class GradientLUTShaderVariantCollection {
9
+ /**
10
+ * @param {CanvasToWebGLContext} context
11
+ * @param {WebGL2RenderingContext} gl
12
+ * @constructor
13
+ * @public
14
+ */
15
+ constructor(context, gl) {
16
+ /**
17
+ * @type {CanvasToWebGLContext}
18
+ * @private
19
+ */
20
+ this._$context = context;
21
+ /**
22
+ * @type {WebGL2RenderingContext}
23
+ * @private
24
+ */
25
+ this._$gl = gl;
26
+ /**
27
+ * @type {Map}
28
+ * @private
29
+ */
30
+ this._$collection = $getMap();
31
+ }
32
+ /**
33
+ * @param {number} stops_length
34
+ * @param {boolean} is_linear_space
35
+ * @return {CanvasToWebGLShader}
36
+ * @method
37
+ * @public
38
+ */
39
+ getGradientLUTShader(stops_length, is_linear_space) {
40
+ const key1 = ("00" + stops_length).slice(-3);
41
+ const key2 = is_linear_space ? "y" : "n";
42
+ const key = `l${key1}${key2}`;
43
+ if (this._$collection.has(key)) {
44
+ const shader = this._$collection.get(key);
45
+ if (shader) {
46
+ return shader;
47
+ }
48
+ }
49
+ const mediumpLength = $Math.ceil(stops_length * 5 / 4);
50
+ const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.TEXTURE(), FragmentShaderSourceGradientLUT.TEMPLATE(mediumpLength, stops_length, is_linear_space));
51
+ this._$collection.set(key, shader);
52
+ return shader;
53
+ }
54
+ /**
55
+ * @param {WebGLShaderUniform} uniform
56
+ * @param {array} stops
57
+ * @param {number} begin
58
+ * @param {number} end
59
+ * @param {Float32Array} table
60
+ * @return {void}
61
+ * @method
62
+ * @public
63
+ */
64
+ setGradientLUTUniformForShape(uniform, stops, begin, end, table) {
65
+ let i = 0;
66
+ const mediump = uniform.mediump;
67
+ // fragment: u_gradient_color
68
+ for (let j = begin; j < end; j++) {
69
+ const color = stops[j][1];
70
+ mediump[i++] = table[color[0]];
71
+ mediump[i++] = table[color[1]];
72
+ mediump[i++] = table[color[2]];
73
+ mediump[i++] = table[color[3]];
74
+ }
75
+ // fragment: u_gradient_t
76
+ for (let j = begin; j < end; j++) {
77
+ mediump[i++] = stops[j][0];
78
+ }
79
+ }
80
+ /**
81
+ * @param {WebGLShaderUniform} uniform
82
+ * @param {array} ratios
83
+ * @param {array} colors
84
+ * @param {array} alphas
85
+ * @param {number} begin
86
+ * @param {number} end
87
+ * @return {void}
88
+ * @method
89
+ * @public
90
+ */
91
+ setGradientLUTUniformForFilter(uniform, ratios, colors, alphas, begin, end) {
92
+ let i = 0;
93
+ const mediump = uniform.mediump;
94
+ // fragment: u_gradient_color
95
+ for (let j = begin; j < end; j++) {
96
+ const color = colors[j];
97
+ mediump[i++] = (color >> 16) / 255;
98
+ mediump[i++] = (color >> 8 & 0xFF) / 255;
99
+ mediump[i++] = (color & 0xFF) / 255;
100
+ mediump[i++] = alphas[j];
101
+ }
102
+ // fragment: u_gradient_t
103
+ for (let j = begin; j < end; j++) {
104
+ mediump[i++] = ratios[j];
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,61 @@
1
+ import { CanvasToWebGLShader } from "../CanvasToWebGLShader";
2
+ import type { CanvasToWebGLContext } from "../../CanvasToWebGLContext";
3
+ import type { WebGLShaderUniform } from "../WebGLShaderUniform";
4
+ import type { CanvasToWebGLContextGrid } from "../../CanvasToWebGLContextGrid";
5
+ /**
6
+ * @class
7
+ */
8
+ export declare class GradientShapeShaderVariantCollection {
9
+ private readonly _$context;
10
+ private readonly _$gl;
11
+ private readonly _$collection;
12
+ /**
13
+ * @param {CanvasToWebGLContext} context
14
+ * @param {WebGL2RenderingContext} gl
15
+ * @constructor
16
+ * @public
17
+ */
18
+ constructor(context: CanvasToWebGLContext, gl: WebGL2RenderingContext);
19
+ /**
20
+ * @param {boolean} is_stroke
21
+ * @param {boolean} has_grid
22
+ * @param {boolean} is_radial
23
+ * @param {boolean} has_focal_point
24
+ * @param {string} spread_method
25
+ * @return {CanvasToWebGLShader}
26
+ * @method
27
+ * @public
28
+ */
29
+ getGradientShapeShader(is_stroke: boolean, has_grid: boolean, is_radial: boolean, has_focal_point: boolean, spread_method: string): CanvasToWebGLShader;
30
+ /**
31
+ * @param {boolean} is_stroke
32
+ * @param {boolean} has_grid
33
+ * @param {boolean} is_radial
34
+ * @param {boolean} has_focal_point
35
+ * @param {string} spread_method
36
+ * @return {string}
37
+ * @method
38
+ * @private
39
+ */
40
+ createCollectionKey(is_stroke: boolean, has_grid: boolean, is_radial: boolean, has_focal_point: boolean, spread_method: string): string;
41
+ /**
42
+ * @param {WebGLShaderUniform} uniform
43
+ * @param {boolean} is_stroke
44
+ * @param {number} half_width
45
+ * @param {number} face
46
+ * @param {number} miter_limit
47
+ * @param {boolean} has_grid
48
+ * @param {Float32Array} matrix
49
+ * @param {Float32Array} inverse_matrix
50
+ * @param {number} viewport_width
51
+ * @param {number} viewport_height
52
+ * @param {CanvasToWebGLContextGrid} grid
53
+ * @param {boolean} is_radial
54
+ * @param {Float32Array} points
55
+ * @param {number} focal_point_ratio
56
+ * @return {void}
57
+ * @method
58
+ * @public
59
+ */
60
+ setGradientShapeUniform(uniform: WebGLShaderUniform, is_stroke: boolean, half_width: number, face: number, miter_limit: number, has_grid: boolean, matrix: Float32Array, inverse_matrix: Float32Array, viewport_width: number, viewport_height: number, grid: CanvasToWebGLContextGrid, is_radial: boolean, points: Float32Array, focal_point_ratio: number): void;
61
+ }