@next2d/webgl 1.15.0 → 1.16.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,5 +1,6 @@
1
1
  import type { CanvasToWebGLContext } from "./CanvasToWebGLContext";
2
- import { BlendModeImpl } from "@next2d/interface";
2
+ import type { BlendModeImpl } from "./interface/BlendModeImpl";
3
+ import type { CachePositionImpl } from "./interface/CachePositionImpl";
3
4
  /**
4
5
  * @class
5
6
  */
@@ -8,6 +9,11 @@ export declare class CanvasToWebGLContextBlend {
8
9
  private readonly _$gl;
9
10
  private _$enabled;
10
11
  private _$funcCode;
12
+ private _$currentOperation;
13
+ private _$currentIndex;
14
+ private _$currentSmoothing;
15
+ private _$variants;
16
+ private _$instanceShader;
11
17
  /**
12
18
  * @param {CanvasToWebGLContext} context
13
19
  * @param {WebGL2RenderingContext} gl
@@ -93,5 +99,77 @@ export declare class CanvasToWebGLContextBlend {
93
99
  * @method
94
100
  * @public
95
101
  */
102
+ clearInstacedArray(): void;
103
+ /**
104
+ * @return {void}
105
+ * @method
106
+ * @public
107
+ */
108
+ drawInstacedArray(): void;
109
+ /**
110
+ * @param {object} position
111
+ * @param {number} ct0
112
+ * @param {number} ct1
113
+ * @param {number} ct2
114
+ * @param {number} ct3
115
+ * @param {number} ct4
116
+ * @param {number} ct5
117
+ * @param {number} ct6
118
+ * @param {number} ct7
119
+ * @param {string} operation
120
+ * @param {number} render_width
121
+ * @param {number} render_height
122
+ * @param {Float32Array} matrix
123
+ * @param {boolean} smoothing
124
+ * @return {void}
125
+ * @method
126
+ * @public
127
+ */
128
+ drawInstance(position: CachePositionImpl, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number, operation: BlendModeImpl, render_width: number, render_height: number, matrix: Float32Array, smoothing: boolean): void;
129
+ /**
130
+ * @param {WebGLTexture} atlas_texture
131
+ * @param {number} x_min
132
+ * @param {number} y_min
133
+ * @param {number} x_max
134
+ * @param {number} y_max
135
+ * @param {number} ct0
136
+ * @param {number} ct1
137
+ * @param {number} ct2
138
+ * @param {number} ct3
139
+ * @param {number} ct4
140
+ * @param {number} ct5
141
+ * @param {number} ct6
142
+ * @param {number} ct7
143
+ * @param {object} cache_position
144
+ * @param {string} operation
145
+ * @param {number} render_width
146
+ * @param {number} render_height
147
+ * @param {Float32Array} matrix
148
+ * @param {boolean} smoothing
149
+ */
150
+ drawInstanceBlend(atlas_texture: WebGLTexture, x_min: number, y_min: number, x_max: number, y_max: number, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number, cache_position: CachePositionImpl, operation: BlendModeImpl, render_width: number, render_height: number, matrix: Float32Array, smoothing: boolean): void;
151
+ /**
152
+ * @param {WebGLTexture} image
153
+ * @param {number} x
154
+ * @param {number} y
155
+ * @param {number} w
156
+ * @param {number} h
157
+ * @param {number} ct0
158
+ * @param {number} ct1
159
+ * @param {number} ct2
160
+ * @param {number} ct3
161
+ * @param {number} ct4
162
+ * @param {number} ct5
163
+ * @param {number} ct6
164
+ * @param {number} ct7
165
+ * @param {string} operation
166
+ * @param {number} renderWidth
167
+ * @param {number} renderHeight
168
+ * @param {Float32Array} matrix
169
+ * @param {boolean} imageSmoothingEnabled
170
+ * @return {void}
171
+ * @method
172
+ * @public
173
+ */
96
174
  drawImage(image: WebGLTexture, x: number, y: number, w: number, h: number, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number, operation: BlendModeImpl, renderWidth: number, renderHeight: number, matrix: Float32Array, imageSmoothingEnabled: boolean): void;
97
175
  }
