aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webglrenderingcontext/bindframebuffer/index.html
blob: ff033a902c913e80c4a9b36087189d8fdec605e4 (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
---
title: WebGLRenderingContext.bindFramebuffer()
slug: Web/API/WebGLRenderingContext/bindFramebuffer
tags:
  - API
  - Method
  - Reference
  - WebGL
  - WebGLRenderingContext
translation_of: Web/API/WebGLRenderingContext/bindFramebuffer
---
<div>{{APIRef("WebGL")}}</div>

<p><a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a> 的 <strong><code>WebGLRenderingContext.bindFramebuffer()</code></strong> 方法将给定的 {{domxref("WebGLFramebuffer")}} 绑定到目标。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">void <var>gl</var>.bindFramebuffer(<var>target</var>, <var>framebuffer</var>);
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt>target</dt>
 <dd>{{domxref("GLenum")}} 指定绑定点(目标)。可能的值为:
 <ul>
  <li><code>gl.FRAMEBUFFER</code>: 收集用于渲染图像的颜色,alpha,深度和模板缓冲区的缓冲区数据存储。</li>
  <li>当使用 {{domxref("WebGL2RenderingContext", "WebGL 2 context", "", 1)}} 时,可以使用以下值:
   <ul>
    <li><code>gl.DRAW_FRAMEBUFFER</code>: 相当于<code>gl.FRAMEBUFFER</code>, 用作绘图,渲染,清除和写入操作。</li>
    <li><code>gl.READ_FRAMEBUFFER</code>: 用作读取操作的资源。</li>
   </ul>
  </li>
 </ul>
 </dd>
 <dt>framebuffer</dt>
 <dd>要绑定的 {{domxref("WebGLFramebuffer")}} 对象。</dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>None.</p>

<h3 id="异常">异常</h3>

<p>如果目标不是 <code>gl.FRAMEBUFFER</code><code>gl.DRAW_FRAMEBUFFER</code><code>gl.READ_FRAMEBUFFER</code> ,则抛出 <code>gl.INVALID_ENUM</code> 错误。</p>

<h2 id="示例">示例</h2>

<h3 id="绑定帧缓冲区">绑定帧缓冲区</h3>

<pre class="brush: js">var canvas = document.getElementById('canvas');
var gl = canvas.getContext('webgl');
var framebuffer = gl.createFramebuffer();

gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
</pre>

<h3 id="获取当前绑定">获取当前绑定</h3>

<p>要检查当前帧缓冲区绑定,请查询 <code>FRAMEBUFFER_BINDING</code> 常量。</p>

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

<h2 id="规范">规范</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.6", "bindFramebuffer")}}</td>
   <td>{{Spec2('WebGL')}}</td>
   <td>WebGL初始定义.</td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 2.0', "glBindFramebuffer.xml", "glBindFramebuffer")}}</td>
   <td>{{Spec2('OpenGL ES 2.0')}}</td>
   <td>OpenGL API手册.</td>
  </tr>
  <tr>
   <td>{{SpecName('WebGL2', "#3.7.1", "bindFrameBuffer")}}</td>
   <td>{{Spec2('WebGL2')}}</td>
   <td>WebGL 2更新定义.<br>
    新增: <code>gl.DRAW_FRAMEBUFFER</code><code>gl.READ_FRAMEBUFFER</code></td>
  </tr>
  <tr>
   <td>{{SpecName('OpenGL ES 3.0', "glBindFramebuffer.xhtml", "glBindFramebuffer")}}</td>
   <td>{{Spec2('OpenGL ES 3.0')}}</td>
   <td>OpenGL ES 3 API手册(类似).</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>

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

<h2 id="另见">另见</h2>

<ul>
 <li>{{domxref("WebGLRenderingContext.createFramebuffer()")}}</li>
 <li>{{domxref("WebGLRenderingContext.deleteFramebuffer()")}}</li>
 <li>{{domxref("WebGLRenderingContext.isFramebuffer()")}}</li>
 <li>Other buffers: {{domxref("WebGLBuffer")}}, {{domxref("WebGLRenderbuffer")}}<br>
   </li>
</ul>