@next2d/webgl 1.15.0 → 1.17.0

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 (41) hide show
  1. package/dist/CanvasPatternToWebGL.d.ts +0 -6
  2. package/dist/CanvasPatternToWebGL.js +0 -11
  3. package/dist/CanvasToWebGLContext.d.ts +90 -31
  4. package/dist/CanvasToWebGLContext.js +244 -71
  5. package/dist/CanvasToWebGLContextBlend.d.ts +79 -1
  6. package/dist/CanvasToWebGLContextBlend.js +197 -13
  7. package/dist/CanvasToWebGLContextMask.d.ts +0 -6
  8. package/dist/CanvasToWebGLContextMask.js +1 -26
  9. package/dist/CanvasToWebGLContextStyle.js +0 -2
  10. package/dist/Const.d.ts +12 -0
  11. package/dist/Const.js +14 -0
  12. package/dist/FrameBufferManager.d.ts +42 -3
  13. package/dist/FrameBufferManager.js +109 -0
  14. package/dist/TextureManager.d.ts +54 -4
  15. package/dist/TextureManager.js +239 -4
  16. package/dist/VertexArrayObjectManager.d.ts +19 -0
  17. package/dist/VertexArrayObjectManager.js +69 -18
  18. package/dist/interface/BlendModeImpl.d.ts +1 -0
  19. package/dist/interface/BlendModeImpl.js +1 -0
  20. package/dist/interface/CachePositionImpl.d.ts +11 -0
  21. package/dist/interface/CachePositionImpl.js +1 -0
  22. package/dist/interface/PointImpl.d.ts +4 -0
  23. package/dist/interface/PointImpl.js +1 -0
  24. package/dist/shader/CanvasToWebGLShader.d.ts +18 -4
  25. package/dist/shader/CanvasToWebGLShader.js +36 -15
  26. package/dist/shader/GradientLUTGenerator.js +7 -0
  27. package/dist/shader/WebGLShaderInstance.d.ts +30 -0
  28. package/dist/shader/WebGLShaderInstance.js +48 -0
  29. package/dist/shader/WebGLShaderUniform.js +0 -6
  30. package/dist/shader/fragment/FragmentShaderLibrary.d.ts +6 -0
  31. package/dist/shader/fragment/FragmentShaderLibrary.js +13 -4
  32. package/dist/shader/fragment/FragmentShaderSourceBlend.d.ts +8 -0
  33. package/dist/shader/fragment/FragmentShaderSourceBlend.js +65 -0
  34. package/dist/shader/fragment/FragmentShaderSourceTexture.d.ts +6 -0
  35. package/dist/shader/fragment/FragmentShaderSourceTexture.js +32 -0
  36. package/dist/shader/variants/BlendShaderVariantCollection.d.ts +60 -0
  37. package/dist/shader/variants/BlendShaderVariantCollection.js +137 -0
  38. package/dist/shader/vertex/VertexShaderSource.d.ts +12 -0
  39. package/dist/shader/vertex/VertexShaderSource.js +72 -0
  40. package/dist/shader/vertex/VertexShaderSourceFill.js +8 -4
  41. package/package.json +2 -2
@@ -1,20 +1,70 @@
1
+ import type { CachePositionImpl } from "./interface/CachePositionImpl";
2
+ import type { GridImpl } from "./interface/GridImpl";
1
3
  /**
2
4
  * @class
3
5
  */
