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()