WEBGL_lose_context.loseContext()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Phương thức WEBGL_lose_context.loseContext() là một phần của WebGL API và cho phép bạn mô phỏng việc mất WebGLRenderingContext.

Nó kích hoạt các bước được mô tả trong WebGL specification cho việc xử lý mất ngữ cảnh. Sự kiện webglcontextlost được gửi đến canvas liên quan với một sự kiện mô phỏng.

Cú pháp

js
loseContext()

Tham số

Không có.

Giá trị trả về

Không có (undefined).

Ví dụ

Với extension này, bạn có thể mô phỏng sự kiện webglcontextlost:

js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");

canvas.addEventListener("webglcontextlost", (event) => {
  console.log(event);
});

gl.getExtension("WEBGL_lose_context").loseContext();

// Sự kiện "webglcontextlost" được kích hoạt.

Thông số kỹ thuật

Specification
WebGL WEBGL_lose_context Khronos Ratified Extension Specification

Tương thích trình duyệt

Xem thêm