4
6
  export declare class TextureManager {
7
+ _$maxWidth: number;
8
+ _$maxHeight: number;
9
+ private _$objectPoolArea;
10
+ private _$activeTexture;
5
11
  private readonly _$gl;
6
12
  private readonly _$objectPool;
7
13
  private readonly _$boundTextures;
8
- private _$objectPoolArea;
9
- private _$activeTexture;
10
- _$maxWidth: number;
11
- _$maxHeight: number;
14
+ private readonly _$atlasNodes;
15
+ private readonly _$atlasTextures;
16
+ private readonly _$positionObjectArray;
17
+ private readonly _$nodeObjectArray;
18
+ private readonly _$atlasCacheMap;
12
19
  /**
13
20
  * @param {WebGL2RenderingContext} gl
14
21
  * @constructor
15
22
  * @public
16
23
  */
17
24
  constructor(gl: WebGL2RenderingContext);
25
+ /**
26
+ * @return {void}
27
+ * @method
28
+ * @public
29
+ */
30
+ createTextureAtlas(): void;
31
+ /**
32
+ * @param {number} index
33
+ * @return {WebGLTexture}
34
+ * @method
35
+ * @public
36
+ */
37
+ getAtlasTexture(index: number): WebGLTexture;
38
+ /**
39
+ * @param {number} x
40
+ * @param {number} y
41
+ * @param {number} w
42
+ * @param {number} h
43
+ * @return {object}
44
+ * @method
45
+ * @public
46
+ */
47
+ getNode(x: number, y: number, w: number, h: number): GridImpl;
48
+ /**
49
+ * @param {number} width
50
+ * @param {number} height
51
+ * @return {object}
52
+ * @method
53
+ * @public
54
+ */
55
+ createCachePosition(width: number, height: number): CachePositionImpl;
56
+ /**
57
+ * @param {object}
58
+ * @method
59
+ * @public
60
+ */
61
+ releasePosition(position: CachePositionImpl): void;
62
+ /**
63
+ * @return {void}
64
+ * @method
65
+ * @private
66
+ */
67
+ clearCache(): void;
18
68
  /**
19
69
  * @param {number} width
20
70
  * @param {number} height
@@ -1,3 +1,4 @@
1
+ import { $RENDER_SIZE } from "./Const";
1
2
  /**
2
3
  * @class
3
4
  */
@@ -8,6 +9,9 @@ export class TextureManager {
8
9
  * @public
9
10
  */
10
11
  constructor(gl) {
12
+ // init setting
13
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
14
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
11
15
  /**
12
16
  * @type {WebGL2RenderingContext}
13
17
  * @private
@@ -47,8 +51,241 @@ export class TextureManager {
47
51
  * @private
48
52
  */
49
53
  this._$maxHeight = 0;
50
- this._$gl.pixelStorei(this._$gl.UNPACK_ALIGNMENT, 1);
51
- this._$gl.pixelStorei(this._$gl.UNPACK_FLIP_Y_WEBGL, true);
54
+ /**
55
+ * @type {array}
56
+ * @private
57
+ */
58
+ this._$atlasTextures = [];
59
+ /**
60
+ * @type {array}
61
+ * @private
62
+ */
63
+ this._$atlasCacheMap = new Map();
64
+ /**
65
+ * @type {array}
66
+ * @private
67
+ */
68
+ this._$positionObjectArray = [];
69
+ /**
70
+ * @type {array}
71
+ * @private
72
+ */
73
+ this._$nodeObjectArray = [];
74
+ /**
75
+ * @type {array}
76
+ * @private
77
+ */
78
+ this._$atlasNodes = new Map();
79
+ }
80
+ /**
81
+ * @return {void}
82
+ * @method
83
+ * @public
84
+ */
85
+ createTextureAtlas() {
86
+ const texture = this._$gl.createTexture();
87
+ texture.width = $RENDER_SIZE;
88
+ texture.height = $RENDER_SIZE;
89
+ this._$gl.activeTexture(this._$gl.TEXTURE3);
90
+ this._$gl.bindTexture(this._$gl.TEXTURE_2D, texture);
91
+ this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_S, this._$gl.CLAMP_TO_EDGE);
92
+ this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_T, this._$gl.CLAMP_TO_EDGE);
93
+ this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_MIN_FILTER, this._$gl.NEAREST);
94
+ this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_MAG_FILTER, this._$gl.NEAREST);
95
+ this._$gl.texStorage2D(this._$gl.TEXTURE_2D, 1, this._$gl.RGBA8, $RENDER_SIZE, $RENDER_SIZE);
96
+ this._$gl.bindTexture(this._$gl.TEXTURE_2D, null);
97
+ if (this._$activeTexture > -1) {
98
+ this._$gl.activeTexture(this._$activeTexture);
99
+ }
100
+ // init array
101
+ const index = this._$atlasTextures.length;
102
+ this._$atlasNodes.set(index, []);
103
+ this._$atlasCacheMap.set(index, []);
104
+ this._$atlasTextures.push(texture);
105
+ }
106
+ /**
107
+ * @param {number} index
108
+ * @return {WebGLTexture}
109
+ * @method
110
+ * @public
111
+ */
112
+ getAtlasTexture(index) {
113
+ return this._$atlasTextures[index];
114
+ }
115
+ /**
116
+ * @param {number} x
117
+ * @param {number} y
118
+ * @param {number} w
119
+ * @param {number} h
120
+ * @return {object}
121
+ * @method
122
+ * @public
123
+ */
124
+ getNode(x, y, w, h) {
125
+ const node = this._$nodeObjectArray.length
126
+ ? this._$nodeObjectArray.pop()
127
+ : {
128
+ "x": 0,
129
+ "y": 0,
130
+ "w": 0,
131
+ "h": 0
132
+ };
133
+ node.x = x;
134
+ node.y = y;
135
+ node.w = w;
136
+ node.h = h;
137
+ return node;
138
+ }
139
+ /**
140
+ * @param {number} width
141
+ * @param {number} height
142
+ * @return {object}
143
+ * @method
144
+ * @public
145
+ */
146
+ createCachePosition(width, height) {
147
+ const object = this._$positionObjectArray.length
148
+ ? this._$positionObjectArray.pop()
149
+ : {
150
+ "index": 0,
151
+ "x": 0,
152
+ "y": 0,
153
+ "w": 0,
154
+ "h": 0
155
+ };
156
+ // init
157
+ object.x = object.y = 0;
158
+ object.w = width;
159
+ object.h = height;
160
+ // search
161
+ for (const [index, nodes] of this._$atlasNodes) {
162
+ // root node
163
+ if (!nodes.length) {
164
+ if (width > height) {
165
+ if ($RENDER_SIZE - width - 1 > 0) {
166
+ nodes.push(this.getNode(width + 1, 0, $RENDER_SIZE - width - 1, height));
167
+ }
168
+ if ($RENDER_SIZE - height - 1 > 0) {
169
+ nodes.push(this.getNode(0, height + 1, $RENDER_SIZE, $RENDER_SIZE - height - 1));
170
+ }
171
+ }
172
+ else {
173
+ if ($RENDER_SIZE - height - 1 > 0) {
174
+ nodes.push(this.getNode(0, height + 1, width, $RENDER_SIZE - height - 1));
175
+ }
176
+ if ($RENDER_SIZE - width - 1 > 0) {
177
+ nodes.push(this.getNode(width + 1, 0, $RENDER_SIZE - width - 1, $RENDER_SIZE));
178
+ }
179
+ }
180
+ object.index = index;
181
+ const caches = this._$atlasCacheMap.get(object.index);
182
+ caches.push(object);
183
+ return object;
184
+ }
185
+ const length = nodes.length;
186
+ for (let idx = 0; idx < length; ++idx) {
187
+ const node = nodes[idx];
188
+ // no hit
189
+ if (width > node.w || height > node.h) {
190
+ continue;
191
+ }
192
+ object.index = index;
193
+ object.x = node.x;
194
+ object.y = node.y;
195
+ const caches = this._$atlasCacheMap.get(object.index);
196
+ caches.push(object);
197
+ // division
198
+ if (node.w !== width || node.h !== height) {
199
+ if (width > height) {
200
+ if (node.h - height - 1 > 0) {
201
+ nodes.push(this.getNode(node.x, node.y + height + 1, node.w, node.h - height - 1));
202
+ }
203
+ if (node.w - width - 1 > 0) {
204
+ node.x = node.x + width + 1;
205
+ node.w = node.w - width - 1;
206
+ node.h = height;
207
+ }
208
+ else {
209
+ nodes.splice(idx, 1);
210
+ this._$nodeObjectArray.push(node);
211
+ }
212
+ }
213
+ else {
214
+ if (node.w - width - 1 > 0) {
215
+ nodes.push(this.getNode(node.x + width + 1, node.y, node.w - width - 1, node.h));
216
+ }
217
+ if (node.h - height - 1 > 0) {
218
+ node.y = node.y + height + 1;
219
+ node.w = width;
220
+ node.h = node.h - height - 1;
221
+ }
222
+ else {
223
+ nodes.splice(idx, 1);
224
+ this._$nodeObjectArray.push(node);
225
+ }
226
+ }
227
+ }
228
+ else {
229
+ nodes.splice(idx, 1);
230
+ this._$nodeObjectArray.push(node);
231
+ }
232
+ return object;
233
+ }
234
+ }
235
+ // ヒットしない場合は新しいtextureを生成
236
+ const index = this._$atlasTextures.length;
237
+ this.createTextureAtlas();
238
+ const nodes = this._$atlasNodes.get(index);
239
+ if (width > height) {
240
+ if ($RENDER_SIZE - width - 1 > 0) {
241
+ nodes.push(this.getNode(width + 1, 0, $RENDER_SIZE - width - 1, height));
242
+ }
243
+ if ($RENDER_SIZE - height - 1 > 0) {
244
+ nodes.push(this.getNode(0, height + 1, $RENDER_SIZE, $RENDER_SIZE - height - 1));
245
+ }
246
+ }
247
+ else {
248
+ if ($RENDER_SIZE - height - 1 > 0) {
249
+ nodes.push(this.getNode(0, height + 1, width, $RENDER_SIZE - height - 1));
250
+ }
251
+ if ($RENDER_SIZE - width - 1 > 0) {
252
+ nodes.push(this.getNode(width + 1, 0, $RENDER_SIZE - width - 1, $RENDER_SIZE));
253
+ }
254
+ }
255
+ object.index = index;
256
+ const caches = this._$atlasCacheMap.get(object.index);
257
+ caches.push(object);
258
+ return object;
259
+ }
260
+ /**
261
+ * @param {object}
262
+ * @method
263
+ * @public
264
+ */
265
+ releasePosition(position) {
266
+ var _a;
267
+ if (!this._$atlasNodes.has(position.index)) {
268
+ return;
269
+ }
270
+ // 先頭にrootとして再登録
271
+ (_a = this
272
+ ._$atlasNodes
273
+ .get(position.index)) === null || _a === void 0 ? void 0 : _a.unshift(this.getNode(position.x, position.y, position.w, position.h));
274
+ // pool
275
+ this._$positionObjectArray.push(position);
276
+ }
277
+ /**
278
+ * @return {void}
279
+ * @method
280
+ * @private
281
+ */
282
+ clearCache() {
283
+ for (const caches of this._$atlasCacheMap.values()) {
284
+ caches.length = 0;
285
+ }
286
+ for (const caches of this._$atlasNodes.values()) {
287
+ caches.length = 0;
288
+ }
52
289
  }
