@next2d/webgl 1.14.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/BezierConverter.d.ts +59 -0
- package/dist/BezierConverter.js +106 -0
- package/dist/CanvasGradientToWebGL.d.ts +96 -0
- package/dist/CanvasGradientToWebGL.js +181 -0
- package/dist/CanvasPatternToWebGL.d.ts +39 -0
- package/dist/CanvasPatternToWebGL.js +66 -0
- package/dist/CanvasToWebGLContext.d.ts +591 -0
- package/dist/CanvasToWebGLContext.js +1427 -0
- package/dist/CanvasToWebGLContextBlend.d.ts +97 -0
- package/dist/CanvasToWebGLContextBlend.js +299 -0
- package/dist/CanvasToWebGLContextGrid.d.ts +74 -0
- package/dist/CanvasToWebGLContextGrid.js +283 -0
- package/dist/CanvasToWebGLContextMask.d.ts +113 -0
- package/dist/CanvasToWebGLContextMask.js +436 -0
- package/dist/CanvasToWebGLContextPath.d.ts +111 -0
- package/dist/CanvasToWebGLContextPath.js +210 -0
- package/dist/CanvasToWebGLContextStyle.d.ts +78 -0
- package/dist/CanvasToWebGLContextStyle.js +139 -0
- package/dist/ColorBufferPool.d.ts +58 -0
- package/dist/ColorBufferPool.js +134 -0
- package/dist/FrameBufferManager.d.ts +135 -0
- package/dist/FrameBufferManager.js +358 -0
- package/dist/StencilBufferPool.d.ts +56 -0
- package/dist/StencilBufferPool.js +142 -0
- package/dist/TextureManager.d.ts +130 -0
- package/dist/TextureManager.js +296 -0
- package/dist/VertexArrayObjectManager.d.ts +96 -0
- package/dist/VertexArrayObjectManager.js +277 -0
- package/dist/WebGLFillMeshGenerator.d.ts +31 -0
- package/dist/WebGLFillMeshGenerator.js +101 -0
- package/dist/WebGLStrokeMeshGenerator.d.ts +183 -0
- package/dist/WebGLStrokeMeshGenerator.js +504 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/interface/AttachmentImpl.d.ts +11 -0
- package/dist/interface/AttachmentImpl.js +1 -0
- package/dist/interface/BoundsImpl.d.ts +6 -0
- package/dist/interface/BoundsImpl.js +1 -0
- package/dist/interface/CapsStyleImpl.d.ts +1 -0
- package/dist/interface/CapsStyleImpl.js +1 -0
- package/dist/interface/ClipObjectImpl.d.ts +14 -0
- package/dist/interface/ClipObjectImpl.js +1 -0
- package/dist/interface/FillMeshImpl.d.ts +5 -0
- package/dist/interface/FillMeshImpl.js +1 -0
- package/dist/interface/GradientTypeImpl.d.ts +1 -0
- package/dist/interface/GradientTypeImpl.js +1 -0
- package/dist/interface/GridImpl.d.ts +6 -0
- package/dist/interface/GridImpl.js +1 -0
- package/dist/interface/IndexRangeImpl.d.ts +4 -0
- package/dist/interface/IndexRangeImpl.js +1 -0
- package/dist/interface/InterpolationMethodImpl.d.ts +1 -0
- package/dist/interface/InterpolationMethodImpl.js +1 -0
- package/dist/interface/JointStyleImpl.d.ts +1 -0
- package/dist/interface/JointStyleImpl.js +1 -0
- package/dist/interface/SpreadMethodImpl.d.ts +1 -0
- package/dist/interface/SpreadMethodImpl.js +1 -0
- package/dist/interface/StrokeMethImpl.d.ts +4 -0
- package/dist/interface/StrokeMethImpl.js +1 -0
- package/dist/interface/UniformDataImpl.d.ts +5 -0
- package/dist/interface/UniformDataImpl.js +1 -0
- package/dist/interface/VerticesImpl.d.ts +1 -0
- package/dist/interface/VerticesImpl.js +1 -0
- package/dist/shader/CanvasToWebGLShader.d.ts +85 -0
- package/dist/shader/CanvasToWebGLShader.js +192 -0
- package/dist/shader/CanvasToWebGLShaderList.d.ts +70 -0
- package/dist/shader/CanvasToWebGLShaderList.js +109 -0
- package/dist/shader/GradientLUTGenerator.d.ts +36 -0
- package/dist/shader/GradientLUTGenerator.js +123 -0
- package/dist/shader/WebGLShaderUniform.d.ts +52 -0
- package/dist/shader/WebGLShaderUniform.js +165 -0
- package/dist/shader/fragment/FragmentShaderLibrary.d.ts +18 -0
- package/dist/shader/fragment/FragmentShaderLibrary.js +35 -0
- package/dist/shader/fragment/FragmentShaderSource.d.ts +29 -0
- package/dist/shader/fragment/FragmentShaderSource.js +99 -0
- package/dist/shader/fragment/FragmentShaderSourceBlend.d.ts +67 -0
- package/dist/shader/fragment/FragmentShaderSourceBlend.js +319 -0
- package/dist/shader/fragment/FragmentShaderSourceGradient.d.ts +44 -0
- package/dist/shader/fragment/FragmentShaderSourceGradient.js +114 -0
- package/dist/shader/fragment/FragmentShaderSourceGradientLUT.d.ts +14 -0
- package/dist/shader/fragment/FragmentShaderSourceGradientLUT.js +58 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.d.ts +12 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.js +36 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.d.ts +12 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceBlurFilter.js +42 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.d.ts +11 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceColorMatrixFilter.js +35 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.d.ts +16 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceConvolutionFilter.js +80 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.d.ts +15 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceDisplacementMapFilter.js +106 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceFilter.d.ts +112 -0
- package/dist/shader/fragment/filter/FragmentShaderSourceFilter.js +275 -0
- package/dist/shader/variants/BlendShaderVariantCollection.d.ts +99 -0
- package/dist/shader/variants/BlendShaderVariantCollection.js +239 -0
- package/dist/shader/variants/FilterShaderVariantCollection.d.ts +150 -0
- package/dist/shader/variants/FilterShaderVariantCollection.js +395 -0
- package/dist/shader/variants/GradientLUTShaderVariantCollection.d.ts +49 -0
- package/dist/shader/variants/GradientLUTShaderVariantCollection.js +107 -0
- package/dist/shader/variants/GradientShapeShaderVariantCollection.d.ts +61 -0
- package/dist/shader/variants/GradientShapeShaderVariantCollection.js +196 -0
- package/dist/shader/variants/ShapeShaderVariantCollection.d.ts +117 -0
- package/dist/shader/variants/ShapeShaderVariantCollection.js +427 -0
- package/dist/shader/vertex/VertexShaderLibrary.d.ts +18 -0
- package/dist/shader/vertex/VertexShaderLibrary.js +75 -0
- package/dist/shader/vertex/VertexShaderSource.d.ts +23 -0
- package/dist/shader/vertex/VertexShaderSource.js +92 -0
- package/dist/shader/vertex/VertexShaderSourceFill.d.ts +45 -0
- package/dist/shader/vertex/VertexShaderSourceFill.js +112 -0
- package/dist/shader/vertex/VertexShaderSourceStroke.d.ts +27 -0
- package/dist/shader/vertex/VertexShaderSourceStroke.js +149 -0
- package/package.json +37 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { TextureManager } from "./TextureManager";
|
|
2
|
+
import { AttachmentImpl } from "./interface/AttachmentImpl";
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export declare class FrameBufferManager {
|
|
7
|
+
private _$gl;
|
|
8
|
+
private _$objectPool;
|
|
9
|
+
private readonly _$frameBuffer;
|
|
10
|
+
private readonly _$frameBufferTexture;
|
|
11
|
+
private _$currentAttachment;
|
|
12
|
+
private _$isBinding;
|
|
13
|
+
private readonly _$textureManager;
|
|
14
|
+
private readonly _$stencilBufferPool;
|
|
15
|
+
private readonly _$colorBufferPool;
|
|
16
|
+
/**
|
|
17
|
+
* @param {WebGL2RenderingContext} gl
|
|
18
|
+
* @param {number} samples
|
|
19
|
+
* @constructor
|
|
20
|
+
*/
|
|
21
|
+
constructor(gl: WebGL2RenderingContext, samples: number);
|
|
22
|
+
/**
|
|
23
|
+
* @member {AttachmentImpl|null}
|
|
24
|
+
* @readonly
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
get currentAttachment(): AttachmentImpl | null;
|
|
28
|
+
/**
|
|
29
|
+
* @member {TextureManager}
|
|
30
|
+
* @readonly
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
get textureManager(): TextureManager;
|
|
34
|
+
/**
|
|
35
|
+
* @param {number} width
|
|
36
|
+
* @param {number} height
|
|
37
|
+
* @param {boolean} [multisample=false]
|
|
38
|
+
* @param {number} [samples=0]
|
|
39
|
+
* @return {AttachmentImpl}
|
|
40
|
+
* @method
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
createCacheAttachment(width: number, height: number, multisample?: boolean, samples?: number): AttachmentImpl;
|
|
44
|
+
/**
|
|
45
|
+
* @param {number} width
|
|
46
|
+
* @param {number} height
|
|
47
|
+
* @return {void}
|
|
48
|
+
* @method
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
setMaxSize(width: number, height: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* @param {number} width
|
|
54
|
+
* @param {number} height
|
|
55
|
+
* @return {AttachmentImpl}
|
|
56
|
+
* @method
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
createTextureAttachment(width: number, height: number): AttachmentImpl;
|
|
60
|
+
/**
|
|
61
|
+
* @param {WebGLTexture} texture
|
|
62
|
+
* @return {AttachmentImpl}
|
|
63
|
+
* @method
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
createTextureAttachmentFrom(texture: WebGLTexture): AttachmentImpl;
|
|
67
|
+
/**
|
|
68
|
+
* @param {AttachmentImpl} [attachment = null]
|
|
69
|
+
* @param {boolean} [should_release_texture=false]
|
|
70
|
+
* @return {void}
|
|
71
|
+
* @method
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
releaseAttachment(attachment?: AttachmentImpl | null, should_release_texture?: boolean): void;
|
|
75
|
+
/**
|
|
76
|
+
* @param {object} attachment
|
|
77
|
+
* @return {void}
|
|
78
|
+
* @method
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
bind(attachment: AttachmentImpl): void;
|
|
82
|
+
/**
|
|
83
|
+
* @return void
|
|
84
|
+
* @method
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
unbind(): void;
|
|
88
|
+
/**
|
|
89
|
+
* @return {WebGLTexture}
|
|
90
|
+
* @method
|
|
91
|
+
* @public
|
|
92
|
+
*/
|
|
93
|
+
getTextureFromCurrentAttachment(): WebGLTexture;
|
|
94
|
+
/**
|
|
95
|
+
* @param {number} width
|
|
96
|
+
* @param {number} height
|
|
97
|
+
* @param {Uint8Array} [pixels=null]
|
|
98
|
+
* @param {boolean} [premultipliedAlpha=false]
|
|
99
|
+
* @param {boolean} [flip_y=true]
|
|
100
|
+
* @return {WebGLTexture}
|
|
101
|
+
* @public
|
|
102
|
+
*/
|
|
103
|
+
createTextureFromPixels(width: number, height: number, pixels?: Uint8Array | null, premultipliedAlpha?: boolean, flip_y?: boolean): WebGLTexture;
|
|
104
|
+
/**
|
|
105
|
+
* @param {HTMLCanvasElement} canvas
|
|
106
|
+
* @return {WebGLTexture}
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
createTextureFromCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): WebGLTexture;
|
|
110
|
+
/**
|
|
111
|
+
* @param {HTMLImageElement} image
|
|
112
|
+
* @param {boolean} [smoothing=false]
|
|
113
|
+
* @return {WebGLTexture}
|
|
114
|
+
* @public
|
|
115
|
+
*/
|
|
116
|
+
createTextureFromImage(image: HTMLImageElement, smoothing?: boolean): WebGLTexture;
|
|
117
|
+
/**
|
|
118
|
+
* @param {HTMLVideoElement} video
|
|
119
|
+
* @param {boolean} [smoothing=false]
|
|
120
|
+
* @return {WebGLTexture}
|
|
121
|
+
* @public
|
|
122
|
+
*/
|
|
123
|
+
createTextureFromVideo(video: HTMLVideoElement, smoothing?: boolean): WebGLTexture;
|
|
124
|
+
/**
|
|
125
|
+
* @return {WebGLTexture}
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
createTextureFromCurrentAttachment(): WebGLTexture;
|
|
129
|
+
/**
|
|
130
|
+
* @param {WebGLTexture} texture
|
|
131
|
+
* @return void
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
releaseTexture(texture: WebGLTexture): void;
|
|
135
|
+
}
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { TextureManager } from "./TextureManager";
|
|
2
|
+
import { StencilBufferPool } from "./StencilBufferPool";
|
|
3
|
+
import { ColorBufferPool } from "./ColorBufferPool";
|
|
4
|
+
/**
|
|
5
|
+
* @class
|
|
6
|
+
*/
|
|
7
|
+
export class FrameBufferManager {
|
|
8
|
+
/**
|
|
9
|
+
* @param {WebGL2RenderingContext} gl
|
|
10
|
+
* @param {number} samples
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(gl, samples) {
|
|
14
|
+
/**
|
|
15
|
+
* @type {WebGL2RenderingContext}
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
this._$gl = gl;
|
|
19
|
+
/**
|
|
20
|
+
* @type {array}
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
this._$objectPool = [];
|
|
24
|
+
/**
|
|
25
|
+
* @type {WebGLFramebuffer}
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
this._$frameBuffer = gl.createFramebuffer();
|
|
29
|
+
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._$frameBuffer);
|
|
30
|
+
/**
|
|
31
|
+
* @type {WebGLFramebuffer}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
this._$frameBufferTexture = gl.createFramebuffer();
|
|
35
|
+
/**
|
|
36
|
+
* @type {AttachmentImpl}
|
|
37
|
+
* @default null
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
this._$currentAttachment = null;
|
|
41
|
+
/**
|
|
42
|
+
* @type {boolean}
|
|
43
|
+
* @default false
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
this._$isBinding = false;
|
|
47
|
+
/**
|
|
48
|
+
* @type {TextureManager}
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
this._$textureManager = new TextureManager(gl);
|
|
52
|
+
/**
|
|
53
|
+
* @type {StencilBufferPool}
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
56
|
+
this._$stencilBufferPool = new StencilBufferPool(gl);
|
|
57
|
+
/**
|
|
58
|
+
* @type {ColorBufferPool}
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
this._$colorBufferPool = new ColorBufferPool(gl, samples);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @member {AttachmentImpl|null}
|
|
65
|
+
* @readonly
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
get currentAttachment() {
|
|
69
|
+
return this._$currentAttachment;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @member {TextureManager}
|
|
73
|
+
* @readonly
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
get textureManager() {
|
|
77
|
+
return this._$textureManager;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @param {number} width
|
|
81
|
+
* @param {number} height
|
|
82
|
+
* @param {boolean} [multisample=false]
|
|
83
|
+
* @param {number} [samples=0]
|
|
84
|
+
* @return {AttachmentImpl}
|
|
85
|
+
* @method
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
createCacheAttachment(width, height, multisample = false, samples = 0) {
|
|
89
|
+
const attachment = this._$objectPool.pop() || {
|
|
90
|
+
"width": 0,
|
|
91
|
+
"height": 0,
|
|
92
|
+
"color": null,
|
|
93
|
+
"texture": null,
|
|
94
|
+
"msaa": false,
|
|
95
|
+
"stencil": null,
|
|
96
|
+
"mask": false,
|
|
97
|
+
"clipLevel": 0,
|
|
98
|
+
"isActive": false
|
|
99
|
+
};
|
|
100
|
+
const texture = this._$textureManager.create(width, height);
|
|
101
|
+
attachment.width = width;
|
|
102
|
+
attachment.height = height;
|
|
103
|
+
if (multisample) {
|
|
104
|
+
attachment.color = this._$colorBufferPool.create(width, height, samples);
|
|
105
|
+
attachment.texture = texture;
|
|
106
|
+
attachment.msaa = true;
|
|
107
|
+
attachment.stencil = attachment.color.stencil;
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
attachment.color = texture;
|
|
111
|
+
attachment.texture = texture;
|
|
112
|
+
attachment.msaa = false;
|
|
113
|
+
attachment.stencil = this._$stencilBufferPool.create(width, height);
|
|
114
|
+
}
|
|
115
|
+
attachment.mask = false;
|
|
116
|
+
attachment.clipLevel = 0;
|
|
117
|
+
attachment.isActive = true;
|
|
118
|
+
return attachment;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* @param {number} width
|
|
122
|
+
* @param {number} height
|
|
123
|
+
* @return {void}
|
|
124
|
+
* @method
|
|
125
|
+
* @public
|
|
126
|
+
*/
|
|
127
|
+
setMaxSize(width, height) {
|
|
128
|
+
this._$stencilBufferPool._$maxWidth = width;
|
|
129
|
+
this._$stencilBufferPool._$maxHeight = height;
|
|
130
|
+
this._$textureManager._$maxWidth = width;
|
|
131
|
+
this._$textureManager._$maxHeight = height;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @param {number} width
|
|
135
|
+
* @param {number} height
|
|
136
|
+
* @return {AttachmentImpl}
|
|
137
|
+
* @method
|
|
138
|
+
* @public
|
|
139
|
+
*/
|
|
140
|
+
createTextureAttachment(width, height) {
|
|
141
|
+
const attachment = this._$objectPool.pop() || {
|
|
142
|
+
"width": 0,
|
|
143
|
+
"height": 0,
|
|
144
|
+
"color": null,
|
|
145
|
+
"texture": null,
|
|
146
|
+
"msaa": false,
|
|
147
|
+
"stencil": null,
|
|
148
|
+
"mask": false,
|
|
149
|
+
"clipLevel": 0,
|
|
150
|
+
"isActive": false
|
|
151
|
+
};
|
|
152
|
+
const texture = this._$textureManager.create(width, height);
|
|
153
|
+
attachment.width = width;
|
|
154
|
+
attachment.height = height;
|
|
155
|
+
attachment.color = texture;
|
|
156
|
+
attachment.texture = texture;
|
|
157
|
+
attachment.msaa = false;
|
|
158
|
+
attachment.stencil = null;
|
|
159
|
+
attachment.mask = false;
|
|
160
|
+
attachment.clipLevel = 0;
|
|
161
|
+
attachment.isActive = true;
|
|
162
|
+
return attachment;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param {WebGLTexture} texture
|
|
166
|
+
* @return {AttachmentImpl}
|
|
167
|
+
* @method
|
|
168
|
+
* @public
|
|
169
|
+
*/
|
|
170
|
+
createTextureAttachmentFrom(texture) {
|
|
171
|
+
const attachment = this._$objectPool.pop() || {
|
|
172
|
+
"width": 0,
|
|
173
|
+
"height": 0,
|
|
174
|
+
"color": null,
|
|
175
|
+
"texture": null,
|
|
176
|
+
"msaa": false,
|
|
177
|
+
"stencil": null,
|
|
178
|
+
"mask": false,
|
|
179
|
+
"clipLevel": 0,
|
|
180
|
+
"isActive": true
|
|
181
|
+
};
|
|
182
|
+
attachment.width = texture.width;
|
|
183
|
+
attachment.height = texture.height;
|
|
184
|
+
attachment.color = texture;
|
|
185
|
+
attachment.texture = texture;
|
|
186
|
+
attachment.msaa = false;
|
|
187
|
+
attachment.stencil = null;
|
|
188
|
+
attachment.mask = false;
|
|
189
|
+
attachment.clipLevel = 0;
|
|
190
|
+
attachment.isActive = true;
|
|
191
|
+
return attachment;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* @param {AttachmentImpl} [attachment = null]
|
|
195
|
+
* @param {boolean} [should_release_texture=false]
|
|
196
|
+
* @return {void}
|
|
197
|
+
* @method
|
|
198
|
+
* @public
|
|
199
|
+
*/
|
|
200
|
+
releaseAttachment(attachment = null, should_release_texture = false) {
|
|
201
|
+
if (!attachment || !attachment.isActive) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (attachment.msaa) {
|
|
205
|
+
if (attachment.color instanceof WebGLRenderbuffer) {
|
|
206
|
+
this._$colorBufferPool.release(attachment.color);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
else if (attachment.stencil) {
|
|
210
|
+
this._$stencilBufferPool.release(attachment.stencil);
|
|
211
|
+
}
|
|
212
|
+
if (should_release_texture && attachment.texture) {
|
|
213
|
+
this._$textureManager.release(attachment.texture);
|
|
214
|
+
}
|
|
215
|
+
attachment.color = null;
|
|
216
|
+
attachment.texture = null;
|
|
217
|
+
attachment.stencil = null;
|
|
218
|
+
attachment.isActive = false;
|
|
219
|
+
this._$objectPool.push(attachment);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @param {object} attachment
|
|
223
|
+
* @return {void}
|
|
224
|
+
* @method
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
bind(attachment) {
|
|
228
|
+
this._$currentAttachment = attachment;
|
|
229
|
+
if (!this._$isBinding) {
|
|
230
|
+
this._$isBinding = true;
|
|
231
|
+
this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, this._$frameBuffer);
|
|
232
|
+
}
|
|
233
|
+
if (attachment.msaa) {
|
|
234
|
+
if (attachment.color instanceof WebGLRenderbuffer) {
|
|
235
|
+
this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, attachment.color);
|
|
236
|
+
this._$gl.framebufferRenderbuffer(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.RENDERBUFFER, attachment.color);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
if (attachment.color instanceof WebGLTexture) {
|
|
241
|
+
if (attachment.color) {
|
|
242
|
+
this._$textureManager.bind0(attachment.color);
|
|
243
|
+
}
|
|
244
|
+
this._$gl.framebufferTexture2D(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.TEXTURE_2D, attachment.color, 0);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, attachment.stencil);
|
|
248
|
+
this._$gl.framebufferRenderbuffer(this._$gl.FRAMEBUFFER, this._$gl.STENCIL_ATTACHMENT, this._$gl.RENDERBUFFER, attachment.stencil);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @return void
|
|
252
|
+
* @method
|
|
253
|
+
* @public
|
|
254
|
+
*/
|
|
255
|
+
unbind() {
|
|
256
|
+
this._$currentAttachment = null;
|
|
257
|
+
if (this._$isBinding) {
|
|
258
|
+
this._$isBinding = false;
|
|
259
|
+
this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, null);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* @return {WebGLTexture}
|
|
264
|
+
* @method
|
|
265
|
+
* @public
|
|
266
|
+
*/
|
|
267
|
+
getTextureFromCurrentAttachment() {
|
|
268
|
+
if (!this._$currentAttachment) {
|
|
269
|
+
throw new Error("the current attachment is null.");
|
|
270
|
+
}
|
|
271
|
+
if (!this._$currentAttachment.msaa
|
|
272
|
+
&& this._$currentAttachment.texture) {
|
|
273
|
+
return this._$currentAttachment.texture;
|
|
274
|
+
}
|
|
275
|
+
const width = this._$currentAttachment.width;
|
|
276
|
+
const height = this._$currentAttachment.height;
|
|
277
|
+
const texture = this._$currentAttachment.texture;
|
|
278
|
+
if (!texture) {
|
|
279
|
+
throw new Error("the texture is null.");
|
|
280
|
+
}
|
|
281
|
+
texture.dirty = false;
|
|
282
|
+
this._$gl.bindFramebuffer(this._$gl.DRAW_FRAMEBUFFER, this._$frameBufferTexture);
|
|
283
|
+
this._$textureManager.bind0(texture);
|
|
284
|
+
this._$gl.framebufferTexture2D(this._$gl.FRAMEBUFFER, this._$gl.COLOR_ATTACHMENT0, this._$gl.TEXTURE_2D, texture, 0);
|
|
285
|
+
this._$gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, this._$gl.COLOR_BUFFER_BIT, this._$gl.NEAREST);
|
|
286
|
+
this._$gl.bindFramebuffer(this._$gl.FRAMEBUFFER, this._$frameBuffer);
|
|
287
|
+
return texture;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @param {number} width
|
|
291
|
+
* @param {number} height
|
|
292
|
+
* @param {Uint8Array} [pixels=null]
|
|
293
|
+
* @param {boolean} [premultipliedAlpha=false]
|
|
294
|
+
* @param {boolean} [flip_y=true]
|
|
295
|
+
* @return {WebGLTexture}
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
createTextureFromPixels(width, height, pixels = null, premultipliedAlpha = false, flip_y = true) {
|
|
299
|
+
return this
|
|
300
|
+
._$textureManager
|
|
301
|
+
.create(width, height, pixels, premultipliedAlpha, flip_y);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* @param {HTMLCanvasElement} canvas
|
|
305
|
+
* @return {WebGLTexture}
|
|
306
|
+
* @public
|
|
307
|
+
*/
|
|
308
|
+
createTextureFromCanvas(canvas) {
|
|
309
|
+
return this
|
|
310
|
+
._$textureManager
|
|
311
|
+
.createFromCanvas(canvas);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* @param {HTMLImageElement} image
|
|
315
|
+
* @param {boolean} [smoothing=false]
|
|
316
|
+
* @return {WebGLTexture}
|
|
317
|
+
* @public
|
|
318
|
+
*/
|
|
319
|
+
createTextureFromImage(image, smoothing = false) {
|
|
320
|
+
return this
|
|
321
|
+
._$textureManager
|
|
322
|
+
.createFromImage(image, smoothing);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @param {HTMLVideoElement} video
|
|
326
|
+
* @param {boolean} [smoothing=false]
|
|
327
|
+
* @return {WebGLTexture}
|
|
328
|
+
* @public
|
|
329
|
+
*/
|
|
330
|
+
createTextureFromVideo(video, smoothing = false) {
|
|
331
|
+
return this
|
|
332
|
+
._$textureManager
|
|
333
|
+
.createFromVideo(video, smoothing);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* @return {WebGLTexture}
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
createTextureFromCurrentAttachment() {
|
|
340
|
+
if (!this._$currentAttachment) {
|
|
341
|
+
throw new Error("the current attachment is null.");
|
|
342
|
+
}
|
|
343
|
+
const width = this._$currentAttachment.width;
|
|
344
|
+
const height = this._$currentAttachment.height;
|
|
345
|
+
const texture = this._$textureManager.create(width, height);
|
|
346
|
+
this._$textureManager.bind0(texture);
|
|
347
|
+
this._$gl.copyTexSubImage2D(this._$gl.TEXTURE_2D, 0, 0, 0, 0, 0, width, height);
|
|
348
|
+
return texture;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* @param {WebGLTexture} texture
|
|
352
|
+
* @return void
|
|
353
|
+
* @public
|
|
354
|
+
*/
|
|
355
|
+
releaseTexture(texture) {
|
|
356
|
+
this._$textureManager.release(texture);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export declare class StencilBufferPool {
|
|
5
|
+
private readonly _$gl;
|
|
6
|
+
private readonly _$objectPool;
|
|
7
|
+
private _$objectPoolArea;
|
|
8
|
+
_$maxWidth: number;
|
|
9
|
+
_$maxHeight: number;
|
|
10
|
+
/**
|
|
11
|
+
* @param {WebGL2RenderingContext} gl
|
|
12
|
+
* @constructor
|
|
13
|
+
*/
|
|
14
|
+
constructor(gl: WebGL2RenderingContext);
|
|
15
|
+
/**
|
|
16
|
+
* @member {number}
|
|
17
|
+
* @param {number} max_width
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
set maxWidth(max_width: number);
|
|
21
|
+
/**
|
|
22
|
+
* @member {number}
|
|
23
|
+
* @param {number} max_height
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
set maxHeight(max_height: number);
|
|
27
|
+
/**
|
|
28
|
+
* @return {WebGLRenderbuffer}
|
|
29
|
+
* @method
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_$createStencilBuffer(): WebGLRenderbuffer;
|
|
33
|
+
/**
|
|
34
|
+
* @param {number} width
|
|
35
|
+
* @param {number} height
|
|
36
|
+
* @return {WebGLRenderbuffer}
|
|
37
|
+
* @method
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
_$getStencilBuffer(width: number, height: number): WebGLRenderbuffer;
|
|
41
|
+
/**
|
|
42
|
+
* @param {number} width
|
|
43
|
+
* @param {number} height
|
|
44
|
+
* @return {WebGLRenderbuffer}
|
|
45
|
+
* @method
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
create(width: number, height: number): WebGLRenderbuffer;
|
|
49
|
+
/**
|
|
50
|
+
* @param {WebGLRenderbuffer} stencilBuffer
|
|
51
|
+
* @return {void}
|
|
52
|
+
* @method
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
release(stencilBuffer: WebGLRenderbuffer): void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { $getArray } from "@next2d/share";
|
|
2
|
+
/**
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
export class StencilBufferPool {
|
|
6
|
+
/**
|
|
7
|
+
* @param {WebGL2RenderingContext} gl
|
|
8
|
+
* @constructor
|
|
9
|
+
*/
|
|
10
|
+
constructor(gl) {
|
|
11
|
+
/**
|
|
12
|
+
* @type {WebGL2RenderingContext}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
this._$gl = gl;
|
|
16
|
+
/**
|
|
17
|
+
* @type {array}
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
this._$objectPool = $getArray();
|
|
21
|
+
/**
|
|
22
|
+
* @type {number}
|
|
23
|
+
* @default 0
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
this._$objectPoolArea = 0;
|
|
27
|
+
/**
|
|
28
|
+
* @type {number}
|
|
29
|
+
* @default 0
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
this._$maxWidth = 0;
|
|
33
|
+
/**
|
|
34
|
+
* @type {number}
|
|
35
|
+
* @default 0
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
this._$maxHeight = 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @member {number}
|
|
42
|
+
* @param {number} max_width
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
set maxWidth(max_width) {
|
|
46
|
+
this._$maxWidth = max_width;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @member {number}
|
|
50
|
+
* @param {number} max_height
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
set maxHeight(max_height) {
|
|
54
|
+
this._$maxHeight = max_height;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @return {WebGLRenderbuffer}
|
|
58
|
+
* @method
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
_$createStencilBuffer() {
|
|
62
|
+
const stencilBuffer = this._$gl.createRenderbuffer();
|
|
63
|
+
if (!stencilBuffer) {
|
|
64
|
+
throw new Error("the stencil buffer is null.");
|
|
65
|
+
}
|
|
66
|
+
stencilBuffer.width = 0;
|
|
67
|
+
stencilBuffer.height = 0;
|
|
68
|
+
stencilBuffer.area = 0;
|
|
69
|
+
stencilBuffer.dirty = true;
|
|
70
|
+
return stencilBuffer;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* @param {number} width
|
|
74
|
+
* @param {number} height
|
|
75
|
+
* @return {WebGLRenderbuffer}
|
|
76
|
+
* @method
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
_$getStencilBuffer(width, height) {
|
|
80
|
+
const length = this._$objectPool.length;
|
|
81
|
+
for (let idx = 0; idx < length; ++idx) {
|
|
82
|
+
const stencilBuffer = this._$objectPool[idx];
|
|
83
|
+
if (stencilBuffer.width === width
|
|
84
|
+
&& stencilBuffer.height === height) {
|
|
85
|
+
this._$objectPool.splice(idx, 1);
|
|
86
|
+
this._$objectPoolArea -= stencilBuffer.area;
|
|
87
|
+
return stencilBuffer;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (length > 100) {
|
|
91
|
+
const stencilBuffer = this._$objectPool.shift();
|
|
92
|
+
if (stencilBuffer) {
|
|
93
|
+
this._$objectPoolArea -= stencilBuffer.area;
|
|
94
|
+
return stencilBuffer;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return this._$createStencilBuffer();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param {number} width
|
|
101
|
+
* @param {number} height
|
|
102
|
+
* @return {WebGLRenderbuffer}
|
|
103
|
+
* @method
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
create(width, height) {
|
|
107
|
+
const stencilBuffer = this._$getStencilBuffer(width, height);
|
|
108
|
+
if (stencilBuffer.width !== width || stencilBuffer.height !== height) {
|
|
109
|
+
stencilBuffer.width = width;
|
|
110
|
+
stencilBuffer.height = height;
|
|
111
|
+
stencilBuffer.area = width * height;
|
|
112
|
+
stencilBuffer.dirty = false;
|
|
113
|
+
this._$gl.bindRenderbuffer(this._$gl.RENDERBUFFER, stencilBuffer);
|
|
114
|
+
this._$gl.renderbufferStorage(this._$gl.RENDERBUFFER, this._$gl.STENCIL_INDEX8, width, height);
|
|
115
|
+
}
|
|
116
|
+
return stencilBuffer;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @param {WebGLRenderbuffer} stencilBuffer
|
|
120
|
+
* @return {void}
|
|
121
|
+
* @method
|
|
122
|
+
* @public
|
|
123
|
+
*/
|
|
124
|
+
release(stencilBuffer) {
|
|
125
|
+
// ステンシルバッファのサイズが非常に大きい場合はプールしない
|
|
126
|
+
if (stencilBuffer.area > this._$maxWidth * this._$maxHeight * 2) {
|
|
127
|
+
this._$gl.deleteRenderbuffer(stencilBuffer);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
stencilBuffer.dirty = true;
|
|
131
|
+
this._$objectPool.push(stencilBuffer);
|
|
132
|
+
this._$objectPoolArea += stencilBuffer.area;
|
|
133
|
+
// プール容量が一定を超えたら、古いステンシルバッファから削除していく
|
|
134
|
+
if (this._$objectPoolArea > this._$maxWidth * this._$maxHeight * 10) {
|
|
135
|
+
const oldStencilBuffer = this._$objectPool.shift();
|
|
136
|
+
if (oldStencilBuffer) {
|
|
137
|
+
this._$objectPoolArea -= oldStencilBuffer.area;
|
|
138
|
+
this._$gl.deleteRenderbuffer(oldStencilBuffer);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|