@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,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export declare class TextureManager {
|
|
5
|
+
private readonly _$gl;
|
|
6
|
+
private readonly _$objectPool;
|
|
7
|
+
private readonly _$boundTextures;
|
|
8
|
+
private _$objectPoolArea;
|
|
9
|
+
private _$activeTexture;
|
|
10
|
+
_$maxWidth: number;
|
|
11
|
+
_$maxHeight: number;
|
|
12
|
+
/**
|
|
13
|
+
* @param {WebGL2RenderingContext} gl
|
|
14
|
+
* @constructor
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
constructor(gl: WebGL2RenderingContext);
|
|
18
|
+
/**
|
|
19
|
+
* @param {number} width
|
|
20
|
+
* @param {number} height
|
|
21
|
+
* @return {WebGLTexture}
|
|
22
|
+
* @method
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
_$createTexture(width: number, height: number): WebGLTexture;
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} width
|
|
28
|
+
* @param {number} height
|
|
29
|
+
* @return {WebGLTexture}
|
|
30
|
+
* @method
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
_$getTexture(width: number, height: number): WebGLTexture;
|
|
34
|
+
/**
|
|
35
|
+
* @param {number} width
|
|
36
|
+
* @param {number} height
|
|
37
|
+
* @param {Uint8Array} [pixels=null]
|
|
38
|
+
* @param {boolean} [premultiplied_alpha=false]
|
|
39
|
+
* @param {boolean} [flip_y=true]
|
|
40
|
+
* @method
|
|
41
|
+
* @return {WebGLTexture}
|
|
42
|
+
*/
|
|
43
|
+
create(width: number, height: number, pixels?: Uint8Array | null, premultiplied_alpha?: boolean, flip_y?: boolean): WebGLTexture;
|
|
44
|
+
/**
|
|
45
|
+
* @param {HTMLImageElement} image
|
|
46
|
+
* @param {boolean} [smoothing=false]
|
|
47
|
+
* @return {WebGLTexture}
|
|
48
|
+
* @method
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
createFromImage(image: HTMLImageElement, smoothing?: boolean): WebGLTexture;
|
|
52
|
+
/**
|
|
53
|
+
* @param {HTMLCanvasElement} canvas
|
|
54
|
+
* @return {WebGLTexture}
|
|
55
|
+
* @method
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
createFromCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): WebGLTexture;
|
|
59
|
+
/**
|
|
60
|
+
* @param {HTMLVideoElement} video
|
|
61
|
+
* @param {boolean} [smoothing=false]
|
|
62
|
+
* @return {WebGLTexture}
|
|
63
|
+
* @method
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
createFromVideo(video: HTMLVideoElement, smoothing?: boolean): WebGLTexture;
|
|
67
|
+
/**
|
|
68
|
+
* @param {number} width
|
|
69
|
+
* @param {number} height
|
|
70
|
+
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} element
|
|
71
|
+
* @param {boolean} [smoothing=false]
|
|
72
|
+
* @return {WebGLTexture}
|
|
73
|
+
* @method
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
_$createFromElement(width: number, height: number, element: HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas, smoothing?: boolean): WebGLTexture;
|
|
77
|
+
/**
|
|
78
|
+
* @param {WebGLTexture} texture
|
|
79
|
+
* @return {void}
|
|
80
|
+
* @method
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
release(texture: WebGLTexture): void;
|
|
84
|
+
/**
|
|
85
|
+
* @param {WebGLTexture} texture0
|
|
86
|
+
* @param {boolean|null} [smoothing0=null]
|
|
87
|
+
* @return {void}
|
|
88
|
+
* @method
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
bind0(texture0: WebGLTexture, smoothing0?: boolean | null): void;
|
|
92
|
+
/**
|
|
93
|
+
* @param {WebGLTexture} texture0
|
|
94
|
+
* @param {WebGLTexture} texture1
|
|
95
|
+
* @param {boolean} [smoothing01=null]
|
|
96
|
+
* @return {void}
|
|
97
|
+
* @method
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
bind01(texture0: WebGLTexture, texture1: WebGLTexture, smoothing01?: boolean | null): void;
|
|
101
|
+
/**
|
|
102
|
+
* @param {WebGLTexture} texture0
|
|
103
|
+
* @param {WebGLTexture} texture1
|
|
104
|
+
* @param {WebGLTexture} texture2
|
|
105
|
+
* @param {boolean} [smoothing2=null]
|
|
106
|
+
* @return {void}
|
|
107
|
+
* @method
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
bind012(texture0: WebGLTexture, texture1: WebGLTexture, texture2: WebGLTexture, smoothing2?: boolean | null): void;
|
|
111
|
+
/**
|
|
112
|
+
* @param {WebGLTexture} texture0
|
|
113
|
+
* @param {WebGLTexture} texture2
|
|
114
|
+
* @param {boolean} [smoothing2=null]
|
|
115
|
+
* @return {void}
|
|
116
|
+
* @method
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
bind02(texture0: WebGLTexture, texture2: WebGLTexture, smoothing2?: boolean | null): void;
|
|
120
|
+
/**
|
|
121
|
+
* @param {number} index
|
|
122
|
+
* @param {number} target
|
|
123
|
+
* @param {WebGLTexture} texture
|
|
124
|
+
* @param {boolean} smoothing
|
|
125
|
+
* @return {void}
|
|
126
|
+
* @method
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
_$bindTexture(index: number, target: number, texture?: WebGLTexture | null, smoothing?: boolean | null): void;
|
|
130
|
+
}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export class TextureManager {
|
|
5
|
+
/**
|
|
6
|
+
* @param {WebGL2RenderingContext} gl
|
|
7
|
+
* @constructor
|
|
8
|
+
* @public
|
|
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 = [];
|
|
21
|
+
/**
|
|
22
|
+
* @type {number}
|
|
23
|
+
* @default 0
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
this._$objectPoolArea = 0;
|
|
27
|
+
/**
|
|
28
|
+
* @type {number}
|
|
29
|
+
* @default -1
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
this._$activeTexture = -1;
|
|
33
|
+
/**
|
|
34
|
+
* @type {array}
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
this._$boundTextures = [null, null, null];
|
|
38
|
+
/**
|
|
39
|
+
* @type {number}
|
|
40
|
+
* @default 0
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
this._$maxWidth = 0;
|
|
44
|
+
/**
|
|
45
|
+
* @type {number}
|
|
46
|
+
* @default 0
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
this._$maxHeight = 0;
|
|
50
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_ALIGNMENT, 1);
|
|
51
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @param {number} width
|
|
55
|
+
* @param {number} height
|
|
56
|
+
* @return {WebGLTexture}
|
|
57
|
+
* @method
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
_$createTexture(width, height) {
|
|
61
|
+
const texture = this._$gl.createTexture();
|
|
62
|
+
texture.width = 0;
|
|
63
|
+
texture.height = 0;
|
|
64
|
+
texture.area = 0;
|
|
65
|
+
texture.dirty = true;
|
|
66
|
+
texture.smoothing = true;
|
|
67
|
+
texture._$offsetX = 0;
|
|
68
|
+
texture._$offsetY = 0;
|
|
69
|
+
this.bind0(texture, false);
|
|
70
|
+
this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_S, this._$gl.CLAMP_TO_EDGE);
|
|
71
|
+
this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_WRAP_T, this._$gl.CLAMP_TO_EDGE);
|
|
72
|
+
texture.width = width;
|
|
73
|
+
texture.height = height;
|
|
74
|
+
texture.area = width * height;
|
|
75
|
+
texture.dirty = false;
|
|
76
|
+
this._$gl.texStorage2D(this._$gl.TEXTURE_2D, 1, this._$gl.RGBA8, width, height);
|
|
77
|
+
return texture;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @param {number} width
|
|
81
|
+
* @param {number} height
|
|
82
|
+
* @return {WebGLTexture}
|
|
83
|
+
* @method
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
_$getTexture(width, height) {
|
|
87
|
+
// プールに同じサイズのテクスチャがあれば、それを使い回す
|
|
88
|
+
for (let i = 0; i < this._$objectPool.length; i++) {
|
|
89
|
+
const texture = this._$objectPool[i];
|
|
90
|
+
if (texture.width === width && texture.height === height) {
|
|
91
|
+
this._$objectPool.splice(i, 1);
|
|
92
|
+
this._$objectPoolArea -= texture.area;
|
|
93
|
+
this.bind0(texture, false);
|
|
94
|
+
return texture;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return this._$createTexture(width, height);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* @param {number} width
|
|
101
|
+
* @param {number} height
|
|
102
|
+
* @param {Uint8Array} [pixels=null]
|
|
103
|
+
* @param {boolean} [premultiplied_alpha=false]
|
|
104
|
+
* @param {boolean} [flip_y=true]
|
|
105
|
+
* @method
|
|
106
|
+
* @return {WebGLTexture}
|
|
107
|
+
*/
|
|
108
|
+
create(width, height, pixels = null, premultiplied_alpha = false, flip_y = true) {
|
|
109
|
+
const texture = this._$getTexture(width, height);
|
|
110
|
+
if (premultiplied_alpha) {
|
|
111
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
112
|
+
}
|
|
113
|
+
if (!flip_y) {
|
|
114
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
115
|
+
}
|
|
116
|
+
if (texture.width !== width || texture.height !== height) {
|
|
117
|
+
texture.width = width;
|
|
118
|
+
texture.height = height;
|
|
119
|
+
texture.area = width * height;
|
|
120
|
+
texture.dirty = false;
|
|
121
|
+
this._$gl.texImage2D(this._$gl.TEXTURE_2D, 0, this._$gl.RGBA, width, height, 0, this._$gl.RGBA, this._$gl.UNSIGNED_BYTE, pixels);
|
|
122
|
+
}
|
|
123
|
+
else if (pixels) {
|
|
124
|
+
texture.dirty = false;
|
|
125
|
+
this._$gl.texSubImage2D(this._$gl.TEXTURE_2D, 0, 0, 0, width, height, this._$gl.RGBA, this._$gl.UNSIGNED_BYTE, pixels);
|
|
126
|
+
}
|
|
127
|
+
if (premultiplied_alpha) {
|
|
128
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
129
|
+
}
|
|
130
|
+
if (!flip_y) {
|
|
131
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_FLIP_Y_WEBGL, true);
|
|
132
|
+
}
|
|
133
|
+
return texture;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* @param {HTMLImageElement} image
|
|
137
|
+
* @param {boolean} [smoothing=false]
|
|
138
|
+
* @return {WebGLTexture}
|
|
139
|
+
* @method
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
createFromImage(image, smoothing = false) {
|
|
143
|
+
return this._$createFromElement(image.width, image.height, image, smoothing);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @param {HTMLCanvasElement} canvas
|
|
147
|
+
* @return {WebGLTexture}
|
|
148
|
+
* @method
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
createFromCanvas(canvas) {
|
|
152
|
+
return this._$createFromElement(canvas.width, canvas.height, canvas, false);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* @param {HTMLVideoElement} video
|
|
156
|
+
* @param {boolean} [smoothing=false]
|
|
157
|
+
* @return {WebGLTexture}
|
|
158
|
+
* @method
|
|
159
|
+
* @public
|
|
160
|
+
*/
|
|
161
|
+
createFromVideo(video, smoothing = false) {
|
|
162
|
+
return this._$createFromElement(video.videoWidth, video.videoHeight, video, smoothing);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @param {number} width
|
|
166
|
+
* @param {number} height
|
|
167
|
+
* @param {HTMLImageElement|HTMLCanvasElement|HTMLVideoElement} element
|
|
168
|
+
* @param {boolean} [smoothing=false]
|
|
169
|
+
* @return {WebGLTexture}
|
|
170
|
+
* @method
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
_$createFromElement(width, height, element, smoothing = false) {
|
|
174
|
+
const texture = this._$getTexture(width, height);
|
|
175
|
+
texture.dirty = false;
|
|
176
|
+
this.bind0(texture, smoothing);
|
|
177
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
178
|
+
if (texture.width !== width || texture.height !== height) {
|
|
179
|
+
texture.width = width;
|
|
180
|
+
texture.height = height;
|
|
181
|
+
texture.area = width * height;
|
|
182
|
+
this._$gl.texImage2D(this._$gl.TEXTURE_2D, 0, this._$gl.RGBA, this._$gl.RGBA, this._$gl.UNSIGNED_BYTE, element);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
this._$gl.texSubImage2D(this._$gl.TEXTURE_2D, 0, 0, 0, this._$gl.RGBA, this._$gl.UNSIGNED_BYTE, element);
|
|
186
|
+
}
|
|
187
|
+
this._$gl.pixelStorei(this._$gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
188
|
+
return texture;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @param {WebGLTexture} texture
|
|
192
|
+
* @return {void}
|
|
193
|
+
* @method
|
|
194
|
+
* @public
|
|
195
|
+
*/
|
|
196
|
+
release(texture) {
|
|
197
|
+
// テクスチャのサイズが非常に大きい場合はプールしない
|
|
198
|
+
if (texture.area > this._$maxWidth * this._$maxHeight * 2) {
|
|
199
|
+
this._$gl.deleteTexture(texture);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
texture.dirty = true;
|
|
203
|
+
this._$objectPool.push(texture);
|
|
204
|
+
this._$objectPoolArea += texture.area;
|
|
205
|
+
// プール容量が一定を超えたら、古いテクスチャから削除していく
|
|
206
|
+
if (this._$objectPool.length
|
|
207
|
+
&& this._$objectPoolArea > this._$maxWidth * this._$maxHeight * 10) {
|
|
208
|
+
const oldTexture = this._$objectPool.shift();
|
|
209
|
+
this._$objectPoolArea -= oldTexture.area;
|
|
210
|
+
this._$gl.deleteTexture(oldTexture);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* @param {WebGLTexture} texture0
|
|
215
|
+
* @param {boolean|null} [smoothing0=null]
|
|
216
|
+
* @return {void}
|
|
217
|
+
* @method
|
|
218
|
+
* @public
|
|
219
|
+
*/
|
|
220
|
+
bind0(texture0, smoothing0 = null) {
|
|
221
|
+
this._$bindTexture(2, this._$gl.TEXTURE2, null, null);
|
|
222
|
+
this._$bindTexture(1, this._$gl.TEXTURE1, null, null);
|
|
223
|
+
this._$bindTexture(0, this._$gl.TEXTURE0, texture0, smoothing0);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* @param {WebGLTexture} texture0
|
|
227
|
+
* @param {WebGLTexture} texture1
|
|
228
|
+
* @param {boolean} [smoothing01=null]
|
|
229
|
+
* @return {void}
|
|
230
|
+
* @method
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
bind01(texture0, texture1, smoothing01 = null) {
|
|
234
|
+
this._$bindTexture(2, this._$gl.TEXTURE2, null, null);
|
|
235
|
+
this._$bindTexture(1, this._$gl.TEXTURE1, texture1, smoothing01);
|
|
236
|
+
this._$bindTexture(0, this._$gl.TEXTURE0, texture0, smoothing01);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* @param {WebGLTexture} texture0
|
|
240
|
+
* @param {WebGLTexture} texture1
|
|
241
|
+
* @param {WebGLTexture} texture2
|
|
242
|
+
* @param {boolean} [smoothing2=null]
|
|
243
|
+
* @return {void}
|
|
244
|
+
* @method
|
|
245
|
+
* @public
|
|
246
|
+
*/
|
|
247
|
+
bind012(texture0, texture1, texture2, smoothing2 = null) {
|
|
248
|
+
this._$bindTexture(2, this._$gl.TEXTURE2, texture2, smoothing2);
|
|
249
|
+
this._$bindTexture(1, this._$gl.TEXTURE1, texture1, null);
|
|
250
|
+
this._$bindTexture(0, this._$gl.TEXTURE0, texture0, null);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* @param {WebGLTexture} texture0
|
|
254
|
+
* @param {WebGLTexture} texture2
|
|
255
|
+
* @param {boolean} [smoothing2=null]
|
|
256
|
+
* @return {void}
|
|
257
|
+
* @method
|
|
258
|
+
* @public
|
|
259
|
+
*/
|
|
260
|
+
bind02(texture0, texture2, smoothing2 = null) {
|
|
261
|
+
this._$bindTexture(2, this._$gl.TEXTURE2, texture2, smoothing2);
|
|
262
|
+
this._$bindTexture(1, this._$gl.TEXTURE1, null, null);
|
|
263
|
+
this._$bindTexture(0, this._$gl.TEXTURE0, texture0, null);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @param {number} index
|
|
267
|
+
* @param {number} target
|
|
268
|
+
* @param {WebGLTexture} texture
|
|
269
|
+
* @param {boolean} smoothing
|
|
270
|
+
* @return {void}
|
|
271
|
+
* @method
|
|
272
|
+
* @private
|
|
273
|
+
*/
|
|
274
|
+
_$bindTexture(index, target, texture = null, smoothing = null) {
|
|
275
|
+
const shouldBind = texture !== this._$boundTextures[index];
|
|
276
|
+
const shouldSmooth = smoothing !== null && texture !== null && smoothing !== texture.smoothing;
|
|
277
|
+
const shouldActive = (shouldBind || shouldSmooth || target === this._$gl.TEXTURE0)
|
|
278
|
+
&& target !== this._$activeTexture;
|
|
279
|
+
if (shouldActive) {
|
|
280
|
+
this._$activeTexture = target;
|
|
281
|
+
this._$gl.activeTexture(target);
|
|
282
|
+
}
|
|
283
|
+
if (shouldBind) {
|
|
284
|
+
this._$boundTextures[index] = texture;
|
|
285
|
+
this._$gl.bindTexture(this._$gl.TEXTURE_2D, texture);
|
|
286
|
+
}
|
|
287
|
+
if (shouldSmooth) {
|
|
288
|
+
if (texture) {
|
|
289
|
+
texture.smoothing = !!smoothing;
|
|
290
|
+
}
|
|
291
|
+
const filter = smoothing ? this._$gl.LINEAR : this._$gl.NEAREST;
|
|
292
|
+
this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_MIN_FILTER, filter);
|
|
293
|
+
this._$gl.texParameteri(this._$gl.TEXTURE_2D, this._$gl.TEXTURE_MAG_FILTER, filter);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { CapsStyleImpl } from "./interface/CapsStyleImpl";
|
|
2
|
+
import type { JointStyleImpl } from "./interface/JointStyleImpl";
|
|
3
|
+
/**
|
|
4
|
+
* @class
|
|
5
|
+
*/
|
|
6
|
+
export declare class VertexArrayObjectManager {
|
|
7
|
+
private _$gl;
|
|
8
|
+
private readonly _$fillVertexArrayPool;
|
|
9
|
+
private readonly _$strokeVertexArrayPool;
|
|
10
|
+
private _$boundVertexArray;
|
|
11
|
+
private readonly _$fillAttrib_vertex;
|
|
12
|
+
private readonly _$fillAttrib_bezier;
|
|
13
|
+
private readonly _$strokeAttrib_vertex;
|
|
14
|
+
private readonly _$strokeAttrib_option1;
|
|
15
|
+
private readonly _$strokeAttrib_option2;
|
|
16
|
+
private readonly _$strokeAttrib_type;
|
|
17
|
+
private readonly _$vertexBufferData;
|
|
18
|
+
private readonly _$commonVertexArray;
|
|
19
|
+
/**
|
|
20
|
+
* @param {WebGL2RenderingContext} gl
|
|
21
|
+
* @constructor
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
constructor(gl: WebGL2RenderingContext);
|
|
25
|
+
/**
|
|
26
|
+
* @param {number} begin
|
|
27
|
+
* @param {number} end
|
|
28
|
+
* @return {WebGLVertexArrayObject}
|
|
29
|
+
* @method
|
|
30
|
+
* @private
|
|
31
|
+
*/
|
|
32
|
+
_$getVertexArray(begin: number, end: number): WebGLVertexArrayObject;
|
|
33
|
+
/**
|
|
34
|
+
* @return {WebGLVertexArrayObject}
|
|
35
|
+
* @method
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
_$getFillVertexArray(): WebGLVertexArrayObject;
|
|
39
|
+
/**
|
|
40
|
+
* @return {WebGLVertexArrayObject}
|
|
41
|
+
* @method
|
|
42
|
+
* @private
|
|
43
|
+
*/
|
|
44
|
+
_$getStrokeVertexArray(): WebGLVertexArrayObject;
|
|
45
|
+
/**
|
|
46
|
+
* @param {array} vertices
|
|
47
|
+
* @return {WebGLVertexArrayObject}
|
|
48
|
+
* @method
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
createFill(vertices: any[]): WebGLVertexArrayObject;
|
|
52
|
+
/**
|
|
53
|
+
* @param {array} vertices
|
|
54
|
+
* @param {string} lineCap
|
|
55
|
+
* @param {string} lineJoin
|
|
56
|
+
* @return {WebGLVertexArrayObject}
|
|
57
|
+
* @method
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
createStroke(vertices: any[], lineCap: CapsStyleImpl, lineJoin: JointStyleImpl): WebGLVertexArrayObject;
|
|
61
|
+
/**
|
|
62
|
+
* @param {WebGLVertexArrayObject} vertex_array
|
|
63
|
+
* @return {void}
|
|
64
|
+
* @method
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
releaseFill(vertex_array: WebGLVertexArrayObject): void;
|
|
68
|
+
/**
|
|
69
|
+
* @param {WebGLVertexArrayObject} vertex_array
|
|
70
|
+
* @return {void}
|
|
71
|
+
* @method
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
releaseStroke(vertex_array: WebGLVertexArrayObject): void;
|
|
75
|
+
/**
|
|
76
|
+
* @param {WebGLVertexArrayObject} [vertex_array = null]
|
|
77
|
+
* @return {void}
|
|
78
|
+
* @method
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
bind(vertex_array?: WebGLVertexArrayObject | null): void;
|
|
82
|
+
/**
|
|
83
|
+
* @return {void}
|
|
84
|
+
* @method
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
bindCommonVertexArray(): void;
|
|
88
|
+
/**
|
|
89
|
+
* @param {number} begin
|
|
90
|
+
* @param {number} end
|
|
91
|
+
* @return {void}
|
|
92
|
+
* @method
|
|
93
|
+
* @public
|
|
94
|
+
*/
|
|
95
|
+
bindGradientVertexArray(begin: number, end: number): void;
|
|
96
|
+
}
|