@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,85 @@
1
+ import { WebGLShaderUniform } from "./WebGLShaderUniform";
2
+ import type { CanvasToWebGLContext } from "../CanvasToWebGLContext";
3
+ /**
4
+ * @class
5
+ */
6
+ export declare class CanvasToWebGLShader {
7
+ private readonly _$gl;
8
+ private readonly _$context;
9
+ private readonly _$program;
10
+ private readonly _$uniform;
11
+ /**
12
+ * @param {WebGL2RenderingContext} gl
13
+ * @param {CanvasToWebGLContext} context
14
+ * @param {string} vertex_source
15
+ * @param {string} fragment_source
16
+ * @constructor
17
+ * @public
18
+ */
19
+ constructor(gl: WebGL2RenderingContext, context: CanvasToWebGLContext, vertex_source: string, fragment_source: string);
20
+ /**
21
+ * @return {WebGLShaderUniform}
22
+ * @readonly
23
+ * @public
24
+ */
25
+ get uniform(): WebGLShaderUniform;
26
+ /**
27
+ * @param {string} vertex_source
28
+ * @param {string} fragment_source
29
+ * @return {WebGLProgram}
30
+ * @method
31
+ * @private
32
+ */
33
+ _$createProgram(vertex_source: string, fragment_source: string): WebGLProgram;
34
+ /**
35
+ * @return {void}
36
+ * @private
37
+ */
38
+ _$attachProgram(): void;
39
+ /**
40
+ * @return {void}
41
+ * @method
42
+ * @public
43
+ */
44
+ _$drawImage(): void;
45
+ /**
46
+ * @param {number} begin
47
+ * @param {number} end
48
+ * @return {void}
49
+ * @method
50
+ * @public
51
+ */
52
+ _$drawGradient(begin: number, end: number): void;
53
+ /**
54
+ * @param {WebGLVertexArrayObject} vertex_array_object
55
+ * @return {void}
56
+ * @method
57
+ * @public
58
+ */
59
+ _$stroke(vertex_array_object: WebGLVertexArrayObject): void;
60
+ /**
61
+ * @param {WebGLVertexArrayObject} vertex_array_object
62
+ * @return {void}
63
+ * @method
64
+ * @public
65
+ */
66
+ _$fill(vertex_array_object: WebGLVertexArrayObject): void;
67
+ /**
68
+ * @param {WebGLVertexArrayObject} vertex_array
69
+ * @param {number} first
70
+ * @param {number} count
71
+ * @return {void}
72
+ * @method
73
+ * @public
74
+ */
75
+ _$containerClip(vertex_array: WebGLVertexArrayObject, first: number, count: number): void;
76
+ /**
77
+ * @param {WebGLVertexArrayObject} vertex_array
78
+ * @param {number} first
79
+ * @param {number} count
80
+ * @return {void}
81
+ * @method
82
+ * @public
83
+ */
84
+ _$drawPoints(vertex_array: WebGLVertexArrayObject, first: number, count: number): void;
85
+ }
@@ -0,0 +1,192 @@
1
+ import { WebGLShaderUniform } from "./WebGLShaderUniform";
2
+ import { $getProgramId } from "@next2d/share";
3
+ /**
4
+ * @class
5
+ */
6
+ export class CanvasToWebGLShader {
7
+ /**
8
+ * @param {WebGL2RenderingContext} gl
9
+ * @param {CanvasToWebGLContext} context
10
+ * @param {string} vertex_source
11
+ * @param {string} fragment_source
12
+ * @constructor
13
+ * @public
14
+ */
15
+ constructor(gl, context, vertex_source, fragment_source) {
16
+ /**
17
+ * @type {WebGL2RenderingContext}
18
+ * @private
19
+ */
20
+ this._$gl = gl;
21
+ /**
22
+ * @type {WebGL2RenderingContext}
23
+ * @private
24
+ */
25
+ this._$context = context;
26
+ /**
27
+ * @type {WebGLProgram}
28
+ * @private
29
+ */
30
+ this._$program = this._$createProgram(vertex_source, fragment_source);
31
+ /**
32
+ * @type {WebGLShaderUniform}
33
+ * @private
34
+ */
35
+ this._$uniform = new WebGLShaderUniform(gl, this._$program);
36
+ }
37
+ /**
38
+ * @return {WebGLShaderUniform}
39
+ * @readonly
40
+ * @public
41
+ */
42
+ get uniform() {
43
+ return this._$uniform;
44
+ }
45
+ /**
46
+ * @param {string} vertex_source
47
+ * @param {string} fragment_source
48
+ * @return {WebGLProgram}
49
+ * @method
50
+ * @private
51
+ */
52
+ _$createProgram(vertex_source, fragment_source) {
53
+ const program = this._$gl.createProgram();
54
+ if (!program) {
55
+ throw new Error("WebGL program error");
56
+ }
57
+ // control number
58
+ program.id = $getProgramId();
59
+ const vertexShader = this._$gl.createShader(this._$gl.VERTEX_SHADER);
60
+ if (!vertexShader) {
61
+ throw new Error("WebGL vertex shader error");
62
+ }
63
+ this._$gl.shaderSource(vertexShader, vertex_source);
64
+ this._$gl.compileShader(vertexShader);
65
+ const fragmentShader = this._$gl.createShader(this._$gl.FRAGMENT_SHADER);
66
+ if (!fragmentShader) {
67
+ throw new Error("WebGL fragment shader error");
68
+ }
69
+ this._$gl.shaderSource(fragmentShader, fragment_source);
70
+ this._$gl.compileShader(fragmentShader);
71
+ this._$gl.attachShader(program, vertexShader);
72
+ this._$gl.attachShader(program, fragmentShader);
73
+ this._$gl.linkProgram(program);
74
+ this._$gl.detachShader(program, vertexShader);
75
+ this._$gl.detachShader(program, fragmentShader);
76
+ this._$gl.deleteShader(vertexShader);
77
+ this._$gl.deleteShader(fragmentShader);
78
+ return program;
79
+ }
80
+ /**
81
+ * @return {void}
82
+ * @private
83
+ */
84
+ _$attachProgram() {
85
+ const shaderList = this._$context.shaderList;
86
+ if (shaderList.currentProgramId !== this._$program.id) {
87
+ shaderList.currentProgramId = this._$program.id;
88
+ this._$gl.useProgram(this._$program);
89
+ }
90
+ }
91
+ /**
92
+ * @return {void}
93
+ * @method
94
+ * @public
95
+ */
96
+ _$drawImage() {
97
+ this._$attachProgram();
98
+ this._$uniform.bindUniforms();
99
+ this._$context.vao.bindCommonVertexArray();
100
+ this._$gl.drawArrays(this._$gl.TRIANGLE_STRIP, 0, 4);
101
+ }
102
+ /**
103
+ * @param {number} begin
104
+ * @param {number} end
105
+ * @return {void}
106
+ * @method
107
+ * @public
108
+ */
109
+ _$drawGradient(begin, end) {
110
+ this._$attachProgram();
111
+ this._$uniform.bindUniforms();
112
+ this._$context.vao.bindGradientVertexArray(begin, end);
113
+ this._$gl.drawArrays(this._$gl.TRIANGLE_STRIP, 0, 4);
114
+ }
115
+ /**
116
+ * @param {WebGLVertexArrayObject} vertex_array_object
117
+ * @return {void}
118
+ * @method
119
+ * @public
120
+ */
121
+ _$stroke(vertex_array_object) {
122
+ // setup
123
+ this._$attachProgram();
124
+ // set alpha
125
+ this._$context.blend.reset();
126
+ // update data
127
+ this._$uniform.bindUniforms();
128
+ // bind vertex array
129
+ this._$context.vao.bind(vertex_array_object);
130
+ // draw
131
+ this._$gl.drawElements(this._$gl.TRIANGLES, vertex_array_object.indexCount, this._$gl.UNSIGNED_SHORT, 0);
132
+ }
133
+ /**
134
+ * @param {WebGLVertexArrayObject} vertex_array_object
135
+ * @return {void}
136
+ * @method
137
+ * @public
138
+ */
139
+ _$fill(vertex_array_object) {
140
+ // setup
141
+ this._$attachProgram();
142
+ // set alpha
143
+ this._$context.blend.reset();
144
+ // update data
145
+ this._$uniform.bindUniforms();
146
+ // bind vertex array
147
+ this._$context.vao.bind(vertex_array_object);
148
+ // draw fill
149
+ const indexRanges = vertex_array_object.indexRanges;
150
+ const range = indexRanges[indexRanges.length - 1];
151
+ const count = range.first + range.count;
152
+ this._$gl.drawArrays(this._$gl.TRIANGLES, 0, count);
153
+ }
154
+ /**
155
+ * @param {WebGLVertexArrayObject} vertex_array
156
+ * @param {number} first
157
+ * @param {number} count
158
+ * @return {void}
159
+ * @method
160
+ * @public
161
+ */
162
+ _$containerClip(vertex_array, first, count) {
163
+ // setup
164
+ this._$attachProgram();
165
+ // set alpha
166
+ this._$context.blend.reset();
167
+ // update data
168
+ this._$uniform.bindUniforms();
169
+ // bind vertex array
170
+ this._$context.vao.bind(vertex_array);
171
+ // draw fill
172
+ this._$gl.drawArrays(this._$gl.TRIANGLES, first, count);
173
+ }
174
+ /**
175
+ * @param {WebGLVertexArrayObject} vertex_array
176
+ * @param {number} first
177
+ * @param {number} count
178
+ * @return {void}
179
+ * @method
180
+ * @public
181
+ */
182
+ _$drawPoints(vertex_array, first, count) {
183
+ // setup
184
+ this._$attachProgram();
185
+ // update data
186
+ this._$uniform.bindUniforms();
187
+ // bind vertex array
188
+ this._$context.vao.bind(vertex_array);
189
+ // draw fill
190
+ this._$gl.drawArrays(this._$gl.POINTS, first, count);
191
+ }
192
+ }
@@ -0,0 +1,70 @@
1
+ import { ShapeShaderVariantCollection } from "./variants/ShapeShaderVariantCollection";
2
+ import { GradientShapeShaderVariantCollection } from "./variants/GradientShapeShaderVariantCollection";
3
+ import { GradientLUTShaderVariantCollection } from "./variants/GradientLUTShaderVariantCollection";
4
+ import { FilterShaderVariantCollection } from "./variants/FilterShaderVariantCollection";
5
+ import { BlendShaderVariantCollection } from "./variants/BlendShaderVariantCollection";
6
+ import type { CanvasToWebGLContext } from "../CanvasToWebGLContext";
7
+ /**
8
+ * @class
9
+ */
10
+ export declare class CanvasToWebGLShaderList {
11
+ private _$currentProgramId;
12
+ private readonly _$shapeShaderVariants;
13
+ private readonly _$gradientShapeShaderVariants;
14
+ private readonly _$gradientLUTShaderVariants;
15
+ private readonly _$filterShaderVariants;
16
+ private readonly _$blendShaderVariants;
17
+ /**
18
+ * @param {CanvasToWebGLContext} context
19
+ * @param {WebGL2RenderingContext} gl
20
+ * @constructor
21
+ * @public
22
+ */
23
+ constructor(context: CanvasToWebGLContext, gl: WebGL2RenderingContext);
24
+ /**
25
+ * @member {number}
26
+ * @public
27
+ */
28
+ get currentProgramId(): number;
29
+ set currentProgramId(current_program_id: number);
30
+ /**
31
+ * @memberof CanvasToWebGLShaderList#
32
+ * @property {ShapeShaderVariantCollection} shapeShaderVariants
33
+ * @return {ShapeShaderVariantCollection}
34
+ * @readonly
35
+ * @public
36
+ */
37
+ get shapeShaderVariants(): ShapeShaderVariantCollection;
38
+ /**
39
+ * @memberof CanvasToWebGLShaderList#
40
+ * @property {GradientShapeShaderVariantCollection} gradientShapeShaderVariants
41
+ * @return {GradientShapeShaderVariantCollection}
42
+ * @readonly
43
+ * @public
44
+ */
45
+ get gradientShapeShaderVariants(): GradientShapeShaderVariantCollection;
46
+ /**
47
+ * @memberof CanvasToWebGLShaderList#
48
+ * @property {GradientLUTShaderVariantCollection} gradientLUTShaderVariants
49
+ * @return {GradientLUTShaderVariantCollection}
50
+ * @readonly
51
+ * @public
52
+ */
53
+ get gradientLUTShaderVariants(): GradientLUTShaderVariantCollection;
54
+ /**
55
+ * @memberof CanvasToWebGLShaderList#
56
+ * @property {FilterShaderVariantCollection} filterShaderVariants
57
+ * @return {FilterShaderVariantCollection}
58
+ * @readonly
59
+ * @public
60
+ */
61
+ get filterShaderVariants(): FilterShaderVariantCollection;
62
+ /**
63
+ * @memberof CanvasToWebGLShaderList#
64
+ * @property {BlendShaderVariantCollection} blendShaderVariants
65
+ * @return {BlendShaderVariantCollection}
66
+ * @readonly
67
+ * @public
68
+ */
69
+ get blendShaderVariants(): BlendShaderVariantCollection;
70
+ }
@@ -0,0 +1,109 @@
1
+ import { ShapeShaderVariantCollection } from "./variants/ShapeShaderVariantCollection";
2
+ import { GradientShapeShaderVariantCollection } from "./variants/GradientShapeShaderVariantCollection";
3
+ import { GradientLUTShaderVariantCollection } from "./variants/GradientLUTShaderVariantCollection";
4
+ import { FilterShaderVariantCollection } from "./variants/FilterShaderVariantCollection";
5
+ import { BlendShaderVariantCollection } from "./variants/BlendShaderVariantCollection";
6
+ /**
7
+ * @class
8
+ */
9
+ export class CanvasToWebGLShaderList {
10
+ /**
11
+ * @param {CanvasToWebGLContext} context
12
+ * @param {WebGL2RenderingContext} gl
13
+ * @constructor
14
+ * @public
15
+ */
16
+ constructor(context, gl) {
17
+ /**
18
+ * @type {number}
19
+ * @default -1
20
+ * @public
21
+ */
22
+ this._$currentProgramId = -1;
23
+ /**
24
+ * @type {ShapeShaderVariantCollection}
25
+ * @private
26
+ */
27
+ this._$shapeShaderVariants = new ShapeShaderVariantCollection(context, gl);
28
+ /**
29
+ * @type {GradientShapeShaderVariantCollection}
30
+ * @private
31
+ */
32
+ this._$gradientShapeShaderVariants = new GradientShapeShaderVariantCollection(context, gl);
33
+ /**
34
+ * @type {GradientLUTShaderVariantCollection}
35
+ * @private
36
+ */
37
+ this._$gradientLUTShaderVariants = new GradientLUTShaderVariantCollection(context, gl);
38
+ /**
39
+ * @type {FilterShaderVariantCollection}
40
+ * @private
41
+ */
42
+ this._$filterShaderVariants = new FilterShaderVariantCollection(context, gl);
43
+ /**
44
+ * @type {BlendShaderVariantCollection}
45
+ * @private
46
+ */
47
+ this._$blendShaderVariants = new BlendShaderVariantCollection(context, gl);
48
+ }
49
+ /**
50
+ * @member {number}
51
+ * @public
52
+ */
53
+ get currentProgramId() {
54
+ return this._$currentProgramId;
55
+ }
56
+ set currentProgramId(current_program_id) {
57
+ this._$currentProgramId = current_program_id;
58
+ }
59
+ /**
60
+ * @memberof CanvasToWebGLShaderList#
61
+ * @property {ShapeShaderVariantCollection} shapeShaderVariants
62
+ * @return {ShapeShaderVariantCollection}
63
+ * @readonly
64
+ * @public
65
+ */
66
+ get shapeShaderVariants() {
67
+ return this._$shapeShaderVariants;
68
+ }
69
+ /**
70
+ * @memberof CanvasToWebGLShaderList#
71
+ * @property {GradientShapeShaderVariantCollection} gradientShapeShaderVariants
72
+ * @return {GradientShapeShaderVariantCollection}
73
+ * @readonly
74
+ * @public
75
+ */
76
+ get gradientShapeShaderVariants() {
77
+ return this._$gradientShapeShaderVariants;
78
+ }
79
+ /**
80
+ * @memberof CanvasToWebGLShaderList#
81
+ * @property {GradientLUTShaderVariantCollection} gradientLUTShaderVariants
82
+ * @return {GradientLUTShaderVariantCollection}
83
+ * @readonly
84
+ * @public
85
+ */
86
+ get gradientLUTShaderVariants() {
87
+ return this._$gradientLUTShaderVariants;
88
+ }
89
+ /**
90
+ * @memberof CanvasToWebGLShaderList#
91
+ * @property {FilterShaderVariantCollection} filterShaderVariants
92
+ * @return {FilterShaderVariantCollection}
93
+ * @readonly
94
+ * @public
95
+ */
96
+ get filterShaderVariants() {
97
+ return this._$filterShaderVariants;
98
+ }
99
+ /**
100
+ * @memberof CanvasToWebGLShaderList#
101
+ * @property {BlendShaderVariantCollection} blendShaderVariants
102
+ * @return {BlendShaderVariantCollection}
103
+ * @readonly
104
+ * @public
105
+ */
106
+ get blendShaderVariants() {
107
+ return this._$blendShaderVariants;
108
+ }
109
+ }
@@ -0,0 +1,36 @@
1
+ import type { CanvasToWebGLContext } from "../CanvasToWebGLContext";
2
+ /**
3
+ * @class
4
+ */
5
+ export declare class GradientLUTGenerator {
6
+ private readonly _$context;
7
+ private readonly _$gl;
8
+ private readonly _$attachment;
9
+ private readonly _$maxLength;
10
+ private readonly _$rgbToLinearTable;
11
+ private readonly _$rgbIdentityTable;
12
+ /**
13
+ * @param {CanvasToWebGLContext} context
14
+ * @param {WebGL2RenderingContext} gl
15
+ * @constructor
16
+ * @public
17
+ */
18
+ constructor(context: CanvasToWebGLContext, gl: WebGL2RenderingContext);
19
+ /**
20
+ * @param {array} stops
21
+ * @param {boolean} is_linear_space
22
+ * @return {WebGLTexture|null}
23
+ * @method
24
+ * @public
25
+ */
26
+ generateForShape(stops: any[], is_linear_space: boolean): WebGLTexture;
27
+ /**
28
+ * @param {array} ratios
29
+ * @param {array} colors
30
+ * @param {array} alphas
31
+ * @return {WebGLTexture}
32
+ * @method
33
+ * @public
34
+ */
35
+ generateForFilter(ratios: number[], colors: number[], alphas: number[]): WebGLTexture;
36
+ }
@@ -0,0 +1,123 @@
1
+ import { $Math } from "@next2d/share";
2
+ /**
3
+ * @class
4
+ */
5
+ export class GradientLUTGenerator {
6
+ /**
7
+ * @param {CanvasToWebGLContext} context
8
+ * @param {WebGL2RenderingContext} gl
9
+ * @constructor
10
+ * @public
11
+ */
12
+ constructor(context, gl) {
13
+ /**
14
+ * @type {CanvasToWebGLContext}
15
+ * @private
16
+ */
17
+ this._$context = context;
18
+ /**
19
+ * @type {WebGL2RenderingContext}
20
+ * @private
21
+ */
22
+ this._$gl = gl;
23
+ /**
24
+ * @type {AttachmentImpl}
25
+ * @private
26
+ */
27
+ this._$attachment = context
28
+ .frameBuffer
29
+ .createTextureAttachment(512, 1);
30
+ /**
31
+ * @type {number}
32
+ * @private
33
+ */
34
+ this._$maxLength = $Math.floor(gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS) * 0.75);
35
+ /**
36
+ * @type {Float32Array}
37
+ * @private
38
+ */
39
+ this._$rgbToLinearTable = new Float32Array(256);
40
+ /**
41
+ * @type {Float32Array}
42
+ * @private
43
+ */
44
+ this._$rgbIdentityTable = new Float32Array(256);
45
+ for (let i = 0; i < 256; i++) {
46
+ const t = i / 255;
47
+ this._$rgbToLinearTable[i] = $Math.pow(t, 2.23333333);
48
+ this._$rgbIdentityTable[i] = t;
49
+ }
50
+ }
51
+ /**
52
+ * @param {array} stops
53
+ * @param {boolean} is_linear_space
54
+ * @return {WebGLTexture|null}
55
+ * @method
56
+ * @public
57
+ */
58
+ generateForShape(stops, is_linear_space) {
59
+ const currentAttachment = this
60
+ ._$context
61
+ .frameBuffer
62
+ .currentAttachment;
63
+ this._$context._$bind(this._$attachment);
64
+ const stopsLength = stops.length;
65
+ const variants = this
66
+ ._$context
67
+ .shaderList
68
+ .gradientLUTShaderVariants;
69
+ const table = is_linear_space
70
+ ? this._$rgbToLinearTable
71
+ : this._$rgbIdentityTable;
72
+ this._$context.blend.toOneZero();
73
+ for (let begin = 0; begin < stopsLength; begin += this._$maxLength - 1) {
74
+ const end = $Math.min(begin + this._$maxLength, stopsLength);
75
+ const shader = variants
76
+ .getGradientLUTShader(end - begin, is_linear_space);
77
+ const uniform = shader.uniform;
78
+ variants
79
+ .setGradientLUTUniformForShape(uniform, stops, begin, end, table);
80
+ shader._$drawGradient(begin === 0 ? 0 : stops[begin][0], end === stopsLength ? 1 : stops[end - 1][0]);
81
+ }
82
+ this._$context._$bind(currentAttachment);
83
+ if (!this._$attachment.texture) {
84
+ throw new Error("the texture is null.");
85
+ }
86
+ return this._$attachment.texture;
87
+ }
88
+ /**
89
+ * @param {array} ratios
90
+ * @param {array} colors
91
+ * @param {array} alphas
92
+ * @return {WebGLTexture}
93
+ * @method
94
+ * @public
95
+ */
96
+ generateForFilter(ratios, colors, alphas) {
97
+ const currentAttachment = this
98
+ ._$context
99
+ .frameBuffer
100
+ .currentAttachment;
101
+ this._$context._$bind(this._$attachment);
102
+ const stopsLength = ratios.length;
103
+ const variants = this
104
+ ._$context
105
+ .shaderList
106
+ .gradientLUTShaderVariants;
107
+ this._$context.blend.toOneZero();
108
+ for (let begin = 0; begin < stopsLength; begin += this._$maxLength - 1) {
109
+ const end = $Math.min(begin + this._$maxLength, stopsLength);
110
+ const shader = variants
111
+ .getGradientLUTShader(end - begin, false);
112
+ const uniform = shader.uniform;
113
+ variants
114
+ .setGradientLUTUniformForFilter(uniform, ratios, colors, alphas, begin, end);
115
+ shader._$drawGradient(begin === 0 ? 0 : ratios[begin], end === stopsLength ? 1 : ratios[end - 1]);
116
+ }
117
+ this._$context._$bind(currentAttachment);
118
+ if (!this._$attachment.texture) {
119
+ throw new Error("the texture is null.");
120
+ }
121
+ return this._$attachment.texture;
122
+ }
123
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @class
3
+ */
4
+ export declare class WebGLShaderUniform {
5
+ private readonly _$gl;
6
+ private readonly _$array;
7
+ private readonly _$map;
8
+ /**
9
+ * @param {WebGL2RenderingContext} gl
10
+ * @param {WebGLProgram} program
11
+ * @constructor
12
+ * @public
13
+ */
14
+ constructor(gl: WebGL2RenderingContext, program: WebGLProgram);
15
+ /**
16
+ * @param {string} name
17
+ * @return {Int32Array|Float32Array}
18
+ * @method
19
+ * @public
20
+ */
21
+ getArray(name: string): Int32Array | Float32Array;
22
+ /**
23
+ * @member {Int32Array|Float32Array}
24
+ * @readonly
25
+ * @public
26
+ */
27
+ get textures(): Int32Array | Float32Array;
28
+ /**
29
+ * @member {Int32Array|Float32Array}
30
+ * @readonly
31
+ * @public
32
+ */
33
+ get highp(): Int32Array | Float32Array;
34
+ /**
35
+ * @member {Int32Array|Float32Array}
36
+ * @readonly
37
+ * @public
38
+ */
39
+ get mediump(): Int32Array | Float32Array;
40
+ /**
41
+ * @member {Int32Array|Float32Array}
42
+ * @readonly
43
+ * @public
44
+ */
45
+ get integer(): Int32Array | Float32Array;
46
+ /**
47
+ * @return {void}
48
+ * @method
49
+ * @public
50
+ */
51
+ bindUniforms(): void;
52
+ }