aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webglrenderingcontext/blendequationseparate/index.html
blob: 6914a93453bd7344de106925e2d55a6f9ff89ede (plain)
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: WebGLRenderingContext.blendEquationSeparate()
slug: Web/API/WebGLRenderingContext/blendEquationSeparate
translation_of: Web/API/WebGLRenderingContext/blendEquationSeparate
---
<div>{{APIRef("WebGL")}}</div>

<p>The <strong><code>WebGLRenderingContext.blendEquationSeparate()</code></strong> method of the <a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a> is used to set the RGB blend equation and alpha blend equation separately.</p>

<p>The blend equation determines how a new pixel is combined with a pixel already in the {{domxref("WebGLFramebuffer")}}.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">void <var>gl</var>.blendEquationSeparate(<var>modeRGB, modeAlpha</var>);
</pre>

<h3 id="Parameters">Parameters</h3>

<dl>
 <dt><code>modeRGB</code></dt>
 <dd>A {{domxref("GLenum")}} specifying how the red, green and blue components of source and destination colors are combined. Must be either:
 <ul>
  <li><code>gl.FUNC_ADD</code>: source + destination (default value),</li>
  <li><code>gl.FUNC_SUBTRACT</code>: source - destination,</li>
  <li><code>gl.FUNC_REVERSE_SUBTRACT</code>: destination - source,</li>
  <li>When using the {{domxref("EXT_blend_minmax")}} extension:
   <ul>
    <li><code>ext.MIN_EXT</code>: Minimum of source and destination,</li>
    <li><code>ext.MAX_EXT</code>: Maximum of source and destination.</li>
   </ul>
  </li>
  <li>When using a {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}}, the following values are available additionally:
   <ul>
    <li><code>gl.MIN</code>: Minimum of source and destination,</li>
    <li><code>gl.MAX</code>: Maximum of source and destination.</li>
   </ul>
  </li>
 </ul>
 </dd>
 <dt><code>modeAlpha</code></dt>
 <dd>A {{domxref("GLenum")}} specifying how the alpha component (transparency) of source and destination colors are combined. Must be either:
 <ul>
  <li><code>gl.FUNC_ADD</code>: source + destination (default value),</li>
  <li><code>gl.FUNC_SUBTRACT</code>: source - destination,</li>
  <li><code>gl.FUNC_REVERSE_SUBTRACT</code>: destination - source,</li>
  <li>When using the {{domxref("EXT_blend_minmax")}} extension:
   <ul>
    <li><code>ext.MIN_EXT</code>: Minimum of source and destination,</li>
    <li><code>ext.MAX_EXT</code>: Maximum of source and destination.</li>
   </ul>
  </li>
  <li>When using a {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}}, the following values are available additionally:
   <ul>
    <li><code>gl.MIN</code>: Minimum of source and destination,</li>
    <li><code>gl.MAX</code>: Maximum of source and destination.</li>
   </ul>
  </li>
 </ul>
 </dd>
</dl>

<h3 id="Return_value">Return value</h3>

<p>None.</p>

<h3 id="Exceptions">Exceptions</h3>

<p>If <em>mode</em> is not one of the three possible values, a <code>gl.INVALID_ENUM</code> error is thrown.</p>

<h2 id="Examples">Examples</h2>

<p>To set the blend equations, use:</p>

<pre class="brush: js">gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_SUBTRACT);
</pre>

<p>To get the current blend equations, query the <code>BLEND_EQUATION</code>, <code>BLEND_EQUATION_RGB</code> and <code>BLEND_EQUATION_ALPHA</code> constants which return <code>gl.FUNC_ADD</code>, <code>gl.FUNC_SUBTRACT</code>, <code>gl.FUNC_REVERSE_SUBTRACT</code>, or if the {{domxref("EXT_blend_minmax")}} is enabled: <code>ext.MIN_EXT</code> or <code>ext.MAX_EXT</code>.</p>

<pre class="brush: js">gl.getParameter(gl.BLEND_EQUATION_RGB) === gl.FUNC_ADD;
// true

gl.getParameter(gl.BLEND_EQUATION_ALPHA) === gl.FUNC_ADD;
// true
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('WebGL', "#5.14.3", "blendEquationSeparate")}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>Initial definition for WebGL.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 2.0', "glBlendEquationSeparate.xml", "glBlendEquationSeparate")}}</td>
   <td>{{Spec2('OpenGL ES 2.0')}}</td>
   <td>Man page of the OpenGL ES 2.0 API.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 3.0', "glBlendEquationSeparate.xhtml", "glBlendEquationSeparate")}}</td>
   <td>{{Spec2('OpenGL ES 3.0')}}</td>
   <td>Man page of the OpenGL ES 3.0 API.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{Compat("api.WebGLRenderingContext.blendEquationSeparate")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("WebGLRenderingContext.blendEquation()")}}</li>
 <li>{{domxref("WebGLRenderingContext.blendColor()")}}</li>
 <li>{{domxref("WebGLRenderingContext.blendFunc()")}}</li>
 <li>{{domxref("EXT_blend_minmax")}}</li>
</ul>