WebGLTexture
Baseline 廣泛可用 *
注意:此功能在 Web Workers 中可用。
WebGLTexture 介面是 WebGL API 的一部分,代表一個不透明的紋理物件,為紋理操作提供儲存和狀態。
WebGL 紋理
WebGLTexture 物件本身不定義任何方法或屬性,其內容也無法直接訪問。在使用 WebGLTexture 物件時,以下 WebGLRenderingContext 的方法很有用:
WebGLRenderingContext.bindTexture()WebGLRenderingContext.createTexture()WebGLRenderingContext.deleteTexture()WebGLRenderingContext.isTexture()
另請參閱 MDN 上的 WebGL 教程,其中介紹了 在 WebGL 中使用紋理。
WebXR 不透明紋理
在使用 WebXR 圖層時,XRWebGLBinding 物件將為顏色和深度/模板附件返回不透明 WebGLTexture 的例項。
返回不透明 WebGLTexture 物件的 WebXR 方法
WebXR 的不透明紋理與標準的 WebGLTexture 相同,但有以下例外:
- WebXR 的不透明紋理在其會話的
requestAnimationFrame()回撥之外是無效的。 - WebXR 的不透明紋理在未被
XRWebGLBinding.getSubImage()或XRWebGLBinding.getViewSubImage()返回之前是無效的。 - WebXR 的顏色附件不透明紋理包含預乘 alpha 的顏色。
- 在
requestAnimationFrame()回撥結束時,WebXR 的不透明紋理將解除繫結,並從所有WebGLShader物件中分離。 - WebXR 的不透明紋理表現得好像它是使用
texStorage2D或texStorage3D(視情況而定)分配的,即使在使用 WebGL 1.0 上下文時也是如此。 - 如果 WebXR 的不透明紋理呼叫
WebGLRenderingContext.deleteTexture(),則會丟擲INVALID_OPERATION錯誤。 - 不允許更改 WebXR 的不透明紋理的尺寸或格式。GL 函式只能修改紋理單元的值和紋理引數。
示例
建立紋理
js
const canvas = document.getElementById("canvas");
const gl = canvas.getContext("webgl");
const texture = gl.createTexture();
規範
| 規範 |
|---|
| WebGL 規範 # 5.9 |
瀏覽器相容性
載入中…
另見
WebGLRenderingContext.bindTexture()WebGLRenderingContext.createTexture()WebGLRenderingContext.deleteTexture()WebGLRenderingContext.isTexture()WebGLRenderingContext.compressedTexImage2D()WebGLRenderingContext.compressedTexSubImage2D()WebGLRenderingContext.copyTexImage2D()WebGLRenderingContext.copyTexSubImage2D()WebGLRenderingContext.generateMipmap()WebGLRenderingContext.getTexParameter()WebGLRenderingContext.texImage2D()WebGLRenderingContext.texSubImage2D()WebGLRenderingContext.texParameterf()WebGLRenderingContext.texParameteri()