aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/webgl_lose_context/restorecontext/index.html
blob: e7203010c669976f81325dd83704dc7f2d11bbba (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
---
title: WEBGL_lose_context.restoreContext()
slug: Web/API/WEBGL_lose_context/restoreContext
tags:
  - API
  - Method
  - Reference
  - WebGL
  - WebGL extension
translation_of: Web/API/WEBGL_lose_context/restoreContext
---
<div>{{APIRef("WebGL")}}</div>

<p><strong>WEBGL_lose_context.restoreContext()</strong> 属于 <a href="/en-US/docs/Web/API/WebGL_API">WebGL API</a>。 , 一般用来模拟 {{domxref("WebGLRenderingContext")}} 的上下文恢复。</p>

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

<pre class="syntaxbox">gl.getExtension('WEBGL_lose_context').restoreContext();</pre>

<h3 id="抛出错误">抛出错误</h3>

<ul>
 <li><code>INVALID_OPERATION</code> 上下文尚未丢失</li>
</ul>

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

<p>你可以用这个方法模拟  <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event">webglcontextrestored</a></code> 事件:</p>

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

canvas.addEventListener('webglcontextrestored', function(e) {
  console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').restoreContext();
</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_lose_context', "", "WEBGL_lose_context.loseContext")}}</td>
   <td>{{Spec2('WEBGL_lose_context')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("api.WEBGL_lose_context.restoreContext")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{domxref("WebGLRenderingContext.isContextLost()")}}</li>
 <li>事件: <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextlost_event">webglcontextlost</a></code>, <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextrestored_event">webglcontextrestored</a></code>, <code><a href="/en-US/docs/Web/API/HTMLCanvasElement/webglcontextcreationerror_event">webglcontextcreationerror</a></code></li>
</ul>