@@ -32,6 +32,33 @@ export class CanvasToWebGLContextBlend {
32
32
  * @private
33
33
  */
34
34
  this._$funcCode = 600;
35
+ /**
36
+ * @type {string}
37
+ * @private
38
+ */
39
+ this._$currentOperation = "normal";
40
+ /**
41
+ * @type {number}
42
+ * @default -1
43
+ * @private
44
+ */
45
+ this._$currentIndex = -1;
46
+ /**
47
+ * @type {boolean}
48
+ * @default null
49
+ * @private
50
+ */
51
+ this._$currentSmoothing = null;
52
+ /**
53
+ * @type {BlendShaderVariantCollection}
54
+ * @private
55
+ */
56
+ this._$variants = context.shaderList.blendShaderVariants;
57
+ /**
58
+ * @type {CanvasToWebGLShader}
59
+ * @private
60
+ */
61
+ this._$instanceShader = this._$variants.getInstanceShader();
35
62
  // start
36
63
  this.enable();
37
64
  }
@@ -190,12 +217,168 @@ export class CanvasToWebGLContextBlend {
190
217
  * @method
191
218
  * @public
192
219
  */
220
+ clearInstacedArray() {
221
+ const instance = this._$instanceShader.instance;
222
+ if (!instance.count) {
223
+ return;
224
+ }
225
+ instance.clear();
226
+ }
227
+ /**
228
+ * @return {void}
229
+ * @method
230
+ * @public
231
+ */
232
+ drawInstacedArray() {
233
+ const instance = this._$instanceShader.instance;
234
+ if (!instance.count) {
235
+ return;
236
+ }
237
+ const manager = this._$context.frameBuffer;
238
+ const texture = manager
239
+ .textureManager
240
+ .getAtlasTexture(this._$currentIndex);
241
+ manager
242
+ .textureManager
243
+ .bind0(texture, this._$currentSmoothing);
244
+ this.toOperation(this._$currentOperation);
245
+ this
246
+ ._$instanceShader
247
+ .drawArraysInstanced(instance);
248
+ instance.clear();
249
+ }
250
+ /**
251
+ * @param {object} position
252
+ * @param {number} ct0
253
+ * @param {number} ct1
254
+ * @param {number} ct2
255
+ * @param {number} ct3
256
+ * @param {number} ct4
257
+ * @param {number} ct5
258
+ * @param {number} ct6
259
+ * @param {number} ct7
260
+ * @param {string} operation
261
+ * @param {number} render_width
262
+ * @param {number} render_height
263
+ * @param {Float32Array} matrix
264
+ * @param {boolean} smoothing
265
+ * @return {void}
266
+ * @method
267
+ * @public
268
+ */
269
+ drawInstance(position, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7, operation, render_width, render_height, matrix, smoothing) {
270
+ if (!this._$currentOperation) {
271
+ this._$currentOperation = operation;
272
+ }
273
+ if (this._$currentIndex === -1) {
274
+ this._$currentIndex = position.index;
275
+ }
276
+ if (this._$currentSmoothing === null) {
277
+ this._$currentSmoothing = smoothing;
278
+ }
279
+ if (this._$currentOperation !== operation
280
+ || this._$currentIndex !== position.index
281
+ || this._$currentSmoothing !== smoothing) {
282
+ // execute
283
+ this.drawInstacedArray();
284
+ // update
285
+ this._$currentOperation = operation;
286
+ this._$currentIndex = position.index;
287
+ this._$currentSmoothing = smoothing;
288
+ }
289
+ this._$variants.pushNormalBlend(this._$instanceShader.instance, position.x, position.y, position.w, position.h, matrix, render_width, render_height, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
290
+ }
291
+ /**
292
+ * @param {WebGLTexture} atlas_texture
293
+ * @param {number} x_min
294
+ * @param {number} y_min
295
+ * @param {number} x_max
296
+ * @param {number} y_max
297
+ * @param {number} ct0
298
+ * @param {number} ct1
299
+ * @param {number} ct2
300
+ * @param {number} ct3
301
+ * @param {number} ct4
302
+ * @param {number} ct5
303
+ * @param {number} ct6
304
+ * @param {number} ct7
305
+ * @param {object} cache_position
306
+ * @param {string} operation
307
+ * @param {number} render_width
308
+ * @param {number} render_height
309
+ * @param {Float32Array} matrix
310
+ * @param {boolean} smoothing
311
+ */
312
+ drawInstanceBlend(atlas_texture, x_min, y_min, x_max, y_max, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7, cache_position, operation, render_width, render_height, matrix, smoothing) {
313
+ this.drawInstacedArray();
314
+ const manager = this._$context.frameBuffer;
315
+ const currentAttachment = manager.currentAttachment;
316
+ const withCT = ct0 !== 1 || ct1 !== 1 || ct2 !== 1 || ct3 !== 1 ||
317
+ ct4 !== 0 || ct5 !== 0 || ct6 !== 0 || ct7 !== 0;
318
+ const texture = manager
319
+ .getTextureFromCurrentAttachment();
320
+ const backTextureAttachment = this
321
+ ._$context
322
+ .frameBuffer
323
+ .createTextureAttachment(cache_position.w, cache_position.h);
324
+ this
325
+ ._$context
326
+ ._$bind(backTextureAttachment);
327
+ manager
328
+ .textureManager
329
+ .bind0(texture);
330
+ const clipShader = this._$variants.getClipShader();
331
+ const clipUniform = clipShader.uniform;
332
+ this._$variants.setClipUniform(clipUniform, 0, 0, cache_position.w, cache_position.h, $inverseMatrix(matrix), render_width, render_height);
333
+ this.reset();
334
+ clipShader._$drawImage();
335
+ const backTexture = manager
336
+ .getTextureFromCurrentAttachment();
337
+ this._$context._$bind(currentAttachment);
338
+ manager
339
+ .textureManager
340
+ .bind01(backTexture, atlas_texture, smoothing);
341
+ const shader = this
342
+ ._$variants
343
+ .getInstanceBlendShader(operation, withCT);
344
+ this._$variants.setInstanceBlendUniform(shader.uniform, cache_position.x / atlas_texture.width, cache_position.y / atlas_texture.height, cache_position.w / atlas_texture.width, cache_position.h / atlas_texture.height, cache_position.w, cache_position.h, matrix, render_width, render_height, withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
345
+ const width = $Math.abs(x_max - x_min);
346
+ const height = $Math.abs(y_max - y_min);
347
+ this._$gl.enable(this._$gl.SCISSOR_TEST);
348
+ this._$gl.scissor(x_min, render_height - (y_min + height), width, height);
349
+ this.toOneZero();
350
+ shader._$drawImage();
351
+ this._$gl.disable(this._$gl.SCISSOR_TEST);
352
+ manager.releaseAttachment(backTextureAttachment, true);
353
+ }
354
+ /**
355
+ * @param {WebGLTexture} image
356
+ * @param {number} x
357
+ * @param {number} y
358
+ * @param {number} w
359
+ * @param {number} h
360
+ * @param {number} ct0
361
+ * @param {number} ct1
362
+ * @param {number} ct2
363
+ * @param {number} ct3
364
+ * @param {number} ct4
365
+ * @param {number} ct5
366
+ * @param {number} ct6
367
+ * @param {number} ct7
368
+ * @param {string} operation
369
+ * @param {number} renderWidth
370
+ * @param {number} renderHeight
371
+ * @param {Float32Array} matrix
372
+ * @param {boolean} imageSmoothingEnabled
373
+ * @return {void}
374
+ * @method
375
+ * @public
376
+ */
193
377
  drawImage(image, x, y, w, h, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7, operation, renderWidth, renderHeight, matrix, imageSmoothingEnabled) {
194
378
  const manager = this._$context.frameBuffer;
195
379
  const currentBuffer = manager.currentAttachment;
196
380
  const withCT = ct0 !== 1 || ct1 !== 1 || ct2 !== 1 || ct3 !== 1 ||
197
381
  ct4 !== 0 || ct5 !== 0 || ct6 !== 0 || ct7 !== 0;
198
- const variants = this._$context.shaderList.blendShaderVariants;
199
382
  switch (operation) {
200
383
  case "normal":
201
384
  case "layer":
@@ -206,8 +389,8 @@ export class CanvasToWebGLContextBlend {
206
389
  case "copy":
207
390
  {
208
391
  manager.textureManager.bind0(image, imageSmoothingEnabled);
209
- const shader = variants.getNormalBlendShader(withCT);
210
- variants.setNormalBlendUniform(shader.uniform, x, y, w, h, matrix, renderWidth, renderHeight, withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
392
+ const shader = this._$variants.getNormalBlendShader(withCT);
393
+ this._$variants.setNormalBlendUniform(shader.uniform, x, y, w, h, matrix, renderWidth, renderHeight, withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
211
394
  const a = matrix[0];
212
395
  const b = matrix[1];
213
396
  const c = matrix[3];
@@ -251,7 +434,7 @@ export class CanvasToWebGLContextBlend {
251
434
  return;
252
435
  }
253
436
  this._$gl.enable(this._$gl.SCISSOR_TEST);
254
- this._$gl.scissor(sx, Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);
437
+ this._$gl.scissor(sx, $Math.max(0, renderHeight - (sy + sh)), sw + 1, sh + 1);
255
438
  }
256
439
  this.toOperation(operation);
257
440
  shader._$drawImage();
@@ -260,10 +443,10 @@ export class CanvasToWebGLContextBlend {
260
443
  break;
261
444
  default:
262
445
  {
263
- const sx = Math.max(0, x + matrix[6]);
264
- const sy = Math.max(0, y + matrix[7]);
265
- const sw = Math.min(Math.max(0, renderWidth - sx), w);
266
- const sh = Math.min(Math.max(0, renderHeight - sy), h);
446
+ const sx = $Math.max(0, x + matrix[6]);
447
+ const sy = $Math.max(0, y + matrix[7]);
448
+ const sw = $Math.min($Math.max(0, renderWidth - sx), w);
449
+ const sh = $Math.min($Math.max(0, renderHeight - sy), h);
267
450
  if (!sw || !sh) {
268
451
  return;
269
452
  }
@@ -274,20 +457,21 @@ export class CanvasToWebGLContextBlend {
274
457
  .createTextureAttachment(w, h);
275
458
  this._$context._$bind(backTextureAttachment);
276
459
  manager.textureManager.bind0(texture);
277
- const clipShader = variants.getClipShader();
460
+ const clipShader = this._$variants.getClipShader();
278
461
  const clipUniform = clipShader.uniform;
279
- variants.setClipUniform(clipUniform, x, y, w, h, $inverseMatrix(matrix), renderWidth, renderHeight);
462
+ this._$variants.setClipUniform(clipUniform, x, y, w, h, $inverseMatrix(matrix), renderWidth, renderHeight);
280
463
  this.reset();
281
464
  clipShader._$drawImage();
282
465
  const backTexture = manager
283
466
  .getTextureFromCurrentAttachment();
284
467
  this._$context._$bind(currentBuffer);
285
468
  manager.textureManager.bind01(backTexture, image, imageSmoothingEnabled);
286
- const shader = variants
469
+ const shader = this
470
+ ._$variants
287
471
  .getBlendShader(operation, withCT);
288
- variants.setBlendUniform(shader.uniform, x, y, w, h, matrix, renderWidth, renderHeight, withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
472
+ this._$variants.setBlendUniform(shader.uniform, x, y, w, h, matrix, renderWidth, renderHeight, withCT, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7);
289
473
  this._$gl.enable(this._$gl.SCISSOR_TEST);
290
- this._$gl.scissor(sx, Math.max(0, renderHeight - (sy + sh)), sw, sh);
474
+ this._$gl.scissor(sx, $Math.max(0, renderHeight - (sy + sh)), sw, sh);
291
475
  this.toOneZero();
292
476
  shader._$drawImage();
293
477
  this._$gl.disable(this._$gl.SCISSOR_TEST);
@@ -43,12 +43,6 @@ export declare class CanvasToWebGLContextMask {
43
43
  * @private
44
44
  */
45
45
  _$onClearRect(): void;
46
- /**
47
- * @return {void}
48
- * @method
49
- * @private
50
- */
51
- _$endClip(): void;
52
46
  /**
53
47
  * @return {void}
54
48
  * @method
@@ -100,28 +100,6 @@ export class CanvasToWebGLContextMask {
100
100
  this._$gl.disable(this._$gl.STENCIL_TEST);
101
101
  this._$currentClip = false;
102
102
  }
103
- /**
104
- * @return {void}
105
- * @method
106
- * @private
107
- */
108
- _$endClip() {
109
- const manager = this._$context.frameBuffer;
110
- const currentAttachment = manager.currentAttachment;
111
- const texture = manager.getTextureFromCurrentAttachment();
112
- this._$context._$bind(this._$context.cacheAttachment);
113
- this._$context.cacheAttachment = null;
114
- // blend off
115
- this._$context.blend.disable();
116
- const cacheBounds = this._$context.cacheBounds;
117
- this._$context.reset();
118
- this._$context.setTransform(1, 0, 0, 1, 0, 0);
119
- this._$context.drawImage(texture, cacheBounds.xMin, cacheBounds.yMin, texture.width, texture.height);
120
- // blend restart
121
- this._$context.blend.enable();
122
- // pool
123
- manager.releaseAttachment(currentAttachment, true);
124
- }
125
103
  /**
126
104
  * @return {void}
127
105
  * @method
@@ -203,10 +181,7 @@ export class CanvasToWebGLContextMask {
203
181
  currentAttachment.mask = !!currentAttachment.clipLevel;
204
182
  // end clip
205
183
  if (!currentAttachment.clipLevel) {
206
- this._$context._$clearRectStencil(0, 0, currentAttachment.width, currentAttachment.height);
207
- if (this._$context.cacheAttachment) {
208
- this._$endClip();
209
- }
184
+ this._$context._$clearRectStencil();
210
185
  return;
211
186
  }
212
187
  // replace
@@ -112,7 +112,6 @@ export class CanvasToWebGLContextStyle {
112
112
  return;
113
113
  }
114
114
  if (this._$fillStyle instanceof CanvasPatternToWebGL) {
115
- this._$fillStyle.dispose();
116
115
  this._$fillStyle = $getFloat32Array4(1, 1, 1, 1);
117
116
  return;
118
117
  }
@@ -130,7 +129,6 @@ export class CanvasToWebGLContextStyle {
130
129
  return;
131
130
  }
132
131
  if (this._$strokeStyle instanceof CanvasPatternToWebGL) {
133
- this._$strokeStyle.dispose();
134
132
  this._$strokeStyle = $getFloat32Array4(1, 1, 1, 1);
135
133
  return;
136
134
  }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @type {number}
3
+ * @public
4
+ */
5
+ export declare let $RENDER_SIZE: number;
6
+ /**
7
+ * @param {number} size
8
+ * @return {void}
9
+ * @method
10
+ * @public
11
+ */
12
+ export declare const $setRenderSize: (size: number) => void;
package/dist/Const.js ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @type {number}
3
+ * @public
4
+ */
5
+ export let $RENDER_SIZE = 2048;
6
+ /**
7
+ * @param {number} size
8
+ * @return {void}
9
+ * @method
10
+ * @public
11
+ */
12
+ export const $setRenderSize = (size) => {
13
+ $RENDER_SIZE = Math.min(4096, size / 2);
14
+ };
@@ -1,24 +1,36 @@
1
1
  import { TextureManager } from "./TextureManager";
2
- import { AttachmentImpl } from "./interface/AttachmentImpl";
2
+ import type { AttachmentImpl } from "./interface/AttachmentImpl";
3
+ import type { CachePositionImpl } from "./interface/CachePositionImpl";
3
4
  /**
4
5
  * @class
5
6
  */
6
7
  export declare class FrameBufferManager {
7
8
  private _$gl;
8
9
  private _$objectPool;
9
- private readonly _$frameBuffer;
10
- private readonly _$frameBufferTexture;
11
10
  private _$currentAttachment;
12
11
  private _$isBinding;
12
+ private _$isRenderBinding;
13
+ private readonly _$frameBuffer;
14
+ private readonly _$frameBufferTexture;
13
15
  private readonly _$textureManager;
14
16
  private readonly _$stencilBufferPool;
15
17
  private readonly _$colorBufferPool;
18
+ private readonly _$stencilBuffer;
19
+ private readonly _$colorBuffer;
16
20
  /**
17
21
  * @param {WebGL2RenderingContext} gl
18
22
  * @param {number} samples
19
23
  * @constructor
20
24
  */
21
25
  constructor(gl: WebGL2RenderingContext, samples: number);
26
+ /**
27
+ * @description 描画用のbufferをbind
28
+ *
29
+ * @return {void}
30
+ * @method
31
+ * @public
32
+ */
33
+ bindRenderBuffer(): void;
22
34
  /**
23
35
  * @member {AttachmentImpl|null}
24
36
  * @readonly
@@ -41,6 +53,12 @@ export declare class FrameBufferManager {
41
53
  * @public
42
54
  */
43
55
  createCacheAttachment(width: number, height: number, multisample?: boolean, samples?: number): AttachmentImpl;
56
+ /**
57
+ * @return {void}
58
+ * @method
59
+ * @public
60
+ */
61
+ clearCache(): void;
44
62
  /**
45
63
  * @param {number} width
46
64
  * @param {number} height
@@ -85,6 +103,27 @@ export declare class FrameBufferManager {
85
103
  * @public
86
104
  */
87
105
  unbind(): void;
106
+ /**
107
+ * @return {void}
108
+ * @method
109
+ * @public
110
+ */
111
+ transferToMainTexture(): void;
112
+ /**
113
+ * @param {number} width
114
+ * @param {number} height
115
+ * @return {object}
116
+ * @method
117
+ * @public
118
+ */
119
+ createCachePosition(width: number, height: number): CachePositionImpl;
120
+ /**
121
+ * @param {object} position
122
+ * @return {void}
123
+ * @method
124
+ * @public
125
+ */
126
+ transferTexture(position: CachePositionImpl): void;
88
127
  /**
89
128
  * @return {WebGLTexture}
90
129
  * @method
@@ -1,6 +1,8 @@
1
1
  import { TextureManager } from "./TextureManager";
2
2
  import { StencilBufferPool } from "./StencilBufferPool";
3
3
  import { ColorBufferPool } from "./ColorBufferPool";
4
+ import { $Math } from "@next2d/share";
5
+ import { $RENDER_SIZE } from "./Const";
4
6
  /**
5
7
  * @class
6
8
  */
@@ -59,6 +61,46 @@ export class FrameBufferManager {
59
61
  * @private
60
62
  */
61
63
  this._$colorBufferPool = new ColorBufferPool(gl, samples);
64
+ /**
65
+ * @type {boolean}
66
+ * @default false
67
+ * @private
68
+ */
69
+ this._$isRenderBinding = false;
70
+ /**
71
+ * @type {WebGLRenderbuffer}
72
+ * @private
73
+ */
74
+ this._$colorBuffer = this._$gl.createRenderbuffer();
75
+ this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, this._$colorBuffer);
76
+ this._$gl.renderbufferStorageMultisample(this._$gl.RENDERBUFFER, samples, this._$gl.RGBA8, $RENDER_SIZE, $RENDER_SIZE);
77
+ /**
78
+ * @type {WebGLRenderbuffer}
79
+ * @private
80
+ */
81
+ this._$stencilBuffer = this._$gl.createRenderbuffer();
82
+ this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, this._$stencilBuffer);
83
+ this._$gl.renderbufferStorageMultisample(this._$gl.RENDERBUFFER, samples, this._$gl.STENCIL_INDEX8, $RENDER_SIZE, $RENDER_SIZE);
84
+ }
85
+ /**
86
+ * @description 描画用のbufferをbind
87
+ *
88
+ * @return {void}
89
+ * @method
90
+ * @public
91
+ */
92
+ bindRenderBuffer() {
93
+ if (!this._$isBinding) {
94
+ this._$isBinding = true;
95
+ this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, this._$frameBuffer);
96
+ }
97
+ if (!this._$isRenderBinding) {
98
+ this._$isRenderBinding = true;
99
+ this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, this._$colorBuffer);
100
+ this._$gl.framebufferRenderbuffer(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.RENDERBUFFER, this._$colorBuffer);
101
+ this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, this._$stencilBuffer);
102
+ this._$gl.framebufferRenderbuffer(this._$gl.FRAMEBUFFER, this._$gl.STENCIL_ATTACHMENT, this._$gl.RENDERBUFFER, this._$stencilBuffer);
103
+ }
62
104
  }
63
105
  /**
64
106
  * @member {AttachmentImpl|null}
@@ -117,6 +159,14 @@ export class FrameBufferManager {
117
159
  attachment.isActive = true;
118
160
  return attachment;
119
161
  }
162
+ /**
163
+ * @return {void}
164
+ * @method
165
+ * @public
166
+ */
167
+ clearCache() {
168
+ this._$textureManager.clearCache();
169
+ }
120
170
  /**
121
171
  * @param {number} width
122
172
  * @param {number} height
@@ -246,6 +296,7 @@ export class FrameBufferManager {
246
296
  }
247
297
  this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, attachment.stencil);
248
298
  this._$gl.framebufferRenderbuffer(this._$gl.FRAMEBUFFER, this._$gl.STENCIL_ATTACHMENT, this._$gl.RENDERBUFFER, attachment.stencil);
299
+ this._$isRenderBinding = false;
249
300
  }
250
301
  /**
251
302
  * @return void
@@ -259,6 +310,64 @@ export class FrameBufferManager {
259
310
  this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, null);
260
311
  }
261
312
  }
313
+ /**
314
+ * @return {void}
315
+ * @method
316
+ * @public
317
+ */
318
+ transferToMainTexture() {
319
+ if (!this._$currentAttachment) {
320
+ throw new Error("the current attachment is null.");
321
+ }
322
+ const width = this._$currentAttachment.width;
323
+ const height = this._$currentAttachment.height;
324
+ const texture = this._$currentAttachment.texture;
325
+ if (!texture) {
326
+ throw new Error("the texture is null.");
327
+ }
328
+ this._$gl.bindFramebuffer(this._$gl.DRAW_FRAMEBUFFER, this._$frameBufferTexture);
329
+ this._$textureManager.bind0(texture);
330
+ this._$gl.framebufferTexture2D(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.TEXTURE_2D, texture, 0);
331
+ // use main Framebuffer
332
+ this._$gl.bindFramebuffer(this._$gl.DRAW_FRAMEBUFFER, null);
333
+ // execute
334
+ this._$gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, this._$gl.COLOR_BUFFER_BIT, this._$gl.NEAREST);
335
+ // reset
336
+ this._$gl.bindFramebuffer(this._$gl.DRAW_FRAMEBUFFER, this._$frameBuffer);
337
+ }
338
+ /**
339
+ * @param {number} width
340
+ * @param {number} height
341
+ * @return {object}
342
+ * @method
343
+ * @public
344
+ */
345
+ createCachePosition(width, height) {
346
+ return this
347
+ ._$textureManager
348
+ .createCachePosition(width, height);
349
+ }
350
+ /**
351
+ * @param {object} position
352
+ * @return {void}
353
+ * @method
354
+ * @public
355
+ */
356
+ transferTexture(position) {
357
+ this._$gl.disable(this._$gl.SCISSOR_TEST);
358
+ this._$gl.bindFramebuffer(this._$gl.DRAW_FRAMEBUFFER, this._$frameBufferTexture);
359
+ const texture = this
360
+ ._$textureManager
361
+ .getAtlasTexture(position.index);
362
+ this._$textureManager.bind0(texture);
363
+ this._$gl.framebufferTexture2D(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.TEXTURE_2D, texture, 0);
364
+ const x0 = $Math.max(0, position.x - 1);
365
+ const y0 = $Math.max(0, position.y - 1);
366
+ const x1 = $Math.min($RENDER_SIZE, position.x + position.w + 1);
367
+ const y1 = $Math.min($RENDER_SIZE, position.y + position.h + 1);
368
+ this._$gl.blitFramebuffer(x0, y0, x1, y1, x0, y0, x1, y1, this._$gl.COLOR_BUFFER_BIT, this._$gl.NEAREST);
369
+ this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, this._$frameBuffer);
370
+ }
262
371
  /**
263
372
  * @return {WebGLTexture}
264
373
  * @method