@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.
- package/dist/CanvasPatternToWebGL.d.ts +0 -6
- package/dist/CanvasPatternToWebGL.js +0 -11
- package/dist/CanvasToWebGLContext.d.ts +90 -31
- package/dist/CanvasToWebGLContext.js +244 -71
- package/dist/CanvasToWebGLContextBlend.d.ts +79 -1
- package/dist/CanvasToWebGLContextBlend.js +197 -13
- package/dist/CanvasToWebGLContextMask.d.ts +0 -6
- package/dist/CanvasToWebGLContextMask.js +1 -26
- package/dist/CanvasToWebGLContextStyle.js +0 -2
- package/dist/Const.d.ts +12 -0
- package/dist/Const.js +14 -0
- package/dist/FrameBufferManager.d.ts +42 -3
- package/dist/FrameBufferManager.js +109 -0
- package/dist/TextureManager.d.ts +54 -4
- package/dist/TextureManager.js +239 -4
- package/dist/VertexArrayObjectManager.d.ts +19 -0
- package/dist/VertexArrayObjectManager.js +69 -18
- package/dist/interface/BlendModeImpl.d.ts +1 -0
- package/dist/interface/BlendModeImpl.js +1 -0
- package/dist/interface/CachePositionImpl.d.ts +11 -0
- package/dist/interface/CachePositionImpl.js +1 -0
- package/dist/interface/PointImpl.d.ts +4 -0
- package/dist/interface/PointImpl.js +1 -0
- package/dist/shader/CanvasToWebGLShader.d.ts +18 -4
- package/dist/shader/CanvasToWebGLShader.js +36 -15
- package/dist/shader/GradientLUTGenerator.js +7 -0
- package/dist/shader/WebGLShaderInstance.d.ts +30 -0
- package/dist/shader/WebGLShaderInstance.js +48 -0
- package/dist/shader/WebGLShaderUniform.js +0 -6
- package/dist/shader/fragment/FragmentShaderLibrary.d.ts +6 -0
- package/dist/shader/fragment/FragmentShaderLibrary.js +13 -4
- package/dist/shader/fragment/FragmentShaderSourceBlend.d.ts +8 -0
- package/dist/shader/fragment/FragmentShaderSourceBlend.js +65 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.d.ts +6 -0
- package/dist/shader/fragment/FragmentShaderSourceTexture.js +32 -0
- package/dist/shader/variants/BlendShaderVariantCollection.d.ts +60 -0
- package/dist/shader/variants/BlendShaderVariantCollection.js +137 -0
- package/dist/shader/vertex/VertexShaderSource.d.ts +12 -0
- package/dist/shader/vertex/VertexShaderSource.js +72 -0
- package/dist/shader/vertex/VertexShaderSourceFill.js +8 -4
- package/package.json +2 -2
|
@@ -60,6 +60,10 @@ export class GradientLUTGenerator {
|
|
|
60
60
|
._$context
|
|
61
61
|
.frameBuffer
|
|
62
62
|
.currentAttachment;
|
|
63
|
+
const cachePosition = this._$context.cachePosition;
|
|
64
|
+
if (cachePosition) {
|
|
65
|
+
this._$gl.disable(this._$gl.SCISSOR_TEST);
|
|
66
|
+
}
|
|
63
67
|
this._$context._$bind(this._$attachment);
|
|
64
68
|
const stopsLength = stops.length;
|
|
65
69
|
const variants = this
|
|
@@ -83,6 +87,9 @@ export class GradientLUTGenerator {
|
|
|
83
87
|
if (!this._$attachment.texture) {
|
|
84
88
|
throw new Error("the texture is null.");
|
|
85
89
|
}
|
|
90
|
+
if (cachePosition) {
|
|
91
|
+
this._$context.bindRenderBuffer(cachePosition);
|
|
92
|
+
}
|
|
86
93
|
return this._$attachment.texture;
|
|
87
94
|
}
|
|
88
95
|
/**
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export declare class WebGLShaderInstance {
|
|
5
|
+
private readonly _$attributes;
|
|
6
|
+
private _$count;
|
|
7
|
+
/**
|
|
8
|
+
* @param {WebGL2RenderingContext} gl
|
|
9
|
+
* @constructor
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
constructor();
|
|
13
|
+
/**
|
|
14
|
+
* @member {array}
|
|
15
|
+
* @readonly
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
get attributes(): number[];
|
|
19
|
+
/**
|
|
20
|
+
* @member {number}
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
get count(): number;
|
|
24
|
+
set count(count: number);
|
|
25
|
+
/**
|
|
26
|
+
* @method
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
clear(): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class
|
|
3
|
+
*/
|
|
4
|
+
export class WebGLShaderInstance {
|
|
5
|
+
/**
|
|
6
|
+
* @param {WebGL2RenderingContext} gl
|
|
7
|
+
* @constructor
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
constructor() {
|
|
11
|
+
/**
|
|
12
|
+
* @type {array}
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
this._$attributes = [];
|
|
16
|
+
/**
|
|
17
|
+
* @type {number}
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
this._$count = 0;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* @member {array}
|
|
24
|
+
* @readonly
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
get attributes() {
|
|
28
|
+
return this._$attributes;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @member {number}
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
get count() {
|
|
35
|
+
return this._$count;
|
|
36
|
+
}
|
|
37
|
+
set count(count) {
|
|
38
|
+
this._$count = count;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @method
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
clear() {
|
|
45
|
+
this._$attributes.length = 0;
|
|
46
|
+
this._$count = 0;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -28,16 +28,10 @@ export class WebGLShaderUniform {
|
|
|
28
28
|
const activeUniforms = this._$gl.getProgramParameter(program, this._$gl.ACTIVE_UNIFORMS);
|
|
29
29
|
for (let i = 0; i < activeUniforms; i++) {
|
|
30
30
|
const info = this._$gl.getActiveUniform(program, i);
|
|
31
|
-
if (!info) {
|
|
32
|
-
throw new Error("the WebGLActiveInfo is null.");
|
|
33
|
-
}
|
|
34
31
|
const name = info.name.endsWith("[0]")
|
|
35
32
|
? info.name.slice(0, -3)
|
|
36
33
|
: info.name;
|
|
37
34
|
const location = this._$gl.getUniformLocation(program, name);
|
|
38
|
-
if (!location) {
|
|
39
|
-
throw new Error("the WebGLUniformLocation is null.");
|
|
40
|
-
}
|
|
41
35
|
// WebGLの仕様でuniformのint型のデフォルト値は0に設定されるため、
|
|
42
36
|
// sampler2D(size=1)の値の更新は不要
|
|
43
37
|
if (info.type === this._$gl.SAMPLER_2D && info.size === 1) {
|
|
@@ -8,6 +8,12 @@ export declare class FragmentShaderLibrary {
|
|
|
8
8
|
* @static
|
|
9
9
|
*/
|
|
10
10
|
static FUNCTION_IS_INSIDE(): string;
|
|
11
|
+
/**
|
|
12
|
+
* @return {string}
|
|
13
|
+
* @method
|
|
14
|
+
* @static
|
|
15
|
+
*/
|
|
16
|
+
static STATEMENT_INSTANCED_COLOR_TRANSFORM_ON(): string;
|
|
11
17
|
/**
|
|
12
18
|
* @param {number} mediump_index
|
|
13
19
|
* @return {string}
|
|
@@ -14,6 +14,18 @@ float isInside(in vec2 uv) {
|
|
|
14
14
|
return step(4.0, dot(step(vec4(0.0, uv.x, 0.0, uv.y), vec4(uv.x, 1.0, uv.y, 1.0)), vec4(1.0)));
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* @return {string}
|
|
21
|
+
* @method
|
|
22
|
+
* @static
|
|
23
|
+
*/
|
|
24
|
+
static STATEMENT_INSTANCED_COLOR_TRANSFORM_ON() {
|
|
25
|
+
return `
|
|
26
|
+
src.rgb /= max(0.0001, src.a);
|
|
27
|
+
src = clamp(src * mul + add, 0.0, 1.0);
|
|
28
|
+
src.rgb *= src.a;
|
|
17
29
|
`;
|
|
18
30
|
}
|
|
19
31
|
/**
|
|
@@ -26,10 +38,7 @@ float isInside(in vec2 uv) {
|
|
|
26
38
|
return `
|
|
27
39
|
vec4 mul = u_mediump[${mediump_index}];
|
|
28
40
|
vec4 add = u_mediump[${mediump_index + 1}];
|
|
29
|
-
|
|
30
|
-
src.rgb /= max(0.0001, src.a);
|
|
31
|
-
src = clamp(src * mul + add, 0.0, 1.0);
|
|
32
|
-
src.rgb *= src.a;
|
|
41
|
+
${FragmentShaderLibrary.STATEMENT_INSTANCED_COLOR_TRANSFORM_ON()}
|
|
33
42
|
`;
|
|
34
43
|
}
|
|
35
44
|
}
|
|
@@ -10,6 +10,14 @@ export declare class FragmentShaderSourceBlend {
|
|
|
10
10
|
* @static
|
|
11
11
|
*/
|
|
12
12
|
static TEMPLATE(operation: string, with_color_transform: boolean): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} operation
|
|
15
|
+
* @param {boolean} with_color_transform
|
|
16
|
+
* @return {string}
|
|
17
|
+
* @method
|
|
18
|
+
* @static
|
|
19
|
+
*/
|
|
20
|
+
static INSTANCE_TEMPLATE(operation: string, with_color_transform: boolean): string;
|
|
13
21
|
/**
|
|
14
22
|
* @return {string}
|
|
15
23
|
* @method
|
|
@@ -65,6 +65,71 @@ void main() {
|
|
|
65
65
|
o_color = blend(src, dst);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @param {string} operation
|
|
72
|
+
* @param {boolean} with_color_transform
|
|
73
|
+
* @return {string}
|
|
74
|
+
* @method
|
|
75
|
+
* @static
|
|
76
|
+
*/
|
|
77
|
+
static INSTANCE_TEMPLATE(operation, with_color_transform) {
|
|
78
|
+
let blendFunction;
|
|
79
|
+
switch (operation) {
|
|
80
|
+
case "subtract":
|
|
81
|
+
blendFunction = this.FUNCTION_SUBTRACT();
|
|
82
|
+
break;
|
|
83
|
+
case "multiply":
|
|
84
|
+
blendFunction = this.FUNCTION_MULTIPLY();
|
|
85
|
+
break;
|
|
86
|
+
case "lighten":
|
|
87
|
+
blendFunction = this.FUNCTION_LIGHTEN();
|
|
88
|
+
break;
|
|
89
|
+
case "darken":
|
|
90
|
+
blendFunction = this.FUNCTION_DARKEN();
|
|
91
|
+
break;
|
|
92
|
+
case "overlay":
|
|
93
|
+
blendFunction = this.FUNCTION_OVERLAY();
|
|
94
|
+
break;
|
|
95
|
+
case "hardlight":
|
|
96
|
+
blendFunction = this.FUNCTION_HARDLIGHT();
|
|
97
|
+
break;
|
|
98
|
+
case "difference":
|
|
99
|
+
blendFunction = this.FUNCTION_DIFFERENCE();
|
|
100
|
+
break;
|
|
101
|
+
case "invert":
|
|
102
|
+
blendFunction = this.FUNCTION_INVERT();
|
|
103
|
+
break;
|
|
104
|
+
default:
|
|
105
|
+
blendFunction = this.FUNCTION_NORMAL();
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
const colorTransformUniform = with_color_transform
|
|
109
|
+
? "uniform vec4 u_mediump[2];"
|
|
110
|
+
: "";
|
|
111
|
+
const colorTransformStatement = with_color_transform
|
|
112
|
+
? FragmentShaderLibrary.STATEMENT_COLOR_TRANSFORM_ON(0)
|
|
113
|
+
: "";
|
|
114
|
+
return `#version 300 es
|
|
115
|
+
precision mediump float;
|
|
116
|
+
|
|
117
|
+
uniform sampler2D u_textures[2];
|
|
118
|
+
${colorTransformUniform}
|
|
119
|
+
|
|
120
|
+
in vec2 v_src_coord;
|
|
121
|
+
in vec2 v_dst_coord;
|
|
122
|
+
out vec4 o_color;
|
|
123
|
+
|
|
124
|
+
${blendFunction}
|
|
125
|
+
|
|
126
|
+
void main() {
|
|
127
|
+
vec4 dst = texture(u_textures[0], v_dst_coord);
|
|
128
|
+
vec4 src = texture(u_textures[1], v_src_coord);
|
|
129
|
+
${colorTransformStatement}
|
|
130
|
+
o_color = blend(src, dst);
|
|
131
|
+
}
|
|
132
|
+
|
|
68
133
|
`;
|
|
69
134
|
}
|
|
70
135
|
/**
|
|
@@ -31,6 +31,38 @@ void main() {
|
|
|
31
31
|
o_color = src;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @return {string}
|
|
38
|
+
* @method
|
|
39
|
+
* @static
|
|
40
|
+
*/
|
|
41
|
+
static INSTANCE_TEMPLATE() {
|
|
42
|
+
return `#version 300 es
|
|
43
|
+
precision mediump float;
|
|
44
|
+
|
|
45
|
+
uniform sampler2D u_texture;
|
|
46
|
+
|
|
47
|
+
in vec4 mul;
|
|
48
|
+
in vec4 add;
|
|
49
|
+
in vec2 v_coord;
|
|
50
|
+
out vec4 o_color;
|
|
51
|
+
|
|
52
|
+
void main() {
|
|
53
|
+
vec4 src = texture(u_texture, v_coord);
|
|
54
|
+
|
|
55
|
+
if (mul.x != 1.0 || mul.y != 1.0 || mul.z != 1.0 || mul.w != 1.0
|
|
56
|
+
|| add.x != 0.0 || add.y != 0.0 || add.z != 0.0 || add.w != 0.0
|
|
57
|
+
) {
|
|
58
|
+
src.rgb /= max(0.0001, src.a);
|
|
59
|
+
src = clamp(src * mul + add, 0.0, 1.0);
|
|
60
|
+
src.rgb *= src.a;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
o_color = src;
|
|
64
|
+
}
|
|
65
|
+
|
|
34
66
|
`;
|
|
35
67
|
}
|
|
36
68
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CanvasToWebGLShader } from "../CanvasToWebGLShader";
|
|
2
2
|
import type { CanvasToWebGLContext } from "../../CanvasToWebGLContext";
|
|
3
3
|
import type { WebGLShaderUniform } from "../WebGLShaderUniform";
|
|
4
|
+
import type { WebGLShaderInstance } from "../WebGLShaderInstance";
|
|
4
5
|
/**
|
|
5
6
|
* @class
|
|
6
7
|
*/
|
|
@@ -15,6 +16,12 @@ export declare class BlendShaderVariantCollection {
|
|
|
15
16
|
* @public
|
|
16
17
|
*/
|
|
17
18
|
constructor(context: CanvasToWebGLContext, gl: WebGL2RenderingContext);
|
|
19
|
+
/**
|
|
20
|
+
* @return {CanvasToWebGLShader}
|
|
21
|
+
* @method
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
getInstanceShader(): CanvasToWebGLShader;
|
|
18
25
|
/**
|
|
19
26
|
* @param {boolean} with_color_transform
|
|
20
27
|
* @return {CanvasToWebGLShader}
|
|
@@ -36,6 +43,14 @@ export declare class BlendShaderVariantCollection {
|
|
|
36
43
|
* @public
|
|
37
44
|
*/
|
|
38
45
|
getBlendShader(operation: string, with_color_transform: boolean): CanvasToWebGLShader;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} operation
|
|
48
|
+
* @param {boolean} with_color_transform
|
|
49
|
+
* @return {CanvasToWebGLShader}
|
|
50
|
+
* @method
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
getInstanceBlendShader(operation: string, with_color_transform: boolean): CanvasToWebGLShader;
|
|
39
54
|
/**
|
|
40
55
|
* @param {WebGLShaderUniform} uniform
|
|
41
56
|
* @param {number} x
|
|
@@ -59,6 +74,28 @@ export declare class BlendShaderVariantCollection {
|
|
|
59
74
|
* @public
|
|
60
75
|
*/
|
|
61
76
|
setNormalBlendUniform(uniform: WebGLShaderUniform, x: number, y: number, w: number, h: number, matrix: Float32Array, render_width: number, render_height: number, with_color_transform: boolean, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* @param {WebGLShaderUniform} uniform
|
|
79
|
+
* @param {number} x
|
|
80
|
+
* @param {number} y
|
|
81
|
+
* @param {number} w
|
|
82
|
+
* @param {number} h
|
|
83
|
+
* @param {Float32Array} matrix
|
|
84
|
+
* @param {number} render_width
|
|
85
|
+
* @param {number} render_height
|
|
86
|
+
* @param {number} ct0
|
|
87
|
+
* @param {number} ct1
|
|
88
|
+
* @param {number} ct2
|
|
89
|
+
* @param {number} ct3
|
|
90
|
+
* @param {number} ct4
|
|
91
|
+
* @param {number} ct5
|
|
92
|
+
* @param {number} ct6
|
|
93
|
+
* @param {number} ct7
|
|
94
|
+
* @return {void}
|
|
95
|
+
* @method
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
pushNormalBlend(instance: WebGLShaderInstance, x: number, y: number, w: number, h: number, matrix: Float32Array, render_width: number, render_height: number, ct0?: number, ct1?: number, ct2?: number, ct3?: number, ct4?: number, ct5?: number, ct6?: number, ct7?: number): void;
|
|
62
99
|
/**
|
|
63
100
|
* @param {WebGLShaderUniform} uniform
|
|
64
101
|
* @param {number} x
|
|
@@ -95,5 +132,28 @@ export declare class BlendShaderVariantCollection {
|
|
|
95
132
|
* @method
|
|
96
133
|
* @public
|
|
97
134
|
*/
|
|
135
|
+
setInstanceBlendUniform(uniform: WebGLShaderUniform, x: number, y: number, w: number, h: number, texture_width: number, texture_height: number, matrix: Float32Array, render_width: number, render_height: number, with_color_transform: boolean, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number): void;
|
|
136
|
+
/**
|
|
137
|
+
* @param {WebGLShaderUniform} uniform
|
|
138
|
+
* @param {number} x
|
|
139
|
+
* @param {number} y
|
|
140
|
+
* @param {number} w
|
|
141
|
+
* @param {number} h
|
|
142
|
+
* @param {Float32Array} matrix
|
|
143
|
+
* @param {number} render_width
|
|
144
|
+
* @param {number} render_height
|
|
145
|
+
* @param {Float32Array} with_color_transform
|
|
146
|
+
* @param {number} ct0
|
|
147
|
+
* @param {number} ct1
|
|
148
|
+
* @param {number} ct2
|
|
149
|
+
* @param {number} ct3
|
|
150
|
+
* @param {number} ct4
|
|
151
|
+
* @param {number} ct5
|
|
152
|
+
* @param {number} ct6
|
|
153
|
+
* @param {number} ct7
|
|
154
|
+
* @return {void}
|
|
155
|
+
* @method
|
|
156
|
+
* @public
|
|
157
|
+
*/
|
|
98
158
|
setBlendUniform(uniform: WebGLShaderUniform, x: number, y: number, w: number, h: number, matrix: Float32Array, render_width: number, render_height: number, with_color_transform: boolean, ct0: number, ct1: number, ct2: number, ct3: number, ct4: number, ct5: number, ct6: number, ct7: number): void;
|
|
99
159
|
}
|
|
@@ -3,6 +3,7 @@ import { VertexShaderSource } from "../vertex/VertexShaderSource";
|
|
|
3
3
|
import { FragmentShaderSourceTexture } from "../fragment/FragmentShaderSourceTexture";
|
|
4
4
|
import { FragmentShaderSourceBlend } from "../fragment/FragmentShaderSourceBlend";
|
|
5
5
|
import { $getMap } from "@next2d/share";
|
|
6
|
+
import { $RENDER_SIZE } from "../../Const";
|
|
6
7
|
/**
|
|
7
8
|
* @class
|
|
8
9
|
*/
|
|
@@ -30,6 +31,23 @@ export class BlendShaderVariantCollection {
|
|
|
30
31
|
*/
|
|
31
32
|
this._$collection = $getMap();
|
|
32
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* @return {CanvasToWebGLShader}
|
|
36
|
+
* @method
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
getInstanceShader() {
|
|
40
|
+
const key = "i";
|
|
41
|
+
if (this._$collection.has(key)) {
|
|
42
|
+
const shader = this._$collection.get(key);
|
|
43
|
+
if (shader) {
|
|
44
|
+
return shader;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.INSTANCE(), FragmentShaderSourceTexture.INSTANCE_TEMPLATE());
|
|
48
|
+
this._$collection.set(key, shader);
|
|
49
|
+
return shader;
|
|
50
|
+
}
|
|
33
51
|
/**
|
|
34
52
|
* @param {boolean} with_color_transform
|
|
35
53
|
* @return {CanvasToWebGLShader}
|
|
@@ -84,6 +102,25 @@ export class BlendShaderVariantCollection {
|
|
|
84
102
|
this._$collection.set(key, shader);
|
|
85
103
|
return shader;
|
|
86
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} operation
|
|
107
|
+
* @param {boolean} with_color_transform
|
|
108
|
+
* @return {CanvasToWebGLShader}
|
|
109
|
+
* @method
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
getInstanceBlendShader(operation, with_color_transform) {
|
|
113
|
+
const key = `i${operation}${with_color_transform ? "y" : "n"}`;
|
|
114
|
+
if (this._$collection.has(key)) {
|
|
115
|
+
const shader = this._$collection.get(key);
|
|
116
|
+
if (shader) {
|
|
117
|
+
return shader;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const shader = new CanvasToWebGLShader(this._$gl, this._$context, VertexShaderSource.INSTANCE_BLEND(), FragmentShaderSourceBlend.INSTANCE_TEMPLATE(operation, with_color_transform));
|
|
121
|
+
this._$collection.set(key, shader);
|
|
122
|
+
return shader;
|
|
123
|
+
}
|
|
87
124
|
/**
|
|
88
125
|
* @param {WebGLShaderUniform} uniform
|
|
89
126
|
* @param {number} x
|
|
@@ -141,6 +178,44 @@ export class BlendShaderVariantCollection {
|
|
|
141
178
|
mediump[7] = ct7;
|
|
142
179
|
}
|
|
143
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* @param {WebGLShaderUniform} uniform
|
|
183
|
+
* @param {number} x
|
|
184
|
+
* @param {number} y
|
|
185
|
+
* @param {number} w
|
|
186
|
+
* @param {number} h
|
|
187
|
+
* @param {Float32Array} matrix
|
|
188
|
+
* @param {number} render_width
|
|
189
|
+
* @param {number} render_height
|
|
190
|
+
* @param {number} ct0
|
|
191
|
+
* @param {number} ct1
|
|
192
|
+
* @param {number} ct2
|
|
193
|
+
* @param {number} ct3
|
|
194
|
+
* @param {number} ct4
|
|
195
|
+
* @param {number} ct5
|
|
196
|
+
* @param {number} ct6
|
|
197
|
+
* @param {number} ct7
|
|
198
|
+
* @return {void}
|
|
199
|
+
* @method
|
|
200
|
+
* @public
|
|
201
|
+
*/
|
|
202
|
+
pushNormalBlend(instance, x, y, w, h, matrix, render_width, render_height, ct0 = 1, ct1 = 1, ct2 = 1, ct3 = 1, ct4 = 0, ct5 = 0, ct6 = 0, ct7 = 0) {
|
|
203
|
+
// texture rectangle
|
|
204
|
+
instance.attributes.push(
|
|
205
|
+
// texture rectangle
|
|
206
|
+
x / $RENDER_SIZE, y / $RENDER_SIZE, w / $RENDER_SIZE, h / $RENDER_SIZE,
|
|
207
|
+
// texture width, height and viewport width, height
|
|
208
|
+
w, h, render_width, render_height,
|
|
209
|
+
// matrix tx, ty and with_color_transform
|
|
210
|
+
matrix[6], matrix[7],
|
|
211
|
+
// matrix scale0, rotate0, scale1, rotate1
|
|
212
|
+
matrix[0], matrix[1], matrix[3], matrix[4],
|
|
213
|
+
// mulColor
|
|
214
|
+
ct0, ct1, ct2, ct3,
|
|
215
|
+
// addColor
|
|
216
|
+
ct4, ct5, ct6, ct7);
|
|
217
|
+
instance.count++;
|
|
218
|
+
}
|
|
144
219
|
/**
|
|
145
220
|
* @param {WebGLShaderUniform} uniform
|
|
146
221
|
* @param {number} x
|
|
@@ -198,6 +273,68 @@ export class BlendShaderVariantCollection {
|
|
|
198
273
|
* @method
|
|
199
274
|
* @public
|
|
200
275
|
*/
|
|
276
|
+
setInstanceBlendUniform(uniform, x, y, w, h, texture_width, texture_height, matrix, render_width, render_height, with_color_transform, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7) {
|
|
277
|
+
const textures = uniform.textures;
|
|
278
|
+
textures[0] = 0;
|
|
279
|
+
textures[1] = 1;
|
|
280
|
+
const highp = uniform.highp;
|
|
281
|
+
// vertex: u_rect
|
|
282
|
+
highp[0] = x;
|
|
283
|
+
highp[1] = y;
|
|
284
|
+
highp[2] = w;
|
|
285
|
+
highp[3] = h;
|
|
286
|
+
// vertex: u_matrix
|
|
287
|
+
highp[4] = matrix[0];
|
|
288
|
+
highp[5] = matrix[1];
|
|
289
|
+
highp[6] = matrix[2];
|
|
290
|
+
highp[8] = matrix[3];
|
|
291
|
+
highp[9] = matrix[4];
|
|
292
|
+
highp[10] = matrix[5];
|
|
293
|
+
highp[12] = matrix[6];
|
|
294
|
+
highp[13] = matrix[7];
|
|
295
|
+
highp[14] = matrix[8];
|
|
296
|
+
// vertex: u_viewport
|
|
297
|
+
highp[7] = render_width;
|
|
298
|
+
highp[11] = render_height;
|
|
299
|
+
// vertex: u_size
|
|
300
|
+
highp[16] = texture_width;
|
|
301
|
+
highp[17] = texture_height;
|
|
302
|
+
if (with_color_transform) {
|
|
303
|
+
const mediump = uniform.mediump;
|
|
304
|
+
// fragment: u_color_transform_mul
|
|
305
|
+
mediump[0] = ct0;
|
|
306
|
+
mediump[1] = ct1;
|
|
307
|
+
mediump[2] = ct2;
|
|
308
|
+
mediump[3] = ct3;
|
|
309
|
+
// fragment: u_color_transform_add
|
|
310
|
+
mediump[4] = ct4;
|
|
311
|
+
mediump[5] = ct5;
|
|
312
|
+
mediump[6] = ct6;
|
|
313
|
+
mediump[7] = ct7;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* @param {WebGLShaderUniform} uniform
|
|
318
|
+
* @param {number} x
|
|
319
|
+
* @param {number} y
|
|
320
|
+
* @param {number} w
|
|
321
|
+
* @param {number} h
|
|
322
|
+
* @param {Float32Array} matrix
|
|
323
|
+
* @param {number} render_width
|
|
324
|
+
* @param {number} render_height
|
|
325
|
+
* @param {Float32Array} with_color_transform
|
|
326
|
+
* @param {number} ct0
|
|
327
|
+
* @param {number} ct1
|
|
328
|
+
* @param {number} ct2
|
|
329
|
+
* @param {number} ct3
|
|
330
|
+
* @param {number} ct4
|
|
331
|
+
* @param {number} ct5
|
|
332
|
+
* @param {number} ct6
|
|
333
|
+
* @param {number} ct7
|
|
334
|
+
* @return {void}
|
|
335
|
+
* @method
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
201
338
|
setBlendUniform(uniform, x, y, w, h, matrix, render_width, render_height, with_color_transform, ct0, ct1, ct2, ct3, ct4, ct5, ct6, ct7) {
|
|
202
339
|
const textures = uniform.textures;
|
|
203
340
|
textures[0] = 0;
|
|
@@ -14,6 +14,18 @@ export declare class VertexShaderSource {
|
|
|
14
14
|
* @static
|
|
15
15
|
*/
|
|
16
16
|
static BLEND(): string;
|
|
17
|
+
/**
|
|
18
|
+
* @return {string}
|
|
19
|
+
* @method
|
|
20
|
+
* @static
|
|
21
|
+
*/
|
|
22
|
+
static INSTANCE_BLEND(): string;
|
|
23
|
+
/**
|
|
24
|
+
* @return {string}
|
|
25
|
+
* @method
|
|
26
|
+
* @static
|
|
27
|
+
*/
|
|
28
|
+
static INSTANCE(): string;
|
|
17
29
|
/**
|
|
18
30
|
* @return {string}
|
|
19
31
|
* @method
|
|
@@ -54,6 +54,78 @@ void main() {
|
|
|
54
54
|
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @return {string}
|
|
61
|
+
* @method
|
|
62
|
+
* @static
|
|
63
|
+
*/
|
|
64
|
+
static INSTANCE_BLEND() {
|
|
65
|
+
return `#version 300 es
|
|
66
|
+
|
|
67
|
+
layout (location = 0) in vec2 a_vertex;
|
|
68
|
+
|
|
69
|
+
uniform vec4 u_highp[5];
|
|
70
|
+
|
|
71
|
+
out vec2 v_src_coord;
|
|
72
|
+
out vec2 v_dst_coord;
|
|
73
|
+
|
|
74
|
+
void main() {
|
|
75
|
+
vec4 rect = vec4(u_highp[0].x, u_highp[0].y, u_highp[0].z, u_highp[0].w);
|
|
76
|
+
vec2 size = vec2(u_highp[4].x, u_highp[4].y);
|
|
77
|
+
mat3 matrix = mat3(u_highp[1].xyz, u_highp[2].xyz, u_highp[3].xyz);
|
|
78
|
+
vec2 viewport = vec2(u_highp[1].w, u_highp[2].w);
|
|
79
|
+
|
|
80
|
+
v_src_coord = a_vertex * rect.zw + rect.xy;
|
|
81
|
+
v_dst_coord = a_vertex;
|
|
82
|
+
|
|
83
|
+
vec2 position = vec2(a_vertex.x, 1.0 - a_vertex.y);
|
|
84
|
+
position = position * size;
|
|
85
|
+
position = (matrix * vec3(position, 1.0)).xy;
|
|
86
|
+
position /= viewport;
|
|
87
|
+
|
|
88
|
+
position = position * 2.0 - 1.0;
|
|
89
|
+
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @return {string}
|
|
96
|
+
* @method
|
|
97
|
+
* @static
|
|
98
|
+
*/
|
|
99
|
+
static INSTANCE() {
|
|
100
|
+
return `#version 300 es
|
|
101
|
+
|
|
102
|
+
layout (location = 0) in vec2 a_vertex;
|
|
103
|
+
layout (location = 1) in vec4 a_rect;
|
|
104
|
+
layout (location = 2) in vec4 a_size;
|
|
105
|
+
layout (location = 3) in vec2 a_offset;
|
|
106
|
+
layout (location = 4) in vec4 a_matrix;
|
|
107
|
+
layout (location = 5) in vec4 a_mul;
|
|
108
|
+
layout (location = 6) in vec4 a_add;
|
|
109
|
+
|
|
110
|
+
out vec2 v_coord;
|
|
111
|
+
out vec4 mul;
|
|
112
|
+
out vec4 add;
|
|
113
|
+
|
|
114
|
+
void main() {
|
|
115
|
+
v_coord = a_vertex * a_rect.zw + a_rect.xy;
|
|
116
|
+
mul = a_mul;
|
|
117
|
+
add = a_add;
|
|
118
|
+
|
|
119
|
+
vec2 position = vec2(a_vertex.x, 1.0 - a_vertex.y);
|
|
120
|
+
position = position * a_size.xy;
|
|
121
|
+
mat3 matrix = mat3(a_matrix.x, a_matrix.y, 0.0, a_matrix.z, a_matrix.w, 0.0, a_offset.x, a_offset.y, 1.0);
|
|
122
|
+
position = (matrix * vec3(position, 1.0)).xy;
|
|
123
|
+
position /= a_size.zw;
|
|
124
|
+
|
|
125
|
+
position = position * 2.0 - 1.0;
|
|
126
|
+
gl_Position = vec4(position.x, -position.y, 0.0, 1.0);
|
|
127
|
+
}
|
|
128
|
+
|
|
57
129
|
`;
|
|
58
130
|
}
|
|
59
131
|
/**
|
|
@@ -16,11 +16,15 @@ export class VertexShaderSourceFill {
|
|
|
16
16
|
const bezierAttribute = for_mask
|
|
17
17
|
? this.ATTRIBUTE_BEZIER_ON()
|
|
18
18
|
: "";
|
|
19
|
-
const uvVarying = for_mask
|
|
20
|
-
|
|
19
|
+
const uvVarying = for_mask
|
|
20
|
+
? this.VARYING_BEZIER_ON()
|
|
21
|
+
: with_uv
|
|
22
|
+
? this.VARYING_UV_ON()
|
|
21
23
|
: "";
|
|
22
|
-
const uvStatement = for_mask
|
|
23
|
-
|
|
24
|
+
const uvStatement = for_mask
|
|
25
|
+
? this.STATEMENT_BEZIER_ON()
|
|
26
|
+
: with_uv
|
|
27
|
+
? this.STATEMENT_UV_ON()
|
|
24
28
|
: "";
|
|
25
29
|
const gridFunction = has_grid
|
|
26
30
|
? VertexShaderLibrary.FUNCTION_GRID_ON(with_uv ? 5 : 0)
|