53
290
  /**
54
291
  * @param {number} width
@@ -64,8 +301,6 @@ export class TextureManager {
64
301
  texture.area = 0;
65
302
  texture.dirty = true;
66
303
  texture.smoothing = true;
67
- texture._$offsetX = 0;
68
- texture._$offsetY = 0;
69
304
  this.bind0(texture, false);
70
305
  this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_S, this._$gl.CLAMP_TO_EDGE);
71
306
  this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_T, this._$gl.CLAMP_TO_EDGE);
@@ -1,5 +1,6 @@
1
1
  import type { CapsStyleImpl } from "./interface/CapsStyleImpl";
2
2
  import type { JointStyleImpl } from "./interface/JointStyleImpl";
3
+ import type { WebGLShaderInstance } from "./shader/WebGLShaderInstance";
3
4
  /**
4
5
  * @class
5
6
  */
@@ -16,12 +17,23 @@ export declare class VertexArrayObjectManager {
16
17
  private readonly _$strokeAttrib_type;
17
18
  private readonly _$vertexBufferData;
18
19
  private readonly _$commonVertexArray;
20
+ private readonly _$instanceVertexArray;
21
+ private readonly _$attributeVertexBuffer;
22
+ private _$attributeBuffer;
19
23
  /**
20
24
  * @param {WebGL2RenderingContext} gl
21
25
  * @constructor
22
26
  * @public
23
27
  */
24
28
  constructor(gl: WebGL2RenderingContext);
29
+ /**
30
+ * @param {number} begin
31
+ * @param {number} end
32
+ * @return {WebGLVertexArrayObject}
33
+ * @method
34
+ * @private
35
+ */
36
+ _$getCommonVertexArray(): WebGLVertexArrayObject;
25
37
  /**
26
38
  * @param {number} begin
27
39
  * @param {number} end
@@ -79,6 +91,13 @@ export declare class VertexArrayObjectManager {
79
91
  * @public
80
92
  */
81
93
  bind(vertex_array?: WebGLVertexArrayObject | null): void;
94
+ /**
95
+ * @param {WebGLShaderInstance} instance
96
+ * @return {void}
97
+ * @method
98
+ * @public
99
+ */
100
+ bindInstnceArray(instance: WebGLShaderInstance): void;
82
101
  /**
83
102
  * @return {void}
84
103
  * @method
@@ -74,12 +74,64 @@ export class VertexArrayObjectManager {
74
74
  * @private
75
75
  */
76
76
  this._$vertexBufferData = new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]);
