forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetBlendMode.js
More file actions
103 lines (90 loc) · 3.26 KB
/
Copy pathSetBlendMode.js
File metadata and controls
103 lines (90 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var CONST = require('../const');
var isEnabled = false;
var currentBlend = null;
var currentBlendEquation = null;
var currentBlendSrc = null;
var currentBlendDst = null;
var currentBlendEquationAlpha = null;
var currentBlendSrcAlpha = null;
var currentBlendDstAlpha = null;
var currentPremultipliedAlpha = null;
var SetBlendMode = function (state, blend, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha)
{
var gl = state.gl;
if (blend === CONST.BLEND_TYPE.NONE)
{
gl.disable(gl.BLEND);
isEnabled = false;
}
else if (!isEnabled)
{
gl.enable(gl.BLEND);
isEnabled = true;
}
if (blend !== CONST.BLEND_TYPE.CUSTOM)
{
if (blend !== currentBlend || premultipliedAlpha !== currentPremultipliedAlpha)
{
if (blend === CONST.BLEND_TYPE.NORMAL)
{
if (premultipliedAlpha)
{
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
}
else
{
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
}
}
if (blend === CONST.BLEND_TYPE.ADD)
{
if (premultipliedAlpha)
{
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE);
}
else
{
gl.blendEquation(gl.FUNC_ADD);
gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
}
}
}
currentBlendEquation = null;
currentBlendSrc = null;
currentBlendDst = null;
currentBlendEquationAlpha = null;
currentBlendSrcAlpha = null;
currentBlendDstAlpha = null;
}
else
{
blendEquationAlpha = blendEquationAlpha || blendEquation;
blendSrcAlpha = blendSrcAlpha || blendSrc;
blendDstAlpha = blendDstAlpha || blendDst;
if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha)
{
gl.blendEquationSeparate(blendEquation, blendEquationAlpha);
currentBlendEquation = blendEquation;
currentBlendEquationAlpha = blendEquationAlpha;
}
if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha)
{
gl.blendFuncSeparate(blendSrc, blendDst, blendSrcAlpha, blendDstAlpha);
currentBlendSrc = blendSrc;
currentBlendDst = blendDst;
currentBlendSrcAlpha = blendSrcAlpha;
currentBlendDstAlpha = blendDstAlpha;
}
}
currentBlend = blend;
currentPremultipliedAlpha = premultipliedAlpha;
};
module.exports = SetBlendMode;