77
+ /**
78
+ * @type {WebGLBuffer}
79
+ * @private
80
+ */
81
+ this._$attributeVertexBuffer = gl.createBuffer();
82
+ /**
83
+ * @type {Float32Array}
84
+ * @private
85
+ */
86
+ this._$attributeBuffer = new Float32Array(22);
87
+ /**
88
+ * @type {WebGLVertexArrayObject}
89
+ * @private
90
+ */
91
+ this._$instanceVertexArray = this._$getCommonVertexArray();
77
92
  /**
78
93
  * @type {WebGLVertexArrayObject}
79
94
  * @private
80
95
  */
81
96
  this._$commonVertexArray = this._$getVertexArray(0, 1);
82
97
  }
98
+ /**
99
+ * @param {number} begin
100
+ * @param {number} end
101
+ * @return {WebGLVertexArrayObject}
102
+ * @method
103
+ * @private
104
+ */
105
+ _$getCommonVertexArray() {
106
+ const vertexArray = this._$gl.createVertexArray();
107
+ this.bind(vertexArray);
108
+ const vertexBuffer = this._$gl.createBuffer();
109
+ this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, vertexBuffer);
110
+ this._$gl.bufferData(this._$gl.ARRAY_BUFFER, new Float32Array([0, 0, 0, 1, 1, 0, 1, 1]), this._$gl.STATIC_DRAW);
111
+ this._$gl.enableVertexAttribArray(0);
112
+ this._$gl.vertexAttribPointer(0, 2, this._$gl.FLOAT, false, 0, 0);
113
+ this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, this._$attributeVertexBuffer);
114
+ this._$gl.bufferData(this._$gl.ARRAY_BUFFER, this._$attributeBuffer.byteLength, this._$gl.DYNAMIC_DRAW);
115
+ this._$gl.enableVertexAttribArray(1);
116
+ this._$gl.vertexAttribPointer(1, 4, this._$gl.FLOAT, false, 88, 0);
117
+ this._$gl.vertexAttribDivisor(1, 1);
118
+ this._$gl.enableVertexAttribArray(2);
119
+ this._$gl.vertexAttribPointer(2, 4, this._$gl.FLOAT, false, 88, 16);
120
+ this._$gl.vertexAttribDivisor(2, 1);
121
+ this._$gl.enableVertexAttribArray(3);
122
+ this._$gl.vertexAttribPointer(3, 2, this._$gl.FLOAT, false, 88, 32);
123
+ this._$gl.vertexAttribDivisor(3, 1);
124
+ this._$gl.enableVertexAttribArray(4);
125
+ this._$gl.vertexAttribPointer(4, 4, this._$gl.FLOAT, false, 88, 40);
126
+ this._$gl.vertexAttribDivisor(4, 1);
127
+ this._$gl.enableVertexAttribArray(5);
128
+ this._$gl.vertexAttribPointer(5, 4, this._$gl.FLOAT, false, 88, 56);
129
+ this._$gl.vertexAttribDivisor(5, 1);
130
+ this._$gl.enableVertexAttribArray(6);
131
+ this._$gl.vertexAttribPointer(6, 4, this._$gl.FLOAT, false, 88, 72);
132
+ this._$gl.vertexAttribDivisor(6, 1);
133
+ return vertexArray;
134
+ }
83
135
  /**
84
136
  * @param {number} begin
85
137
  * @param {number} end
@@ -89,9 +141,6 @@ export class VertexArrayObjectManager {
89
141
  */
90
142
  _$getVertexArray(begin, end) {
91
143
  const vertexArray = this._$gl.createVertexArray();
92
- if (!vertexArray) {
93
- throw new Error("the WebGLVertexArrayObject is null.");
94
- }
95
144
  this.bind(vertexArray);
96
145
  const vertexBuffer = this._$gl.createBuffer();
97
146
  this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, vertexBuffer);
@@ -117,14 +166,8 @@ export class VertexArrayObjectManager {
117
166
  }
118
167
  }
119
168
  const vertexArray = this._$gl.createVertexArray();
120
- if (!vertexArray) {
121
- throw new Error("the WebGLVertexArrayObject is null.");
122
- }
123
169
  this.bind(vertexArray);
124
170
  const vertexBuffer = this._$gl.createBuffer();
125
- if (!vertexBuffer) {
126
- throw new Error("the WebGLBuffer is null.");
127
- }
128
171
  vertexArray.vertexBuffer = vertexBuffer;
129
172
  vertexArray.vertexLength = 0;
130
173
  this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, vertexBuffer);
@@ -147,21 +190,12 @@ export class VertexArrayObjectManager {
147
190
  }
148
191
  }
149
192
  const vertexArray = this._$gl.createVertexArray();
150
- if (!vertexArray) {
151
- throw new Error("the WebGLVertexArrayObject is null.");
152
- }
153
193
  this.bind(vertexArray);
154
194
  const vertexBuffer = this._$gl.createBuffer();
155
- if (!vertexBuffer) {
156
- throw new Error("the WebGLBuffer is null.");
157
- }
158
195
  vertexArray.vertexBuffer = vertexBuffer;
159
196
  vertexArray.vertexLength = 0;
160
197
  this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, vertexBuffer);
161
198
  const indexBuffer = this._$gl.createBuffer();
162
- if (!indexBuffer) {
163
- throw new Error("the WebGLBuffer is null.");
164
- }
165
199
  vertexArray.indexBuffer = indexBuffer;
166
200
  vertexArray.indexLength = 0;
167
201
  this._$gl.bindBuffer(this._$gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
@@ -255,6 +289,23 @@ export class VertexArrayObjectManager {
255
289
  this._$boundVertexArray = vertex_array;
256
290
  this._$gl.bindVertexArray(vertex_array);
257
291
  }
292
+ /**
293
+ * @param {WebGLShaderInstance} instance
294
+ * @return {void}
295
+ * @method
296
+ * @public
297
+ */
298
+ bindInstnceArray(instance) {
299
+ // bind vao
300
+ this.bind(this._$instanceVertexArray);
301
+ this._$gl.bindBuffer(this._$gl.ARRAY_BUFFER, this._$attributeVertexBuffer);
302
+ if (instance.attributes.length > this._$attributeBuffer.length) {
303
+ this._$attributeBuffer = new Float32Array(instance.attributes.length);
304
+ this._$gl.bufferData(this._$gl.ARRAY_BUFFER, this._$attributeBuffer.byteLength, this._$gl.DYNAMIC_DRAW);
305
+ }
306
+ this._$attributeBuffer.set(instance.attributes);
307
+ this._$gl.bufferSubData(this._$gl.ARRAY_BUFFER, 0, this._$attributeBuffer.subarray(0, instance.attributes.length));
308
+ }
258
309
  /**
259
310
  * @return {void}
260
311
  * @method
@@ -0,0 +1 @@
1
+ export type BlendModeImpl = "copy" | "add" | "alpha" | "darken" | "difference" | "erase" | "hardlight" | "invert" | "layer" | "lighten" | "multiply" | "normal" | "overlay" | "screen" | "subtract";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ export interface CachePositionImpl {
2
+ index: number;
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ filterState?: boolean;
8
+ matrix?: string;
9
+ offsetX?: number;
10
+ offsetY?: number;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ export interface PointImpl {
2
+ x: number;
3
+ y: number;
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import { WebGLShaderUniform } from "./WebGLShaderUniform";
2
+ import { WebGLShaderInstance } from "./WebGLShaderInstance";
2
3
  import type { CanvasToWebGLContext } from "../CanvasToWebGLContext";
3
4
  /**
4
5
  * @class
@@ -8,15 +9,22 @@ export declare class CanvasToWebGLShader {
8
9
  private readonly _$context;
9
10
  private readonly _$program;
10
11
  private readonly _$uniform;
12
+ private _$instance;
11
13
  /**
12
- * @param {WebGL2RenderingContext} gl
13
- * @param {CanvasToWebGLContext} context
14
- * @param {string} vertex_source
15
- * @param {string} fragment_source
14
+ * @param {WebGL2RenderingContext} gl
15
+ * @param {CanvasToWebGLContext} context
16
+ * @param {string} vertex_source
17
+ * @param {string} fragment_source
16
18
  * @constructor
17
19
  * @public
18
20
  */
19
21
  constructor(gl: WebGL2RenderingContext, context: CanvasToWebGLContext, vertex_source: string, fragment_source: string);
22
+ /**
23
+ * @return {WebGLShaderInstance}
24
+ * @readonly
25
+ * @public
26
+ */
27
+ get instance(): WebGLShaderInstance;
20
28
  /**
21
29
  * @return {WebGLShaderUniform}
22
30
  * @readonly
@@ -36,6 +44,12 @@ export declare class CanvasToWebGLShader {
36
44
  * @private
37
45
  */
38
46
  _$attachProgram(): void;
47
+ /**
48
+ * @param {WebGLShaderInstance} instance
49
+ * @method
50
+ * @public
51
+ */
52
+ drawArraysInstanced(instance: WebGLShaderInstance): void;
39
53
  /**
40
54
  * @return {void}
41
55
  * @method
@@ -1,14 +1,15 @@
1
1
  import { WebGLShaderUniform } from "./WebGLShaderUniform";
2
+ import { WebGLShaderInstance } from "./WebGLShaderInstance";
2
3
  import { $getProgramId } from "@next2d/share";
3
4
  /**
4
5
  * @class
5
6
  */
6
7
  export class CanvasToWebGLShader {
7
8
  /**
8
- * @param {WebGL2RenderingContext} gl
9
- * @param {CanvasToWebGLContext} context
10
- * @param {string} vertex_source
11
- * @param {string} fragment_source
9
+ * @param {WebGL2RenderingContext} gl
10
+ * @param {CanvasToWebGLContext} context
11
+ * @param {string} vertex_source
12
+ * @param {string} fragment_source
12
13
  * @constructor
13
14
  * @public
14
15
  */
@@ -33,6 +34,23 @@ export class CanvasToWebGLShader {
33
34
  * @private
34
35
  */
35
36
  this._$uniform = new WebGLShaderUniform(gl, this._$program);
37
+ /**
38
+ * @type {WebGLShaderInstance}
39
+ * @default null
40
+ * @private
41
+ */
42
+ this._$instance = null;
43
+ }
44
+ /**
45
+ * @return {WebGLShaderInstance}
46
+ * @readonly
47
+ * @public
48
+ */
49
+ get instance() {
50
+ if (!this._$instance) {
51
+ this._$instance = new WebGLShaderInstance();
52
+ }
53
+ return this._$instance;
36
54
  }
37
55
  /**
38
56
  * @return {WebGLShaderUniform}
@@ -51,21 +69,12 @@ export class CanvasToWebGLShader {
51
69
  */
52
70
  _$createProgram(vertex_source, fragment_source) {
53
71
  const program = this._$gl.createProgram();
54
- if (!program) {
55
- throw new Error("WebGL program error");
56
- }
57
72
  // control number
58
73
  program.id = $getProgramId();
59
74
  const vertexShader = this._$gl.createShader(this._$gl.VERTEX_SHADER);
60
- if (!vertexShader) {
61
- throw new Error("WebGL vertex shader error");
62
- }
63
75
  this._$gl.shaderSource(vertexShader, vertex_source);
64
76
  this._$gl.compileShader(vertexShader);
65
77
  const fragmentShader = this._$gl.createShader(this._$gl.FRAGMENT_SHADER);
66
- if (!fragmentShader) {
67
- throw new Error("WebGL fragment shader error");
68
- }
69
78
  this._$gl.shaderSource(fragmentShader, fragment_source);
70
79
  this._$gl.compileShader(fragmentShader);
71
80
  this._$gl.attachShader(program, vertexShader);
@@ -88,6 +97,19 @@ export class CanvasToWebGLShader {
88
97
  this._$gl.useProgram(this._$program);
89
98
  }
90
99
  }
100
+ /**
101
+ * @param {WebGLShaderInstance} instance
102
+ * @method
103
+ * @public
104
+ */
105
+ drawArraysInstanced(instance) {
106
+ // setup
107
+ this._$attachProgram();
108
+ // bind data
109
+ this._$context.vao.bindInstnceArray(instance);
110
+ // draw
111
+ this._$gl.drawArraysInstanced(this._$gl.TRIANGLE_STRIP, 0, 4, instance.count);
112
+ }
91
113
  /**
92
114
  * @return {void}
93
115
  * @method
@@ -148,8 +170,7 @@ export class CanvasToWebGLShader {
148
170
  // draw fill
149
171
  const indexRanges = vertex_array_object.indexRanges;
150
172
  const range = indexRanges[indexRanges.length - 1];
151
- const count = range.first + range.count;
152
- this._$gl.drawArrays(this._$gl.TRIANGLES, 0, count);
173
+ this._$gl.drawArrays(this._$gl.TRIANGLES, 0, range.first + range.count);
153
174
  }
154
175
  /**
155
176
  * @param {WebGLVertexArrayObject} vertex_array